Volume P1 · Proof, induction and invariants
Methods of proof
Draft. This chapter is written and checked by the tools of the project, and a person has not reviewed it yet. Read it with care.
Read first
Direct proof
Statement
A direct proof starts from the assumptions and reaches the claim by steps. This section gives the form of a direct proof for each shape of a statement, and applies the forms to the first facts about integers.
The proofs in this chapter use the integers with addition, subtraction and multiplication. The facts that the sum, the difference and the product of integers are integers, and the usual laws of the arithmetic, are taken as known.
Definition P1.3.1 (even, odd, divides). An integer is even if for some integer , and odd if for some integer . An integer divides an integer , written , if for some integer . Then is a multiple of .
Lean: Even n is ∃ r, n = r + r, Odd n is ∃ m, n = 2 * m + 1, and a ∣ b is ∃ c, b = a * c (Mathlib).
Example P1.3.2. The integer is even, and is odd. Also is even. The number since , and .
Example P1.3.3. Every integer divides , since . The integer divides only , since . So the sentence "" has a meaning for , and "" does not.
The forms of a direct proof. The shape of the statement decides the first line of the proof.
- To prove : write "let be arbitrary" and prove . The letter must not have a value that was chosen earlier.
- To prove : give an element of and prove .
- To prove : write "suppose " and prove .
- To prove : prove and .
- To prove : prove and prove .
- To prove : prove (or ), or split into cases and in each case prove one of the two.
- To use : choose any element and conclude .
- To use : write "let be such that " and continue with a new letter .
- To use : prove the claim in the case and in the case .
Lean: the forms are the tactics intro (forms 1 and 3), use or exact ⟨a, h⟩ (form 2), constructor (forms 4 and 5), left and right (form 6), obtain ⟨a, h⟩ := h (form 8) and rcases h with h | h (form 9).
Example P1.3.4. Claim: for all integers , if is even then is even. Following the forms: let be an arbitrary integer (form 1). Suppose is even (form 3). By the definition, for an integer (form 8). Then , and is an integer, so is even.
Example P1.3.5. Claim: there is an integer with and . Form 2 asks for an element. Try : and . So works. For the other solution of the equation, , the condition fails.
Theorem P1.3.6 (parity). For integers and :
- if and are even, then and are even;
- if is even and is odd, then is odd and is even;
- if and are odd, then is even and is odd.
Lean: Even.add, Even.mul_right, Odd.add_odd and Odd.mul (Mathlib).
Proof. Let or and or , as the case needs. Rule 1: and . Rule 2: let and . Then and . Rule 3: let and . Then and . In each case the number in brackets is an integer.
Example P1.3.7. For and rule 2 gives and . For and rule 3 gives and .
Example P1.3.8. The theorem proves that the sum of two numbers has the same parity as the difference, since and has the same parity as . Also is odd if and only if exactly one of and is odd. This is the exclusive or of Chapter 1.
Theorem P1.3.9 (properties of division). For integers , , :
- if and , then ;
- if and , then for all integers and ;
- if and , then .
Lean: dvd_trans (rule 1), dvd_add and Dvd.dvd.mul_right (rule 2), and Int.le_of_dvd for natural-number versions (Mathlib).
Proof. Rule 1: let and . Then . Rule 2: let and . Then . Rule 3: let . As , , so and .
Example P1.3.10. Since and , rule 1 gives . Since and , rule 2 gives , and indeed .
Example P1.3.11. Rule 2 is the basis of Euclid's algorithm. If divides and and , then . So the divisors of and divide too. Chapter 5 completes the argument.
Proof by cases. To prove from a proof treats the case and the case apart. The cases must cover all possibilities. They need not be disjoint.
Theorem P1.3.12 (the triangle inequality). For real numbers and , .
Lean: Mathlib has the statement as abs_add in older versions and as abs_add_le in newer ones.
Proof. Recall that for and for , and that for all . Add the two inequalities for and for : . For the value is , and the right inequality is the claim. For the value is , and the left inequality gives .
Example P1.3.13. For and : . For and the two sides are equal, .
Example P1.3.14. The proof by cases can also settle a statement about an integer. For all , is even: if is even, then and are even and the sum is even by rule 1. If is odd, then is odd by rule 3 of the parity theorem, so is the sum of two odd numbers and is even. For the values of are .
Proof
The forms of a direct proof come from the meaning of the quantifiers and the connectives of Chapter 1. They are not tricks, and a proof that uses them does not need a clever idea at its first step. A reader who does not know how to start should write the statement in logical form, as in Chapter 1, and then write the first line that the form asks for.
Notice what the proof of " even implies even" does not do. It does not choose a value for . If a proof of a universal statement says "take " and checks the claim for , it has proved a case, not the statement. Section 3 returns to this error.
Examples
Example P1.3.15 (a chain of divisors). Prove that if and , then . By rule 2 of the division theorem, . By rule 3, , and since . So or .
Example P1.3.16 (the square mod 4). For every integer , or for some . If , then . If , then . A computer check of shows only the remainders and of modulo , and the proof says that no other remainder can occur.
Example P1.3.17 (an inequality). For real and , . The difference of the two sides is , which is not negative, since a square of a real number is not negative. For and the two sides are and . The same step, with and for , gives .
Exercises
- [10] Prove that the sum of an odd integer and an even integer is odd.
- [12] Prove that if and , then and .
- [15] Prove that is even for every integer , by cases on the parity of .
- [15] Prove that for real and , by cases on and .
- [M18] Prove that is or , and use it to show that no integer sum has the form . Show that is not a sum of two squares.
- [M20] Prove that the product of three consecutive integers is divisible by .
- [M20] Prove that for all reals, and that for .
- [M22] Prove that if and are positive integers with and , then .
- [M22] Show that the statement "for all , is prime" has its first failure at . Why does this not contradict the proof method of this section?
- [M25] Prove that is divisible by for every integer , by cases on , and use the product of three consecutive integers to show that it is divisible by .
Lean
A proof of a universal implication is a function: theorem even_sq (n : ℤ) (h : Even n) : Even (n ^ 2) is proved by obtain ⟨k, hk⟩ := h and exact ⟨2 * k ^ 2, by subst hk; ring⟩, which has the lines of the first example of this section. Mathlib has Int.even_or_odd for the case split on the parity, and Int.emod_emod_of_dvd for remainders. A claim about a bounded range, such as the table of for , is checked by decide on Fin 8 or on Finset.range 8. The tactic omega proves linear claims about integers, such as .
Notes and history
The ancient Greek mathematicians gave the first proofs in the style of this section, and the Elements of Euclid, around 300 BCE, uses the forms of direct proof and of proof by contradiction throughout. The prime-producing polynomial of Exercise 9 is a shift of a polynomial of Euler from 1772.
TAOCP Section 1.1 argues that Algorithm E stops with the greatest common divisor, and the argument rests on the rule that a common divisor of and divides (rule 2 of the theorem on division). Section 1.2.1 proves its first claims by induction, and each claim has the shape "for all " of form 1 of this section.
Indirect proof
Statement
Some statements are hard to prove from their hypotheses and easy to prove from their denial. This section gives the two methods that use this fact, the proof by contrapositive and the proof by contradiction, and the methods for statements of uniqueness and for existence statements that give no example.
Definition P1.3.18 (the contrapositive method). To prove , prove : suppose is false and show that is false. The two implications are equivalent (Chapter 1, Section 1).
Lean: not_imp_not and the tactic contrapose! (Mathlib).
Example P1.3.19. Claim: for an integer , if is even then is even. A direct proof has no start: the hypothesis does not give at once. The contrapositive says: if is odd, then is odd. This is rule 3 of the parity theorem, since is a product of two odd numbers.
Example P1.3.20. Claim: for an integer , if is even then is even. The contrapositive says that if is odd then is odd. Let . Then , which is odd.
Definition P1.3.21 (the method of contradiction). To prove a statement , suppose and derive a contradiction, that is, a statement and its denial. The rule is: if is true for some statement , then is true. To prove by contradiction, suppose and together and derive a contradiction.
Lean: by_contra h and absurd; the rule is by_contradiction or Classical.byContradiction (Lean core and Mathlib).
Example P1.3.22. Claim: there is no integer with . Suppose . Then is even, so is even by the first example, and gives , so . But is even and is odd. This is a contradiction.
Example P1.3.23. Claim: the sum of a rational number and an irrational number is irrational. Let be rational and be irrational, and suppose is rational. Then is the difference of two rational numbers, so it is rational. This contradicts the choice of .
Definition P1.3.24 (rational, irrational). A real number is rational if it equals for integers and with . A real number that is not rational is irrational.
Lean: Rat and the predicate Irrational (Mathlib); irrational_sqrt_two states that is irrational.
Example P1.3.25. The numbers and and are rational. The number is rational too. The number is irrational, and the next theorem proves it.
Example P1.3.26. The sum and the product of two rational numbers are rational, since and , with . Each rational number can be written in lowest terms, with and having no common factor larger than , by dividing out a common factor.
Theorem P1.3.27 (irrationality of ). The real number is irrational.
Lean: irrational_sqrt_two (Mathlib).
Proof. Suppose with integers and , , in lowest terms. Squaring gives . So is even, and is even by the first example of this section. Write . Then and , so is even and is even. Now and are both even, which contradicts the assumption that they have no common factor larger than .
Example P1.3.28. The same proof shows that is irrational, with the fact " implies " in place of the fact about parity. This fact has the same proof by contrapositive: if , then is not a multiple of .
Example P1.3.29. The proof does not work for , as it must not. The step " implies even" is true, but then gives , with no contradiction. Indeed is rational.
Theorem P1.3.30 (infinitely many primes). For every finite list of primes there is a prime that is not in the list. So there are infinitely many primes.
Lean: Nat.exists_infinite_primes (Mathlib).
Proof. Let . Then and has a smallest divisor , which is a prime: a smaller divisor of would be a smaller divisor of above . Suppose for some . Then and , so by rule 2 of the division theorem. This is impossible, since . So is a prime that is not in the list.
Example P1.3.31. For the list the number is not prime, but its smallest divisor is a prime outside the list. The proof gives a new prime, not that is prime.
Example P1.3.32. For the list the number is prime and is new. For the list the number is , which is prime. The number is the first such number in this sequence that is not prime.
Definition P1.3.33 (uniqueness). A statement "there is exactly one with " is proved in two parts: existence, an element with , and uniqueness: if and then .
Lean: ∃! x, P x, with ExistsUnique and the constructor ⟨a, ha, fun y hy => ...⟩ (Lean core and Mathlib).
Example P1.3.34. The equation has exactly one real solution. Existence: works. Uniqueness: if and , then , so .
Example P1.3.35. A binary operation on a set has at most one identity , with for all . If and are both identities, then , where the first equation uses that is an identity and the second uses that is.
Theorem P1.3.36 (a nonconstructive existence). There are irrational numbers and such that is rational.
Lean: no name; the proof is by by_cases on the rationality of (the project does not state it).
Proof. The number is irrational. Consider . If is rational, take . If is irrational, take and . Then , which is rational. In both cases a pair exists.
Example P1.3.37. The proof does not tell which pair works. A deeper theorem of Gelfond and Schneider shows that is irrational, so the pair is the second one. A proof that gives the element is constructive, and this proof is not.
Example P1.3.38. A proof of existence by the pigeonhole principle (Chapter 2) is also nonconstructive in the same sense: it proves that two boxes have the same content and does not find them.
Proof
The choice of method is a matter of the form of the hypotheses. A statement that says "there is no" or "is not" has the form of a denial, and a proof by contradiction often starts easily: assume the object exists and examine it. A statement of the form "if then " where is a denial is easier by contraposition. A statement where is complicated and is simple is also a candidate for the contrapositive.
A proof by contradiction must derive a contradiction, and a proof by contrapositive must reach the denial of the hypothesis. A reader who finds "a contradiction" in a proof by contradiction that is not a contradiction of the assumption has found an error. The next section lists such errors. The proof of the irrationality of is the model: assume the claim is false, derive a statement ( and even) and its denial ( and with no common factor).
Examples
Example P1.3.39 (a proof that cannot be direct). Claim: there is no pair of integers with . Suppose there is a pair. Then . The integers and have the same parity, since their difference is . If both are odd, the product is odd. If both are even, the product is a multiple of . In neither case is the product . A search over finds no pair, and the proof shows that no larger values help.
Example P1.3.40 (). The number is irrational. If with positive integers and , then and . The left side is and has a factor , and the right side has no factor . This is a contradiction. The proof uses the fact that each integer larger than has a prime factorization with the primes unique, which Chapter 5 proves.
Example P1.3.41 (a number with many prime factors). For each , the number has a prime divisor larger than . A prime divisor would divide and , and so would divide . For , , and . For , with the divisor . For , , and .
Exercises
- [10] Prove by the contrapositive that if is even, then is even.
- [12] Prove by contradiction that there is no largest integer.
- [15] Prove that is irrational. First prove that if then .
- [15] Prove that if is rational and not zero, and is irrational, then is irrational.
- [M18] Prove that has no integer solution, and decide whether has solutions in general.
- [M20] Prove that is irrational.
- [M20] Prove that for every the number has a prime divisor larger than .
- [M22] Prove that an element of a set with an associative operation has at most one inverse for the identity : if and , then .
- [M25] Prove that is irrational and that is irrational.
- [M25] Prove that if , , are integers with , then at least one of and is even.
Lean
The tactic contrapose! turns a goal into , and by_contra h adds the denial of the goal to the context and sets the goal to False. For existence and uniqueness the tactic use gives the element, and a proof of ∃! x, P x is refine ⟨a, ha, ?_⟩; intro y hy. The statement Irrational (Real.sqrt 2) is irrational_sqrt_two in Mathlib, and Nat.exists_infinite_primes (n : ℕ) : ∃ p, n ≤ p ∧ Nat.Prime p is the theorem on the infinity of the primes. A proof of the theorem with a computer reads off a finite case: example : Nat.Prime 211 := by norm_num checks one of the numbers of the examples.
Notes and history
The proof of the irrationality of is attributed to the school of Pythagoras, and the proof of the infinity of the primes is in Book IX of the Elements. Euclid's form says that, for any finite list of primes, there is another one, and it avoids the product of all primes. The theorem of Gelfond and Schneider is from 1934, and it shows that is transcendental for algebraic and irrational algebraic , so is irrational.
The method of the least counterexample, which Chapter 5 teaches, is a form of proof by contradiction: suppose a counterexample exists, take the smallest one, and show that a smaller one exists.
Writing proofs and common errors
Statement
A proof is a text for a reader. It must be right, and the reader must be able to see that it is right. This section gives the proof methods that remain (cases, "without loss of generality", proof of an equivalence), a set of rules for the text, and a list of the errors that occur most often.
Definition P1.3.42 (proof by cases). To prove , find statements such that is true, and prove for each . The cases must cover all possibilities. They need not be disjoint.
Lean: rcases h with h1 | h2 and by_cases h : p (Lean core and Mathlib).
Example P1.3.43. Claim: for every real number , . Case : . Case : . The cases cover all reals.
Example P1.3.44. Claim: for every integer , the number is even. Case even: gives . Case odd: gives with , so the product is even. The cases are disjoint and cover all integers.
Definition P1.3.45 (without loss of generality). The phrase "without loss of generality" (abbreviated wlog) in a proof means that a case is omitted because it follows from another case by a symmetry. The symmetry must be real: the statement must be unchanged when the roles of two objects are exchanged.
Lean: wlog h : a ≤ b with H (Mathlib).
Example P1.3.46. Claim: for real numbers and , . Wlog , since the claim is unchanged when and are exchanged. Then and , and the sum is .
Example P1.3.47 (a false use of wlog). Claim: for real numbers and , . A reader who writes "wlog " proves a false claim from a true case. The statement changes when and are exchanged, so no symmetry exists.
Definition P1.3.48 (proof of an equivalence). To prove , prove and . To prove that statements are all equivalent, prove a cycle .
Lean: Iff.intro, written constructor for a goal P ↔ Q; for a list, tfae_have and tfae_finish (Mathlib).
Example P1.3.49. Claim: for an integer , is odd iff is odd. If is odd, then is odd by the parity theorem. If is odd, then is odd by the contrapositive of the claim " even implies even".
Example P1.3.50. Claim: for sets and the three statements , and are equivalent. The cycle of three implications in Chapter 2, Section 1 proves it, and it needs three proofs, not six.
Definition P1.3.51 (a counterexample). A counterexample to is one element with . One counterexample disproves a universal statement, and many examples do not prove it.
Lean: push_neg and use a for a goal ¬ ∀ x, P x (Mathlib).
Example P1.3.52. The claim "for every integer , is prime" is true for and false for : the number is . Forty correct cases do not make a proof.
Example P1.3.53. The claim "if then or " is false: , , gives but and . It is true when is a prime, which is a theorem of Chapter 5.
Proof
The rules for the text of a proof are these.
- State what is to be proved, and say which method is in use at the start: "by contradiction", "by cases", "prove both directions".
- Introduce each symbol before it is used, with its type: "let be an integer". Do not reuse a symbol for two objects.
- Give a reason with each step, or make the reason clear from the step. "Since " or "by rule 2 of the division theorem" are reasons.
- Say what is assumed and what is proved. A line that is only assumed must not appear as if it were proved.
- Use words between the formulas, such as "so", "then", "since", "because", "suppose". A column of formulas without words has no logic that the reader can check.
- End with the statement that was to be proved, or a mark, and check that the last line is that statement.
The errors that occur most often have names, and each has a test.
Assuming the conclusion. A proof that starts from the claim and derives a true statement proves nothing, unless every step can be reversed. Test: read the proof from the last line to the first. Each step must follow from the next.
Dividing by zero. A step that divides by an expression must show that the expression is not zero.
A conclusion from examples. A claim for all is not proved by a finite list of cases. Test: ask which cases are not in the list.
Confusing the converse with the statement. From and one cannot conclude . Test: write the implication with the letters and compare.
A hidden quantifier. The sentence "for every there is a " must not be read as "there is a for every " (Chapter 1, Section 3). Test: ask whether the may depend on .
A circular argument. A proof of that uses or a statement equivalent to , perhaps in a lemma, proves nothing.
The wrong negation. The denial of "for all , and " is not "for all , not and not ". Test: use the laws of Chapter 1, Section 3.
Examples
Example P1.3.54 (a false proof that ). Let . Then , so , and . Divide by to get , so and . The error is the division: because .
Example P1.3.55 (an induction-like error, in advance of Chapter 4). A false proof says that all horses have the same color. The claim for one horse is true. For a set of horses, remove one horse and use the claim for the other , then remove another horse and do the same. The two sets of horses share horses, so all have the same color. The error is that for the two sets of one horse share no horse, so the step fails there. The lesson is that every case of a step must be checked, including the smallest.
Example P1.3.56 (a claim for small cases). The claim "every positive integer is a sum of two squares of integers" holds for , , and . It fails for , since the squares up to are and , and the sums of two of them are , and . One counterexample ends the discussion.
Example P1.3.57 (a check is not a proof). The identity gives, for , , , , the value on the left and on the right. The check agrees, and it proves the identity for these four numbers only. The proof is the expansion of both sides, which gives each time.
Exercises
- [10] Prove by cases that for every real , and that for real and .
- [12] Prove that for every integer the number is even, and that is divisible by .
- [14] Find the error in the proof that above, and give a similar false proof that that has a division by zero in another form.
- [15] Prove that for real numbers and , , with a wlog.
- [16] Give a counterexample to each: (a) if then or ; (b) if then , for integers ; (c) if then , for real and .
- [18] Prove that for integers the three statements are equivalent: (i) is even; (ii) is even; (iii) is divisible by .
- [20] Find the error: "Claim: if is a real number with , then . Proof: divide both sides by ."
- [M20] Find the smallest for which is not prime, and prove that the number is not prime for that . List all such with a computer.
- [M22] Prove that for integers and , is even iff and have the same parity.
- [M25] The sentence "for every there is a with " and the sentence "there is a such that for every , " differ. Give a domain in which the first is true and the second false, and a domain in which both are false. Say what the error is in a proof that goes from the first sentence to the second.
Lean
A proof by cases is rcases on a disjunction or by_cases h : p, and an equivalence is constructor followed by two goals. A refutation of a universal claim by a counterexample is intro h and have := h 40, followed by a computation such as norm_num at this. The tactic field_simp asks for a hypothesis a - b ≠ 0 before it divides by a - b, which is how a proof assistant catches the error of the false proof that .
Notes and history
The rules for the text follow the practice of the two spine texts. Velleman treats the writing of a proof together with each method, and Lehman, Leighton and Meyer give a chapter on the first rules of proofs with a list of false proofs, of which the horses are the classic one (it is due to Polya). The polynomial is due to Euler.
A proof is a finite list of steps that a reader can check, each step either an assumption, a definition, a known result, or a consequence of earlier steps by a rule of logic. This chapter teaches the forms of proof that the rest of the volume uses, and the forms of error to avoid.
Section 1 treats the direct proof. It shows what to write for each logical form of a statement: a universal statement, an existence statement, an implication, an equivalence and a statement with "or". It proves some first facts about integers: sums and products of even and odd numbers, divisibility, and an inequality by cases. Section 2 treats the indirect proofs, the proof by contrapositive and the proof by contradiction, with the two classical results that every reader should know: the irrationality of and the infinity of the primes. It also treats the proof of uniqueness and the existence proof that gives no example. Section 3 is about the proof as a text. It lists the usual errors, such as the division by zero and the proof by one example, shows how to use a counterexample, and ends with a checklist for a proof that the writer is about to hand in.
The chapter prepares TAOCP Section 1.1, where Euclid's algorithm is argued correct, and Section 1.2.1, where the book proves the first statements by induction and says in words what the proof must contain. Chapter 4 begins with induction, which is a method of proof for statements with a universal quantifier over the natural numbers. Every proof in the later chapters uses the forms of this chapter.
The chapter assumes Chapters 1 and 2. The spine texts are Velleman, How to Prove It, Chapter 3, and Lehman, Leighton and Meyer, Mathematics for Computer Science, Chapters 1 and 2. Each section ends with exercises, and the solutions are in the last chapter of the volume.
The source of this page. Something is wrong? Report it.