Skip to content
The Lumenary
Advanced undergraduateUndergraduate 140 min

Number theory

Primitive roots, the law of quadratic reciprocity with a complete proof, Möbius inversion, which primes are sums of two squares, and why x2−61y2=1x^2 - 61y^2 = 1 has its smallest solution at x=1 766 319 049x = 1\,766\,319\,049.

Formally verified · 19 LeanComputationally tested · 3 PythonAI-drafted · awaiting human reviewMathematically reviewed: Awaiting human review
MotivationH

Questions about whole numbers

On Christmas Day 1640, Pierre de Fermat wrote to Marin Mersenne that every prime of the form 4k+14k + 1 is a sum of two squares — 5=1+45 = 1 + 4, 13=4+913 = 4 + 9, 29=4+2529 = 4 + 25 — while no prime of the form 4k+34k + 3 is. He gave no proof, and Leonhard Euler supplied one a century later. Why should the remainder on division by 44 decide such a thing?

Some questions look even more innocent. Is 3737 a perfect square modulo 101101, that is, does 101101 divide x2−37x^2 - 37 for some xx? One can try all 101101 residues. Euler, Adrien-Marie Legendre and finally Carl Friedrich Gauss found something much better, a hidden symmetry between primes: whether pp is a square modulo qq is tied to whether qq is a square modulo pp. Gauss called this theorema aureum, the golden theorem, and gave eight proofs.

The oldest question here is Pell's equation x2−dy2=1x^2 - dy^2 = 1. Brahmagupta studied it in 628, and Bhāskara II solved x2−61y2=1x^2 - 61y^2 = 1 in the twelfth century with his chakravāla method. The smallest solution is

x=1 766 319 049,y=226 153 980.x = 1\,766\,319\,049, \qquad y = 226\,153\,980 .

In 1657 Fermat set the same equation as a challenge to European mathematicians, apparently unaware it had been solved in India five hundred years earlier.

This lesson proves the central results of classical number theory beyond congruences. The tools are the group theory of groups (the unit group modulo pp is cyclic), a clever count of lattice points (for reciprocity), the Gaussian integers of rings (for sums of two squares), and approximation of irrationals by fractions (for Pell).

IntuitionH

Powers going round the clock

Take the powers of 33 modulo 77: 3,2,6,4,5,13, 2, 6, 4, 5, 1. They visit every non-zero residue before returning to 11. So every non-zero residue is a power of 33, and 33 is a primitive root modulo 77. The powers of 22 only reach 2,4,12, 4, 1. Modulo 88 nothing works: 32=9≡13^2 = 9 \equiv 1, 52≡15^2 \equiv 1, 72≡17^2 \equiv 1, so every unit has order at most 22.

When a primitive root gg exists, the multiplicative structure becomes additive. Every unit is gkg^k, multiplying units adds exponents, and a=gka = g^k is a perfect square exactly when kk is even. So modulo an odd prime exactly half of the non-zero residues are squares. Modulo 77 they are 1,2,41, 2, 4, the even powers of 33. A whole theory of quadratic residues grows from this observation, and its crowning result relates the squares modulo pp to those modulo qq.

Primes in columns of four

With four columns, the odd primes fall into two columns: remainder 1 and remainder 3 on division by 4. The primes in the first column are exactly the odd primes that are sums of two squares.

  • prime
  • crossed out

Step 1 of 7

Here are the numbers from 1 to 100. Press “Next step” to start sieving.

DefinitionsH

Primitive roots, residues and arithmetic functions

Throughout, pp and qq denote primes, φ\varphi is Euler's totient, and (Z/nZ)×(\Z/n\Z)^\times is the group of units modulo nn, of order φ(n)\varphi(n). For gcd⁡(a,n)=1\gcd(a, n) = 1, ord⁡n(a)\operatorname{ord}_n(a) is the order of aa in this group, the least k≥1k \ge 1 with ak≡1(modn)a^k \equiv 1 \pmod n.

Definition— primitive root

A primitive root modulo nn is an integer gg with ord⁡n(g)=φ(n)\operatorname{ord}_n(g) = \varphi(n), that is, a generator of (Z/nZ)×(\Z/n\Z)^\times. A primitive root exists iff (Z/nZ)×(\Z/n\Z)^\times is cyclic.

Definition— quadratic residue and Legendre symbol

For an odd prime pp and p∤ap \nmid a, aa is a quadratic residue modulo pp if x2≡a(modp)x^2 \equiv a \pmod p has a solution, and a non-residue otherwise. The Legendre symbol is

