← workshop ← workbench

The Best Rational

continued fractions & the Stern–Brocot tree
self-test …
φ 1.6180339887…
continued fraction [a₀; a₁, a₂, …]
the Stern–Brocot descent
Every positive fraction lives once in this tree, already in lowest terms. Each node is the mediant of its neighbours — (a+c)/(b+d). The descent toward the target turns left/right; the steps where it changes direction are exactly the convergents — the best rational approximations.
convergents pₙ/qₙ — the best rationals
aₙpₙ/qₙvalue|x − p/q|q²·errbest ≤ q?
how fast does it close in? q²·|x − pₙ/qₙ|
this number   φ (the floor, 1/√5)   — lower = a better deal per denominator
choose a number

what you're seeing
A convergent pₙ/qₙ is the truncation of the continued fraction after n terms. The best-approximation theorem: it is the closest fraction to x of any denominator up to qₙ. This bench checks that twice over — the recurrence vs. a brute-force search of every denominator, and the mediant descent of the Stern–Brocot tree.
the punchlines
φ = [1;1,1,1,…] — every term is the smallest one can be, so its convergents (the Fibonacci ratios 1,2,3,5,8,13…) crawl in slowest. That makes φ the most irrational number — and the reason sunflower seeds sit at the golden angle: it's the angle hardest to approximate by a tidy fraction, so the seeds never line up into gaps.

The cross-link: φ is why phyllotaxis packs seeds the way it does.