![$ [a_0,a_1,\ldots, a_m]$](img1568.png) for some
 for some  .
We give an inductive definition of numbers
.
We give an inductive definition of numbers  and
 and  such that for all
 
such that for all  
 matrices
matrices 
 and
 and
 .  which we will repeatedly use to
deduce properties of the sequence of partial convergents
.  which we will repeatedly use to
deduce properties of the sequence of partial convergents
![$ [a_0,\ldots,a_k]$](img1577.png) .  
We will use Algorithm 1.1.13 to prove that every
rational number is represented by a continued fraction, as in
(5.1.1).
.  
We will use Algorithm 1.1.13 to prove that every
rational number is represented by a continued fraction, as in
(5.1.1).
 
where each
 is a real number and
 is a real number and  for all
 for all  .
.
 are all integers.
 are all integers.To get a feeling for continued fractions, observe that
| ![$\displaystyle [a_0]$](img1581.png) |  | |
| ![$\displaystyle [a_0, a_1]$](img1583.png) |  | |
| ![$\displaystyle [a_0, a_1, a_2]$](img1585.png) |  | 
| ![$\displaystyle [a_0, a_1, \ldots ,a_{n-1}, a_n]$](img1587.png) | ![$\displaystyle = \left[a_0, a_1, \ldots, a_{n-2}, a_{n-1} + \frac{1}{a_n}\right]$](img1588.png) | |
| ![$\displaystyle = a_0 + \frac{1}{[a_1,\ldots, a_n]}$](img1589.png) | ||
| ![$\displaystyle = [a_0, [a_1,\ldots, a_n]].$](img1590.png) | 
sage: continued_fraction(17/23) [0, 1, 2, 1, 5] sage: continued_fraction(e) [2, 1, 2, 1, 1, 4, 1, 1, 6, 1, 1, 8, 1, 1, 10, 1, 1, 12, 1, 1, 11]Use the optional second argument bits = n to determine the precision (in bits) of the input number that is used to compute the continued fraction.
sage: continued_fraction(e, bits=20) [2, 1, 2, 1, 1, 4, 1, 1, 6] sage: continued_fraction(e, bits=30) [2, 1, 2, 1, 1, 4, 1, 1, 6, 1, 1, 8, 1, 1]You can obtain the value of a continued fraction and even do arithmetic with continued fractions:
sage: a = continued_fraction(17/23); a [0, 1, 2, 1, 5] sage: a.value() 17/23 sage: b = continued_fraction(6/23); b [0, 3, 1, 5] sage: a + b [1]