

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


HW 7 Prof. Caldwell Due: 18 September 2008 COSC 3015
Problem 1.1. Read chapter 3 of Bird.
Problem 1.2. Do exercises 3.2.1 1 and 3.2.4 (for finite natural numbers) using the principle of mathematical induction given on page 63. Hint for 3.2.4: Choose arbitrary m, n โ N at and do induction on p.
In class we gave the following definitions.
date Nat = Zero | Succ Nat deriving (Eq,Ord,Show)
(+) :: Nat -> Nat -> Nat m + Zero = m m + (Succ n) = Succ (m + n)
We can prove properties of our addition function, verifying that it really behaves like the addition we know an love, by using mathematical induction.
Lemma 2.1. โm : N at. Zero + m = m Proof: By induction on m. The property P is given as:
P (m) def = Zero + m = m
Case[P (Zero)] We must show Zero + Zero = Zero, which holds by the definition of + so the base case holds.
Case[P (Succ k)] Assume P (k) and show P (Succ k).
P (k) : Zero + k = k P (Succ k) : Zero + (Succ k) = (Succ k)
Starting on the left side of the equality P (Succ k):
Zero + (Succ k)
ใใdef. of (+)ใใ = Succ (Zero + k)
ใใP (k)ใใ = Succ k
(^1) i.e. prove โm : N at. Succ Zero ร m = m
Lemma 2.2. โn : N at. โk : N at. Succ k + n = k + Succ n Proof: By induction on n. Then
P (n)
def = โk : N at. Succ k + n = k + Succ n
Case[P (Zero)] We must show โk : N at. Succ k + Zero = k + Succ Zero. Choose arbitrary k and show Succ k + Zero = k + Succ Zero. But, consider the following sequences of equalities:
Succ k + Zero
ใใdef. of (+)ใใ = Succ k k + Succ Zero
ใใdef. of (+)ใใ = Succ (k + Zero)
ใใdef. of (+)ใใ = Succ k
so the base case holds. Case[P (Succ m)] Assume P (m) and show P (Succ m).
P (m) : โk : N at. Succ k + m = k + Succ m P (Succ m) : โk : N at. Succ k + Succ m = k + Succ (Succ m) Notice that in the second equation, substituting Succ m for n in the term Succ n on the right side gives Succ (Succ m), this could would be an easy place to make an error. To prove p(Succ m) holds, choose arbitrary k โ N at and show Succ k + Succ m = k + Succ (Succ m) Consider the following sequences of equalities:
Succ k + Succ m
ใใdef. of (+)ใใ = Succ (Succ k + m)
ใใP (m)ใใ = Succ (k + Succ m) k + Succ (Succ m)
ใใdef. of (+)ใใ = Succ (k + Succ m)
Now, we prove the commutativity of addition:
Theorem 2.1. โn : N at. โm : N at. m + n = n + m Proof: By induction on m. Then
P (n) def = โm : N at. m + n = n + m
Case[P (Zero)] We must show โm : N at. m + Zero = Zero + m. Choose arbitrary m and notice that by definition of (+) m + Zero = m and by Lemma 2.1 Zero + m = m. Thus, the base case holds. Case[P (Succ m)] Assume P (m) and show P (Succ m).
P (k) : โm : N at. m + k = k + m P (Succ k) : โm : N at. m + Succ k = Succ k + m To show P (Succ k) choose arbitrary m and show m + Succ k = Succ k + m. m + Succ k ใใdef. of (+)ใใ = Succ (m + k) ใใP (k)ใใ = Succ (k + m) ใใdef. of (+)[backwards]ใใ = k + Succ m ใใ(Lemma 2 .1)ใใ = Succ k + m
Note: In the second to last step, we use the equality k + Succ m
ใใdef. of (+)ใใ = Succ (k + m) in the right to left direction. This can be seen as a step in which we fold up the definition of (+).