CPSC 121: Models of Computation Module 7: Proof Techniques

CPSC 121: Models of Computation
Module 7: Proof Techniques (part 1)
Assignment #3 is due Friday October 28 th at
17:00.
Pre-class quiz #8 is due Monday October 31 st at
19:00
Module 7: Proof Techniques (part 1)
Epp, 4th edition: 12.2, pages 791 to 795.
Epp, 3rd edition: 12.2, pages 745 to 747, 752 to 754
Rosen, 6th edition: 12.2 pages 796 to 798, 12.3
Rosen, 7th edition: 13.2 pages 858 to 861, 13.3
CPSC 121 – 2016W T1
Module 7: Proof Techniques (part 1)
2
Module 7: Proof Techniques (part 1)
By the start of class, you should be able to, for
each proof strategy below:
Pre-class quiz #9 is tentatively due Monday
November 7th at 19:00.
Identify the form of statement the strategy can
prove.
Textbook sections:
Epp, 4th edition: 5.1 to 5.4
Epp, 3rd edition: 4.1 to 4.4
Rosen, 6th edition: 4.1, 4.2
Rosen, 7th edition: 5.1, 5.2
Sketch the structure of a proof that uses the
strategy.
Strategies:
constructive/non-constructive proofs of existence
generalizing from the generic particular
direct proof (antecedent assumption)
CPSC 121 – 2016W T1
3
CPSC 121 – 2016W T1
4
Module 7: Proof Techniques (part 1)
Module 7: Proof Techniques (part 1)
Strategies (continued):
Quiz 7 feedback:
indirect proofs by contrapositive and contradiction
Well done
proof by cases.
No question had an average below 90%.
Most answers to the open-ended question were
very good.
CPSC 121 – 2016W T1
5
CPSC 121 – 2016W T1
6
Module 7: Proof Techniques (part 1)
Quiz 7 open-ended question: when should you
switch strategies?
CPSC 121: the BIG questions:
Monitor yourself
Module 7: Proof Techniques (part 1)
?
When you are stuck.
When the proof is going around in circles.
?
?
?
?
We need to prove its correctness.
?
?
?
How do we determine whether or not one algorithm
is better than another one?
When the proof is getting too messy.
When it is taking too long.
Through experience (how do you get that?)
CPSC 121 – 2016W T1
?
?
How can we convince ourselves that an algorithm
does what it's supposed to do?
?
7
?
Sometimes, we need a proof to convince someone
that the number of steps of our algorithm is what we
claim it is.
CPSC 121 – 2016W T1
?
?
?
?
8
Module 7: Proof Techniques (part 1)
Module 7: Proof Techniques (part 1)
By the end of this module, you should be able to:
Module Summary
Devise and attempt multiple different, appropriate
proof strategies for a given theorem, including
Techniques for direct proofs.
Existential quantifiers.
Universal quantifiers.
all those listed in the "pre-class" learning goals
logical equivalences,
rules of inference,
universal modus ponens/tollens,
Dealing with multiple quantifiers.
Indirect proofs: contrapositive and contradiction
Additional Examples
For theorems requiring only simple insights beyond
strategic choices or for which the insight is
given/hinted, additionally prove the theorem.
CPSC 121 – 2016W T1
9
Module 7.1: Direct Proofs
CPSC 121 – 2016W T1
10
Module 7.1.1: Direct Proofs (existential)
Form 1: ∃x ∈ D, P(x)
Direct Proofs:
To prove this statement is true, we must
We start with some facts (premises, hypotheses)
They are known or assumed to be true.
Find a value of x (a “witness”) for which P(x) holds.
We move one step at a time towards the conclusion.
So the proof will look like this:
There are two general forms of statements:
Choose x = <some value in D>
Those that start with an existential quantifier.
Those that start with a universal quantifier.
Verify that the x we chose satisfies the predicate.
Example: there is a prime number x such that
3x+2 is not prime.
We use different techniques for them.
CPSC 121 – 2016W T1
More general term than in Epp.
11
CPSC 121 – 2016W T1
12
Module 7.1.1: Direct Proofs (existential)
How do we translate There is a prime number x
such that 3x+2 is not prime into predicate logic?
+
Module 7.1.1: Direct Proofs (existential)
So the proof goes as follows:
Proof:
x
a) ∀x ∈ Z , Prime(x) ∧ ~Prime(3 +2)
b) ∃x ∈ Z+, Prime(x) ∧ ~Prime(3x+2)
c) ∀x ∈ Z+, Prime(x) → ~Prime(3x+2)
d) ∃x ∈ Z+, Prime(x) → ~Prime(3x+2)
e) ∀x ∈ P, ~Prime(3x+2) where P is the set of all primes
Choose x =
It is prime because its only factors are 1 and
Now 3x+2 =
and
Hence 3x+2 is not prime.
QED.
▷
CPSC 121 – 2016W T1
13
Module 7: Proof Techniques (part 1)
CPSC 121 – 2016W T1
Module 7.1.2: Direct Proofs (universal)
Form 2: ∀x ∈ D, P(x)
Module Summary
Techniques for direct proofs.
To prove this statement is true, we must
Existential quantifiers.
Universal quantifiers.
Show that P(x) holds no matter how we choose x.
So the proof will look like this:
Dealing with multiple quantifiers.
Consider an unspecified element x of D
Indirect proofs: contrapositive and contradiction
Verify that the predicate P holds for this x.
Additional Examples
CPSC 121 – 2016W T1
15
Note: the only assumption we can make about x is
the fact that it belongs to D. So we can only use
properties common to all elements of D.
16
CPSC 121 – 2016W T1
17
Module 7.1.2: Direct Proofs (universal)
Module 7.1.2: Direct Proofs (universal)
Example: every non-anonymous Racket
function is at least 12 characters long.
Terminology: the following statements all mean
the same thing:
The proof goes as follows:
Consider an unspecified element x of D
Without loss of generality consider a valid element x
of D.
Proof:
Consider an unspecified Racket function f
This function
Suppose x is a particular but arbitrarily chosen
element of D.
Therefore f is at least 12 characters long.
QED
CPSC 121 – 2016W T1
18
Module 7.1.2: Direct Proofs (universal)
CPSC 121 – 2016W T1
19
Module 7.1.2: Direct Proofs (universal)
Another example:
Why is this theorem useful?
For every two positive integers x and y where x ≥ y,
gcd(x, y) = gcd(y, x mod y)
gcd(x, y) is the greatest common divisor of x and y.
x mod y is the remainder after you divide x by y. For
instance 17 mod 5 = 2.
Racket supports rational numbers.
It simplifies x/y by dividing x and y by gcd(x,y).
The theorem gives us a way to compute gcd(x,y) by
instead computing gcd(y, x mod y)
x mod y is smaller than y
so we move closer to a base case.
Let us write a mygcd() function in Dr. Racket.
CPSC 121 – 2016W T1
20
CPSC 121 – 2016W T1
21
Module 7.1.2: Direct Proofs (universal)
Module 7.1.2: Direct Proofs (universal)
How do we prove
Proof outline:
gcd(x, y) = gcd(y, x mod y)
Consider two unspecified positive integers x, y.
Assume x ≥ y without loss of generality.
?
The proof uses the following facts:
First we prove that gcd(x, y) ≤ gcd(y, x mod y):
a = b if (and only if) a ≤ b and b ≤ a.
...
we can write x as x = ay + (x mod y) where
Now we prove that gcd(y, x mod y) ≤ gcd(x, y):
a is the quotient (a non-negative integer)
x mod y is the remainder.
CPSC 121 – 2016W T1
...
Therefore gcd(x, y) = gcd(y, x mod y). QED
22
Module 7.1.2: Direct Proofs (universal)
CPSC 121 – 2016W T1
23
Module 7.1.2: Direct Proofs (universal)
Form 2*: ∀x ∈ D, P(x) → Q(x)
Why is the line Assume that P(x) is true valid?
This is a special case of form 2
The textbook calls this (and only this) a direct proof.
The proof looks like this:
a) Because these are the only cases where Q(x)
matters.
b) Because P(x) is preceded by a universal quantifier.
c) Because we know that P(x) is true.
Proof:
d) Both (a) and (c)
Consider an unspecified element x of D.
Assume that P(x) is true.
Use this and properties of the element of D to verify
that the predicate Q holds for this x.
e) Both (b) and (c)
▷
CPSC 121 – 2016W T1
24
CPSC 121 – 2016W T1
25
Module 7.1.2: Direct Proofs (universal)
Module 7.1.2: Direct Proofs (universal)
Example: prove that
Other interesting techniques for direct proofs ☺
∀n ∈ N, n ≥ 1024 → 10n ≤ nlog2 n
Proof by intimidation
Proof by lack of space (Fermat's favorite!)
Proof:
Consider an unspecified natural number n.
Proof by authority
Assume that n ≥ 1024.
Proof by never-ending revision
Then ...
For the full list, see:
http://school.maths.uwa.edu.au/~berwin/humour/invali
d.proofs.html
CPSC 121 – 2016W T1
27
CPSC 121 – 2016W T1
28
Module 7.2: Dealing with multiple
quantifiers
Module 7: Proof Techniques (part 1)
Module Summary
How do we deal with theorems that involve
multiple quantifiers?
Techniques for direct proofs.
Start the proof from the outermost quantifier.
Existential quantifiers.
Universal quantifiers.
Work our way inwards.
Dealing with multiple quantifiers.
Example 1:
Indirect proofs: contrapositive and contradiction
Every even integer can be expressed as the sum of
two odd integers whose difference is less than 7.
Additional Examples
Written using predicate logic:
CPSC 121 – 2016W T1
29
CPSC 121 – 2016W T1
30
Module 7.2: Dealing with multiple
quantifiers
Module 7.2: Dealing with multiple
quantifiers
The proof goes as follows:
Example 2:
Proof:
For every positive integer n, there is a prime p that
is larger than n.
Consider an unspecified positive even integer n
Choose x =
Choose y =
Written using predicate logic:
∀n ∈ Z+
∃x,y ∈ Z+ Now prove that x + y = n and that |y – x| < 7
CPSC 121 – 2016W T1
31
Module 7.2: Dealing with multiple
quantifiers
CPSC 121 – 2016W T1
Module 7.2: Dealing with multiple
quantifiers
The proof goes as follows:
Details (part 1)
Proof:
How do we choose p?
Consider an unspecified positive integer n
Choose p as follows:
First we compute x = n! + 1 (where n! = 1∙2∙3∙ ∙∙∙ ∙(n1)∙n).
By the fundamental theorem of arithmetic, x can be
written as a product of primes:
∀n ∈ Z+
∃p ∈ Z+
x = p1∙p2∙ ∙∙∙ pt
Now prove that p > n and that p is prime.
CPSC 121 – 2016W T1
32
33
We use any one of these as p (say p1).
The integer p is a prime by definition.
CPSC 121 – 2016W T1
34
Module 7.2: Dealing with multiple
quantifiers
Module 7.2: Dealing with multiple
quantifiers
Details (part 2).
Details (part 3).
Now we need to prove that p > n.
Now the proof:
Pick an unspecified integer 2 ≤ i ≤ n.
Observe that
x n ! +1 n ! 1
1
=
= + =1⋅2⋯(i−1)⋅(i +1)⋯n+
i
i
i i
i
Which of the following should we prove?
a) ∀i ∈ Z+, i ≤ n → i divides n!
b) ∃i ∈ Z+, i ≤ n ∧ i does not divide x
c) ∀i ∈ Z+, i ≤ p → i does not divide x
Since 1⋅2⋯(i −1)⋅(i +1)⋯n is an integer, but 1/i is not an
integer, this means that x/i is not an integer.
Hence i does not divide x.
d) ∀i ∈ Z+, (i > 1 ∧ i ≤ n) → i does not divide x
e) None of the above.
▷
CPSC 121 – 2016W T1
35
Module 7.2: Dealing with multiple
quantifiers
CPSC 121 – 2016W T1
37
Module 7.2: Dealing with multiple
quantifiers
Another example: every even square can be written
as the sum of two consecutive odd integers.
∀x ∈ Z , Even(x) ∧ Square(x) → SumOfTwoConsOdd(x)
+
How do we define:
The proof goes as follows:
Proof:
Consider an unspecified integer x
Assume that x is an even square.
Hint: for every positive integer n, if n2 is even, then n is
even.
Square(x):
SumOfTwoConsOdd(x):
Therefore x can be written as the sum of two
consecutive odd integers.
CPSC 121 – 2016W T1
38
CPSC 121 – 2016W T1
39
Module 7: Proof Techniques (part 1)
Module 7.3: Indirect Proofs
Consider the following theorem:
Module Summary
If the square of a positive integer n is even, then n
is even.
Techniques for direct proofs.
Existential quantifiers.
Universal quantifiers.
How can we prove this?
Dealing with multiple quantifiers.
Let's try a direct proof.
Indirect proofs: contrapositive and contradiction
Consider an unspecified integer n.
Assume that n2 is even.
So n2 = 2k for some (positive) integer k.
Hence n=√ 2k .
Then what?
Additional Examples
CPSC 121 – 2016W T1
40
CPSC 121 – 2016W T1
Module 7.3: Indirect Proofs
Module 7.3: Indirect Proofs
Consider instead the following theorem:
What is the relationship between
If a positive integer n is odd, then its square is odd.
We can prove this easily:
If the square of a positive integer n is even, then n
is even.
and
Consider an unspecified positive integer n.
If a positive integer n is odd, then its square is odd.
Assume that n is odd.
Hence n = 2k+1 for some integer k.
?
Then n2 = (2k+1)2 = 4k2 + 4k + 1 = 2(2k2+2k)+1
They are
Therefore n2 is odd.
and hence
CPSC 121 – 2016W T1
41
42
CPSC 121 – 2016W T1
43
Module 7.3: Indirect Proofs
Module 7.3: Indirect Proofs
We would normally write the proof of the
original theorem like this:
Another proof technique: proofs by contradiction.
To prove:
Proof: we will prove the contrapositive, that is, that
if a positive integer n is odd, then its square is odd.
Consider an unspecified positive integer n.
Premise 1
...
Premise n
...
 Conclusion
