Upload
others
View
10
Download
0
Embed Size (px)
Citation preview
CPSC 121: Models of Computation
Module 10: Proof Techniques (part 2)Mathematical Induction
CPSC 121 – 2020W T1 2
Module 10: Announcements
Pre-class quiz #11 is due Monday November 30th at 19:00.
Textbook sections:
Epp, 5th or 4th edition: remainder of 6.1, 7.1
Epp, 3rd edition: remainder of 5.1, 6.1
Rosen, 6th edition: remainder of 2.1, 2.3 up to the top of page 136.
Rosen, 7th edition: remainder of 2.1, 2.3 down to the bottom of page 141.
CPSC 121 – 2020W T1 3
Module 10: Announcements
Assignment #5 is due Wednesday December 2nd at 19:00.
There is no pre-class quiz #12. ☺☺☺
CPSC 121 – 2020W T1 4
Module 10: Mathematical Induction
By the start of class, you should be able to
Convert sequences to and from explicit formulas that describe the sequence.
Convert sums to and from summation/Σ notation.
Convert products to and from product/π notation.
Manipulate formulas in summation/product notation by adjusting their bounds, merging or splitting summations/products, and factoring out values.
CPSC 121 – 2020W T1 5
Module 10: Mathematical Induction
Pre-class quiz #10
Well done overall.
You had a bit more trouble on the questions about the coin-changing induction proof.
We will discuss induction proofs at length and do a lot of examples.
Being comfortable with summations is important not only for CPSC 121, but for following courses too!
As usual, we will revisit the open-ended question shortly.
CPSC 121 – 2020W T1 6
Module 10: Mathematical Induction
If you haven’t already done so,
read the rest of the chapters on mathematical induction (Epp4, 5.2 to 5.4, etc).
After this reading, you will be able to:
Given a theorem to prove stated in terms of its induction variable (i.e., usually, in terms of n), write out the skeleton of an inductive proof including:
the base case(s) that need to be proven,
the induction hypothesis, and
the inductive step that needs to be proven.
CPSC 121 – 2020W T1 7
Module 10: Mathematical Induction
By the end of this module, you should be able to:
Establish properties of self-referential structures using inductive proofs that naturally build on those self-references.
Critique formal inductive proofs to determine whether they are valid and where the error(s) lie if they are invalid.
Prove properties of the non-negative integers (or a subset) with appropriate self-referential structure using weak or strong induction as needed.
CPSC 121 – 2020W T1 8
Module 10: Mathematical Induction
??
?
?
?
? ??
?
???
?
?
?
?
?
CPSC 121: the BIG questions:
1. How can we convince ourselves that an algorithm does what it's supposed to do?
2. How do we determine whether or not one algorithm is better than another one?
Mathematical induction is a veryvery useful tool when proving the correctness or efficiency of an algorithm.
We will see several examples of this.
CPSC 121 – 2020W T1 9
Module 10: Mathematical Induction
Module Summary
Example: single-elimination tournaments.
Defining and validating mathematical induction.
More examples where we can use induction.
A slightly different type of induction.
CPSC 121 – 2020W T1 10
Module 10.1: Single-elimination tournaments
Problem: single-elimination tournament
Teams play one another in pairs
The winner of each pair advances to the next roundLos Angeles
Montréal
Toronto
New York Isl.
Vancouver
St. Louis
Pittsburgh
Buffalo
Round 2 Round 3 Round 4
CPSC 121 – 2020W T1 11
Module 10.1: Single-elimination tournaments
Problem: single-elimination tournament
Teams play one another in pairs
The winner of each pair advances to the next round
Montréal
Los Angeles
Montréal
Toronto
New York Isl.
Vancouver
St. Louis
Pittsburgh
Buffalo
Los AngelesToronto
New York Isl.
Round 2 Round 3 Round 4
CPSC 121 – 2020W T1 12
Module 10.1: Single-elimination tournaments
Problem: single-elimination tournament
Teams play one another in pairs
The winner of each pair advances to the next round
Montréal
Montréal
Los Angeles
Montréal
Toronto
New York Isl.
Vancouver
St. Louis
Pittsburgh
Buffalo
Los Angeles
Los Angeles
Toronto
New York Isl.
Round 2 Round 3 Round 4
CPSC 121 – 2020W T1 13
Module 10.1: Single-elimination tournaments
Problem: single-elimination tournament
Teams play one another in pairs
The winner of each pair advances to the next round
Montréal
Montréal
Los Angeles
Montréal
Toronto
New York Isl.
Vancouver
St. Louis
Pittsburgh
Buffalo
Los Angeles
Los Angeles
Toronto
New York Isl.Montréal
Round 2 Round 3 Round 4
CPSC 121 – 2020W T1 14
Module 10.1: Single-elimination tournaments
Question: if we have n rounds of playoffs, how many teams can participate?
a) n
b) 2n
c) n2
d) 2n
e) None of the above.
▷
CPSC 121 – 2020W T1 16
Module 10.1: Single-elimination tournaments
How can we prove this result formally?
We will use a technique called mathematical induction.
We will convince ourselves that it is a valid proof technique.
Many theorems involve summations, so it is important to be comfortable manipulating them.
Hence the inclusion of section 5.1 in the reading for pre-class quiz #10.
CPSC 121 – 2020W T1 17
Module 10.1: Single-elimination tournaments
First we look at the following question instead:
If t teams can participate in a playoff with n rounds, how many teams can participate in a playoff with n+1 rounds?
a) t+1
b) 2t
c) t2
d) 2t
e) None of the above.
▷
CPSC 121 – 2020W T1 19
Module 10.1: Single-elimination tournaments
Proof:
Consider an unspecified playoff with n rounds. Assume that t teams can participate in that playoff.
We can think of a playoff with n+1 rounds as follows:
Two playoffs with n rounds proceed in parallel.
The two winners then play each other in the n+1st round.
Since each playoff with n rounds has n teams, we thus have 2n teams in total.
CPSC 121 – 2020W T1 20
Module 10.1: Single-elimination tournaments
How do we use this to prove what we want?
Recall Universal Modus Ponens:P(a)∀x D, P(x) → Q(x)∈\ Q(a)
If we define
P(t, n): Up to t teams can participate in a playoff with n rounds
then we have proved
∀t Z∈ + n Z∀ ∈ + , P(t, n)→P(2t, n+1)
CPSC 121 – 2020W T1 21
Module 10.1: Single-elimination tournaments
So
We know that only 2 teams can play with 1 round.
This is P(2, 1).
Given
P(2, 1)
∀t Z∈ + n Z∀ ∈ +, P(t, n) → P(2t, n+1)
We can deduce:
P(4, 2)
CPSC 121 – 2020W T1 22
Module 10.1: Single-elimination tournaments
Given
P(4, 2)∀t Z∈ + n Z∀ ∈ +, P(t, n) → P(2t, n+1)
We can deduce:
P(8, 3)
Given
P(8, 3)∀t Z∈ + n Z∀ ∈ +, P(t, n) → P(2t, n+1)
We can deduce:
P(16, 4)
CPSC 121 – 2020W T1 23
Module 10.1: Single-elimination tournaments
Given
P(16, 4)∀t Z∈ + n Z∀ ∈ +, P(t, n) → P(2t, n+1)
We can deduce:
P(32, 5)
Etc...
Therefore we can show that
∀n Z∈ +, P(2n, n)
CPSC 121 – 2020W T1 24
Module 10.1: Single-elimination tournaments
Another way to think about this:
Given an unspecified positive integer n.
To prove P(2n+1, n+1):
First we prove P(2n, n).
Then we use the fact that∀t Z∈ + n Z∀ ∈ +, P(t, n) → P(2t, n+1)
Hence induction is more or less the same as recursion!
A fun example involving induction: http://www.youtube.com/watch?v=daRS98L9rHs&feature=related
CPSC 121 – 2020W T1 25
Module 10: Mathematical Induction
Module Summary
Example: single-elimination tournaments.
Defining and validating mathematical induction.
More examples where we can use induction.
A slightly different type of induction.
CPSC 121 – 2020W T1 26
Module 10.2: Defining and validating M.I.
Define Q(n) by:
Q(n): P(2n,n)
In the previous example, we proved
Q(1)
∀n Z∈ +, Q(n) → Q(n+1)
and deduced that
∀n Z∈ +, Q(n)
Why is this a valid proof technique?
CPSC 121 – 2020W T1 27
Module 10.2: Defining and validating M.I.
Theorem:
Q(1) ^ ( n Z∀ ∈ +, Q(n) → Q(n+1)) → n Z∀ ∈ +, Q(n)
Proof:
We use a proof by contradiction.
Suppose that the premises hold, but that n Z∀ ∈ +, Q(n) is false. There is at least one value of n for which Q(n) does not hold.
Let y be the smallest such value. Clearly y > 1, so y – 1 Z∈ +.
CPSC 121 – 2020W T1 28
Module 10.2: Defining and validating M.I.
Proof (continued):
Because y is the smallest value for which Q(n) is false, and y – 1 Z∈ +, Q(y - 1) is true.
But then the 2nd premise implies that Q(y) is true, a contradiction (since we assumed Q(y) was false).
Therefore the conclusion must be true, that is n ∀ ∈Z+, Q(n) holds.
CPSC 121 – 2020W T1 29
Module 10.2: Defining and validating M.I.
So a proof by mathematical induction has
One (or more) base case(s): Q(1)
Usually very straightforward to prove.
An induction step:
∀n Z∈ +, Q(n) → Q(n+1) OR n Z∀ ∈ +, Q(n-1) → Q(n)
We can use any proof technique we know for it.
Usually a direct proof will work well.
CPSC 121 – 2020W T1 30
Module 10: Mathematical Induction
Module Summary
Example: single-elimination tournaments.
Defining and validating mathematical induction.
More examples where we can use induction.
A slightly different type of induction.
CPSC 121 – 2020W T1 31
Module 10.3: More induction examples
Example: recall the exercises from our first class:
Make group of 5 students.
Then order each group from in order of day of birth by swapping pairs of adjacent students.
We claimed the maximum number of swaps for n students is n(n-1)/2.
CPSC 121 – 2020W T1 32
Module 10.3: More induction examples
How many swaps do we need?
Suppose we place students from left to right.
The students already placed are ordered by day of birth.
We swap each new student with his/her neighbour until he/she is at the right place.
The ith student may be swapped with all previous i-1 students.
So the total number of swaps is at most
Hence we need to prove that
∑i=0
n−1
i
∑i=0
n−1
i=n(n−1)
2
CPSC 121 – 2020W T1 33
Module 10.3: More induction examples
Which fact(s) do we need to prove?
a)
b)
c)
d) Both (a) and (b)
e) Both (a) and (c)
∑i=0
0
i=0
∀ n∈ℤ+ (∑
i=0
n−1
i=n(n−1)
2 )→(∑i=0
n
i=(n+1) n
2 )(∀n∈ℤ+ ,∑
i=0
n−1
i=n(n−1)
2 )→(∀ n∈ℤ+ ,∑i=0
n
i=(n+1)n
2 )
▷
CPSC 121 – 2020W T1 35
Module 10.3: More induction examples
Proof:
Base case: n = 1
Clearly, with only 1 student, no swap is needed: which is equal to 1 (1-1)/2
Induction step:
Pick an unspecified n ≥ 1. Assume that when we have n students, we need at most n(n-1)/2 swaps. Equivalently we assume that
This is called the Induction Hypothesis.
∑i=0
0
i=0
∑i=0
n−1
i=n(n−1)2
CPSC 121 – 2020W T1 36
Module 10.3: More induction examples
Proof (continued)
Induction step (continued)
For n+1 students, we need at most swaps.
By the induction hypothesis, this is equal to
swaps, as required for the induction step.
Hence by the principle of M.I., the theorem holds. QED
∑i=0
n
i=(∑i=0
n−1
i)+ n
n(n−1)2
+ n=(n+ 1)n2
CPSC 121 – 2020W T1 37
Module 10.3: More induction examples
Worksheet problems 1 and 2
Theorem: for every value of a ≠0, 1:
These summations occur frequently when we need to determine the running time of divide-and-conquer algorithms.
Theorem: n ≥ 4, 2n < n!
∑i=0
t
a i=
a t+ 1−1
a−1
CPSC 121 – 2020W T1 38
Module 10.3: More induction examples
Rules for inequalities:
Start from one side (say the left side)
Work step by step towards the other.
When dealing with <, you are allowed to make the expression on the RHS larger, but never smaller.
Example: if I am smaller than you, then I am still smaller than you when you stand on a bench.
CPSC 121 – 2020W T1 39
Module 10.3: More induction examples
Worksheet problem 3
Theorem: prove that for every n ≥ 1,
Hint:
Note (this doesn’t help with the proof; it’s simply an interesting mathematical fact):
∑i=1
n1i2≤2−
1n
∑i=1
∞ 1
i2=π
2
6
1
n2<
1n (n−1)
CPSC 121 – 2020W T1 40
Module 10.3: More induction examples
Example: consider the following DFA:
3
20
4
1
CPSC 121 – 2020W T1 41
Module 10.3: More induction examples
This DFA accepts the empty string, and which other strings?
a) Strings whose length is divisible by 5.
b) Unsigned binary integers that are prime numbers.
c) Strings where every 1 is followed by 01.
d) Unsigned binary integers that are divisible by 5.
e) None of the above.
▷
CPSC 121 – 2020W T1 43
Module 10.3: More induction examples
Worksheet problem 4
Theorem: After reading the string s representing the unsigned binary integer xs, the DFA is in state xs mod 5
Hint 1: use induction on the length n of s.
Hint 2: if bn-1
bn-2
...b1b
0 represents the integer x,
then bn-1
bn-2
...b1b
0b represents the integer 2x+b.
CPSC 121 – 2020W T1 44
Module 10.3: More induction examples
Mathematical induction is how we analyze recursive algorithms:
Example:
(define (sum n)
(if (= n 0)
0
(+ n (sum (- n 1)))))
The type of induction we discussed so far works when the recursive call is with argument (- n 1)
∑i=0
n
i=n+ (∑i=0
n−1
i)
CPSC 121 – 2020W T1 45
Module 10: Mathematical Induction
Module Summary
Example: single-elimination tournaments.
Defining and validating mathematical induction.
More examples where we can use induction.
A slightly different type of induction.
CPSC 121 – 2020W T1 46
Module 10.4: A slightly different type of induction
Some recursions have recursive calls where the argument is not (- n 1):
(function1 (- n 2))
(function2 (quotient n 2))
(function3 x) where x is some integer in the range 0 < x < n
CPSC 121 – 2020W T1 47
Module 10.4: A slightly different type of induction
How do we handle these?
A recursive function/method has
One or more base casesWhen it can compute the answer directly
An induction stepIt computes recursively the solutions to one or more “smaller” sub-problems, and combines them to obtain its answer.
Our induction proofs mimic this structure.
It is similar to the templates you used in CPSC 110.
CPSC 121 – 2020W T1 48
Module 10.4: A slightly different type of induction
We use a slightly different induction hypothesis.
Instead of proving that
∀x Z∈ +, Q(x) → Q(x+1)
We prove that
∀x Z∈ +, (Q(1) ^ Q(2) ^ ... ^ Q(x)) → Q(x+1)
We can also show that this type of induction is a valid proof technique.
The proof is the same proof by contradiction that we looked at earlier.
CPSC 121 – 2020W T1 49
Module 10.4: A slightly different type of induction
Example: Wilma Flinstone asks Fred to buy dinosaurs eggs to make a large omelet for a party. Eggs are sold in packs of 4 and 7 eggs. Prove:
F(x): Fred can buy exactly x dinosaur eggs for any integer x ≥ 18.
▷
CPSC 121 – 2020W T1 50
Module 10.2: Defining and validating M.I.
How do we decide which base cases we need?
Look at the induction step. Decide for which values of n it can be used to prove F(x).
The induction step might not be usable for some x:
because it needs Q(some k < x) and k would be smaller than smallest x for which Q holds.
because some mathematical steps only work for large enough values of x.
If the induction step is not usable for x, then x needs to be a base case!
CPSC 121 – 2020W T1 51
Module 10.4: A slightly different type of induction
In the simplest induction step possible, which fact will we use to prove F(x) ?
a) F(x-1)
b) F(x-2)
c) F(x-3)
d) F(x-4)
e) F(y) where y is a value other than x-1, x-2, x-3, x-4.
▷
CPSC 121 – 2020W T1 53
Module 10.4: A slightly different type of induction
Induction step:
Consider an unspecified integer x ≥
Assume F(k) holds when k is in the range 18 ≤ k < x.
Then Fred can buy x eggs as follows:Fred buys x - eggs.Then Fred buys a pack of eggs.
CPSC 121 – 2020W T1 54
Module 10.4: A slightly different type of induction
Base case: what case(s) do we need to prove?
a) x = 18
b) x = 18, x = 19
c) x = 18, x = 19, x = 20, x = 21
d) x = 18 up to x = 26
e) None of the above.
▷
CPSC 121 – 2020W T1 56
Module 10.4: A slightly different type of induction
Base cases:
18 = 2 x 7 + 1 x 4
19 = 1 x 7 + 3 x 4
20 = 0 x 7 + 5 x 4
21 = 3 x 7 + 0 x 4
CPSC 121 – 2020W T1 57
Module 10.4: A slightly different type of induction
Worksheet problems 5 and 6
Theorem: we define the Gibbonacci numbers as follows: G(1) = G(2) = 1, G(n) = 2G(n-1) + 3G(n-2) for n ≥ 3. Prove that G(n) ≤ 3n.
Theorem: every positive integer n greater than 1 that is either a prime or can be written as a product of primes.
CPSC 121 – 2020W T1 58
Module 10.4: A slightly different type of induction
Problem: find the ith smallest element in a list
Algorithm:
Pick a random element x of the list.
Divide the list into three sublists:
list-smaller: elements smaller than x
list-equal: elements equal to x
list-larger: elements larger than x
Then searchlist-smaller if i ≤ length of list-smallerlist-larger if i > length of list smaller + length of list-equalotherwise return x
CPSC 121 – 2020W T1 59
Module 10.4: A slightly different type of induction
This algorithm is called randomized-quick-select.
Racket code will be posted on the course web site.
A student shows the expected number of steps S(n) of the algorithm on a list with n elements is:
S(1) = 4c
S(2) = 12c
S(3) = 20c
S(n) ≤ 2cn + S(ë3n/4û) when n ≥ 4
CPSC 121 – 2020W T1 60
Module 10.4: A slightly different type of induction
Worksheet problem 7
Prove that for every n ≥ 1, S(n) ≤ 8cn.