Continued Fraction Expansion - Maple Help

NumberTheory

 ContinuedFraction
 continued fraction expansion

 Calling Sequence ContinuedFraction(ex) ContinuedFraction(cf_list) ContinuedFraction(ex, v) ContinuedFraction(cf_list, v) Term(cf, n, form = formopt, diagonal = diagopt) Convergent(cf, m, form = formopt, diagonal = diagopt) Numerator(cf, m, form = formopt, diagonal = diagopt) Denominator(cf, m, form = formopt, diagonal = diagopt) Value(cf)

Parameters

 ex - complex number, $\mathrm{RootOf}$ representing one real number, rational function, or Laurent series v - either $s$ or $s=a$ where $s$ is a name and $a$ is an algebraic expression cf_list - list of terms of a finite or periodic continued fraction expansion cf - $\mathrm{ContinuedFraction}$ object m - natural number, range of natural numbers, or the symbol all n - natural number, range of natural numbers, or one of the symbols all or periodic form = formopt - (optional) keyword argument where formopt is one of simple, regular, centered, monic, simple_regular, or semisimple diagonal = diagopt - (optional) keyword argument where diagopt is one of super or sub

Description

 • The ContinuedFraction function returns an object which represents a continued fraction expansion depending on ex and v.
 • For ContinuedFraction(ex), the value represented by the returned object depends on ex. If ex is a complex number, a rational function in one variable, or a Laurent series, then ex is represented exactly. An error message is displayed if any other type of value is given.
 • For ContinuedFraction(cf_list), if cf_list is a list of two elements where the first element is a list of integers and the second element is a list of positive integers, then cf_list is interpreted as representing a periodic expansion, where the first list is the pre-periodic part and the second list is the periodic part. Otherwise, cf_list is interpreted as a finite expansion and the exact value is represented.
 • For ContinuedFraction('ex', 'v') and ContinuedFraction('cf_list', 'v'), the interpretation of ex depends on v. If v is a name, then ex is a rational function in v, if possible and otherwise the returned object represents the Laurent series expansion of ex expanded at $v=0$. If v is an equation $s=a$, then the value represented is the Laurent series expansion of ex at $s=a$.
 • The Term command returns terms of the continued fraction cf.
 – If n is a range $a..b$, then Term returns the terms with indices $a..b$. The return value is always a list in this case and if the indices exceed the available terms in a finite expansion, then NULL is used to fill their place.
 – If n is a number, then Term returns the term with index n. If n exceeds the available terms, then an error message is displayed.
 – If n is all, then Term returns all terms if the expansion is finite.
 – If n is periodic, then Term returns the periodic expansion if cf represents a real quadratic surd.
 • If cf represents a complex number, then formopt can be one of simple or centered, where simple is the default. If cf represents a rational function, then formopt can be one of simple, regular, or monic, where simple is the default. If cf represents a series, then formopt can be one of simple, regular, simple_regular, or semisimple, where regular is the default.
 • The diagonal option is valid only when cf represents a series. The default is super.
 • The commands Convergent, Numerator, and Denominator return, respectively, a convergent, the numerator of a convergent, and the denominator of a convergent. Their arguments follow the same rules as the arguments of Term except when m is a number. For a finite continued fraction, the sequence of convergents is infinite where after some finite number of initial terms in the sequence, every term thereafter is equal to the value represented by the continued fraction.
 • The Value command returns the exact value represented by cf.
 • A continued fraction

${b}_{0}+\frac{{a}_{1}}{{b}_{1}+\frac{{a}_{2}}{{b}_{2}+\frac{\mathrm{...}}{\mathrm{...}+\frac{{a}_{n}}{{b}_{n}+\mathrm{...}}}}}$

 is represented in list form as

$\left[{b}_{0},\left[{a}_{1},{b}_{1}\right],\left[{a}_{2},{b}_{2}\right],\mathrm{...},\left[{a}_{n},{b}_{n}\right],\mathrm{...}\right]$

 • The different forms for continued fraction expansions:
 1 Regular continued fraction:

$\left[{b}_{0},\left[{a}_{1},{b}_{1}\right],\left[{a}_{2},{b}_{2}\right],\mathrm{...},\left[{a}_{n},{b}_{n}\right],\mathrm{...}\right]$

 where, usually, ${a}_{i}$ and ${b}_{i}$ for i > 0 are integers or polynomials with integer coefficients. If ${b}_{0}\ne 0$ then it is called superdiagonal, otherwise it is called subdiagonal.
 2 Simple continued fraction:

