Lecture 9: reciprocals in modular arithmetic, key exchange, induction, Fundamental Theorem of Arithmetic, Euclid’s infinitude of primes [01EP]
- October 20, 2026
- Marcelo Fiore, Jon Sterling
These lecture notes were prepared by Jon Sterling using Marcelo Fiore’s lectures as source material. Any mistakes were introduced by Jon Sterling. Generative AI was not used to write these lecture notes.
Reciprocals in modular arithmetic [01EY]
- October 28, 2026
- Marcelo Fiore, Jon Sterling
Corollary Linear coefficients of the gcd and reciprocals of modular integers [01EZ]
- October 28, 2026
- Marcelo Fiore, Jon Sterling
For all positive integers m and n,
- n\cdot \operatorname {lc}_2{\mathopen {}\left (m,n\right )\mathclose {}} \equiv \gcd {\mathopen {}\left (m,n\right )\mathclose {}}\mod m, and
- whenever m and n are coprime (i.e. \gcd {\mathopen {}\left (m,n\right )\mathclose {}}=1), the modular normal form {\mathopen {}\left [\operatorname {lc}_2{\mathopen {}\left (m,n\right )\mathclose {}}\right ]\mathclose {}}_m is the reciprocal of {\mathopen {}\left [n\right ]\mathclose {}}_m in \mathbb {Z}_m.
After attempting to prove this yourself, you may click this text to see my proof.
Proof.
- October 28, 2026
- Marcelo Fiore, Jon Sterling
The first proposition is seen to hold by definition. Indeed: \gcd {\mathopen {}\left (m,n\right )\mathclose {}} = \operatorname {lc}_1{\mathopen {}\left (m,n\right )\mathclose {}}\cdot m+\operatorname {lc}_2{\mathopen {}\left (m,n\right )\mathclose {}}\cdot n so we have \gcd {\mathopen {}\left (m,n\right )\mathclose {}} - \operatorname {lc}_2{\mathopen {}\left (m,n\right )\mathclose {}}\cdot n = \operatorname {lc}_1{\mathopen {}\left (m,n\right )\mathclose {}}\cdot m and hence m \mid {\mathopen {}\left ( \gcd {\mathopen {}\left (m,n\right )\mathclose {}} - n\cdot \operatorname {lc}_2{\mathopen {}\left (m,n\right )\mathclose {}}\right )\mathclose {}} which is identical to the claim by definition of congruence.
For the second proposition, we assume \gcd {\mathopen {}\left (m,n\right )\mathclose {}} = 1 and we must prove {\mathopen {}\left [\operatorname {lc}_2{\mathopen {}\left (m,n\right )\mathclose {}}\right ]\mathclose {}}_m \cdot _m {\mathopen {}\left [n\right ]\mathclose {}}_m = 1 which is equivalent to \operatorname {lc}_2{\mathopen {}\left (m,n\right )\mathclose {}}\cdot n \equiv 1\mod m and, by assumption, to \operatorname {lc}_2{\mathopen {}\left (m,n\right )\mathclose {}}\cdot n \equiv \gcd {\mathopen {}\left (m,n\right )\mathclose {}}\mod m\text {.}
By definition, we must show that m\mid {\mathopen {}\left (\gcd {\mathopen {}\left (m,n\right )\mathclose {}}-\operatorname {lc}_2{\mathopen {}\left (m,n\right )\mathclose {}}\cdot n\right )\mathclose {}}, which is immediate because \gcd {\mathopen {}\left (m,n\right )\mathclose {}}-\operatorname {lc}_2{\mathopen {}\left (m,n\right )\mathclose {}}\cdot n = \operatorname {lc}_1{\mathopen {}\left (m,n\right )\mathclose {}}\cdot m.
Remark Reciprocals in the modular integers [01F1]
- October 28, 2026
- Marcelo Fiore, Jon Sterling
For every pair of positive integers m and n, the modular normal form {\mathopen {}\left [n\right ]\mathclose {}}_m has a reciprocal in the modular integers \mathbb {Z}_m if and only if m and n are coprime.
Key exchange and encryption [01F2]
- October 28, 2026
- Marcelo Fiore, Jon Sterling
Although one may (and should!) learn elementary number theory for love of the game, it actually has some “practical” applications. One of these is cryptography. We will see how modular arithmetic may be used to agree upon a private key over an insecure line, via the Diffie–Hellman protocol; another application is Shamir’s three-pass protocol, which uses Fermat’s Little Theorem to privately send messages without exchanging keys.
The Diffie–Hellman key-exchange protocol [01F4]
- October 29, 2026
- Marcelo Fiore, Jon Sterling
First some pre-mathematical intuition:
Illustration Intuition for the Diffie–Hellman key exchange protocol [01F3]
- October 29, 2026
In the illustration, paint colours are used as a metaphor for numerical data; the mixing of paint is a metaphor for applying efficiently computable arithmetic operations to numbers that are prohibitively difficult to undo. It is important, above, that mixing of paints is a commutative operation, since otherwise Alice and Bob would not end up with the same secret colour. Modular arithmetic provides one source of such operations: modular exponentiation is easy to compute, but the inverse operation (discrete logarithm) is very hard to compute.
The Diffie–Hellman protocol, formally [01F7]
- October 29, 2026
- Marcelo Fiore, Jon Sterling
In this protocol, Alice and Bob will agree upon a shared secret key by communicating in public.
- In public, Alice and Bob agree upon an integer c and a prime p.
- Privately, Alice chooses her own prive key \mathsf {priv}_{A} and Bob separately decides upon his own private key \mathsf {priv}_{B}.
- Individually, Alice and Bob define public keys as follows by modular exponentiation using their private keys: \begin {aligned} \mathsf {pub}_{X} \coloneqq {\mathopen {}\left [c^{\mathsf {priv}_{X}}\right ]\mathclose {}}_p \quad {\mathopen {}\left (X\in {\mathopen {}\left \{A,B\right \}\mathclose {}}\right )\mathclose {}} \end {aligned}
- In public, Alice and Bob then transmit to each other their public keys.
- In private, Alice and Bob both compute their own copies of the shared secret key as follows: \begin {aligned} K_A&\coloneqq {\mathopen {}\left [\mathsf {pub}_{B}^{\mathsf {priv}_{A}}\right ]\mathclose {}}_p \\ K_B&\coloneqq {\mathopen {}\left [\mathsf {pub}_{A}^{\mathsf {priv}_{B}}\right ]\mathclose {}}_p \end {aligned}
Finally, we show that Alice’s and Bob’s computations of the shared secret agree in the sense that K_A=K_B\text {.}
Proof.
- October 29, 2026
- Marcelo Fiore, Jon Sterling
We calculate:
\begin {aligned} K_A &\equiv \mathsf {pub}_{B}^{\mathsf {priv}_{A}} &&\mod p \\ &\equiv {\mathopen {}\left (c^{\mathsf {priv}_{B}}\right )\mathclose {}}^{\mathsf {priv}_{A}} &&\mod p \\ &\equiv c^{\mathsf {priv}_{B}\cdot \mathsf {priv}_{A}} &&\mod p \\ &\equiv c^{\mathsf {priv}_{A}\cdot \mathsf {priv}_{B}} &&\mod p \\ &\equiv {\mathopen {}\left (c^{\mathsf {priv}_{A}}\right )\mathclose {}}^{\mathsf {priv}_{B}} &&\mod p \\ &\equiv \mathsf {pub}_{A}^{\mathsf {priv}_{B}} &&\mod p \\ &\equiv K_B &&\mod p \end {aligned}Therefore, K_A=K_B.
Why exponentiation modulo a prime? [01F8]
- October 29, 2026
- Jon Sterling
We have already commented that modular exponentiation is easy to compute but very difficult to invert. But why don’t we do exponentiation modulo a non-prime number?
The protocol itself does not depend on the modulus being prime. To break Diffie–Hellman, you might try to compute discrete logarithms; discrete logarithms over a prime modulus is very very hard; if your modulus is composite, then the Chinese Remainder Theorem can be used to reduce the discrete logarithm problem to the prime factors of the modulus. So Diffie–Hellman over a prime modulus has only one avenue of attack: computing the discrete logarithm of a big prime. In contrast, Diffie–Hellman over a composite modulus has two avenues of attack: computing the discrete logarithm of a big number, or factoring the big number and then computing the discrete logarithms of some little primes.
Encryption and decryption via modular exponentiation [01F9]
- October 31, 2026
- Marcelo Fiore, Jon Sterling
We now consider some other additional cryptographic protocols that are based on having separate keys for encryption and for decryption. In the Diffie–Hellman protocol, each actor had just one private key, whereas we will now consider protocols in which the private keys are split into two: an encryption key and a decryption key. The relationship between encryption and decryption keys will then be governed by Fermat’s little theorem.
We are going to use modular exponentiation to model encryption and decryption. In particular, we will be considering pairs of integers {\mathopen {}\left (e,d\right )\mathclose {}} such that k^{e\cdot d} \equiv k \mod p; such a pair is an encryption-decryption pair modulo p. To find a good source of such encryption-decryption pairs, we must return to Fermat’s Little Theorem and develop some of its consequences.
Theorem Fermat’s Little Theorem [01BK]
- September 29, 2026
- Marcelo Fiore, Jon Sterling
For all natural numbers i and primes p, we have the following:
- i^p \equiv i \mod p
- i^{p-1}\equiv 1 \mod p unless i is a multiple of p
For simplicity, we had previously established Fermat’s Little Theorem only for naturals. But it holds, in fact, for all integers, which we shall need:
Corollary Fermat’s Little Theorem for integers [01FC]
- October 31, 2026
- Jon Sterling
For all integers k and primes p, we have the following:
- k^p\equiv k \mod p
- k^{p-1}\equiv 1 \mod p unless k is a multiple of p.
Proof.
- October 31, 2026
- Jon Sterling
This follows straightaway from Fermat’s Little Theorem, because every integer k is congruent to some natural i modulo p: indeed, just add p to k enough times to get into the naturals.
Then we have: k^p \equiv i^p \equiv i \equiv k \mod p and k^{p-1}\equiv i^{p-1}\equiv 1\mod p under the stated assumptions.
Corollary A useful consequence of Fermat’s Little Theorem [01FB]
- October 31, 2026
- Jon Sterling
For every natural number c, integer k, and prime p, the following identity holds modulo p:
k^{1+c\cdot {\mathopen {}\left (p-1\right )\mathclose {}}} \equiv k \mod pProof.
- October 31, 2026
- Jon Sterling
We proceed depending on whether p\mid k.
- Suppose that p\mid k. Then k \equiv 0\mod p by definition, so k^{1+c\cdot {\mathopen {}\left (p-1\right )\mathclose {}}} \equiv 0 \equiv k\mod p\text {.}
- Suppose on the other hand that p\nmid k. Then by Fermat’s Little Theorem for integers, we have k^{p-1}\equiv 1 \mod p. We therefore deduce k^{1+c\cdot {\mathopen {}\left (p-1\right )\mathclose {}}} \equiv k \mod p by elementary equational reasoning as follows: \begin {aligned} k^{1+c\cdot {\mathopen {}\left (p-1\right )\mathclose {}}} &= k\cdot k^{c\cdot {\mathopen {}\left (p-1\right )\mathclose {}}} \\ &= k\cdot {\mathopen {}\left (k^{p-1}\right )\mathclose {}}^c \\ &\equiv k \cdot 1^c &&\mod p \\ &= k \end {aligned}
Lemma A good condition for encryption-decryption key pairs [01FD]
- October 31, 2026
- Jon Sterling
By Corollary [01FB], for prime p every pair {\mathopen {}\left (e,d\right )\mathclose {}} of positive integers such that e\cdot d \equiv 1 \mod p-1 is an encryption-decryption key pair modulo p in the sense that \forall k:\mathbb {Z}\mathpunct {.} k^{e\cdot d} \equiv k \mod p\text {.}
Proof.
- October 31, 2026
- Jon Sterling
That e\cdot d is congruent to 1 modulo p-1 is equivalent to the existence of some c:\mathbb {Z} such that e\cdot d = 1+c\cdot {\mathopen {}\left (p-1\right )\mathclose {}}:
\begin {aligned} &e\cdot d \equiv 1 \mod p - 1 \\ &\Longleftrightarrow {\mathopen {}\left (p-1\right )\mathclose {}}\mid {\mathopen {}\left (e\cdot d - 1\right )\mathclose {}} \\ &\Longleftrightarrow \exists c:\mathbb {Z}\mathpunct {.} c\cdot {\mathopen {}\left (p-1\right )\mathclose {}} = e\cdot d - 1 \\ &\Longleftrightarrow \exists c:\mathbb {Z}\mathpunct {.} 1+ c\cdot {\mathopen {}\left (p-1\right )\mathclose {}} = e\cdot d \end {aligned}Because d,e are positive, we know that e\cdot d - 1 is non-negative and hence any such c is also non-negative, so we have c\in \mathbb {N}.
Now, we fix an integer k to check that k^{e\cdot d} \equiv k\mod p, which follows below from Corollary [01FB]:
k^{e\cdot d} = k^{1+c\cdot {\mathopen {}\left (p-1\right )\mathclose {}}}\equiv k \mod p\text {.}{}Lemma A good source of encryption-decryption key pairs [01FE]
- October 31, 2026
- Marcelo Fiore, Jon Sterling
Let p be prime and let e be a positive integer coprime with p-1. Define d \coloneqq {\mathopen {}\left [\operatorname {lc}_2{\mathopen {}\left (p-1,e\right )\mathclose {}}\right ]\mathclose {}}_{p-1}\text {.}
Then for all integers k we have k^{e\cdot d}\equiv k \mod p.
Proof.
- October 31, 2026
- Marcelo Fiore, Jon Sterling
That e and p-1 are coprime means that their greatest common divisor is 1. Meanwhile, we recall the representation of greatest common divisors as integer linear combinations, so that we have:
\begin {aligned} 1 &= \gcd {\mathopen {}\left (p-1,e\right )\mathclose {}} \\ &= {\mathopen {}\left (p-1\right )\mathclose {}}\cdot \operatorname {lc}_1{\mathopen {}\left (p-1,e\right )\mathclose {}} + e\cdot \operatorname {lc}_2{\mathopen {}\left (p-1,e\right )\mathclose {}} \\ &\equiv {\mathopen {}\left (p-1\right )\mathclose {}}\cdot \operatorname {lc}_1{\mathopen {}\left (p-1,e\right )\mathclose {}} + e\cdot d &&\mod p-1 \\ &\equiv 0 \cdot \operatorname {lc}_1{\mathopen {}\left (p-1,e\right )\mathclose {}} + e\cdot d &&\mod p - 1 \\ &\equiv e\cdot d &&\mod p-1 \end {aligned}As e\cdot d\equiv 1 \mod p -1, we deduce via Lemma [01FD] that k^{e\cdot d}\equiv k for all integers k.
Example Shamir’s three-pass protocol [01F6]
- October 29, 2026
- Marcelo Fiore, Jon Sterling
Whereas Diffie-Hellman is a way for two actors to agree upon a secret key that neither of them started with, Shamir’s three-pass protocol is a way for one actor to securely send secret information to another. Here is how Alice would send a secret integer k<p to Bob without anyone else being able to intercept it:
- In public, Alice and Bob agree upon a prime p.
- In private, Alice choose a key pair (e_A,d_A) satisfying d_A\cdot e_A\equiv 1 \mod p-1. Bob similarly chooses a key pair (e_B,d_B) satisfying the same property.
- Alice encrypts k as the modular exponentiation {\mathopen {}\left [k^{e_A}\right ]\mathclose {}}_p, and sends it to Bob.
- Bob then encrypts the received value as {\mathopen {}\left [k^{e_A\cdot e_B}\right ]\mathclose {}}_p , and the result back to Alice.
- Alice decrypts the received value as {\mathopen {}\left [k^{e_A\cdot e_B\cdot d_A}\right ]\mathclose {}}_p and sends it back to Bob.
- Finally, Bob decrypts the received value as {\mathopen {}\left [k^{e_A\cdot e_B\cdot d_A\cdot d_B}\right ]\mathclose {}}_p \equiv k^{e_A\cdot e_B\cdot d_A\cdot d_B} \equiv {\mathopen {}\left (k^{e_A\cdot d_A}\right )\mathclose {}}^{e_B\cdot d_B} \equiv k\mod p\text {.} Because k<p, Bob’s final decrypted value is equal to k.
Lemma Encryption/decryption in RSA [01FF]
- October 31, 2026
- Marcelo Fiore, Jon Sterling
Let p,q be distinct primes and let d,e be positive integers such that e\cdot d \equiv 1 \mod {\mathopen {}\left (p-1\right )\mathclose {}}\cdot {\mathopen {}\left (q-1\right )\mathclose {}}. Then for all integers k, we have k^{e\cdot d} \equiv k \mod p\cdot q\text {.}
With what you are expected to know at this point, you would not be able to prove this theorem. I will cheat and use the Chinese Remainder Theorem, which we regrettably will not teach you in this course.
Proof.
- October 31, 2026
- Marcelo Fiore, Jon Sterling
By our assumptions that d,e are positive and that e\cdot d\equiv 1 \mod {\mathopen {}\left (p-1\right )\mathclose {}}\cdot {\mathopen {}\left (q-1\right )\mathclose {}}, we may choose a natural number c such that e\cdot d = 1 + c\cdot {\mathopen {}\left (p-1\right )\mathclose {}}\cdot {\mathopen {}\left (q-1\right )\mathclose {}}.
Because any two distinct primes are coprime, to verify k^{e\cdot d}\equiv k \mod p\cdot q it suffices by the Chinese Remainder Theorem to show that k^{e\cdot d}\equiv k \mod p and k^{e\cdot d}\equiv k \mod q. To that end, we make a few observations:
- If r\mid k, then k^{e\cdot d} \equiv k\mod r for any natural number r. This is immediate as e,d are positive.
- If p\nmid k then k^{e\cdot d}\equiv k \mod p, and similarly if q\nmid k then k^{e\cdot d}\equiv k\mod q. Without loss of generality, we consider just the first case, where we calculate using Fermat’s little theorem for integers: \begin {aligned} k^{e\cdot d} &= k^{1+c\cdot {\mathopen {}\left (p-1\right )\mathclose {}}\cdot {\mathopen {}\left (q-1\right )\mathclose {}}} \\ &= k\cdot {\mathopen {}\left (k^{p-1}\right )\mathclose {}}^{c\cdot {\mathopen {}\left (q-1\right )\mathclose {}}} \\ &\equiv k\cdot 1&&\mod p\\ &= k \end {aligned}
We now conclude that both k^{e\cdot d}\equiv k \mod p and k^{e\cdot d}\equiv k \mod q hold by cases on whether p\mid k and whether q\mid k.
Natural numbers and mathematical induction [01FG]
- October 31, 2026
- Marcelo Fiore, Jon Sterling
Several lectures ago, we introduced the natural numbers and identified two distinct ways of thinking about them: as a subset of the integers, and in their own terms as an algebra generated from a single element by successive increments. The latter description endows the naturals with their main reasoning principle, that of mathematical induction.
Principle of Mathematical Induction [01FH]
- October 31, 2026
- Marcelo Fiore, Jon Sterling
Let P be a predicate ranging over the natural numbers, so that P{\mathopen {}\left (n\right )\mathclose {}} is a statement for each n:\mathbb {N}. If:
- the statement P{\mathopen {}\left (0\right )\mathclose {}} holds, and
- the statement \forall n:\mathbb {N}\mathpunct {.} {\mathopen {}\left (P{\mathopen {}\left (n\right )\mathclose {}}\implies P{\mathopen {}\left (n+1\right )\mathclose {}}\right )\mathclose {}} also holds,
Equivalent formulation of mathematical induction [01FI]
- October 31, 2026
- Jon Sterling
Let S\subseteq \mathbb {N} be a subset of the natural numbers. If 0\in S and \forall n\in S\mathpunct {.} n+1\in S holds, then S = \mathbb {N}.
Justification.
- October 31, 2026
- Jon Sterling
This is a special case of ordinary mathematical induction, because given a subset S\subseteq \mathbb {N} we may consider the predicate P{\mathopen {}\left (n\right )\mathclose {}}={\mathopen {}\left (n\in S\right )\mathclose {}}. Conversely, given a predicate P we may consider the subset comprehension {\mathopen {}\left \{x:\mathbb {N}\,\middle \vert \,P{\mathopen {}\left (x\right )\mathclose {}}\right \}\mathclose {}}.
It is sometimes more intuitive to think about things in terms of subsets, and vice versa.
A proof pattern for using mathematical induction [01FJ]
- October 31, 2026
- Marcelo Fiore, Jon Sterling
If your goal is to prove \forall n:\mathbb {N}\mathpunct {.} P{\mathopen {}\left (n\right )\mathclose {}} and you plan to use mathematical induction to prove it, then you should literally do exactly as I say below on your paper:
- Write “To prove that P holds for all n:\mathbb {N}, we will use mathematical induction”. You must make clear exactly what predicate P you are proving by induction. If you don’t, I will assume you don’t know.
- Write “In the base case, we show that P{\mathopen {}\left (0\right )\mathclose {}} holds by…” (and fill in the proof).
- Write “In the inductive step, we show that for all n:\mathbb {N}, if P{\mathopen {}\left (n\right )\mathclose {}} holds then P{\mathopen {}\left (n+1\right )\mathclose {}} holds.” (And then give a proof of that claim.) When proving this, you may refer to the assumption that P{\mathopen {}\left (n\right )\mathclose {}} holds as your induction hypothesis.
- Write “We conclude that P{\mathopen {}\left (n\right )\mathclose {}} holds for all n.”
Example Proving the binomial theorem by mathematical induction [01FM]
- October 31, 2026
- Marcelo Fiore, Jon Sterling
Theorem The Binomial Theorem [01BG]
- September 29, 2026
- Marcelo Fiore, Jon Sterling
Let x,y be elements of a commutative semiring {\mathopen {}\left (A,+,0,\cdot ,1\right )\mathclose {}}. For all n\in \mathbb {N}, we have {\mathopen {}\left (x+y\right )\mathclose {}}^n = \sum _{k=0}^n \binom {n}{k}\cdot x^{n-k}\cdot y^k \text {.}
Lemma A useful identity for binomial coefficients [01FL]
- October 31, 2026
- Marcelo Fiore
For any natural numbers n and k, we have \binom {n+1}{k} = \binom {n}{k} + \binom {n}{k-1}
After attempting to prove this yourself, you may click this text to see my proof.
Proof.
- October 31, 2026
- Marcelo Fiore
The combination on the left represents the process of choosing k members of a set of n+1 elements. There are two possibilities:
- We ignore the last element, so we in fact choose k elements from among n elements.
- We do choose the last element, and so it remains to choose k-1 elements from among the remaining n elements.
Summing these two possibilities gives exactly the right-hand side.
Proof of the binomial theorem [01FK]
- October 31, 2026
- Marcelo Fiore, Jon Sterling
Let x,y be elements of a commutative semiring {\mathopen {}\left (A,+,0,\cdot ,1\right )\mathclose {}}. We let P be the following predicate on the natural numbers:
P{\mathopen {}\left (n\right )\mathclose {}} \Longleftrightarrow {\mathopen {}\left (x+y\right )\mathclose {}}^n = \sum _{k=0}^n \binom {n}{k}\cdot x^{n-k}\cdot y^kWe will prove \forall n:\mathbb {N}\mathpunct {.} P{\mathopen {}\left (n\right )\mathclose {}} using the principle of mathematical induction.
- In the base case, we verify P{\mathopen {}\left (0\right )\mathclose {}} as follows: {\mathopen {}\left (x+y\right )\mathclose {}}^0 = 1 = \binom {0}{0}\cdot x^0\cdot y^0 = \sum _{k=0}^0 \binom {0}{k}\cdot x^{0-k}\cdot y^k
- In the inductive step, we fix n:\mathbb {N} and assume that {\mathopen {}\left (x+y\right )\mathclose {}}^n = \sum _{k=0}^n \binom {n}{k}\cdot x^{n-k} \cdot y^k and we must prove {\mathopen {}\left (x+y\right )\mathclose {}}^{n+1} = \sum _{k=0}^{n+1} \binom {n+1}{k}\cdot x^{{\mathopen {}\left (n+1\right )\mathclose {}}-k} \cdot y^k \text {.} We calculate as follows: \begin {aligned} &\sum _{k=0}^{n+1}\binom {n+1}{k}\cdot x^{{\mathopen {}\left (n+1\right )\mathclose {}}-k}\cdot y^k \\ &\quad = x^{n+1} + {\mathopen {}\left ( \sum _{k=1}^n \binom {n+1}{k}\cdot x^{n-k+1}\cdot y^k \right )\mathclose {}} + y^{n+1} \end {aligned} Now we apply a useful identity: \begin {aligned} &\quad = x^{n+1} + {\mathopen {}\left ( \sum _{k=1}^n {\mathopen {}\left (\binom {n}{k}+\binom {n}{k-1}\right )\mathclose {}} \cdot x^{n-k+1}\cdot y^k \right )\mathclose {}} + y^{n+1} \\ &\quad = x^{n+1}+{\mathopen {}\left ( \sum _{k=1}^n \binom {n}{k} \cdot x^{n-k+1} \cdot y^k \right )\mathclose {}}+{\mathopen {}\left ( \sum _{k=1}^n \binom {n}{k-1} \cdot x^{n-k+1} \cdot y^k \right )\mathclose {}} + y^{n+1} \\ &\quad = {\mathopen {}\left ( \sum _{k=0}^n \binom {n}{k} \cdot x^{n-k+1} \cdot y^k \right )\mathclose {}}+{\mathopen {}\left ( \sum _{j=0}^n \binom {n}{j} \cdot x^{n-j} \cdot y^{j+1} \right )\mathclose {}} \\ &\quad = x\cdot {\mathopen {}\left ( \sum _{k=0}^n \binom {n}{k} \cdot x^{n-k} \cdot y^k \right )\mathclose {}} + y\cdot {\mathopen {}\left ( \sum _{j=0}^n \binom {n}{j} \cdot x^{n-j} \cdot y^{j} \right )\mathclose {}} \\ &\quad = {\mathopen {}\left (x+y\right )\mathclose {}}\cdot \sum _{i=0}^n\binom {n}{i}\cdot x^{n-i}\cdot y^i \end {aligned} By our induction hypothesis, we have: \begin {aligned} {\mathopen {}\left (x+y\right )\mathclose {}}\cdot \sum _{i=0}^n\binom {n}{i}\cdot x^{n-i}\cdot y^i &= {\mathopen {}\left (x+y\right )\mathclose {}}\cdot {\mathopen {}\left (x+y\right )\mathclose {}}^n \\ &= {\mathopen {}\left (x+y\right )\mathclose {}}^n \end {aligned}
Replacing unrigorous “iteration” with induction [01FN]
- October 31, 2026
- Marcelo Fiore, Jon Sterling
Recall below our proof of the many dropout lemma, which was one of the ingredients to Fermat’s little theorem:
Proposition The Many Dropout Lemma [01BJ]
- September 29, 2026
- Marcelo Fiore, Jon Sterling
For all natural numbers m and i and primes p, we have (m+i)^p \equiv m^p+i\mod p\text {.}
Proof.
- September 29, 2026
- Marcelo Fiore, Jon Sterling
We note that any natural number i may be rewritten as a sum of ones:
i = \sum _{k=1}^i 1Therefore by i-many applications of the dropout lemma, we have (m+i)^p \equiv m^p + \sum _{k=1}^i1 \equiv m^p + i \mod p\text {.}
In the proof above, where we say “by i-many applications of the dropout lemma, we have…” we were a bit unrigorous. If someone asks you what is going on there, you might say, “Think about it! It’s true!” but that is not a rigorous proof. To give a rigorous proof, we use mathematical induction.
Proof A rigorous proof of the many dropout lemma [01FO]
- October 31, 2026
- Marcelo Fiore, Jon Sterling
We fix a natural number m and a prime p. Let P be the following predicate on the naturals:
P{\mathopen {}\left (i\right )\mathclose {}} \Longleftrightarrow {\mathopen {}\left (m+i\right )\mathclose {}}^p \equiv m^p + i \mod pWe will prove that P holds for all i:\mathbb {N} using the principle of mathematical induction.
- In the base case, we see that P{\mathopen {}\left (0\right )\mathclose {}} holds immediately because {\mathopen {}\left (m+0\right )\mathclose {}}^p = m^p = m^p+0.
- In the inductive step, we fix i: \mathbb {N} such that P{\mathopen {}\left (i\right )\mathclose {}} holds and we must show P{\mathopen {}\left (i+1\right )\mathclose {}}. In other words, we assume {\mathopen {}\left (m+i\right )\mathclose {}}^p \equiv m^p+i \mod p and must show {\mathopen {}\left (m+i+1\right )\mathclose {}}^p\equiv m^p+i+1 \mod p\text {.} Using the dropout lemma followed by our induction hypothesis, we have: \begin {aligned} {\mathopen {}\left (m+i+1\right )\mathclose {}}^p &\equiv {\mathopen {}\left (m+i\right )\mathclose {}}^p+1 &&\mod p \\ &\equiv m^p+i+1 &&\mod p \end {aligned}
Derived induction principles [01FP]
- October 31, 2026
- Marcelo Fiore, Jon Sterling
Induction from a basis [01FQ]
- October 31, 2026
- Marcelo Fiore, Jon Sterling
Let P be a predicate ranging over natural numbers greater than or equal to a fixed natural number \ell :\mathbb {N}, so that P{\mathopen {}\left (m\right )\mathclose {}} is a meaningful statement for each for each m\geq l. How would we go about proving that P holds for all m\geq \ell ?
The trick is to extend P to a predicate over all the natural numbers by shifting the number line to start at \ell . Then ordinary mathematical induction will do the job! Define P_\ell as a predicate on the naturals as follows:
P_\ell {\mathopen {}\left (m\right )\mathclose {}} \Longleftrightarrow P{\mathopen {}\left (\ell +m\right )\mathclose {}}Evidently, proving P_\ell {\mathopen {}\left (0\right )\mathclose {}},P_\ell {\mathopen {}\left (1\right )\mathclose {}},P_\ell {\mathopen {}\left (2\right )\mathclose {}},\ldots is the same as proving P{\mathopen {}\left (\ell \right )\mathclose {}}, P{\mathopen {}\left (\ell +1\right )\mathclose {}}, P{\mathopen {}\left (\ell +2\right )\mathclose {}}, etc. We can abstract this into a new “derived” induction principle, which we will call the principle of induction from basis \ell . To do this, we notice the following logical equivalences for the base case, inductive step, and goal:
- Base case: P_\ell {\mathopen {}\left (0\right )\mathclose {}}\Longleftrightarrow P{\mathopen {}\left (\ell \right )\mathclose {}}
- Inductive step: \begin {aligned} &{\mathopen {}\left ( \forall n:\mathbb {N}\mathpunct {.} {\mathopen {}\left ( P_\ell {\mathopen {}\left (n\right )\mathclose {}}\implies P_\ell {\mathopen {}\left (n+1\right )\mathclose {}} \right )\mathclose {}} \right )\mathclose {}} \\ &\Longleftrightarrow {\mathopen {}\left ( \forall n\geq \ell \mathpunct {.} {\mathopen {}\left (P{\mathopen {}\left (n\right )\mathclose {}}\implies P{\mathopen {}\left (n+1\right )\mathclose {}}\right )\mathclose {}} \right )\mathclose {}} \end {aligned}
- Goal: {\mathopen {}\left ( \forall m:\mathbb {N}\mathpunct {.} P_\ell {\mathopen {}\left (m\right )\mathclose {}} \right )\mathclose {}} \Longleftrightarrow {\mathopen {}\left ( \forall m \geq \ell \mathpunct {.} P{\mathopen {}\left (m\right )\mathclose {}} \right )\mathclose {}}
Therefore, the principle of induction from basis \ell says that to prove \forall m \geq l\mathpunct {.} P{\mathopen {}\left (m\right )\mathclose {}} it suffices to show:
- Base case: P{\mathopen {}\left (\ell \right )\mathclose {}}, and
- Inductive step: for any n \geq l such that P{\mathopen {}\left (n\right )\mathclose {}} holds, we have P{\mathopen {}\left (n+1\right )\mathclose {}}.
Of course, when \ell =0 we just get ordinary mathematical induction.
Strong induction, from a basis [01FR]
- October 31, 2026
- Marcelo Fiore, Jon Sterling
Let P be a predicate on natural numbers greater than or equal to a fixed number l:\mathbb {N}. We now consider the following derived predicate P^\sharp , again ranging over naturals greater than or equal to \ell :
P^\sharp {\mathopen {}\left (m\right )\mathclose {}} = \forall k:{\mathopen {}\left [\ell \ldots m\right ]\mathclose {}}\mathpunct {.} P{\mathopen {}\left (k\right )\mathclose {}}We now analysis the principle of induction from basis \ell for P^\sharp solely in terms of P:
- Base case: P^\sharp {\mathopen {}\left (\ell \right )\mathclose {}}\Longleftrightarrow P{\mathopen {}\left (\ell \right )\mathclose {}}
- Inductive step \begin {aligned} &{\mathopen {}\left ( \forall n\geq \ell \mathpunct {.} {\mathopen {}\left ( P^\sharp {\mathopen {}\left (n\right )\mathclose {}} \implies P^\sharp {\mathopen {}\left (n+1\right )\mathclose {}} \right )\mathclose {}} \right )\mathclose {}} \\ &\Longleftrightarrow {\mathopen {}\left ( \forall n \geq \ell \mathpunct {.} {\mathopen {}\left (\forall k:{\mathopen {}\left [\ell \ldots n\right ]\mathclose {}}\mathpunct {.} P{\mathopen {}\left (k\right )\mathclose {}}\right )\mathclose {}} \implies P{\mathopen {}\left (n+1\right )\mathclose {}} \right )\mathclose {}} \end {aligned}
- Goal {\mathopen {}\left ( \forall m \geq \ell \mathpunct {.} P^\sharp {\mathopen {}\left (m\right )\mathclose {}} \right )\mathclose {}} \Longleftrightarrow {\mathopen {}\left ( \forall m\geq l\mathpunct {.}P{\mathopen {}\left (m\right )\mathclose {}} \right )\mathclose {}}
We call the induction principle thus derived the principle of strong induction (from basis \ell ). It says that to prove \forall m \geq l\mathpunct {.} P{\mathopen {}\left (m\right )\mathclose {}} it suffices to show:
- Base case: P{\mathopen {}\left (\ell \right )\mathclose {}}, and
- Inductive step: for any n\geq l such that P{\mathopen {}\left (k\right )\mathclose {}} holds for all k:{\mathopen {}\left [l\ldots n\right ]\mathclose {}}, we have P{\mathopen {}\left (k+1\right )\mathclose {}}.
In practice, we mainly will need strong induction from basis 0, which is just called “strong induction”.
What good is strong induction? [01FS]
- October 31, 2026
- Jon Sterling
Why would you want to use strong induction? Because sometimes in the middle of an inductive proof, you don’t have a strong enough inductive hypothesis: you want to know that P holds of some number smaller than the current index n, but you in fact only know it for n. Many students just pretend that it must also hold for all smaller numbers, but that is not valid and will merit little or no credit: if you need an induction hypothesis that covers smaller n, then you must explicitly use strong induction.
Prime factorisation and the fundamental theorem of arithmetic [01FT]
- October 31, 2026
- Marcelo Fiore, Jon Sterling
Proposition Existence of prime factorisation [01FU]
- October 31, 2026
- Marcelo Fiore, Jon Sterling
Every natural number n greater than or equal to 2 is a product of finite sequence of primes, i.e. we have n = \prod {\mathopen {}\left (\vec {p}\right )\mathclose {}} for some finite sequence \vec {p} of primes.
Proof.
- October 31, 2026
- Marcelo Fiore, Jon Sterling
Let P{\mathopen {}\left (m\right )\mathclose {}} be the statement “m is the product of some sequence of primes.” We will now prove \forall m \geq 2\mathpunct {.} P{\mathopen {}\left (m\right )\mathclose {}} using the principle of strong induction from basis 2.
- Base case. P{\mathopen {}\left (2\right )\mathclose {}} holds because 2 is prime, so 2 = \prod _{p\in {\mathopen {}\left \{2\right \}\mathclose {}}}p.
- Inductive step. Let n \geq 2 such that we have P{\mathopen {}\left (k\right )\mathclose {}} for all k:{\mathopen {}\left [2\ldots n\right ]\mathclose {}}. We must prove P{\mathopen {}\left (n+1\right )\mathclose {}}, which we will do by cases on whether or not n+1 is prime.
- If n+1 is prime, then P{\mathopen {}\left (n+1\right )\mathclose {}} holds immediately.
- If to the contrary n+1 is composite, then it follows that we may factor n+1 as j\cdot k with both j,k:{\mathopen {}\left [2\ldots n\right ]\mathclose {}}. Our strong induction hypothesis implies P{\mathopen {}\left (j\right )\mathclose {}} and P{\mathopen {}\left (k\right )\mathclose {}} and so we have finite sequences \vec {p} and \vec {q} such that j = \prod {\mathopen {}\left (\vec {p}\right )\mathclose {}} and k =\prod {\mathopen {}\left (\vec {q}\right )\mathclose {}}. We therefore may define a new finite sequence by concatenating \vec {p}\ldots \vec {q} and it follows straightaway that j\cdot k is the product of the concatenated sequence.
Lemma Uniqueness of sorted prime factorisation [01FV]
- November 1, 2026
- Marcelo Fiore, Jon Sterling
Let \vec {p} and \vec {q} be two sorted nonempty finite sequences of primes. (By “sorted” we mean that \vec {p}_i \leq \vec {p}_{j} whenever i\leq j.) Then if \prod {\mathopen {}\left (\vec {p}\right )\mathclose {}} = \prod {\mathopen {}\left (\vec {q}\right )\mathclose {}}, then \vec {p} = \vec {q}.
Remark.
- November 1, 2026
- Marcelo Fiore, Jon Sterling
In other words, the function \prod that sends a sorted nonempty finite sequences of primes to its product is injective; we will learn about injectivity in future lectures, however.
Proof.
- November 1, 2026
- Marcelo Fiore, Jon Sterling
We will proceed by induction with basis 1 on the length of the first sequence of primes. In particular, let P{\mathopen {}\left (\ell \right )\mathclose {}} be the following statement:
For all sorted nonempty finite sequences of primes \vec {p} and \vec {q} such that \vec {p} has length \ell , if \prod {\mathopen {}\left (\vec {p}\right )\mathclose {}} = \prod {\mathopen {}\left (\vec {q}\right )\mathclose {}} then \vec {p}=\vec {q}.
We will show that P{\mathopen {}\left (\ell \right )\mathclose {}} holds for all \ell \geq 1 by induction as follows:
- Base case. To establish P{\mathopen {}\left (1\right )\mathclose {}}, we fix a prime p and a sorted nonempty finite sequence of primes \vec {q}, and we must show that if p = \prod {\mathopen {}\left (\vec {q}\right )\mathclose {}} then \vec {q} is the sequence that contains just the prime p. Our assumption says that \prod {\mathopen {}\left (\vec {q}\right )\mathclose {}} is prime, and therefore (by definition) it cannot contain more than one element, so we are done.
Inductive step. We now fix a positive natural \ell \geq 1 and assume the induction hypothesis P{\mathopen {}\left (\ell \right )\mathclose {}}, and we must show that P{\mathopen {}\left (\ell +1\right )\mathclose {}} holds. To that end, we might fix \vec {p} of length \ell +1 and an arbitrary \vec {q} and we assume \prod {\mathopen {}\left (\vec {p}\right )\mathclose {}} = \prod {\mathopen {}\left (\vec {q}\right )\mathclose {}}.
By Euclid’s theorem, p_0 divides some q_i and therefore equals it. For the same reason, q_0 divides and therefore equals some p_j. Therefore we may deduce q_0 = p_0 as follows, using our assumption that the sequences were sorted:
q_0 \leq q_i = p_0 \qquad p_0 \leq p_j = q_0Writing \vec {r} and \vec {s} for the suffixes of \vec {p} and \vec {q} respectively obtained by removing their first elements, we have:
\begin {aligned} p_0 \cdot \prod {\mathopen {}\left (\vec {r}\right )\mathclose {}} = \prod {\mathopen {}\left (\vec {p}\right )\mathclose {}} = \prod {\mathopen {}\left (\vec {q}\right )\mathclose {}} = q_0\cdot \prod {\mathopen {}\left (\vec {s}\right )\mathclose {}} = p_0\cdot \prod {\mathopen {}\left (\vec {s}\right )\mathclose {}} \end {aligned}Therefore by cancellation, we have \prod {\mathopen {}\left (\vec {r}\right )\mathclose {}} = \prod {\mathopen {}\left (\vec {q}\right )\mathclose {}} and because \vec {r} is of length \ell , our induction hypothesis states that \vec {r} = \vec {s}. We therefore deduce \vec {p}=\vec {q}.
Apology Induction on the length is usually a mistake [01FW]
- November 1, 2026
- Jon Sterling
In our proof of the uniqueness of prime factorisations, we proceeded by induction on the length of a prime factorisation. In all honesty, that is not usually the best proof technique, as it leads to arguments that are technical and artificial rather than getting to the heart of the matter. Mathematical induction is the induction priniciple of the natural numbers, but these are only the simplest and most impoverished data structure that we can come up with; finite sequences also have an induction principle, as do trees (even infinitely branching trees!). These more sophisticated induction principles for data structures get to the heart of the matter, and lead to proofs that have more in common with algorithms that work on the data structures in question. The reason we are not using the induction principle for finite sequences here is simply that we haven’t learned enough yet to apply it.
Corollary The fundamental theorem of arithmetic [01FX]
- November 1, 2026
- Marcelo Fiore, Jon Sterling
Every positive natural number n is the product of a unique sorted sequence of prime numbers.
Proof.
- November 1, 2026
- Marcelo Fiore, Jon Sterling
We consider two cases:
- If n=1, then n is the product of the empty sequence of primes. There can be no non-empty sequence of primes that multiplies to 1, since all primes are strictly greater than 1.
- If n\geq 2, then we have already shown that there exists an (unsorted) prime factorisation of n; of course, we may order it using any sorting algorithm. So it remains to show the remaining sorted factorisation is unique, which follows immediately from our lemma estaablishing uniqueness of sorted prime factorisations.
Theorem Euclid’s infinitude of primes [01FZ]
- November 1, 2026
- Marcelo Fiore, Jon Sterling
The set of prime numbers is infinite.
Proof.
- November 1, 2026
- Marcelo Fiore, Jon Sterling
We will use proof by contradiction. In particular, suppose that the set of primes is finite, and let p_1,\ldots ,p_\ell be the collection of all primes. When then consider the natural number p \coloneqq p_1\cdot \ldots \cdot p_\ell + 1 which we know not to be in the list because it is strictly greater than any p_i. By the prime factorisation existence lemma, p is a product of primes, and so there must exist some p_i in our list of all primes such that p_i\mid p. Because p_i\mid {\mathopen {}\left (p_1\cdot \ldots \cdot p_\ell \right )\mathclose {}}, it also divides their difference p-{\mathopen {}\left (p_1\cdot \ldots \cdot p_\ell \right )\mathclose {}} = 1, so we have p\mid 1, but this is contradictory as p\geq 1.