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 , is even.
Proof. Case 1: is even, . Then . Case 2: is odd, . Then . Every integer is even or odd, so the cases are exhaustive.
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 . Of the other 5, at least 3 know or at least 3 do not (cases!). Say all know . If any two of know each other, they form a trio with . Otherwise are three mutual strangers. The other case is symmetric.
Here the "for any group" claim covers possible friendship patterns among 6 people (15 pairs), few enough to check by computer as well.
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 , assume and derive a statement that is false (a contradiction, such as , or ). Since true statements only lead to true statements, must be false, so is true.
Theorem. is irrational.
Proof. Suppose, for contradiction, that for integers with , and that the fraction is in lowest terms (no common factor). Squaring gives , so is even, so is even (previous lesson): . Then , so , and is even too. Now and share the factor 2, contradicting lowest terms.
Theorem (Euclid). There are infinitely many primes.
Proof. Suppose there are only finitely many, . Let . has some prime factor , and must be one of the . But dividing by any leaves remainder 1, so no divides . Contradiction.
Note that itself need not be prime. The proof only needs a prime that is missing from the list.
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 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 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 , is 0 or 1.
Answer
Cases , , give .
Solution
Every integer has one of these three forms.
Exercise 2: Irrationality of
Prove that is irrational.
Answer
Same pattern as , using "if then ".
Solution
Suppose in lowest terms. Then , so . By Exercise 1, a square that is divisible by 3 comes from , so : write . Then , so and . Both and are divisible by 3: contradiction.
Exercise 3: No largest even number
Prove by contradiction that there is no largest even integer.
Answer
If were the largest, is even and larger.
Solution
Suppose is the largest even integer, . Then is even and , contradicting the choice of .
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 knows and nobody else.
Solution
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?
- They must not overlap
- Together they must cover every possibility
- There must be exactly two
- Each must be proved by contradiction
In Euclid's proof, why can't be divisible by any ?
- Because is prime
- Because leaves remainder 1 when divided by each
- Because is even
- Because is a perfect square
To prove by contradiction, you start by assuming…
- nothing