How do I do the induction to establish the statement moll n = doll n
, with
moll 0 = 1 --(m.1)
moll n = moll ( n-1) + n --(m.2)
doll n = sol 0 n --(d.1)
where
sol acc 0 = acc +1 --(d.2)
sol acc n = sol ( acc + n) (n-1) -- ? (d.2)
I tried to prove the base case for n = 0
doll 0 = (d.2) = 1 = (m.1) = moll 0 , which is correct.
Now for n+1
, show that
moll 2n = doll (n + 1)
=> doll (n + 1) = (d.2) = soll (acc + n + 1) n
But what now? How can I simplify it any further?
You've got a mistake in your
n+1
step. I suspect this is because you're new to Haskell and its precedence rules.moll (n+1)
is not, as you writemoll 2n
- I'm assuming that by that you meanmoll (2*n)
, sincemoll 2n
is a haskell syntax error.In any case,
moll (n+1)
is in factmoll n + n + 1
, or, with extra parentheses added just to be explicit:That is, you apply
moll
ton
and then you addn + 1
to the result of that.From here you should be able to apply the induction hypothesis and go forward.
More explicitly, since you seem to still be having trouble:
Now, as a lemma:
This can be proved by induction on
n
. It's obviously true forn
equal to 0.For the lemma's induction step:
That second time I used the induction hypothesis may seem a bit odd, but remember that the induction hypothesis says:
For all
x
. Therefore, I can apply it to anything added to(sol 0 n)
, includingn+1
.Now, back to the main proof, using our lemma: