我试图证明以下内容:
filter p . filter q = filter (and p q)
where
and p q x = p x && q x
这是我的尝试,但我不确定它是否正确,有人能给我一些想法吗?
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
归纳案例是我挣扎的点,过滤器可以通过foldr实现,也可以列表理解,但如果我使用列表理解, 可以成为一个归纳案例吗?