Number

One solution that makes all the others

The equation x² − 2y² = 1 has infinitely many whole-number solutions, and every one of them is a power of the smallest. The multiplication that produces them is what multiplying two numbers of the form a + b√2 comes to when the √2 terms are collected — so an equation about a hyperbola turns out to carry a group.

Worth reading first: A fraction that never closes · The square that cannot shrink.

Find whole numbers xx and yy with x22y2=1x^2 - 2y^2 = 1. There is the trivial answer x=1x = 1, y=0y = 0, and after a little searching there is 32222=98=13^2 - 2\cdot 2^2 = 9 - 8 = 1.

That second solution is worth more than it looks, because it manufactures the rest.

Whole-number points on x² − 2y² = 1. The branch of the hyperbola x² − 2y² = 1 in the first quadrant, with the whole-number points on it marked and labelled, and the lattice drawn faintly behind.
Fig. 1 The branch of x22y2=1x^2 - 2y^2 = 1 in the first quadrant, with its whole-number points marked and the lattice drawn faintly behind. After (3,2)(3,2) come (17,12)(17,12) and (99,70)(99,70), and every solution with yy up to 70 is one of these — checked by trying every yy, not by trusting the pattern.

The multiplication

Take two solutions (x,y)(x, y) and (x,y)(x', y') and combine them by

(x,y)(x,y)=(xx+2yy,  xy+xy).(x, y) \cdot (x', y') = (xx' + 2yy',\; xy' + x'y).

That looks arbitrary until it is read the right way. Consider x+y2x + y\sqrt 2 and x+y2x' + y'\sqrt 2, and multiply them:

(x+y2)(x+y2)=xx+2yy+(xy+xy)2.(x + y\sqrt2)(x' + y'\sqrt2) = xx' + 2yy' + (xy' + x'y)\sqrt2.

The rule is ordinary multiplication of numbers of the form a+b2a + b\sqrt 2, with the 2\sqrt2 terms collected. And the equation x22y2=1x^2 - 2y^2 = 1 says exactly that (x+y2)(xy2)=1(x + y\sqrt2)(x - y\sqrt2) = 1 — so a solution is a number of that form whose product with its conjugate is one.

Products of such numbers are again such numbers, and conjugation respects multiplication, so the product of two solutions is a solution. That is the whole verification, and it is why the multiplication is not arbitrary: it is the only multiplication there was.

Applying it repeatedly to (3,2)(3,2) gives (17,12)(17,12), then (99,70)(99,70), then (577,408)(577, 408), each one 3+223 + 2\sqrt2 raised to a higher power. The solutions form a group, generated by one element together with the sign changes, and the theorem is that there are no others.

Whole-number points on x² − 3y² = 1. The branch of the hyperbola x² − 3y² = 1 in the first quadrant, with the whole-number points on it marked and labelled, and the lattice drawn faintly behind.
Fig. 2 x23y2=1x^2 - 3y^2 = 1, whose smallest non-trivial solution is (2,1)(2,1) — smaller than for D=2D = 2, and the powers (7,4)(7,4) and (26,15)(26,15) arrive correspondingly sooner. The size of the first solution has no relation to the size of DD, which is the equation’s most striking behaviour.

Why there are infinitely many

The existence of one non-trivial solution is the hard part, and the standard proof is a pigeonhole argument that will already be familiar.

How close a fraction can get proves Dirichlet’s theorem: for any irrational α\alpha there are infinitely many fractions p/qp/q with αp/q<1/q2|\alpha - p/q| < 1/q^2. Apply it to D\sqrt D. Then pqD<1/q|p - q\sqrt D| < 1/q, and multiplying by p+qD<2qD+1|p + q\sqrt D| < 2q\sqrt D + 1 gives

p2Dq2<2D+1.|p^2 - Dq^2| < 2\sqrt D + 1.

So infinitely many pairs (p,q)(p,q) give a value of p2Dq2p^2 - Dq^2 inside a fixed bounded range. Only finitely many whole numbers are in that range, so some value kk is hit infinitely often — pigeonhole again. Among those infinitely many pairs, two agree in both pmodkp \bmod k and qmodkq \bmod k, and dividing one by the other in the D\sqrt D sense produces a solution with kk cancelled: a genuine solution of x2Dy2=1x^2 - Dy^2 = 1.

