Skip to content

FromContinuedFraction ​

The value of a continued fraction given its list of terms [a0,a1,…][a_0, a_1, \ldots].

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguageFromContinuedFraction!
FromContinuedFraction(terms)For a flat list of integers/symbols with at least one symbol, builds the nested unsimplified form a+1/(b+1/c)a + 1/(b + 1/c) term by term rather than compute-engine's combined single ratio.
SageMathcontinued_fraction(terms).value()SymPycontinued_fraction_reduce(terms)
Typed signatures
TypePackageApplies
(collection<any>) -> numberanalyticreplaces compute-enginealways
(collection<any>) -> numbercompute-enginealways
(collection<any>) -> numbermodularreplaces analyticalways

Domain: Compute engine

Details
  • Takes the list of terms [a0;a1,…][a_0; a_1, \ldots], or [a0,[period]][a_0, [\text{period}]] for a periodic tail, as Wolfram's does; ContinuedFraction is its inverse.
  • The empty list stays unevaluated, where Wolfram answers Infinity.

Examples

Basic #

[3;7,15,1][3;7,15,1] is the convergent 355/113355/113

live ↗
InFromContinuedFraction([3,7,15,1])\mathrm{FromContinuedFraction}(\bigl\lbrack3, 7, 15, 1\bigr\rbrack)Out355113\frac{355}{113}
Scope #

Built term by term, unsimplified

live ↗
InFromContinuedFraction([a,b,c])\mathrm{FromContinuedFraction}(\bigl\lbrack a, b, c\bigr\rbrack)Outa+1b+1ca+\frac{1}{b+\frac{1}{c}}

[1;1‾][1;\overline{1}] is the golden ratio

live ↗
InFromContinuedFraction([1,[1]])\mathrm{FromContinuedFraction}(\bigl\lbrack1, \bigl\lbrack1\bigr\rbrack\bigr\rbrack)Out1+52\frac{1+\sqrt{5}}{2}

A one-term list is that integer

live ↗
InFromContinuedFraction([5])\mathrm{FromContinuedFraction}(\bigl\lbrack5\bigr\rbrack)Out55

The first term may be negative: −3+1/(2+1/5)-3+1/(2+1/5)

live ↗
InFromContinuedFraction([−3,2,5])\mathrm{FromContinuedFraction}(\bigl\lbrack-3, 2, 5\bigr\rbrack)Out−2811-\frac{28}{11}
Properties #

Inverts ContinuedFraction: a rational round-trips through its expansion

live ↗
InFromContinuedFraction(ContinuedFraction(4717))\mathrm{FromContinuedFraction}(\mathrm{ContinuedFraction}(\frac{47}{17}))Out4717\frac{47}{17}
Possible issues #

The empty list has no value here

live ↗
InFromContinuedFraction([])\mathrm{FromContinuedFraction}(\bigl\lbrack\bigr\rbrack)OutFromContinuedFraction([])\mathrm{FromContinuedFraction}(\bigl\lbrack\bigr\rbrack)
About
Examples7
Checked againstWolfram Language 6 agree1 differSageMath 4 agree3 errorSymPy 6 agree1 unevaluated
CrosswalkWolfram LanguageSageMathSymPy

Implementation

mappedsympypackages/oracle/src/mappings.ts

A periodic tail [a0, [period]] is SymPy's own nested-list form. The empty list is 0 there, where ours stays unevaluated and Wolfram answers Infinity.

mappedsagepackages/oracle/src/mappings.ts

See also: ContinuedFraction