Beruflich Dokumente
Kultur Dokumente
Kanak Kshetri
1 Introduction
• Want to prove that every element x of a set X has a property P
• i.e. ∀x ∈ X, P (x)
• Direct proof for each element doesn’t work because we want finitely long proof even for
an infinite set
• We’ll use:
• Strategy:
• Since every element in the set of natural numbers can be reached by starting at 0
and repeatedly adding 1, we have a finitely long proof that the property holds for each
natural number
2.1.2 Proof
• Using axiomatic set theory
1
3 Examples of Induction on Natural Numbers
3.1 Sum of natural numbers
3.1.1 Theorem: Statement
• ∀n ∈ N, ni=0 i = n(n+1)
P
2
• Base case, n = 0
P0
– Left side = i=0 i = 0
0(0+1)
– Right side = 2 = 20 =0
• Inductive case, n = k + 1
Pk k(k+1)
– Inductive hypothesis: i=0 i = 2
– Add k + 1 to both sides of the inductive hypothesis
– Left side: ki=0 i + (k + 1) = k+1
i=0 i by definition of sum
P P
k(k+1) (k+1)(k+2)
– Right side: 2 + (k + 1) = (k + 1)( k2 + 1) = 2
3.2.2 Proof
• Proof is by induction on n
• Base case, n = 0
• Inductive case, n = k + 1
2
– If a = 0, trivially true because ∀x ∈ N, 0x = 0 (what about 00 ??)
– Assume a 6= 0, multiply both sides by am
∗ Left side: amk ∗ ak = amk+m = am(k+1)
∗ Right side: (am )k ∗ am = (am )k+1
3.3.2 Proof
• Proof is by induction on n
• Base case, n = 0
– Left side: 0
– Right side: 0
• Inductive case, n = k + 1
3.4.2 Proof
• Proof is by induction on n
• Base case, n = 0
P0
– Left side: 1
i=0 a = a0 = 1
a1 −1
– Right side: a−1 = 1
3
• Inductive case, n = k
Pk ak+1 −1
– Inductive hypothesis: i=0 a
i = a−1
– add ak+1 to both sides
– Left side is now k+1 i
P
i=0 a
ak+1 −1 ak+2 −ak+1 +ak+1 −1 ak+2 −1
– Right side is ak+1 ∗ a−1 = a−1 = a−1
4.1.2 Proof
• Proof is by induction on n
• Base case: n = 0
• Inductive case: n = k + 1
Qk
– Inductive hypothesis: f actorialk = i=1 i
Qk Qk+1
– f actorial(k + 1) = (k + 1) ∗ f actorialk = (k + 1) ∗ i=1 = i=1 i
–
4
4.2.2 Proof
• Proof is by induction on n
• Base case, n = 0
P0
– Left side = = 0 (by definition of )
P
i=1 f ib(i)
– Right side = f ib(0 + 2) − 1 = f ib(2) − 1 = f ib(0) + f ib(1) − 1 = 0 + 1 − 1 = 0
• Inductive case, n = k + 1
Pk
– Inductive hypothesis: i=1 f ib(i) = f ib(k + 2) − 1
– Add f ib(k + 1) to both sides
– Left side: k+1
P
i=1 f ib(i)
– Right side: f ib(k + 2) + f ib(k + 1) − 1 = f ib(k + 3) − 1
5.1.2 Proof
• Proof is by structural induction on Peano
5
5.2.2 Proof
• by structural induction on x
– Left side:
∗ sub (add y Zero) Zero
∗ add y Zero
∗ y
– Right side:
∗ y
∗ Left Side
· add y (Succ Zero)
· add (Succ y) Zero
· Succ y
∗ Right Side
· Succ (add y Zero)
· Succ y
– Inductive case: a = (Succ b)
6
· add (Succ y) (Succ b)
· Succ (add (Succ y) b) by inductive hypothesis
∗ Right side
· Succ (add y a)
· Succ (add y (Succ b))
· Succ (add (Succ y) b)
6 Induction on Lists
• Suppose P (xs) is a predicate on lists of type [a]
• Suppose that if P (xs) holds for an arbitrary xs, then P (x : xs) is also true
• Right side
– sum [] + sum ys
– 0 + sum ys
– sum ys
• Left side
• Right side
7
– sum xs ++ sum ys
– sum (k:ks) ++ sum ys
– k + sum ks + sum ys
• Left Side:
• Right Side:
– length xs + length ys
– length (k:ks) + length ys
– 1 + length ks + length ys
8
6.3.2 Inductive case, xs = k:ks
• Inductive hypothesis: length (map f ks) = length ks
• Left Side
• Right Side
– length xs
– length k:ks
– 1 + length ks
• Left Side
9
6.5.1 Base Case, xs = []
• Left side: (map f . map g) [] = map f (map g []) = map f [] = []
• Left Side
– (map f . map g) xs
– map f (map g (k:ks))
– map f ((g k) : (map g ks))
– (f (g k)) : (map f (map g ks))
– ((f . g) k) : ((map f . map g) ks) i.e. change from bracket form back to point form
– ((f . g) k) : (map (f . g) ks) by inductive hypothesis
– map (f . g) (k:ks) by definition of map
– map (f . g) xs
• Left Side
10
6.7 Theorem: foldr (:) [] xs = xs
• Proof is by induction on xs
• Right side: xs = []
• Left side
• Right side:
11
6.8.2 Inductive case: xss = ks:kss
• Inductive hypothesis: map f (concat kss) = concat (map (map f) kss)
• Left Side:
• Left Side:
6.10 Exercise 9
• (Exercises 5,6,7,8 are about proving theorems that I proved while reading)
• Proof is by induction on xs
• Left side:
12
– k + y + sum (map (k +) ys)
– k + y + k * length ys + sum ys
– k * 1 + k * length ys + y + sum ys
– k (1 + length ys) + sum (y:ys)
– k * length xs + sum xs
7 Functional Equality
7.1 Definition
• Equality: If you give two functions/algorithms the same input, they provide the same
output
13
7.4.1 Base case, xs = []
• Left side: [] ++ (ys ++ zs) = ys ++ zs
• Left Side:
– xs ++ (ys ++ zs)
– (k:ks) ++ (ys ++ zs)
– k:(ks ++ (ys ++ zs))
– k:((ks ++ ys) ++ zs) by inductive hypothesis
– k:(ks ++ ys) ++ zs (relation between : and ++)
– ((k:ks) ++ ys) ++ zs
– (xs ++ ys) ++ zs
• Right Side:
– length . concat []
– length []
– 0
14
7.5.2 Inductive case, xss = ks:kss
• Inductive Hypothesis: sum (map length kss) = length (concat kss)
• Left Side:
9 Limitations of Induction
• set must be countably infinite
• i.e. you don’t prove something about P(infinity), you just show that for any P(n), n is
finitely large, P holds
• e.g. proving that reverse (reverse) = id is only true for finite lists
• problem is that infinite lists cannot be constructed in a finite number of steps, which is
the key to making induction work
15
9.1 Exercise 14: Length constraint in concat xss = foldr (++) [] xss
• xss must be finite for concat to yield a meaningful value
• Left Side:
• Right Side: []
16
9.4.2 Inductive case, xs = k:ks
• Inductive Hypothesis: reverse (reverse ks) = ks
• Left Side:
9.5 Exercise 18: Why doesn’t Ex 17’s result hold for infinite lists
• reverse never terminates
• Bird-Meertens calculus
11 Review Exercises
11.1 Ex 19: length (concat xss) = sum (map length xss) for finite xss
• Proof is by induction on xss
• Left Side:
17
– length ks + sum (map length kss)
– sum ((length ks) : (map length kss))
– sum (map length (ks:kss))
11.2 Ex 20: Or
• Problem statement: “or” defined over an argument that has an arbitrary number of
elements delivers True if True occurs as one of the elements of its argument
• Long-winded way of saying if or is passed a list that has a True in it, then it returns
True
• True || or []
• or [y:ys]
• y || (or ys)
• but ys is a list of length n containing True so, by inductive hypothesis, we return True
18
11.3.2 Inductive Case: xs = y:ys, xs is of length n + 1
• Inductive Hypothesis: For lists sized n containing all True, “and” returns True
• Left Side:
– and (y:ys)
– y && (and ys)
– (and ys) [since xs is a list of all True, and y is an element of xs]
– True [inductive hypothesis]
• Proof is by contradiction
f i r s t E l t s : : [ [ a ] ] −> [ a ]
f i r s t E l t s = map head
11.7 Ex 26: Prove that concat = foldr (++) [], assuming that lists are finite
• Proof is by induction on the argument to concat, xss which is a list of lists
19
11.7.2 Inductive case: xss = ks:kss
• Inductive hypothesis: concat kss = foldr (++) [] kss
• Left side:
– concat (ks:kss)
– ks ++ concat kss [by definition of concat]
– ks ++ (foldr (++) [] kss)
– foldr (++) [] (ks:kss) [by definition of foldr]
– foldr (++) [] xss
20