We assume Premise 1, ..., Premise n, ~Conclusion and then
derive a contradiction (p ^ ~p, x is odd ^ x is even, x < 5 ^ x >
10, etc).
CPSC 121 – 2016W T1
44
We then conclude that Conclusion is true.
CPSC 121 – 2016W T1
Module 7.3: Indirect Proofs
Module 7.3: Indirect Proofs
Why are proofs by contradiction a valid proof technique?
Why are proofs by contradiction a valid proof technique?
We proved
Otherwise
Premise 1 ^ ... ^ Premise n ^ ~Conclusion F
Premise 1 ^ ... ^ Premise n T
This is only true if
but
Premise 1 ^ ... ^ Premise n ^ ~Conclusion F
Premise 1 ^ ... ^ Premise n ^ ~Conclusion F
If
therefore
Premise 1 ^ ... ^ Premise n F
~Conclusion F which means that Conclusion T
then
and so
Premise 1 ^ ... ^ Premise n Conclusion
Premise 1 ^ ... ^ Premise n Conclusion
is true.
CPSC 121 – 2016W T1
45
is true.
46
CPSC 121 – 2016W T1
47
Module 7.3: Indirect Proofs
Module 7.3: Indirect Proofs
Example:
Example:
Not every CPSC 121 student got an above average grade
on midterm 1.
What are:
The premise(s)?
A group of CPSC 121 students show up in a room for a
tutorial. The TA is late, and so the students start talking to
each other. If every student has talked to at least one
other student, then two of the students talked to exactly
the same number of people.
What are
The negated conclusion?
the premise(s)?
the negated conclusion?
Let us prove this theorem together.
CPSC 121 – 2016W T1
Prove the theorem!
48
Module 7.3: Indirect Proofs
49
Module 7.3: Indirect Proofs
Another example:
How should you tackle a proof?
Try the simpler methods first:
Prove that for all real numbers x and y, if x is a rational
number, and y is an irrational number, then x+y is
irrational.
Witness proofs (if applicable).
Generalizing from the generic particular.
Indirect proof using the contrapositive.
Proof by contradiction.
What are
the premise(s)?
the negated conclusion?
If you don't know if the theorem is true:
Prove the theorem!
CPSC 121 – 2016W T1
CPSC 121 – 2016W T1
Alternate between trying to prove and disprove it.
Use a failed attempt at one to help with the other.
50
CPSC 121 – 2016W T1
51
Module 7.3: Indirect Proofs
Module 7: Proof Techniques (part 1)
How should you tackle a proof (continued)?
Module Summary
If you get stuck, try looking backwards from the
conclusion you want.
Techniques for direct proofs.
Existential quantifiers.
Universal quantifiers.
But don't forget the argument must eventually be
written from the premises to the conclusion (not the
other way around).
Dealing with multiple quantifiers.
Indirect proofs: contrapositive and contradiction
Try to derive all new facts you can derive from the
premises without worrying about whether or not they
will help.
Additional Examples
If you are really stuck, ask for help!
CPSC 121 – 2016W T1
52
CPSC 121 – 2016W T1
Module 7.4: Additional examples
Module 7.4: Additional examples
Additional theorems you might wish to prove:
Additional theorems you might wish to prove:
Prove that if a, b and c are integers, and a2+b2=c2,
then at least one of a and b is even. Hint: use a
proof by contradiction, and show that 4 divides both
c2 and c2-2.
Prove that for every positive integer x, either √ x is
an integer, or it is irrational.
Prove that any circuit consisting of NOT, OR, AND
and XOR gates can be implemented using only
NOR gates.
CPSC 121 – 2016W T1
53
Prove that there is a positive integer c such that
x + y ≤ c ∙ max{ x, y } for every pair of positive
integers x and y.
54
CPSC 121 – 2016W T1
55