Hi I'm quite new to haskell and just got into structural induction and was wondering if someone could explain the steps I should take it would be very helpful.
Question: -- computes the sum of all numbers in the list
sum :: [Integer] -> Integer
sum [] = 0
sum (x:xs) = x + sum xs
-- appends two lists
(++) :: [Integer] -> [Integer] -> [Integer]
[] ++ ys = ys
(x:xs) ++ ys = x : (xs ++ ys)
Prove (by using structural induction) that the following equation holds, for all lists of integers xs
and ys
:
sum (xs ++ ys) = sum xs + sum ys
Don't forget to state the I.H. in the induction step. Please also make sure you clearly state the reasons why you make the steps in your proofs.
My steps: To prove:
sum (xs ++ ys) = sum xs + sum ys
Proof: by structural induction
Let P ( ) <--- dont really know what to type in there so if someone could take it from there I would appreciete it greatly!