ContinuedFraction
The regular continued fraction of . Its partial quotients are the run lengths of the rational's Stern–Brocot path, and the -exponents of its matrix — one object under three names.
Continued fractionMathWorldContinuedFractionWikidataQ4115724Wolfram LanguageContinuedFraction!Rosetta CodeContinued fractionContinuedFraction(x)the partial quotients of a rational — compute-engine's own headlist(continued_fraction(x))SymPylist(continued_fraction(x))ContinuedFraction(x, n)the first terms — exact for a quadratic irrational, certified-precision otherwise (compute-engine's own signature, extended)FromContinuedFraction(list)back to the rational — compute-engine's ownlist(continued_fraction(list))SymPylist(continued_fraction(list))FromContinuedFraction([a0, [period]])back to the quadratic irrational, from its periodic-tail shapeSternBrocotPath(p, q)the same data as a word in and FareySequence(n)every reduced in with , in orderlist(continued_fraction(n))SymPylist(continued_fraction(n))Typed signatures
| Type | Package | Applies |
|---|---|---|
((list<integer>) -> continued_fraction) & ((real, integer?) -> list<integer>) | number-theoryreplaces modular | always |
(real, integer?) -> list<integer> | compute-engine | always |
(real, integer?) -> list<integer> | modularreplaces compute-engine | always |
Details
ContinuedFractionandFromContinuedFractionare compute-engine's heads, extended in place rather than redeclared — pass the RATIONAL, not a numerator and denominator, since the two-argument form means "the first terms"- For a quadratic irrational , the one-argument form runs the exact PQa algorithm over bigints and returns the eventually-periodic expansion; the two-argument form truncates it. Anything else irrational — , , a cube root, a sum of surds, the named
GoldenRatio— goes through a BigDecimal extraction certified by agreement across two working precisions, so it isn't limited to double precision - The expansion is made unique by never ending in : is rewritten
- The path is with the LAST exponent one short — the final step is the arrival, not a turn
- Consecutive Farey fractions satisfy , which is a determinant, which is a group element
- The Fibonacci fractions alternate , the sense in which is the most irrational number
Examples
1 more kept as data, checked against the oraclesBasic #
a quadratic irrational's exact expansion is eventually periodic, written with the period as a nested list
live ↗Properties #
Possible issues #
About
| Examples | 37 |
|---|---|
| Checked against | Wolfram Language 28 agree3 differSageMath 6 agree2 differ7 errorSymPy 26 agree2 differ3 error |
| Crosswalk | WikipediaMathWorldWikidataWolfram LanguageSageMathSymPyRosetta Code |
Implementation
wolframpackages/oracle/src/mappings.tsSage's continued_fraction returns a ContinuedFraction object (str() is '[3; 7, 16]'); list(...) gives the plain quotients, like the SymPy row.
sympypackages/oracle/src/mappings.tsSage's continued_fraction returns a ContinuedFraction object (str() is '[3; 7, 16]'); list(...) gives the plain quotients, like the SymPy row.
sagepackages/oracle/src/mappings.tsSage's continued_fraction returns a ContinuedFraction object (str() is '[3; 7, 16]'); list(...) gives the plain quotients, like the SymPy row.
sympypackages/oracle/src/mappings.tsThe first n terms of the expansion, as ours is (an irrational's is not folded into a periodic tail, which the one-argument form does). Exact arguments only: continued_fraction_iterator(3.245) expands the binary double, where ours reads a float as the rational it prints.
See also: ModularWord, IntegerDigits, Convergents