Every step is a counting argument and none of them exhibits anything. The proof establishes that a solution exists without giving the least hint of how large it is — which turns out to be the honest state of affairs, because the size is wild.

Finding the smallest one

Searching for the fundamental solution by trying every yy works and stops working quickly. There is a better route, and it goes through the continued fraction of D\sqrt D.

The continued fraction of √2, and the convergent that solves Pell. A table of the continued-fraction terms of √2 with each convergent and the value of p² − 2q² at it, so the convergent solving the equation can be picked out.
Fig. 3 The continued fraction of 2\sqrt 2, which is [1;2,2,2,][1; 2, 2, 2, \dots] with period 1, and the value of p22q2p^2 - 2q^2 at each convergent. The values alternate between 1-1 and 11, and the first to give 1 is 3/23/2 — the fundamental solution, arrived at by a route that never mentions the equation.

The connection is a theorem: every solution of x2Dy2=1x^2 - Dy^2 = 1 has x/yx/y a convergent of the continued fraction of D\sqrt D. The reason is that a solution makes x/yx/y an extremely good rational approximation to D\sqrt D — from x2Dy2=1x^2 - Dy^2 = 1,

xyD=1y2(xy+D)<12y2,\left|\frac{x}{y} - \sqrt D\right| = \frac{1}{y^2\left(\frac{x}{y} + \sqrt D\right)} < \frac{1}{2y^2},

and a rational within 1/2y21/2y^2 of a number is one of its convergents. So the search can run down the convergents instead of down the whole numbers, and there are far fewer of them.

Which convergent it is depends on the period of the expansion. The continued fraction of D\sqrt D is always eventually periodic — that is Lagrange’s theorem, and it holds for every quadratic irrational — and the fundamental solution appears at the end of the first or the second period, according as the period is even or odd.

The continued fraction of √7, and the convergent that solves Pell. A table of the continued-fraction terms of √7 with each convergent and the value of p² − 7q² at it, so the convergent solving the equation can be picked out.
Fig. 4 7=[2;1,1,1,4,]\sqrt 7 = [2; 1, 1, 1, 4, \dots] with period 4. The values of p27q2p^2 - 7q^2 run 3,2,3,1-3, 2, -3, 1 and then repeat, so the fundamental solution 8/38/3 arrives at the end of the first period. Every convergent stays within 27+12\sqrt 7 + 1 of the hyperbola, which is the bound the pigeonhole proof needed.

How large the first solution can be

For D=2D = 2 the answer is (3,2)(3, 2). For D=3D = 3 it is (2,1)(2,1). For D=13D = 13 it is (649,180)(649, 180).

The continued fraction of √13, and the convergent that solves Pell. A table of the continued-fraction terms of √13 with each convergent and the value of p² − 13q² at it, so the convergent solving the equation can be picked out.
Fig. 5 13=[3;1,1,1,1,6,]\sqrt{13} = [3; 1, 1, 1, 1, 6, \dots] with period 5 — odd, so the first period ends at p213q2=1p^2 - 13q^2 = -1 rather than +1+1, and the equation is not solved until the second period closes at 649/180649/180. The convergents’ values run 4,3,3,4,1-4, 3, -3, 4, -1 and repeat with the sign reversed.

For D=61D = 61 the fundamental solution is

17663190492612261539802=1,1\,766\,319\,049^2 - 61 \cdot 226\,153\,980^2 = 1,

which is why the equation is not a small thing to solve by search. There is no formula for the size, it does not grow with DD in any regular way — D=60D = 60 has the solution (31,4)(31, 4) — and the record-holders for size are related to the class numbers of quadratic fields, which are themselves famously irregular.

Fermat posed the D=61D = 61 case as a challenge to English mathematicians in 1657, and it is generally agreed that he chose 61 precisely because the answer is large. Brouncker and Wallis found it; whether they had a general method or a great deal of persistence was disputed at the time.

The same picture, as a motion of the plane

There is a geometric reading of the multiplication that explains why the solutions thin out the way they do.