$\left[{a}_{0},{a}_{1},{a}_{2},\mathrm{...},{a}_{n},\mathrm{...}\right]=\left[{a}_{0},\left[1,{a}_{1}\right],\left[1,{a}_{2}\right],\mathrm{...},\left[1,{a}_{n}\right],\mathrm{...}\right]$

 3 Simple regular continued fraction:

$\left[{b}_{0},\left[{a}_{1},1\right],\left[{a}_{2},1\right],\mathrm{...},\left[{a}_{n},1\right],\mathrm{...}\right]$

 4 Semisimple continued fraction:

$\left[{b}_{0},\left[{e}_{1},{b}_{1}\right],\left[{e}_{2},{b}_{2}\right],\mathrm{...},\left[{e}_{n},{b}_{n}\right],\mathrm{...}\right]$

 where ${e}_{i}=±1$ and $\mathrm{sign}\left({b}_{i}\right)=1$ for all $i$.
 5 Monic polynomial continued fraction:

$\left[{b}_{0},\left[{e}_{1},{b}_{1}\right],\left[{e}_{2},{b}_{2}\right],\mathrm{...},\left[{e}_{n},{b}_{n}\right],\mathrm{...}\right]$

 where each ${b}_{i}$ is a monic polynomial for all $i$.
 6 Periodic continued fraction:

$\left[\left[{a}_{0},\mathrm{...},{a}_{m}\right],\left[{b}_{0},\mathrm{...},{b}_{n}\right]\right]=\left[{a}_{0},\mathrm{...},{a}_{m},{b}_{0},\mathrm{...},{b}_{n},{b}_{0},\mathrm{...},{b}_{n},\mathrm{...}\right]$

