The Well Ordering Principle
The Well Ordering Principle (WOP) says:
Every non-empty set of non-negative integers has a smallest element.
It sounds obvious, and it is: but it is also a powerful proof tool, closely related to induction. It fails for other number sets. The integers have no smallest element, and neither do the positive rationals: for any , is smaller.
The template: a smallest counterexample
To prove for all :
- Suppose, for contradiction, that the set of counterexamples is non-empty.
- By the WOP, has a smallest element .
- Use to find a smaller counterexample (or show holds anyway). Contradiction.
- So is empty and holds for all .
Theorem. For all : .
Proof. Suppose some fails, and let be the smallest failure. , because the formula holds at 0 (both sides are 0). So , and is not a failure by minimality:
Add to both sides: the right side becomes , so the formula holds at after all. Contradiction.
Lowest terms exist
The proof that is irrational assumed a fraction can be written in lowest terms. WOP justifies it: among all ways of writing with positive denominator, the set of denominators is a non-empty set of positive integers, so it has a smallest member . If were not in lowest terms, dividing both by a common factor would give a smaller denominator. Python's Fraction always stores this minimal form.
from fractions import Fraction
from math import gcd
a, b = 84, 120
g = gcd(a, b)
print(f"{a}/{b} -> {a // g}/{b // g} (divided by gcd {g})")
print("Fraction stores:", Fraction(a, b))84/120 -> 7/10 (divided by gcd 12)
Fraction stores: 7/10
Every integer greater than 1 is a product of primes
Theorem. Every integer is a product of one or more primes.
Proof. Let be the set of integers that are not products of primes, and suppose is non-empty. Its smallest element is not prime (a prime is a product of one prime). So with . Since , they are not in : each is a product of primes. Then is a product of primes too. Contradiction.
The proof contains an algorithm: keep splitting a composite number into two smaller factors until only primes remain. Termination is guaranteed because the numbers keep getting smaller, and you cannot go down forever in .
def split(n):
"""Factor n by repeatedly splitting off the smallest divisor."""
for d in range(2, int(n ** 0.5) + 1):
if n % d == 0:
return split(d) + split(n // d)
return [n] # no divisor found: n is prime
for n in [12, 97, 360, 1001, 2 ** 10 - 1]:
print(n, "=", " * ".join(map(str, split(n))))12 = 2 * 2 * 3
97 = 97
360 = 2 * 2 * 2 * 3 * 3 * 5
1001 = 7 * 11 * 13
1023 = 3 * 11 * 31
Termination arguments
The same idea proves that loops and recursions stop. If every step of a process decreases a non-negative integer (a variant or measure), the process cannot run forever: otherwise the set of values it visits would have no smallest element. Euclid's algorithm terminates because the second argument strictly decreases; the recursive split above terminates because decreases.
Exercises
Exercise 1: A sum formula by WOP
Use the smallest-counterexample template to prove for all .
Answer
If is the smallest failure, , the formula holds for , and adding gives : contradiction.
Solution
At both sides equal 1, so the smallest failure satisfies . By minimality, . Adding the next odd number:
So is not a failure. Contradiction: there is no failure.
Exercise 2: Where WOP fails
Show that the set has no smallest element.
Answer
For any positive rational , is a smaller positive rational.
Solution
Suppose were the smallest. is rational, positive, and . Contradiction. So WOP is special to sets of non-negative integers (and sets that look like them).
Exercise 3: Postage with 3 and 5 (code + proof idea)
Check in Python that every amount from 8 to 100 cents can be paid with 3-cent and 5-cent stamps. Then explain with WOP why it works for all .
Answer
The check passes. If were the smallest failure, works, and one more 3-cent stamp pays .
Solution
def payable(n):
return any((n - 5 * f) % 3 == 0 for f in range(n // 5 + 1))
print(all(payable(n) for n in range(8, 101)))
print("not payable below 8:", [n for n in range(1, 8) if not payable(n)])True
not payable below 8: [1, 2, 4, 7]
8, 9 and 10 work directly (, , ). Let be the smallest failure ; then , so is payable by minimality, and adding a 3-cent stamp pays . Contradiction.
Test yourself
Which set has a smallest element?
- the positive rationals
- the negative integers
In a WOP proof, after picking the smallest counterexample , what do you usually show?
- That is prime
- That a smaller counterexample exists or that is not a counterexample
- That
- That is even
Why does a loop that strictly decreases a non-negative integer each iteration terminate?
- Because computers are finite
- Because an infinite strictly decreasing sequence of natural numbers would have no smallest element
- Because of floating point
- It might not terminate