<<

Today’s topics Terminology

• Proof techniques • – Indirect, by cases, and direct – Rules of logical – A that has been proven to be true. – Correct & fallacious proofs • , postulates, hypotheses, – Assumptions (often unproven) defining the • Reading: Section 1.5 structures about which we are reasoning. • Upcoming – Sets and Functions • Rules of inference – Patterns of logically valid deductions from hypotheses to conclusions.

CompSci 102 © Michael Frank CompSci 102 © Michael Frank 4.1 4.2

More Proof Terminology Inference Rules - General Form

• Lemma - A minor theorem used as a stepping- • An Inference Rule is stone to proving a major theorem. – A pattern establishing that if we know that a • Corollary - A minor theorem proved as an easy of antecedent statements of certain forms consequence of a major theorem. are all true, then we can validly deduce that a • - A statement whose value has certain related consequent statement is true. not been proven. (A conjecture may be widely believed to be true, regardless.) • antecedent 1 • – The set of all that can be antecedent 2 … proven from a given set of axioms. ! consequent “!” means “therefore”

CompSci 102 © Michael Frank CompSci 102 © Michael Frank 4.3 4.4 Inference Rules & Implications Some Inference Rules

• Each valid logical inference rule • p Rule of Addition corresponds to an implication that is a ! p$q . • p"q Rule of Simplification • antecedent 1 Inference rule • antecedent 1 Inference rule ! p antecedent 2 … ! consequent • p Rule of Conjunction • Corresponding tautology: q p q ((ante. 1) " (ante. 2) " …) # consequent ! p"q

CompSci 102 © Michael Frank CompSci 102 © Michael Frank 4.5 4.6

Modus Ponens & Tollens Inference Rules

“the mode of • p Rule of affirming” • p#q Rule of hypothetical p#q (a.k.a. of detachment) q#r syllogism !q !p#r • ¬q • p $ q Rule of disjunctive p#q Rule of ¬p syllogism !¬p “the mode of denying” ! q

Aristotle

CompSci 102 © Michael Frank CompSci 102 © Michael Frank (ca. 384-322 B.C.) 4.7 4.8 Formal Proofs Example

• A formal proof of a conclusion C, given • Suppose we have the following premises: “It is not sunny and it is cold.” premises p1, p2,…,pn consists of a “We will swim only if it is sunny.” of steps, each of which applies some “If we do not swim, then we will canoe.” inference rule to premises or previously- “If we canoe, then we will be home early.” proven statements (antecedents) to yield a • Given these premises, prove the theorem “We will be home early” using inference rules. new true statement (the consequent). • A proof demonstrates that if the premises are true, then the conclusion is true.

CompSci 102 © Michael Frank CompSci 102 © Michael Frank 4.9 4.10

Inference Rules for Quantifiers Common Fallacies

• %x P(x) • A fallacy is an inference rule or other proof !P(o) (substitute any specific object o) method that is not logically valid. • P(g) (for g a general of u.d.) – A fallacy may yield a conclusion! !%x P(x) • Fallacy of affirming the conclusion: • &x P(x) – “p#q is true, and q is true, so p must be true.” !P(c) (substitute a new constant c) (No, because F#T is true.) • P(o) (substitute any extant object o) • Fallacy of denying the : x P(x) !& – “p#q is true, and p is false, so q must be false.” (No, again because F#T is true.) CompSci 102 © Michael Frank CompSci 102 © Michael Frank 4.11 4.12 Circular Reasoning A Correct Proof

• The fallacy of (explicitly or implicitly) assuming the very We know that n must be either odd or even. statement you are trying to prove in the course of its 2 proof. Example: If n were odd, then n would be odd, since an • Prove that an n is even, if n2 is even. odd number times an odd number is always 2 • Attempted proof: “Assume n2 is even. Then n2=2k for an odd number. Since n is even, it is not some integer k. Dividing both sides by n gives n = (2k)/n odd, since no even number is also an odd = 2(k/n). So there is an integer j (namely k/n) such that number. Thus, by modus tollens, n is not odd n=2j. Therefore n is even.” number. Thus, by modus tollens, n is not odd – Circular reasoning is used in this proof. Where? either. Thus, by , n must be even. !

CompSci 102 © Michael Frank CompSci 102 © Michael Frank 4.13 4.14

A More Verbose Version Proof Methods for Implications

