Stern–Brocot Tree Explorer — Find any Fraction’s L/R Path & Mediant Convergents
Locate any positive fraction p/q (or a decimal approximation) in the Stern–Brocot tree of all reduced fractions. See the L/R path from 1/1, the mediant fractions visited (best approximations), and how the L/R run-lengths are exactly the continued-fraction terms. Reverse an L/R string back to its fraction. Live, exact with BigInt, copy.
How to Use
- Type a positive fraction like <code>3/5</code>, or a decimal like <code>0.6</code> — the decimal is approximated to a nearby reduced fraction.
- Read the <strong>L/R path</strong> from the root 1/1: at each step the tool compares your target to the mediant of the current bounds and goes Left (smaller) or Right (larger).
- Follow the <strong>mediant sequence</strong> — these are the successive best rational approximations (convergents) on the way down.
- Switch to <strong>Path → fraction</strong> and enter an L/R string (e.g. <code>LRL</code>) to walk the tree the other way.
- Click any value to copy it.
Every fraction has an address
The Stern–Brocot tree is an infinite binary tree that contains every positive reduced fraction exactly once — no duplicates, no gaps. It grows from two boundary fractions, 0/1 (zero) and 1/0 (treated as infinity). The fraction sitting between any two neighbours a/b and c/d is their mediant (a+c)/(b+d); the first mediant of the two bounds is 1/1, the root. Because the tree is a binary tree, a left/right path from the root is a unique address for each fraction — a perfect, exact way to name, store and compare rationals.
Finding a fraction is a binary search
To locate p/q you keep a left bound L = 0/1 and a right bound R = 1/0 and repeatedly form their mediant m. If p/q < m you step Left (so m becomes the new right bound); if p/q > m you step Right (so m becomes the new left bound); if they are equal you have arrived. The mediants you pass through are the successive best rational approximations — each is the simplest fraction (smallest denominator) lying between the current bounds. This is the same machinery as Farey sequences and the convergents of a continued fraction.
The path is the continued fraction
Group the L/R path into runs of identical letters. Those run-lengths are exactly the continued-fraction terms of the fraction, and the mediants at the end of each run are exactly its convergents. For example 3/5 has path LRL with mediant sequence 1/1 → 1/2 → 2/3 → 3/5, and its continued fraction is [0; 1, 1, 2]. So the Stern–Brocot tree, Farey mediants and continued fractions are three views of one idea.
Quick reference
About the Stern–Brocot Tree Explorer — Find any Fraction’s L/R Path & Mediant Convergents
Whether you are at a desk or on your phone, the Stern–Brocot Tree Explorer — Find any Fraction’s L/R Path & Mediant Convergents makes everyday tasks easy — and it is completely free. Locate any positive fraction p/q (or a decimal approximation) in the Stern–Brocot tree of all reduced fractions. See the L/R path from 1/1, the mediant fractions visited (best approximations), and how the L/R run-lengths are exactly the continued-fraction terms. Reverse an L/R string back to its fraction. Live, exact with BigInt, copy.
How it works
Type in what you have, and the answer shows up right away. Change anything and it updates by itself. Everything runs in your browser, so it is fast and nothing you type is sent away.
Want the deeper story? The Knowledge Base explains the ideas behind the tools in more detail.
Frequently Asked Questions
What is the Stern–Brocot tree?
It is an infinite binary tree containing every positive reduced fraction exactly once, with no duplicates and no gaps. It is built from two boundary fractions 0/1 (zero) and 1/0 (infinity): the child between any two neighbours a/b and c/d is their mediant (a+c)/(b+d). Starting from those bounds, the very first mediant is 1/1, the root of the tree.
What does the L/R path mean?
Finding a fraction is a binary search. You keep a left bound and a right bound and form their mediant. If your target is smaller than the mediant you move Left (the mediant becomes the new right bound); if it is larger you move Right (the mediant becomes the new left bound). The recorded L/R string is the unique address of your fraction in the tree.
How is this related to continued fractions?
The run-lengths of the L/R path are exactly the continued-fraction terms. For 3/5 the path is L R L, with run-lengths 1, 1, 1 — and 3/5 = [0; 1, 1, 2] (the final term is one more than the trailing run because the path stops at the fraction itself). The mediants visited are precisely the convergents of that continued fraction.
Why are these mediants the “best” approximations?
Each mediant on the path is the fraction with the smallest possible denominator that lies strictly between the current bounds, so it is the best rational approximation to your target achievable with a denominator that small. This is the same theory behind Farey sequences and convergents.
What about decimals or improper fractions?
A decimal is approximated to a reduced fraction near it (you can see the fraction the tool used). Improper fractions such as 5/2 are fine — they simply live deeper to the right of 1/1. Everything is computed with BigInt so the arithmetic is exact even for long paths.
Is anything uploaded?
No. The whole search runs in your browser with JavaScript — nothing is sent to a server.
How do I use the Stern–Brocot Tree Explorer — Find any Fraction’s L/R Path & Mediant Convergents?
Just type your numbers. The answer shows up right away — there is no button to press. Change anything and it updates by itself.
Is it free? Does it work without internet?
Yes to both. It is free with no sign-up, and once the page has loaded it keeps working even with no internet.
Where does my data go?
Nowhere — every calculation runs on your own device. Nothing you enter is uploaded, logged, or stored.
Common Use Cases
Best rational approximations
Read off the convergents (mediants) of a decimal to find the simplest fraction within a given denominator — gear ratios, calendar cycles, tuning.
Understanding continued fractions
See, concretely, why the continued-fraction terms are the L/R run-lengths and why the convergents are mediants in a tree.
Teaching number theory
Demonstrate Farey neighbours, mediants and the bijection between fractions and binary addresses with a live, exact tool.
Encoding fractions as bits
Every positive fraction maps to a unique L/R string — a compact, exact address you can store, transmit and round-trip.
Last updated: