Continued fractions: how to find the best rational approximation to any number
Continued fractions are the Euclidean algorithm in disguise. We develop convergents and the best-approximation property, compute the continued fraction of sqrt(2), connect it to Pell's equation, and sketch the Stern-Brocot tree.
The fraction approximates with an error of less than , using a denominator of only . Why is so good? The answer lies in the theory of continued fractions.
1 Definition
2 The connection to the Euclidean algorithm
The continued fraction expansion and the Euclidean algorithm are exactly the same computation.
3 Convergents: truncating for good approximations
Convergents can be computed efficiently via a recurrence.
4 Best rational approximations
5 The continued fraction of
6 Pell's equation
The continued fraction of leads directly to solutions of Pell's equation.
7 The Stern–Brocot tree
Every positive rational number appears exactly once, in lowest terms.
The tree is always sorted (left child parent right child).
The path to each node (a sequence of left and right turns) corresponds to the continued fraction expansion.
A binary search on the tree finds the closest fraction with denominator in time.
8 Takeaway
Continued fractions are the Euclidean algorithm viewed from a different angle.
Convergents are the best rational approximations with bounded denominator.
The continued fraction of is periodic and yields solutions to Pell's equation.
The Stern–Brocot tree organizes all positive rationals into a single systematic structure.
In the final article of this series, we shall see how the theorems developed throughout these eight articles converge in a single, celebrated application: the RSA cryptosystem.
Mathematics "between the lines" — exploring the intuition textbooks leave out, written in LaTeX on Folio.