Number

Sixty needs two digits and sixty-one needs ten

The smallest solution of x² − 60y² = 1 is x = 31. For x² − 61y² = 1 it is x = 1,766,319,049. The jump is not an accident of 61: the solution is exactly the product of one period's complete quotients, so its size is set by how long the continued fraction takes to come home — and for the cattle problem Archimedes is said to have posed, that product has 103,273 digits.

Worth reading first: Why the expansion has to repeat · A method that is allowed to miss.

In February 1657 Pierre de Fermat sent a challenge to the mathematicians of Europe: find a whole-number solution of x261y2=1x^2 - 61y^2 = 1, other than the trivial one. He chose 61 with care. The smallest answer is

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

and the equations on either side of it are no challenge at all. x260y2=1x^2 - 60y^2 = 1 is solved by x=31x = 31, y=4y = 4, and x262y2=1x^2 - 62y^2 = 1 by x=63x = 63, y=8y = 8. Bhāskara II had solved the 61 case five hundred years earlier by the cyclic method that a method that is allowed to miss describes, and he too chose it as a showpiece.

Why should two neighbouring equations differ by eight digits? The existence of a solution is guaranteed for every non-square DD, and one solution that makes all the others shows that all the others follow from the smallest. Its size is the remaining mystery, and it is a mystery with a precise answer: the smallest solution is the product of the continued fraction’s complete quotients over one period. A long period with large quotients means an enormous solution, and nothing about the size of DD controls either.

How many digits Pell's first solution has, for D up to 1000. A scatter of the digit count of the smallest solution of Pell's equation against D, with the record-setting values ringed and labelled.
Fig. 1 The number of digits of xx in the smallest solution of x2Dy2=1x^2 - Dy^2 = 1, for every DD from 2 to 1,000 that is not a square, with each new record ringed. The records run 2 (1 digit), 10 (2), 13 (3), 29 (4), 46 (5), 61 (10), 109 (15), 181 (19), 277 (21), 409 (23), 421 (34), 541 (37) and 661 (38). Most DD sit near the floor, while a thin upper edge climbs with DD.

Neighbours that disagree by eight digits

The scatter above shows the first surprise in bulk. Most values of DD have small solutions: 777 of the 969 non-square DD up to 1,000 need fewer than ten digits. But the top edge climbs steadily, and the records are spaced irregularly — 61 jumps from five digits to ten, 421 from 23 to 34, and between records the cloud is dense and noisy. There is no smooth function of DD hiding under it.

The first solution of Pell's equation for D from 52 to 72. Bars giving the digit count of the smallest solution of Pell's equation for consecutive D, with the period length printed beneath each and squares left blank.
Fig. 2 The number of digits of xx in the smallest solution of x2Dy2=1x^2 - Dy^2 = 1 for each DD from 52 to 72, with 64 left out because it is a square; the length of the continued fraction’s period is printed under each bar. D=61D = 61 needs x=1,766,319,049x = 1{,}766{,}319{,}049, ten digits, while D=60D = 60 needs 31 and D=62D = 62 needs 63.

Look closely at a run of consecutive values. From 52 to 72, the solutions have 1 to 5 digits except at 61, which has 10. The row of periods printed under the bars tells the same story at a smaller scale: 61’s period is 11, the longest in the run; 67’s is 10 and its solution has five digits; 63, 65 and 68 have periods of 1 or 2 and solutions of one to three digits.

The small ones have a reason that can be seen directly. When DD is one less than a square, D=n21D = n^2 - 1, the solution is x=nx = n, y=1y = 1, since n2(n21)=1n^2 - (n^2 - 1) = 1. So 63 has x=8x = 8 and 99 has x=10x = 10. When DD is one more than a square, n2+1n^2 + 1, the number n+Dn + \sqrt D has norm 1-1 and its square, 2n2+1+2nD2n^2 + 1 + 2n\sqrt D, solves the equation: 65 has x=129x = 129. Values next to a square are cheap, and the floor of the scatter is made of them — the small scalloped arches visible along the bottom of the second scatter below.

61 is as far from structure as a number between 49 and 64 can be, and it pays for it. The same is true of every record-setter: none sits beside a square.

