Explore the most natural representation of real numbers and solve x² - Dy² = 1
Every real number has a continued fraction expansion [a0; a1, a2, ...] that provides the best possible rational approximations. Unlike decimals, continued fractions reveal the true approximation complexity of a number.
For quadratic irrationals like √D, the expansion is always periodic — and this periodicity is the key to solving Pell's equation x² - Dy² = 1, one of the oldest problems in Diophantine equations. This topic connects to Galois Theory through units of real quadratic number fields.
Watch a continued fraction expansion build term by term. Each convergent pk/qk is a "best rational approximation" — no fraction with a smaller denominator gets closer. Convergents alternate above and below the target, bracketing it ever more tightly.
Convergents alternate above and below the target (red line), converging from both sides. Even convergents (amber) approach from below, odd (blue) from above.
How fast do convergents approach the target? The error |α - pk/qk| is always less than 1/qk². Numbers with large CF coefficients (like π) are well-approximated by simple fractions; those with small coefficients (like the golden ratio φ) are the hardest to approximate — making φ the "most irrational" number.
| k | pk/qk | value | error |
|---|---|---|---|
| 0 | 3/1 | 3.00000000 | 1.42e-1 |
| 1 | 22/7 | 3.14285714 | 1.26e-3 |
| 2 | 333/106 | 3.14150943 | 8.32e-5 |
| 3 | 355/113 | 3.14159292 | 2.67e-7 |
| 4 | 103993/33102 | 3.14159265 | 5.78e-10 |
| 5 | 104348/33215 | 3.14159265 | 3.32e-10 |
| 6 | 208341/66317 | 3.14159265 | 1.22e-10 |
| 7 | 312689/99532 | 3.14159265 | 2.91e-11 |
| 8 | 833719/265381 | 3.14159265 | 8.72e-12 |
| 9 | 1146408/364913 | 3.14159265 | 1.61e-12 |
Pell's equation x² - Dy² = 1 has been studied since ancient times (Archimedes posed a version for D = 4729494). The continued fraction of √D is always periodic, and the convergent at the end of the period gives the fundamental solution. All other solutions are generated by "powers" of it.
| # | x | y | x² - 2y² |
|---|---|---|---|
| 1 | 3 | 2 | 1 |
| 2 | 17 | 12 | 1 |
| 3 | 99 | 70 | 1 |
| 4 | 577 | 408 | 1 |
| 5 | 3363 | 2378 | 1 |
For each fraction p/q in lowest terms, draw a circle of radius 1/(2q²) tangent to the x-axis at p/q. The resulting Ford circles exhibit beautiful tangency relations: two circles are tangent if and only if their fractions are neighbors in some Farey sequence. Zoom in to see the fractal-like structure.
Ford circles are tangent to the x-axis at each fraction p/q (in lowest terms) with radius 1/(2q²). Two Ford circles are tangent to each other iff their fractions are Farey neighbors.
You've completed the Number Theory module! You now understand:
From divisibility and primes through modular arithmetic, the zeta function, quadratic reciprocity, and continued fractions — you've explored the full landscape of classical number theory. Head to the Playground to experiment freely, or test yourself with the Quiz!