The continued fraction expansion of an irrational number $r$ is the sequence $a_0, a_1, a_2, \ldots, a_i \in$ $\mathbf{N}$, such that (in the limit)
$$
r=a_0+\frac{1}{a_1+\frac{1}{a_2+\ldots}}
$$
The $a_i$ can be found as follows. Let $r_0=r$. The first term, $a_0$, is equal to the integer part of $r_0$ :
$$
a_0=\left\lfloor r_0\right\rfloor \text {. }
$$
The fractional part of $r_0$ is $r_0-a_0$. Its reciprocal, $r_1=1 /\left(r_0-a_0\right)$, is therefore
$$
r_1=a_1+\frac{1}{a_2+\frac{1}{a_3+\ldots}} .
$$
Thus, we get
$$
a_1=\left\lfloor r_1\right\rfloor
$$
and so on.
1. Write a function continuedFraction $\left[r_{-}, n_{-}\right.$Integer $]$that computes the first $n$ elements of the continued fraction expansion of $r$ as the list $\left\{a_0, a_1, \ldots, a_{n-1}\right\}$. You can use a loop or program recursively.
2. Write a function continuedValue[1_List] that returns the number belonging to the initial segment $l=\left\{a_0, a_1, \ldots, a_{n-1}\right\}$ of a continued fraction.
3. Write a simple definition for continuedError $[r, n]$, which finds the absolute error of the continued fraction approximation of length $n$. This error is the absolute value of the difference of $r$ and the approximation with $n$ terms.
Here are the first 10 elements of $\pi$ 's continued fraction expansion.
$$
\begin{aligned}
& \text { In }[1]:=\text { continuedFraction }[\mathrm{Pi}, 10] \\
& \text { Out }[1]=\{3,7,15,1,292,1,1,1,2,1\}
\end{aligned}
$$
The numerical value of the previous continued fraction is this rational number.
The numerical value of the previous continued fraction is this rational number.
$$
\begin{aligned}
& \text { In }[2]:=\text { continuedValue[\%] } \\
& \text { Out }[2]=\frac{1146408}{364913}
\end{aligned}
$$
Here is the error of the 10-term approxima-
$$
\begin{aligned}
& \operatorname{In}[3]:=N[\text { continuedBrror }[\mathrm{Pi}, 10]] \\
& \text { Out }[3]=1.6107110^{-12}
\end{aligned}
$$
Note that coth 1 has an interesting expansion.
$$
\begin{aligned}
& \text { In }[4]:=\text { continuedPraction }[\operatorname{Coth}[1], 12] \\
& \text { Out }[4]=\{1,3,5,7,9,11,13,15,17,19,21,23\}
\end{aligned}
$$