The solution is a product of the steps

The link between the period and the size is an identity, and it is exact. The continued fraction of D\sqrt D is computed as a fraction that never closes computes any continued fraction, by repeatedly taking a whole part and inverting what is left, and the numbers produced along the way are the complete quotients α1,α2,\alpha_1, \alpha_2, \ldots — for 61\sqrt{61}, the first is 1/(617)=(7+61)/121.2341/(\sqrt{61} - 7) = (7 + \sqrt{61})/12 \approx 1.234. Why the expansion has to repeat writes each one as a state (P+D)/Q(P + \sqrt D)/Q and shows that the states cycle.

The unit of √61 as a product of its complete quotients. A horizontal bar divided into 11 segments, one per complete quotient of the continued fraction of the square root of 61, each as long as the logarithm of that quotient.
Fig. 3 The 11 complete quotients of 61\sqrt{61} over one period, (P+61)/Q(P + \sqrt{61})/Q, laid end to end by their logarithms; the bar’s full length is ln(29,718+3,80561)=10.9927\ln(29{,}718 + 3{,}805\sqrt{61}) = 10.9927. Multiplied out exactly, the product of the quotients is 29,718+3,8056129{,}718 + 3{,}805\sqrt{61}, which solves x261y2=1x^2 - 61y^2 = -1 because the period is odd, and its square is the fundamental solution 1,766,319,049+226,153,980611{,}766{,}319{,}049 + 226{,}153{,}980\sqrt{61}.

Multiply the complete quotients of one period together. The result is not merely close to the fundamental unit — it is the fundamental unit, or its square root when the period is odd. The reason is a general fact about continued fractions: for any number xx with convergents pk/qkp_k/q_k,

α1α2αn=1qn1xpn1.\alpha_1 \alpha_2 \cdots \alpha_n = \frac{1}{\lvert q_{n-1}x - p_{n-1}\rvert}.

Each inversion magnifies the leftover error, and the product of the magnifications is the reciprocal of the error remaining after nn steps. For x=Dx = \sqrt D at the end of a period, the convergent p/qp/q satisfies p2Dq2=±1p^2 - Dq^2 = \pm 1, so pqD=±1/(p+qD)p - q\sqrt D = \pm 1/(p + q\sqrt D) and the product is exactly p+qDp + q\sqrt D.

The figure makes the identity visible. The eleven quotients of 61\sqrt{61} have logarithms 0.21, 1.45, 1.31, 0.35, 0.86, 1.02, 0.27, 1.16, 1.60, 0.07 and 2.70, and stacked end to end they reach 10.99 — the logarithm of 29,718+3,8056129{,}718 + 3{,}805\sqrt{61}. Multiplied out exactly, with no rounding anywhere, the product of the eleven numbers (P+61)/Q(P + \sqrt{61})/Q is that number itself. Its norm is 1-1, because 11 is odd, and squaring it gives the answer to Fermat’s challenge.

Size is length times average step

The identity turns a question about size into a question about length. The logarithm of the fundamental unit is a sum of one term per step of the period, so it is the period’s length times the average logarithm of a complete quotient. Either factor can make a solution large.

The unit of √94 as a product of its complete quotients. A horizontal bar divided into 16 segments, one per complete quotient of the continued fraction of the square root of 94, each as long as the logarithm of that quotient.
Fig. 4 The same bar for 94\sqrt{94}, whose period is 16 and even: the complete quotients multiply to 2,143,295+221,064942{,}143{,}295 + 221{,}064\sqrt{94}, which is already the fundamental solution of x294y2=1x^2 - 94y^2 = 1, and the bar’s length is its logarithm, 15.271.

For 94\sqrt{94} the period has 16 terms, the product lands on +1+1 directly, and the logarithm is 15.27 — about 0.95 per step, a little below 61\sqrt{61}'s 1.0 per step. The last quotient is always the largest: it is a0+Da_0 + \sqrt D, roughly 2D2\sqrt D, because the last term of every period is twice the first. So a period of length \ell produces a unit of size roughly 2D2\sqrt D times the product of 1\ell - 1 more modest factors, and a long period is what makes a solution enormous.

