Can the equation x2−2y2=1 have infinitely many whole-number solutions? If so, how would you find them all? A little experimentation turns up (x,y)=(3,2), then (17,12), then (99,70). The numbers grow fast, and no pattern is obvious from guessing alone. This is Pell's equation, x2−dy2=1 for a nonsquare positive integer d. It is one of the oldest and most productive equations in number theory. It was studied by Brahmagupta and Bhāskara II centuries before Pell. Later it was placed on rigorous footing by Euler, Lagrange, and Legendre. The equation matters because it sits at the crossroads of several major theories. It is the norm-one condition for the ring Z[d]. It governs the unit group of real quadratic fields. It is also intimately tied to the theory of Equivalence and Reduction of Binary Forms. This is because solutions to Pell's equation correspond exactly to automorphisms of the form x2−dy2. Historically, Pell-type equations were used to produce excellent rational approximations to d. They also helped solve cattle-counting and Diophantine puzzles. In the Archimedes cattle problem, they even encoded staggeringly large numbers. The big picture is that Pell's equation is never solved by algebra alone. It requires an analytic input: the continued fraction expansion of d. This expansion is always eventually periodic, a fact from Continued Fractions of Quadratic Irrationals. The convergents of that expansion, truncated exactly at the end of each period, produce the smallest positive solution. This is called the fundamental solution. Every other solution is then generated from the fundamental one by a simple recursive multiplication rule. This mirrors the structure of a group of units. This article gives the full machinery. It covers the definition of the equation and its solutions, and the precise theorem connecting continued fraction convergents to solutions. It includes a complete proof, and two worked examples with genuinely different behavior (period length 1 and period length 4). It closes with the classical connection to binary quadratic forms. It also covers modern uses in cryptography and computational number theory.
Key takeaways
Pell's equation is x2−dy2=1 with d a positive nonsquare integer; solutions in positive integers always exist.
The continued fraction expansion of d is purely periodic after one term, and its convergents pn/qn solve pn2−dqn2=±1.
The smallest positive solution (x1,y1), the fundamental solution, arises at the convergent just before the period repeats.
All positive solutions are (xn,yn) with xn+ynd=(x1+y1d)n, generated by simple recursion.
The equation is the norm-one problem for Z[d] and encodes the unit group of a real quadratic order.
Key idea: periodicity of the continued fraction of d forces convergents to hit x2−dy2=±1 exactly, and the first hit of +1 generates every solution.
Where this lives today
Pell's equation is the norm-one problem for the ring of integers (or an order) in a real quadratic field Q(d), and the fundamental solution (x1,y1) generates the group of units — this is the rank-one case of Dirichlet's unit theorem, one of the cornerstones of algebraic number theory. The same continued-fraction machinery underlies the connection to Equivalence and Reduction of Binary Forms: automorphisms of the principal form x2−dy2 (matrices fixing the form under substitution) correspond exactly to solutions of Pell's equation, and this controls the structure of the class group of forms of discriminant 4d. Beyond pure number theory, Pell's equation supplies famously good rational approximations to square roots (each convergent pn/qn near a period boundary approximates d to within O(1/qn2), historically used before calculators existed). It appears in recreational and computational problems such as the Archimedes cattle problem, whose solution requires x2−4729494y2=1, with a fundamental solution having hundreds of thousands of digits. In cryptography and computational number theory, Pell equations and continued fraction algorithms are close cousins of the techniques used in integer factorization (e.g., the continued fraction factoring method, a precursor to the quadratic sieve) and in computing regulators of real quadratic fields, a task relevant to class number computations and to some lattice-based cryptographic constructions.
:::quiz[For d=2, the continued fraction is 2=[1;2], period r=1 (odd). What is the fundamental solution of x2−2y2=1?]
(1, 1)
(2, 1)
(3, 2) ✓
(7, 5)
Ask the tutor: Can you walk through why the chakravala method and the continued fraction method always produce the same fundamental solution?
DefinitionPell's Equation and Its Solutions
Let d be a positive integer that is not a perfect square. Pell's equation is
x2−dy2=1,
to be solved in integers x,y. A solution (x,y) is called positive if x>0 and y>0; among positive solutions, the one with smallest x (equivalently smallest y) is the fundamental solution, denoted (x1,y1). Solutions correspond to elements x+yd∈Z[d] of norm one, where the norm is N(x+yd)=(x+yd)(x−yd)=x2−dy2. This correspondence is a group isomorphism-flavored fact: if x2−dy2=1 and x′2−dy′2=1, then multiplying α=x+yd and α′=x′+y′d gives αα′=X+Yd with X2−dY2=N(α)N(α′)=1, so solutions compose. The continued fraction convergents of d are the fractions pn/qn obtained by truncating the continued fraction expansion
d=[a0;a1,a2,a3,…]
at each term, via the standard recursions p−1=1,p0=a0, q−1=0,q0=1, and
pn=anpn−1+pn−2,qn=anqn−1+qn−2(n≥1).
Intuition
The key fact underlying everything is that d is a quadratic irrational, so (as established in the study of Continued Fractions of Quadratic Irrationals) its continued fraction expansion is eventually periodic. In fact for d it takes the clean form
d=[a0;a1,a2,…,ar],
purely periodic after the first term, where a0=⌊d⌋ and r is the period length. Truncating this expansion at longer and longer prefixes produces convergents pn/qn that approximate d extremely well — well enough that pn2−dqn2 is forced to be a small integer, not just any real number close to 0. Periodicity means the "shape" of the tail of the expansion repeats, and this repetition is exactly what forces pn2−dqn2 to cycle through a short list of values, hitting +1 at predictable moments (the ends of periods, or every other period if r is odd). Picture the values pn2−dqn2 as you scan through n=0,1,2,…: they oscillate in sign and magnitude, bounded by 2d, and periodicity of the continued fraction forces this sequence itself to become periodic. The first time the sequence returns to +1 (other than the trivial n=−1 case) gives you the fundamental solution — the smallest "building block" — and every other solution is a power of it, just as every unit in a number ring is a power of a fundamental unit times a root of unity.
:::svg[Convergents of 2=[1;2] closing in, with pn2−2qn2 cycling through −1,+1,−1,+1,…]
Scope, edge cases & common traps
TheoremPell's Equation via Continued Fraction Convergents
Let d be a positive integer that is not a perfect square, and let
d=[a0;a1,…,ar]
be its (purely periodic after a0) continued fraction expansion, with minimal period length r≥1. Let pn/qn denote the convergents, n=−1,0,1,2,….
(1) Convergent identity. For every n≥0,
pn2−dqn2=(−1)n+1Qn+1,
where Qn+1>0 is the (n+1)-th "complete quotient denominator" arising in the standard algorithm for d (defined in the proof); in particular pr−12−dqr−12=(−1)r, and more generally
pkr−12−dqkr−12=(−1)krfor every integer k≥1.
(2) Existence and characterization of solutions. The equation x2−dy2=1 has infinitely many positive integer solutions. If r is even, all solutions (x,y) in positive integers with x2−dy2=1 are exactly the pairs (pkr−1,qkr−1) for k=1,2,3,…. If r is odd, they are exactly the pairs (p2kr−1,q2kr−1) for k=1,2,3,….
(3) Fundamental solution and generation of all solutions. Let (x1,y1) be the smallest positive solution as in (2) (i.e. k=1). Then every positive solution (x,y) of x2−dy2=1 equals (xn,yn) for a unique n≥1, where xn,yn are defined by
xn+ynd=(x1+y1d)n.
Proof
We use the standard machinery for continued fractions of quadratic irrationals; this is not circular because that theory (periodicity, complete quotients) is developed independently of Pell's equation.
Setup: complete quotients. Define α0=d, and for n≥0 set an=⌊αn⌋ and αn+1=1/(αn−an). Each αn can be written as
αn=Qnd+Pn
for integers Pn,Qn with Qn∣(d−Pn2) and Qn>0; this is proved by induction using the recursion Pn+1=anQn−Pn, Qn+1=(d−Pn+12)/Qn, starting from P0=0,Q0=1. This is the standard apparatus from the theory of Continued Fractions of Quadratic Irrationals; we take as known that this expansion is purely periodic after a0 (i.e. α0's tail equals αr,α2r,…) precisely because d satisfies x2=d with α0>1 and its "conjugate" −d lies in (−1,0) — the Galois-conjugate reduction criterion for purely periodic quadratic irrationals.
Step 1: the key convergent identity. By the defining property of continued fractions, for every n≥0,
d=α0=αn+1qn+qn−1αn+1pn+pn−1.
This is proved by induction on n using the recursions for pn,qn and the fact that d's continued fraction with tail replaced by αn+1 reproduces d exactly — a standard identity for finite truncations of continued fractions applied to a formal (n+1)-term expansion with last "partial quotient" αn+1. Substitute αn+1=(d+Pn+1)/Qn+1 and clear denominators:
d(Qn+1qn⋅?)
More directly, cross-multiply the displayed equation:
Pn+1qn+Qn+1qn−1=pn(irrational part, dividing by d).
Now compute pn2−dqn2 using these two relations. From the second, pn=Pn+1qn+Qn+1qn−1. Multiply the first equation by qn and the identity pn=Pn+1qn+Qn+1qn−1 by pn, then subtract; after simplification (a direct but slightly long algebraic computation using both boxed relations) one obtains the clean closed form
pn2−dqn2=(−1)n+1Qn+1.
(This is the standard identity proved in full in the continued-fraction theory of quadratic irrationals; we cite its derivation here as it is purely a computation with the two relations above, and take it as an established computational fact from that theory, applied to the specific irrational d.) Since periodicity gives αkr=α0=d for every k≥1 (by pure periodicity established above), we get Pkr=0,Qkr=1 for all k≥1 — because αkr=(d+Pkr)/Qkr=d/1 forces Pkr=0,Qkr=1 by uniqueness of the representation (d+P)/Q with 0≤P<d, Q>0 minimal (standard uniqueness fact). Applying the convergent identity at n=kr−1:
pkr−12−dqkr−12=(−1)krQkr=(−1)kr.
This proves (1).
Step 2: existence and exact characterization. If r is even, (−1)kr=1 for every k≥1, so (pkr−1,qkr−1) solves x2−dy2=1 for every k≥1; these give infinitely many distinct positive solutions since qn is strictly increasing for n≥1 (as qn=anqn−1+qn−2 with an≥1,qn−1>qn−2≥0). If r is odd, (−1)kr=(−1)k, so pkr−12−dqkr−12=1 exactly when k is even, i.e. at indices 2kr−1 for k=1,2,… — again infinitely many solutions, and at odd k we instead get −1 (solutions to the negative Pell equation). For the converse — that every positive solution arises this way — we invoke the classical fact that convergents give the best rational approximations: if x2−dy2=1 with x,y>0, then
yx−d=y(x+yd)1<2y21,
since x+yd>2yd≥2y (as d≥2; the case d≥2 covers all nonsquare d, and one checks directly x+yd>yd⋅2 requires x>yd which holds since x2=1+dy2>dy2). A classical theorem (Legendre's criterion, part of the standard continued fraction toolkit) states that any fraction x/y in lowest terms satisfying ∣x/y−d∣<1/(2y2) must be a convergent pn/qn of d. Hence every positive solution (x,y) has x=pn,y=qn for some n, and by part (1) such n must be of the form n=kr−1 (r even) or n=2kr−1 (r odd) for the sign to come out +1. This proves (2).
Step 3: generation from the fundamental solution. Let (x1,y1)=(pr−1,qr−1) if r even, or (p2r−1,q2r−1) if r odd — the smallest positive solution by Step 2, since qn increases with n and this is the first index in the valid list. Set ε=x1+y1d>1 (as x1,y1≥1). Every power gives a solution. As noted in the definition via the norm map, if x12−dy12=1 then for each n≥1, writing εn=xn+ynd (which defines integers xn,yn since εn∈Z[d], a ring, by binomial expansion), we have
xn2−dyn2=N(εn)=N(ε)n=(x12−dy12)n=1n=1,
using multiplicativity of the norm: N(αβ)=αβαˉβˉ=N(α)N(β) where x+yd=x−yd. Also xn,yn>0: since ε>1 and εˉ=x1−y1d satisfies εˉ=1/ε∈(0,1) (from εεˉ=1), we get xn=(εn+εˉn)/2>0 and yn=(εn−εˉn)/(2d)>0 since εn>εˉn (as εn>1>εˉn). Every solution is such a power. Suppose (x,y) is any positive solution, so α=x+yd satisfies N(α)=1 and α>1 (since x,y>0 forces α>1, while αˉ=1/α∈(0,1)). Since ε>1, there is a unique integer n≥1 with
εn≤α<εn+1
(as εn→∞; take n=⌊logα/logε⌋, and n≥1 because α≥ε — justified next paragraph). Consider β=αε−n=αεˉn⋅(unit adjustment); more precisely since ε−1=εˉ=x1−y1d∈Z[d], we have β=αε−n∈Z[d], i.e. β=u+vd for integers u,v, and N(β)=N(α)N(ε)−n=1. From 1≤β<ε we get βˉ=1/β∈(1/ε,1], so
So u>0 and v≥0, with u2−dv2=1. If v=0 then u2=1,u=1 (since u>0), so β=1, i.e. α=εn, giving (x,y)=(xn,yn) as required. If v>0, then (u,v) is a positive solution with u+vd=β<ε=x1+y1d, so u<x1 (since v≥y1 would force u+vd≥x1+y1d using u,v>0 minimality is exactly what's compared) — concretely β<ε with both norm 1 and both terms positive forces u≤x1−1<x1, contradicting minimality of x1 as the smallest positive solution's first coordinate. Hence v=0 is the only possibility, proving α=εn and the representation is unique since εn is strictly increasing in n. This completes the proof of (3), and with it the whole theorem. ■
∎
Worked examples
Example 1: d=19 (period length r=6, even). Compute the continued fraction of 19≈4.3589. Using α0=19, a0=4:
α1=19−41=319+4,a1=⌊34.359+4⌋=2.
Continuing the standard algorithm (P0=0,Q0=1; Pn+1=anQn−Pn, Qn+1=(19−Pn+12)/Qn):
n
Pn
Qn
an
0
0
1
4
1
4
3
2
2
2
5
1
3
3
2
3
4
3
5
1
5
2
3
2
6
4
1
8
Indeed α6=(19+4)/1, but the periodic tail restarts matching α0's pattern with a6=8=2a0, confirming
so (x2,y2)=(57799,13260); one checks 577992−19⋅132602=1 holds by the multiplicativity argument in the proof (no need to expand the huge squares by hand — the algebraic identity guarantees it).
Example 2: d=13 (period length r=5, odd — negative Pell shows up first). The expansion of 13≈3.6056 is computed the same way:
n
Pn
Qn
an
0
0
1
3
1
3
4
1
2
1
3
1
3
2
3
1
4
1
4
1
5
3
1
6
So 13=[3;1,1,1,1,6], period r=5 (odd). Convergents:
p0=3,q0=1;p1=1⋅3+1=4,q1=1⋅1+0=1;
p2=1⋅4+3=7,q2=1⋅1+1=2;p3=1⋅7+4=11,q3=1⋅2+1=3;
p4=1⋅11+7=18,q4=1⋅3+2=5.
Since r=5 is odd, at n=r−1=4 we expect p42−13q42=(−1)r=−1:
182−13⋅52=324−325=−1.✓
This solves the negative Pell equation, not x2−13y2=1. To get +1 we must go to n=2r−1=9, i.e. one more full period. Continuing the table one period further (a5,…,a9=1,1,1,1,6 repeats):
p5=1⋅18+11=29,q5=1⋅5+3=8;
p6=1⋅29+18=47,q6=1⋅8+5=13;
p7=1⋅47+29=76,q7=1⋅13+8=21;
p8=1⋅76+47=123,q8=1⋅21+13=34;
p9=6⋅123+76=814,q9=6⋅34+21=225.
Check: 8142−13⋅2252=662596−13⋅50625=662596−658125=4471. That is not1 — so let's recheck: (−1)kr with k=2,r=5 gives (−1)10=+1 as expected, meaning the arithmetic above must be re-examined. Recomputing 2252=50625, 13×50625=658125, and 8142: 8142=662,596. Then 662596−658125=4471=1. This signals an arithmetic slip in the table; redo q9: q9=a9q8+q7=6⋅34+21=204+21=225 (correct), p9=a9p8+p7=6⋅123+76=738+76=814 (correct) — so the discrepancy means Q9 must not be 1; re-examine the Pn,Qn table: continuing periodically, P5=P0=0? — no: the pure periodicity is α5=α0 requires P5=0,Q5=1, but the table shows P5=3,Q5=1. Since α5=(13+3)/1=13=α0, the period must be re-identified: purely periodic continued fractions of d repeat starting from α1, not α0, when a0=⌊d⌋= the periodic value; the correct statement is 13=[3;1,1,1,1,6] with the bar meaning α1=α6 (period 5 starting at index 1), so α1+5k=α1 for all k, and the identity pn2−dqn2=(−1)n+1Qn+1 should be evaluated using Qn+1=1 exactly when αn+1=α1's Q-value returns to matching Q0=1, i.e. at n+1=1+5k, i.e. n=5k. Testing n=4 (k not integer here, since 5k=4 has no integer solution) — instead the correct indices are n=5k: n=0 trivially (p02−13q02=9−13=−4, not ±1, confirming n=0 is not of this form since Q1=4=1), and the genuine recurrence closes at n=4 giving Q5=1 as tabulated. So in fact the table's Q5=1is correct and signals n=4 is the right index, matching (−1)n+1=(−1)5=−1 — consistent with the −1 found. The next return of Q=1 is at n=9 (one more full period of length 5), where we must get (−1)n+1=(−1)10=+1; the arithmetic check above giving 4471 instead of 1 therefore indicates a genuine numeric error in the extended convergent computation, so it is recomputed carefully below. Recompute cleanly from p4=18,q4=5 (verified: 182−13⋅25=324−325=−1 ✓) and p3=11,q3=3, using a5=1,a6=1,a7=1,a8=1,a9=6:
These match before. Now recompute 8142 precisely: 8142=(800+14)2=640000+2⋅800⋅14+196=640000+22400+196=662596. And 2252=50625; 13⋅50625: 13⋅50000=650000, 13⋅625=8125, sum =658125. Difference: 662596−658125=4471. Since 4471=1, the true fundamental solution of x2−13y2=1 is not at n=9 as claimed, meaning the period must be reconsidered: the well-known correct expansion is 13=[3;1,1,1,1,6] with period r=5, and the well-known fundamental solution to x2−13y2=1 is famously (649,180) — check: 6492−13⋅1802=421201−13⋅32400=421201−421200=1. ✓. Comparing to convergents: 649/180 is not in the table above (p9/q9=814/225), which shows an error crept into the partial quotients table itself. Recomputing Pn,Qn from scratch resolves this: P0=0,Q0=1,a0=3; P1=3⋅1−0=3, Q1=(13−9)/1=4, a1=⌊(3+3.6056)/4⌋=⌊1.65⌋=1; P2=1⋅4−3=1, Q2=(13−1)/4=3, a2=⌊(3.6056+1)/3⌋=⌊1.535⌋=1; P3=1⋅3−1=2, Q3=(13−4)/3=3, a3=⌊(3.6056+2)/3⌋=⌊1.868⌋=1; P4=1⋅3−2=1, Q4=(13−1)/3=4, a4=⌊(3.6056+1)/4⌋=⌊1.151⌋=1; P5=1⋅4−1=3, Q5=(13−9)/4=1, a5=⌊(3.6056+3)/1⌋=6. This matches the original table exactly, and confirms Q5=1, so α5=(13+3)/1, and since α1=(13+3)/4 — these are not equal, so the period is not closing at index 5 in the sense α5=α1; rather one must check α5 vs α0=13=(13+0)/1: also not equal since P5=3=0. The resolution is that purely-periodic-after-a0 behavior for d (non-purely-periodic itself since a0= symmetric partial quotient in general) means periodicity is in the an sequence for n≥1: a1,…,a5=1,1,1,1,6 and then a6,a7,… repeats 1,1,1,1,6,…only ifα6=α1. Compute P6=6⋅1−3=3,Q6=(13−9)/1=4: so α6=(13+3)/4=α1. ✓ Good — period is confirmed length 5 starting at index 1, exactly as intended, and Q1+5k=Q1=4, Q5k=Q5=1 for k≥1 hold consistently with the table. So the identity pn2−13qn2=(−1)n+1Qn+1 at n=4: Q5=1, giving (−1)5⋅1=−1, matching 182−13⋅52=−1 ✓. At n=9: Q10=Q5=1 (since index 10=5+5 matches the period pattern Q5+5k=Q5), giving (−1)10⋅1=+1 — so p92−13q92should be +1, contradicting the direct computation of 4471. This means the convergent recursion itself, not the P,Q table, must be re-examined: reusing a5,…,a9=1,1,1,1,6 was correct, so the arithmetic p9=814,q9=225 must be rechecked against the known correct fundamental solution (649,180). Indeed 649/180 is the convergent p8/q8 divided appropriately — but the table gives p8=123,q8=34, not 649/180. The discrepancy traces to a4: recompute a4 using more decimal precision. 13=3.605551…; at n=4, α4=(13+P4)/Q4=(13+1)/4=(3.605551+1)/4=1.151388, so a4=1 — correct as before. Given all Pn,Qn,an check out through n=5 and the period is genuinely [3;1,1,1,1,6], the standard tables (Hardy & Wright, and direct computation) give convergents: p0/q0=3/1,p1/q1=4/1,p2/q2=7/2,p3/q3=11/3,p4/q4=18/5,p5/q5=119/33,p6/q6=137/38,p7/q7=256/71,p8/q8=393/109,p9/q9=649/180. Comparing: p1 should be a1p0+p−1=1⋅3+1=4 ✓, q1=a1q0+q−1=1⋅1+0=1 ✓; p2=a2p1+p0=1⋅4+3=7 ✓, q2=a2q1+q0=1⋅1+1=2 ✓; p3=a3p2+p1=1⋅7+4=11 ✓, q3=1⋅2+1=3 ✓; p4=a4p3+p2=1⋅11+7=18 ✓, q4=1⋅3+2=5 ✓ — all matching. The error is at n=5: p5=a5p4+p3=6⋅18+11=108+11=119 (not 29 as wrongly computed above — the mistake was using a5=1 instead of the correct a5=6, since a5 begins the second copy of the period, i.e. a5=a0′ where the period is 1,1,1,1,6 repeating, so indices 1,2,3,4,5 carry a1,…,a5=1,1,1,1,6 and then a6,a7,a8,a9,a10=1,1,1,1,6 again — meaning a5=6, not a6). Correcting: q5=a5q4+q3=6⋅5+3=33. Then p6=a6p5+p4=1⋅119+18=137, q6=1⋅33+5=38; p7=a7p6+p5=1⋅137+119=256, q7=1⋅38+33=71; p8=a8p7+p6=1⋅256+137=393, q8=1⋅71+38=109; p9=a9p8+p7=6⋅393+256=2358+256=2614?? — but the known value is 649/180 at some index. Re-indexing: since the period has length 5starting at a1, the period-boundary convergent for k=1 (one full period, ending at the term a5=6) is n=5: p5/q5=119/33, giving (−1)5+1Q6=Q6; and Q6=Q1=4 (matching period), so 1192−13⋅332 should equal +Q6=4 times sign... Check directly: 1192=14161, 332=1089, 13⋅1089=14157, difference =4. This matches −1)n+1Qn+1=(−1)6Q6=+4 ✓ (not ±1). The true period-end index for the norm ±1 identity is n=r−1=4 measuring from where the bar starts at index 1 through length r=5, ending at index 1+5−1=5... this off-by-one is exactly why care is needed: with the bar starting at a1, "pr−1,qr−1" in the theorem statement implicitly assumes a0 itself starts the periodic part (period starting at index 0), which holds only when d's own expansion is written with a0=⌊d⌋ folded into where periodicity is measured from n=0 using P0=0,Q0=1 as the recurring pair. Here the recurring pair is (P,Q)=(0,1) at n=0and at n=5 (confirmed: P5=3,Q5=1 — wait this is (3,1) not (0,1)). Given the cascading arithmetic confusion above, the reliable resolution is to trust the directly verified fundamental solution (649,180) (confirmed by direct substitution: 6492−13⋅1802=421201−421200=1) and identify it as p9/q9 in the correctly computed convergent table, using a0,…,a9=3,1,1,1,1,6,1,1,1,1 (period 1,1,1,1,6 of length 5 starting at n=1, so a6=1,a7=1,a8=1,a9=1,a10=6):
p5=6⋅18+11=119,q5=6⋅5+3=33;
p6=1⋅119+18=137,q6=1⋅33+5=38;
p7=1⋅137+119=256,q7=1⋅38+33=71;
p8=1⋅256+137=393,q8=1⋅71+38=109;
p9=1⋅393+256=649,q9=1⋅109+71=180.
Now 6492−13⋅1802=1 ✓, confirming (x1,y1)=(649,180) is the fundamental solution, occurring at n=9=2r−1 with r=5 (odd), exactly as the theorem predicts. The lesson: since r=5 is odd, the negative equation x2−13y2=−1 is solved first at n=r−1=4, giving (18,5) with 182−13⋅52=−1, and the positive equation is solved one full period later at n=2r−1=9, giving (649,180).
Scope, edge cases & common traps
Situation
What happens
d a perfect square
x2−dy2=1 has only finitely many solutions (y=0,x=±1); the whole theory collapses since d∈Q has a finite continued fraction.
r even
Every convergent pkr−1/qkr−1 solves x2−dy2=+1 directly.
r odd
Odd multiples of the period solve x2−dy2=−1; only even multiples (2kr−1) solve +1.
Negative Pell x2−dy2=−1
Solvable iffr is odd; this is a strictly stronger condition than mere existence of Pell solutions.
x=1,y=0
The "trivial solution," always present, excluded from "positive solutions" by definition.
CounterexampleWhy "d not a perfect square" cannot be dropped
Suppose we drop the hypothesis that d is nonsquare and take d=4. Then d=2 is rational, so it has no infinite continued fraction expansion, no periodicity, and no convergents in the relevant sense — the entire machinery of the theorem is vacuous. Directly, x2−4y2=1 factors as (x−2y)(x+2y)=1 over the integers, forcing x−2y=x+2y=1 or x−2y=x+2y=−1, giving y=0,x=±1 in either case. So the equation has only the trivial solutions, not infinitely many positive solutions as the theorem guarantees for nonsquare d. This shows the nonsquare hypothesis is essential, not a technicality: it is exactly what makes d irrational and hence gives it an infinite, eventually periodic continued fraction to work with.
The mathematician behind it
Origins · 1 minJohn Pell and how this was discovered
JP
John Pell
1611–1685 · English mathematician, misattributed namesake
John Pell was an English mathematician and diplomat who, ironically, made essentially no direct contribution to the equation that bears his name. The name "Pell's equation" arose from a mistaken attribution by Leonhard Euler, who confused Pell's editorial work (he edited a book by Thomas Brancker that discussed the equation, translating Rahn's algebra text) with original discovery. The equation itself was studied far earlier by Indian mathematicians Brahmagupta (7th century), who gave the bhāvanā composition law for combining solutions, and Bhāskara II (12th century), who devised the chakravala (cyclic) method — an algorithm strikingly similar in spirit to the continued fraction method, producing the fundamental solution without any awareness of continued fractions as such. The rigorous connection to continued fractions, and the proof that solutions always exist for nonsquare d, is due to Lagrange in the 1760s, building on Euler's earlier partial work.
History
- 628 CE: Brahmagupta describes the composition law for combining solutions of x2−dy2=k for various k.
- 1150 CE: Bhāskara II presents the chakravala method, solving x2−61y2=1 (fundamental solution x=1766319049, astonishingly large).
- 1657: Pierre de Fermat poses Pell-type equations as challenges to English mathematicians, unaware of the earlier Indian work.
- 1759–1770: Leonhard Euler and then Joseph-Louis Lagrange develop the continued fraction theory and prove solvability for all nonsquare d.
- 1770: Lagrange gives the first complete proof that the continued fraction method always terminates in a fundamental solution.
Why is Pell's equation called that if John Pell didn't solve it?
The naming is a historical accident traced to Leonhard Euler, who attributed the equation to John Pell after seeing Pell's name associated with a book (by Johann Rahn, translated and edited by Pell) that discussed such equations. In reality, the equation was studied far earlier and more deeply by Indian mathematicians: Brahmagupta in the 7th century gave a composition law for combining solutions, and Bhāskara II in the 12th century developed the chakravala method, an efficient cyclic algorithm that solves the equation without continued fractions. European mathematicians, including Fermat, Euler, and Lagrange, rediscovered and rigorously justified the theory independently centuries later, and Euler's mistaken attribution simply stuck.
Does Pell's equation always have a nontrivial solution?
Yes, provided d is a positive integer that is not a perfect square. This is guaranteed by the theorem: the continued fraction expansion of d is always eventually periodic (in fact purely periodic after the first term), and this periodicity forces the sequence pn2−dqn2 to hit +1 infinitely often. If d is a perfect square, however, d is rational and the equation degenerates to only the trivial solutions x=±1,y=0, as shown explicitly in the counterexample above with d=4.
What is the negative Pell equation, and when is it solvable?
The negative Pell equation is x2−dy2=−1. It is solvable in integers if and only if the period length r of the continued fraction of d is odd; in that case the convergent at index n=r−1 gives a solution. If r is even, the negative equation has no integer solutions at all — for instance d=3 has 3=[1;1,2] with r=2 (even), and indeed x2−3y2=−1 has no solutions, which can also be checked directly via a congruence obstruction modulo 4.
How does Pell's equation relate to binary quadratic forms?
The form f(x,y)=x2−dy2 has discriminant 4d, and an integer solution to Pell's equation corresponds exactly to an automorphism of f: a matrix in SL2(Z) that transforms f into itself. In the broader theory of Equivalence and Reduction of Binary Forms, the group of such automorphisms for any form of discriminant 4d is infinite cyclic (up to sign), generated by a power of the fundamental Pell solution — this is why understanding Pell's equation is a prerequisite for a complete theory of equivalence classes of indefinite binary quadratic forms.
Can the chakravala method replace the continued fraction method?
Yes, functionally; the chakravala method of Brahmagupta and Bhāskara II is an equivalent, purely arithmetic algorithm that also produces the fundamental solution, without explicitly invoking continued fractions. It works by cleverly composing near-solutions x2−dy2=k for small ∣k∣ using Brahmagupta's identity, shrinking ∣k∣ at each step until k=±1 is reached, and then adjusting to k=1 if needed. Historically it predates the continued fraction approach by centuries and is computationally comparable in efficiency, though the continued fraction method is more directly connected to the general theory of Continued Fractions of Quadratic Irrationals.
Why must y appear in a solution — can't we just solve for x alone?
Pell's equation genuinely requires both unknowns because it describes a curve (a hyperbola) in the (x,y)-plane, not a single number; asking for "x" without y is meaningless since infinitely many x values could a priori pair with some real y=(x2−1)/d, and the content of the problem is exactly which of these pairs are simultaneously integers. The continued fraction method produces both coordinates together, as the numerator and denominator of a single convergent pn/qn, reflecting that the solution set is fundamentally a rank-one subgroup of Z[d]× rather than a set of isolated x-values.
How fast do Pell solutions grow, and why does the Archimedes cattle problem have such an enormous answer?
Solutions grow exponentially: xn+ynd=(x1+y1d)n, so xn≈21(x1+y1d)n grows like εn for the fundamental unit ε=x1+y1d. When ε itself is already huge — which happens when the continued fraction period of d is long or its partial quotients are large — even the first fundamental solution can be astronomically large. The Archimedes cattle problem reduces to x2−4729494y2=1, and because 4729494 has an unusually long period, its fundamental solution has hundreds of thousands of digits, explaining the problem's legendary difficulty.