ContinuedFraction[x,n]
generates a list of the first n terms in the continued fraction representation of x.
generates a list of all terms that can be obtained given the precision of x.
ContinuedFraction
ContinuedFraction[x,n]
generates a list of the first n terms in the continued fraction representation of x.
generates a list of all terms that can be obtained given the precision of x.
Details
- The continued fraction representation {a1,a2,a3,…} corresponds to the expression a1+1/(a2+1/(a3+…)).
- x can be either an exact or an inexact number.
- For exact numbers, ContinuedFraction[x] can be used if x is rational, or is a quadratic irrational.
- For quadratic irrationals, ContinuedFraction[x] returns a result of the form {a1,a2,…,{b1,b2,…}}, corresponding to an infinite sequence of terms, starting with the ai, and followed by cyclic repetitions of the bi. »
- Since the continued fraction representation for a rational number has only a limited number of terms, ContinuedFraction[x,n] may yield a list with less than n elements in this case.
- For terminating continued fractions, {…,k} is always equivalent to {…,k-1,1}; ContinuedFraction returns the first of these forms.
- FromContinuedFraction[list] reconstructs a number from the result of ContinuedFraction.
Examples
open all close allBasic Examples (1)
Scope (2)
ContinuedFraction[47 / 17]2 + 1 / (1 + 1 / (3 + 1 / 4))2 + (1/1 + (1/3 + (1/4)))Quadratic irrational (recurring continued fraction):
ContinuedFraction[Sqrt[13]]ContinuedFraction[Sqrt[13], 20]Generalizations & Extensions (1)
ContinuedFraction stops when it runs out of precision:
ContinuedFraction[N[Pi]]ContinuedFraction[N[Pi, 20]]Applications (3)
The continued fractions for n
roots of
are very regular:
ContinuedFraction[Sqrt[E], 25]Geometric mean of the first 1000 continued fraction terms in
:
N[Apply[Times, ContinuedFraction[Pi, 1000]] ^ (1 / 1000)]N[Khinchin]ContinuedFraction[Exp[Pi Sqrt[163]], 10]N[Exp[Pi Sqrt[163]], 50]Properties & Relations (2)
FromContinuedFraction is effectively the inverse of ContinuedFraction:
ContinuedFraction[Pi, 20]FromContinuedFraction[%]N[%]Explicit representation using nested fractional parts:
Floor[NestList[1 / FractionalPart[#]&, Pi, 20]]ContinuedFraction[Pi, 21]Related Guides
Related Links
History
Introduced in 1999 (4.0)
Text
Wolfram Research (1999), ContinuedFraction, Wolfram Language function, https://reference.wolfram.com/language/ref/ContinuedFraction.html.
CMS
Wolfram Language. 1999. "ContinuedFraction." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/ContinuedFraction.html.
APA
Wolfram Language. (1999). ContinuedFraction. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ContinuedFraction.html
BibTeX
@misc{reference.wolfram_2026_continuedfraction, author="Wolfram Research", title="{ContinuedFraction}", year="1999", howpublished="\url{https://reference.wolfram.com/language/ref/ContinuedFraction.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_continuedfraction, organization={Wolfram Research}, title={ContinuedFraction}, year={1999}, url={https://reference.wolfram.com/language/ref/ContinuedFraction.html}, note=[Accessed: 13-June-2026]}