taocp

This site has no text of the book. Keep your own copy of TAOCP next to it. See what is checked.

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
Contents
  1. Direct proof
  2. Indirect proof
  3. Writing proofs and common errors

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 ℤ\mathbb{Z} 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 nn is even if n=2kn = 2k for some integer kk, and odd if n=2k+1n = 2k + 1 for some integer kk. An integer aa divides an integer bb, written a∣ba \mid b, if b=akb = ak for some integer kk. Then bb is a multiple of aa.

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 18=2⋅918 = 2 \cdot 9 is even, and −7=2⋅(−4)+1-7 = 2 \cdot (-4) + 1 is odd. Also 0=2⋅00 = 2 \cdot 0 is even. The number 4∣284 \mid 28 since 28=4⋅728 = 4 \cdot 7, and 5∤285 \nmid 28.

Example P1.3.3. Every integer divides 00, since 0=a⋅00 = a \cdot 0. The integer 00 divides only 00, since 0⋅k=00 \cdot k = 0. So the sentence "a∣ba \mid b" has a meaning for a=0a = 0, and "b/ab / a" does not.

The forms of a direct proof. The shape of the statement decides the first line of the proof.

  1. To prove ∀x∈D P(x)\forall x \in D\ P(x): write "let x∈Dx \in D be arbitrary" and prove P(x)P(x). The letter xx must not have a value that was chosen earlier.
  2. To prove ∃x∈D P(x)\exists x \in D\ P(x): give an element aa of DD and prove P(a)P(a).
  3. To prove P→QP \to Q: write "suppose PP" and prove QQ.
  4. To prove P↔QP \leftrightarrow Q: prove P→QP \to Q and Q→PQ \to P.
  5. To prove P∧QP \wedge Q: prove PP and prove QQ.
  6. To prove P∨QP \vee Q: prove ¬P→Q\neg P \to Q (or ¬Q→P\neg Q \to P), or split into cases and in each case prove one of the two.
  7. To use ∀x P(x)\forall x\ P(x): choose any element aa and conclude P(a)P(a).
  8. To use ∃x P(x)\exists x\ P(x): write "let aa be such that P(a)P(a)" and continue with a new letter aa.
  9. To use P∨QP \vee Q: prove the claim in the case PP and in the case QQ.

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 nn, if nn is even then n2n^2 is even. Following the forms: let nn be an arbitrary integer (form 1). Suppose nn is even (form 3). By the definition, n=2kn = 2k for an integer kk (form 8). Then n2=4k2=2(2k2)n^2 = 4k^2 = 2(2k^2), and 2k22k^2 is an integer, so n2n^2 is even.

Example P1.3.5. Claim: there is an integer nn with n>1n > 1 and n2=n+6n^2 = n + 6. Form 2 asks for an element. Try n=3n = 3: 32=93^2 = 9 and 3+6=93 + 6 = 9. So n=3n = 3 works. For the other solution of the equation, n=−2n = -2, the condition n>1n > 1 fails.

Theorem P1.3.6 (parity). For integers aa and bb:

  1. if aa and bb are even, then a+ba + b and abab are even;
  2. if aa is even and bb is odd, then a+ba + b is odd and abab is even;
  3. if aa and bb are odd, then a+ba + b is even and abab is odd.

Lean: Even.add, Even.mul_right, Odd.add_odd and Odd.mul (Mathlib).

Proof. Let a=2sa = 2s or 2s+12s + 1 and b=2tb = 2t or 2t+12t + 1, as the case needs. Rule 1: a+b=2(s+t)a + b = 2(s + t) and ab=2(2st)ab = 2(2st). Rule 2: let a=2sa = 2s and b=2t+1b = 2t + 1. Then a+b=2(s+t)+1a + b = 2(s + t) + 1 and ab=2(2st+s)ab = 2(2st + s). Rule 3: let a=2s+1a = 2s + 1 and b=2t+1b = 2t + 1. Then a+b=2(s+t+1)a + b = 2(s + t + 1) and ab=4st+2s+2t+1=2(2st+s+t)+1ab = 4st + 2s + 2t + 1 = 2(2st + s + t) + 1. In each case the number in brackets is an integer. □\square