For a typical real number the average is known exactly, and it is the rate at which the denominators of the best approximations in how close a fraction can get grow. Paul Lévy proved in 1936 that for almost every xx the denominators of the convergents grow like eβne^{\beta n} with β=π2/(12ln2)1.1866\beta = \pi^2/(12 \ln 2) \approx 1.1866, so the average logarithm of a complete quotient is that constant. Quadratic irrationals are not typical — they form a set of measure nothing — but their periods behave like short samples of typical expansions, and the per-step averages for D\sqrt D up to 1,000 have a median of about 1.28 — above Lévy’s constant, because in a short period the large final quotient carries a heavy share.

So the problem of size reduces to the problem of period length, which the essay on repetition found scattered below a ceiling of about 2D2\sqrt D up to 1,000, with no formula predicting which DD come close. The solution’s size inherits exactly that irregularity, multiplied by about one per step.

Why the records sit five past a multiple of eight

The records in the first scatter share a remainder. After the small early ones, they are 61, 109, 181, 277, 421, 541 and 661 — every one of them a prime, and every one except 409 leaves remainder 5 on division by 8. That is not a quirk of the range, and the reason is one of the prettiest facts in the subject.

When DD leaves remainder 1 on division by 4, the ring Z[D]\mathbb{Z}[\sqrt D] is not the whole of the integers in its field. The numbers (a+bD)/2(a + b\sqrt D)/2 with aa and bb both odd are integers too — they satisfy a monic equation with whole coefficients, the point the integers a field contains makes about the golden ratio — and the field’s smallest unit may be one of them. For 61 it is

ε0=39+5612,39261524=152115254=1.\varepsilon_0 = \frac{39 + 5\sqrt{61}}{2}, \qquad \frac{39^2 - 61 \cdot 5^2}{4} = \frac{1521 - 1525}{4} = -1.

Pell’s equation cannot see ε0\varepsilon_0, because its coordinates are not whole numbers. It sees the first power of ε0\varepsilon_0 whose coordinates are, and that power is the cube: ε03=29,718+3,80561\varepsilon_0^3 = 29{,}718 + 3{,}805\sqrt{61}, exactly the product of the eleven complete quotients above. The answer to Fermat’s challenge is a cube, and a third of its digits are the price of refusing halves.

Why the cube, always? Reduce the half-integers modulo 2. When DD is 5 more than a multiple of 8, the result is the field with four elements, whose non-zero elements form a group of order 3; the whole-number ones are exactly those that reduce to 1, and every element cubed reduces to 1. When DD is 1 more than a multiple of 8, the reduction is two copies of the field with two elements, a unit with odd aa and bb would need a2Db2=±4a^2 - Db^2 = \pm 4 with the left side a multiple of 8, and no half-integer unit exists. Of the 102 square-free DD up to 1,000 that are 5 more than a multiple of 8, 77 have a half-integer unit, and for each of them the Pell solution’s logarithm is tripled. The records collect where the tripling happens and where, as the class number formula below requires of a large unit, the class number is small.

How large it can get

The size of Pell's first solution against √D, up to 1000. A scatter of the natural logarithm of the fundamental unit against the square root of D, with a dashed line of slope one.
Fig. 5 ln(x1+y1D)\ln(x_1 + y_1\sqrt D) for every DD up to 1,000 that is not a square, plotted against D\sqrt D: the cloud fills a wedge, and the steepest line from the origin through any point has slope 3.80. The dashed line is ln(x1+y1D)=D\ln(x_1 + y_1\sqrt D) = \sqrt D, the order of size the class number formula gives when the class number is 1; 218 of the 969 points lie above it.

Plotted against D\sqrt D rather than DD, the logarithm of the unit fills a wedge. The steepest line from the origin through any point has slope 3.80, reached at D=421D = 421, where lnε78\ln\varepsilon \approx 78 and D20.5\sqrt D \approx 20.5. That wedge shape is not a coincidence of the range.

The class number formula is where the shape comes from. For each real quadratic field it relates two quantities that look unrelated — the class number hh, which counts how badly unique factorisation fails, and the logarithm of the fundamental unit — through a special value of an LL-function:

