Continued Fractions Calculator: Best Rational Approximations

simulator advanced ~12 min
Loading simulation...
355/113 = [3; 7, 15, 1] — the best rational approximation to π with denominator < 1000

355/113 has the continued fraction expansion [3; 7, 15, 1] and approximates π to within 2.67 × 10⁻⁷, making it the best rational approximation with a denominator under 1000.

Formula

x = a₀ + 1/(a₁ + 1/(a₂ + 1/(...)))
pₙ = aₙ pₙ₋₁ + pₙ₋₂, qₙ = aₙ qₙ₋₁ + qₙ₋₂ (convergent recurrence)
|x - pₙ/qₙ| < 1/(qₙ qₙ₊₁) (best approximation bound)

Fractions Inside Fractions

A continued fraction peels back a real number layer by layer: first the integer part, then a reciprocal remainder, then the integer part of that, and so on. The notation [a₀; a₁, a₂, ...] compactly encodes this nested structure. Unlike decimal expansions, continued fractions naturally reveal the best rational approximations to a number — the convergents obtained by truncating the expansion. This simulator computes the CF of any fraction and animates how convergents home in on the target value.

Convergents and Best Approximations

Each truncation of a continued fraction yields a convergent pₙ/qₙ that alternates above and below the true value. A remarkable theorem guarantees that convergents are the best rational approximations: no fraction with a smaller denominator comes closer to the target. The recurrence relations pₙ = aₙ pₙ₋₁ + pₙ₋₂ and qₙ = aₙ qₙ₋₁ + qₙ₋₂ make convergents easy to compute iteratively.

Large Partial Quotients

When a large partial quotient appears in the CF expansion, the previous convergent is an unusually good approximation. The classic example is π = [3; 7, 15, 1, 292, ...] — the term 292 makes 355/113 accurate to six decimal places, known to Zu Chongzhi in 5th-century China. Conversely, the golden ratio φ = [1; 1, 1, 1, ...] has all-1 partial quotients, making it the most poorly approximable irrational number.

Applications Beyond Number Theory

Continued fractions appear throughout mathematics and engineering. The Euclidean algorithm is secretly a CF computation. Pell's equation x² - Dy² = 1 is solved via the CF of √D. In signal processing, CF-based rational approximations optimize filter design. Calendar algorithms use CFs to find leap year cycles: the 97/400 Gregorian rule comes from the CF of the tropical year minus 365.

FAQ

What is a continued fraction?

A continued fraction represents a real number as a₀ + 1/(a₁ + 1/(a₂ + ...)) where a₀ is an integer and subsequent terms (partial quotients) are positive integers. Every rational number has a finite CF; irrationals have infinite CFs. They provide the best rational approximations to real numbers.

What are convergents?

Convergents are the rational numbers obtained by truncating a continued fraction at successive terms: p₀/q₀, p₁/q₁, p₂/q₂, ... They alternate above and below the target value, and each convergent is the best rational approximation with denominator ≤ qₙ.

Why is 355/113 such a good approximation to π?

In the CF of π = [3; 7, 15, 1, 292, ...], the large partial quotient 292 means the convergent before it (355/113) is exceptionally accurate — the next better approximation needs a denominator over 33,000. This is why 355/113 was used for centuries in China (Zu Chongzhi, 5th century).

What is the golden ratio's continued fraction?

The golden ratio φ = (1+√5)/2 has the simplest infinite CF: [1; 1, 1, 1, ...]. Because all partial quotients are 1 (the smallest possible), φ is the 'hardest to approximate' irrational — its convergents (Fibonacci ratios) converge the slowest of any CF.

Sources

Embed

<iframe src="https://homo-deus.com/lab/number-theory/continued-fractions/embed" width="100%" height="400" frameborder="0"></iframe>
View source on GitHub