Uses some we haven’t defined yet. Suppose n2 is even !2||n2 ! n2 mod 2 = 0. Of course n mod For proving implications p#q, we have: 2 is either 0 or 1. If it’s 1, then n'1 (mod 2), so n2'1 (mod 2), using the theorem that if a'b (mod m) and c'd (mod m) • : Assume p is true, and prove q. 2 then ac'bd (mod m), with a=c=n and b=d=1. Now n '1 • Indirect proof: Assume ¬q, and prove ¬p. (mod 2) implies that n2 mod 2 = 1. So by the rule, (n mod 2 = 1) implies (n2 mod 2 = 1). Since • Vacuous proof: Prove ¬p by itself. we know n2 mod 2 = 0 ( 1, by modus tollens we know that n mod 2 ( 1. So by disjunctive syllogism we have that n mod • Trivial proof: Prove q by itself. 2 = 0 !2|n ! n is even. • Proof by cases: Show p#(a $ b), and (a#q) and (b#q).

CompSci 102 © Michael Frank CompSci 102 © Michael Frank 4.15 4.16 Direct Proof Example Indirect Proof Example

: An integer n is called odd iff n=2k+1 • Theorem: (For all n) for some integer k; n is even iff n=2k for some k. If 3n+2 is odd, then n is odd. • Theorem: Every integer is either odd or even. • Proof: Suppose that the conclusion is false, i.e., that n is – This can be proven from even simpler axioms. even. Then n=2k for some integer k. Then 3n+2 = • Theorem: (For all numbers n) If n is an odd 3(2k)+2 = 6k+2 = 2(3k+1). Thus 3n+2 is even, because it integer, then n2 is an odd integer. equals 2j for integer j = 3k+1. So 3n+2 is not odd. We • Proof: If n is odd, then n = 2k+1 for some have shown that ¬(n is odd)"¬(3n+2 is odd), thus its integer k. Thus, n2 = (2k+1)2 = 4k2 + 4k + 1 = contra-positive (3n+2 is odd) " (n is odd) is also true. # 2(2k2 + 2k) + 1. Therefore n2 is of the form 2j + 1 (with j the integer 2k2 + 2k), thus n2 is odd. #

CompSci 102 © Michael Frank CompSci 102 © Michael Frank 4.17 4.18

Vacuous Proof Example Trivial Proof Example

• Theorem: (For all n) If n is both odd and • Theorem: (For integers n) If n is the sum even, then n2 = n + n. of two prime numbers, then either n is odd • Proof: The statement “n is both odd and or n is even. even” is necessarily false, since no number • Proof: Any integer n is either odd or even. can be both odd and even. So, the theorem So the conclusion of the implication is true is vacuously true. # regardless of the truth of the antecedent. Thus the implication is true trivially. #

CompSci 102 © Michael Frank CompSci 102 © Michael Frank 4.19 4.20 Proof by Example

• A method for proving p. 2 • Theorem: 2 is irrational. 1/2 • Assume ¬p, and prove both q and ¬q for – Proof: Assume 2 were rational. This means there are integers i,j with no common divisors some q. (Can be anything!) such that 21/2 = i/j. Squaring both sides, 2 = • Thus ¬p# (q " ¬q) i2/j2, so 2j2 = i2. So i2 is even; thus i is even. Let i=2k. So 2j2 = (2k)2 = 4k2. Dividing both • (q " ¬q) is a trivial contradiction, equal to F sides by 2, j2 = 2k2. Thus j2 is even, so j is • Thus ¬p#F, which is only true if ¬p=F even. But then i and j have a common divisor, namely 2, so we have a contradiction. # • Thus p is true.

CompSci 102 © Michael Frank CompSci 102 © Michael Frank 4.21 4.22

Review: Proof Methods So Far Proving Existentials

• Direct, indirect, vacuous, and trivial proofs • A proof of a statement of the form &x P(x) of statements of the form p#q. is called an existence proof. • Proof by contradiction of any statements. • If the proof demonstrates how to actually find or construct a specific element a such • Next: Constructive and nonconstructive that P(a) is true, then it is a constructive existence proofs. proof. • Otherwise, it is nonconstructive.

CompSci 102 © Michael Frank CompSci 102 © Michael Frank 4.23 4.24 Another Constructive Constructive Existence Proof Existence Proof