hlnεDL(1,χD),h \cdot \ln\varepsilon \approx \sqrt D \cdot L(1, \chi_D),

up to a constant depending on how DD sits modulo 4. The LL-value is never large; it is at most a constant times logD\log D. So lnε\ln\varepsilon is at most about DlogD\sqrt D \log D, and it is near that size exactly when the class number is small. When h=1h = 1 — which heuristics predict for most prime DD — the unit is forced to be as large as DL(1,χD)\sqrt D \cdot L(1, \chi_D), and the dashed line of slope 1 is that prediction with the LL-value set to its typical size.

Seen this way, the huge solution for 61 is not bad luck but good arithmetic. Q(61)\mathbb{Q}(\sqrt{61}) has class number 1, so every scrap of 61L(1,χ)\sqrt{61} \cdot L(1, \chi) must be carried by the unit. For D=60D = 60 the field is Q(15)\mathbb{Q}(\sqrt{15}), since 60=215\sqrt{60} = 2\sqrt{15}, and its class number is 2, so the budget is shared and the unit is small: it is 4+154 + \sqrt{15}, and the solution for 60 is its square, 31+815=31+46031 + 8\sqrt{15} = 31 + 4\sqrt{60}. A large unit and a small class number are the same fact. That is the tie two families of solutions ended on, seen from the other side.

The cattle of the Sun

The most famous large solution belongs to a problem written in verse and attributed to Archimedes, rediscovered by Lessing in a Wolfenbüttel manuscript in 1773. It asks for the numbers of bulls and cows, white, black, yellow and dappled, in the herd of the Sun god, subject to seven linear conditions and two more: that the white and black bulls together make a square, and the yellow and dappled bulls a triangular number. In 1880 August Amthor reduced it to

x24,729,494y2=1with 9,314 dividing y.x^2 - 4{,}729{,}494\,y^2 = 1 \quad \text{with } 9{,}314 \text{ dividing } y.

The power of Pell's unit that the cattle problem needs. The divisors of 4658 in a row, each marked by whether the y-coordinate of that power of the fundamental unit of 4729494 is divisible by 4657, with the first such power highlighted.
Fig. 6 The smallest solution of x24729494y2=1x^2 - 4729494y^2 = 1 has x=109,931,986,732,829x = 109{,}931{,}986{,}732{,}829\ldots with 45 digits, from a period of 92; the cattle problem needs yy divisible by 9314=246579314 = 2 \cdot 4657, and y1y_1 is already even. Since 4729494 is not a square modulo 4657, the powers of the unit repeat modulo 4657 with a period dividing 4658; across the divisors of 4658, yy first vanishes modulo 4657 at the 2329th power, so the solution the problem needs has xx with 103,273 digits.

The fundamental solution of x24729494y2=1x^2 - 4729494y^2 = 1 is not the difficulty. The continued fraction of 4729494\sqrt{4729494} has period 92, and the product of its complete quotients is a unit whose xx has 45 digits. The difficulty is the extra condition: yy must be divisible by 9314=2×46579314 = 2 \times 4657. The first solution’s yy is even already, so everything depends on 4657.

The powers εk=xk+ykD\varepsilon^k = x_k + y_k\sqrt D all solve the equation, and the question is the first kk with 4657yk4657 \mid y_k. Reduce everything modulo 4657. Since 47294944729494 is not a square modulo 4657 — Euler’s criterion gives 1-1 — the numbers a+bDa + b\sqrt D modulo 4657 form a finite field with 465724657^2 elements, in which raising to the power 4657 is the same as conjugating. So ε4657=εˉ=ε1\varepsilon^{4657} = \bar\varepsilon = \varepsilon^{-1}, and ε4658=1\varepsilon^{4658} = 1 modulo 4657. The kk wanted is the order of ε\varepsilon in that field, and it must divide 4658=2×17×1374658 = 2 \times 17 \times 137.

