I need to prove
f (g xs) == g (f xs)
whenver xs is a finite list of Ints.
Assume both f and g are of type [Int]->[Int]
I need to prove
f (g xs) == g (f xs)
whenver xs is a finite list of Ints.
Assume both f and g are of type [Int]->[Int]
Disproof by counterexample:
f xs = []
g xs = [1]
If you want this property to hold, you need more specific constraints on what f
and g
are.
You may be thinking of the law that
(map f . map g) == map (f . g)
which can indeed be proven.
Found this from somewhere
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