Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS2420: Lecture 2 Vladimir Kulyukin Computer Science Department Utah State University.

Similar presentations


Presentation on theme: "CS2420: Lecture 2 Vladimir Kulyukin Computer Science Department Utah State University."— Presentation transcript:

1 CS2420: Lecture 2 Vladimir Kulyukin Computer Science Department Utah State University

2 Outline Useful Proof Techniques (Sections 1.2.5, 1.3)

3 Useful Proof Techniques Direct proof Proof by contradiction Proof by counterexample Proof by induction

4 Direct Proof Need to Show: If P, then Q. (P  Q). Assume that P is true and use the axioms, definitions, and previous theorems to show that Q is true.

5 Direct Proof: Example

6 Proof By Contradiction Need to show: If P, then Q. Assume that P is true and Q is false and find a contradiction, i.e., a statement that contradicts another true statement. A contradiction is typically the negation of a statement that is known or assumed to be true. Remember that what is assumed to be true (P) remains true throughout the proof.

7 Proof By Contradiction: Example 1 You have three classes: P, Q, and R in a software module M. P is loaded automatically. Q must be loaded manually or kept out. You know that R is loaded either by P or by Q but not by both. P must be loaded and R must be loaded for M to run. You need to decide whether to load Q.

8 Proof By Contradiction: Example 1 Consider the following scenario: –Q is kept out. –P is loaded. –M does not run. Since M does not run, R must have failed to load. The last statement is a contradiction because R must be loaded.

9 Proof By Contradiction: Example 1 To what do we attribute the failure? To the decision to keep Q out. Thus, if M does not run, Q must be loaded.

10 Proof By Contradiction: Example 2

11 Proof By Contradiction: Example 3

12 Proof By Contradiction: Example 4

13 Proof By Counterexample Given a statement P, produce an example that contradicts P. Show that All numbers are even. Counterexample: Any odd number.

14 Proof By Induction: Example 5 We place a set of blocks numbered 1, 2, …, N on the table. We want to be convinced that if we knock the first block down, then all blocks will fall.

15 The Structure of the Inductive Proof Base Case: We need to show that the first domino will be knocked down. Induction: We need to show that if one domino falls (Inductive Hypothesis), the next one will fall two. If we can show the base case and induction, we will be convinced that all dominos will fall.

16 Why Does This Code Work? long fact(long n) { if ( n == 0 ) return 1; else return n * fact (n – 1); }

17 Why Does This Code Work? We can use induction to convince ourselves that it works without running it. We show that the base case, which is f(0), is directly computable. We then argue that if we can compute f(n), we can compute f(n+1).


Download ppt "CS2420: Lecture 2 Vladimir Kulyukin Computer Science Department Utah State University."

Similar presentations


Ads by Google