Algebra

The sums of primitive roots are always whole

Take the roots of unity of order exactly q, raise each to the power n and add them. The answer is always a whole number, it depends on n only through what n shares with q, and as n varies the sums behave like the sines and cosines of a Fourier series — so well that Ramanujan could rebuild the sum of the divisors of any number from them, and prove that their weighted total is nought, a fact that at n = 1 is the prime number theorem.

Worth reading first: The sums that obey a smaller equation · The polygon an equation forces.

A root of unity of order qq is one that returns to 11 after exactly qq multiplications and no fewer. Of the qq solutions of zq=1z^q = 1, the ones of order exactly qq are the primitive ones: e2πia/qe^{2\pi i a/q} with aa sharing no factor with qq. There are φ(q)\varphi(q) of them, Euler’s totient.

The polygon an equation forces found that the primitive qq-th roots add up to a very small number: 11, −1-1 or 00, according to the Möbius function of qq. Here is the generalisation Srinivasa Ramanujan wrote down in 1918. Raise every primitive qq-th root to the same power nn before adding:

cq(n)=∑1≤a≤qgcd⁡(a,q)=1e2πian/q.c_q(n) = \sum_{\substack{1 \le a \le q \\ \gcd(a, q) = 1}} e^{2\pi i a n/q}.

Each term is a point on the unit circle. There is no evident reason for the sum to be anything in particular.

The primitive 15th roots of unity, raised to a power and added. c₁₅(1) = 1; c₁₅(3) = −2; c₁₅(5) = −4; c₁₅(6) = −2; c₁₅(10) = −4; c₁₅(15) = 8.
Fig. 1 The eight primitive fifteenth roots of unity, each raised to the power n and then added head to tail from the origin, for n = 1, 3, 5, 6, 10 and 15. The walk always ends on a whole number — 1, −2, −4, −2, −4 and 8 — and the value depends on n only through what n shares with 15.

And yet it is always a whole number. For q=15q = 15 the eight primitive roots, raised to the first power, trace an irregular octagonal walk that ends at 11. Raised to the third power they end at −2-2; to the fifth, at −4-4; to the fifteenth, all eight land on 11 and the walk runs straight out to 88. The sums cq(n)c_q(n) are Ramanujan’s sums, and this essay is about why they are whole, what formula they obey, and what Ramanujan used them for.

Why the sum cannot be anything but whole

The reason is the one the sums that obey a smaller equation gave for Gauss’s periods, and Ramanujan’s sum is in fact the coarsest period of all.

Raising a root of unity to a power gg that shares no factor with qq sends primitive roots to primitive roots — it multiplies each exponent aa by gg, and gaga still shares no factor with qq — and it sends distinct roots to distinct roots. So it permutes the set of primitive qq-th roots. The same map applied to the sum permutes its terms, and leaves the sum unchanged. The sum is therefore fixed by every symmetry of the field generated by a primitive qq-th root, and a number in that field fixed by every symmetry is rational.

It is also a sum of roots of unity, and so an algebraic integer; a rational algebraic integer is a whole number. The same argument applies with the exponent anan in place of aa, for any fixed nn, so every cq(n)c_q(n) is whole. The figures check it independently: each sum is added numerically and required to lie within a hundred-millionth of an integer, with an imaginary part that vanishes because the primitive roots come in conjugate pairs.

The smallest cases can be done in the head. The primitive fourth roots are ii and −i-i, and they add to 00; squared, both become −1-1, and the sum is −2-2; raised to the fourth power, both become 11, and the sum is 22. The primitive sixth roots are 12±32i\tfrac12 \pm \tfrac{\sqrt3}{2} i, whose imaginary parts cancel and whose real parts add to 11; squared, they become the primitive cube roots −12±32i-\tfrac12 \pm \tfrac{\sqrt3}{2}i, which add to −1-1. In each case the irrational parts — ii, 3\sqrt 3 — are paired off by complex conjugation or by a larger symmetry, and only a whole number is left.

In the language of periods, cq(n)c_q(n) is the single period that uses the whole group — every primitive root in one coset — evaluated at the root e2πin/qe^{2\pi i n/q}. A period of index one has an equation of degree one, and an equation of degree one with whole-number coefficients has a whole-number root.