The map (x,y)(3x+4y,  2x+3y)(x,y) \mapsto (3x + 4y,\; 2x + 3y) — which is multiplication by (3,2)(3,2) written out — is a linear map of the plane. It has determinant 98=19 - 8 = 1, so it preserves area, and it carries the hyperbola x22y2=1x^2 - 2y^2 = 1 to itself, because it carries solutions to solutions and the same algebra works for non-whole xx and yy.

A linear map preserving a hyperbola and area is a shear along the hyperbola: it slides every point along the curve, by a fixed amount of hyperbolic angle. So the solutions are the orbit of (1,0)(1,0) under a rigid sliding, equally spaced in the hyperbola’s own natural parameter — and unequally spaced, exponentially, in ordinary coordinates.

That is why the picture looks the way it does. The points are evenly distributed by the curve’s own measure, and the curve’s own measure runs off to infinity logarithmically, so a drawing in xx and yy crushes the early points together and pushes the later ones off the page.

Whole-number points on x² − 5y² = 1. The branch of the hyperbola x² − 5y² = 1 in the first quadrant, with the whole-number points on it marked and labelled, and the lattice drawn faintly behind.
Fig. 6 x25y2=1x^2 - 5y^2 = 1, whose smallest solution is (9,4)(9,4) and whose next is already (161,72)(161,72). The multiplier here is 9+4517.99 + 4\sqrt5 \approx 17.9, three times the multiplier for D=2D = 2, so two points are all that fit before the third is a hundred times further out.

The same reading gives the group structure for nothing. The solutions are the orbit of one point under a map, and the maps form a group under composition isomorphic to the whole numbers, so the solutions are indexed by the whole numbers — which is the theorem that every solution is a power of the fundamental one, stated as a fact about a group action.

Asking for a different constant

Replace 1 on the right by another whole number NN and the question changes character. x22y2=7x^2 - 2y^2 = 7 has solutions (3,1)(3,1) and (5,3)(5,3); x22y2=5x^2 - 2y^2 = 5 has none; x22y2=1x^2 - 2y^2 = -1 has (1,1)(1,1).

Two things happen at once. First, solutions may not exist, and the obstruction is often a congruence: modulo 8, x22y2x^2 - 2y^2 can be 0, 1, 2, 4, 6 or 7 but never 5, so N=5N = 5 is impossible without any search. Second, when solutions do exist they come in several families rather than one, each family being the orbit of one solution under multiplication by the fundamental unit.

So the general problem has two halves: decide whether any solution exists, and find one representative of each family. The first is a finite check modulo a suitable number together with a bound; the second is a finite search, because every family has a representative with yy below a bound depending on NN and the fundamental solution.

√2 as a continued fraction. The nested fraction, one quotient per step, descending to the right.
Fig. 7 2\sqrt2 drawn as the nested fraction it is: one plus one over two plus one over two, for ever. The self-similarity is exact — the tail is the whole thing again — which is why the expansion has period 1, and periodicity of the expansion is what makes Pell’s equation solvable at all.

That the expansion of 2\sqrt2 repeats immediately is the reason its fundamental solution is small. The period is the number of convergents that must be walked before the value p2Dq2p^2 - Dq^2 returns to ±1\pm1, and a long period means a long walk and correspondingly enormous numerators. 61\sqrt{61} has period 11, and its fundamental solution has ten digits.

What the solutions are, in another language

The set {a+bD:a,b whole}\{a + b\sqrt D : a, b \text{ whole}\} is closed under addition and multiplication, and a solution of Pell’s equation is an element of it whose product with its conjugate is 1 — a unit, in the language of rings: an element with a multiplicative inverse inside the set.

Read that way, the theorem that all solutions are powers of one becomes a statement about the structure of the unit group: it is infinite cyclic, together with ±1\pm 1. Dirichlet proved a far more general version — for the integers of any number field, the units form a finitely generated group whose rank is determined by how many real and complex embeddings the field has — and Pell’s equation is the simplest non-trivial case of it.

That is the reason the equation survived being solved. It is not interesting because hyperbolas have lattice points on them; it is interesting because it is the visible face of a structure that appears throughout algebraic number theory, and the fundamental solution is a fundamental unit, a quantity that shows up in class number formulas and regulators.