Checking the eight divisors in turn, the first power whose yy vanishes modulo 4657 is the 2329th, 2329=17×1372329 = 17 \times 137. The solution the herd needs is therefore ε2329\varepsilon^{2329}, and its xx has 2329log10εlog102+1=103,273\lfloor 2329 \log_{10}\varepsilon - \log_{10} 2 \rfloor + 1 = 103{,}273 digits. Amthor found this in 1880 and worked out that the total herd begins 7766 and runs to 206,545 digits. The whole number was computed in 1965 by Williams, German and Zarnke, and printed out in 1981 — forty-seven pages of it.

The argument is a short tour of a good deal of number theory in one place: Fermat’s little theorem in a field of p2p^2 elements, where the Frobenius power is conjugation; the order of an element dividing the size of the group; and a unit of Pell’s equation whose size comes, as above, from a period of 92 complete quotients.

What the scatter cannot show

The digit counts are exact and the explanation is not. Every point in the scatters is a solution computed and verified in exact arithmetic, and the identity with the complete quotients is checked by multiplying them out. The class number formula is quoted rather than drawn, and no figure computes a class number or an LL-value, so the claim that the wedge’s top edge belongs to class number 1 is the theory’s, not the picture’s.

The range is small. Up to 1,000 the steepest slope is 3.80, and nothing in the figures says how that number behaves further out. The theory’s bound of order DlogD\sqrt D \log D allows it to grow slowly without limit, and whether it does, for infinitely many DD, is tied to the same unanswered questions about class numbers.

And a digit count is not a computation. Writing down ε2329\varepsilon^{2329} takes 103,273 digits, but finding the exponent took eight trials modulo 4657. The size of the answer and the difficulty of finding it are different things, and the scatter shows only the first. A scatter of the time each solution took to find would look different again: the cyclic method and the continued fraction both take a number of steps proportional to the period, not to the digits, so the 61 case is eleven steps of small arithmetic that happen to end on a large number.

Still open: computing the size without writing it down

The logarithm of the fundamental unit, the regulator, is a small number even when the unit is enormous — for the cattle problem’s unit it is about 237,795, while the unit itself has over a hundred thousand digits. Algorithms since Shanks and Lenstra compute the regulator to any precision without ever writing the unit out, representing it instead as a short product of manageable numbers, and they run in subexponential time in the number of digits of DD.

In 2002 Sean Hallgren gave a quantum algorithm that computes the regulator in polynomial time, one of the few problems besides factoring and discrete logarithms on which a quantum algorithm is exponentially faster than every known classical one. Whether a classical computer can do it in polynomial time is open. It is believed not — the problem is at least as hard as factoring — but no proof of that exists either, and the question sits alongside factoring as one of the few natural problems on which quantum and classical computation are thought to differ.

The gap is sharpest for exactly the equations this essay has been about. A solution with a hundred thousand digits cannot be printed in polynomial time by anybody, quantum or not, because printing it takes a hundred thousand steps. What can be asked of an algorithm is the regulator, the logarithm, to a stated number of places — a few dozen digits in place of a few hundred thousand — and that is the quantity whose classical complexity is unknown.

A size set by a journey

Neighbouring equations have wildly different first solutions because the first solution is not a function of DD in any simple sense. It is the product of the steps the continued fraction takes to return to its start, so it is as long as the journey and as large as the steps along it. A number just beside a square returns in one or two steps; 61 takes eleven; 4729494 takes ninety-two, and then the cattle problem asks for the journey to be repeated 2329 times.

When a quantity is a product along a cycle, its size is the cycle’s length times the typical step — and the right question stops being “how large is it?” and becomes “how long is the cycle?”, which here has an honest answer only in the class number formula, and a complete one nowhere.

Two further facts sharpen the answer without completing it. The cycle can be shorter than the unit it produces suggests, when the field has a smaller unit with halves in it that Pell’s equation is not allowed to use; then the solution is a cube, and the records cluster where that happens. And the cycle is long exactly when the class number is small, because the class number formula shares a fixed budget between the two. Fermat chose 61 because it was hard. He could not have known that it is hard because Q(61)\mathbb{Q}(\sqrt{61}) factors uniquely, and because 61 is five more than a multiple of eight.

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.

Continued fractionsFundamental solutionGrowth rateLogarithmOrder of an elementPell equationQuadratic irrational