(ap)={0p∣a,1a a quadratic residue mod p,−1a a non-residue mod p.\left(\frac{a}{p}\right) = \begin{cases} 0 & p \mid a, \\ 1 & a \text{ a quadratic residue mod } p, \\ -1 & a \text{ a non-residue mod } p. \end{cases}

Definition— arithmetic functions

An arithmetic function is a function f:Z>0→Cf : \Z_{\gt 0} \to \C. It is multiplicative if f(1)=1f(1) = 1 and f(mn)=f(m)f(n)f(mn) = f(m)f(n) whenever gcd⁡(m,n)=1\gcd(m, n) = 1. The Dirichlet convolution is (f∗g)(n)=∑d∣nf(d) g(n/d)(f * g)(n) = \sum_{d \mid n} f(d)\,g(n/d). Important examples are 1(n)=1\mathbf{1}(n) = 1, id⁡(n)=n\operatorname{id}(n) = n, ε(n)=[n=1]\varepsilon(n) = [n = 1], the divisor functions τ=1∗1\tau = \mathbf 1 * \mathbf 1 and σ=id⁡∗1\sigma = \operatorname{id} * \mathbf 1, Euler's φ\varphi, and the Möbius function μ\mu: μ(n)=(−1)r\mu(n) = (-1)^r if nn is a product of rr distinct primes, and μ(n)=0\mu(n) = 0 if nn has a square factor.

Definition— Pell's equation

For a positive integer dd that is not a square, Pell's equation is x2−dy2=1x^2 - dy^2 = 1 in integers. Its solutions with y≠0y \ne 0 are non-trivial. Identify (x,y)(x, y) with the real number x+ydx + y\sqrt d. The norm N(x+yd)=(x+yd)(x−yd)=x2−dy2N(x + y\sqrt d) = (x + y\sqrt d)(x - y\sqrt d) = x^2 - dy^2 is multiplicative.

Worked examplesH

Worked examples

Example— Primitive roots and indices

Modulo 1111, ord⁡(2)=10\operatorname{ord}(2) = 10, since 25=32≡−1≠12^5 = 32 \equiv -1 \ne 1 and 22≠12^2 \ne 1. So 22 is a primitive root, and its powers 2,4,8,5,10,9,7,3,6,12, 4, 8, 5, 10, 9, 7, 3, 6, 1 give every unit an index (discrete logarithm). For instance ind⁡(7)=7\operatorname{ind}(7) = 7. To solve x3≡7(mod11)x^3 \equiv 7 \pmod{11}, write x=2kx = 2^k: then 3k≡7(mod10)3k \equiv 7 \pmod{10}, so k≡9k \equiv 9 and x=29≡6x = 2^9 \equiv 6. Check: 63=216=19⋅11+76^3 = 216 = 19 \cdot 11 + 7.

Example— Squares modulo 13

The squares of 1,…,61, \dots, 6 modulo 1313 are 1,4,9,3,12,101, 4, 9, 3, 12, 10. These are the six quadratic residues, and xx and −x-x have the same square, so the list is complete. The non-residues are 2,5,6,7,8,112, 5, 6, 7, 8, 11. Note that −1≡12-1 \equiv 12 is a residue (52=25≡−15^2 = 25 \equiv -1), as it must be for 13≡1(mod4)13 \equiv 1 \pmod 4.

Example— Arithmetic functions

φ(12)=4\varphi(12) = 4, τ(12)=6\tau(12) = 6, σ(12)=1+2+3+4+6+12=28\sigma(12) = 1 + 2 + 3 + 4 + 6 + 12 = 28, and μ(12)=0\mu(12) = 0, μ(30)=−1\mu(30) = -1, μ(15)=1\mu(15) = 1. Since these functions are multiplicative, it suffices to know them on prime powers: φ(pk)=pk−pk−1\varphi(p^k) = p^k - p^{k-1}, τ(pk)=k+1\tau(p^k) = k + 1, σ(pk)=pk+1−1p−1\sigma(p^k) = \frac{p^{k+1} - 1}{p - 1}. For example σ(12)=σ(4)σ(3)=7⋅4=28\sigma(12) = \sigma(4)\sigma(3) = 7 \cdot 4 = 28.

Example— A Pell equation solved by hand

For d=2d = 2: 32−2⋅22=13^2 - 2 \cdot 2^2 = 1, so 3+223 + 2\sqrt2 is a solution. Its powers (3+22)2=17+122(3 + 2\sqrt2)^2 = 17 + 12\sqrt2, (3+22)3=99+702(3 + 2\sqrt2)^3 = 99 + 70\sqrt2, … are solutions too, because the norm is multiplicative. The fractions 32,1712,9970,577408\frac32, \frac{17}{12}, \frac{99}{70}, \frac{577}{408} approximate 2\sqrt2 extremely well. Pell's equation is about the best rational approximations to d\sqrt d.

ProofH

Primitive roots

Theorem— Theorem 1 (the units modulo a prime form a cyclic group)

For every prime pp, (Z/pZ)×(\Z/p\Z)^\times is cyclic of order p−1p - 1. More precisely, for each d∣p−1d \mid p - 1 there are exactly φ(d)\varphi(d) elements of order dd; in particular there are φ(p−1)\varphi(p - 1) primitive roots.

Proof

Let ψ(d)\psi(d) be the number of elements of order dd. By Lagrange's theorem every order divides p−1p - 1, so ∑d∣p−1ψ(d)=p−1\sum_{d \mid p-1}\psi(d) = p - 1. Suppose ψ(d)≥1\psi(d) \ge 1, and let aa have order dd. Then 1,a,…,ad−11, a, \dots, a^{d-1} are dd distinct roots of xd−1x^d - 1. Over the field Z/pZ\Z/p\Z a polynomial of degree dd has at most dd roots (factor theorem plus no zero divisors), so these are all the roots. Every element of order dd is therefore a power aka^k, and aka^k has order dd iff gcd⁡(k,d)=1\gcd(k, d) = 1. Hence ψ(d)=φ(d)\psi(d) = \varphi(d) whenever ψ(d)≠0\psi(d) \ne 0, so ψ(d)≤φ(d)\psi(d) \le \varphi(d) for all dd. But ∑d∣p−1φ(d)=p−1\sum_{d \mid p-1}\varphi(d) = p - 1 (groups lesson, Proposition 4), so the inequalities are equalities. In particular ψ(p−1)=φ(p−1)≥1\psi(p - 1) = \varphi(p - 1) \ge 1.

∎

The same proof shows that every finite subgroup of the multiplicative group of any field is cyclic. The proof does not construct a primitive root, and no efficient deterministic method is known for finding one. In practice one tests g=2,3,5,…g = 2, 3, 5, \dots using the criterion: gg is a primitive root modulo pp iff g(p−1)/q≢1g^{(p-1)/q} \not\equiv 1 for every prime q∣p−1q \mid p - 1.

Theorem— Theorem 2 (no primitive roots modulo 2ᵏ for k ≥ 3)

If k≥3k \ge 3 and aa is odd, then a2k−2≡1(mod2k)a^{2^{k-2}} \equiv 1 \pmod{2^k}. Since φ(2k)=2k−1\varphi(2^k) = 2^{k-1}, there is no primitive root modulo 2k2^k.

Proof

For k=3k = 3: a=2m+1a = 2m + 1 gives a2=4m(m+1)+1≡1(mod8)a^2 = 4m(m + 1) + 1 \equiv 1 \pmod 8, as m(m+1)m(m + 1) is even. If a2k−2=1+2kta^{2^{k-2}} = 1 + 2^k t, squaring gives a2k−1=1+2k+1t+22kt2≡1(mod2k+1)a^{2^{k-1}} = 1 + 2^{k+1}t + 2^{2k}t^2 \equiv 1 \pmod{2^{k+1}}. Induct on kk.

∎

Theorem— Theorem 3 (which moduli have primitive roots)

A primitive root modulo nn exists if and only if n=1,2,4,pkn = 1, 2, 4, p^k or 2pk2p^k, where pp is an odd prime and k≥1k \ge 1.

Proof

None otherwise. If n=2kn = 2^k with k≥3k \ge 3, use Theorem 2. Otherwise n=mm′n = m m' with gcd⁡(m,m′)=1\gcd(m, m') = 1 and m,m′>2m, m' \gt 2, so φ(m)\varphi(m) and φ(m′)\varphi(m') are both even. By the Chinese remainder theorem (quotients), (Z/n)×≅(Z/m)××(Z/m′)×(\Z/n)^\times \cong (\Z/m)^\times \times (\Z/m')^\times. Every element then has order dividing lcm⁡(φ(m),φ(m′))≤φ(m)φ(m′)/2<φ(n)\operatorname{lcm}(\varphi(m), \varphi(m')) \le \varphi(m)\varphi(m')/2 \lt \varphi(n).

Odd prime powers. Let gg be a primitive root modulo pp. If gp−1≡1(modp2)g^{p-1} \equiv 1 \pmod{p^2}, replace gg by g+pg + p: by the binomial theorem (g+p)p−1≡gp−1+(p−1)gp−2p≢1(modp2)(g + p)^{p-1} \equiv g^{p-1} + (p-1)g^{p-2}p \not\equiv 1 \pmod{p^2}. So we may assume gp−1=1+ptg^{p-1} = 1 + pt with p∤tp \nmid t. By induction, using the binomial theorem and pp odd, (1+pt)pj=1+pj+1tj(1 + pt)^{p^{j}} = 1 + p^{j+1}t_j with p∤tjp \nmid t_j. The order of gg modulo pkp^k divides φ(pk)=(p−1)pk−1\varphi(p^k) = (p - 1)p^{k-1} and is a multiple of p−1p - 1 (reduce modulo pp), so it is (p−1)pj(p-1)p^j for some jj. It is not (p−1)pj(p-1)p^{j} for j<k−1j \lt k - 1, since g(p−1)pk−2=1+pk−1tk−2≢1(modpk)g^{(p-1)p^{k-2}} = 1 + p^{k-1}t_{k-2} \not\equiv 1 \pmod{p^k}. So gg is a primitive root modulo every pkp^k.

2pk2p^k, 22 and 44. (Z/2pk)×≅(Z/pk)×(\Z/2p^k)^\times \cong (\Z/p^k)^\times (the factor (Z/2)×(\Z/2)^\times is trivial), and an odd primitive root modulo pkp^k is a primitive root modulo 2pk2p^k. Modulo 22 and 44, 11 and 33 are primitive roots.

∎

ProofH

Quadratic residues and reciprocity

Fix an odd prime pp.

Theorem— Theorem 4 (Euler's criterion)

For every integer aa, (ap)≡a(p−1)/2(modp)\left(\frac{a}{p}\right) \equiv a^{(p-1)/2} \pmod p. Consequently there are exactly p−12\frac{p-1}{2} quadratic residues and p−12\frac{p-1}{2} non-residues, and the Legendre symbol is completely multiplicative: (abp)=(ap)(bp)\left(\frac{ab}{p}\right) = \left(\frac ap\right)\left(\frac bp\right).

Proof

If p∣ap \mid a both sides are 00. Otherwise let gg be a primitive root (Theorem 1) and a≡gka \equiv g^k. Then aa is a square iff kk is even: gk=(gj)2g^k = (g^j)^2 means k≡2j(modp−1)k \equiv 2j \pmod{p - 1}, and p−1p - 1 is even. On the other hand g(p−1)/2≡−1g^{(p-1)/2} \equiv -1, because it is a root of x2−1x^2 - 1 other than 11 (as gg has order p−1p - 1). So a(p−1)/2=(g(p−1)/2)k≡(−1)ka^{(p-1)/2} = (g^{(p-1)/2})^k \equiv (-1)^k. This is 11 for even kk and −1-1 for odd kk. Exactly half of k=0,…,p−2k = 0, \dots, p-2 are even. Multiplicativity follows since (ab)(p−1)/2=a(p−1)/2b(p−1)/2(ab)^{(p-1)/2} = a^{(p-1)/2}b^{(p-1)/2}, and the values ±1\pm 1 are distinct modulo p>2p \gt 2.

∎

Theorem— Corollary 5 (first supplementary law)

(−1p)=(−1)(p−1)/2\left(\frac{-1}{p}\right) = (-1)^{(p-1)/2}: −1-1 is a square modulo pp iff p≡1(mod4)p \equiv 1 \pmod 4.

Theorem— Lemma 6 (Gauss's lemma)

Let p∤ap \nmid a, and let μ\mu be the number of k∈{1,…,p−12}k \in \{1, \dots, \frac{p-1}{2}\} for which the least positive residue of kaka exceeds p2\frac p2. Then (ap)=(−1)μ\left(\frac ap\right) = (-1)^\mu.

Proof

Let h=p−12h = \frac{p-1}{2}. Write the residues of a,2a,…,haa, 2a, \dots, ha as s1,…,sλs_1, \dots, s_\lambda (those below p2\frac p2) and t1,…,tμt_1, \dots, t_\mu (those above). The hh numbers s1,…,sλ,p−t1,…,p−tμs_1, \dots, s_\lambda, p - t_1, \dots, p - t_\mu all lie in {1,…,h}\{1, \dots, h\}, and they are distinct. The ss's are distinct, and so are the tt's. If si=p−tjs_i = p - t_j, then ka+la≡0ka + la \equiv 0 for some 1≤k,l≤h1 \le k, l \le h, so p∣k+lp \mid k + l, impossible as 2≤k+l≤p−12 \le k + l \le p - 1. So they are exactly 1,…,h1, \dots, h in some order. Multiplying, h!≡∏si∏(p−tj)≡(−1)μ∏si∏tj≡(−1)μ ah h!(modp)h! \equiv \prod s_i \prod (p - t_j) \equiv (-1)^\mu \prod s_i \prod t_j \equiv (-1)^\mu\, a^h\, h! \pmod p. Cancel h!h! and use Euler's criterion.

∎

Theorem— Corollary 7 (second supplementary law)

(2p)=(−1)(p2−1)/8\left(\frac{2}{p}\right) = (-1)^{(p^2-1)/8}: 22 is a square modulo pp iff p≡±1(mod8)p \equiv \pm 1 \pmod 8.

Proof

For a=2a = 2, the residues 2k2k with 1≤k≤h1 \le k \le h are just 2,4,…,p−12, 4, \dots, p - 1. Those exceeding p2\frac p2 are the 2k2k with k>p4k \gt \frac p4, so μ=h−⌊p4⌋\mu = h - \lfloor \frac p4 \rfloor. Checking p=8m+1,8m+3,8m+5,8m+7p = 8m + 1, 8m + 3, 8m + 5, 8m + 7 gives μ=2m,2m+1,2m+1,2m+2\mu = 2m, 2m + 1, 2m + 1, 2m + 2. So μ\mu is even exactly for p≡±1(mod8)p \equiv \pm 1 \pmod 8, and (−1)μ=(−1)(p2−1)/8(-1)^\mu = (-1)^{(p^2 - 1)/8} in each case.

∎

Theorem— Theorem 8 (law of quadratic reciprocity)

For distinct odd primes pp and qq,

(pq)(qp)=(−1)p−12⋅q−12.\left(\frac{p}{q}\right)\left(\frac{q}{p}\right) = (-1)^{\frac{p-1}{2}\cdot\frac{q-1}{2}} .

So (pq)=(qp)\left(\frac pq\right) = \left(\frac qp\right) unless p≡q≡3(mod4)p \equiv q \equiv 3 \pmod 4, in which case (pq)=−(qp)\left(\frac pq\right) = -\left(\frac qp\right).

Proof

(Eisenstein, 1844.) Step 1: for odd aa with p∤ap \nmid a, μ≡∑k=1h⌊kap⌋(mod2)\mu \equiv \sum_{k=1}^{h} \lfloor \frac{ka}{p} \rfloor \pmod 2. With the notation of Lemma 6, ka=p⌊kap⌋+(residue)ka = p\lfloor\frac{ka}{p}\rfloor + (\text{residue}). Summing over k=1,…,hk = 1, \dots, h gives

a∑k=1hk=p∑k=1h⌊kap⌋+∑isi+∑jtj.a\sum_{k=1}^h k = p\sum_{k=1}^h \Big\lfloor \frac{ka}{p}\Big\rfloor + \sum_i s_i + \sum_j t_j .

From the proof of Lemma 6, ∑k=1hk=∑isi+∑j(p−tj)=∑isi+pμ−∑jtj\sum_{k=1}^h k = \sum_i s_i + \sum_j (p - t_j) = \sum_i s_i + p\mu - \sum_j t_j. Subtracting, (a−1)∑k=p(∑⌊kap⌋−μ)+2∑jtj(a - 1)\sum k = p\big(\sum\lfloor\frac{ka}p\rfloor - \mu\big) + 2\sum_j t_j. Reduce modulo 22: a−1a - 1 is even and pp is odd, so ∑⌊kap⌋≡μ\sum\lfloor \frac{ka}{p}\rfloor \equiv \mu.

Step 2: count lattice points. Consider the points (x,y)(x, y) with 1≤x≤p−121 \le x \le \frac{p-1}{2} and 1≤y≤q−121 \le y \le \frac{q-1}{2}; there are p−12⋅q−12\frac{p-1}{2}\cdot\frac{q-1}{2} of them. None lies on the line py=qxpy = qx, since that would need p∣xp \mid x. Below the line, the column at xx contains ⌊qxp⌋\lfloor \frac{qx}{p} \rfloor points, so there are ∑x⌊qxp⌋≡μ(q,p)\sum_x \lfloor\frac{qx}{p}\rfloor \equiv \mu(q, p) points below. Symmetrically, there are ∑y⌊pyq⌋≡μ(p,q)\sum_y \lfloor \frac{py}{q}\rfloor \equiv \mu(p, q) points above. By Gauss's lemma,

(qp)(pq)=(−1)μ(q,p)+μ(p,q)=(−1)p−12⋅q−12.\left(\frac qp\right)\left(\frac pq\right) = (-1)^{\mu(q,p) + \mu(p, q)} = (-1)^{\frac{p-1}{2}\cdot\frac{q-1}{2}} .

∎

x = 1, 2, 3 (up to p/2)y = 1, …, 5 (up to q/2)7y = 11x
Eisenstein's count for p = 7, q = 11: the 3 × 5 = 15 lattice points in the rectangle split into 8 below the line 7y = 11x (gold) and 7 above it. Gauss's lemma turns the parities into (11/7) = (−1)⁸ = 1 and (7/11) = (−1)⁷ = −1, and the product (−1)¹⁵ = −1 is the reciprocity sign.

Example— Computing a Legendre symbol

Is 219219 a square modulo 383383? Both numbers are small enough to check by hand, but reciprocity makes it quick. 219=3⋅73219 = 3 \cdot 73, so (219383)=(3383)(73383)\left(\frac{219}{383}\right) = \left(\frac{3}{383}\right)\left(\frac{73}{383}\right). Since 3≡383≡3(mod4)3 \equiv 383 \equiv 3 \pmod 4, (3383)=−(3833)=−(23)=1\left(\frac{3}{383}\right) = -\left(\frac{383}{3}\right) = -\left(\frac{2}{3}\right) = 1. Since 73≡1(mod4)73 \equiv 1 \pmod 4, (73383)=(38373)=(1873)=(273)(973)=1⋅1\left(\frac{73}{383}\right) = \left(\frac{383}{73}\right) = \left(\frac{18}{73}\right) = \left(\frac{2}{73}\right)\left(\frac{9}{73}\right) = 1 \cdot 1, as 73≡1(mod8)73 \equiv 1 \pmod 8. So (219383)=1\left(\frac{219}{383}\right) = 1, and 219219 is a square modulo 383383; indeed 1692=28561=74⋅383+219169^2 = 28561 = 74 \cdot 383 + 219.

ProofH

Arithmetic functions and Möbius inversion

Theorem— Proposition 9 (the Dirichlet ring)

Dirichlet convolution is commutative and associative, with identity ε\varepsilon. If ff and gg are multiplicative, so is f∗gf * g. And μ∗1=ε\mu * \mathbf 1 = \varepsilon, that is, ∑d∣nμ(d)=[n=1]\sum_{d \mid n}\mu(d) = [n = 1].

Proof

(f∗g)(n)=∑ab=nf(a)g(b)(f * g)(n) = \sum_{ab = n} f(a)g(b) is symmetric in f,gf, g, and ((f∗g)∗h)(n)=∑abc=nf(a)g(b)h(c)((f * g) * h)(n) = \sum_{abc = n} f(a)g(b)h(c) is symmetric in the bracketing. Also (f∗ε)(n)=f(n)(f * \varepsilon)(n) = f(n). If gcd⁡(m,n)=1\gcd(m, n) = 1, the divisors of mnmn are exactly the products ded e with d∣md \mid m, e∣ne \mid n, each uniquely, and then gcd⁡(d,e)=1\gcd(d, e) = 1 and gcd⁡(m/d,n/e)=1\gcd(m/d, n/e) = 1. So (f∗g)(mn)=∑d,ef(d)f(e)g(md)g(ne)=(f∗g)(m)(f∗g)(n)(f * g)(mn) = \sum_{d,e} f(d)f(e)g(\frac md)g(\frac ne) = (f * g)(m)(f * g)(n). Finally μ∗1\mu * \mathbf 1 is multiplicative, and on a prime power pkp^k with k≥1k \ge 1 it is μ(1)+μ(p)=1−1=0\mu(1) + \mu(p) = 1 - 1 = 0.

∎

Theorem— Theorem 10 (Möbius inversion)

For arithmetic functions f,gf, g:   g(n)=∑d∣nf(d)\;g(n) = \sum_{d \mid n} f(d) for all nn   ⟺  \iff f(n)=∑d∣nμ(d) g(n/d)f(n) = \sum_{d \mid n}\mu(d)\,g(n/d) for all nn.

Proof

The first statement says g=f∗1g = f * \mathbf 1, the second f=μ∗gf = \mu * g. If g=f∗1g = f * \mathbf 1 then μ∗g=f∗(1∗μ)=f∗ε=f\mu * g = f * (\mathbf 1 * \mu) = f * \varepsilon = f. If f=μ∗gf = \mu * g then f∗1=g∗(μ∗1)=gf * \mathbf 1 = g * (\mu * \mathbf 1) = g.

∎

Example— Euler's function and necklaces

Gauss's identity ∑d∣nφ(d)=n\sum_{d \mid n}\varphi(d) = n says φ∗1=id⁡\varphi * \mathbf 1 = \operatorname{id}. By inversion φ=μ∗id⁡\varphi = \mu * \operatorname{id}, that is, φ(n)=∑d∣nμ(d)nd=n∏p∣n(1−1p)\varphi(n) = \sum_{d \mid n}\mu(d)\frac nd = n\prod_{p \mid n}\big(1 - \frac1p\big), since only square-free dd contribute. In the same way, the number of monic irreducible polynomials of degree nn over Fq\mathbb{F}_q is 1n∑d∣nμ(d)qn/d\frac1n\sum_{d \mid n}\mu(d)q^{n/d} (see fields and Galois theory). That is also the number of aperiodic necklaces of nn beads in qq colours.

ProofH

Sums of two squares

Theorem— Theorem 11 (Fermat; proved by Euler)

An odd prime pp is a sum of two squares if and only if p≡1(mod4)p \equiv 1 \pmod 4.

Proof

Only if. Squares are 00 or 11 modulo 44, so a2+b2≢3(mod4)a^2 + b^2 \not\equiv 3 \pmod 4.

If. Let p≡1(mod4)p \equiv 1 \pmod 4. By Corollary 5 there is an xx with p∣x2+1=(x+i)(x−i)p \mid x^2 + 1 = (x + i)(x - i) in the Gaussian integers Z[i]\Z[i]. But pp divides neither factor, since xp±1pi∉Z[i]\frac xp \pm \frac 1p i \notin \Z[i]. So pp is not a prime element of Z[i]\Z[i]. Now Z[i]\Z[i] is a Euclidean domain, hence a UFD in which irreducible elements are prime (rings lesson, Theorems 6–9). So pp is not irreducible: p=αβp = \alpha\beta with α,β\alpha, \beta non-units. Taking norms, p2=N(α)N(β)p^2 = N(\alpha)N(\beta) with N(α),N(β)>1N(\alpha), N(\beta) \gt 1, so N(α)=pN(\alpha) = p. Writing α=a+bi\alpha = a + bi gives p=a2+b2p = a^2 + b^2.

∎

The representation is unique up to order and signs (by unique factorisation in Z[i]\Z[i]). Combined with the Brahmagupta–Fibonacci identity

(a2+b2)(c2+d2)=(ac−bd)2+(ad+bc)2,(a^2 + b^2)(c^2 + d^2) = (ac - bd)^2 + (ad + bc)^2,

which is the multiplicativity of NN on Z[i]\Z[i], this gives the full answer. A positive integer is a sum of two squares iff every prime q≡3(mod4)q \equiv 3 \pmod 4 divides it to an even power. (If q≡3(mod4)q \equiv 3 \pmod 4 divides a2+b2a^2 + b^2, then q∣aq \mid a and q∣bq \mid b, because −1-1 is not a square modulo qq.) Don Zagier (1990) found a famous "one-sentence" proof of Theorem 11, by an involution on a finite set with exactly one fixed point. Roger Heath-Brown's earlier argument underlies it.

ProofH

Pell's equation

Let d>0d \gt 0 be a non-square, so d\sqrt d is irrational. Write η=x+yd\eta = x + y\sqrt d and ηˉ=x−yd\bar\eta = x - y\sqrt d. The set U={η∣x,y∈Z, x2−dy2=1}U = \{\eta \mid x, y \in \Z,\ x^2 - dy^2 = 1\} is a group under multiplication. It is closed under products by the multiplicativity of the norm, and η−1=ηˉ\eta^{-1} = \bar\eta. This is Brahmagupta's bhāvanā: (x1,y1)⋅(x2,y2)=(x1x2+dy1y2, x1y2+x2y1)(x_1, y_1) \cdot (x_2, y_2) = (x_1x_2 + dy_1y_2,\ x_1y_2 + x_2y_1).

Theorem— Lemma 12 (Dirichlet's approximation theorem)

For every irrational α\alpha there are infinitely many pairs of integers (x,y)(x, y) with y≥1y \ge 1 and ∣x−yα∣<1y|x - y\alpha| \lt \frac1y.

Proof

Fix Q≥1Q \ge 1. The Q+1Q + 1 numbers {0α},{1α},…,{Qα}\{0\alpha\}, \{1\alpha\}, \dots, \{Q\alpha\} (fractional parts) lie in [0,1)[0, 1). By the pigeonhole principle two of them, say for 0≤j<k≤Q0 \le j \lt k \le Q, lie in the same interval [iQ,i+1Q)[\frac iQ, \frac{i+1}Q). Then y=k−j∈[1,Q]y = k - j \in [1, Q] and x=⌊kα⌋−⌊jα⌋x = \lfloor k\alpha \rfloor - \lfloor j\alpha \rfloor satisfy ∣yα−x∣<1Q≤1y|y\alpha - x| \lt \frac1Q \le \frac1y. As α\alpha is irrational, ∣yα−x∣>0|y\alpha - x| \gt 0. Taking QQ larger than 1/∣yα−x∣1/|y\alpha - x| produces a new pair each time, so there are infinitely many.

∎

Theorem— Theorem 13 (Pell's equation; Lagrange 1768)

(a) Pell's equation has a non-trivial solution. (b) There is a least solution ε=x1+y1d>1\varepsilon = x_1 + y_1\sqrt d \gt 1, the fundamental solution, and every solution is ±εn\pm\varepsilon^n with n∈Zn \in \Z. So U≅Z/2×ZU \cong \Z/2 \times \Z, and there are infinitely many solutions.

Proof

(a) For each pair from Lemma 12 (with α=d\alpha = \sqrt d),

∣x2−dy2∣=∣x−yd∣ ∣x+yd∣<1y(2yd+1)≤2d+1.|x^2 - dy^2| = |x - y\sqrt d|\,|x + y\sqrt d| \lt \frac1y\big(2y\sqrt d + 1\big) \le 2\sqrt d + 1 .

So infinitely many pairs give values x2−dy2x^2 - dy^2 in a finite set. None is 00, since d\sqrt d is irrational. By the pigeonhole principle infinitely many pairs share the same value NN and the same residues of xx and yy modulo ∣N∣|N|. Take two distinct such pairs (x1,y1)(x_1, y_1), (x2,y2)(x_2, y_2) with positive coordinates, and set

x1+y1dx2+y2d=(x1+y1d)(x2−y2d)N=u+vd,u=x1x2−dy1y2N,v=x2y1−x1y2N.\frac{x_1 + y_1\sqrt d}{x_2 + y_2\sqrt d} = \frac{(x_1 + y_1\sqrt d)(x_2 - y_2\sqrt d)}{N} = u + v\sqrt d, \qquad u = \frac{x_1x_2 - dy_1y_2}{N}, \quad v = \frac{x_2y_1 - x_1y_2}{N} .

Modulo ∣N∣|N|, x1x2−dy1y2≡x12−dy12=N≡0x_1x_2 - dy_1y_2 \equiv x_1^2 - dy_1^2 = N \equiv 0 and x2y1−x1y2≡x1y1−x1y1=0x_2y_1 - x_1y_2 \equiv x_1y_1 - x_1y_1 = 0, so u,v∈Zu, v \in \Z. Taking norms, u2−dv2=N⋅N/N2=1u^2 - dv^2 = N \cdot N / N^2 = 1. If v=0v = 0 then u=±1u = \pm 1, and the two positive numbers xi+yidx_i + y_i\sqrt d would be equal, so the pairs would be equal. Hence v≠0v \ne 0.

(b) If η=x+yd∈U\eta = x + y\sqrt d \in U and η>1\eta \gt 1, then ηˉ=η−1∈(0,1)\bar\eta = \eta^{-1} \in (0, 1), so x=η+ηˉ2>0x = \frac{\eta + \bar\eta}{2} \gt 0 and y=η−ηˉ2d>0y = \frac{\eta - \bar\eta}{2\sqrt d} \gt 0. Such η\eta exist by (a): replace (x,y)(x, y) by (∣x∣,∣y∣)(|x|, |y|). Among them, the one with the least xx (and so the least yy) is the least element ε\varepsilon of U∩(1,∞)U \cap (1, \infty). Now let η∈U\eta \in U with η>0\eta \gt 0, and choose nn with εn≤η<εn+1\varepsilon^n \le \eta \lt \varepsilon^{n+1}. Then ηε−n∈U∩[1,ε)\eta\varepsilon^{-n} \in U \cap [1, \varepsilon), so it equals 11 by minimality, and η=εn\eta = \varepsilon^n. If η<0\eta \lt 0, apply this to −η-\eta.

∎

Finding ε\varepsilon. The continued fraction of d\sqrt d is periodic, d=[a0;a1,…,ar‾]\sqrt d = [a_0; \overline{a_1, \dots, a_r}] with ar=2a0a_r = 2a_0 (Lagrange). If hiki\frac{h_i}{k_i} are its convergents, the fundamental solution is (hr−1,kr−1)(h_{r-1}, k_{r-1}) if rr is even, and (h2r−1,k2r−1)(h_{2r-1}, k_{2r-1}) if rr is odd. For d=13d = 13, 13=[3;1,1,1,1,6‾]\sqrt{13} = [3; \overline{1, 1, 1, 1, 6}] has odd period 55, and the method gives 6492−13⋅1802=1649^2 - 13 \cdot 180^2 = 1. For d=61d = 61 the period has length 1111, and the answer is the enormous solution of the introduction. For proofs see Niven, Zuckerman and Montgomery (1991), chapter 7. The third experiment runs the algorithm.

Formal mathematicsF

Number theory in Lean and Mathlib

Mathlib has a substantial library of elementary number theory. ZMod n is Z/nZ\Z/n\Z, legendreSym p a is (ap)\left(\frac ap\right), ArithmeticFunction with ArithmeticFunction.moebius handles Dirichlet convolution, and Pell.Solution₁ d is the group of solutions of Pell's equation.

Primitive roots (Theorems 1 and 2). Cyclicity is cited, and the computations modulo 77 and 88 are checked by decide. The impossibility of a primitive root modulo 88 is the lesson's argument:

units_cyclicLean 4Applies a library theoremFormally verified
/-- For a prime `p`, the group `(ℤ/pℤ)ˣ` is cyclic: a primitive root exists. Mathlib proves
that every finite subgroup of the units of an integral domain is cyclic
(`isCyclic_of_subgroup_isDomain`), by the counting argument of the lesson. -/
theorem units_cyclic (p : ℕ) [Fact p.Prime] : IsCyclic (ZMod p)ˣ :=
  inferInstance
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/ElementaryNumberTheory.leanTry it in the Lean web editor
sum_totientLean 4Applies a library theoremFormally verified
/-- Gauss's identity `∑_{d ∣ n} φ(d) = n`, the key to the cyclicity proof. Mathlib's
`Nat.sum_totient`. -/
theorem sum_totient (n : ℕ) : ∑ d ∈ n.divisors, Nat.totient d = n :=
  Nat.sum_totient n
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/ElementaryNumberTheory.leanTry it in the Lean web editor
three_primitive_root_mod_sevenLean 4Proved here from basic factsFormally verified
/-- `3` is a primitive root modulo `7`: its powers `3, 2, 6, 4, 5, 1` run through all six
non-zero residues, i.e. its order is `6`. `decide` checks `3⁶ = 1` and `3ᵐ ≠ 1` for `0 < m < 6`. -/
theorem three_primitive_root_mod_seven : orderOf (3 : ZMod 7) = 6 :=
  (orderOf_eq_iff (by norm_num)).mpr ⟨by decide, by decide⟩
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/ElementaryNumberTheory.leanTry it in the Lean web editor
units_mod_eight_sqLean 4Proved here from basic factsFormally verified
/-- Every unit modulo `8` squares to `1`: `1² = 1`, `3² = 9`, `5² = 25`, `7² = 49` are all `≡ 1`.
Checked by `decide` over the four units. -/
theorem units_mod_eight_sq : ∀ u : (ZMod 8)ˣ, u ^ 2 = 1 := by
  decide
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/ElementaryNumberTheory.leanTry it in the Lean web editor
no_primitive_root_mod_eightLean 4Proved here from basic factsFormally verified
/-- **There is no primitive root modulo `8`.** `(ℤ/8ℤ)ˣ` has `φ(8) = 4` elements; a generator
would have order `4`, but every unit has order dividing `2` (`units_mod_eight_sq`). -/
theorem no_primitive_root_mod_eight : ¬ IsCyclic (ZMod 8)ˣ := by
  intro h
  obtain ⟨g, hg⟩ := h.exists_generator
  have hcard : Nat.card (ZMod 8)ˣ = 4 := by
    rw [Nat.card_eq_fintype_card, ZMod.card_units_eq_totient]
    decide
  have hord : orderOf g = 4 := by
    rw [← hcard]
    exact orderOf_eq_card_of_forall_mem_zpowers hg
  have hdvd : orderOf g ∣ 2 := orderOf_dvd_of_pow_eq_one (units_mod_eight_sq g)
  rw [hord] at hdvd
  omega
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/ElementaryNumberTheory.leanTry it in the Lean web editor

Quadratic residues. A non-residue checked by computation, then Euler's criterion, the supplementary laws and reciprocity, all from Mathlib. Mathlib's proof of reciprocity uses Gauss's lemma and Eisenstein's lattice-point count, as Theorem 8 does:

two_not_square_mod_fiveLean 4Proved here from basic factsFormally verified
/-- `2` is a quadratic non-residue modulo `5`: the squares modulo `5` are `0, 1, 4`. -/
theorem two_not_square_mod_five : ¬ IsSquare (2 : ZMod 5) := by
  rintro ⟨r, hr⟩
  revert hr
  revert r
  decide
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/ElementaryNumberTheory.leanTry it in the Lean web editor
euler_criterionLean 4Applies a library theoremFormally verified
/-- **Euler's criterion**: for `a ≢ 0 (mod p)`, `a` is a square modulo `p` iff
`a^((p − 1)/2) ≡ 1`. Mathlib's `ZMod.euler_criterion` (here `p / 2 = (p − 1)/2` for odd `p`). -/
theorem euler_criterion (p : ℕ) [Fact p.Prime] {a : ZMod p} (ha : a ≠ 0) :
    IsSquare a ↔ a ^ (p / 2) = 1 :=
  ZMod.euler_criterion p ha
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/ElementaryNumberTheory.leanTry it in the Lean web editor
neg_one_square_iffLean 4Applies a library theoremFormally verified
/-- **First supplementary law**: `−1` is a square modulo a prime `p` iff `p ≢ 3 (mod 4)`.
Mathlib's `ZMod.exists_sq_eq_neg_one_iff`. -/
theorem neg_one_square_iff (p : ℕ) [Fact p.Prime] : IsSquare (-1 : ZMod p) ↔ p % 4 ≠ 3 :=
  ZMod.exists_sq_eq_neg_one_iff
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/ElementaryNumberTheory.leanTry it in the Lean web editor
two_square_iffLean 4Applies a library theoremFormally verified
/-- **Second supplementary law**: for an odd prime `p`, `2` is a square modulo `p` iff
`p ≡ ±1 (mod 8)`. Mathlib's `ZMod.exists_sq_eq_two_iff`. -/
theorem two_square_iff (p : ℕ) [Fact p.Prime] (hp : p ≠ 2) :
    IsSquare (2 : ZMod p) ↔ p % 8 = 1 ∨ p % 8 = 7 :=
  ZMod.exists_sq_eq_two_iff hp
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/ElementaryNumberTheory.leanTry it in the Lean web editor
quadratic_reciprocityLean 4Applies a library theoremFormally verified
/-- **The law of quadratic reciprocity**: for distinct odd primes `p` and `q`,
`(q/p)(p/q) = (−1)^(((p−1)/2)((q−1)/2))`. Mathlib's `legendreSym.quadratic_reciprocity`,
proved (like the lesson) via Gauss's lemma and a lattice-point count. -/
theorem quadratic_reciprocity (p q : ℕ) [Fact p.Prime] [Fact q.Prime] (hp : p ≠ 2) (hq : q ≠ 2)
    (hpq : p ≠ q) :
    legendreSym q p * legendreSym p q = (-1) ^ (p / 2 * (q / 2)) :=
  legendreSym.quadratic_reciprocity hp hq hpq
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/ElementaryNumberTheory.leanTry it in the Lean web editor

Möbius inversion (Theorem 10):

moebius_inversionLean 4Applies a library theoremFormally verified
/-- **Möbius inversion**: `g(n) = ∑_{d ∣ n} f(d)` for all `n > 0` iff
`f(n) = ∑_{de = n} μ(d) g(e)` for all `n > 0`. Mathlib's
`ArithmeticFunction.sum_eq_iff_sum_mul_moebius_eq`. -/
theorem moebius_inversion {f g : ℕ → ℤ} :
    (∀ n > 0, ∑ i ∈ n.divisors, f i = g n) ↔
      ∀ n > 0, ∑ x ∈ n.divisorsAntidiagonal,
        (ArithmeticFunction.moebius x.fst : ℤ) * g x.snd = f n :=
  ArithmeticFunction.sum_eq_iff_sum_mul_moebius_eq
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/ElementaryNumberTheory.leanTry it in the Lean web editor

Sums of two squares. The "only if" direction of Theorem 11 is proved here, in the stronger form that no integer ≡3(mod4)\equiv 3 \pmod 4 is a sum of two squares, together with the Brahmagupta–Fibonacci identity. Fermat's theorem itself is cited; Mathlib proves it through the Gaussian integers, as the lesson does:

sq_mod_fourLean 4Proved here from basic factsFormally verified
/-- Squares modulo `4` are `0` or `1`. -/
theorem sq_mod_four : ∀ x : ZMod 4, x ^ 2 = 0 ∨ x ^ 2 = 1 := by
  decide
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/ElementaryNumberTheory.leanTry it in the Lean web editor
not_sum_two_squaresLean 4Proved here from basic factsFormally verified
/-- No integer `≡ 3 (mod 4)` is a sum of two squares: modulo `4`, `a² + b²` is `0 + 0`, `0 + 1`,
`1 + 0` or `1 + 1`, never `3`. In particular no prime `p ≡ 3 (mod 4)` is a sum of two squares. -/
theorem not_sum_two_squares (a b : ℤ) : (a ^ 2 + b ^ 2) % 4 ≠ 3 := by
  intro h
  have hcast : ((a ^ 2 + b ^ 2 : ℤ) : ZMod 4) = ((3 : ℤ) : ZMod 4) := by
    rw [ZMod.intCast_eq_intCast_iff']
    simpa using h
  push_cast at hcast
  rcases sq_mod_four (a : ZMod 4) with ha | ha <;> rcases sq_mod_four (b : ZMod 4) with hb | hb <;>
    rw [ha, hb] at hcast <;> revert hcast <;> decide
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/ElementaryNumberTheory.leanTry it in the Lean web editor
brahmagupta_fibonacciLean 4Proved here from basic factsFormally verified
/-- **Brahmagupta–Fibonacci identity**: a product of sums of two squares is a sum of two squares,
`(a² + b²)(c² + d²) = (ac − bd)² + (ad + bc)²` — the multiplicativity of the norm on `ℤ[i]`. -/
theorem brahmagupta_fibonacci (a b c d : ℤ) :
    (a ^ 2 + b ^ 2) * (c ^ 2 + d ^ 2) = (a * c - b * d) ^ 2 + (a * d + b * c) ^ 2 := by
  ring
Axioms used: propext, Quot.soundformal/Lumenary/ElementaryNumberTheory.leanTry it in the Lean web editor
fermat_two_squaresLean 4Applies a library theoremFormally verified
/-- **Fermat's two-squares theorem**: a prime `p` with `p ≢ 3 (mod 4)` is a sum of two squares.
Mathlib's `Nat.Prime.sq_add_sq`, proved via the Gaussian integers as in the lesson. -/
theorem fermat_two_squares (p : ℕ) [Fact p.Prime] (hp : p % 4 ≠ 3) :
    ∃ a b : ℕ, a ^ 2 + b ^ 2 = p :=
  Nat.Prime.sq_add_sq hp
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/ElementaryNumberTheory.leanTry it in the Lean web editor

Pell's equation. The composition law and a numerical example are proved here. Existence (Theorem 13(a), proved in Mathlib by Dirichlet approximation) and the structure of all solutions (Theorem 13(b)) are cited:

pell_compositionLean 4Proved here from basic factsFormally verified
/-- **Composition of Pell solutions** (Brahmagupta's *bhāvanā*): if `x₁² − d y₁² = 1` and
`x₂² − d y₂² = 1`, then `(x₁x₂ + d y₁y₂)² − d (x₁y₂ + x₂y₁)² = 1`. It is the multiplicativity of
the norm `N(x + y√d) = x² − dy²`. -/
theorem pell_composition (d x₁ y₁ x₂ y₂ : ℤ) (h₁ : x₁ ^ 2 - d * y₁ ^ 2 = 1)
    (h₂ : x₂ ^ 2 - d * y₂ ^ 2 = 1) :
    (x₁ * x₂ + d * y₁ * y₂) ^ 2 - d * (x₁ * y₂ + x₂ * y₁) ^ 2 = 1 := by
  linear_combination (x₂ ^ 2 - d * y₂ ^ 2) * h₁ + h₂
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/ElementaryNumberTheory.leanTry it in the Lean web editor
pell_thirteenLean 4Proved here from basic factsFormally verified
/-- The fundamental solution of `x² − 13y² = 1` is surprisingly large: `649² − 13 · 180² = 1`. -/
theorem pell_thirteen : (649 : ℤ) ^ 2 - 13 * 180 ^ 2 = 1 := by
  norm_num
Axioms used: propextformal/Lumenary/ElementaryNumberTheory.leanTry it in the Lean web editor
pell_existsLean 4Applies a library theoremFormally verified
/-- **Pell's equation has a non-trivial solution** for every positive non-square `d`.
Mathlib's `Pell.exists_of_not_isSquare`, proved by Dirichlet's approximation argument as in the
lesson. -/
theorem pell_exists {d : ℤ} (h₀ : 0 < d) (hd : ¬ IsSquare d) :
    ∃ x y : ℤ, x ^ 2 - d * y ^ 2 = 1 ∧ y ≠ 0 :=
  Pell.exists_of_not_isSquare h₀ hd
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/ElementaryNumberTheory.leanTry it in the Lean web editor
pell_powersLean 4Applies a library theoremFormally verified
/-- Every solution with `x > 0` and `y ≥ 0` is a power of the fundamental solution `ε`:
`x + y√d = εⁿ`. Mathlib's `Pell.IsFundamental.eq_pow_of_nonneg`, stated for its structure
`Pell.Solution₁ d` of solutions. -/
theorem pell_powers {d : ℤ} {ε : Pell.Solution₁ d} (hε : Pell.IsFundamental ε)
    {a : Pell.Solution₁ d} (hx : 0 < a.x) (hy : 0 ≤ a.y) : ∃ n : ℕ, a = ε ^ n :=
  hε.eq_pow_of_nonneg hx hy
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/ElementaryNumberTheory.leanTry it in the Lean web editor

What is and is not formalised. Proved independently here: there is no primitive root modulo 88 (Theorem 2 for k=3k = 3); 33 is a primitive root modulo 77; 22 is a non-residue modulo 55; no integer ≡3(mod4)\equiv 3 \pmod 4 is a sum of two squares; the Brahmagupta–Fibonacci identity; the composition of Pell solutions; and 6492−13⋅1802=1649^2 - 13 \cdot 180^2 = 1. Cited from Mathlib: Theorem 1, Gauss's identity, Euler's criterion, both supplementary laws, quadratic reciprocity, Möbius inversion, Fermat's two-squares theorem, and Theorem 13. Not formalised here: Theorem 2 for general kk, the full classification of Theorem 3, and the continued-fraction algorithm for Pell's equation.

ComputationC

Experiments with primes

The first program decides for every n≤60n \le 60 whether a primitive root exists, checks Theorem 3, lists least primitive roots, and asks how often 22 is a primitive root.

Primitive roots and Artin's conjecturePythonExact computationExhaustive finite checkStatistical evidenceComputationally tested
"""Primitive roots: which moduli have them, and how often 2 is one.

A primitive root modulo n is a generator of the unit group (Z/nZ)^x. The
program finds, for every n up to 60, whether a primitive root exists, and
compares with the theorem: exactly when n is 1, 2, 4, p^k or 2p^k for an odd
prime p. It lists the least primitive root of the first primes, then counts the
primes below 50000 for which 2 is a primitive root and compares the proportion
with Artin's constant 0.3739558..., which Artin conjectured in 1927 to be the
limiting density (proved by Hooley in 1967 assuming the generalised Riemann
hypothesis; still open unconditionally).
"""

from math import gcd

ARTIN_CONSTANT = 0.3739558136

def prime_factors(n):
    """The distinct prime factors of n, by trial division."""
    factors, q = [], 2
    while q * q <= n:
        if n % q == 0:
            factors.append(q)
            while n % q == 0:
                n //= q
        q += 1
    if n > 1:
        factors.append(n)
    return factors

def totient(n):
    """Euler's phi function from the prime factorisation."""
    result = n
    for q in prime_factors(n):
        result -= result // q
    return result

def multiplicative_order(a, n):
    """Least k >= 1 with a^k = 1 mod n (requires gcd(a, n) = 1)."""
    phi = totient(n)
    order = phi
    for q in prime_factors(phi):
        while order % q == 0 and pow(a, order // q, n) == 1:
            order //= q
    return order

def primitive_root(n):
    """The least primitive root modulo n, or None if there is none."""
    if n == 1:
        return 0
    phi = totient(n)
    for a in range(1, n):
        if gcd(a, n) == 1 and multiplicative_order(a, n) == phi:
            return a
    return None

def predicted(n):
    """The classification: n = 1, 2, 4, p^k or 2 p^k with p an odd prime."""
    if n in (1, 2, 4):
        return True
    m = n // 2 if n % 2 == 0 else n
    if m % 2 == 0:
        return False
    return len(prime_factors(m)) == 1

def primes_below(n):
    """Sieve of Eratosthenes."""
    sieve = bytearray([1]) * n
    sieve[0:2] = b"\x00\x00"
    for i in range(2, int(n ** 0.5) + 1):
        if sieve[i]:
            sieve[i * i::i] = bytearray(len(sieve[i * i::i]))
    return [i for i in range(n) if sieve[i]]

def two_is_primitive_share(bound):
    """(number of odd primes p < bound with 2 a primitive root, number of odd primes)."""
    ps = primes_below(bound)[1:]
    hits = sum(multiplicative_order(2, p) == p - 1 for p in ps)
    return hits, len(ps)

def main():
    have = [n for n in range(1, 61) if primitive_root(n) is not None]
    print("n <= 60 with a primitive root:")
    print("  " + " ".join(map(str, have[:24])))
    print("  " + " ".join(map(str, have[24:])))
    agree = all((primitive_root(n) is not None) == predicted(n) for n in range(1, 61))
    print(f"matches 1, 2, 4, p^k, 2p^k for every n <= 60: {agree}")
    print("no primitive root: 8, 12, 15, ... e.g. orders mod 8:",
          [multiplicative_order(a, 8) for a in (1, 3, 5, 7)])
    first = primes_below(60)
    print("least primitive root of p:")
    print("  " + "  ".join(f"{p}:{primitive_root(p)}" for p in first[:9]))
    print("  " + "  ".join(f"{p}:{primitive_root(p)}" for p in first[9:]))
    for bound in (1000, 10000, 50000):
        hits, total = two_is_primitive_share(bound)
        print(f"2 is a primitive root for {hits:>4} of {total:>4} odd primes "
              f"below {bound:>5}: {hits / total:.4f}")
    print(f"Artin's constant (conjectured density):           {ARTIN_CONSTANT:.4f}")
    print()
    print("Epistemic status: the table for n <= 60 is exact and exhaustive, and")
    print("agrees with the classification proved in the lesson. The proportions")
    print("for 2 are statistical evidence for Artin's conjecture, which remains")
    print("unproved without the generalised Riemann hypothesis.")

if __name__ == "__main__":
    main()
Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.

The table is exact. The last lines are statistical evidence for a famous open problem. Emil Artin conjectured in 1927 that 22 (indeed any integer other than −1-1 that is not a perfect square) is a primitive root modulo infinitely many primes, with a density close to 0.37395580.3739558 (Artin's constant, ∏p(1−1p(p−1))\prod_p \big(1 - \frac{1}{p(p-1)}\big), for 22). Christopher Hooley proved this in 1967 assuming the generalised Riemann hypothesis. Unconditionally, Roger Heath-Brown (1986) showed that at most two prime numbers fail to be primitive roots for infinitely many primes — but no specific integer, not even 22, has been proved to work.

The second program checks quadratic reciprocity, Gauss's lemma and Eisenstein's count for all pairs of odd primes below 200200, and finds which small primes are sums of two squares.

Quadratic reciprocity and sums of two squares by computerPythonExact computationExhaustive finite checkComputationally tested
"""Quadratic reciprocity, checked three ways, and sums of two squares.

For every pair of distinct odd primes p, q below 200 the program computes the
Legendre symbols (p/q) and (q/p) by Euler's criterion and checks the law of
quadratic reciprocity. It also checks the two ingredients of the lesson's proof:
Gauss's lemma, (q/p) = (-1)^mu with mu the number of "negative" least residues
of q, 2q, ..., ((p-1)/2) q, and Eisenstein's lattice-point identity, that the
points under the diagonal of the (p/2) x (q/2) rectangle number
((p-1)/2)((q-1)/2). Finally it lists which primes are sums of two squares.
"""

def odd_primes_below(n):
    """Odd primes below n by trial division."""
    return [p for p in range(3, n, 2) if all(p % d for d in range(3, int(p ** 0.5) + 1, 2))]

def legendre(a, p):
    """Legendre symbol (a/p) for an odd prime p, by Euler's criterion."""
    r = pow(a % p, (p - 1) // 2, p)
    return -1 if r == p - 1 else r

def gauss_lemma(q, p):
    """(-1)^mu, mu = number of k*q (1 <= k <= (p-1)/2) with residue above p/2."""
    mu = sum((k * q) % p > p // 2 for k in range(1, (p - 1) // 2 + 1))
    return (-1) ** mu

def lattice_points(p, q):
    """Points (x, y), 1 <= x <= (p-1)/2, 1 <= y <= (q-1)/2, counted in two
    triangles: below the diagonal qx = py, and above it."""
    below = sum((k * q) // p for k in range(1, (p - 1) // 2 + 1))
    above = sum((k * p) // q for k in range(1, (q - 1) // 2 + 1))
    return below, above

def two_squares(n):
    """A representation n = a^2 + b^2 with 0 <= a <= b, or None."""
    a = 0
    while 2 * a * a <= n:
        b2 = n - a * a
        b = int(round(b2 ** 0.5))
        for c in (b - 1, b, b + 1):
            if c >= 0 and c * c == b2:
                return a, c
        a += 1
    return None

def main():
    primes = odd_primes_below(200)
    pairs = [(p, q) for p in primes for q in primes if p < q]
    reciprocity = all(legendre(p, q) * legendre(q, p)
                      == (-1) ** (((p - 1) // 2) * ((q - 1) // 2)) for p, q in pairs)
    gauss = all(gauss_lemma(q, p) == legendre(q, p) for p, q in pairs) and all(
        gauss_lemma(p, q) == legendre(p, q) for p, q in pairs)
    eisenstein = all(sum(lattice_points(p, q)) == ((p - 1) // 2) * ((q - 1) // 2)
                     for p, q in pairs)
    print(f"{len(pairs)} pairs of distinct odd primes below 200:")
    print(f"  (p/q)(q/p) = (-1)^((p-1)/2 * (q-1)/2) in every case: {reciprocity}")
    print(f"  Gauss's lemma agrees with Euler's criterion:         {gauss}")
    print(f"  lattice points below + above diagonal = product:     {eisenstein}")
    below, above = lattice_points(7, 11)
    print(f"  e.g. p = 7, q = 11: {below} + {above} = {below + above} = 3 * 5;"
          f" (7/11)(11/7) = {legendre(7, 11) * legendre(11, 7)}")
    minus_one = all((legendre(-1, p) == 1) == (p % 4 == 1) for p in primes)
    two = all((legendre(2, p) == 1) == (p % 8 in (1, 7)) for p in primes)
    print(f"  (-1/p) = 1 exactly when p = 1 mod 4:  {minus_one}")
    print(f"  (2/p) = 1 exactly when p = +-1 mod 8: {two}")
    print("Primes below 100 as sums of two squares:")
    reps = [(p, two_squares(p)) for p in [2] + odd_primes_below(100)]
    line = ""
    for p, rep in reps:
        if rep:
            item = f"{p}={rep[0]}^2+{rep[1]}^2"
            if len(line) + len(item) > 74:
                print("  " + line.rstrip())
                line = ""
            line += item + "  "
    print("  " + line.rstrip())
    missing = [p for p, rep in reps if rep is None]
    print(f"  not sums of two squares: {missing}")
    print(f"  all of these are 3 mod 4: {all(p % 4 == 3 for p in missing)}")
    print()
    print("Epistemic status: exact, exhaustive checks for primes below 200 (and")
    print("100). They confirm the theorems for these primes only; the lesson's")
    print("proofs (Gauss's lemma and Eisenstein's count, and the Gaussian")
    print("integers for two squares) cover all primes.")

if __name__ == "__main__":
    main()
Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.

These are exhaustive checks of proved theorems: confirmation, and a test of the proofs' ingredients one by one, but not proofs for all primes. The third program runs the continued-fraction algorithm for Pell's equation and verifies every answer exactly.

Pell's equation by continued fractionsPythonExact computationComputationally tested
"""Pell's equation x^2 - d y^2 = 1 solved by continued fractions.

The continued fraction of sqrt(d), for d not a square, is periodic:
sqrt(d) = [a0; a1, ..., a_r] with the block a1..a_r repeating. The convergents
h/k satisfy h^2 - d k^2 = (-1)^(i+1) q_(i+1), and the fundamental solution of
Pell's equation is the convergent just before the end of the first period (or
of the second, when the period length r is odd). The program runs the exact
integer algorithm, checks each answer, and composes the fundamental solution
with itself (Brahmagupta's composition) to produce the next solutions.
"""

from math import isqrt

def sqrt_continued_fraction(d):
    """(a0, period) for sqrt(d), d > 0 not a square, by the exact (m, q, a) recursion."""
    a0 = isqrt(d)
    if a0 * a0 == d:
        raise ValueError("d must not be a perfect square")
    m, q, a = 0, 1, a0
    period = []
    while a != 2 * a0:
        m = a * q - m
        q = (d - m * m) // q
        a = (a0 + m) // q
        period.append(a)
    return a0, period

def fundamental_solution(d):
    """Least x > 1, y > 0 with x^2 - d y^2 = 1, from the convergents of sqrt(d)."""
    a0, period = sqrt_continued_fraction(d)
    r = len(period)
    terms = [a0] + (period * 2)[: (r if r % 2 == 0 else 2 * r) - 1]
    h_prev, h = 1, terms[0]
    k_prev, k = 0, 1
    for a in terms[1:]:
        h_prev, h = h, a * h + h_prev
        k_prev, k = k, a * k + k_prev
    return h, k

def compose(s, t, d):
    """Brahmagupta's composition of two solutions (x1 + y1 sqrt d)(x2 + y2 sqrt d)."""
    (x1, y1), (x2, y2) = s, t
    return x1 * x2 + d * y1 * y2, x1 * y2 + x2 * y1

def brute_force(d, limit):
    """Least y in 1..limit with d y^2 + 1 a square, as (x, y), or None."""
    for y in range(1, limit + 1):
        x2 = d * y * y + 1
        x = isqrt(x2)
        if x * x == x2:
            return x, y
    return None

def main():
    print(" d  period of sqrt(d)      fundamental solution (x, y)")
    ok = True
    for d in range(2, 31):
        if isqrt(d) ** 2 == d:
            continue
        a0, period = sqrt_continued_fraction(d)
        x, y = fundamental_solution(d)
        ok &= x * x - d * y * y == 1
        if d <= 14 or d in (19, 22, 29):
            shown = "[" + str(a0) + "; " + ",".join(map(str, period)) + "]"
            print(f"{d:>2}  {shown:<21}  ({x}, {y})")
    print(f"every non-square d <= 30 solved and checked exactly: {ok}")
    agree = all(brute_force(d, 2000) == fundamental_solution(d)
                for d in range(2, 31) if isqrt(d) ** 2 != d)
    print(f"brute force agrees for d <= 30 (y <= 2000): {agree}")
    for d in (61, 109):
        x, y = fundamental_solution(d)
        print(f"d = {d}: x = {x}, y = {y}")
        print(f"        x^2 - {d} y^2 = {x * x - d * y * y}")
    s = fundamental_solution(2)
    powers = [s]
    for _ in range(4):
        powers.append(compose(powers[-1], s, 2))
    print("x^2 - 2y^2 = 1: the powers of (3, 2) under composition are")
    print("  " + ", ".join(map(str, powers)))
    print()
    print("Epistemic status: exact integer computations, each solution verified")
    print("by substitution. That the continued-fraction method always finds the")
    print("fundamental solution, and that every solution is a power of it, are")
    print("theorems (see the lesson); the runs here are illustrations.")

if __name__ == "__main__":
    main()
Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.

The jump from d=60d = 60 (solution (31,4)(31, 4)) to d=61d = 61 (a ten-digit xx) shows why the equation is hard to solve by search, and why Fermat chose 6161 for his challenge. The size of the fundamental solution is governed by the class number and the regulator of Q(d)\Q(\sqrt d), an analytic subject in its own right.

Explore

Explore: multiplicative partners and primitive roots

In the multiplication tab of the clock, choose a prime number of hours kk. Every non-zero residue has a partner, so the units form a group of order k−1k - 1. Try k=7k = 7 and step through the multiples of 33 in your head: 3,9≡2,6,18≡4,12≡5,15≡13, 9 \equiv 2, 6, 18 \equiv 4, 12 \equiv 5, 15 \equiv 1. The powers of 33 visit every unit. Then try k=8k = 8, where the units 1,3,5,71, 3, 5, 7 are each their own partner. That is the reason, in Theorem 2, that no primitive root exists.

The clock laboratory

On a clock with k hours, counting wraps around. Explore adding and multiplying.

01234567891011

9 + 5 = 14 ≡ 2 (mod 12)

14 hours forward on a 12-hour clock lands on 2: the remainder when 14 is divided by 12.

Exercises

Exercises

1. Number theory

Warm-upHuman

How many primitive roots are there modulo 1313?

2. Number theory

CoreHuman

Use quadratic reciprocity to compute the Legendre symbol (37101)\left(\frac{37}{101}\right). (Enter 11 or −1-1.)

3. Number theory

CoreHuman

For which moduli nn does a primitive root exist? (Select all that apply.)

Choose all that apply

4. Number theory

Warm-upHuman

Which of these numbers are sums of two squares of integers? (Select all that apply.)

Choose all that apply

5. Number theory

CoreHuman

In the proof of Euler's criterion, let gg be a primitive root modulo an odd prime pp and a=gka = g^k. Why is a(p−1)/2≡1a^{(p-1)/2} \equiv 1 exactly when kk is even?

Choose one

6. Number theory

CoreHuman

Compute ∑d∣60μ(d)\sum_{d \mid 60} \mu(d), where μ\mu is the Möbius function.

7. Number theory

StretchHuman

The fundamental solution of x2−2y2=1x^2 - 2y^2 = 1 is (3,2)(3, 2). Using composition, (x+y2)=(3+22)2(x + y\sqrt2) = (3 + 2\sqrt2)^2, find the next solution. What is its xx?

8. Number theory

CoreFormal

In Lean, legendreSym p a is the Legendre symbol (ap)\left(\frac{a}{p}\right). Which statement is the law of quadratic reciprocity for primes p, q (with [Fact p.Prime] [Fact q.Prime])?

Choose one

9. Number theory

StretchComputational

Write order(a, n) returning the multiplicative order of aa modulo nn (assume gcd⁡(a,n)=1\gcd(a, n) = 1, n≥2n \ge 2), and primitive_roots(p) returning the sorted list of primitive roots modulo a prime pp. Check that there are φ(p−1)\varphi(p - 1) of them.

Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.
Common misconceptionsH

Common misconceptions

Misconception

"Every modulus has a primitive root." Modulo 88 every unit squares to 11, and modulo 1515 every unit has order dividing 4<8=φ(15)4 \lt 8 = \varphi(15). Primitive roots exist exactly for n=1,2,4,pk,2pkn = 1, 2, 4, p^k, 2p^k with pp an odd prime (Theorem 3).

Misconception

"Quadratic reciprocity is an isolated trick." It has more than two hundred published proofs, through Gauss sums, lattice points, cyclotomic fields, counting arguments and more, and far-reaching generalisations. These include cubic and biquadratic reciprocity (Gauss, Eisenstein, Jacobi), Hilbert's reciprocity law, the Artin reciprocity law of class field theory, and the Langlands programme, which can be read as a vast non-abelian reciprocity law.

Misconception

"A Jacobi symbol (an)=1\left(\frac an\right) = 1 means that aa is a square modulo nn." The Legendre symbol does detect squares modulo a prime. Its extension to odd composite moduli, the Jacobi symbol (an)=∏(api)\left(\frac{a}{n}\right) = \prod \left(\frac{a}{p_i}\right), does not. For example (215)=(23)(25)=(−1)(−1)=1\left(\frac{2}{15}\right) = \left(\frac 23\right)\left(\frac 25\right) = (-1)(-1) = 1, yet 22 is not a square modulo 1515 (it is not even a square modulo 33).

Misconception

"Every n≡1(mod4)n \equiv 1 \pmod 4 is a sum of two squares." The congruence condition n≢3(mod4)n \not\equiv 3 \pmod 4 is necessary only. 21≡1(mod4)21 \equiv 1 \pmod 4 is not a sum of two squares, because 33 and 77 divide it to odd powers. The full criterion is about the prime factorisation.

Misconception

"Pell's equation is Pell's." Euler attributed it to John Pell by mistake (Pell did not solve it). The equation was studied by Brahmagupta (628), solved in general by the chakravāla method of Jayadeva and Bhāskara II (11th–12th centuries), and its solvability was first proved by Lagrange (1768).

ViewpointsH

Many ways of seeing

Algebra— Reciprocity from cyclotomic fields

Let ζ=e2πi/p\zeta = e^{2\pi i/p} and form the Gauss sum g=∑a=1p−1(ap)ζag = \sum_{a=1}^{p-1}\left(\frac ap\right)\zeta^a. A short computation gives g2=(−1p)p=p∗g^2 = \left(\frac{-1}{p}\right)p = p^*, so p∗∈Q(ζ)\sqrt{p^*} \in \Q(\zeta). Now work modulo qq in the ring Z[ζ]\Z[\zeta]. On one side gq≡∑(ap)ζaq=(qp)gg^q \equiv \sum \left(\frac ap\right)\zeta^{aq} = \left(\frac qp\right)g, by the Frobenius property (x+y)q≡xq+yq(x + y)^q \equiv x^q + y^q. On the other, gq=g (p∗)(q−1)/2≡g(p∗q)g^q = g\,(p^*)^{(q-1)/2} \equiv g\left(\frac{p^*}{q}\right), by Euler's criterion. Comparing the two gives reciprocity. In the language of Galois theory, (p∗q)\left(\frac{p^*}{q}\right) records whether the Frobenius element at qq fixes p∗\sqrt{p^*}, and (qp)\left(\frac qp\right) records whether the corresponding element of Gal⁡(Q(ζ)/Q)≅(Z/p)×\operatorname{Gal}(\Q(\zeta)/\Q) \cong (\Z/p)^\times is a square. Reciprocity says these agree, and Artin reciprocity generalises it to all abelian extensions.

Geometry— Lattices and hyperbolas

The proof of Theorem 8 is a lattice-point count, and lattice geometry gives other proofs too. By Minkowski's theorem, a convex region symmetric about 00 with area greater than 4det⁡L4\det L contains a non-zero point of the lattice LL. Take L={(a,b)∣b≡xa(modp)}L = \{(a, b) \mid b \equiv xa \pmod p\}, where x2≡−1x^2 \equiv -1, with det⁡L=p\det L = p, and the disc a2+b2<2pa^2 + b^2 \lt 2p. It contains a point with 0<a2+b2<2p0 \lt a^2 + b^2 \lt 2p and p∣a2+b2p \mid a^2 + b^2, so a2+b2=pa^2 + b^2 = p. Pell's equation is geometric too. Its solutions are the lattice points on the hyperbola x2−dy2=1x^2 - dy^2 = 1, and ε\varepsilon acts on the hyperbola as a hyperbolic "rotation" (a Lorentz boost) preserving the lattice Z[d]\Z[\sqrt d]. The group U≅Z/2×ZU \cong \Z/2 \times \Z is the group of such symmetries. This is the first case of Dirichlet's unit theorem in algebraic number theory.

Analysis— Primes in progressions and L-functions

Are there infinitely many primes ≡1(mod4)\equiv 1 \pmod 4? Yes. If p1,…,pkp_1, \dots, p_k were all of them, any prime factor of (2p1⋯pk)2+1(2p_1\cdots p_k)^2 + 1 would be ≡1(mod4)\equiv 1 \pmod 4 by Corollary 5, and new. Dirichlet's theorem (1837) gives infinitely many primes ≡a(modm)\equiv a \pmod m whenever gcd⁡(a,m)=1\gcd(a, m) = 1, and each class receives the same share 1/φ(m)1/\varphi(m). The proof is analytic. It uses the LL-functions L(s,χ)=∑χ(n)n−sL(s, \chi) = \sum \chi(n)n^{-s} attached to characters χ\chi of (Z/m)×(\Z/m)^\times, and the key point is that L(1,χ)≠0L(1, \chi) \ne 0. For χ(n)=(−1n)\chi(n) = \left(\frac{-1}{n}\right), the character modulo 44, Leibniz's series 1−13+15−⋯=π41 - \frac13 + \frac15 - \dots = \frac\pi4 is L(1,χ)L(1, \chi). Its non-vanishing is the first case. See analytic number theory.

Probability— Heuristics, biases and densities

Many statements in this subject are densities: half the odd primes are ≡1(mod4)\equiv 1 \pmod 4; 22 is a quadratic residue for half the primes, namely those ≡±1(mod8)\equiv \pm 1 \pmod 8; 22 is a primitive root for a proportion ≈0.374\approx 0.374 of primes (conjecturally). Artin's constant comes from a probabilistic heuristic. For each prime ℓ\ell, the chance that ℓ∣p−1\ell \mid p - 1 and 22 is an ℓ\ell-th power modulo pp is "1ℓ(ℓ−1)\frac{1}{\ell(\ell - 1)}", and treating these events as independent gives ∏ℓ(1−1ℓ(ℓ−1))\prod_\ell \big(1 - \frac1{\ell(\ell-1)}\big). Heuristics like this are guides, not proofs. They can even mislead: Chebyshev's bias is the observation that primes ≡3(mod4)\equiv 3 \pmod 4 are ahead of primes ≡1(mod4)\equiv 1 \pmod 4 in most initial segments. Rubinstein and Sarnak (1994) quantified it, under the generalised Riemann hypothesis and a linear independence hypothesis: the logarithmic density of xx for which 3 mod 43 \bmod 4 leads is about 0.99590.9959.

Computation— Cryptography and fast algorithms

Primitive roots are the setting of Diffie–Hellman key exchange (1976). With a public prime pp and primitive root gg, two parties exchange gag^a and gbg^b and share the secret gabg^{ab}. Computing gag^a is fast by repeated squaring. Recovering aa — the discrete logarithm — is believed to be hard for well-chosen large pp, a belief supported by decades of cryptanalysis, not by proof (cryptography). Legendre and Jacobi symbols can be computed in polynomial time with reciprocity, without factoring. Square roots modulo a prime are found efficiently by the Tonelli–Shanks algorithm. Distinguishing squares from non-squares modulo a composite n=pqn = pq without knowing pp and qq seems hard, and the Goldwasser–Micali cryptosystem (1982) is built on that assumption.

History & global context

History and global context

  • India. Brahmagupta's Brāhmasphuṭasiddhānta (628) introduced the composition law (bhāvanā) for x2−Ny2=kx^2 - Ny^2 = k and used it to generate solutions of Pell's equation. Jayadeva (11th century) and Bhāskara II (Bījagaṇita, 1150) gave the cyclic chakravāla method, which always succeeds, and solved x2−61y2=1x^2 - 61y^2 = 1.
  • Fermat and Euler. Fermat stated the two-squares theorem (letter to Mersenne, 1640) and challenged mathematicians with x2−61y2=1x^2 - 61y^2 = 1 (1657); William Brouncker and John Wallis found methods. Euler proved the two-squares theorem (1747–1749), introduced the totient and the term "primitive root", and conjectured quadratic reciprocity. Lagrange proved that Pell's equation always has a non-trivial solution (1768).
  • Legendre and Gauss. Legendre introduced his symbol (1798) and published an incomplete proof of reciprocity. Gauss gave the first complete proof in the Disquisitiones Arithmeticae (1801), together with the first proof that primitive roots exist modulo every prime, and eventually published eight proofs. Gotthold Eisenstein's lattice-point proof (1844) is the one given here.
  • The nineteenth and twentieth centuries. August Möbius introduced his function (1832). Peter Gustav Lejeune Dirichlet proved his theorem on primes in progressions (1837), founding analytic number theory. Emil Artin made his conjecture on primitive roots in 1927, and Christopher Hooley proved it conditionally in 1967. Reciprocity grew into class field theory (Hilbert, Takagi, Artin) and then into the Langlands programme.
Further reading

Further reading

  • Kenneth Ireland and Michael Rosen, A Classical Introduction to Modern Number Theory (2nd edition, 1990), chapters 2–6 — primitive roots, quadratic reciprocity with Gauss sums, and more.
  • G. H. Hardy and E. M. Wright, An Introduction to the Theory of Numbers (1938; 6th edition 2008) — arithmetic functions, sums of squares, continued fractions and Pell's equation.
  • Ivan Niven, Herbert S. Zuckerman and Hugh L. Montgomery, An Introduction to the Theory of Numbers (5th edition, 1991).
  • Franz Lemmermeyer, Reciprocity Laws: From Euler to Eisenstein (2000) — the history and many proofs of reciprocity.
  • André Weil, Number Theory: An Approach through History from Hammurapi to Legendre (1984).