• Theorem: There exists a positive integer n • Theorem: For any integer n>0, there that is the sum of two perfect cubes in two exists a sequence of n consecutive different ways: composite integers. – equal to j3 + k3 and l3 + m3 where j, k, l, m are • Same statement in predicate : positive integers, and {j,k} $ {l,m} %n>0 &x %i (1)i)n)#(x+i is composite) • Proof: Consider n = 1729, j = 9, k = 10, • Proof ? l = 1, m = 12. Now just check that the equalities hold.

CompSci 102 © Michael Frank CompSci 102 © Michael Frank 4.25 4.26

The proof... Nonconstructive Existence Proof

• Given n>0, let x = (n + 1)! + 1. • Theorem: “There are infinitely many prime numbers.” • Let i * 1 and i ) n, and consider x+i. • Any of numbers must contain a maximal • Note x+i = (n + 1)! + (i + 1). element, so we can prove the theorem if we can just show that there is no largest . • Note (i+1)|(n+1)!, since 2 ) i+1 ) n+1. • I.e., show that for any prime number, there is a larger • Also (i+1)|(i+1). So, (i+1)|(x+i). number that is also prime. • More generally: For any number, & a larger prime. • ! x+i is composite. • Formally: Show %n &p>n : p is prime. • ! %n &x %1)i)n : x+i is composite. Q.E.D.

CompSci 102 © Michael Frank CompSci 102 © Michael Frank 4.27 4.28 The proof, using proof by cases... The Halting Problem (Turing‘36)

• The halting problem was the first • Given n>0, prove there is a prime p>n. mathematical proven to • Consider x = n!+1. Since x>1, we know have no algorithm that computes it! • Consider x = n!+1. Since x>1, we know – We say, it is uncomputable. (x is prime)$(x is composite). • The desired function is Halts(P,I) :% the of this statement: • Case 1: x is prime. Obviously x>n, so let – “Program P, given input I, eventually terminates.” • Theorem: Halts is uncomputable! Alan Turing p=x and we’re done. 1912-1954 – I.e., There does not exist any algorithm A that • Case 2: x has a prime factor p. But if p)n, computes Halts correctly for all possible inputs. • Its proof is thus a non-existence proof. then p mod x = 1. So p>n, and we’re done. • Corollary: General impossibility of predictive analysis of arbitrary computer programs.

CompSci 102 © Michael Frank CompSci 102 © Michael Frank 4.29 4.30

The halting problem: writing doesHalt Consider the Confuse.java

public class ProgramUtils public static void main(String[] args){ /** String prog = "Foo.java"; * Returns true if progname halts on input, * otherwise returns false (progname loops) if (ProgramUtils.doesHalt(prog,prog)) { */ while (true) { public static boolean doesHalt(String progname, // do nothing forever String input){ } } } } ! A compiler is a program that reads other programs as input } ! Can a word counting program count its own words? ! We want to show writing doesHalt is impossible ! The doesHalt method might simulate, analyze, … ! Proof by contradiction: ! One program/function that works for any program/input ! Assume possible, show impossible situation results

CompSci 102 3.31 CompSci 102 3.32 Limits on Proofs More Proof Examples

• Some very simple statements of number • Quiz question 1a: Is this correct or incorrect? – “All TAs compose easy quizzes. Seda is a TA. Therefore, Seda theory haven’t been proved or disproved! composes easy quizzes.” – E.g. Goldbach’s conjecture: Every integer n&2 • First, separate the premises from conclusions: is exactly the average of some two primes. – #1: All TAs compose easy quizzes. – Premise #2: Seda is a TA. – %n!2 & primes p,q: n=(p+q)/2. – Conclusion: Seda composes easy quizzes. • There are true statements of number theory (or any sufficiently powerful system) that can never be proved (or disproved) (Gödel).

CompSci 102 © Michael Frank CompSci 102 © Michael Frank 4.33 4.34

Another example Another Example

• Quiz question 2b: Correct or incorrect: At least one of the • Quiz question #2: Prove that the sum of a rational number 9 students in the class is intelligent. Y is a student of this and an irrational number is always irrational. class. Therefore, Y is intelligent. • First, you have to understand exactly what the question is • First: Separate premises/conclusion, asking you to prove: & translate to logic: – “For all real numbers x,y, if x is rational and y is irrational, then – Premises: (1) &x InClass(x) " Intelligent(x) x+y is irrational.” (2) InClass(Y) – %x,y: Rational(x) " Irrational(y) " Irrational(x+y) – Conclusion: Intelligent(Y)

CompSci 102 © Michael Frank CompSci 102 © Michael Frank 4.35 4.36