Number

Why the expansion has to repeat

The continued fraction of √61 runs 7; 1, 4, 3, 1, 2, 2, 1, 3, 4, 1, 14 and then starts again. It must: each step's state is a pair of whole numbers trapped in a small band, and only 14 pairs fit. The expansion of √61 visits 11 of them in a cycle, the other 3 form a cycle of their own, and the period reads the same backwards before its last term, which is twice the first.

Worth reading first: One solution that makes all the others · A method that is allowed to miss.

One solution that makes all the others solved Pell’s equation by walking the continued fraction of D\sqrt D to the end of its period, and a method that is allowed to miss solved it faster by a cycle of near misses. Both leaned on the same unproved promise: that the expansion of D\sqrt D repeats, so that the walk has an end and the cycle closes.

The promise is Lagrange’s theorem of 1770, and the proof is a counting argument of the plainest kind. The interesting part is what the counting leaves behind — a finite set of states, arranged in cycles, with the expansion of D\sqrt D running round exactly one of them.

The states the continued fraction of √61 can be in. A grid of whole-number pairs with the band of reduced states shaded, the pairs that qualify marked, and the cycle of states visited by the expansion of the square root numbered in order.
Fig. 1 Every state of the expansion of 61\sqrt{61} is a pair of whole numbers (P,Q)(P, Q), the complete quotient being (P+61)/Q(P + \sqrt{61})/Q; after the first step each lies in the shaded band 0<P<610 < P < \sqrt{61}, 61P<Q<61+P\sqrt{61} - P < Q < \sqrt{61} + P, with QQ dividing 61P261 - P^2, and only 14 pairs in the whole grid qualify. So the expansion must meet a state again within 14 steps and repeat from there; 61\sqrt{61}'s own states form the numbered cycle of 11, and the 3 it never visits form one other cycle.

The expansion as a machine with a state

To expand 61\sqrt{61}, take its whole part, 7, and invert what is left: 1/(617)1/(\sqrt{61} - 7). Rationalising gives (61+7)/12(\sqrt{61} + 7)/12, a number of the same kind. Its whole part is 1; subtract, invert, rationalise, and the result is again of the form (P+61)/Q(P + \sqrt{61})/Q with whole numbers PP and QQ. Every complete quotient of D\sqrt D has this shape, and the whole expansion can be run in whole numbers:

P=aQP,Q=DP2Q,a=D+PQ.P' = aQ - P, \qquad Q' = \frac{D - P'^2}{Q}, \qquad a' = \left\lfloor \frac{\lfloor\sqrt D\rfloor + P'}{Q'} \right\rfloor.

The division in the middle always comes out exact, because QQ always divides DP2D - P'^2, and only the very first whole part needs a square root. The pair (P,Q)(P, Q) is the whole state of the computation. Knowing it determines the next term and the next pair, and nothing else about the history matters.

The first state after the whole part, (7,12)(7, 12), is the number (7+61)/121.2342(7 + \sqrt{61})/12 \approx 1.2342, whose whole part 1 is the next term; its conjugate (761)/120.0675(7 - \sqrt{61})/12 \approx -0.0675 will matter shortly. For 61\sqrt{61} the states run (7,12)(7, 12), (5,3)(5, 3), (7,4)(7, 4), (5,9)(5, 9), (4,5)(4, 5), (6,5)(6, 5), (4,9)(4, 9), (5,4)(5, 4), (7,3)(7, 3), (5,12)(5, 12), (7,1)(7, 1), and then (7,12)(7, 12) again. From that point the terms must repeat, because the machine is in the state it was in before.

Why only finitely many states

The pairs are not merely whole numbers; after the first step they are confined. Each complete quotient (P+D)/Q(P + \sqrt D)/Q is greater than 1, since it is the tail of a continued fraction, and its conjugate (PD)/Q(P - \sqrt D)/Q — the same expression with D\sqrt D replaced by D-\sqrt D — lies between 1-1 and 0. Those two facts together force

0<P<D,DP<Q<D+P.0 < P < \sqrt D, \qquad \sqrt D - P < Q < \sqrt D + P.

The band comes straight from the two facts. Write x=(P+D)/Qx = (P + \sqrt D)/Q and x=(PD)/Qx' = (P - \sqrt D)/Q. Their difference is 2D/Q2\sqrt D/Q, which exceeds 1 because x>1x > 1 and x<0x' < 0, so Q<2DQ < 2\sqrt D. Their sum is 2P/Q2P/Q, which is positive because x>1x > 1 outweighs x>1x' > -1, so P>0P > 0. The conjugate being negative forces P<DP < \sqrt D; being above 1-1 forces Q>DPQ > \sqrt D - P; and x>1x > 1 forces Q<D+PQ < \sqrt D + P.

Why every complete quotient after the first has those two properties is a short induction. The first, (D+D)/(DD2)(\lfloor\sqrt D\rfloor + \sqrt D)/(D - \lfloor\sqrt D\rfloor^2), can be checked directly; and if a state is greater than 1 with its conjugate between 1-1 and 0, then subtracting its whole part and inverting produces a number greater than 1 whose conjugate, the inverse of something below 1-1, lies between 1-1 and 0 again. The property is inherited at every step, so the band holds the whole expansion after its first term.

That is the shaded band in the figure. For D=61D = 61, PP can only be 1 to 7 and QQ only 1 to 14, and the requirement that QQ divide 61P261 - P^2 cuts the band’s cells down to 14 qualifying pairs. A machine with 14 possible states, run for 15 steps, must revisit one of them — the pigeonhole principle of more things than boxes — and from the first revisit on, everything repeats.

The same argument, with the band replaced by a finite set, is the reason the orbit that must come back comes back: any deterministic process on finitely many states is eventually periodic. The work is all in showing that the states are finite. Lagrange’s theorem extends the conclusion from D\sqrt D to every quadratic irrational, (a+bD)/c(a + b\sqrt D)/c, whose complete quotients have the same shape.

The same reason decimals repeat

The argument is the continued-fraction version of a fact met much earlier. Divide 1 by 7 by long division and the digits run 0.1428571428570.142857142857\ldots, repeating with period 6. The state of long division is the remainder, and the remainders after each step are 1, 3, 2, 6, 4, 5 and then 1 again: a remainder on division by 7 can only be one of six nonzero values, so it must recur, and the digits repeat from there. That is arithmetic in numbers that wrap: each new remainder is ten times the last, reduced modulo 7.

The two facts are parallel, and so are their converses. A decimal expansion eventually repeats exactly when the number is a fraction, and a continued fraction eventually repeats exactly when the number is a quadratic irrational. For fractions the continued fraction does not repeat at all — it stops, because the Euclidean algorithm that computes it strictly decreases a pair of whole numbers until one of them reaches zero, as a fraction that never closes shows. Stopping, cycling and wandering are three different fates, and they sort numbers into rational, quadratic and everything else.

“Everything else” is not uniform. The continued fraction of ee runs [2;1,2,1,1,4,1,1,6,1,1,8,][2; 1, 2, 1, 1, 4, 1, 1, 6, 1, 1, 8, \ldots], a pattern Euler found, with no repetition but a perfectly regular rule; the number of the curve that is its own slope is not quadratic, yet its expansion is anything but random. The continued fraction of π\pi shows no pattern at all that anyone has found. Periodicity picks out the quadratic irrationals exactly, and says nothing about the rest.

A palindrome in every period

The periods of √D for D = 29, 46, 61, 94, 139, read both ways. Rows of continued-fraction terms for several square roots, the first term separate, the period's terms coloured so that mirror positions match, and the last term of each period highlighted.
Fig. 2 The continued fractions of 29\sqrt{29}, 46\sqrt{46}, 61\sqrt{61}, 94\sqrt{94} and 139\sqrt{139}: the first term, then one full period, with the terms before the last coloured so that mirror positions match — and they read the same forwards and backwards. Every period ends in twice the first term — 10 for 29\sqrt{29}, 12 for 46\sqrt{46}, 14 for 61\sqrt{61}, 18 for 94\sqrt{94}, 22 for 139\sqrt{139} — which is where the expansion returns to its starting state; both facts were checked for every DD up to 1,000.

The periods have more structure than repetition. For 61\sqrt{61} the period is 1, 4, 3, 1, 2, 2, 1, 3, 4, 1, 14. Leave off the last term and the rest reads the same backwards; the last term, 14, is twice the first whole part, 7. The same holds for 29\sqrt{29}, whose period 2, 1, 1, 2, 10 is a palindrome followed by twice 5, and for every DD up to 1,000, where the figure checked all 969 that are not squares.

The last term is explained by the state it returns to. The final state (7,1)(7, 1) has Q=1Q = 1, and its complete quotient is 7+617 + \sqrt{61}, whose whole part is 14 and whose fractional part is 617\sqrt{61} - 7 — exactly where the expansion began after taking off its first 7. Twice the first term marks the moment the machine is back at its start.

The palindrome is explained by reversal. Running the expansion of D\sqrt D backwards corresponds to expanding 1-1 over the conjugate of each state, and for D\sqrt D the conjugates reproduce the same numbers in reverse order. So reading the period backwards is reading the same expansion from the other end, and the two readings must agree.

The states that repeat from the start

Every reduced state of discriminant 61, against its conjugate. A scatter of points, each a complete quotient across and its conjugate up, all lying in the strip to the right of one with the conjugate between minus one and zero.
Fig. 3 Each reduced state of discriminant 61 as a point: across, the complete quotient (P+61)/Q(P + \sqrt{61})/Q; up, its conjugate (P61)/Q(P - \sqrt{61})/Q61\sqrt{61}'s own 11 states filled, the others hollow. Every one lies right of 1 with its conjugate between −1 and 0, the strip Galois showed belongs exactly to the numbers whose expansions repeat from the first term; 61\sqrt{61} itself, with conjugate 61-\sqrt{61}, lies far below the strip, which is why its expansion needs one term before the repetition starts.

Some quadratic irrationals repeat from their very first term, and the golden ratio, [1;1,1,1,][1; 1, 1, 1, \ldots], is the familiar case that the rectangle that eats itself builds. Évariste Galois proved in 1829, in his first published paper, exactly which ones: a quadratic irrational has a purely periodic expansion if and only if it is reduced — greater than 1, with its conjugate between 1-1 and 0.

The figure plots all 14 reduced states of discriminant 61 by their value and their conjugate, and all of them fall in that strip. The golden ratio is reduced too: it is about 1.618, and its conjugate is about 0.618-0.618. 61\sqrt{61} is not, since its conjugate is 61-\sqrt{61}, far below the strip; that is why its expansion has a first term, 7, standing outside the period, and why every expansion of D\sqrt D has the shape [a0;a1,,ar][a_0; \overline{a_1, \ldots, a_r}].

Reducedness does a second job in the proof of periodicity. A reduced state has only one possible predecessor that is also reduced, because the conjugate’s position in (1,0)(-1, 0) pins down the term that was taken. So the step is reversible on reduced states, and a reversible process on a finite set cannot have a tail leading into a cycle — every state lies on a cycle. That is why the expansion of D\sqrt D does not merely become periodic eventually, but repeats from its second term.

States the root never visits

How the reduced states of √D split into cycles, for D = 34, 46, 61, 79, 94. Bars of reduced states for several values of D, each divided into segments for the cycles, with the cycle of the square root's own expansion shaded first.
Fig. 4 For DD = 34, 46, 61, 79 and 94, the reduced states laid end to end and split into the cycles the continued-fraction step makes of them; D\sqrt{D}'s own cycle is the first, shaded, and its length is D\sqrt{D}'s period. Sometimes D\sqrt{D}'s cycle uses every state and sometimes it does not: 34 has 10 states in cycles of 4 + 6; 46 has 12 states in one cycle; 61 has 14 states in cycles of 11 + 3; 79 has 16 states in cycles of 4 + 6 + 6; 94 has 16 states in one cycle.

Because the step is reversible, the reduced states split into disjoint cycles, and the expansion of D\sqrt D is only one of them. For D=61D = 61 the other three states — (5,6)(5, 6), (7,6)(7, 6) and (7,2)(7, 2) in the grid — form a cycle of their own: they are the complete quotients of numbers like (7+61)/6(7 + \sqrt{61})/6, whose expansion never passes through 61\sqrt{61}'s states. For D=79D = 79 there are three cycles, of 4, 6 and 6, and 79\sqrt{79} uses only the cycle of 4. For D=46D = 46 and D=94D = 94 a single cycle holds every reduced state.

These cycles were not invented for continued fractions. Gauss organised the reduced indefinite quadratic forms — expressions ax2+bxy+cy2ax^2 + bxy + cy^2 taking both positive and negative values, built from the same kind of whole-number data as the states here — into cycles of exactly this sort in 1801, and used them to sort forms into classes: two forms represent the same numbers under a change of variables when their reduced forms lie on the same cycle. The number of cycles is therefore closely tied to the number of classes of forms, and it is one of the routes by which the continued fraction of D\sqrt D is connected to the class numbers that the chakravala essay ended on.

The count matters for Pell’s equation directly. When D\sqrt D’s cycle holds every state, a single cycle carries all the arithmetic of the discriminant; when it does not, the other cycles describe numbers of the form a2Db2a^2 - Db^2 that D\sqrt D’s own convergents never produce.

How long the period can be

The period of √D for every D up to 1000. A scatter of the continued-fraction period length of the square root of D against D, odd periods filled and even ones hollow, with a faint guide curve of the square root of D.
Fig. 5 The length of the period of D\sqrt{D} for every DD from 2 to 1000 that is not a square: odd periods filled, even ones hollow, and the curve D\sqrt{D} drawn faintly. The longest is 60, at D=919D = 919; 152 of the 969 periods are odd; no period in this range exceeds 1.98 times D\sqrt{D}, and every one is at most the number of reduced states available to it.

The counting argument gives a bound immediately: the period is at most the number of reduced states, and the band has room for no more than about 2D2D of them. That bound is honest and nearly useless. The actual periods up to 1,000 are much shorter, scattered below a ceiling that grows roughly like D\sqrt D: the longest is 60, at D=919D = 919, and none exceeds 1.98 times D\sqrt D in this range.

The scatter is wide. Next to D=919D = 919 with its period of 60 sit values with periods of 1 or 2, such as D=920=302+20D = 920 = 30^2 + 20 and D=960=3121D = 960 = 31^2 - 1, because DD one less than a square always has period 2: n21=[n1;1,2n2]\sqrt{n^2 - 1} = [n - 1; \overline{1, 2n - 2}]. Nothing about the size of DD alone predicts the period. It is known that the period can never be much longer than DlogD\sqrt D \log D, a bound that comes from the same class number formula mentioned above, but which DD come close to it is irregular.

The odd periods, 152 of the 969, are the ones the Pell essay singled out: an odd period is exactly the condition for x2Dy2=1x^2 - Dy^2 = -1 to have a solution, and for the chakravala to pass through a miss of 1-1 on its way.

Where Pell’s equation sits on the cycle

The cycle also shows where the solutions of Pell’s equation come from. At each state, the convergent reached so far, p/qp/q, satisfies p2Dq2=±Qp^2 - Dq^2 = \pm Q for the QQ of the next state, with the sign alternating. So the value of p2Dq2p^2 - Dq^2 along the convergents is the sequence of QQ’s read off the cycle, with signs: for 61\sqrt{61} the QQ’s run 12, 3, 4, 9, 5, 5, 9, 4, 3, 12, 1, and the convergents’ values run 12-12, 3, 4-4, 9, 5-5, 5, 9-9, 4, 3-3, 12, 1-1.

A value of ±1\pm 1 appears exactly where Q=1Q = 1, and within a period that happens only at the last state, (7,1)(7, 1). The solution of Pell’s equation is the state on the cycle whose QQ is 1, reached once per period. Whether it gives +1+1 or 1-1 depends on whether the period is even or odd: for 61\sqrt{61}, with period 11, the first return gives 1-1, and the second, 22 convergents in, gives +1+1 — the 22 that the chakravala essay compared its 13 steps against.

That also explains the palindrome’s use to anyone computing by hand. The QQ’s along the cycle read the same backwards, just as the terms do, so the middle of the period already determines the whole; it is the same symmetry the chakravala’s sequence of misses displayed, seen here in the states rather than in the misses.

What periodicity buys

A guarantee that searching ends. Both the continued-fraction walk and the chakravala are searches that stop when something returns to 1. Periodicity is what promises the return: the state that means “solved” is on the cycle, and the cycle is finite.

A certificate that a number is quadratic. Euler proved the converse of Lagrange’s theorem: any eventually periodic continued fraction is a quadratic irrational. So periodicity characterises exactly one class of numbers, and a long enough computed expansion that has visibly not repeated is evidence — though never proof — that a number is not quadratic.

And a finite description of an infinite object. The expansion of 61\sqrt{61} is infinite, but eleven terms and a promise describe all of it, in the same way that the orbit written as a word describes a periodic orbit of a map by one repeating block. Continued fractions are themselves the orbits of a map — take the reciprocal of the fractional part — and the quadratic irrationals are exactly its eventually periodic points.

Every state listed, and Gauss’s forms only quoted

Every state was enumerated, not argued about. The grid, the cycles and the reduced strip were computed by listing every pair in the band and following the step; the palindrome and the final term were checked for all 969 non-square DD up to 1,000. The reasons given — reversal for the palindrome, reversibility for pure periodicity — are the standard proofs, stated in words rather than drawn.

The correspondence with quadratic forms is described, not computed. That the cycles of reduced states match Gauss’s cycles of reduced forms, and count classes of forms, is quoted from the theory; no figure checks it against an independent count of classes.

And the period bound is observed up to 1,000. The ratio 1.98 is the largest in the range drawn; the theoretical bound of order DlogD\sqrt D \log D is stated and not shown.

Still open: whether a cube root’s expansion stays small

Quadratic irrationals are the numbers whose continued fractions repeat. For the next simplest numbers — roots of cubic equations, such as 23\sqrt[3]{2}, which begins [1;3,1,5,1,1,4,1,1,8,1,14,][1; 3, 1, 5, 1, 1, 4, 1, 1, 8, 1, 14, \ldots] — nothing comparable is known. It is not known whether the terms of the continued fraction of 23\sqrt[3]{2} are bounded, or whether they grow without limit, although computations of millions of terms find the occasional very large one and suggest they behave like the terms of a randomly chosen number. For no algebraic number of degree three or more has anyone determined whether its terms are bounded.

Finite states, forced repetition

The continued fraction of D\sqrt D repeats for the same reason a clock does: its state is a small amount of whole-number information, and there are only so many states it can be in. The states form cycles because the step can be run backwards, the period is a palindrome because running it backwards gives the same numbers, and the cycles that D\sqrt D does not visit are the other classes of forms of the same discriminant.

To prove that a process repeats, find what it remembers and show that it can only remember finitely much. The repetition then comes for free, and the structure of the finite set says far more than the repetition alone.

What links here

Computed from the collection, not written here: the essays that point at this one.

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.

ConjugateContinued fractionsPell equationPeriodicityPigeonhole principleQuadratic formQuadratic irrational