Example P1.3.7. For a=14a = 14 and b=9b = 9 rule 2 gives a+b=23=2⋅11+1a + b = 23 = 2 \cdot 11 + 1 and ab=126=2⋅63ab = 126 = 2 \cdot 63. For a=7a = 7 and b=5b = 5 rule 3 gives a+b=12a + b = 12 and ab=35=2⋅17+1ab = 35 = 2 \cdot 17 + 1.

Example P1.3.8. The theorem proves that the sum of two numbers has the same parity as the difference, since a−b=a+(−b)a - b = a + (-b) and −b-b has the same parity as bb. Also a+ba + b is odd if and only if exactly one of aa and bb is odd. This is the exclusive or of Chapter 1.

Theorem P1.3.9 (properties of division). For integers aa, bb, cc:

  1. if a∣ba \mid b and b∣cb \mid c, then a∣ca \mid c;
  2. if a∣ba \mid b and a∣ca \mid c, then a∣(bx+cy)a \mid (bx + cy) for all integers xx and yy;
  3. if a∣ba \mid b and b≠0b \ne 0, then ∣a∣≤∣b∣|a| \le |b|.

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 b=akb = ak and c=bℓc = b\ell. Then c=a(kℓ)c = a(k\ell). Rule 2: let b=akb = ak and c=aℓc = a\ell. Then bx+cy=a(kx+ℓy)bx + cy = a(kx + \ell y). Rule 3: let b=akb = ak. As b≠0b \ne 0, k≠0k \ne 0, so ∣k∣≥1|k| \ge 1 and ∣b∣=∣a∣∣k∣≥∣a∣|b| = |a||k| \ge |a|. □\square

Example P1.3.10. Since 6∣126 \mid 12 and 12∣6012 \mid 60, rule 1 gives 6∣606 \mid 60. Since 7∣217 \mid 21 and 7∣567 \mid 56, rule 2 gives 7∣3⋅21−2⋅56=63−112=−497 \mid 3 \cdot 21 - 2 \cdot 56 = 63 - 112 = -49, and indeed −49=7⋅(−7)-49 = 7 \cdot (-7).

Example P1.3.11. Rule 2 is the basis of Euclid's algorithm. If dd divides mm and nn and m=qn+rm = qn + r, then d∣m−qn=rd \mid m - qn = r. So the divisors of mm and nn divide rr too. Chapter 5 completes the argument.

Proof by cases. To prove RR from P∨QP \vee Q a proof treats the case PP and the case QQ apart. The cases must cover all possibilities. They need not be disjoint.

Theorem P1.3.12 (the triangle inequality). For real numbers xx and yy, ∣x+y∣≤∣x∣+∣y∣|x + y| \le |x| + |y|.

Lean: Mathlib has the statement as abs_add in older versions and as abs_add_le in newer ones.

Proof. Recall that ∣t∣=t|t| = t for t≥0t \ge 0 and ∣t∣=−t|t| = -t for t<0t < 0, and that −∣t∣≤t≤∣t∣-|t| \le t \le |t| for all tt. Add the two inequalities for xx and for yy: −(∣x∣+∣y∣)≤x+y≤∣x∣+∣y∣-(|x| + |y|) \le x + y \le |x| + |y|. For x+y≥0x + y \ge 0 the value ∣x+y∣|x + y| is x+yx + y, and the right inequality is the claim. For x+y<0x + y < 0 the value is −(x+y)-(x + y), and the left inequality gives −(x+y)≤∣x∣+∣y∣-(x + y) \le |x| + |y|. □\square

Example P1.3.13. For x=3x = 3 and y=−5y = -5: ∣x+y∣=2≤8=∣x∣+∣y∣|x + y| = 2 \le 8 = |x| + |y|. For x=4x = 4 and y=9y = 9 the two sides are equal, 1313.

Example P1.3.14. The proof by cases can also settle a statement about an integer. For all nn, n2+nn^2 + n is even: if nn is even, then n2n^2 and nn are even and the sum is even by rule 1. If nn is odd, then n2n^2 is odd by rule 3 of the parity theorem, so n2+nn^2 + n is the sum of two odd numbers and is even. For n=0,…,7n = 0, \dots, 7 the values of n2+nn^2 + n are 0,2,6,12,20,30,42,560, 2, 6, 12, 20, 30, 42, 56.

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 "nn even implies n2n^2 even" does not do. It does not choose a value for nn. If a proof of a universal statement says "take n=4n = 4" and checks the claim for 44, 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 a∣ba \mid b and a∣(b+1)a \mid (b + 1), then a=±1a = \pm 1. By rule 2 of the division theorem, a∣(b+1)−b=1a \mid (b + 1) - b = 1. By rule 3, ∣a∣≤1|a| \le 1, and a≠0a \ne 0 since 0∤10 \nmid 1. So a=1a = 1 or a=−1a = -1.

