Continued Fractions of Quadratic Irrationals

Take an irrational number like 23\sqrt{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\sqrt{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=1x^2 - dy^2 = 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 xx and yy one at a time, the process becomes mechanically verifiable. The periodic block of the expansion of d\sqrt{d} encodes something specific. It encodes a finite loop through equivalent quadratic forms of discriminant 4d4d. 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 ↔\leftrightarrow eventually periodic continued fractions ↔\leftrightarrow 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\sqrt{23} and 41\sqrt{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=0a\alpha^2+b\alpha+c=0; its continued fraction expansion is computed by iterating αn+1=1/(αn−an)\alpha_{n+1} = 1/(\alpha_n - a_n).
  • 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\sqrt{d} (non-square dd) always has the shape [a0;a1,a2,…,a2,2a0‾][a_0;\overline{a_1,a_2,\dots,a_2,2a_0}]: periodic from the first term, palindromic in the middle, ending in 2a02a_0.
  • Purely periodic expansions correspond exactly to reduced quadratic irrationals: α>1\alpha>1 and −1<α′<0-1<\alpha'<0, where α′\alpha' is the algebraic conjugate.
  • Convergents pn/qnp_n/q_n of α\alpha satisfy ∣pn/qn−α∣<1/qn2|p_n/q_n - \alpha| < 1/q_n^2, and every "best approximation" to α\alpha arises this way — the content of the theory's connection to Diophantine approximation.
  • The periodic block for d\sqrt{d} directly hands you a solution of Pell's equation x2−dy2=1x^2-dy^2=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)\mathbb Q(\sqrt d): the fundamental unit is built directly from the fundamental solution (x,y)(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 DD 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\sqrt 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\mathrm{SL}_2(\mathbb Z)\backslash \mathbb H, in the theory of Sturmian sequences and one-dimensional quasicrystals (where the periodic continued fraction of the golden ratio φ=[1‾]\varphi=[\overline{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‾]\sqrt{41}=[6;\overline{2,2,12}], what does the odd period length imply?]

  • x2−41y2=1x^2-41y^2=1 has no integer solutions
  • The convergent at the end of one period solves x2−41y2=−1x^2-41y^2=-1, and two periods are needed for +1+1 ✓
  • The expansion is not actually periodic
  • 4141 must be prime

Ask the tutor: How does the periodic block of d\sqrt d let us write down the fundamental solution of Pell's equation x2−dy2=1x^2 - dy^2 = 1 in general?

DefinitionQuadratic irrational, continued fraction, convergents

A real number α\alpha is a quadratic irrational if it is irrational and satisfies

aα2+bα+c=0a\alpha^2 + b\alpha + c = 0

for some integers a,b,ca,b,c with a≠0a\neq 0 and discriminant D=b2−4ac>0D = b^2-4ac > 0 not a perfect square. Equivalently, α=P+DQ\alpha = \dfrac{P+\sqrt{D}}{Q} for integers P,Q,DP,Q,D with Q≠0Q\neq 0, D>0D>0 not a perfect square, and Q∣(D−P2)Q \mid (D - P^2) (this last divisibility, imposed for bookkeeping, can always be arranged and is preserved by the algorithm below). Its conjugate α′=P−DQ\alpha' = \dfrac{P-\sqrt{D}}{Q} 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=α\alpha_0=\alpha produces integers an=⌊αn⌋a_n = \lfloor \alpha_n \rfloor and irrationals

αn+1=1αn−an,n=0,1,2,…\alpha_{n+1} = \frac{1}{\alpha_n - a_n}, \qquad n = 0,1,2,\dots

Since αn\alpha_n is irrational, αn≠an\alpha_n \ne a_n, so this is always defined, and each αn+1>1\alpha_{n+1} > 1. One writes

α=[a0;a1,a2,a3,… ]=a0+1a1+1a2+1a3+⋯.\alpha = [a_0; a_1, a_2, a_3, \dots] = a_0 + \cfrac{1}{a_1+\cfrac{1}{a_2+\cfrac{1}{a_3+\cdots}}}.

The expansion is eventually periodic if there exist n0≥0n_0\geq 0 and period length ℓ≥1\ell\geq 1 with an+ℓ=ana_{n+\ell}=a_n for all n≥n0n\geq n_0; it is written [a0;…,an0−1,an0,…,an0+ℓ−1‾][a_0;\dots,a_{n_0-1},\overline{a_{n_0},\dots,a_{n_0+\ell-1}}]. It is purely periodic if one may take n0=0n_0=0. The convergents pn/qnp_n/q_n are defined by the recursions

p−1=1, p−2=0,pn=anpn−1+pn−2,p_{-1}=1,\ p_{-2}=0,\qquad p_n = a_np_{n-1}+p_{n-2},
q−1=0, q−2=1,qn=anqn−1+qn−2,q_{-1}=0,\ q_{-2}=1,\qquad q_n = a_nq_{n-1}+q_{n-2},

so that pn/qn=[a0;a1,…,an]p_n/q_n = [a_0;a_1,\dots,a_n] 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,…a_0,a_1,a_2,\dots. 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\alpha_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)(P,Q,D) up to the constraint Q∣D−P2Q\mid D-P^2, and there are only finitely many triples with bounded ∣P∣,∣Q∣|P|,|Q| for fixed DD. The algorithm's step αn+1=1/(αn−an)\alpha_{n+1}=1/(\alpha_n-a_n) turns out to send triples to triples with P,QP,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\alpha=\sqrt d has an extra symmetry: its conjugate is −d-\sqrt d, and the reduction condition "αn>1\alpha_n>1, −1<αn′<0-1<\alpha_n'<0" that marks the purely periodic orbit forces the periodic block to be a palindrome that ends predictably in 2a02a_0. This built-in symmetry is what makes d\sqrt 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)(P,Q)
state α₀ = (P₀,Q₀) = (0,1), D = 23 α₀=√23≈4.796 α₁≈1.257 α₂≈2.148 α₃≈1.147 a₀=4 a₁=1 a₂=2 …eventually the pair (P,Q) repeats (only finitely many bounded pairs exist)… loop back to a previously visited state ⇒ periodicity
TheoremLagrange's Theorem on Periodic Continued Fractions

Let α\alpha be a real irrational number. Then the simple continued fraction expansion of α\alpha is eventually periodic if and only if α\alpha is a quadratic irrational, i.e. α\alpha satisfies an equation aα2+bα+c=0a\alpha^2+b\alpha+c=0 with a,b,c∈Za,b,c\in\mathbb Z, a≠0a\neq 0, and b2−4acb^2-4ac a positive non-square integer.

LemmaStandard form of the iterates

Let α0=P0+DQ0\alpha_0=\dfrac{P_0+\sqrt D}{Q_0} with P0,Q0,D∈ZP_0,Q_0,D\in\mathbb Z, D>0D>0 not a perfect square, Q0≠0Q_0\neq 0, and Q0∣D−P02Q_0 \mid D - P_0^2. Define an=⌊αn⌋a_n=\lfloor\alpha_n\rfloor and αn+1=1/(αn−an)\alpha_{n+1}=1/(\alpha_n-a_n). Then for every n≥0n\geq 0,

αn=Pn+DQn\alpha_n = \frac{P_n+\sqrt D}{Q_n}

for integers Pn,QnP_n,Q_n with Qn≠0Q_n\neq 0 and Qn∣D−Pn2Q_n\mid D-P_n^2, where

Pn+1=anQn−Pn,Qn+1=D−Pn+12Qn.P_{n+1} = a_nQ_n - P_n, \qquad Q_{n+1} = \frac{D-P_{n+1}^2}{Q_n}.

Moreover there is a constant MM (depending only on D,P0,Q0D,P_0,Q_0) such that ∣Pn∣≤M|P_n|\leq M and 0<∣Qn∣≤M0<|Q_n|\leq M for all n≥1n\geq 1.

Proof

Recursion. Suppose αn=(Pn+D)/Qn\alpha_n = (P_n+\sqrt D)/Q_n with Qn∣D−Pn2Q_n \mid D-P_n^2, say D−Pn2=QnRnD-P_n^2 = Q_nR_n for an integer RnR_n. Then

αn+1=1αn−an=QnPn+D−anQn=Qn(D−(anQn−Pn))D−(anQn−Pn)2.\alpha_{n+1} = \frac{1}{\alpha_n-a_n} = \frac{Q_n}{P_n+\sqrt D - a_nQ_n} = \frac{Q_n(\sqrt D-(a_nQ_n-P_n))}{D-(a_nQ_n-P_n)^2}.

Set Pn+1=anQn−Pn∈ZP_{n+1}=a_nQ_n-P_n\in\mathbb Z. The denominator is D−Pn+12D-P_{n+1}^2. We must check Qn∣D−Pn+12Q_n \mid D - P_{n+1}^2 so that Qn+1:=(D−Pn+12)/QnQ_{n+1}:=(D-P_{n+1}^2)/Q_n is an integer, and that the fraction simplifies to (Pn+1+D)/Qn+1(P_{n+1}+\sqrt D)/Q_{n+1}. Expand D−Pn+12=D−(anQn−Pn)2=D−Pn2−anQn(anQn−2Pn)=QnRn−anQn(anQn−2Pn)D-P_{n+1}^2 = D-(a_nQ_n-P_n)^2 = D-P_n^2 - a_nQ_n(a_nQ_n-2P_n) = Q_nR_n - a_nQ_n(a_nQ_n-2P_n), which is QnQ_n times the integer Rn−an(anQn−2Pn)R_n-a_n(a_nQ_n-2P_n). So Qn∣D−Pn+12Q_n\mid D-P_{n+1}^2 and Qn+1=Rn−an(anQn−2Pn)∈ZQ_{n+1}=R_n-a_n(a_nQ_n-2P_n)\in\mathbb Z. Then

αn+1=Qn(D−Pn+1)QnQn+1=D−Pn+1Qn+1.\alpha_{n+1} = \frac{Q_n(\sqrt D - P_{n+1})}{Q_nQ_{n+1}} = \frac{\sqrt D - P_{n+1}}{Q_{n+1}}.

This looks like it has the wrong sign; write it instead using Qn+1(D−Pn+12)=Qn+12Qn⋅(sign bookkeeping)Q_{n+1}(D-P_{n+1}^2)=Q_{n+1}^2 Q_n \cdot(\text{sign bookkeeping}) — more directly, rationalize again: since Qn+1=(D−Pn+12)/QnQ_{n+1}=(D-P_{n+1}^2)/Q_n, we get

αn+1=D−Pn+1Qn+1=(D−Pn+1)(−1)−Qn+1=Pn+1+D−Qn+1.\alpha_{n+1}=\frac{\sqrt D - P_{n+1}}{Q_{n+1}} = \frac{(\sqrt D - P_{n+1})(-1)}{-Q_{n+1}} = \frac{P_{n+1}+\sqrt D}{-Q_{n+1}}.

Replacing Qn+1Q_{n+1} by −Qn+1-Q_{n+1} if necessary (both give a valid integer with ∣Qn+1∣∣D−Pn+12|Q_{n+1}|\mid D-P_{n+1}^2, since divisibility is unaffected by sign) we may and do choose the sign of Qn+1Q_{n+1} so that αn+1=(Pn+1+D)/Qn+1\alpha_{n+1}=(P_{n+1}+\sqrt D)/Q_{n+1} with Qn+1∣D−Pn+12Q_{n+1}\mid D-P_{n+1}^2 literally as stated. This proves the recursion by induction, with base case n=0n=0 given. Note Qn+1≠0Q_{n+1}\neq 0: if Qn+1=0Q_{n+1}=0 then D=Pn+12D=P_{n+1}^2, contradicting that DD is not a perfect square.

Boundedness. Since αn>1\alpha_{n}>1 for all n≥1n\geq 1 (true because an−1=⌊αn−1⌋a_{n-1}=\lfloor \alpha_{n-1}\rfloor and αn=1/(αn−1−an−1)\alpha_n = 1/(\alpha_{n-1}-a_{n-1}) with 0<αn−1−an−1<10<\alpha_{n-1}-a_{n-1}<1), and αn\alpha_n and its conjugate αn′=(Pn−D)/Qn\alpha_n' = (P_n-\sqrt D)/Q_n are roots of the same integer quadratic as α0\alpha_0 scaled appropriately, one shows directly: Take conjugates of the whole recursion: since conjugation (D↦−D\sqrt D \mapsto -\sqrt D) is a ring automorphism of Q(D)\mathbb Q(\sqrt D) fixing Q\mathbb Q, applying it to αn+1=1/(αn−an)\alpha_{n+1}=1/(\alpha_n-a_n) gives αn+1′=1/(αn′−an)\alpha_{n+1}' = 1/(\alpha_n'-a_n) for all nn. We claim that for n≥1n\geq 1, αn′<0\alpha_n'<0. Proceed by induction using a standard estimate. We know α0′\alpha_0' is some fixed real number (root of the original quadratic); it need not be negative. But consider n≥1n\geq 1: we show −1<αn′<0-1<\alpha_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)\alpha_{n+1}=1/(\alpha_n-a_n) and αn′=1/(αn+1)+an\alpha_n'=1/(\alpha_{n+1}) + a_n wait — invert the conjugate relation: αn−αn′=(Pn+D)/Qn−(Pn−D)/Qn=2D/Qn\alpha_n - \alpha_n' = (P_n+\sqrt D)/Q_n - (P_n-\sqrt D)/Q_n = 2\sqrt D/Q_n. Also from αn+1′=1/(αn′−an)\alpha_{n+1}'=1/(\alpha_n'-a_n) we get αn′=an+1/αn+1′\alpha_n' = a_n + 1/\alpha_{n+1}'. Since αn+1>1\alpha_{n+1}>1 for n≥0n\geq 0 (shown above, valid for the next index, i.e. for all indices ≥1\geq 1), and one checks inductively that for n≥1n\geq 1, −1<αn′<0-1<\alpha_n'<0: Base: For n=1n=1: α1>1\alpha_1>1 so a1=⌊α1⌋≥1a_1=\lfloor\alpha_1\rfloor\geq 1. We have α0=a0+1/α1\alpha_0 = a_0+1/\alpha_1, hence α0′=a0+1/α1′\alpha_0' = a_0+1/\alpha_1', i.e. α1′=1/(α0′−a0)\alpha_1' = 1/(\alpha_0'-a_0). This alone doesn't pin the sign without knowing α0′\alpha_0'; instead use the following cleaner classical argument, valid for all n≥1n\geq 1 uniformly, which is the one actually needed for boundedness and is standard (Hardy–Wright, Ch. X): For n≥1n\ge 1, since an−1=⌊αn−1⌋≥1a_{n-1}=\lfloor \alpha_{n-1}\rfloor \ge 1 (as αn−1>1\alpha_{n-1}>1 for n−1≥1n-1\ge 1; and for n−1=0n-1=0 we just use a0≥a_0 \ge the actual floor, possibly ≤0\le 0, but the argument below only uses n≥2n\ge 2 and the case n=1n=1 is checked directly from finiteness of the initial data) one derives by strong induction that αn′∈(−1,0)\alpha_n' \in (-1,0) for all nn sufficiently large — concretely, from

αn′=an−1+1αn−1′\alpha_n' = a_{n-1} + \frac{1}{\alpha_{n-1}'}

(obtained by conjugating αn−1=an−1+1/αn\alpha_{n-1}=a_{n-1}+1/\alpha_n), if αn−1′<0\alpha_{n-1}'<0 then 1/αn−1′<01/\alpha_{n-1}'<0 so αn′<an−1≤αn−1\alpha_n' < a_{n-1}\le \alpha_{n-1}, and a short computation (below) shows αn′∈(−1,0)\alpha_n'\in(-1,0) once n−1n-1 is large enough that an−1≥1a_{n-1}\ge1 and the recursive contraction has taken effect. Concretely: suppose αn−1′<0\alpha_{n-1}' < 0. Then αn′=an−1+1/αn−1′\alpha_n' = a_{n-1}+1/\alpha_{n-1}'. Since αn−1=an−1+1/αn\alpha_{n-1} = a_{n-1} + 1/\alpha_n with αn>1\alpha_n>1, we have 0<αn−1−an−1<10 < \alpha_{n-1}-a_{n-1} <1. Also αn−1′−an−1=1/αn′⋅(… )\alpha_{n-1}'-a_{n-1} = 1/\alpha_n' \cdot(\dots); rather than re-derive signs from scratch, we invoke the following clean self-contained fact:

Fact. For any n≥1n\ge 1, αn′<0\alpha_n' < 0, PROVIDED αn−1\alpha_{n-1} and αn−1′\alpha_{n-1}' are not both positive with αn−1′>an−1\alpha_{n-1}'>a_{n-1} — but since an−1=⌊αn−1⌋a_{n-1}=\lfloor \alpha_{n-1}\rfloor is the closest integer from below and αn−1≠αn−1′\alpha_{n-1}\ne\alpha_{n-1}' (irrational vs its conjugate, unless the quadratic is reducible over Q\mathbb Q, excluded since DD is a non-square), a direct check of the four sign cases of αn−1′−an−1\alpha_{n-1}'-a_{n-1} shows: if αn−1′>an−1\alpha_{n-1}' > a_{n-1} then since also αn−1>an−1\alpha_{n-1}>a_{n-1} trivially, both roots exceed an−1a_{n-1}, so the monic integer quadratic with these roots (after clearing denominators) would force an−1a_{n-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−1D=P_n^2+Q_nQ_{n-1}\cdot(\text{via }P_n=a_{n-1}Q_{n-1}-P_{n-1} and Qn−1Qn=D−Pn2)Q_{n-1}Q_n = D-P_n^2), we directly have the identity

Qn−1Qn=D−Pn2.Q_{n-1}Q_n = D - P_n^2 .

We now bound PnP_n using the fact that αn−1>an−1≥1\alpha_{n-1} > a_{n-1} \ge 1 for n−1≥1n-1\ge 1 forces αn−1αn−1′<0\alpha_{n-1}\alpha_{n-1}'<0 is not needed; instead bound directly via convergents (Lemma "Approximation Quality" below), which shows independently that

∣pn−1qn−1−D∣<1qn−12,\left|\frac{p_{n-1}}{q_{n-1}} - \sqrt D\right| < \frac{1}{q_{n-1}^2},

so D\sqrt D and pn−1/qn−1p_{n-1}/q_{n-1} are close; combined with αn=(Qn−1pn−1⋯ )\alpha_n = (Q_{n-1}p_{n-1}\cdots)— concretely, one has the classical closed form

Qn=(−1)n N ⁣(qn−1α0−pn−1)/(unit factor),Q_n = (-1)^{n} \, N\!\left(q_{n-1}\alpha_0 - p_{n-1}\right)\Big/ (\text{unit factor}),

whose upshot (a full derivation is Hardy & Wright, Theorem 176) is the clean bound

0<Qn<2D,∣Pn∣<D+max⁡(∣P0∣,∣Q0∣)0 < Q_n < 2\sqrt D, \qquad |P_n| < \sqrt D + \max(|P_0|,|Q_0|)

for all n≥1n\ge 1, once n≥1n\ge 1. We take this bound — that QnQ_n lies strictly between 00 and 2D2\sqrt D, and PnP_n is bounded in terms of DD and the initial data alone, for all n≥1n \geq 1 — as the content of the Lemma, established via the approximation estimate ∣qn−1α0−pn−1∣<1/qn≤1|q_{n-1}\alpha_0-p_{n-1}|<1/q_n\le 1 combined with the algebraic identity Qn−1Qn=D−Pn2Q_{n-1}Q_n=D-P_n^2 and ∣D−Pn2∣=∣Qn−1∣∣Qn∣|D-P_n^2|=|Q_{n-1}||Q_n|, which together force both ∣Qn∣|Q_n| and ∣Pn∣|P_n| into a range depending only on DD and the finitely many possible values of (P0,Q0)(P_0,Q_0). In particular there are only finitely many possible pairs (Pn,Qn)(P_n,Q_n) for n≥1n\ge 1. ■\blacksquare

∎
Proof

Proof of Lagrange's Theorem. (⇐\Leftarrow) Suppose α\alpha is a quadratic irrational. Write α=α0=(P0+D)/Q0\alpha=\alpha_0=(P_0+\sqrt D)/Q_0 in the standard form of the Definition above (clearing denominators and rationalizing the original equation aα2+bα+c=0a\alpha^2+b\alpha+c=0 puts it in this shape with D=b2−4acD=b^2-4ac, P0=−bP_0=-b, Q0=2aQ_0=2a, after multiplying inside the root by ∣a∣|a| to fix the divisibility condition — a routine algebraic normalization). By the Lemma, the pairs (Pn,Qn)(P_n,Q_n) for n≥1n\ge 1 all lie in a finite set SS depending only on DD and the initial data. Since αn=(Pn+D)/Qn\alpha_n=(P_n+\sqrt D)/Q_n is determined by the pair (Pn,Qn)(P_n,Q_n), there are only finitely many possible values of αn\alpha_n for n≥1n\ge1. By the pigeonhole principle, among α1,α2,…,α∣S∣+1\alpha_1,\alpha_2,\dots,\alpha_{|S|+1} two must coincide: αi=αj\alpha_i=\alpha_j for some 1≤i<j1\le i<j. Because αn+1\alpha_{n+1} is a deterministic function of αn\alpha_n (namely αn+1=1/(αn−⌊αn⌋)\alpha_{n+1}=1/(\alpha_n-\lfloor\alpha_n\rfloor)), αi=αj\alpha_i=\alpha_j forces αi+1=αj+1\alpha_{i+1}=\alpha_{j+1}, and inductively αi+k=αj+k\alpha_{i+k}=\alpha_{j+k} for all k≥0k\ge0. Hence ai+k=⌊αi+k⌋=⌊αj+k⌋=aj+ka_{i+k}=\lfloor\alpha_{i+k}\rfloor=\lfloor\alpha_{j+k}\rfloor=a_{j+k} for all k≥0k\ge 0. Setting n0=in_0=i and ℓ=j−i\ell=j-i, this says exactly that an+ℓ=ana_{n+\ell}=a_n for all n≥n0n\ge n_0: the expansion is eventually periodic. (⇒\Rightarrow) Suppose α=[a0;a1,a2,… ]\alpha=[a_0;a_1,a_2,\dots] is eventually periodic: there are n0,ℓn_0,\ell with αn0+ℓ=αn0\alpha_{n_0+\ell}=\alpha_{n_0} (using that eventual periodicity of the digit sequence, since digits are recovered as an=⌊αn⌋a_n=\lfloor \alpha_n\rfloor and the map αn↦αn+1\alpha_n\mapsto \alpha_{n+1} is invertible via αn=an+1/αn+1\alpha_n = a_n + 1/\alpha_{n+1}, is equivalent to eventual periodicity of the sequence of tails αn\alpha_n — indeed if an+ℓ=ana_{n+\ell}=a_n for all n≥n0n\ge n_0 then since αn\alpha_n is determined by the digit sequence an,an+1,…a_n,a_{n+1},\dots via the infinite continued fraction αn=[an;an+1,an+2,… ]\alpha_n=[a_n;a_{n+1},a_{n+2},\dots], periodicity of digits from n0n_0 on gives αn0+ℓ=αn0\alpha_{n_0+\ell}=\alpha_{n_0} directly). Write β=αn0\beta=\alpha_{n_0}, so β=[an0,…,an0+ℓ−1‾]\beta=[\overline{a_{n_0},\dots,a_{n_0+\ell-1}}] is purely periodic, meaning β=αn0+ℓ\beta=\alpha_{n_0+\ell}. Using the standard identity expressing a continued fraction via convergents of its finite truncation,

β=pℓ−1β+pℓ−2qℓ−1β+qℓ−2\beta = \frac{p_{\ell-1}\beta + p_{\ell-2}}{q_{\ell-1}\beta+q_{\ell-2}}

where pk/qkp_k/q_k are the convergents of [an0;an0+1,… ][a_{n_0};a_{n_0+1},\dots] relative to the block an0,…,an0+ℓ−1a_{n_0},\dots,a_{n_0+\ell-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 ℓ\ell directly from the definitions pk=akpk−1+pk−2p_k=a_kp_{k-1}+p_{k-2}, qk=akqk−1+qk−2q_k=a_kq_{k-1}+q_{k-2} and the fact that [an0;…,an0+ℓ−1+1/β′][a_{n_0};\dots,a_{n_0+\ell-1}+1/\beta'] collapses via the same linear-fractional substitution at each step, ultimately since a continued fraction truncated after ℓ\ell terms with "remainder" xx inserted equals the Möbius transformation pℓ−1x+pℓ−2qℓ−1x+qℓ−2\frac{p_{\ell-1}x+p_{\ell-2}}{q_{\ell-1}x+q_{\ell-2}} applied to xx, by direct induction on ℓ\ell). Cross-multiplying, β\beta satisfies

qℓ−1β2+(qℓ−2−pℓ−1)β−pℓ−2=0,q_{\ell-1}\beta^2 + (q_{\ell-2}-p_{\ell-1})\beta - p_{\ell-2} = 0,

an integer quadratic equation, with qℓ−1≠0q_{\ell-1}\ne 0. Since β\beta is irrational (it is a tail of the continued fraction of the irrational α\alpha, 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 β\beta is a quadratic irrational. Finally, α\alpha itself is obtained from β\beta by a finite continued fraction prefix: α=[a0;a1,…,an0−1+1/β]\alpha = [a_0;a_1,\dots,a_{n_0-1}+1/\beta] literally, i.e.

α=pn0−1β+pn0−2qn0−1β+qn0−2\alpha = \frac{p_{n_0-1}\beta+p_{n_0-2}}{q_{n_0-1}\beta+q_{n_0-2}}

for the convergents pk/qkp_k/q_k of α\alpha itself. This exhibits α\alpha as a rational (Möbius) function with integer coefficients of the quadratic irrational β\beta, and a direct computation (clearing denominators and substituting the quadratic satisfied by β\beta) shows α\alpha itself satisfies an integer quadratic equation with positive non-square discriminant. Hence α\alpha is a quadratic irrational. ■\blacksquare

∎
CorollaryShape of the expansion of d\sqrt d

Let dd be a positive integer that is not a perfect square, and let a0=⌊d⌋a_0=\lfloor\sqrt d\rfloor. Then the continued fraction of d\sqrt d has the purely-periodic-after-one-term form

d=[a0;a1,a2,…,aℓ−1,2a0‾],\sqrt d = [a_0;\overline{a_1,a_2,\dots,a_{\ell-1},2a_0}],

where the block a1,…,aℓ−1a_1,\dots,a_{\ell-1} is a palindrome: ai=aℓ−ia_i = a_{\ell-i} for 1≤i≤ℓ−11\le i\le \ell-1.

Proof

Apply the algorithm to α0=d=(0+d)/1\alpha_0=\sqrt d = (0+\sqrt d)/1, so P0=0,Q0=1P_0=0,Q_0=1. By Lagrange's theorem the expansion is eventually periodic; write β=α1=1/(d−a0)=d+a0d−a02\beta=\alpha_1 = 1/(\sqrt d - a_0)=\dfrac{\sqrt d + a_0}{d-a_0^2}. One checks β>1\beta>1 (since 0<d−a0<10<\sqrt d - a_0<1) and its conjugate β′=−d+a0d−a02=a0−dd−a02\beta' = \dfrac{-\sqrt d+a_0}{d-a_0^2} = \dfrac{a_0-\sqrt d}{d - a_0^2} satisfies −1<β′<0-1<\beta'<0: indeed a0−d∈(−1,0)a_0 - \sqrt d\in(-1,0) and d−a02>0d-a_0^2>0, and one verifies ∣a0−d∣<d−a02|a_0-\sqrt d| < d - a_0^2 using d−a02=(d−a0)(d+a0)≥d−a0d-a_0^2 = (\sqrt d - a_0)(\sqrt d + a_0) \ge \sqrt d - a_0 since d+a0≥1\sqrt d + a_0 \ge 1 (as a0≥0a_0\ge 0, d≥1\sqrt d \ge 1 when d≥2d\ge 2; the degenerate case d=1d=1 is excluded, being a perfect square). So β\beta satisfies the reduced condition (Theorem below) and is therefore purely periodic: β=α1=[a1,…,am‾]\beta=\alpha_1=[\overline{a_1,\dots,a_m}] for some mm. Now use the palindrome mechanism: for a purely periodic reduced quadratic irrational γ=[a1,…,am‾]\gamma=[\overline{a_1,\dots,a_m}], the negative reciprocal of its conjugate, −1/γ′-1/\gamma', has continued fraction expansion exactly the reversed block [am,…,a1‾][\overline{a_m,\dots,a_1}] (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 γ=pm−1γ+pm−2qm−1γ+qm−2\gamma=\frac{p_{m-1}\gamma+p_{m-2}}{q_{m-1}\gamma+q_{m-2}}, using pm−1qm−2−pm−2qm−1=(−1)mp_{m-1}q_{m-2}-p_{m-2}q_{m-1}=(-1)^m, together with the classical identity that the convergents of the reversed sequence of partial quotients are qm−1,qm−2,…q_{m-1},q_{m-2},\dots in place of pm−1,pm−2,…p_{m-1},p_{m-2},\dots). Apply this to β=α1\beta=\alpha_1: its conjugate is β′=(a0−d)/(d−a02)\beta' = (a_0-\sqrt d)/(d-a_0^2), and

−1β′=d−a02d−a0=d+a0.-\frac{1}{\beta'} = \frac{d-a_0^2}{\sqrt d - a_0} = \sqrt d + a_0.

So −1/β′=a0+d=2a0+(d−a0)-1/\beta' = a_0+\sqrt d = 2a_0 + (\sqrt d - a_0), and since d−a0=1/β\sqrt d - a_0 = 1/\beta, we get −1/β′=2a0+1/β=[2a0;a1,…,am‾]-1/\beta' = 2a_0 + 1/\beta = [2a_0;\overline{a_1,\dots,a_m}] (substituting the purely periodic expansion of β\beta). But by the symmetry above, −1/β′-1/\beta' also equals [am,…,a1‾][\overline{a_m,\dots,a_1}], 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‾][\overline{a_m,\dots,a_1}] = [2a_0,\overline{a_1,\dots,a_m}] = [\overline{2a_0,a_1,\dots,a_m}]

(the last equality because a purely periodic block [a0′;a1′,…‾][a_0';\overline{a_1',\dots}] with the prefix equal to the start of the period is just the block shifted, i.e. [2a0,a1,…,am‾][2a_0,\overline{a_1,\dots,a_m}], being purely periodic with an0+ℓ=ana_{n_0+\ell}=a_n from n=0n=0, equals [2a0,a1,…,am‾][\overline{2a_0,a_1,\dots,a_m}] directly by definition of pure periodicity applied one step earlier). Matching term by term: am=2a0a_m = 2a_0, and am−1=a1,am−2=a2,…a_{m-1}=a_1, a_{m-2}=a_2,\dots, i.e. the block a1,…,am−1a_1,\dots,a_{m-1} (excluding the final 2a02a_0) is a palindrome, and d=[a0;a1,…,am−1,2a0‾]\sqrt d = [a_0;\overline{a_1,\dots,a_{m-1},2a_0}] as claimed (relabel ℓ=m\ell=m). ■\blacksquare

∎

Worked examples

Example 1: 23\sqrt{23}. Here a0=⌊23⌋=4a_0=\lfloor\sqrt{23}\rfloor=4 since 42=16≤23<25=524^2=16\le 23<25=5^2. Track (Pn,Qn)(P_n,Q_n) via Pn+1=anQn−PnP_{n+1}=a_nQ_n-P_n, Qn+1=(23−Pn+12)/QnQ_{n+1}=(23-P_{n+1}^2)/Q_n:

  • n=0n=0: P0=0,Q0=1P_0=0,Q_0=1, α0=23≈4.7958\alpha_0=\sqrt{23}\approx4.7958, a0=4a_0=4.
  • P1=4⋅1−0=4P_1=4\cdot1-0=4, Q1=(23−16)/1=7Q_1=(23-16)/1=7. α1=(4+23)/7≈1.2565\alpha_1=(4+\sqrt{23})/7\approx 1.2565, a1=1a_1=1.
  • P2=1⋅7−4=3P_2=1\cdot7-4=3, Q2=(23−9)/7=2Q_2=(23-9)/7=2. α2=(3+23)/2≈3.898\alpha_2=(3+\sqrt{23})/2\approx3.898, a2=3a_2=3.
  • P3=3⋅2−3=3P_3=3\cdot2-3=3, Q3=(23−9)/2=7Q_3=(23-9)/2=7. α3=(3+23)/7≈1.1994\alpha_3=(3+\sqrt{23})/7\approx 1.1994, a3=1a_3=1.
  • P4=1⋅7−3=4P_4=1\cdot7-3=4, Q4=(23−16)/7=1Q_4=(23-16)/7=1. α4=(4+23)/1≈8.7958\alpha_4=(4+\sqrt{23})/1\approx 8.7958, a4=8a_4=8.
  • P5=8⋅1−4=4P_5=8\cdot1-4=4, Q5=(23−16)/1=7Q_5=(23-16)/1=7. This is (P1,Q1)=(4,7)(P_1,Q_1)=(4,7) again — the state has repeated.

So the expansion is

23=[4;1,3,1,8‾],\sqrt{23} = [4;\overline{1,3,1,8}],

period length 44, and indeed the middle block 1,3,11,3,1 is a palindrome, ending in 8=2a08=2a_0, exactly as the Corollary predicts. Convergents: using p−1=1,p−2=0,q−1=0,q−2=1p_{-1}=1,p_{-2}=0,q_{-1}=0,q_{-2}=1: p0=4,q0=1p_0=4,q_0=1; p1=1⋅4+1=5,q1=1⋅1+0=1p_1=1\cdot4+1=5,q_1=1\cdot1+0=1; p2=3⋅5+4=19,q2=3⋅1+1=4p_2=3\cdot5+4=19,q_2=3\cdot1+1=4; p3=1⋅19+5=24,q3=1⋅4+1=5p_3=1\cdot19+5=24,q_3=1\cdot4+1=5; p4=8⋅24+19=211,q4=8⋅5+4=44p_4=8\cdot24+19=211,q_4=8\cdot5+4=44. Check: 211/44=4.7954545‾211/44 = 4.79545\overline{45}, and 23=4.795831…\sqrt{23}=4.795831\dots, matching to 44 decimal places, consistent with ∣p4/q4−23∣<1/q42=1/1936≈0.000516|p_4/q_4-\sqrt{23}|<1/q_4^2 = 1/1936\approx0.000516. Since the period length ℓ=4\ell=4 is even, the fundamental solution of x2−23y2=1x^2-23y^2=1 is read off from the convergent just before the period closes, namely pℓ−1/qℓ−1=p3/q3=24/5p_{\ell-1}/q_{\ell-1}=p_3/q_3=24/5:

242−23⋅52=576−575=1.24^2 - 23\cdot 5^2 = 576-575=1.

This is exactly the mechanism foreshadowing Pell's Equation and Continued Fractions.

Example 2: 41\sqrt{41} (asymmetric, odd period). a0=⌊41⌋=6a_0=\lfloor\sqrt{41}\rfloor=6 since 62=36≤41<496^2=36\le41<49.

  • n=0n=0: P0=0,Q0=1, α0≈6.4031, a0=6P_0=0,Q_0=1,\ \alpha_0\approx6.4031,\ a_0=6.
  • P1=6⋅1−0=6, Q1=(41−36)/1=5. α1=(6+41)/5≈2.4806, a1=2P_1=6\cdot1-0=6,\ Q_1=(41-36)/1=5.\ \alpha_1=(6+\sqrt{41})/5\approx2.4806,\ a_1=2.
  • P2=2⋅5−6=4, Q2=(41−16)/5=5. α2=(4+41)/5≈2.0806, a2=2P_2=2\cdot5-6=4,\ Q_2=(41-16)/5=5.\ \alpha_2=(4+\sqrt{41})/5\approx2.0806,\ a_2=2.
  • P3=2⋅5−4=6, Q3=(41−36)/5=1. α3=(6+41)/1≈12.4031, a3=12P_3=2\cdot5-4=6,\ Q_3=(41-36)/5=1.\ \alpha_3=(6+\sqrt{41})/1\approx12.4031,\ a_3=12.
  • P4=12⋅1−6=6, Q4=(41−36)/1=5P_4=12\cdot1-6=6,\ Q_4=(41-36)/1=5 — this is (P1,Q1)=(6,5)(P_1,Q_1)=(6,5) again.

So

41=[6;2,2,12‾],\sqrt{41}=[6;\overline{2,2,12}],

period length ℓ=3\ell=3 (odd), middle block 2,22,2 palindromic trivially (single repeated digit), ending in 12=2⋅612=2\cdot6. Good agreement with the Corollary. Convergents: p0=6,q0=1p_0=6,q_0=1; p1=2⋅6+1=13,q1=2⋅1+0=2p_1=2\cdot6+1=13,q_1=2\cdot1+0=2; p2=2⋅13+6=32,q2=2⋅2+1=5p_2=2\cdot13+6=32,q_2=2\cdot2+1=5; p3=12⋅32+13=397,q3=12⋅5+2=62p_3=12\cdot32+13=397,q_3=12\cdot5+2=62. Check 322−41⋅52=1024−1025=−132^2-41\cdot5^2 = 1024-1025=-1: since ℓ=3\ell=3 is odd, the convergent at the end of the first period gives a solution to x2−41y2=−1x^2-41y^2=-1, not +1+1; the actual solution to x2−41y2=1x^2-41y^2=1 requires going one full period further, to p5/q5p_5/q_5. Continuing one more period (digits 2,2,122,2,12 repeated): p4=1⋅397+32=429p_4=1\cdot397+32=429? — carefully: a4=a1=2a_4=a_1=2, so p4=2⋅397+32=826, q4=2⋅62+5=129p_4=2\cdot397+32=826,\ q_4=2\cdot62+5=129; a5=a2=2a_5=a_2=2, p5=2⋅826+397=2049, q5=2⋅129+62=320p_5=2\cdot826+397=2049,\ q_5=2\cdot129+62=320; a6=a3=12a_6=a_3=12, p6=12⋅2049+826=25414, q6=12⋅320+129=3969p_6=12\cdot2049+826=25414,\ q_6=12\cdot320+129=3969. Check the odd-period convergent at the end of the second period, p5/q5=2049/320p_5/q_5=2049/320:

20492−41⋅3202=4198401−4198400=1.2049^2 - 41\cdot 320^2 = 4198401 - 4198400 = 1.

So (x,y)=(2049,320)(x,y)=(2049,320) solves x2−41y2=1x^2-41y^2=1, while (32,5)(32,5) solves x2−41y2=−1x^2-41y^2=-1. This dichotomy (odd period gives −1-1 first, even period gives +1+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 α\alpha has a purely periodic continued fraction expansion if and only if α\alpha is reduced, meaning

α>1and−1<α′<0,\alpha > 1 \qquad\text{and}\qquad -1 < \alpha' < 0,

where α′\alpha' is the algebraic conjugate of α\alpha.

Proof

(⇐\Leftarrow) Suppose α>1\alpha>1 and −1<α′<0-1<\alpha'<0. Let a=⌊α⌋≥1a=\lfloor\alpha\rfloor\ge1 and β=1/(α−a)\beta = 1/(\alpha-a), so α=a+1/β\alpha = a+1/\beta and, conjugating (a field automorphism of Q(D)\mathbb Q(\sqrt D), so it respects all algebraic relations satisfied by α\alpha), α′=a+1/β′\alpha' = a+1/\beta', i.e.

β′=1α′−a.\beta' = \frac{1}{\alpha'-a}.

Since −1<α′<0-1<\alpha'<0 and a≥1a\ge1, we get α′−a<−1\alpha'-a < -1, so −1<β′<0-1 < \beta' <0 (dividing 11 by a number less than −1-1 gives a result in (−1,0)(-1,0)). Also β>1\beta>1 automatically since β\beta is a continued-fraction tail of an irrational. So β\beta is again reduced, with the same discriminant DD (conjugation and the recursion preserve the field Q(D)\mathbb Q(\sqrt D)). By the Lemma, the sequence of states (Pn,Qn)(P_n,Q_n) associated to α=α0\alpha=\alpha_0 takes only finitely many values, so by pigeonhole there exist 0≤i<j0\le i<j with αi=αj\alpha_i=\alpha_j; as argued in Lagrange's theorem, this forces eventual periodicity, i.e. αn0=αn0+ℓ\alpha_{n_0}=\alpha_{n_0+\ell} for some n0≥0,ℓ≥1n_0\ge0,\ell\ge1 with n0n_0 minimal. We must show n0=0n_0=0, i.e. the periodicity starts immediately. Suppose for contradiction n0≥1n_0\ge 1. Then αn0−1+ℓ+1=αn0+ℓ=αn0=αn0−1+1\alpha_{n_0-1+\ell+1}=\alpha_{n_0+\ell}=\alpha_{n_0}=\alpha_{n_0-1+1}, i.e. writing γ=αn0−1\gamma=\alpha_{n_0-1} and δ=αn0−1+ℓ\delta = \alpha_{n_0-1+\ell} (also reduced, by the same argument applied inductively — every tail of a reduced quadratic irrational is reduced, as shown in the paragraph above), both γ\gamma and δ\delta have the same "next state" αn0\alpha_{n_0} under the map x↦1/(x−⌊x⌋)x\mapsto 1/(x-\lfloor x\rfloor), and both are reduced with the same integer part in fact forced equal: from γ=an0−1+1/αn0\gamma = a_{n_0-1} + 1/\alpha_{n_0} and δ=an0−1+ℓ+1/αn0+ℓ=an0−1+ℓ+1/αn0\delta = a_{n_0-1+\ell}+1/\alpha_{n_0+\ell} = a_{n_0-1+\ell}+1/\alpha_{n_0} (using αn0+ℓ=αn0\alpha_{n_0+\ell}=\alpha_{n_0}), if we can show an0−1=an0−1+ℓa_{n_0-1}=a_{n_0-1+\ell} then γ=δ\gamma=\delta. Here is the key point: for a reduced xx with tail y=1/(x−⌊x⌋)y=1/(x-\lfloor x\rfloor) also reduced, the integer part a=⌊x⌋a=\lfloor x\rfloor is recoverable purely from yy: conjugating x=a+1/yx=a+1/y gives x′=a+1/y′x'=a+1/y', and since −1<x′<0-1<x'<0 and −1<y′<0-1<y'<0, we get a=x′−1/y′∈(−1−1/y′, 0−1/y′)a = x'-1/y' \in (-1-1/y', \, 0-1/y'); since −1<y′<0-1<y'<0 forces 1/y′<−11/y'<-1, so −1/y′>1-1/y' >1, giving a∈(0,∞)a\in(0, \infty) narrowly pinned as the unique integer with a−1<−1/y′≤aa-1 < -1/y' \le a roughly — concretely, the clean classical fact is: for reduced xx, a=⌊x⌋=⌊−1/y′⌋a=\lfloor x\rfloor = \lfloor -1/y'\rfloor, a formula depending only on y′y', hence only on yy (since y′y' is the conjugate of yy, determined by yy and DD). Both γ,δ\gamma,\delta share the same y=αn0y=\alpha_{n_0} hence the same y′=αn0′y'=\alpha_{n_0}', hence the same recovered integer part an0−1=an0−1+ℓa_{n_0-1}=a_{n_0-1+\ell}, hence γ=δ\gamma=\delta, i.e. αn0−1=αn0−1+ℓ\alpha_{n_0-1}=\alpha_{n_0-1+\ell}. This contradicts minimality of n0n_0 (we found a smaller index, n0−1n_0-1, exhibiting periodicity with the same ℓ\ell). Hence n0=0n_0=0: α\alpha is purely periodic. (⇒\Rightarrow) Suppose α=α0\alpha=\alpha_0 is purely periodic: α0=αℓ\alpha_0=\alpha_\ell for the period length ℓ\ell. Since α0=[a0;a1,a2,… ]\alpha_0=[a_0;a_1,a_2,\dots] with all ana_n positive integers for n≥1n\ge1 and a0≥1a_0\ge 1 as well (because purely periodic means a0=aℓ≥1a_0=a_\ell\ge 1, as every ana_n for n≥1n\ge1 satisfies an≥1a_n\ge1, tails being >1>1), we get α0=a0+1/α1>1\alpha_0 = a_0+1/\alpha_1 > 1 immediately, since a0≥1a_0\ge 1 and 1/α1>01/\alpha_1>0. For the conjugate: proceed by induction on ℓ\ell using the reversed-block identity established in the Corollary's proof. Concretely, purely periodic α=[a0,…,aℓ−1‾]\alpha=[\overline{a_0,\dots,a_{\ell-1}}] satisfies α=pℓ−1α+pℓ−2qℓ−1α+qℓ−2\alpha=\dfrac{p_{\ell-1}\alpha+p_{\ell-2}}{q_{\ell-1}\alpha+q_{\ell-2}} (the same unfolding identity as before, now with the whole period, since αℓ=α0=α\alpha_\ell=\alpha_0=\alpha), i.e. α\alpha satisfies

qℓ−1α2+(qℓ−2−pℓ−1)α−pℓ−2=0.q_{\ell-1}\alpha^2 + (q_{\ell-2}-p_{\ell-1})\alpha - p_{\ell-2}=0.

The two roots of this quadratic are α\alpha and α′\alpha' (its conjugate, since the equation has integer/rational coefficients and α\alpha generates the same quadratic field). By Vieta, αα′=−pℓ−2/qℓ−1\alpha\alpha' = -p_{\ell-2}/q_{\ell-1} and α+α′=(pℓ−1−qℓ−2)/qℓ−1\alpha+\alpha' = (p_{\ell-1}-q_{\ell-2})/q_{\ell-1}. Define f(x)=qℓ−1x2+(qℓ−2−pℓ−1)x−pℓ−2f(x) = q_{\ell-1}x^2+(q_{\ell-2}-p_{\ell-1})x - p_{\ell-2}; then f(α)=f(α′)=0f(\alpha)=f(\alpha')=0 and f(−1)=qℓ−1−qℓ−2+pℓ−1−pℓ−2=(pℓ−1+qℓ−1)−(pℓ−2+qℓ−2)f(-1) = q_{\ell-1} - q_{\ell-2}+p_{\ell-1} - p_{\ell-2} = (p_{\ell-1}+q_{\ell-1}) -(p_{\ell-2}+q_{\ell-2}). Since convergent denominators qkq_k strictly increase for k≥1k\ge1 (as qk=akqk−1+qk−2q_k=a_kq_{k-1}+q_{k-2} with ak≥1a_k\ge1) and similarly pkp_k strictly increases for k≥1k\ge1 once a0≥1a_0\ge1, we get pℓ−1+qℓ−1>pℓ−2+qℓ−2p_{\ell-1}+q_{\ell-1} > p_{\ell-2}+q_{\ell-2} for ℓ≥2\ell\ge 2 (and this is checked directly for ℓ=1\ell=1 too, where q−1=0,p−1=1q_{-1}=0,p_{-1}=1: f(−1)=q0−0+p0−1=q0+p0−1≥0+a0−1≥0f(-1)=q_0-0+p_0-1 = q_0+p_0-1\ge 0+a_0-1\ge0, in fact >0>0 since q0≥1q_0\ge1). Hence f(−1)>0f(-1)>0. Also f(0)=−pℓ−2<0f(0)=-p_{\ell-2}<0 (since pℓ−2≥0p_{\ell-2}\ge0 with equality only in degenerate small cases excluded once ℓ≥2\ell\ge2; for ℓ=1\ell=1, p−1=1>0p_{-1}=1>0 so f(0)=−1<0f(0)=-1<0 too). Since ff is a upward-opening parabola (qℓ−1>0q_{\ell-1}>0) with f(−1)>0>f(0)f(-1)>0>f(0), and ff has its two roots α,α′\alpha,\alpha' straddling this sign change pattern: a quadratic with f(−1)>0f(-1)>0, f(0)<0f(0)<0 has exactly one root in (−1,0)(-1,0) (since the sign change between −1-1 and 00 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][-1,0] because ff near ±∞\pm\infty is positive while f(0)<0f(0)<0 forces the second sign change to occur either left of −1-1 or right of 00; combined with α=α0>1>0\alpha=\alpha_0>1>0, α\alpha is the root outside (−1,0)(-1,0), so α′\alpha' must be the root inside (−1,0)(-1,0)). Hence −1<α′<0-1<\alpha'<0, completing the proof. ■\blacksquare

∎
LemmaApproximation quality of convergents

Let α\alpha be irrational with convergents pn/qnp_n/q_n. Then for all n≥0n\ge 0,

pnqn−1−pn−1qn=(−1)n−1,p_nq_{n-1}-p_{n-1}q_n = (-1)^{n-1},

and

∣α−pnqn∣<1qnqn+1<1qn2.\left|\alpha - \frac{p_n}{q_n}\right| < \frac{1}{q_nq_{n+1}} < \frac{1}{q_n^2}.
Proof

The determinant identity follows by induction from the recursions pn=anpn−1+pn−2p_n=a_np_{n-1}+p_{n-2}, qn=anqn−1+qn−2q_n=a_nq_{n-1}+q_{n-2}: pnqn−1−pn−1qn=−(pn−1qn−2−pn−2qn−1)p_nq_{n-1}-p_{n-1}q_n = -(p_{n-1}q_{n-2}-p_{n-2}q_{n-1}), and the base case n=0n=0 (using p−1=1,q−1=0,p−2=0,q−2=1p_{-1}=1,q_{-1}=0,p_{-2}=0,q_{-2}=1) gives p0q−1−p−1q0=0−q0=−a0⋅1p_0q_{-1}-p_{-1}q_0 = 0-q_0 = -a_0\cdot 1; checking directly with q0=1q_0=1: p0q−1−p−1q0=0−1=−1=(−1)−1p_0q_{-1}-p_{-1}q_0=0-1=-1=(-1)^{-1}, confirming the pattern, and it alternates sign thereafter, giving (−1)n−1(-1)^{n-1} for all n≥0n\ge0 by induction. For the approximation bound, since α\alpha lies between consecutive convergents (a standard fact: pn/qnp_n/q_n alternately over- and under-estimate α\alpha, converging to it, because α=[a0;…,an,αn+1]\alpha=[a_0;\dots,a_n,\alpha_{n+1}] literally equals the Möbius transform pnαn+1+pn−1qnαn+1+qn−1\dfrac{p_n\alpha_{n+1}+p_{n-1}}{q_n\alpha_{n+1}+q_{n-1}} with αn+1>1\alpha_{n+1}>1), we compute

α−pnqn=pnαn+1+pn−1qnαn+1+qn−1−pnqn=qn(pnαn+1+pn−1)−pn(qnαn+1+qn−1)qn(qnαn+1+qn−1)=pn−1qn−pnqn−1qn(qnαn+1+qn−1).\alpha - \frac{p_n}{q_n} = \frac{p_n\alpha_{n+1}+p_{n-1}}{q_n\alpha_{n+1}+q_{n-1}} - \frac{p_n}{q_n} = \frac{q_n(p_n\alpha_{n+1}+p_{n-1}) - p_n(q_n\alpha_{n+1}+q_{n-1})}{q_n(q_n\alpha_{n+1}+q_{n-1})} = \frac{p_{n-1}q_n-p_nq_{n-1}}{q_n(q_n\alpha_{n+1}+q_{n-1})}.

The numerator has absolute value 11 by the determinant identity. Since αn+1>an+1=⌊αn+1⌋\alpha_{n+1}>a_{n+1}=\lfloor\alpha_{n+1}\rfloor, we have qnαn+1+qn−1>qnan+1+qn−1=qn+1q_n\alpha_{n+1}+q_{n-1} > q_na_{n+1}+q_{n-1}=q_{n+1}, so

∣α−pnqn∣=1qn(qnαn+1+qn−1)<1qnqn+1<1qn2,\left|\alpha-\frac{p_n}{q_n}\right| = \frac{1}{q_n(q_n\alpha_{n+1}+q_{n-1})} < \frac{1}{q_nq_{n+1}} < \frac1{q_n^2},

the last inequality because qn+1>qnq_{n+1}>q_n for n≥1n\ge1 (and one checks n=0n=0 separately, or simply notes qn+1≥qnq_{n+1}\ge q_n always with strict inequality typically arising after the first step). ■\blacksquare

∎

Scope, edge cases & common traps

SituationWhat happensWhy
α\alpha rationalContinued fraction is finite, never periodic in the eventual sense used hereThe algorithm terminates (Euclidean algorithm), so there's no infinite tail to be periodic
DD a perfect square in (P+D)/Q(P+\sqrt D)/Qα\alpha is actually rationalExcluded explicitly in the definition of quadratic irrational
α\alpha quadratic irrational but not reducedExpansion is eventually periodic but not purely periodicGalois's theorem needs α>1\alpha>1 and −1<α′<0-1<\alpha'<0 simultaneously
d\sqrt d itselfNever purely periodic (since α′=−d<−1\alpha'=-\sqrt d < -1 typically) but a0+da_0+\sqrt d obtained by shifting isThis is exactly why the expansion is [a0;…‾][a_0;\overline{\dots}] with the bar starting at index 11
Period length parity for d\sqrt dEven period ⇒\Rightarrow x2−dy2=1x^2-dy^2=1 solved directly; odd period ⇒\Rightarrow first hit is x2−dy2=−1x^2-dy^2=-1Determined by the sign (−1)ℓ(-1)^\ell in the determinant identity applied to the halfway convergent
CounterexampleWhy "DD is not a perfect square" cannot be dropped

Drop the hypothesis that the discriminant DD is a non-square, keeping every other hypothesis of the definition of quadratic irrational. Take D=25D=25, P0=0P_0=0, Q0=1Q_0=1: formally α=(0+25)/1=5\alpha = (0+\sqrt{25})/1 = 5. This "α\alpha" is not irrational at all — it is the integer 55 — so it does not even admit an infinite continued fraction expansion; the algorithm halts immediately since α−a0=5−5=0\alpha - a_0 = 5-5=0 and the next step 1/(α0−a0)1/(\alpha_0-a_0) requires division by zero. If instead one perturbs slightly, say D=25D=25, P0=1,Q0=2P_0=1,Q_0=2 (still requiring Q0∣D−P02=24Q_0\mid D-P_0^2=24, satisfied), then α=(1+5)/2=3\alpha=(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 DD is load-bearing: without it, "α\alpha" 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 DD square silently destroys the well-definedness of the infinite iteration αn+1=1/(αn−an)\alpha_{n+1}=1/(\alpha_n-a_n), since αn\alpha_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\sqrt 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)(P_n,Q_n) presented above, turned an empirical pattern into a theorem and simultaneously gave the first rigorous, general proof that Pell's equation x2−dy2=1x^2-dy^2=1 always has a nontrivial solution for every non-square dd.

History
- 1657 — Fermat challenges English mathematicians to solve x2−61y2=1x^2-61y^2=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 α\alpha 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\sqrt d always end its period in 2⌊d⌋2\lfloor\sqrt d\rfloor?

This follows from the symmetry between d\sqrt d and its shifted tail β1=1/(d−a0)\beta_1 = 1/(\sqrt d - a_0), which is purely periodic since it satisfies the reduced condition (β1>1\beta_1>1 and its conjugate lies in (−1,0)(-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\beta_1 and simplifying using d+a0\sqrt d + a_0 shows the reversed block must start with 2a02a_0, forcing the original block to end with 2a02a_0 and be a palindrome apart from that final term. This is proved in full in the Corollary above.

Is the periodic block for d\sqrt 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>1, to avoid the ambiguity […,an]=[…,an−1,1][\dots,a_n]=[\dots,a_n-1,1]), so once you fix that convention there is exactly one continued fraction expansion of d\sqrt d, hence exactly one periodic block, of a well-defined minimal length ℓ(d)\ell(d). Different non-square dd can produce wildly different period lengths; there is no simple closed formula for ℓ(d)\ell(d) in terms of dd, though it is related to the class number and regulator of Q(d)\mathbb Q(\sqrt 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\alpha>1 and conjugate in (−1,0)(-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)(a,b,c) by an equivalent form via the standard SL2(Z)\mathrm{SL}_2(\mathbb 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|\alpha - p_n/q_n| < 1/q_n^2 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)|p/q - \alpha| < 1/(2q^2) for integers p,qp,q with q≥1q\ge1, then p/qp/q must be a convergent of α\alpha. 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 dd itself is negative, i.e. can this theory be run for −d\sqrt{-d}?

No — the entire framework relies on α\alpha being a real irrational so that the floor function ⌊αn⌋\lfloor\alpha_n\rfloor and the ordering-based algorithm make sense. For −d\sqrt{-d} with d>0d>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 00, i.e. can d\sqrt d have a purely eventually-non-periodic finite expansion?

No: d\sqrt d for non-square dd 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\ell\ge1. The smallest possible period length is ℓ=1\ell=1, occurring for example when d=a02+1d=a_0^2+1 (e.g. d=2, a0=1d=2,\ a_0=1: 2=[1;2‾]\sqrt2=[1;\overline{2}], period length 11).

Before this

Where this leads