3.5. Primes and unique factorisation
We have already proved that every positive integer factors into primes.
But we have not yet proved that the factorisation is unique.
It can sometimes be hard to explain to people what the issue is here.
Let me attempt to do so. Say p<q<r<s are prime numbers.
Say that you are only allowed to use the definition of a prime number (that its only factors are 1 and itself).
How do you deduce from this that ps\neq qr?
The problem is that ps and qr are both probably bigger than p,q,r,s,
so the definition of a prime number (which only tells you things about numbers less than the prime) isn't much help.
The following crucial lemma gets us out of this mess.
Theorem 54 (Euclid's lemma)
If p is prime and if a,b are natural numbers, and if p\mid ab, then p\mid a or p\mid b.
See problem sheet 2 for a demonstration of how this and other ideas do not generalise away from primes.
Proof
Assume p is prime and p\mid ab.
Let's assume the p\nmid a, and we'll show that p\mid b.
What can we say about gcd(p,a)?
Certainly it divides p, which means that it must be 1 or p, because p is prime.
But it can't be p because p\nmid a.
Hence it's 1.
Thus by Corollary 53 there exist integers \lambda and \mu such that \lambda a+\mu p=1.
Multiplying both sides by b we deduce \lambda ab + \mu p b=b.
But p divides ab and hence p divides the left hand side of this equality,
so p divides the right hand side, which is b.
Corollary 55
If p is prime and if a_1,a_2,\ldots,a_n are natural numbers, and if p\mid a_1a_2\ldots a_n then p divides one of the a_i.
Proof
Induction on n\geq1.
The base case n=1 has p\mid a_1 as an assuption, so we're done.
For the inductive step assume that if p\mid a_1a_2\ldots a_n then p divides one of the a_i,
and we have to deduce that if p\mid a_1a_2\ldots a_na_{n+1}=(a_1a_2\ldots a_n)a_{n+1} then it divides one of the a_i.
By Euclid's lemma (Theorem 54) we know p divides either a_1a_2\ldots a_n or a_{n+1}.
If p divides a_{n+1} we're done immediately, and if p divides a_1a_2\ldots a_n then we're done by the inductive hypothesis.
Theorem 56 (Uniqueness of prime factorisation)
Every positive integer is uniquely the product of prime numbers, up to re-ordering.
Proof
We have already shown that every positive integer can be written as the product of primes in Proposition 32.
What is left to show that if
n=p_1p_2\ldots p_r=q_1q_2\ldots q_s
with the p_i and the q_j all prime numbers,
then r=s and after possibly re-ordering the q_i, we have p_i=q_i for all i.
Let's prove this by strong induction on n.
Suppose we have established this uniqueness result for all nonzero natural numbers smaller than n.
Now let n=p_1p_2\ldots p_r=q_1q_2\ldots q_s be two prime factorisations of n.
By switching the p's and q's if necessary, we can assume r\leq s.
If r=0 then p_1p_2\ldots p_r=1 (the product of no things is 1),
so n=1, so q_1q_2\ldots q_s=1 meaning that s must also be 0 (because if s\geq1 then q_1q_2\ldots q_s>1).
Therefore the r-factorisation and the s-factorisation are both empty, and so are equal.
If however r\geq1 then consider the last prime p_r on the left hand side.
It divides p_1p_2\ldots p_r, so it divides q_1q_2\ldots q_s.
By Corollary 55, p_r must divide one of the q_i.
By rearranging the q_i we can assume that it's q_s.
But the only divisors of q_s are 1 and q_s, because q_s is prime.
Hence p_r=q_s, meaning that we can cancel and get p_1p_2\ldots p_{r-1}=q_1q_2\ldots q_{s-1}.
This number is less than n, so by the inductive hypothesis, its prime factorisation is unique;
it follows that its factorisations p_1p_2\ldots p_{r-1} and q_1q_2\ldots q_{s-1} agree up to re-ordering.
Therefore the factorisations p_1p_2\ldots p_{r} and q_1q_2\ldots q_{s} of n also agree up to re-ordering.
Something else we can do with subtraction is to prove that the quotient and remainder whose existence we proved in Definition 27 and Proposition 28 are unique! In fact we can extend the quotient-remainder result to integers, as long as the integer we're dividing by is positive.
Proposition 57 (quotient-remainder for integers)
If a is an integer and b is a positive integer, there exists integers q and r with 0\leq r<b and a=qb+r.
Proof
See problem sheet 2.
Note that b is positive and the remainder r is non-negative even if a is negative.
For example if we divide -37 by 10 using this method, we get q=-4 and r=3.
Theorem 58 (uniqueness of quotient and remainder)
If a is an integer, b is a positive integer, and a=qb+r=q'b+r' with 0\leq r,r'<b then q=q' and r=r'.
Proof
By swapping q,r with q',r' if necessary, we can assume r\leq r'. Now subtracting the equations gives (q-q')b=r'-r, so r'-r is a multiple of b.
But it's \geq 0 and <b, so it can't be b\times S(x) because this is bx+b\geq b and hence too big.
So it must be b\times 0, meaning r=r'.
Hence qb=q'b and because b\neq0 we deduce q=q' from the fact that you can cancel multiplication by non-zero naturals
(this needs a proof: see problem sheets 1 and 2!)