Every fraction exactly once builds the tree that the convergents walk down, and One way to factor, and no other sets out unique factorisation for whole numbers. In rings like Z[D]\mathbb{Z}[\sqrt D] that property often fails, and the units are one of the two things that have to be understood before anything can be said about factorisation at all — the other being the class group.

The negative equation, which sometimes has no solutions

Ask instead for x2Dy2=1x^2 - Dy^2 = -1. For D=2D = 2 there is (1,1)(1,1); for D=13D = 13 there is (18,5)(18, 5); for D=3D = 3 there is nothing at all.

The obstruction is visible modulo 4. If x23y2=1x^2 - 3y^2 = -1 then x2+13y2x^2 + 1 \equiv 3y^2, and squares are 0 or 1 mod 4, so the left side is 1 or 2 and the right is 0 or 3. No solution, and none needs to be searched for.

More generally the negative equation is solvable exactly when the continued fraction of D\sqrt D has odd period — which is the pattern visible in the two tables above: 2\sqrt 2 has period 1 and its convergents hit 1-1; 7\sqrt 7 has period 4 and they never do. Deciding which DD have odd period is not elementary and is still not fully understood; the density of such DD among those with no obvious obstruction was conjectured by Stevenhagen and proved only in 2022.

So the positive equation always has solutions and the negative one sometimes does, and the difference between “always” and “sometimes” is one of the places where this corner of number theory stops being tidy.

Where the name came from, and why it is wrong

The equation is not Pell’s. John Pell had nothing to do with it; Euler attributed it to him in 1730 through a misreading of a book by Wallis, where Pell’s name appears in connection with a different method, and the misattribution stuck.

The genuine history runs the other way round the world. Brahmagupta solved cases in 628 and stated the composition identity — the multiplication above — in general, calling it samasa. Bhāskara II gave a complete method, the chakravala, in 1150, which finds the fundamental solution for D=61D = 61 in a handful of steps and is more efficient than the continued-fraction method Europeans arrived at six centuries later. Lagrange gave the first proof that a solution always exists, in 1768.

The chakravala’s key idea is worth stating because it is not the obvious one: rather than working only with solutions of x2Dy2=1x^2 - Dy^2 = 1, it works with solutions of x2Dy2=kx^2 - Dy^2 = k for small kk and composes them, dividing out kk when it can. Allowing the intermediate steps to miss the target is what makes the method fast, and it is exactly the move the pigeonhole proof makes as well.

What the pictures cannot show

The hyperbola figures draw three or four solutions and the fourth is already off the useful part of the page — the points thin out exponentially, since each is about (3+22)5.83(3+2\sqrt2) \approx 5.83 times the last for D=2D = 2. Any drawing showing five solutions at once shows the first four crushed against the origin.

The exhaustive check that no solution has been missed runs up to the largest yy drawn, so it is a genuine check over a finite range and not a proof. The theorem that every solution is a power of the fundamental one is quoted rather than established here.

And the convergent tables stop after eight or eleven terms. The continued fraction of D\sqrt D is infinite and periodic; a table shows one or two periods and asserts that the state has repeated, which is what the periodicity claim rests on — the recurrence’s state is a pair of whole numbers, and a repeated state means everything after repeats too.

The ladder from here

Below: a fraction that never closes, which builds continued fractions and their convergents, and the square that cannot shrink, which is why 2\sqrt 2 is irrational and the expansion never terminates. Sideways: how close a fraction can get, the approximation theorem the existence proof runs on; two squares and a lattice, a different equation whose solutions are read off a lattice; and a tree that holds every triple, where the solutions of another equation are generated from one by a rule. Above: the chakravala method, Lagrange’s theorem on periodic continued fractions, Dirichlet’s unit theorem, and the connection between fundamental units and class numbers.

What is worth carrying away

An equation with infinitely many solutions is usually described by a parametrisation. This one is described by a generator: one solution, and a rule for combining solutions, and everything follows.

The rule was not invented for the purpose. It is multiplication in Z[D]\mathbb{Z}[\sqrt D], which was already there, and the equation is the condition for an element to be invertible. When a set of solutions turns out to be closed under an operation, the operation was almost never designed for them — it was already present in whatever the solutions really are, and finding it is the same as finding out what they really are.