Examples

 > $\mathrm{with}\left(\mathrm{NumberTheory}\right):$
 > $\mathrm{cf}≔\mathrm{ContinuedFraction}\left(\mathrm{\pi }\right)$
 ${\mathrm{cf}}{≔}{3}{+}\frac{{1}}{{7}{+}\frac{{1}}{{15}{+}\frac{{1}}{{1}{+}\frac{{1}}{{292}{+}\frac{{1}}{{1}{+}\frac{{1}}{{1}{+}\frac{{1}}{{1}{+}\frac{{1}}{{2}{+}\frac{{1}}{{1}{+}{\dots }}}}}}}}}}$ (1)
 > $\mathrm{Term}\left(\mathrm{cf},0..100\right)$
 $\left[{3}{,}{7}{,}{15}{,}{1}{,}{292}{,}{1}{,}{1}{,}{1}{,}{2}{,}{1}{,}{3}{,}{1}{,}{14}{,}{2}{,}{1}{,}{1}{,}{2}{,}{2}{,}{2}{,}{2}{,}{1}{,}{84}{,}{2}{,}{1}{,}{1}{,}{15}{,}{3}{,}{13}{,}{1}{,}{4}{,}{2}{,}{6}{,}{6}{,}{99}{,}{1}{,}{2}{,}{2}{,}{6}{,}{3}{,}{5}{,}{1}{,}{1}{,}{6}{,}{8}{,}{1}{,}{7}{,}{1}{,}{2}{,}{3}{,}{7}{,}{1}{,}{2}{,}{1}{,}{1}{,}{12}{,}{1}{,}{1}{,}{1}{,}{3}{,}{1}{,}{1}{,}{8}{,}{1}{,}{1}{,}{2}{,}{1}{,}{6}{,}{1}{,}{1}{,}{5}{,}{2}{,}{2}{,}{3}{,}{1}{,}{2}{,}{4}{,}{4}{,}{16}{,}{1}{,}{161}{,}{45}{,}{1}{,}{22}{,}{1}{,}{2}{,}{2}{,}{1}{,}{4}{,}{1}{,}{2}{,}{24}{,}{1}{,}{2}{,}{1}{,}{3}{,}{1}{,}{2}{,}{1}{,}{1}{,}{10}{,}{2}\right]$ (2)
 > $\mathrm{Digits}≔200:$$\mathrm{evalf}\left(\mathrm{abs}\left(\mathrm{Value}\left(\mathrm{ContinuedFraction}\left(\right)\right)-\mathrm{\pi }\right)\right);$$\mathrm{Digits}≔10:$
 ${2.27286794373942716879912269871874593270206667615219263136362270252567582047192090135453196247894}{×}{{10}}^{{-104}}$ (3)
 > $\mathrm{Term}\left(\mathrm{cf},4\right)$
 ${292}$ (4)
 > $\mathrm{cf}≔\mathrm{ContinuedFraction}\left(\mathrm{sqrt}\left(3\right)\right)$
 ${\mathrm{cf}}{≔}{1}{+}\frac{{1}}{{1}{+}\frac{{1}}{{2}{+}\frac{{1}}{{1}{+}\frac{{1}}{{2}{+}\frac{{1}}{{1}{+}\frac{{1}}{{2}{+}\frac{{1}}{{1}{+}\frac{{1}}{{2}{+}\frac{{1}}{{1}{+}{\dots }}}}}}}}}}$ (5)
 > $\mathrm{Term}\left(\mathrm{cf},\mathrm{periodic}\right)$
 $\left[\left[{1}\right]{,}\left[{1}{,}{2}\right]\right]$ (6)
 > $\mathrm{Value}\left(\mathrm{ContinuedFraction}\left(\right)\right)$
 $\sqrt{{3}}$ (7)
 > $\mathrm{Term}\left(\mathrm{ContinuedFraction}\left(\frac{35470}{99661}+\frac{315}{99661}I\right),\mathrm{all},\mathrm{form}=\mathrm{centered}\right)$
 $\left[{0}{,}\left[{I}{,}{3}{}{I}\right]{,}\left[{1}{,}{1}{+}{5}{}{I}\right]{,}\left[{-1}{,}{2}{+}{I}\right]{,}\left[{I}{,}{1}{+}{2}{}{I}\right]{,}\left[{-I}{,}{3}{+}{2}{}{I}\right]{,}\left[{-I}{,}{1}{+}{I}\right]\right]$ (8)
 > $\mathrm{Term}\left(\mathrm{ContinuedFraction}\left(\frac{{x}^{4}+13{x}^{2}+50x+120}{5{x}^{2}+x+1}\right),\mathrm{all}\right)$
 $\left[\frac{{1}}{{5}}{}{{x}}^{{2}}{-}\frac{{1}}{{25}}{}{x}{+}\frac{{321}}{{125}}{,}\frac{{625}{}{x}}{{5934}}{-}\frac{{2810875}}{{11737452}}{,}\frac{{23216680056}{}{x}}{{14242671875}}{+}\frac{{57431352636}}{{14242671875}}\right]$ (9)
 > $\mathrm{Term}\left(\mathrm{ContinuedFraction}\left({\left(1+x\right)}^{k},x\right),0..7,\mathrm{form}=\mathrm{simple_regular},\mathrm{diagonal}=\mathrm{sub}\right)$
 $\left[{0}{,}\left[{1}{,}{1}\right]{,}\left[{-}{k}{}{x}{,}{1}\right]{,}\left[\frac{\left({k}{+}{1}\right){}{x}}{{2}}{,}{1}\right]{,}\left[{-}\frac{\left({k}{-}{1}\right){}{x}}{{6}}{,}{1}\right]{,}\left[\frac{\left({k}{+}{2}\right){}{x}}{{6}}{,}{1}\right]{,}\left[{-}\frac{\left({k}{-}{2}\right){}{x}}{{10}}{,}{1}\right]{,}\left[\frac{\left({k}{+}{3}\right){}{x}}{{10}}{,}{1}\right]\right]$ (10)
 > $\mathrm{Term}\left(\mathrm{ContinuedFraction}\left(\mathrm{exp}\left(x\right),x=a\right),0..5\right)$
 $\left[{{ⅇ}}^{{a}}{,}\left[{x}{-}{a}{,}\frac{{1}}{{{ⅇ}}^{{a}}}\right]{,}\left[{x}{-}{a}{,}{-}{2}{}{{ⅇ}}^{{a}}\right]{,}\left[{x}{-}{a}{,}{-}\frac{{3}}{{{ⅇ}}^{{a}}}\right]{,}\left[{x}{-}{a}{,}{2}{}{{ⅇ}}^{{a}}\right]{,}\left[{x}{-}{a}{,}\frac{{5}}{{{ⅇ}}^{{a}}}\right]\right]$ (11)

Compatibility

 • The NumberTheory[ContinuedFraction] command was introduced in Maple 2016.