Explore the most natural representation of real numbers and solve x² - Dy² = 1
A continued fraction finds the best fractions for any real number. It explains why 355/113 is so close to π, and it cracks an equation Archimedes posed.
Pick a number and build its expansion term by term. The convergents land alternately above and below it, closing in each time.
Convergents alternate above and below the target (red line), converging from both sides. Even convergents (amber) approach from below, odd (blue) from above.
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.
Compare how fast the error shrinks for π and for the golden ratio φ. Big terms mean big jumps; φ's are all 1, so it converges slowest.
| 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 |
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.
Slide D to solve x² - Dy² = 1. Watch the periodic expansion of √D produce the smallest solution, and find it on the hyperbola.
| # | x | y | x² - 2y² |
|---|---|---|---|
| 1 | 3 | 2 | 1 |
| 2 | 17 | 12 | 1 |
| 3 | 99 | 70 | 1 |
| 4 | 577 | 408 | 1 |
| 5 | 3363 | 2378 | 1 |
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 fundamental solution is a convergent: the one at the end of the first period if the period length is even, or at the end of the second period if it is odd (the first then solves x² - Dy² = -1 instead). All other solutions are generated by "powers" of it.
Raise the maximum denominator and zoom into a range. Tangent circles mark neighbouring fractions, and smaller circles nestle in every gap.
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.
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.
Spot a mistake or have an idea?