-- #1 {- map f [] = [] -- (map1) map f (x:xs) = f x : map f xs -- (map2) (f . g) x = f (g x) -- (comp) Prove, for all finite xs: map (f.g) xs = (map f . map g) xs Base case: xs == [] Proof: map (f.g) [] = (map1) [] = (map1) map f [] = (map1) map f (map g []) = (comp) (map f . map g) [] Induction case: Assume: map (f.g) xs = (map f . map g) xs Prove map (f.g) (x:xs) = (map f . map g) (x:xs) Proof: map (f.g) (x:xs) = (map 2) ((f.g) x) : (map (f.g) xs) = comp (f (g x)) : (map (f.g) xs) = IH (f (g x)) : ((map f . map g) xs) = comp (f (g x)) : (map f (map g xs)) = map2 map f (g x : (map g xs)) = map2 map f (map g (x:xs)) = comp (map f . map g) (x:xs) -} -- #2 {- reverse [] = [] -- (rev1) reverse (x:xs) = reverse xs ++ [x] -- (rev2) [] ++ ys = ys -- (++1) (x:xs) ++ ys = x:(xs ++ ys) -- (++2) (xs ++ ys) ++ zs = xs ++ (ys ++ zs) -- (++assoc) xs ++ [] = [] ++ xs = xs -- (++nil) Prove, for all finite xs: reverse (reverse xs) = xs Base case: xs == [] Proof: reverse (reverse []) = (rev1) reverse [] = (rev1) [] Induction case: Assume: reverse (reverse xs) = xs Prove: reverse (reverse (x:xs)) = x:xs Proof: reverse (reverse (x:xs)) = (rev2) reverse ((reverse xs) ++ [x]) = (lemma below) reverse [x] ++ reverse(reverse xs) = (IH) reverse [x] ++ xs = (rev2) (reverse [] ++ [x]) ++ xs = (rev1) ([] ++ [x]) ++ xs = (++1) [x] ++ xs = (++2) x:([] ++ xs) = (++1) x:xs Lemma: for all finite xs, reverse (xs ++ ys) = reverse ys ++ reverse xs Proof is again by induction Base case: xs = [] Proof: reverse ([] ++ ys) = (++1) reverse ys = (++nil) reverse ys ++ [] = (rev1) reverse ys ++ reverse [] Induction case: Assume: reverse (xs ++ ys) = reverse ys ++ reverse xs Show: reverse (x:xs ++ ys) = reverse ys ++ reverse (x:xs) Proof: reverse(x:xs ++ ys) = (++2) reverse(x:(xs ++ ys)) = (rev2) reverse (xs ++ ys) ++ [x] = (IH) (reverse ys ++ reverse xs) ++ [x] = (++assoc) reverse ys ++ (reverse xs ++ [x]) = (rev 2) reverse ys ++ reverse (x:xs) -}