cpsc 121: models of computation - ugrad.cs.ubc.ca · apply proof by exhaustion? a) ... strategie...

47
CPSC 121 – 2010W T2 CPSC 121: Models of Computation Unit 7: Proof Techniques (part 1)

Upload: trankhue

Post on 26-May-2018

213 views

Category:

Documents


0 download

TRANSCRIPT

CPSC 121 – 2010W T2

CPSC 121: Models of Computation

Unit 7: Proof Techniques (part 1)

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

Assignment #3 due Monday February 28th at 17:00.

Assignment #4 will be available Wednesday or Thursday, due Wednesday March 9 th at 17:00

Online quiz #8 due Tuesday March 1st at 21:00

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

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

By the start of class, you should be able to, for each proof strategy below:

Identify the form of statement the strategy can prove.

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)

indirect proofs by contrapositive and contradiction

proof by cases.

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

Quiz 7 feedback:

Several of the questions caused problems.Most notable the four questions on choosing a proof strategy.

The four proof strategy questions had their weights reduced from 10 to 3.

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

Consider the statement x ∀ ∈ D, P(x) → Q(x). For which of the following D, P() and Q() can you apply proof by exhaustion?

a) D = Z+, P(x) is true if and only if x ≥ 10 and x ≤ 30.

b) D = R+, P(x) is true if and only if x ≥ 10 and x ≤ 30.

c) D is the set of all the rooms in the ICICS building, P(x) is “x has a window”. Q(x) is “x has a whiteboard.”

d) D is the set of all possible statements, P(x) is “the statement x is true”, Q(x) is “x is not found in this quiz.”

e) D is the set of all prime numbers, P(x) is true if and only if (x - 2) is a multiple of 3, Q(x) is true if and only if x ≥ 30.

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

Which of the following statements can be proved using a constructive proof of existence?

a) There exists a false statement.

b) ∀x Z, ~(x > 0 ∈ → x < 0)

c) ~ x Z, x > 0 ∀ ∈ → x < 0

d) There does not exist an even integer which is the sum of three primes.

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

Which of the following proof techniques could be a plausible first step in proving that:

Every subtree contains at least one node with a value larger than the value in the parent node.

a) Constructive or non-constructive proofs of existence

b) Exhaustive proof of universals

c) Generalizing from the generic particular

d) Direct proof

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

Which of the following proof techniques could be a plausible first step in proving that:

One of the cards in the middle three rows is the one the user selected at the start of the trick.

a) Constructive or non-constructive proofs of existence

b) Exhaustive proof of universals

c) Generalizing from the generic particular

d) Direct proof

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

Which of the following proof techniques could be a plausible first step in proving that:

∃c R∈ +, n∃0 Z∈ +, n Z∀ ∈ +, n > n

0 → T(n) > c·2n.

a) Constructive or non-constructive proofs of existence

b) Exhaustive proof of universals

c) Generalizing from the generic particular

d) Direct proof

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

Which of the following proof techniques could be a plausible first step in proving that:

All binary trees (of the infinite number of possible trees) have a height that is bounded below by the log of their size.

a) Constructive or non-constructive proofs of existence

b) Exhaustive proof of universals

c) Generalizing from the generic particular

d) Direct proof

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

Open-ended question: when should you switch strategies?

When you are stuck.

When the proof is going around in circles.

The proof is getting too messy.

It is taking too long.

Through experience (how do you get that?)

Mo

nito

r yo

urs

elf

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

Where are we?How do we model computational systems?

Now: learning how put everything we've learned so far together to prove new theorems.

How do we build devices to compute?

Now: nothing really new, but we can now apply these techniques to statements about the computations these devices can perform.

Th

eo

ryH

ard

wa

re

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

By the end of this unit, you should be able to:Devise and attempt multiple different, appropriate proof strategie for a given theorem, including

all those listed in the "pre-class" learning goals

logical equivalences,

rules of inference,

universal modus ponens/tollens,

For theorems requiring only simple insights beyond strategic choices or for which the insight is given/hinted, additionally prove the theorem.

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

Unit Summary

Techniques for direct proofs.Existential quantifiers.

Universal quantifiers.

Dealing with multiple quantifiers.

Indirect proofs: contrapositive and contradiction

Additional Examples

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

Direct Proofs (antecedent assumption)

Assume the premises hold.

Move 1 step at a time towards the conclusion.

There are two general forms of statements:

Those that start with an existential quantifier.Those that start with a universal quantifier.

We use different techniques for them.

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

Form 1: x D, P(x)∃ ∈

To prove this statement is true, we must

Find a value of x (a “witness”) for which P(x) holds.

So the proof will look like this:

Choose x = <some value in D>

Verify that the x we chose satisfies the predicate.

Example: there is a prime number x such that 3x+2 is not prime.

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

How do we translate There is a prime number x such that 3x+2 is not prime into predicate logic?

a) ∀x Z∈ +, Prime(x) ~Prime(3∧ x+2)

b) ∃x Z∈ +, Prime(x) ~Prime(3∧ x+2)

c) ∀x Z∈ +, Prime(x) → ~Prime(3x+2)

d) ∃x Z∈ +, Prime(x) → ~Prime(3x+2)

e) ∀x P, ~Prime(3∈ x+2) where P is the set of all primes

f) Two of the above.

g) None of the above.

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

So the proof goes as follows:

Proof: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 – 2010W T2

Unit 7: Proof Techniques (part 1)

Unit Summary

Techniques for direct proofs.Existential quantifiers.

Universal quantifiers.

Dealing with multiple quantifiers.

Indirect proofs: contrapositive and contradiction

Additional Examples

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

Form 2: x D, P(x)∀ ∈

To prove this statement is true, we must

Show that P(x) holds no matter how we choose x.

