Home › Number Theory › Lesson 12

Continued Fractions and Pell's Equation

Lesson 12 of 13

Key idea of this section

For non-square d > 0, x² − dy² = 1 has infinitely many solutions, all of the form ±(x₁ + y₁√d)ⁿ.

Continued fractions

Every real α has a simple continued fraction expansion α = [a₀; a₁, a₂, …], obtained by a₀ = ⌊α⌋, α₁ = 1/(α − a₀), a₁ = ⌊α₁⌋, and so on; it terminates exactly when α is rational, and then it is the Euclidean algorithm in disguise. The convergents pₖ/qₖ = [a₀; a₁, …, aₖ] satisfy

pₖ = aₖpₖ₋₁ + pₖ₋₂,   qₖ = aₖqₖ₋₁ + qₖ₋₂,   pₖqₖ₋₁ − pₖ₋₁qₖ = (−1)k−1,

with p₋₁ = 1, q₋₁ = 0, p₋₂ = 0, q₋₂ = 1. The last identity implies that consecutive convergents straddle α and that |α − pₖ/qₖ| < 1/(qₖqₖ₊₁) < 1/qₖ². Conversely (Legendre), any fraction p/q with |α − p/q| < 1/(2q²) is a convergent. Convergents are the best rational approximations: for instance π = [3; 7, 15, 1, 292, …] gives 22/7 and 355/113, the latter accurate to within 3 · 10⁻⁷ because the next partial quotient, 292, is large.

Theorem 12.1 (Euler; Lagrange, 1770). The continued fraction of α is eventually periodic if and only if α is a quadratic irrational. For a non-square d > 0,

√d = [a₀; a₁, a₂, …, aᵣ₋₁, 2a₀]   with period r, the block a₁, …, aᵣ₋₁ being a palindrome.

For example √2 = [1; 2, 2, 2, …], √7 = [2; 1, 1, 1, 4, …] with period 4, √13 = [3; 1, 1, 1, 1, 6, …] with period 5, and √61 = [7; 1, 4, 3, 1, 2, 2, 1, 3, 4, 1, 14, …] with period 11. No pattern of this kind is known for cube roots or for any algebraic number of degree ≥ 3; it is not even known whether the partial quotients of ∛2 are bounded.

Pell's equation

The equation x² − dy² = 1 for a non-square d > 0 was studied by Brahmagupta (628), who discovered the composition law

(x₁² − dy₁²)(x₂² − dy₂²) = (x₁x₂ + dy₁y₂)² − d(x₁y₂ + x₂y₁)²,

and posed x² − 92y² = 1 (smallest solution (1151, 120)). The chakravala method of Bhāskara II (1150) solved x² − 61y² = 1. Fermat set the same equation as a challenge in 1657; the name of John Pell is a historical accident due to Euler. In modern language, solutions correspond to units of norm 1 in the ring ℤ[√d], since (x + y√d)(x − y√d) = x² − dy².

Theorem 12.2 (Lagrange, 1768). For non-square d > 0, x² − dy² = 1 has a solution with y ≠ 0.

Proof. By Dirichlet's approximation theorem (pigeonhole applied to the fractional parts of 0, √d, 2√d, …, N√d) there are infinitely many pairs of positive integers (p, q) with |p − q√d| < 1/q. For each, |p² − dq²| = |p − q√d| · |p + q√d| < (1/q)(2q√d + 1/q) ≤ 2√d + 1. Hence some integer k, necessarily non-zero because √d is irrational, satisfies p² − dq² = k for infinitely many pairs. Among these, two distinct pairs (p₁, q₁), (p₂, q₂) have p₁ ≡ p₂ and q₁ ≡ q₂ (mod |k|). Put α = p₁ + q₁√d and β = p₂ + q₂√d, both of norm k. Then

α β̄ = (p₁p₂ − dq₁q₂) + (p₂q₁ − p₁q₂)√d,

and modulo |k| the coefficients are ≡ p₁² − dq₁² = k ≡ 0 and ≡ p₁q₁ − p₁q₁ = 0. So αβ̄/k = x + y√d with x, y ∈ ℤ and x² − dy² = N(α)N(β)/k² = 1. If y = 0 then x = ±1 and αβ̄ = ±k = ±ββ̄, so α = ±β, impossible for distinct pairs of positive integers. ∎

