Home▸Mathematics▸Continued Fractions: Best Rational Approximations (2D)

Continued Fractions: Best Rational Approximations (2D)

2D continued-fraction lab: unfold any real number into [a0; a1, a2,…], watch its convergents p/q on a number line, an independent Stern-Brocot mediant search, and a log-scale error chart checked against the theoretical bound.

Mathematics2DEasy60 FPS📱 Mobile-adapted⇄ 3D version
2d-continued-fractions ↗ Open standalone

This 2D companion runs the same greedy continued-fraction expansion as the 3D version — a0 = floor(x), then repeatedly inverting the remainder — and tracks its convergents p_n/q_n through the standard recurrence, but adds an independent check: a Stern-Brocot mediant search that locates the same fractions from scratch by binary-searching the tree of all positive rationals starting from 0/1 and 1/0. A linked log-scale error chart plots |x − p_n/q_n| against the theoretical 1/(q_n·q_(n+1)) bound, so you can watch two different algorithms converge on the same "best rational approximation" answer.

⚙ Under the hood

2D continued-fraction lab: greedy expansion with the p_n = a_n p_(n-1)+p_(n-2) / q_n = a_n q_(n-1)+q_(n-2) recurrence, an independent Stern-Brocot mediant search over the tree of positive rationals, and a log-scale error chart against the theoretical 1/(q_n q_(n+1)) bound.

continued fractionsgolden ratiostern-brocotconvergentscanvas 2d

2D · HTML5 Canvas 2D · 60 FPS target · runs fully client-side, no install

What did you find?

Add reproduction steps (optional)