I am trying to prove the following:
filter p . filter q = filter (and p q)
where
and p q x = p x && q x
here is my try, but i am not sure if it is correct, can anyone give me some ideas?
Induction of list xs
Base case xs = []
(filter p . filter q) xs
= {definition of .}
filter p ( filter q xs )
= {xs = []}
filter p ( filter q [] )
= {definition of filter}
filter p []
= {definition of filter}
[]
= {xs = []}
filter (and p q) []
= {definition of filter}
= []
Inductive case:
(filter p . filter q) xs
= {definition of .}
filter p ( filter q xs)
= {definition of filter}
filter p [ x | x<-xs, q x]
= {definition of filter}
[ y | y <- [ x | x<-xs, q x], p y]
= {definition of list} -- i am not sure if it is correct as well
[ x | <- xs, (p x) && (q x)]
= {definition of and p q x = p x && q x}
[ x | x<-xs, and p q x ]
= {definition of filter}
filter (and p q) xs
The inductive case is the point i struggled, filter can be implemented by foldr and also list comprehension, but if i use the list comprehension, it is ok to be a inductive case?