Mathwords logoMathwords

Pell Equation — Definition, Formula & Examples

A Pell equation is a Diophantine equation of the form x2Dy2=1x^2 - Dy^2 = 1, where DD is a positive integer that is not a perfect square and you seek integer solutions for xx and yy. It always has infinitely many solutions, and all of them can be generated from a single smallest positive solution called the fundamental solution.

Given a positive nonsquare integer DD, the Pell equation x2Dy2=1x^2 - Dy^2 = 1 has a fundamental solution (x1,y1)(x_1, y_1) with x1,y1>0x_1, y_1 > 0 that minimizes x1x_1. Every positive solution (xn,yn)(x_n, y_n) is obtained from the recurrence xn+ynD=(x1+y1D)nx_n + y_n\sqrt{D} = (x_1 + y_1\sqrt{D})^n for n1n \geq 1. The fundamental solution can be found via the convergents of the continued fraction expansion of D\sqrt{D}.

Key Formula

x2Dy2=1x^2 - Dy^2 = 1
Where:
  • xx = Positive integer to be determined
  • yy = Positive integer to be determined
  • DD = A fixed positive integer that is not a perfect square

How It Works

To solve a Pell equation, first compute the continued fraction expansion of D\sqrt{D}. The expansion is periodic, and the convergent pk/qkp_k/q_k at the end of the first complete period (or twice the period) gives the fundamental solution x1=pkx_1 = p_k, y1=qky_1 = q_k. Once you have (x1,y1)(x_1, y_1), generate all further solutions by expanding (x1+y1D)n(x_1 + y_1\sqrt{D})^n and collecting integer and irrational parts. Alternatively, use the recurrence xn+1=x1xn+Dy1ynx_{n+1} = x_1 x_n + D\, y_1 y_n and yn+1=x1yn+y1xny_{n+1} = x_1 y_n + y_1 x_n.

Worked Example

Problem: Find the fundamental solution and the next solution to the Pell equation x² − 2y² = 1.
Step 1: The continued fraction of √2 is [1; 2, 2, 2, ...] with period length 1. The first convergent at the end of the period is 3/2.
2=1+12+12+\sqrt{2} = 1 + \cfrac{1}{2 + \cfrac{1}{2 + \cdots}}
Step 2: Test x = 3, y = 2 as the fundamental solution.
322(22)=98=13^2 - 2(2^2) = 9 - 8 = 1 \quad \checkmark
Step 3: Generate the next solution using (x₁ + y₁√2)² = (3 + 2√2)².
9+122+8=17+1229 + 12\sqrt{2} + 8 = 17 + 12\sqrt{2}
Answer: The fundamental solution is (3, 2). The next solution is (17, 12), since 17² − 2(12²) = 289 − 288 = 1.

Why It Matters

Pell equations appear in problems about rational approximation of square roots, in algebraic number theory when studying the unit group of real quadratic fields, and in competition mathematics. Archimedes' famous cattle problem reduces to a Pell equation with enormous solutions.

Common Mistakes

Mistake: Trying D values that are perfect squares, such as D = 4 or D = 9.
Correction: When D is a perfect square, x² − Dy² = 1 factors over the integers and has only the trivial solution (x, y) = (1, 0). The Pell equation requires D to be a nonsquare positive integer.