This site is supported by donations to The OEIS Foundation.

Template:Cfrac/doc

From OeisWiki
Jump to: navigation, search

This documentation subpage contains instructions, categories, or other information for Template:Cfrac. [<Edit> Template:Cfrac]

[⧼Purge⧽ Template:Cfrac/doc]

The {{cfrac}} mathematical formatting template typesets either finite or infinite [generalized] continued fractions in either HTML+CSS or LaTeX.

Usage

For finite continued fractions, use

{{cfrac|a0 ;; b1//a1 ,, b2//a2 ,, ... ,, bk//ak|format}}

or (to omit the integer part)

{{cfrac|;; b1//a1 ,, b2//a2 ,, ... ,, bk//ak|format}}

while for infinite continued fractions, use (where the last ak is left blank)

{{cfrac|a0 ;; b1//a1 ,, b2//a2 ,, ... ,, bk//|format}}

or (to omit the integer part)

{{cfrac|;; b1//a1 ,, b2//a2 ,, ... ,, bk//|format}}

where

  • a0 followed by two consecutive semi-columns is the integer part, and
  • bi//ai, with 1   ≤   i   ≤   12, separated by two consecutive commas, are the partial quotients (with the expanded styles, only the first eight partial quotients are considered, the others are ignored);

and where format is from

  • htm: condensed style HTML+CSS,
  • HTM: expanded style HTML+CSS,
  • tex: condensed style LaTeX,
  • TEX: expanded style LaTeX.

Examples

Text style

The code

{{indent}}the continued fraction is {{math|
? {{=}} {{cfrac|0;; 2//1,, 4//2,, 6//3,, 8//4,, 10//5,, 12//6,, 14//7,, 16//8,, 18//9,, 20//10|htm}} {{=}} {{cfrac|0;; 2//1,, 4//2,, 6//3,, 8//4,, 10//5,, 12//6,, 14//7,, 16//8,, 18//9,, 20//|htm}} 
|&}}

yields the text style HTML+CSS

     the continued fraction is 
? = 0  + 2  /  (1  + 4  /  (2  + 6  /  (3  + 8  /  (4  + 10  /  (5  + 12  /  (6  + 14  /  (7  + 16  /  (8  + 18  /  (9  + 20  /  (10 + ) ) = 0  + 2  /  (1  + 4  /  (2  + 6  /  (3  + 8  /  (4  + 10  /  (5  + 12  /  (6  + 14  /  (7  + 16  /  (8  + 18  /  (9  + 20  /  ( + ) )

The code

{{indent}}the continued fraction is {{math|
? {{=}} {{cfrac|0;; 2//1,, 4//2,, 6//3,, 8//4,, 10//5,, 12//6,, 14//7,, 16//8,, 18//9,, 20//10|tex}} {{=}} {{cfrac|0;; 2//1,, 4//2,, 6//3,, 8//4,, 10//5,, 12//6,, 14//7,, 16//8,, 18//9,, 20//|tex}}
|$}}

yields the text style LaTeX

     the continued fraction is

The code

{{indent}}{{math|
? {{=}} {{cfrac|0;; 2//1,, 4//2,, 6//3,, 8//4,, 10//5,, 12//6,, 14//7,, 16//8,, 18//9,, 20//10|HTM}}
|&}}

yields the text style HTML+CSS

      
? = 0 + 
2
1 + 
4
2 + 
6
3 + 
8
4 + 
10
5 + 
12
6 + 
14
7 + 
16
8 + 
18
9 + 
20
10

The code

{{indent}}{{math|
? {{=}} {{cfrac|0;; 2//1,, 4//2,, 6//3,, 8//4,, 10//5,, 12//6,, 14//7,, 16//8,, 18//9,, 20//10|TEX}}
|$}}

yields the text style LaTeX

     

Display style

The code

{{indent}}{{math|
? {{=}} {{cfrac|0;; 2//1,, 4//2,, 6//3,, 8//4,, 10//5,, 12//6,, 14//7,, 16//8|HTM}}
|&&}}

yields the display style HTML+CSS

     
? = 0 + 
2
1 + 
4
2 + 
6
3 + 
8
4 + 
10
5 + 
12
6 + 
14
7 + 
16
8

The code

{{indent}}{{math|
? {{=}} {{cfrac|0;; 2//1,, 4//2,, 6//3,, 8//4,, 10//5,, 12//6,, 14//7,, 16//8|TEX}}
|$$}}

yields the display style LaTeX

     

The code

{{indent}}{{math|
? {{=}} {{cfrac|0;; 2//1,, 4//2,, 6//3,, 8//4|HTM}}
|&&}}

yields the display style HTML+CSS

     
? = 0 + 
2
1 + 
4
2 + 
6
3 + 
8
4

The code

{{indent}}{{math|
? {{=}} {{cfrac|0;; 2//1,, 4//2,, 6//3,, 8//4|TEX}}
|$$}}

yields the display style LaTeX

     

The code

{{indent}}{{math|
? {{=}} {{cfrac|;; 2//1,, 4//2,, 6//3,, 8//|HTM}}
|&&}}

yields the display style HTML+CSS

     
? =
2
1 + 
4
2 + 
6
3 + 
8

The code

{{indent}}{{math|
? {{=}} {{cfrac|;; 2//1,, 4//2,, 6//3,, 8//|TEX}}
|$$}}

yields the display style LaTeX

     

The code

{{indent}}{{math|
? {{=}} {{cfrac|0;; ''x''//1,, ''x''{{^|2}}//2,, ''x''{{^|3}}//3,, ''x''{{^|4}}//4,, ''x''{{^|5}}//5,, <!--
-->''x''{{^|6}}//6,, ''x''{{^|7}}//7,, ''x''{{^|8}}//|HTM}}
|&&}}

yields the display style HTML+CSS

     
? = 0 + 
x
1 + 
x 2
2 + 
x 3
3 + 
x 4
4 + 
x 5
5 + 
x 6
6 + 
x 7
7 + 
x 8

The code

{{indent}}{{math|
? {{=}} {{cfrac|0;; ''x''//1,, ''x''{{^|2|tex}}//2,, ''x''{{^|3|tex}}//3,, ''x''{{^|4|tex}}//4,, ''x''{{^|5|tex}}//5,, <!--
-->''x''{{^|6|tex}}//6,, ''x''{{^|7|tex}}//7,, ''x''{{^|8|tex}}//|TEX}}
|$$}}

yields the display style LaTeX

     

The code

{{indent}}{{math|
? {{=}} {{cfrac|0;; ''x''//1,, ''x''{{^|2}}//2,, ''x''{{^|3}}//3,, ''x''{{^|4}}//4|HTM}}
|&&}}

yields the display style HTML+CSS

     
? = 0 + 
x
1 + 
x 2
2 + 
x 3
3 + 
x 4
4

The code

{{indent}}{{math|
? {{=}} {{cfrac|0;; ''x''//1,, ''x''{{^|2|tex}}//2,, ''x''{{^|3|tex}}//3,, ''x''{{^|4|tex}}//4|TEX}}
|$$}}

yields the display style LaTeX

     

The code

{{indent}}{{math|
? {{=}} {{cfrac|0;; ''x''//1,, ''x''{{^|2}}//2,, ''x''{{^|3}}//3,, ''x''{{^|4}}//|HTM}}
|&&}}

yields the display style HTML+CSS

     
? = 0 + 
x
1 + 
x 2
2 + 
x 3
3 + 
x 4

The code

{{indent}}{{math|
? {{=}} {{cfrac|0;; ''x''//1,, ''x''{{^|2|tex}}//2,, ''x''{{^|3|tex}}//3,, ''x''{{^|4|tex}}//|TEX}}
|$$}}

yields the display style LaTeX

     

Simple continued fraction for π

The code

{{indent}}{{math|{{Gr|pi}} {{=}} {{cfrac|3;; 1//7,, 1//15,, 1//1,, 1//292,, 1//1,, 1//1,, 1 //|HTM}}
|tex = \pi = {{cfrac|3;; 1//7,, 1//15,, 1//1,, 1//292,, 1//1,, 1//1,, 1 //|TEX}}|&&}}

yields the display style HTML+CSS

     
π = 3 + 
1
7 + 
1
15 + 
1
1 + 
1
292 + 
1
1 + 
1
1 + 
1

and with the $$ option, yields the LaTeX

     

Continued fraction with minus signs

The code

{{indent}}{{math|''G''{{sub|{''a''{{sub|''n''|80%}}{{sp|1}}, ''n''{{rel|ge}}0} }}(''x'') {{=|sp}} {{cfrac|;; 1 // 1 ,-, ''x'' // 1 ,, ''x''{{^|2}} // 1 ,-, ''x''{{^|3}} // 1 ,, ''x''{{^|4}} //|HTM}}
|tex = G_{ \{ a_n,\, n \ge 0 \} }(x) = {{cfrac|;; 1 // 1 ,-, x // 1 ,, x^2 // 1 ,-, x^3 // 1 ,, x^4 //|TEX}}<!-- \cfrac{1}{1 - \cfrac{x}{1 + \cfrac{x^2}{1 - \cfrac{x^3}{1 + \cfrac{x^4}{\ddots} } } } } -->,|&&}}

yields the display style HTML+CSS (NOT RIGHT: should be minus signs in front of odd powers of x only; template needs more work...)

     
G{an , n  ≥  0}(x)  = 
1
1 − 
x
1 − 
x 2
1 − 
x 3
1 − 
x 4

Two-dimensional continued fractions

Example from (with commas added to separate the two-dimensional subscript indices: for testing purposes): http://www.sciencedirect.com/science/article/pii/S0377042799000308

The code

{{indent}}{{math|
''f''{{sub|2}} {{=}} <!--
-->{{cfrac| ;; ''a''{{sub|0}} // <!--
-->''b''{{sub|0}} + <!--
-->{{cfrac|;; ''a''{{sub|1,0}}//''b''{{sub|1,0}} ,, ''a''{{sub|2,0}}//''b''{{sub|2,0}} ,, ''a''{{sub|3,0}}//|HTM}} + <!--
-->{{cfrac|;; ''a''{{sub|0,1}}//''b''{{sub|0,1}} ,, ''a''{{sub|0,2}}//''b''{{sub|0,2}} ,, ''a''{{sub|0,3}}//|HTM}} + <!--
-->{{cfrac|;; ''a''{{sub|1}}//''b''{{sub|1}} ,, <!--
  -->{{tfrac|''a''{{sub|2,1}}|''b''{{sub|2,1}}|HTM}} + {{tfrac|''a''{{sub|1,2}}|''b''{{sub|1,2}}|HTM}} + {{tfrac|''a''{{sub|2}}|''b''{{sub|2}}|HTM}}
   |HTM}}
|HTM}}
|&&}}

yields the display style HTML+CSS

     
Error: String exceeds 10,000 character limit.

The code

{{indent}}{{math|
''f''{{sub|2|tex}} {{=}} <!--
-->{{cfrac| ;; ''a''{{sub|0|tex}} // <!--
-->''b''{{sub|0|tex}} + <!--
-->{{cfrac|;; ''a''{{sub|1,0|tex}}//''b''{{sub|1,0|tex}} ,, ''a''{{sub|2,0|tex}}//''b''{{sub|2,0|tex}} ,, ''a''{{sub|3,0|tex}}//|TEX}} + <!--
-->{{cfrac|;; ''a''{{sub|0,1|tex}}//''b''{{sub|0,1|tex}} ,, ''a''{{sub|0,2|tex}}//''b''{{sub|0,2|tex}} ,, ''a''{{sub|0,3|tex}}//|TEX}} + <!--
-->{{cfrac|;; ''a''{{sub|1|tex}}//''b''{{sub|1|tex}} ,, <!--
  -->{{tfrac|''a''{{sub|2,1|tex}}|''b''{{sub|2,1|tex}}|TEX}} + {{tfrac|''a''{{sub|1,2|tex}}|''b''{{sub|1,2|tex}}|TEX}} + <!--
  -->{{tfrac|''a''{{sub|2|tex}}|''b''{{sub|2|tex}}|TEX}}
   |TEX}}
|TEX}}
|$$}}

yields the display style LaTeX

     

More examples

For more examples, see

Convergents

See Continued fractions#Generalized continued fractions convergents.

The code

: Convergents numerators {{math|''p''{{sub|''i''}}{{sp|1}}, ''i'' {{rel|ge}} 0|tex = p_i,\, i \ge 0|&}}: {{mathfont|{{set|{{cfrac|3;; 1//7,, 1//15,, 1//1,, 1//292,, 1//1,, 1//1,, 1 //|convnums}}}}}}
: Convergents denominators {{math|''q''{{sub|''i''}}{{sp|1}}, ''i'' {{rel|ge}} 0|tex = q_i,\, i \ge 0|&}}: {{mathfont|{{set|{{cfrac|3;; 1//7,, 1//15,, 1//1,, 1//292,, 1//1,, 1//1,, 1 //|convdens}}}}}}

yields

Convergents numerators
pi , i   ≥   0
: {3, 22}
Convergents denominators
qi , i   ≥   0
: {1, 7}

Tests

The following tests show

  • why we have to use ;; instead of ; between the integer part and the partial quotients;
  • why we have to use // instead of / for the partial quotients;
  • and why (since some CSS use comma separated values) we better use ,, instead of , to separate the partial quotients.

The code

{{pre|
{{#explode: ''x''{{^|2}};2|;|0}} ''and'' {{#explode: ''x''{{^|2}};2|;|1}}{{nl}}
{{#explode: ''x''{{^|2}};;2|;;|0}} ''and'' {{#explode: ''x''{{^|2}};;2|;;|1}}{{nl}}
{{#explode: ''x''{{^|2}}/2|/|0}} ''and'' {{#explode: ''x''{{^|2}}/2|/|1}}{{nl}}
{{#explode: ''x''{{^|2}}//2|//|0}} ''and'' {{#explode: ''x''{{^|2}}//2|//|1}}
|/pre}}

yields (see how the first and third lines inside {{pre|...|/pre}} failed to parse properly)

''x''<span style="position: relative ''and''  vertical-align: 1.25ex<br />
''x''<span style="position: relative; vertical-align: 1.25ex; line-height: 0.75ex; font-size: 0.75em;"><span style="position: relative; vertical-align: middle;"> 2</span></span> ''and'' 2<br />
''x''<span style="position: relative; vertical-align: 1.25ex; line-height: 0.75ex; font-size: 0.75em;"><span style="position: relative; vertical-align: middle;"> 2< ''and'' span><<br />
''x''<span style="position: relative; vertical-align: 1.25ex; line-height: 0.75ex; font-size: 0.75em;"><span style="position: relative; vertical-align: middle;"> 2</span></span> ''and'' 2

See also

  • {{nroot}} (typesets [generalized] nested radicals in either HTML+CSS or LaTeX) (finite or infinite [generalized] continued fractions are a particular case of finite or infinite [generalized] nested radicals with root indices all equal to 
     − 1
    )