The equation x2−dy2=1, whose integer solutions connect to continued fractions.
IntuitionIntuition: integer points on a hyperbola that approximate d
Look for integers x,y with x2−2y2=1. Trying small values: (x,y)=(3,2) works, since 9−8=1. Rearranging, (yx)2=2+y21, so x/y=3/2=1.5 is already a startlingly good approximation to 2≈1.41421. Equations of the form x2−dy2=1 — called Pell's equation — turn out to be inseparable from the theory of continued fractions and best rational approximations.
A path graph of continued fraction convergents with one node highlighted as the fundamental solution of the Pell equation.
The continued-fraction convergents of d drawn as a path graph: each node is a convergent pk/qk, and the highlighted node is the fundamental solution.
AdvancedDefinition, fundamental solution, and structure
Definition: Pell's equation and fundamental solution
For a positive integer d that is not a perfect square, x2−dy2=1 is called Pell's equation. Among its positive integer solutions (x,y), the one with smallest x (equivalently smallest y) is the fundamental solution(x1,y1).
x2−dy2=1,d∈Z>0not a perfect square
Factoring the left side as (x−yd)(x+yd)=1 turns Pell's equation into a statement about the ring Z[d]: solutions correspond to elements of norm 1, and multiplying two such elements gives another. In particular, once we know (x1,y1), every further solution is obtained by taking powers: xn+ynd=(x1+y1d)n.
For every positive integer d that is not a perfect square, x2−dy2=1 has a solution with x,y positive integers.
Why is it true?
It is not obvious at all that a hyperbola x2−dy2=1, which certainly has real points, must pass through a lattice point — this theorem guarantees it always does, for every non-square d, via a clever pigeonhole argument on rational approximations.
Proof
By Dirichlet's approximation theorem, for any integer Q>0 there exist integers p,q with 1≤q≤Q and d−qp<qQ1. Letting Q→∞ produces infinitely many pairs (p,q) with d−qp<q21.
For each such pair, ∣p−qd∣<q1, so ∣p2−dq2∣=∣p−qd∣⋅∣p+qd∣<q1(2qd+q1)<2d+1. Thus p2−dq2 takes one of only finitely many integer values in (−2d−1,2d+1), while there are infinitely many pairs (p,q).
By the pigeonhole principle, some fixed nonzero integer k in that finite range satisfies p2−dq2=k for infinitely many pairs (p,q). Among these infinitely many pairs, again by pigeonhole, infinitely many share the same residues p≡p0,q≡q0(mod∣k∣).
Take two distinct such pairs (p1,q1)=(p2,q2) with p12−dq12=p22−dq22=k and matching residues mod ∣k∣. Set x+yd=k(p1+q1d)(p2−q2d); expanding shows x=kp1p2−dq1q2 and y=kp1q2−p2q1 are honest integers precisely because of the matching residues mod ∣k∣, and multiplicativity of the norm N(a+bd)=a2−db2 gives x2−dy2=k2k⋅k=1. Since (p1,q1)=(p2,q2) but they give the same ratio in the limit, one checks y=0, and replacing (x,y) by (∣x∣,∣y∣) (still a solution, since only squares appear) gives a solution in positive integers.
If (x1,y1) is the fundamental solution of x2−dy2=1, then every solution in positive integers (x,y) equals (xn,yn) for some n≥1, where xn+ynd=(x1+y1d)n.
Why is it true?
It says the infinitely many solutions are not a mysterious scattered set but a completely predictable geometric-like sequence generated by repeatedly "multiplying" the smallest one — reducing an infinite search to finding just one number.
Proof
First check (xn,yn) defined by xn+ynd=(x1+y1d)n is indeed a solution for every n: taking conjugates, xn−ynd=(x1−y1d)n, so xn2−dyn2=(xn+ynd)(xn−ynd)=[(x1+y1d)(x1−y1d)]n=(x12−dy12)n=1n=1.
Now suppose (x,y) is any positive integer solution not of this form; since xn→∞ as n→∞, there is a unique n with xn+ynd≤x+yd<xn+1+yn+1d=(xn+ynd)(x1+y1d).
Divide through by (xn+ynd), i.e. multiply by its inverse (xn−ynd) (valid since xn2−dyn2=1): set x′+y′d=(x+yd)(xn−ynd). Then 1≤x′+y′d<x1+y1d, and x′2−dy′2=(x2−dy2)(xn2−dyn2)=1⋅1=1, so (x′,y′) is also a solution of Pell's equation.
A short computation using x′+y′d≥1 and x′2−dy′2=1 shows x′≥1 and y′≥0 (a solution with x′+y′d≥1 but y′<0 would force x′>x1, contradicting x′+y′d<x1+y1d combined with the norm equation). If y′>0, then (x′,y′) is a positive solution with x′+y′d<x1+y1d, contradicting minimality of the fundamental solution. So y′=0, forcing x′=1, i.e. x+yd=xn+ynd, so (x,y)=(xn,yn) after all — contradicting our assumption.
Hence every positive solution is exactly some (xn,yn), proving the fundamental solution generates the entire solution set.
AdvancedReal-World Applications and Worked Examples
Pell's equation is far more than a puzzle: it governs the best rational approximations used in mechanical gear design, its arithmetic underlies classical integer-factorization algorithms, and computing its fundamental solution for large d is exactly the computational problem that Hallgren's quantum algorithm solves in polynomial time — with no known efficient classical method.
Example: Finding the fundamental solution for d=2
Use the continued fraction of 2 to find the fundamental solution of x2−2y2=1, then generate the next solution.
Solution
The continued fraction of 2 is [1;2]=1+2+2+⋯11, with convergents 1,23,57,1217,2941,…
Checking the convergent 23: 32−2⋅22=9−8=1. This is the smallest convergent that works, so the fundamental solution is (x1,y1)=(3,2).
Using the recursion xn+ynd=(x1+y1d)n with n=2: x2+y22=(3+22)2=9+122+8=17+122, so (x2,y2)=(17,12).
Verify: 172−2⋅122=289−288=1, confirming the next solution, which matches the convergent 1217 found above — exactly as the theory predicts.
Example: Engineering approximation: designing a gear ratio close to 2
A mechanism needs two meshed gears whose tooth-count ratio approximates 2 as closely as possible using small integer tooth counts, so the error stays tiny after many rotations. Use the Pell equation convergents to choose the tooth counts and bound the error.
Solution
From the fundamental solution (3,2) of x2−2y2=1, the ratio 3/2=1.5 gives ∣3/2−2∣≈0.0858 — usable, but coarse for precision machinery.
Using the next convergent from (17,12) (found by squaring 3+22): a gear pair with 17 and 12 teeth gives ratio 17/12≈1.41667, and ∣17/12−2∣≈0.00245, nearly 35 times more accurate than the 3/2 design for only modestly larger tooth counts.
The general bound for any convergent pk/qk of a continued fraction is qkpk−2<qk21, so as engineers move to the next Pell solution (x3,y3) (obtained from (3+22)3=99+702, i.e. 99/70) the tooth count grows to 70 but the error shrinks below 1/702≈0.0002.
This illustrates the fundamental engineering trade-off explicit in Pell's equation: each successive solution (xn,yn) trades a manufacturing cost increase (more teeth, i.e. larger yn) for a quantifiable, rapidly shrinking approximation error, letting a designer pick exactly the point on this curve that fits a budget and precision requirement.
What is the fundamental solution of x2−2y2=1?
If (x1,y1) is the fundamental solution, how is the solution (x2,y2) obtained?
Does x2−3y2=−1 have an integer solution?
Hallgren's algorithm solves Pell's equation in polynomial time using what kind of computation?