So the proof will look like this:

Consider an unspecified element x of D

Verify that the predicate P holds for this x.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.

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

Example: every Scheme/Racket function is at least 12 characters long.

The proof goes as follows:

Proof:Consider an unspecified Scheme/Racket function f

This function

Therefore f is at least 12 characters long.

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

Terminology: the following statements all mean the same thing:

Consider an unspecified element x of D

Without loss of generality consider a valid element x of D.

Suppose x is a particular but arbitrarily chosen element of D.

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

Form 2*: x D, P(x) → Q(x)∀ ∈

This is a special case of form 2

The textbook calls this (and only this) a direct proof.

The proof looks like this:Proof:

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.

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

Why is the line Assume that P(x) is true valid?

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.

d) Both (a) and (c)

e) Both (b) and (c)

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

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:

Square(x):

SumOfTwoConsOdd(x):

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

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.

Therefore x can be written as the sum of two consecutive odd integers.

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

Other interesting techniques for direct proofs ☺

Proof by intimidation

Proof by lack of space

Proof by astonishment

Proof by never-ending revision

For the full list, see:

http://school.maths.uwa.edu.au/~berwin/humour/invalid.proofs.html

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

Unit Summary

Techniques for direct proofs.Existential quantifiers.

Universal quantifiers.

Dealing with multiple quantifiers.

Indirect proofs: contrapositive and contradiction

Additional Examples

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

How do we deal with theorems that involve multiple quantifiers?

Start the proof from the outermost quantifier.

Work our way inwards.

Example:

for every positive integer n, there is a prime p that is larger than n.

Written using predicate logic:

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

The proof goes as follows:

Proof:Consider an unspecified positive integer n

Choose p as follows:

Now prove that p > n and that p is prime.

∀n Z∈ +∀n Z∈ +

∃p Z∈ +∃p Z∈ +

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

Details (part 1)

How do we choose p?First we compute x = n! + 1 (where n! = 1·2·3· ··· ·(n-1)·n).

By the fundamental theorem of arithmetic, x can be written as a product of primes:

x = p1·p

2· ··· p

t

We use any one of these as p (say p1).

The integer p is a prime by definition.

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

Details (part 2).Now we need to prove that p > n.

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

d) ∀i Z∈ +, i ≤ n → i does not divide x

e) None of the above.

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

Details (part 3).Now the proof:

Pick an unspecified integer 2 ≤ i ≤ n.

Observe that

Since 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.

xi=n !1i

=n!i

1i=1⋅2⋯i−1⋅i1⋯n

1i

1⋅2⋯i−1⋅i1⋯n

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

Unit Summary

Techniques for direct proofs.Existential quantifiers.

Universal quantifiers.

Dealing with multiple quantifiers.

Indirect proofs: contrapositive and contradiction

Additional Examples

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

Consider the following theorem:

If the square of a positive integer n is even, then n is even.

How can we prove this?

Let's try a direct proof.Consider an unspecified integer n.

Assume that n2 is even.

So n2 = 2k for some (positive) integer k.

Hence .

Then what?

n=2k

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

Consider instead the following theorem:

If a positive integer n is odd, then its square is odd.

We can prove this easily:

Consider an unspecified positive integer n.

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

Therefore n2 is odd.

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

What is the relationship between

If the square of a positive integer n is even, then n is even.

and

If a positive integer n is odd, then its square is odd.

?

They are

and hence

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

Another proof technique: proofs by contradiction.

To prove: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).

We then conclude that Conclusion is true.

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

Why are proofs by contradiction a valid proof technique?

We proved

Premise 1 ^ ... ^ Premise n ^ ~Conclusion → F

This is only true if

Premise 1 ^ ... ^ Premise n ^ ~Conclusion F

If

Premise 1 ^ ... ^ Premise n F

then

Premise 1 ^ ... ^ Premise n → Conclusion

is true.

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

Why are proofs by contradiction a valid proof technique?

Otherwise

Premise 1 ^ ... ^ Premise n T

but

Premise 1 ^ ... ^ Premise n ^ ~Conclusion F

therefore

~Conclusion F which means that Conclusion T

and so

Premise 1 ^ ... ^ Premise n → Conclusion

is true.

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

Example:

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. Prove that 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 premise(s)?

the negated conclusion?

Prove the theorem!

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

Another example:

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.

What are

the premise(s)?

the negated conclusion?

Prove the theorem!

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

How should you tackle a proof?

Try the simpler methods first:

Witness proofs (if applicable).

Generalizing from the generic particular.

Indirect proof using the contrapositive.

Proof by contradiction.

If you don't know if the theorem is true:

Alternate between trying to prove and disprove it.

Use a failed attempt at one to help with the other.

CPSC 121 – 2010W T2

How should you tackle a proof?

How should you tackle a proof (continued)?

If you get stuck, try looking backwards from the conclusion you want.

But don't forget the argument must eventually be written from the premises to the conclusion (not the other way around).

Try to derive all new facts you can derive from the premises without worrying about whether or not they will help.

If you are really stuck, ask for help!

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

Unit Summary

Techniques for direct proofs.Existential quantifiers.

Universal quantifiers.

Dealing with multiple quantifiers.

Indirect proofs: contrapositive and contradiction

Additional Examples

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

Additional theorems you might wish to prove:

For any two non-negative integers a, b, if a = bq + r (where q are r are also non-negative integers) then gcd(a,b) = gcd(b,r).

Hint: show gcd(a,b) ≤ gcd(b,r) and gcd(a,b) ≥ gcd(b,r).

Prove that for every positive integer x, either 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.

x

CPSC 121 – 2010W T2

Unit 7: Proof Techniques (part 1)

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 there is a positive integer c such that x + y ≤ c · max{ x, y } for every pair of positive integers x and y.