Theorem 12.3. Let (x₁, y₁) be the solution in positive integers with x₁ + y₁√d minimal (the fundamental solution) and ε = x₁ + y₁√d. Then the solutions of x² − dy² = 1 are exactly x + y√d = ±εⁿ, n ∈ ℤ.

Proof. Every ±εⁿ has norm 1. Conversely let η = x + y√d have norm 1; replacing η by −η we may assume η > 0, and replacing η by η⁻¹ = x − y√d we may assume η ≥ 1. Choose n ≥ 0 with εⁿ ≤ η < εⁿ⁺¹. Then u = ηε⁻ⁿ has norm 1 and 1 ≤ u < ε. If u > 1, write u = a + b√d; since u⁻¹ = a − b√d lies in (0, 1), we get a = (u + u⁻¹)/2 > 0 and b√d = (u − u⁻¹)/2 > 0, so (a, b) is a positive solution with a + b√d < ε, contradicting minimality. So u = 1 and η = εⁿ. ∎

The units of ℤ[√d] therefore form the group {±1} × ⟨ε⟩ ≅ C₂ × ℤ, the simplest case of Dirichlet's unit theorem (1846), which describes the unit group of the ring of integers of any number field as a finite cyclic group times ℤr₁+r₂−1.

Finding the fundamental solution

Theorem 12.4. Let √d have period r and convergents pₖ/qₖ. Then pₖ² − dqₖ² = ±1 exactly for k ≡ −1 (mod r), with sign (−1)k+1. Consequently the fundamental solution of x² − dy² = 1 is (pᵣ₋₁, qᵣ₋₁) if r is even and (p₂ᵣ₋₁, q₂ᵣ₋₁) if r is odd; and x² − dy² = −1 is solvable if and only if r is odd.

Worked example: d = 7. The convergents of [2; 1, 1, 1, 4, …] are 2/1, 3/1, 5/2, 8/3, and r = 4, so the fundamental solution is (8, 3): 64 − 63 = 1. The next solution is (8 + 3√7)² = 127 + 48√7, and 127² − 7 · 48² = 16129 − 16128 = 1.

Worked example: d = 13. The convergents of [3; 1, 1, 1, 1, 6, …] are 3/1, 4/1, 7/2, 11/3, 18/5, and r = 5 is odd. So 18² − 13 · 5² = 324 − 325 = −1, and the fundamental solution of the positive equation is

(18 + 5√13)² = (324 + 325) + 180√13 = 649 + 180√13,   649² − 13 · 180² = 421201 − 421200 = 1.

For d = 61 the period 11 is odd; x² − 61y² = −1 has fundamental solution (29718, 3805), and squaring gives the fundamental solution (1766319049, 226153980) of x² − 61y² = 1, the answer to Fermat's challenge. The fundamental solution can be enormous compared to d: its logarithm is the regulator, and by the class number formula it is related to the class number of ℚ(√d), so large regulators are typical. The Archimedes cattle problem reduces to x² − 410286423278424y² = 1, whose solution gives a herd whose size has 206 545 digits; it was computed in full only in 1965 (Williams, German and Zarnke).

Exercise

  • (a)
    Find the fundamental solution of x² − 3y² = 1 and the next two solutions.
  • (b)
    Show that x² − 3y² = −1 has no integer solutions.
  • (c)
    Verify that (1151, 120) solves x² − 92y² = 1.
Show solution

Answers: (a) √3 = [1; 1, 2, …] has period 2, convergents 1/1, 2/1, so the fundamental solution is (2, 1). Then (2 + √3)² = 7 + 4√3 and (2 + √3)³ = (7 + 4√3)(2 + √3) = 26 + 15√3, giving (7, 4) and (26, 15): 49 − 48 = 1 and 676 − 675 = 1. (b) Modulo 3, x² ≡ −1 ≡ 2, but squares are 0 or 1 mod 3. (Equivalently, the period of √3 is even.) (c) 1151² = 1324801 and 92 · 120² = 92 · 14400 = 1324800.

V.3.1