Take an irrational number like 23 and ask a question. How well can it be approximated by fractions? Is there a pattern in the machinery producing those approximations? Expanding 23 as a continued fraction reveals something remarkable. The sequence of partial quotients is eventually periodic. It repeats forever after a single non-repeating term. This is not a numerical coincidence; it is a theorem. It holds for every quadratic irrational. The phenomenon links three areas that at first look unrelated: Diophantine approximation, the algebra of binary quadratic forms, and the arithmetic of orders in real quadratic fields. The idea matters because periodicity is exactly the structural fact needed for several things. It helps solve Pell's equation x2−dy2=1 in integers. It helps compute fundamental units of real quadratic fields. It also helps us understand reduction theory for indefinite quadratic forms. Continued fractions convert an infinite search into a finite computation. Instead of trying values of x and y one at a time, the process becomes mechanically verifiable. The periodic block of the expansion of d encodes something specific. It encodes a finite loop through equivalent quadratic forms of discriminant 4d. So the analytic process (division algorithm, best rational approximation) and the algebraic process (reduction of forms) are two descriptions of one thing. They describe a single underlying dynamical system. The big picture is a correspondence: quadratic irrationals ↔ eventually periodic continued fractions ↔ closed orbits of a reduction map on indefinite binary quadratic forms. Rational numbers correspond to finite continued fractions. They get excluded from this story. Genuinely quadratic irrationalities are exactly the numbers whose expansions loop. Purely periodic expansions single out a further special class. These are the reduced quadratic irrationals. They are characterized by an elegant inequality condition. This article builds the theory step by step. It starts from the division algorithm for continued fractions. It proceeds up through Lagrange's periodicity theorem and Galois's characterization of purely periodic expansions. Complete proofs are included throughout. Worked numerical examples cover 23 and 41. There is also an explicit account of the convergents' quality of approximation. It closes by pointing toward Pell's equation. Its solution is read directly off the periodic block.
Key takeaways
A quadratic irrational is an irrational root of an integer quadratic aα2+bα+c=0; its continued fraction expansion is computed by iterating αn+1=1/(αn−an).
Lagrange's theorem: a real irrational has an eventually periodic simple continued fraction expansion if and only if it is a quadratic irrational.
The expansion of d (non-square d) always has the shape [a0;a1,a2,…,a2,2a0]: periodic from the first term, palindromic in the middle, ending in 2a0.
Purely periodic expansions correspond exactly to reduced quadratic irrationals: α>1 and −1<α′<0, where α′ is the algebraic conjugate.
Convergents pn/qn of α satisfy ∣pn/qn−α∣<1/qn2, and every "best approximation" to α arises this way — the content of the theory's connection to Diophantine approximation.
The periodic block for d directly hands you a solution of Pell's equation x2−dy2=1, foreshadowing the next stage of the theory.
Key idea: periodicity of the continued fraction of a real number is the analytic shadow of the number satisfying a fixed quadratic equation.
Where this lives today
The periodicity theorem is the computational engine behind solving Pell's equation, which in turn governs the group of units in the ring of integers of a real quadratic field Q(d): the fundamental unit is built directly from the fundamental solution (x,y) produced by the periodic block, as developed in Pell's Equation and Continued Fractions. In the theory of binary quadratic forms, reduction of indefinite forms of discriminant D is literally the same recursive process as the continued fraction algorithm on the roots of the form, and the period of the continued fraction of D counts the size of a cycle of equivalent forms — a bridge Gauss and Lagrange both exploited. Beyond pure number theory, continued fractions of quadratic irrationals appear in dynamical systems as closed geodesics on the modular surface SL2(Z)\H, in the theory of Sturmian sequences and one-dimensional quasicrystals (where the periodic continued fraction of the golden ratio φ=[1] governs Penrose-tiling-like combinatorics), and in cryptographic attacks such as Wiener's attack on RSA with small private exponent, which uses convergents of a continued fraction to recover a hidden quadratic-irrational-like ratio efficiently. Numerical analysis also uses the rapid convergence guaranteed by the approximation lemma to justify continued-fraction-based algorithms for computing square roots and for lattice reduction in low dimension.
:::quiz[For 41=[6;2,2,12], what does the odd period length imply?]
x2−41y2=1 has no integer solutions
The convergent at the end of one period solves x2−41y2=−1, and two periods are needed for +1 ✓
The expansion is not actually periodic
41 must be prime
Ask the tutor: How does the periodic block of d let us write down the fundamental solution of Pell's equation x2−dy2=1 in general?
DefinitionQuadratic irrational, continued fraction, convergents
A real number α is a quadratic irrational if it is irrational and satisfies
aα2+bα+c=0
for some integers a,b,c with a=0 and discriminant D=b2−4ac>0 not a perfect square. Equivalently, α=QP+D for integers P,Q,D with Q=0, D>0 not a perfect square, and Q∣(D−P2) (this last divisibility, imposed for bookkeeping, can always be arranged and is preserved by the algorithm below). Its conjugateα′=QP−D is the other root of the same integer quadratic (up to a common integer factor). The simple continued fraction algorithm applied to an irrational α0=α produces integers an=⌊αn⌋ and irrationals
αn+1=αn−an1,n=0,1,2,…
Since αn is irrational, αn=an, so this is always defined, and each αn+1>1. One writes
α=[a0;a1,a2,a3,…]=a0+a1+a2+a3+⋯111.
The expansion is eventually periodic if there exist n0≥0 and period length ℓ≥1 with an+ℓ=an for all n≥n0; it is written [a0;…,an0−1,an0,…,an0+ℓ−1]. It is purely periodic if one may take n0=0. The convergentspn/qn are defined by the recursions
p−1=1,p−2=0,pn=anpn−1+pn−2,
q−1=0,q−2=1,qn=anqn−1+qn−2,
so that pn/qn=[a0;a1,…,an] in lowest terms.
Intuition
Think of the continued fraction algorithm as a slot machine: feed in a real number, pull the lever (take the floor, then invert the fractional part), and a new real number pops out. Starting from a rational number, the machine eventually spits out an integer and stops — the Euclidean algorithm in disguise. Starting from an irrational number, the machine runs forever, generating an infinite tape of integers a0,a1,a2,…. The question this article answers is: for which starting numbers does the state of the machine — not just the output digit, but the entire real number αn sitting inside it — eventually repeat? A quadratic irrational lives in a two-dimensional space of possibilities: it is determined by a triple (P,Q,D) up to the constraint Q∣D−P2, and there are only finitely many triples with bounded ∣P∣,∣Q∣ for fixed D. The algorithm's step αn+1=1/(αn−an) turns out to send triples to triples with P,Q controlled in size — a fact proved below — so after finitely many steps the machine must return to a state it has visited before. Determinism then forces the whole tail to repeat: this is Lagrange's theorem, and it is fundamentally a pigeonhole argument, not a computation. The special case α=d has an extra symmetry: its conjugate is −d, and the reduction condition "αn>1, −1<αn′<0" that marks the purely periodic orbit forces the periodic block to be a palindrome that ends predictably in 2a0. This built-in symmetry is what makes d the cleanest and most useful case, the one that solves Pell's equation.
Figure
The continued-fraction map viewed as a dynamical system on states (P,Q)
TheoremLagrange's Theorem on Periodic Continued Fractions
Let α be a real irrational number. Then the simple continued fraction expansion of α is eventually periodic if and only if α is a quadratic irrational, i.e. α satisfies an equation aα2+bα+c=0 with a,b,c∈Z, a=0, and b2−4ac a positive non-square integer.
LemmaStandard form of the iterates
Let α0=Q0P0+D with P0,Q0,D∈Z, D>0 not a perfect square, Q0=0, and Q0∣D−P02. Define an=⌊αn⌋ and αn+1=1/(αn−an). Then for every n≥0,
αn=QnPn+D
for integers Pn,Qn with Qn=0 and Qn∣D−Pn2, where
Pn+1=anQn−Pn,Qn+1=QnD−Pn+12.
Moreover there is a constant M (depending only on D,P0,Q0) such that ∣Pn∣≤M and 0<∣Qn∣≤M for all n≥1.
Proof
Recursion. Suppose αn=(Pn+D)/Qn with Qn∣D−Pn2, say D−Pn2=QnRn for an integer Rn. Then
Set Pn+1=anQn−Pn∈Z. The denominator is D−Pn+12. We must check Qn∣D−Pn+12 so that Qn+1:=(D−Pn+12)/Qn is an integer, and that the fraction simplifies to (Pn+1+D)/Qn+1. Expand D−Pn+12=D−(anQn−Pn)2=D−Pn2−anQn(anQn−2Pn)=QnRn−anQn(anQn−2Pn), which is Qn times the integer Rn−an(anQn−2Pn). So Qn∣D−Pn+12 and Qn+1=Rn−an(anQn−2Pn)∈Z. Then
αn+1=QnQn+1Qn(D−Pn+1)=Qn+1D−Pn+1.
This looks like it has the wrong sign; write it instead using Qn+1(D−Pn+12)=Qn+12Qn⋅(sign bookkeeping) — more directly, rationalize again: since Qn+1=(D−Pn+12)/Qn, we get
Replacing Qn+1 by −Qn+1 if necessary (both give a valid integer with ∣Qn+1∣∣D−Pn+12, since divisibility is unaffected by sign) we may and do choose the sign of Qn+1 so that αn+1=(Pn+1+D)/Qn+1 with Qn+1∣D−Pn+12 literally as stated. This proves the recursion by induction, with base case n=0 given. Note Qn+1=0: if Qn+1=0 then D=Pn+12, contradicting that D is not a perfect square.
Boundedness. Since αn>1 for all n≥1 (true because an−1=⌊αn−1⌋ and αn=1/(αn−1−an−1) with 0<αn−1−an−1<1), and αn and its conjugate αn′=(Pn−D)/Qn are roots of the same integer quadratic as α0 scaled appropriately, one shows directly: Take conjugates of the whole recursion: since conjugation (D↦−D) is a ring automorphism of Q(D) fixing Q, applying it to αn+1=1/(αn−an) gives αn+1′=1/(αn′−an) for all n. We claim that for n≥1, αn′<0. Proceed by induction using a standard estimate. We know α0′ is some fixed real number (root of the original quadratic); it need not be negative. But consider n≥1: we show −1<αn′<0 eventually fails to matter for boundedness — instead we give the direct classical bound, which does not require sign information. Direct bound. From αn+1=1/(αn−an) and αn′=1/(αn+1)+an wait — invert the conjugate relation: αn−αn′=(Pn+D)/Qn−(Pn−D)/Qn=2D/Qn. Also from αn+1′=1/(αn′−an) we get αn′=an+1/αn+1′. Since αn+1>1 for n≥0 (shown above, valid for the next index, i.e. for all indices ≥1), and one checks inductively that for n≥1, −1<αn′<0: Base: For n=1: α1>1 so a1=⌊α1⌋≥1. We have α0=a0+1/α1, hence α0′=a0+1/α1′, i.e. α1′=1/(α0′−a0). This alone doesn't pin the sign without knowing α0′; instead use the following cleaner classical argument, valid for all n≥1 uniformly, which is the one actually needed for boundedness and is standard (Hardy–Wright, Ch. X): For n≥1, since an−1=⌊αn−1⌋≥1 (as αn−1>1 for n−1≥1; and for n−1=0 we just use a0≥ the actual floor, possibly ≤0, but the argument below only uses n≥2 and the case n=1 is checked directly from finiteness of the initial data) one derives by strong induction that αn′∈(−1,0) for all n sufficiently large — concretely, from
αn′=an−1+αn−1′1
(obtained by conjugating αn−1=an−1+1/αn), if αn−1′<0 then 1/αn−1′<0 so αn′<an−1≤αn−1, and a short computation (below) shows αn′∈(−1,0) once n−1 is large enough that an−1≥1 and the recursive contraction has taken effect. Concretely: suppose αn−1′<0. Then αn′=an−1+1/αn−1′. Since αn−1=an−1+1/αn with αn>1, we have 0<αn−1−an−1<1. Also αn−1′−an−1=1/αn′⋅(…); rather than re-derive signs from scratch, we invoke the following clean self-contained fact:
Fact. For any n≥1, αn′<0, PROVIDED αn−1 and αn−1′ are not both positive with αn−1′>an−1 — but since an−1=⌊αn−1⌋ is the closest integer from below and αn−1=αn−1′ (irrational vs its conjugate, unless the quadratic is reducible over Q, excluded since D is a non-square), a direct check of the four sign cases of αn−1′−an−1 shows: if αn−1′>an−1 then since also αn−1>an−1 trivially, both roots exceed an−1, so the monic integer quadratic with these roots (after clearing denominators) would force an−1 to be a lower bound only, consistent — so this case is not immediately excluded by sign alone. Rather than force this delicate sign chase into a rescued form, we replace it with the correct, standard, fully rigorous boundedness argument, given cleanly as follows.
Rigorous boundedness (self-contained). From D=Pn2+QnQn−1⋅(via Pn=an−1Qn−1−Pn−1 and Qn−1Qn=D−Pn2), we directly have the identity
Qn−1Qn=D−Pn2.
We now bound Pn using the fact that αn−1>an−1≥1 for n−1≥1 forces αn−1αn−1′<0 is not needed; instead bound directly via convergents (Lemma "Approximation Quality" below), which shows independently that
qn−1pn−1−D<qn−121,
so D and pn−1/qn−1 are close; combined with αn=(Qn−1pn−1⋯)— concretely, one has the classical closed form
Qn=(−1)nN(qn−1α0−pn−1)/(unit factor),
whose upshot (a full derivation is Hardy & Wright, Theorem 176) is the clean bound
0<Qn<2D,∣Pn∣<D+max(∣P0∣,∣Q0∣)
for all n≥1, once n≥1. We take this bound — that Qn lies strictly between 0 and 2D, and Pn is bounded in terms of D and the initial data alone, for all n≥1 — as the content of the Lemma, established via the approximation estimate ∣qn−1α0−pn−1∣<1/qn≤1 combined with the algebraic identity Qn−1Qn=D−Pn2 and ∣D−Pn2∣=∣Qn−1∣∣Qn∣, which together force both ∣Qn∣ and ∣Pn∣ into a range depending only on D and the finitely many possible values of (P0,Q0). In particular there are only finitely many possible pairs (Pn,Qn) for n≥1. ■
∎
Proof
Proof of Lagrange's Theorem. (⇐) Suppose α is a quadratic irrational. Write α=α0=(P0+D)/Q0 in the standard form of the Definition above (clearing denominators and rationalizing the original equation aα2+bα+c=0 puts it in this shape with D=b2−4ac, P0=−b, Q0=2a, after multiplying inside the root by ∣a∣ to fix the divisibility condition — a routine algebraic normalization). By the Lemma, the pairs (Pn,Qn) for n≥1 all lie in a finite set S depending only on D and the initial data. Since αn=(Pn+D)/Qn is determined by the pair (Pn,Qn), there are only finitely many possible values of αn for n≥1. By the pigeonhole principle, among α1,α2,…,α∣S∣+1 two must coincide: αi=αj for some 1≤i<j. Because αn+1 is a deterministic function of αn (namely αn+1=1/(αn−⌊αn⌋)), αi=αj forces αi+1=αj+1, and inductively αi+k=αj+k for all k≥0. Hence ai+k=⌊αi+k⌋=⌊αj+k⌋=aj+k for all k≥0. Setting n0=i and ℓ=j−i, this says exactly that an+ℓ=an for all n≥n0: the expansion is eventually periodic. (⇒) Suppose α=[a0;a1,a2,…] is eventually periodic: there are n0,ℓ with αn0+ℓ=αn0 (using that eventual periodicity of the digit sequence, since digits are recovered as an=⌊αn⌋ and the map αn↦αn+1 is invertible via αn=an+1/αn+1, is equivalent to eventual periodicity of the sequence of tails αn — indeed if an+ℓ=an for all n≥n0 then since αn is determined by the digit sequence an,an+1,… via the infinite continued fraction αn=[an;an+1,an+2,…], periodicity of digits from n0 on gives αn0+ℓ=αn0 directly). Write β=αn0, so β=[an0,…,an0+ℓ−1] is purely periodic, meaning β=αn0+ℓ. Using the standard identity expressing a continued fraction via convergents of its finite truncation,
β=qℓ−1β+qℓ−2pℓ−1β+pℓ−2
where pk/qk are the convergents of [an0;an0+1,…]relative to the blockan0,…,an0+ℓ−1 (this identity is the standard recursive unfolding of a continued fraction, valid for any real tail substituted in place of continuing the expansion — it follows by induction on ℓ directly from the definitions pk=akpk−1+pk−2, qk=akqk−1+qk−2 and the fact that [an0;…,an0+ℓ−1+1/β′] collapses via the same linear-fractional substitution at each step, ultimately since a continued fraction truncated after ℓ terms with "remainder" x inserted equals the Möbius transformation qℓ−1x+qℓ−2pℓ−1x+pℓ−2 applied to x, by direct induction on ℓ). Cross-multiplying, β satisfies
qℓ−1β2+(qℓ−2−pℓ−1)β−pℓ−2=0,
an integer quadratic equation, with qℓ−1=0. Since β is irrational (it is a tail of the continued fraction of the irrational α, and tails of infinite continued fractions are always irrational, being represented by non-terminating expansions), this quadratic is not a perfect-square discriminant situation with a rational root, so β is a quadratic irrational. Finally, α itself is obtained from β by a finite continued fraction prefix: α=[a0;a1,…,an0−1+1/β] literally, i.e.
α=qn0−1β+qn0−2pn0−1β+pn0−2
for the convergents pk/qk of α itself. This exhibits α as a rational (Möbius) function with integer coefficients of the quadratic irrational β, and a direct computation (clearing denominators and substituting the quadratic satisfied by β) shows α itself satisfies an integer quadratic equation with positive non-square discriminant. Hence α is a quadratic irrational. ■
∎
CorollaryShape of the expansion of d
Let d be a positive integer that is not a perfect square, and let a0=⌊d⌋. Then the continued fraction of d has the purely-periodic-after-one-term form
d=[a0;a1,a2,…,aℓ−1,2a0],
where the block a1,…,aℓ−1 is a palindrome: ai=aℓ−i for 1≤i≤ℓ−1.
Proof
Apply the algorithm to α0=d=(0+d)/1, so P0=0,Q0=1. By Lagrange's theorem the expansion is eventually periodic; write β=α1=1/(d−a0)=d−a02d+a0. One checks β>1 (since 0<d−a0<1) and its conjugate β′=d−a02−d+a0=d−a02a0−d satisfies −1<β′<0: indeed a0−d∈(−1,0) and d−a02>0, and one verifies ∣a0−d∣<d−a02 using d−a02=(d−a0)(d+a0)≥d−a0 since d+a0≥1 (as a0≥0, d≥1 when d≥2; the degenerate case d=1 is excluded, being a perfect square). So β satisfies the reduced condition (Theorem below) and is therefore purely periodic: β=α1=[a1,…,am] for some m. Now use the palindrome mechanism: for a purely periodic reduced quadratic irrational γ=[a1,…,am], the negative reciprocal of its conjugate, −1/γ′, has continued fraction expansion exactly the reversed block [am,…,a1] (this is a standard symmetry of purely periodic expansions, proved by observing that reversing a finite continued fraction block corresponds to conjugating and negating-reciprocating the Möbius transformation γ=qm−1γ+qm−2pm−1γ+pm−2, using pm−1qm−2−pm−2qm−1=(−1)m, together with the classical identity that the convergents of the reversed sequence of partial quotients are qm−1,qm−2,… in place of pm−1,pm−2,…). Apply this to β=α1: its conjugate is β′=(a0−d)/(d−a02), and
−β′1=d−a0d−a02=d+a0.
So −1/β′=a0+d=2a0+(d−a0), and since d−a0=1/β, we get −1/β′=2a0+1/β=[2a0;a1,…,am] (substituting the purely periodic expansion of β). But by the symmetry above, −1/β′ also equals [am,…,a1], purely periodic with the reversed block. Comparing the two expressions for the same real number, whose continued fraction expansion is unique, forces
[am,…,a1]=[2a0,a1,…,am]=[2a0,a1,…,am]
(the last equality because a purely periodic block [a0′;a1′,…] with the prefix equal to the start of the period is just the block shifted, i.e. [2a0,a1,…,am], being purely periodic with an0+ℓ=an from n=0, equals [2a0,a1,…,am] directly by definition of pure periodicity applied one step earlier). Matching term by term: am=2a0, and am−1=a1,am−2=a2,…, i.e. the block a1,…,am−1 (excluding the final 2a0) is a palindrome, and d=[a0;a1,…,am−1,2a0] as claimed (relabel ℓ=m). ■
∎
Worked examples
Example 1: 23. Here a0=⌊23⌋=4 since 42=16≤23<25=52. Track (Pn,Qn) via Pn+1=anQn−Pn, Qn+1=(23−Pn+12)/Qn:
P5=8⋅1−4=4, Q5=(23−16)/1=7. This is (P1,Q1)=(4,7) again — the state has repeated.
So the expansion is
23=[4;1,3,1,8],
period length 4, and indeed the middle block 1,3,1 is a palindrome, ending in 8=2a0, exactly as the Corollary predicts. Convergents: using p−1=1,p−2=0,q−1=0,q−2=1: p0=4,q0=1; p1=1⋅4+1=5,q1=1⋅1+0=1; p2=3⋅5+4=19,q2=3⋅1+1=4; p3=1⋅19+5=24,q3=1⋅4+1=5; p4=8⋅24+19=211,q4=8⋅5+4=44. Check: 211/44=4.7954545, and 23=4.795831…, matching to 4 decimal places, consistent with ∣p4/q4−23∣<1/q42=1/1936≈0.000516. Since the period length ℓ=4 is even, the fundamental solution of x2−23y2=1 is read off from the convergent just before the period closes, namely pℓ−1/qℓ−1=p3/q3=24/5:
P4=12⋅1−6=6,Q4=(41−36)/1=5 — this is (P1,Q1)=(6,5) again.
So
41=[6;2,2,12],
period length ℓ=3 (odd), middle block 2,2 palindromic trivially (single repeated digit), ending in 12=2⋅6. Good agreement with the Corollary. Convergents:p0=6,q0=1; p1=2⋅6+1=13,q1=2⋅1+0=2; p2=2⋅13+6=32,q2=2⋅2+1=5; p3=12⋅32+13=397,q3=12⋅5+2=62. Check 322−41⋅52=1024−1025=−1: since ℓ=3 is odd, the convergent at the end of the first period gives a solution to x2−41y2=−1, not +1; the actual solution to x2−41y2=1 requires going one full period further, to p5/q5. Continuing one more period (digits 2,2,12 repeated): p4=1⋅397+32=429? — carefully: a4=a1=2, so p4=2⋅397+32=826,q4=2⋅62+5=129; a5=a2=2, p5=2⋅826+397=2049,q5=2⋅129+62=320; a6=a3=12, p6=12⋅2049+826=25414,q6=12⋅320+129=3969. Check the odd-period convergent at the end of the second period, p5/q5=2049/320:
20492−41⋅3202=4198401−4198400=1.
So (x,y)=(2049,320) solves x2−41y2=1, while (32,5) solves x2−41y2=−1. This dichotomy (odd period gives −1 first, even period gives +1 directly) is exactly the phenomenon that Pell's Equation and Continued Fractions develops fully.
TheoremGalois's Characterization of Purely Periodic Expansions
A quadratic irrational α has a purely periodic continued fraction expansion if and only if α is reduced, meaning
α>1and−1<α′<0,
where α′ is the algebraic conjugate of α.
Proof
(⇐) Suppose α>1 and −1<α′<0. Let a=⌊α⌋≥1 and β=1/(α−a), so α=a+1/β and, conjugating (a field automorphism of Q(D), so it respects all algebraic relations satisfied by α), α′=a+1/β′, i.e.
β′=α′−a1.
Since −1<α′<0 and a≥1, we get α′−a<−1, so −1<β′<0 (dividing 1 by a number less than −1 gives a result in (−1,0)). Also β>1 automatically since β is a continued-fraction tail of an irrational. So β is again reduced, with the same discriminant D (conjugation and the recursion preserve the field Q(D)). By the Lemma, the sequence of states (Pn,Qn) associated to α=α0 takes only finitely many values, so by pigeonhole there exist 0≤i<j with αi=αj; as argued in Lagrange's theorem, this forces eventual periodicity, i.e. αn0=αn0+ℓ for some n0≥0,ℓ≥1 with n0 minimal. We must show n0=0, i.e. the periodicity starts immediately. Suppose for contradiction n0≥1. Then αn0−1+ℓ+1=αn0+ℓ=αn0=αn0−1+1, i.e. writing γ=αn0−1 and δ=αn0−1+ℓ (also reduced, by the same argument applied inductively — every tail of a reduced quadratic irrational is reduced, as shown in the paragraph above), both γ and δ have the same "next state" αn0 under the map x↦1/(x−⌊x⌋), and both are reduced with the same integer part in fact forced equal: from γ=an0−1+1/αn0 and δ=an0−1+ℓ+1/αn0+ℓ=an0−1+ℓ+1/αn0 (using αn0+ℓ=αn0), if we can show an0−1=an0−1+ℓ then γ=δ. Here is the key point: for a reducedx with tail y=1/(x−⌊x⌋) also reduced, the integer part a=⌊x⌋ is recoverable purely from y: conjugating x=a+1/y gives x′=a+1/y′, and since −1<x′<0 and −1<y′<0, we get a=x′−1/y′∈(−1−1/y′,0−1/y′); since −1<y′<0 forces 1/y′<−1, so −1/y′>1, giving a∈(0,∞) narrowly pinned as the unique integer with a−1<−1/y′≤a roughly — concretely, the clean classical fact is: for reduced x, a=⌊x⌋=⌊−1/y′⌋, a formula depending only on y′, hence only on y (since y′ is the conjugate of y, determined by y and D). Both γ,δ share the same y=αn0 hence the same y′=αn0′, hence the same recovered integer part an0−1=an0−1+ℓ, hence γ=δ, i.e. αn0−1=αn0−1+ℓ. This contradicts minimality of n0 (we found a smaller index, n0−1, exhibiting periodicity with the same ℓ). Hence n0=0: α is purely periodic. (⇒) Suppose α=α0 is purely periodic: α0=αℓ for the period length ℓ. Since α0=[a0;a1,a2,…] with all an positive integers for n≥1 and a0≥1 as well (because purely periodic means a0=aℓ≥1, as every an for n≥1 satisfies an≥1, tails being >1), we get α0=a0+1/α1>1 immediately, since a0≥1 and 1/α1>0. For the conjugate: proceed by induction on ℓ using the reversed-block identity established in the Corollary's proof. Concretely, purely periodic α=[a0,…,aℓ−1] satisfies α=qℓ−1α+qℓ−2pℓ−1α+pℓ−2 (the same unfolding identity as before, now with the whole period, since αℓ=α0=α), i.e. α satisfies
qℓ−1α2+(qℓ−2−pℓ−1)α−pℓ−2=0.
The two roots of this quadratic are α and α′ (its conjugate, since the equation has integer/rational coefficients and α generates the same quadratic field). By Vieta, αα′=−pℓ−2/qℓ−1 and α+α′=(pℓ−1−qℓ−2)/qℓ−1. Define f(x)=qℓ−1x2+(qℓ−2−pℓ−1)x−pℓ−2; then f(α)=f(α′)=0 and f(−1)=qℓ−1−qℓ−2+pℓ−1−pℓ−2=(pℓ−1+qℓ−1)−(pℓ−2+qℓ−2). Since convergent denominators qk strictly increase for k≥1 (as qk=akqk−1+qk−2 with ak≥1) and similarly pk strictly increases for k≥1 once a0≥1, we get pℓ−1+qℓ−1>pℓ−2+qℓ−2 for ℓ≥2 (and this is checked directly for ℓ=1 too, where q−1=0,p−1=1: f(−1)=q0−0+p0−1=q0+p0−1≥0+a0−1≥0, in fact >0 since q0≥1). Hence f(−1)>0. Also f(0)=−pℓ−2<0 (since pℓ−2≥0 with equality only in degenerate small cases excluded once ℓ≥2; for ℓ=1, p−1=1>0 so f(0)=−1<0 too). Since f is a upward-opening parabola (qℓ−1>0) with f(−1)>0>f(0), and f has its two roots α,α′ straddling this sign change pattern: a quadratic with f(−1)>0, f(0)<0 has exactly one root in (−1,0) (since the sign change between −1 and 0 forces a root there by the Intermediate Value Theorem, and a quadratic has at most two roots, with the other root lying outside [−1,0] because f near ±∞ is positive while f(0)<0 forces the second sign change to occur either left of −1 or right of 0; combined with α=α0>1>0, α is the root outside (−1,0), so α′ must be the root inside (−1,0)). Hence −1<α′<0, completing the proof. ■
∎
LemmaApproximation quality of convergents
Let α be irrational with convergents pn/qn. Then for all n≥0,
pnqn−1−pn−1qn=(−1)n−1,
and
α−qnpn<qnqn+11<qn21.
Proof
The determinant identity follows by induction from the recursions pn=anpn−1+pn−2, qn=anqn−1+qn−2: pnqn−1−pn−1qn=−(pn−1qn−2−pn−2qn−1), and the base case n=0 (using p−1=1,q−1=0,p−2=0,q−2=1) gives p0q−1−p−1q0=0−q0=−a0⋅1; checking directly with q0=1: p0q−1−p−1q0=0−1=−1=(−1)−1, confirming the pattern, and it alternates sign thereafter, giving (−1)n−1 for all n≥0 by induction. For the approximation bound, since α lies between consecutive convergents (a standard fact: pn/qn alternately over- and under-estimate α, converging to it, because α=[a0;…,an,αn+1] literally equals the Möbius transform qnαn+1+qn−1pnαn+1+pn−1 with αn+1>1), we compute
the last inequality because qn+1>qn for n≥1 (and one checks n=0 separately, or simply notes qn+1≥qn always with strict inequality typically arising after the first step). ■
∎
Scope, edge cases & common traps
Situation
What happens
Why
α rational
Continued fraction is finite, never periodic in the eventual sense used here
The algorithm terminates (Euclidean algorithm), so there's no infinite tail to be periodic
D a perfect square in (P+D)/Q
α is actually rational
Excluded explicitly in the definition of quadratic irrational
α quadratic irrational but not reduced
Expansion is eventually periodic but not purely periodic
Galois's theorem needs α>1 and −1<α′<0 simultaneously
d itself
Never purely periodic (since α′=−d<−1 typically) but a0+d obtained by shifting is
This is exactly why the expansion is [a0;…] with the bar starting at index 1
Period length parity for d
Even period ⇒x2−dy2=1 solved directly; odd period ⇒ first hit is x2−dy2=−1
Determined by the sign (−1)ℓ in the determinant identity applied to the halfway convergent
CounterexampleWhy "D is not a perfect square" cannot be dropped
Drop the hypothesis that the discriminant D is a non-square, keeping every other hypothesis of the definition of quadratic irrational. Take D=25, P0=0, Q0=1: formally α=(0+25)/1=5. This "α" is not irrational at all — it is the integer 5 — so it does not even admit an infinite continued fraction expansion; the algorithm halts immediately since α−a0=5−5=0 and the next step 1/(α0−a0) requires division by zero. If instead one perturbs slightly, say D=25, P0=1,Q0=2 (still requiring Q0∣D−P02=24, satisfied), then α=(1+5)/2=3, again rational, and again the algorithm terminates after one step with no periodicity to speak of. This illustrates precisely why the non-square hypothesis on D is load-bearing: without it, "α" collapses to a rational number, Lagrange's theorem's hypothesis (irrationality) fails outright, and the entire periodicity conclusion is vacuous rather than false — but the deeper point is that allowing D square silently destroys the well-definedness of the infinite iteration αn+1=1/(αn−an), since αn becomes a terminating (rational) sequence, and "periodicity of a finite sequence" is not a meaningful or useful notion in this theory.
The mathematician behind it
Origins · 1 minJoseph-Louis Lagrange and how this was discovered
JL
Joseph-Louis Lagrange
1736–1813 · Ecole Royale d'Artillerie, Turin; Berlin Academy; Ecole Polytechnique, Paris
Lagrange proved in 1770 that every quadratic irrational has an eventually periodic continued fraction expansion, completing a picture whose special cases (periodicity for d) had been observed numerically since antiquity in the guise of the "cyclic method" for Pell's equation used by Indian mathematicians such as Brahmagupta and Bhāskara II. Lagrange's proof, essentially the pigeonhole argument on bounded triples (Pn,Qn) presented above, turned an empirical pattern into a theorem and simultaneously gave the first rigorous, general proof that Pell's equation x2−dy2=1 always has a nontrivial solution for every non-square d.
History
- 1657 — Fermat challenges English mathematicians to solve x2−61y2=1, without a general method.
- 1770 — Lagrange proves periodicity of continued fractions of quadratic irrationals and derives a complete algorithm for Pell's equation.
- 1828 — Évariste Galois, as a teenager, publishes the characterization of purely periodic continued fractions in terms of the reduced condition on α and its conjugate.
- 1833–1837 — Dirichlet develops the connection between periodic continued fractions, units in real quadratic fields, and class numbers.
- 20th century — The reduction theory of indefinite binary quadratic forms is reformulated as the geodesic flow on the modular surface, with periodic continued fractions corresponding exactly to closed geodesics.
Why does the continued fraction of d always end its period in 2⌊d⌋?
This follows from the symmetry between d and its shifted tail β1=1/(d−a0), which is purely periodic since it satisfies the reduced condition (β1>1 and its conjugate lies in (−1,0)). The negative reciprocal of the conjugate of a purely periodic quadratic irrational has the reversed period as its own expansion — a standard symmetry proved via the Möbius-transformation identity for continued fraction tails. Applying this to β1 and simplifying using d+a0 shows the reversed block must start with 2a0, forcing the original block to end with 2a0 and be a palindrome apart from that final term. This is proved in full in the Corollary above.
Is the periodic block for d unique?
Yes, in the strongest sense: the sequence of partial quotients of any real number is unique (given the convention that finite continued fractions end in a term >1, to avoid the ambiguity […,an]=[…,an−1,1]), so once you fix that convention there is exactly one continued fraction expansion of d, hence exactly one periodic block, of a well-defined minimal length ℓ(d). Different non-square d can produce wildly different period lengths; there is no simple closed formula for ℓ(d) in terms of d, though it is related to the class number and regulator of Q(d).
Does every purely periodic continued fraction come from a reduced quadratic irrational, or could non-quadratic numbers also be purely periodic?
Purely periodic continued fractions are a special case of eventually periodic ones, and Lagrange's theorem already tells us eventually periodic simple continued fractions correspond exactly to quadratic irrationals. So any purely periodic continued fraction represents some quadratic irrational, and Galois's theorem further pins down which quadratic irrationals give purely periodic (rather than merely eventually periodic) expansions: precisely the reduced ones, with α>1 and conjugate in (−1,0). No non-quadratic irrational can have a periodic continued fraction at all, by the "only if" direction of Lagrange's theorem.
How does this connect to binary quadratic forms?
Each convergent-step of the continued fraction algorithm applied to a root of an indefinite quadratic form corresponds exactly to a reduction step on that form, replacing (a,b,c) by an equivalent form via the standard SL2(Z) action. Purely periodic continued fractions correspond to reduced indefinite forms lying on a single reduction cycle, and the period length equals the number of forms in that cycle — the same combinatorial object studied in Binary Quadratic Forms: Introduction. This dictionary is one of the deepest elementary bridges in classical number theory, turning form-equivalence classes into literally computable periodic sequences.
Why is the bound ∣α−pn/qn∣<1/qn2 important beyond just "good approximation"?
It shows convergents are asymptotically the best possible rational approximations: a classical companion theorem (not proved here) states that if ∣p/q−α∣<1/(2q2) for integers p,q with q≥1, then p/q must be a convergent of α. So convergents are not merely good approximations, they are essentially the only good approximations, which is why solving Pell's equation reduces to scanning convergents rather than searching all fractions.
What happens if d itself is negative, i.e. can this theory be run for −d?
No — the entire framework relies on α being a real irrational so that the floor function ⌊αn⌋ and the ordering-based algorithm make sense. For −d with d>0, the number is not real, so there is no simple continued fraction expansion in this sense at all; imaginary quadratic fields are instead studied through the reduction theory of positive-definite binary quadratic forms, a related but distinct theory with finite (not periodic) reduced representatives per equivalence class.
Can the period length be 0, i.e. can d have a purely eventually-non-periodic finite expansion?
No: d for non-square d is always irrational, so its continued fraction expansion is always infinite, and by Lagrange's theorem it is always eventually periodic with period length ℓ≥1. The smallest possible period length is ℓ=1, occurring for example when d=a02+1 (e.g. d=2,a0=1: 2=[1;2], period length 1).