Stern–Brocot Neighbor Mediant
Insert the reduced mediant between ordered nonnegative Stern–Brocot neighbors satisfying b·c−a·d=1, including the boundary pair 0/1 and 1/0.
Description
The mediant of two fractions adds their numerators and denominators.
The mediant of two fractions adds their numerators and denominators. Ordered Stern–Brocot neighbors satisfy a determinant condition that ensures their mediant is already reduced.1
The tool returns numerator, denominator. The indexing and output conventions below determine how to read these values.
When to use Stern–Brocot Neighbor Mediant
Use this for the following task: Insert the reduced mediant between ordered nonnegative Stern–Brocot neighbors satisfying b·c−a·d=1, including the boundary pair 0/1 and 1/0. Use the input and output conventions below to reproduce the intended mathematical quantity.
How to use Stern–Brocot Neighbor Mediant and understand its results
- Choose the required indexes, integers or sequence entries. Preserve decimal-string encodings where the field table specifies strings.
- Enter leftNumerator, leftDenominator, rightNumerator, rightDenominator according to the field table, then run the tool.
- Read numerator, denominator. Preserve exact decimal strings and the stated indexing or coefficient order.
- Keep exact decimal strings for subsequent integer arithmetic; distinguish them from any explicitly approximate numeric result.
| Input field | Meaning | Value type and bounds | Requirement |
|---|---|---|---|
| leftNumerator | Left numerator | string (integer/arbitrary); maximum text length 200; pattern ^(0|[1-9][0-9]*)$ | Required |
| leftDenominator | Left denominator | string (integer/arbitrary); maximum text length 200; pattern ^(0|[1-9][0-9]*)$ | Required |
| rightNumerator | Right numerator | string (integer/arbitrary); maximum text length 200; pattern ^(0|[1-9][0-9]*)$ | Required |
| rightDenominator | Right denominator | string (integer/arbitrary); maximum text length 200; pattern ^(0|[1-9][0-9]*)$ | Required |
Parse all four nonnegative decimal strings with BigInt. Require determinant exactly one, then return numerator and denominator sums as strings.
for a/b<c/d with b×c−a×d=1: mediant=(a+c)/(b+d) The symbols and boundary conditions refer to the supplied fields and the implementation described above.
| Output field | Meaning | Value type |
|---|---|---|
| numerator | Mediant numerator | string (integer/arbitrary) |
| denominator | Mediant denominator | string (integer/arbitrary) |
{
"input": {
"leftNumerator": "1",
"leftDenominator": "3",
"rightNumerator": "1",
"rightDenominator": "2"
},
"output": {
"numerator": "2",
"denominator": "5"
}
} Limitations and assumptions
This is a neighbor operation, not general fraction addition or reduction. The special boundary pair 0/1 and 1/0 is accepted; invalid neighbors give an error.
Use the declared integer bounds and string formats. Large exact outputs remain decimal strings; numerical approximations use ordinary floating-point arithmetic. A rejected input is different from a valid zero count or false membership flag.
Alternative or Complementary methods
Choose Farey Sequence of Order n when you need its operation: List the reduced fractions from zero to one in increasing order with denominators at most n; order is capped at 300 to bound the output size. Choose Continued Fraction Convergents for the complementary operation: Build all exact rational convergents of a finite simple continued fraction with an integral first coefficient and positive remaining coefficients.
Background reference: OEIS A002487.
References
-
OEIS A002487 — OEIS Foundation
Similar or alternative tools
- Farey Sequence of Order n
List the reduced fractions from zero to one in increasing order with denominators at most n; order is capped at 300 to bound the output size.
- Continued Fraction Convergents
Build all exact rational convergents of a finite simple continued fraction with an integral first coefficient and positive remaining coefficients.