TExcelTAD
Home › Discrete Mathematics › Proof by Cases and by Contradiction

Proof by Cases and by Contradiction

Two more proof templates cover a large share of everyday mathematics. Proof by cases splits a problem into situations that together cover everything. Proof by contradiction assumes the statement is false and shows that this leads to nonsense.

Proof by cases

If every possibility falls into case 1 or case 2 (or more cases), and the statement holds in each case, it holds always. The cases must be exhaustive; they may overlap.

Theorem. For every integer nn, n2+nn^2 + n is even.

Proof. Case 1: nn is even, n=2kn = 2k. Then n2+n=4k2+2k=2(2k2+k)n^2 + n = 4k^2 + 2k = 2(2k^2 + k). Case 2: nn is odd, n=2k+1n = 2k + 1. Then n2+n=(2k+1)(2k+2)=2(2k+1)(k+1)n^2 + n = (2k + 1)(2k + 2) = 2(2k + 1)(k + 1). Every integer is even or odd, so the cases are exhaustive. ■\blacksquare

A classic puzzle shows how cases can help even when you do not know which case is true.

Theorem. In any group of 6 people, there are 3 who all know each other or 3 who are all strangers to each other.

Proof sketch. Pick a person xx. Of the other 5, at least 3 know xx or at least 3 do not (cases!). Say a,b,ca, b, c all know xx. If any two of a,b,ca, b, c know each other, they form a trio with xx. Otherwise a,b,ca, b, c are three mutual strangers. The other case is symmetric. ■\blacksquare

Here the "for any group" claim covers 2152^{15} possible friendship patterns among 6 people (15 pairs), few enough to check by computer as well.

python · try it yourself
from itertools import combinations, product

people = range(6)
pairs = list(combinations(people, 2))
trios = list(combinations(people, 3))

def has_mono_trio(knows):
    for a, b, c in trios:
        e = (knows[(a, b)], knows[(a, c)], knows[(b, c)])
        if e == (True, True, True) or e == (False, False, False):
            return True
    return False

count = 0
for bits in product([False, True], repeat=len(pairs)):
    count += has_mono_trio(dict(zip(pairs, bits)))
print("patterns:", 2 ** len(pairs), " with a trio:", count)
patterns: 32768  with a trio: 32768

All 32768 patterns contain such a trio. With 5 people it fails: arrange them in a pentagon where neighbours know each other. This is the first case of Ramsey theory.

Proof by contradiction

To prove PP, assume ¬P\neg P and derive a statement that is false (a contradiction, such as 1=01 = 0, or Q∧¬QQ \land \neg Q). Since true statements only lead to true statements, ¬P\neg P must be false, so PP is true.

Theorem. 2\sqrt{2} is irrational.

Proof. Suppose, for contradiction, that 2=ab\sqrt{2} = \frac{a}{b} for integers a,ba, b with b>0b > 0, and that the fraction is in lowest terms (no common factor). Squaring gives a2=2b2a^2 = 2b^2, so a2a^2 is even, so aa is even (previous lesson): a=2ca = 2c. Then 4c2=2b24c^2 = 2b^2, so b2=2c2b^2 = 2c^2, and bb is even too. Now aa and bb share the factor 2, contradicting lowest terms. ■\blacksquare

Theorem (Euclid). There are infinitely many primes.

Proof. Suppose there are only finitely many, p1,…,pkp_1, \ldots, p_k. Let N=p1p2⋯pk+1N = p_1 p_2 \cdots p_k + 1. N>1N > 1 has some prime factor pp, and pp must be one of the pip_i. But dividing NN by any pip_i leaves remainder 1, so no pip_i divides NN. Contradiction. ■\blacksquare

Note that NN itself need not be prime. The proof only needs a prime that is missing from the list.

python · try it yourself
from math import prod
from sympy import primerange, factorint

for k in range(1, 8):
    ps = list(primerange(2, 20))[:k]
    N = prod(ps) + 1
    print(f"primes {ps}: N = {N}, factors {factorint(N)}")
primes [2]: N = 3, factors {3: 1}
primes [2, 3]: N = 7, factors {7: 1}
primes [2, 3, 5]: N = 31, factors {31: 1}
primes [2, 3, 5, 7]: N = 211, factors {211: 1}
primes [2, 3, 5, 7, 11]: N = 2311, factors {2311: 1}
primes [2, 3, 5, 7, 11, 13]: N = 30031, factors {59: 1, 509: 1}
primes [2, 3, 5, 7, 11, 13, 17]: N = 510511, factors {19: 1, 97: 1, 277: 1}

The last lines show N=30031=59⋅509N = 30031 = 59 \cdot 509 for the first six primes: not prime, but its prime factors are new.

In software

Proof by cases is what a match statement or an exhaustive if/elif/else does; compilers for Rust, Haskell and TypeScript check that the cases are exhaustive. Proof by contradiction appears in impossibility results: there is no comparison sort faster than nlog⁡nn \log n comparisons in the worst case, and no program can decide whether every program halts.

Exercises

Exercise 1: Cases on remainders

Prove that for every integer nn, n2 mod 3n^2 \bmod 3 is 0 or 1.

Answer

Cases n=3kn = 3k, 3k+13k + 1, 3k+23k + 2 give n2≡0,1,1(mod3)n^2 \equiv 0, 1, 1 \pmod 3.

Solution
(3k)2=3(3k2)remainder 0(3k+1)2=3(3k2+2k)+1remainder 1(3k+2)2=3(3k2+4k+1)+1remainder 1\begin{aligned} (3k)^2 &= 3(3k^2) && \text{remainder } 0 \\ (3k + 1)^2 &= 3(3k^2 + 2k) + 1 && \text{remainder } 1 \\ (3k + 2)^2 &= 3(3k^2 + 4k + 1) + 1 && \text{remainder } 1 \end{aligned}

Every integer has one of these three forms. ■\blacksquare

Exercise 2: Irrationality of 3\sqrt{3}

Prove that 3\sqrt{3} is irrational.

Answer

Same pattern as 2\sqrt{2}, using "if 3∣a23 \mid a^2 then 3∣a3 \mid a".

Solution

Suppose 3=ab\sqrt{3} = \frac{a}{b} in lowest terms. Then a2=3b2a^2 = 3b^2, so 3∣a23 \mid a^2. By Exercise 1, a square that is divisible by 3 comes from n=3kn = 3k, so 3∣a3 \mid a: write a=3ca = 3c. Then 9c2=3b29c^2 = 3b^2, so b2=3c2b^2 = 3c^2 and 3∣b3 \mid b. Both aa and bb are divisible by 3: contradiction. ■\blacksquare

Exercise 3: No largest even number

Prove by contradiction that there is no largest even integer.

Answer

If mm were the largest, m+2m + 2 is even and larger.

Solution

Suppose mm is the largest even integer, m=2km = 2k. Then m+2=2(k+1)m + 2 = 2(k + 1) is even and m+2>mm + 2 > m, contradicting the choice of mm. ■\blacksquare

Exercise 4: Five people are not enough (code)

Find a friendship pattern among 5 people with no 3 mutual friends and no 3 mutual strangers.

Answer

The pentagon: person ii knows i±1 mod 5i \pm 1 \bmod 5 and nobody else.

Solution
python · try it yourself
from itertools import combinations

knows = lambda a, b: (a - b) % 5 in (1, 4)
bad = [t for t in combinations(range(5), 3)
       if len({knows(t[0], t[1]), knows(t[0], t[2]), knows(t[1], t[2])}) == 1]
print("monochromatic trios in the pentagon:", bad)
monochromatic trios in the pentagon: []

Test yourself

What must be true of the cases in a proof by cases?

  1. They must not overlap
  2. Together they must cover every possibility
  3. There must be exactly two
  4. Each must be proved by contradiction

In Euclid's proof, why can't N=p1⋯pk+1N = p_1 \cdots p_k + 1 be divisible by any pip_i?

  1. Because NN is prime
  2. Because NN leaves remainder 1 when divided by each pip_i
  3. Because NN is even
  4. Because NN is a perfect square

To prove PP by contradiction, you start by assuming…

  1. PP
  2. ¬P\neg P
  3. P→QP \to Q
  4. nothing