-1

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!

reflective_mind
  • 1,475
  • 3
  • 15
  • 28
Huskey
  • 15
  • 3
  • 1
    If you're hoping somebody is going to just do your homework for you, I hope to heck your hopes are dashed. See also [How do I ask and answer homework questions?](http://meta.stackoverflow.com/questions/334822/how-do-i-ask-and-answer-homework-questions) for advice on turning this copy-and-paste job into a question that could be productive both for you and for the site. In the meantime, I am following the advice on that page in voting to close this question as "too broad". – Daniel Wagner Oct 05 '16 at 21:32
  • Not homework though. This is an old exam question from a university I wish to attend next year. So dont jump to conclusions please. – Huskey Oct 06 '16 at 08:39
  • In fact, "homework" vs. "not homework" doesn't matter. What matters is that you have evidently made no effort to solve the problem yourself, and no effort to identify and communicate to us exactly what it is you need to know to make progress. – Daniel Wagner Oct 06 '16 at 15:06

1 Answers1

2

++ is defined by induction on its first argument, xs, so this is usually a good sign that we need to proceed by induction on xs.

Hence, we fix ys once for all, and define P(xs) as follows

P(xs) = (sum (xs ++ ys) == sum xs + sum ys)

Now you have to prove that P(xs) holds for all xs. Apply the induction principle on lists and you should be OK.

chi
  • 111,837
  • 3
  • 133
  • 218