A prime, where there are only two answers

When qq is a prime pp, every root except 11 is primitive, and there are only two cases.

The primitive 7th roots of unity, raised to a power and added. c₇(1) = −1; c₇(2) = −1; c₇(3) = −1; c₇(7) = 6.
Fig. 2 The six primitive seventh roots of unity raised to the powers 1, 2, 3 and 7 and added. For any n not divisible by 7, raising to the n-th power only shuffles the six roots, and they add to −1; for n = 7 every root becomes 1 and the sum is 6.

If pp does not divide nn, raising to the nn-th power shuffles the p−1p - 1 non-trivial roots among themselves, and their sum is always the same: the full sum of all pp roots is 00, so the non-trivial ones add to −1-1. If pp divides nn, every root is sent to 11 and the sum is p−1p - 1. So

cp(n)={−1p∤n,p−1p∣n.c_p(n) = \begin{cases} -1 & p \nmid n, \\ p - 1 & p \mid n. \end{cases}

The walk for a prime is the regular polygon walked out of order: raising to the power 22 visits the vertices of the heptagon two at a time, raising to 33 three at a time, and every such order closes up one step short of the origin.

The table, and the formula behind it

For a composite qq the values are more varied, but the pattern is visible in a table.

Ramanujan's sums for q up to 12 and n up to 24. A table of Ramanujan sums; the first column, the Möbius function, reads 1, −1, −1, 0, −1, 1, −1, 0, 0, 1, −1, 0.
Fig. 3 The Ramanujan sum for q = 1 to 12 down the side and n = 1 to 24 across, shaded by sign. Every entry is a whole number; the first column is the Möbius function μ(q); each row repeats with period q and peaks at φ(q) on the multiples of q.

Three things stand out, and all three are forced.

Each row is periodic in nn with period qq, because e2πian/qe^{2\pi i a n/q} depends on nn only modulo qq.

Each row reaches its maximum φ(q)\varphi(q) exactly at the multiples of qq, where every term is 11.

Each row depends on nn only through gcd⁡(n,q)\gcd(n, q). Row 1212 reads 0,2,0,−2,0,−4,0,−2,0,2,0,40, 2, 0, -2, 0, -4, 0, -2, 0, 2, 0, 4 and then repeats; the value at n=10n = 10 equals the value at n=2n = 2 because both share exactly 22 with 1212. The reason is the permutation argument once more: multiplying nn by a number coprime to qq only permutes the terms of the sum.

The closed form, found by Robert von Sterneck in 1902 and independently by Otto Hölder, writes the value directly. With g=gcd⁡(n,q)g = \gcd(n, q),

cq(n)=μ ⁣(qg)φ(q)φ(q/g).c_q(n) = \mu\!\left(\frac{q}{g}\right) \frac{\varphi(q)}{\varphi(q/g)}.

Every entry in every figure is checked against it. For q=15q = 15 and n=6n = 6, g=3g = 3, q/g=5q/g = 5, μ(5)=−1\mu(5) = -1 and φ(15)/φ(5)=8/4=2\varphi(15)/\varphi(5) = 8/4 = 2, so c15(6)=−2c_{15}(6) = -2 — the walk in the first figure that ends two units to the left of the origin.

A second formula, a sum over the common divisors, shows the structure differently:

cq(n)=∑d∣gcd⁡(n,q)μ ⁣(qd)d.c_q(n) = \sum_{d \mid \gcd(n, q)} \mu\!\left(\frac{q}{d}\right) d.

It comes from the fact that the sum of all qq-th roots raised to the nn-th power is qq if qq divides nn and 00 otherwise — the filter that every third coefficient used to pick out terms of a polynomial — combined with Möbius inversion to strip off the roots of smaller order.

Thirty, built from two, three and five

When qq has several prime factors, the sum splits along them.

The primitive 30th roots of unity, raised to a power and added. c₃₀(1) = −1; c₃₀(2) = 1; c₃₀(3) = 2; c₃₀(5) = 4; c₃₀(6) = −2; c₃₀(30) = 8.
Fig. 4 The eight primitive thirtieth roots of unity raised to the powers 1, 2, 3, 5, 6 and 30 and added. The sums are −1, 1, 2, 4, −2 and 8: each is the product of the sums for 2, 3 and 5 at the same power — for n = 5, (−1)(−1)(4) = 4.

The Ramanujan sum is multiplicative in qq: if qq and rr share no factor, then cqr(n)=cq(n) cr(n)c_{qr}(n) = c_q(n)\, c_r(n) for every nn. The reason is the Chinese remainder theorem. A primitive qrqr-th root of unity is, uniquely, a product of a primitive qq-th root and a primitive rr-th root, so the sum over primitive qrqr-th roots is the product of the two smaller sums.

So c30c_{30} is a product of three prime cases, each of which takes only two values. For n=5n = 5: c2(5)=−1c_2(5) = -1 since 2∤52 \nmid 5, c3(5)=−1c_3(5) = -1 since 3∤53 \nmid 5, and c5(5)=4c_5(5) = 4 since 5∣55 \mid 5; the product is 44, and the eight-step walk for n=5n = 5 ends four units to the right. For n=6n = 6, c2(6)=1c_2(6) = 1, c3(6)=2c_3(6) = 2, c5(6)=−1c_5(6) = -1, and the product is −2-2. Every value in the table is a product of numbers of the form −1-1 or p−1p - 1, with the correction for prime powers that von Sterneck’s formula carries: cpk(n)c_{p^k}(n) is 00 unless pk−1p^{k-1} divides nn, which is why the rows for 44, 88 and 99 are mostly empty.

That is also why the sums are so much smaller than they might be. Eight unit vectors could add to anything up to 88 in length; for q=30q = 30 they reach that length only when 1515 divides nn — +8+8 at the multiples of 3030, −8-8 at the odd multiples of 1515 — and otherwise stay within 44 of the origin. The primitive roots are spread so evenly round the circle that most of them cancel, and what survives is decided prime by prime.

The rows are orthogonal, like sines and cosines

The table’s rows are more than periodic. Take two different rows, qq and rr, multiply them entry by entry over a common period — any multiple of both qq and rr — and add. The answer is exactly 00.

∑n=1Lcq(n) cr(n)=0(q≠r, q∣L, r∣L).\sum_{n=1}^{L} c_q(n)\, c_r(n) = 0 \qquad (q \ne r,\ q \mid L,\ r \mid L).

The figure’s table is checked this way for every pair of rows up to twelve, over a period of 27,72027{,}720. When q=rq = r the same sum is L φ(q)L\,\varphi(q), never zero. That is the defining property of an orthogonal family, the property the sines and cosines of a Fourier series have: sin⁡(jx)\sin(jx) and sin⁡(kx)\sin(kx) multiplied and integrated over a period give nought unless j=kj = k.

The analogy is exact in one direction. A function of nn that depends only on nn modulo qq can be written as a combination of the rows cd(n)c_d(n) for the divisors dd of qq — provided it depends on nn only through gcd⁡(n,q)\gcd(n, q), the functions called even modulo qq. The Ramanujan sums are the Fourier basis for such functions, with divisibility playing the part of frequency: a row cdc_d is a “tone” that repeats every dd steps.

Rebuilding the sum of divisors

Ramanujan’s paper of 1918 used the analogy in the other direction. An arithmetic function like σ(n)\sigma(n), the sum of the divisors of nn, is not periodic at all. But Ramanujan found that it can still be expanded in the cq(n)c_q(n), exactly as a non-periodic signal is expanded in sines of every frequency:

σ(n)n=π26∑q=1∞cq(n)q2.\frac{\sigma(n)}{n} = \frac{\pi^2}{6} \sum_{q=1}^{\infty} \frac{c_q(n)}{q^2}.

Sums of divisors rebuilt from Ramanujan's sums. n = 2: partial sum 1.4997 against σ(n)/n = 1.5000; n = 6: partial sum 2.0006 against σ(n)/n = 2.0000; n = 7: partial sum 1.1429 against σ(n)/n = 1.1429; n = 60: partial sum 2.8284 against σ(n)/n = 2.8000.
Fig. 5 Partial sums of π2/6\pi^2/6 times the Ramanujan sums for n, the q-th divided by q2q^2, for n = 2, 6, 7 and 60, with the number of terms running to 60. The dashed lines are the sums of divisors divided by n — 1.5, 2, 1.143 and 2.8 — and each partial sum settles on its own line.

For n=7n = 7, a prime, the terms are cq(7)=μ(q)c_q(7) = \mu(q) unless 77 divides qq; the series is π26(1−14−19−… )\frac{\pi^2}{6}\left(1 - \frac14 - \frac19 - \dots\right) with a correction at every multiple of 77, and it settles on σ(7)/7=8/7\sigma(7)/7 = 8/7. For n=6n = 6 it settles on 22 — six is perfect, so its divisors add to twice itself — and for n=60n = 60 on 168/60=2.8168/60 = 2.8.

The factor π2/6\pi^2/6 is ∑1/q2\sum 1/q^2, the value of ζ(2)\zeta(2) that sums of powers, read off a staircase places among the even zeta values, and it enters because the average of σ(n)/n\sigma(n)/n over all nn is exactly that. The Ramanujan sums supply the deviation of each particular nn from the average. A function defined by divisibility is being written as a superposition of sums of roots of unity, each of which encodes one divisibility test.

The expansion also makes the special numbers visible. A number whose divisors add to exactly twice itself, like 66 or 2828, has σ(n)/n=2\sigma(n)/n = 2, so its Ramanujan series sums to exactly 22; the numbers whose divisors add to three times themselves, which divisors that add to three times the number catalogued, have series summing to 33. The series does not make such numbers easier to find — each term needs gcd⁡(n,q)\gcd(n, q), and so knowledge of the factors of nn — but it says in what sense being perfect is a statement about how nn sits against every modulus at once: each term records whether qq, or a part of it, divides nn, and the weights 1/q21/q^2 make the small moduli count most.

Ramanujan gave several such expansions in the same paper, among them one for the number of divisors, d(n)=−∑qln⁡qqcq(n)d(n) = -\sum_q \frac{\ln q}{q} c_q(n), which converges only conditionally, and one for the number of ways of writing nn as a sum of two squares.

A sum that is nought, and the primes

The most striking of Ramanujan’s identities is the simplest to state:

∑q=1∞cq(n)q=0for every n.\sum_{q=1}^{\infty} \frac{c_q(n)}{q} = 0 \qquad \text{for every } n.

Ramanujan's sums divided by q add up to nought. n = 1: partial sum −0.00166 at 3000 terms; n = 2: partial sum −0.00196 at 3000 terms; n = 6: partial sum −0.00607 at 3000 terms.
Fig. 6 Partial sums of the q-th Ramanujan sum divided by q, for n = 1, 2 and 6, with the number of terms from 10 to 3000 on a logarithmic scale. Each oscillates and closes in on nought; at 3000 terms the sums are −0.0017, −0.0020 and −0.0061.

For n=1n = 1 the terms are μ(q)/q\mu(q)/q, and the statement becomes

∑q=1∞μ(q)q=0,\sum_{q=1}^{\infty} \frac{\mu(q)}{q} = 0,

which Edmund Landau showed in 1899 to be equivalent to the prime number theorem — the statement, followed in counting what has no formula, that the primes up to xx number about x/ln⁡xx/\ln x. The equivalence runs through the product Euler wrote for the zeta function, the sieve written as a product: the reciprocal of that product is the series ∑μ(q)/qs\sum \mu(q)/q^s, and its value at s=1s = 1 is the sum in the figure. The figure’s curves approach nought slowly and irregularly, and the slowness is honest: the rate at which ∑μ(q)/q\sum \mu(q)/q approaches its limit is controlled by the zeros of the Riemann zeta function, and an estimate good enough to settle the Riemann hypothesis would be a statement about exactly this kind of curve.

So a sum of roots of unity, weighted by 1/q1/q, contains the distribution of the primes. That is the surprising connection Ramanujan’s sums make, and it is not a coincidence of notation: the Möbius function is the sum of the primitive roots, and the Möbius function is the device by which counting primes is turned into analysis.

Where the sums are used now

The sums found their largest use in the circle method of Hardy, Littlewood and Ramanujan himself, the technique for counting the ways of writing a number as a sum of primes or of powers.

When the method predicts how many ways a large even number NN can be written as a sum of two primes, the prediction has two factors. One is smooth, about N/(ln⁡N)2N/(\ln N)^2. The other, the singular series, adjusts for divisibility: it is larger when NN has many small prime factors, because then fewer residue classes are ruled out. The singular series is a sum over qq of Ramanujan’s sums cq(N)c_q(N) weighted by the square of μ(q)/φ(q)\mu(q)/\varphi(q) — one term per modulus, each asking how NN sits relative to the multiples of qq. The predicted counts match computation to high accuracy for every even number anyone has checked, though the prediction itself remains unproved.

In signal processing, the rows of the table have been used since the 2010s as a basis for detecting hidden periods in integer-valued sequences, since they are integer-valued and orthogonal and a period of qq shows up as energy in the rows cdc_d with d∣qd \mid q.

What the walks and tables cannot show

The integrality is checked, then proved. Each drawn sum is computed as a sum of floating-point cosines and required to be within 10−810^{-8} of a whole number; each also agrees with von Sterneck’s closed form. The proof is the permutation argument, which the figures do not show.

The expansions are drawn only to finitely many terms. The partial sums of σ(n)/n\sigma(n)/n at sixty terms are within a few thousandths of their targets, and the partial sums of cq(n)/qc_q(n)/q at three thousand terms are within a hundredth of nought. Neither is a proof of convergence. Ramanujan’s expansion of σ(n)/n\sigma(n)/n converges absolutely and the proof is short; the one for ∑cq(n)/q\sum c_q(n)/q lies at the depth of the prime number theorem, and the figure is only a picture of it.

The analogy with Fourier series is exact only for functions that are even modulo qq. For general arithmetic functions, when a Ramanujan expansion exists, whether it is unique is a subtle question, and some functions have expansions of different kinds that converge to the same values.

Still open: how fast the Möbius sums settle

The sum ∑q≤Qμ(q)/q\sum_{q \le Q} \mu(q)/q tends to nought, and the prime number theorem is equivalent to that. How fast it tends to nought is not known. If the Riemann hypothesis is true, the partial sums shrink faster than Q−1/2+εQ^{-1/2+\varepsilon} for every positive ε\varepsilon; the best unconditional bound, from the zero-free region of the zeta function, is much weaker: it shrinks like exp⁡(−c(ln⁡Q)3/5)\exp\big(-c(\ln Q)^{3/5}\big) up to smaller factors — faster than any power of 1/ln⁡Q1/\ln Q, but slower than any power of 1/Q1/Q.

The same holds for the unweighted sums M(Q)=∑q≤Qμ(q)M(Q) = \sum_{q \le Q} \mu(q), Mertens’s function, which how evenly the fractions spread met as the measure of how evenly the Farey fractions fill the interval: the Riemann hypothesis is equivalent to M(Q)M(Q) growing no faster than Q1/2+εQ^{1/2 + \varepsilon}. Franz Mertens conjectured in 1897 that ∣M(Q)∣<Q|M(Q)| < \sqrt Q always; Andrew Odlyzko and Herman te Riele disproved that in 1985 without exhibiting a counterexample, and the smallest QQ where it fails is still unknown. The curves in the last figure are the gentlest possible view of the same unknown.

A sum that forgets everything but a divisor

The habit worth keeping is to ask what a sum is invariant under.

Eight points on a circle, added, could land anywhere. Because they are all the primitive roots of one order, every symmetry of the number system shuffles them among themselves, and the sum has nowhere to go but the whole numbers. Raising them to a power nn keeps that property and adds one more: the answer can see only what nn shares with qq. Invariance under shuffling made the sums whole; invariance under coprime scaling made them depend only on a divisor; and those two facts together are what let Ramanujan write the sum of divisors, and the distribution of the primes, in terms of roots of unity.

Shares its objects with

Essays that name at least two of the same things, and that neither author linked.

Named objects

A dashed tag is an object no other essay names yet.

Cyclotomic polynomialFourier seriesGreatest common divisorMobius functionPrime number theoremRoots of unityTotient