我需要证明
f (g xs) == g (f xs)
当xs是Ints的有限列表时。
假设f和g都是[Int] - > [Int]
类型答案 0 :(得分:3)
反例反驳:
f xs = []
g xs = [1]
如果您希望保留此属性,则需要对f
和g
的更多具体限制。
你可能在想法律
(map f . map g) == map (f . g)
确实可以证明。
答案 1 :(得分:-1)
从某个地方找到这个
Theorem: (map f . map g) xs = map (f . g) xs
- Proof is by induction on xs
*** Base Case, xs = []
- Left side: (map f . map g) [] = map f (map g []) = map f [] = []
- Right side: map (f . g) [] = []
*** Inductive Case, xs = k:ks
- Inductive Hypothesis: (map f . map g) ks = map (f . g) ks
- Left Side
+ (map f . map g) xs
+ map f (map g (k:ks))
+ map f ((g k) : (map g ks))
+ (f (g k)) : (map f (map g ks))
+ ((f . g) k) : ((map f . map g) ks) i.e. change from bracket form back to point form
+ ((f . g) k) : (map (f . g) ks) by inductive hypothesis
+ map (f . g) (k:ks) by definition of map
+ map (f . g) xs