Example P1.3.16 (the square mod 4). For every integer nn, n2=4qn^2 = 4q or n2=4q+1n^2 = 4q + 1 for some qq. If n=2kn = 2k, then n2=4k2n^2 = 4k^2. If n=2k+1n = 2k + 1, then n2=4k2+4k+1=4(k2+k)+1n^2 = 4k^2 + 4k + 1 = 4(k^2 + k) + 1. A computer check of n=0,…,99n = 0, \dots, 99 shows only the remainders 00 and 11 of n2n^2 modulo 44, and the proof says that no other remainder can occur.

Example P1.3.17 (an inequality). For real xx and yy, xy≤(x2+y2)/2xy \le (x^2 + y^2) / 2. The difference of the two sides is (x2+y2)/2−xy=(x−y)2/2(x^2 + y^2) / 2 - xy = (x - y)^2 / 2, which is not negative, since a square of a real number is not negative. For x=3x = 3 and y=5y = 5 the two sides are 1515 and 1717. The same step, with x\sqrt{x} and y\sqrt{y} for x,y≥0x, y \ge 0, gives xy≤(x+y)/2\sqrt{xy} \le (x + y) / 2.

Exercises

  1. [10] Prove that the sum of an odd integer and an even integer is odd.
  2. [12] Prove that if a∣ba \mid b and a∣ca \mid c, then a∣(b+c)a \mid (b + c) and a∣bca \mid bc.
  3. [15] Prove that 3n2+n3n^2 + n is even for every integer nn, by cases on the parity of nn.
  4. [15] Prove that max⁡(x,y)=(x+y+∣x−y∣)/2\max(x, y) = (x + y + |x - y|) / 2 for real xx and yy, by cases on x≤yx \le y and x>yx > y.
  5. [M18] Prove that n2 mod 4n^2 \bmod 4 is 00 or 11, and use it to show that no integer sum a2+b2a^2 + b^2 has the form 4k+34k + 3. Show that 20232023 is not a sum of two squares.
  6. [M20] Prove that the product of three consecutive integers is divisible by 66.
  7. [M20] Prove that xy≤(x2+y2)/2xy \le (x^2 + y^2) / 2 for all reals, and that xy≤(x+y)/2\sqrt{xy} \le (x + y) / 2 for x,y≥0x, y \ge 0.
  8. [M22] Prove that if aa and bb are positive integers with a∣ba \mid b and b∣ab \mid a, then a=ba = b.
  9. [M22] Show that the statement "for all n≥0n \ge 0, n2+n+41n^2 + n + 41 is prime" has its first failure at n=40n = 40. Why does this not contradict the proof method of this section?
  10. [M25] Prove that n3−nn^3 - n is divisible by 33 for every integer nn, by cases on n mod 3n \bmod 3, and use the product of three consecutive integers to show that it is divisible by 66.

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 n2+nn^2 + n for n=0,…,7n = 0, \dots, 7, is checked by decide on Fin 8 or on Finset.range 8. The tactic omega proves linear claims about integers, such as 2023 mod 4=32023 \bmod 4 = 3.

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 n2+n+41n^2 + n + 41 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 mm and nn divides m−qnm - qn (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 n≥1n \ge 1" 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 P→QP \to Q, prove ¬Q→¬P\neg Q \to \neg P: suppose QQ is false and show that PP 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 nn, if n2n^2 is even then nn is even. A direct proof has no start: the hypothesis n2=2kn^2 = 2k does not give nn at once. The contrapositive says: if nn is odd, then n2n^2 is odd. This is rule 3 of the parity theorem, since n2=n⋅nn^2 = n \cdot n is a product of two odd numbers.

Example P1.3.20. Claim: for an integer nn, if 3n+23n + 2 is even then nn is even. The contrapositive says that if nn is odd then 3n+23n + 2 is odd. Let n=2k+1n = 2k + 1. Then 3n+2=6k+5=2(3k+2)+13n + 2 = 6k + 5 = 2(3k + 2) + 1, which is odd.

Definition P1.3.21 (the method of contradiction). To prove a statement PP, suppose ¬P\neg P and derive a contradiction, that is, a statement and its denial. The rule is: if ¬P→(R∧¬R)\neg P \to (R \wedge \neg R) is true for some statement RR, then PP is true. To prove P→QP \to Q by contradiction, suppose PP and ¬Q\neg Q 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 nn with n2=2n^2 = 2. Suppose n2=2n^2 = 2. Then n2n^2 is even, so nn is even by the first example, and n=2kn = 2k gives 4k2=24k^2 = 2, so 2k2=12k^2 = 1. But 2k22k^2 is even and 11 is odd. This is a contradiction.

Example P1.3.23. Claim: the sum of a rational number and an irrational number is irrational. Let rr be rational and xx be irrational, and suppose r+xr + x is rational. Then x=(r+x)−rx = (r + x) - r is the difference of two rational numbers, so it is rational. This contradicts the choice of xx.

Definition P1.3.24 (rational, irrational). A real number is rational if it equals p/qp/q for integers pp and qq with q≠0q \ne 0. A real number that is not rational is irrational.

Lean: Rat and the predicate Irrational (Mathlib); irrational_sqrt_two states that 2\sqrt 2 is irrational.

Example P1.3.25. The numbers 3/43/4 and −7-7 and 0.125=1/80.125 = 1/8 are rational. The number 0.333…=1/30.333\ldots = 1/3 is rational too. The number 2\sqrt 2 is irrational, and the next theorem proves it.

Example P1.3.26. The sum and the product of two rational numbers are rational, since p/q+r/s=(ps+qr)/(qs)p/q + r/s = (ps + qr)/(qs) and (p/q)(r/s)=(pr)/(qs)(p/q)(r/s) = (pr)/(qs), with qs≠0qs \ne 0. Each rational number can be written in lowest terms, with pp and qq having no common factor larger than 11, by dividing out a common factor.

Theorem P1.3.27 (irrationality of 2\sqrt 2). The real number 2\sqrt 2 is irrational.

Lean: irrational_sqrt_two (Mathlib).

Proof. Suppose 2=p/q\sqrt 2 = p/q with integers pp and qq, q>0q > 0, in lowest terms. Squaring gives p2=2q2p^2 = 2q^2. So p2p^2 is even, and pp is even by the first example of this section. Write p=2kp = 2k. Then 4k2=2q24k^2 = 2q^2 and q2=2k2q^2 = 2k^2, so q2q^2 is even and qq is even. Now pp and qq are both even, which contradicts the assumption that they have no common factor larger than 11. □\square

Example P1.3.28. The same proof shows that 3\sqrt 3 is irrational, with the fact "3∣p23 \mid p^2 implies 3∣p3 \mid p" in place of the fact about parity. This fact has the same proof by contrapositive: if p=3k±1p = 3k \pm 1, then p2=9k2±6k+1p^2 = 9k^2 \pm 6k + 1 is not a multiple of 33.

Example P1.3.29. The proof does not work for 4\sqrt 4, as it must not. The step "p2=4q2p^2 = 4q^2 implies pp even" is true, but then p=2kp = 2k gives k2=q2k^2 = q^2, with no contradiction. Indeed 4=2\sqrt 4 = 2 is rational.

Theorem P1.3.30 (infinitely many primes). For every finite list of primes p1,…,pnp_1, \dots, p_n there is a prime that is not in the list. So there are infinitely many primes.

Lean: Nat.exists_infinite_primes (Mathlib).

Proof. Let N=p1p2⋯pn+1N = p_1 p_2 \cdots p_n + 1. Then N>1N > 1 and NN has a smallest divisor q>1q > 1, which is a prime: a smaller divisor of qq would be a smaller divisor of NN above 11. Suppose q=piq = p_i for some ii. Then q∣p1⋯pnq \mid p_1 \cdots p_n and q∣Nq \mid N, so q∣N−p1⋯pn=1q \mid N - p_1 \cdots p_n = 1 by rule 2 of the division theorem. This is impossible, since q>1q > 1. So qq is a prime that is not in the list. □\square

Example P1.3.31. For the list 2,3,5,7,11,132, 3, 5, 7, 11, 13 the number N=30031=59⋅509N = 30031 = 59 \cdot 509 is not prime, but its smallest divisor 5959 is a prime outside the list. The proof gives a new prime, not that NN is prime.

Example P1.3.32. For the list 2,3,52, 3, 5 the number N=31N = 31 is prime and is new. For the list 2,3,5,72, 3, 5, 7 the number is 211211, which is prime. The number 2⋅3⋅5⋅7⋅11⋅13+12 \cdot 3 \cdot 5 \cdot 7 \cdot 11 \cdot 13 + 1 is the first such number in this sequence that is not prime.

Definition P1.3.33 (uniqueness). A statement "there is exactly one xx with P(x)P(x)" is proved in two parts: existence, an element with PP, and uniqueness: if P(x)P(x) and P(y)P(y) then x=yx = y.

Lean: ∃! x, P x, with ExistsUnique and the constructor ⟨a, ha, fun y hy => ...⟩ (Lean core and Mathlib).

Example P1.3.34. The equation 3x+5=113x + 5 = 11 has exactly one real solution. Existence: x=2x = 2 works. Uniqueness: if 3x+5=113x + 5 = 11 and 3y+5=113y + 5 = 11, then 3x=3y3x = 3y, so x=yx = y.

Example P1.3.35. A binary operation ∗\ast on a set SS has at most one identity ee, with e∗s=s=s∗ee \ast s = s = s \ast e for all ss. If ee and e′e' are both identities, then e=e∗e′=e′e = e \ast e' = e', where the first equation uses that e′e' is an identity and the second uses that ee is.

Theorem P1.3.36 (a nonconstructive existence). There are irrational numbers aa and bb such that aba^b is rational.

Lean: no name; the proof is by by_cases on the rationality of 22\sqrt 2^{\sqrt 2} (the project does not state it).

Proof. The number 2\sqrt 2 is irrational. Consider c=22c = \sqrt 2^{\sqrt 2}. If cc is rational, take a=b=2a = b = \sqrt 2. If cc is irrational, take a=ca = c and b=2b = \sqrt 2. Then ab=(22)2=22⋅2=22=2a^b = (\sqrt 2^{\sqrt 2})^{\sqrt 2} = \sqrt 2^{\sqrt 2 \cdot \sqrt 2} = \sqrt 2^2 = 2, which is rational. In both cases a pair exists. □\square

Example P1.3.37. The proof does not tell which pair works. A deeper theorem of Gelfond and Schneider shows that 22\sqrt 2^{\sqrt 2} 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 PP then QQ" where QQ is a denial is easier by contraposition. A statement where PP is complicated and ¬Q\neg Q 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 2\sqrt 2 is the model: assume the claim is false, derive a statement (pp and qq even) and its denial (pp and qq with no common factor).

Examples

Example P1.3.39 (a proof that cannot be direct). Claim: there is no pair of integers x,yx, y with x2−y2=2x^2 - y^2 = 2. Suppose there is a pair. Then (x−y)(x+y)=2(x - y)(x + y) = 2. The integers x−yx - y and x+yx + y have the same parity, since their difference is 2y2y. If both are odd, the product is odd. If both are even, the product is a multiple of 44. In neither case is the product 22. A search over −100≤x,y≤100-100 \le x, y \le 100 finds no pair, and the proof shows that no larger values help.

Example P1.3.40 (log⁡102\log_{10} 2). The number log⁡102\log_{10} 2 is irrational. If log⁡102=p/q\log_{10} 2 = p/q with positive integers pp and qq, then 10p/q=210^{p/q} = 2 and 10p=2q10^p = 2^q. The left side is 2p5p2^p 5^p and has a factor 55, and the right side has no factor 55. This is a contradiction. The proof uses the fact that each integer larger than 11 has a prime factorization with the primes unique, which Chapter 5 proves.

Example P1.3.41 (a number with many prime factors). For each n≥2n \ge 2, the number n!+1n! + 1 has a prime divisor larger than nn. A prime divisor q≤nq \le n would divide n!n! and n!+1n! + 1, and so would divide 11. For n=5n = 5, n!+1=121=112n! + 1 = 121 = 11^2, and 11>511 > 5. For n=4n = 4, n!+1=25n! + 1 = 25 with the divisor 5>45 > 4. For n=6n = 6, n!+1=721=7⋅103n! + 1 = 721 = 7 \cdot 103, and 7>67 > 6.

Exercises

  1. [10] Prove by the contrapositive that if 3n+23n + 2 is even, then nn is even.
  2. [12] Prove by contradiction that there is no largest integer.
  3. [15] Prove that 3\sqrt 3 is irrational. First prove that if 3∣p23 \mid p^2 then 3∣p3 \mid p.
  4. [15] Prove that if rr is rational and not zero, and xx is irrational, then rxrx is irrational.
  5. [M18] Prove that x2−y2=2x^2 - y^2 = 2 has no integer solution, and decide whether x2−y2=4k+2x^2 - y^2 = 4k + 2 has solutions in general.
  6. [M20] Prove that log⁡102\log_{10} 2 is irrational.
  7. [M20] Prove that for every n≥2n \ge 2 the number n!+1n! + 1 has a prime divisor larger than nn.
  8. [M22] Prove that an element aa of a set with an associative operation has at most one inverse for the identity ee: if ab=e=baab = e = ba and ac=e=caac = e = ca, then b=cb = c.
  9. [M25] Prove that 6\sqrt 6 is irrational and that 2+3\sqrt 2 + \sqrt 3 is irrational.
  10. [M25] Prove that if aa, bb, cc are integers with a2+b2=c2a^2 + b^2 = c^2, then at least one of aa and bb is even.

Lean

The tactic contrapose! turns a goal P→QP \to Q into ¬Q→¬P\neg Q \to \neg P, 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 2\sqrt 2 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 aba^b is transcendental for algebraic a≠0,1a \ne 0, 1 and irrational algebraic bb, so 22\sqrt 2^{\sqrt 2} 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 PP, find statements C1,…,CkC_1, \dots, C_k such that C1∨⋯∨CkC_1 \vee \cdots \vee C_k is true, and prove Ci→PC_i \to P for each ii. 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 xx, ∣x∣≥x|x| \ge x. Case x≥0x \ge 0: ∣x∣=x|x| = x. Case x<0x < 0: ∣x∣=−x>0>x|x| = -x > 0 > x. The cases cover all reals.

Example P1.3.44. Claim: for every integer nn, the number n2+nn^2 + n is even. Case nn even: n=2kn = 2k gives 4k2+2k=2(2k2+k)4k^2 + 2k = 2(2k^2 + k). Case nn odd: n=2k+1n = 2k + 1 gives n(n+1)n(n + 1) with n+1=2(k+1)n + 1 = 2(k + 1), 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 aa and bb, max⁡(a,b)+min⁡(a,b)=a+b\max(a, b) + \min(a, b) = a + b. Wlog a≤ba \le b, since the claim is unchanged when aa and bb are exchanged. Then max⁡=b\max = b and min⁡=a\min = a, and the sum is a+ba + b.

Example P1.3.47 (a false use of wlog). Claim: for real numbers aa and bb, a−b≥0a - b \ge 0. A reader who writes "wlog a≥ba \ge b" proves a false claim from a true case. The statement changes when aa and bb are exchanged, so no symmetry exists.

Definition P1.3.48 (proof of an equivalence). To prove P↔QP \leftrightarrow Q, prove P→QP \to Q and Q→PQ \to P. To prove that statements P1,…,PnP_1, \dots, P_n are all equivalent, prove a cycle P1→P2→⋯→Pn→P1P_1 \to P_2 \to \cdots \to P_n \to P_1.

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 nn, nn is odd iff n2n^2 is odd. If nn is odd, then n2n^2 is odd by the parity theorem. If n2n^2 is odd, then nn is odd by the contrapositive of the claim "nn even implies n2n^2 even".

Example P1.3.50. Claim: for sets AA and BB the three statements A⊆BA \subseteq B, A∪B=BA \cup B = B and A∩B=AA \cap B = A 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 ∀x P(x)\forall x\, P(x) is one element aa with ¬P(a)\neg P(a). 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 n≥0n \ge 0, n2+n+41n^2 + n + 41 is prime" is true for n=0,1,…,39n = 0, 1, \dots, 39 and false for n=40n = 40: the number is 1681=4121681 = 41^2. Forty correct cases do not make a proof.

Example P1.3.53. The claim "if a∣bca \mid bc then a∣ba \mid b or a∣ca \mid c" is false: a=6a = 6, b=2b = 2, c=3c = 3 gives 6∣66 \mid 6 but 6∤26 \nmid 2 and 6∤36 \nmid 3. It is true when aa is a prime, which is a theorem of Chapter 5.

Proof

The rules for the text of a proof are these.

  1. State what is to be proved, and say which method is in use at the start: "by contradiction", "by cases", "prove both directions".
  2. Introduce each symbol before it is used, with its type: "let nn be an integer". Do not reuse a symbol for two objects.
  3. Give a reason with each step, or make the reason clear from the step. "Since n=2kn = 2k" or "by rule 2 of the division theorem" are reasons.
  4. Say what is assumed and what is proved. A line that is only assumed must not appear as if it were proved.
  5. 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.
  6. 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 nn 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 P→QP \to Q and QQ one cannot conclude PP. Test: write the implication with the letters and compare.

A hidden quantifier. The sentence "for every xx there is a yy" must not be read as "there is a yy for every xx" (Chapter 1, Section 3). Test: ask whether the yy may depend on xx.

A circular argument. A proof of PP that uses PP or a statement equivalent to PP, perhaps in a lemma, proves nothing.

The wrong negation. The denial of "for all xx, PP and QQ" is not "for all xx, not PP and not QQ". Test: use the laws of Chapter 1, Section 3.

Examples

Example P1.3.54 (a false proof that 1=21 = 2). Let a=ba = b. Then a2=aba^2 = ab, so a2−b2=ab−b2a^2 - b^2 = ab - b^2, and (a+b)(a−b)=b(a−b)(a + b)(a - b) = b(a - b). Divide by a−ba - b to get a+b=ba + b = b, so 2b=b2b = b and 2=12 = 1. The error is the division: a−b=0a - b = 0 because a=ba = b.

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 n+1n + 1 horses, remove one horse and use the claim for the other nn, then remove another horse and do the same. The two sets of nn horses share horses, so all n+1n + 1 have the same color. The error is that for n+1=2n + 1 = 2 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 1=12+021 = 1^2 + 0^2, 2=12+122 = 1^2 + 1^2, 4=22+024 = 2^2 + 0^2 and 5=22+125 = 2^2 + 1^2. It fails for 33, since the squares up to 33 are 00 and 11, and the sums of two of them are 00, 11 and 22. One counterexample ends the discussion.

Example P1.3.57 (a check is not a proof). The identity (a2+b2)(c2+d2)=(ac−bd)2+(ad+bc)2(a^2 + b^2)(c^2 + d^2) = (ac - bd)^2 + (ad + bc)^2 gives, for a=1a = 1, b=2b = 2, c=3c = 3, d=4d = 4, the value 5⋅25=1255 \cdot 25 = 125 on the left and (3−8)2+(4+6)2=25+100=125(3 - 8)^2 + (4 + 6)^2 = 25 + 100 = 125 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 a2c2+a2d2+b2c2+b2d2a^2c^2 + a^2d^2 + b^2c^2 + b^2d^2 each time.

Exercises

  1. [10] Prove by cases that ∣x∣≥x|x| \ge x for every real xx, and that ∣xy∣=∣x∣∣y∣|xy| = |x||y| for real xx and yy.
  2. [12] Prove that for every integer nn the number n2+nn^2 + n is even, and that n3−nn^3 - n is divisible by 33.
  3. [14] Find the error in the proof that 1=21 = 2 above, and give a similar false proof that 0=10 = 1 that has a division by zero in another form.
  4. [15] Prove that for real numbers aa and bb, max⁡(a,b)=(a+b+∣a−b∣)/2\max(a, b) = (a + b + |a - b|)/2, with a wlog.
  5. [16] Give a counterexample to each: (a) if a∣bca \mid bc then a∣ba \mid b or a∣ca \mid c; (b) if n2>nn^2 > n then n>1n > 1, for integers nn; (c) if a2=b2a^2 = b^2 then a=ba = b, for real aa and bb.
  6. [18] Prove that for integers nn the three statements are equivalent: (i) nn is even; (ii) n2n^2 is even; (iii) n2n^2 is divisible by 44.
  7. [20] Find the error: "Claim: if xx is a real number with x2=xx^2 = x, then x=1x = 1. Proof: divide both sides by xx."
  8. [M20] Find the smallest n≥0n \ge 0 for which n2+n+41n^2 + n + 41 is not prime, and prove that the number is not prime for that nn. List all such n≤100n \le 100 with a computer.
  9. [M22] Prove that for integers aa and bb, a+ba + b is even iff aa and bb have the same parity.
  10. [M25] The sentence "for every xx there is a yy with y>xy > x" and the sentence "there is a yy such that for every xx, y>xy > x" 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 1=21 = 2.

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 n2+n+41n^2 + n + 41 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 2\sqrt 2 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.