%% Created by Maple 18.00 (IBM INTEL NT)
%% Source Worksheet: confrac_samples.mws
%% Generated: Fri Oct 07 08:31:14 2016
\documentclass{article}
\usepackage{maple2e}
 \def\emptyline{\vspace{12pt}}
\DefineParaStyle{Heading 1}
\DefineParaStyle{Maple Output}
\DefineParaStyle{Maple Output}
\DefineParaStyle{Maple Output}
\DefineCharStyle{2D Comment}
\DefineCharStyle{2D Math}
\DefineCharStyle{2D Output}
\DefineCharStyle{Plot Text}
\DefineCharStyle{Popup}
\begin{document}
\pagestyle{empty}
\begin{maplegroup}
\begin{flushleft}
{\large The Brouncker algorithm for the continued fractions of a root
of a quadratic.}
\end{flushleft}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{with(linalg):}{%
}
\end{mapleinput}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\end{mapleinput}

\end{maplegroup}

\section{ Basic calculations and functions.}

\begin{maplegroup}
\begin{flushleft}
To start, we create a matrix from  
\mapleinline{inert}{2d}{ x^2-7*y^2;}{%
$x^{2} - 7\,y^{2}$%
}
\end{flushleft}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{A:=matrix(2,4,[1,0,1,0,0,1,0,-7]);}{%
}
\end{mapleinput}

\begin{mapleinput}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{A := matrix([[1, 0, 1, 0], [0, 1, 0, -7]]);}{%
\[
A :=  \left[ 
{\begin{array}{rrrr}
1 & 0 & 1 & 0 \\
0 & 1 & 0 & -7
\end{array}}
 \right] 
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{flushleft}
The function "fun" produces a polynomial in x,y from a 2 x 2 matrix.
We need its values to calculate  steps.
\end{flushleft}

\emptyline
\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\end{mapleinput}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{fun:=m-> unapply(m[1,3]*x^2+2*m[1,4]*x*y+m[2,4]*y^2,x,y);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{fun := m -> unapply(x^2*m[1,3]+2*x*y*m[1,4]+y^2*m[2,4],x,y);}{%
\[
\mathit{fun} := m\rightarrow \mathrm{unapply}(x^{2}\,{m_{1, \,3}}
 + 2\,x\,y\,{m_{1, \,4}} + y^{2}\,{m_{2, \,4}}, \,x, \,y)
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{fun(A)(x,y);fun(A)(3,1);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{x^2-7*y^2;}{%
\[
x^{2} - 7\,y^{2}
\]
%
}
\end{maplelatex}

\begin{maplelatex}
\mapleinline{inert}{2d}{2;}{%
\[
2
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{flushleft}
The function ch(m,t,n) changes matrix m as follows: 
\end{flushleft}

\begin{flushleft}
If n=1 then it add t times row 1 to row 2. 
\end{flushleft}

\begin{flushleft}
If n=2 it adds t times row 2 to row 1. 
\end{flushleft}

\begin{flushleft}
Then it makes  a symmetric matrix operation on the last two columns.
\end{flushleft}

\emptyline
\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{ch:=proc(m,t,n) local tmp:
tmp:=copy(m); if n=1 then  tmp:=addrow(tmp,1,2,t);
tmp:=addcol(tmp,3,4,t);
elif n=2 then 
tmp:=addrow(tmp,2,1,t);tmp:=addcol(tmp,4,3,t);fi;op(tmp);end:}{%
}
\end{mapleinput}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\end{mapleinput}

\end{maplegroup}

\section{Case of 
\mapleinline{inert}{2d}{sqrt(7);}{%
$\sqrt{7}$%
}}

\begin{maplegroup}
\begin{flushleft}
\textbf{We start work on 
\mapleinline{inert}{2d}{x^2-7*y^2;}{%
$x^{2} - 7\,y^{2}$%
} . }
\end{flushleft}

\begin{flushleft}
\textbf{We shall record the t-values as we proceed}.
\end{flushleft}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{A:=matrix(2,4,[1,0,1,0,0,1,0,-7]);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{A := matrix([[1, 0, 1, 0], [0, 1, 0, -7]]);}{%
\[
A :=  \left[ 
{\begin{array}{rrrr}
1 & 0 & 1 & 0 \\
0 & 1 & 0 & -7
\end{array}}
 \right] 
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{flushleft}
We check the function at (1,1); 
\end{flushleft}

\begin{flushleft}
{\large If it is negative,} then we try values at (t,1) and stop just
before the values change sign.
\end{flushleft}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{fun(A)(1,1); fun(A)(2,1);fun(A)(3,1);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{-6;}{%
\[
-6
\]
%
}
\end{maplelatex}

\begin{maplelatex}
\mapleinline{inert}{2d}{-3;}{%
\[
-3
\]
%
}
\end{maplelatex}

\begin{maplelatex}
\mapleinline{inert}{2d}{2;}{%
\[
2
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{flushleft}
So set t=2 and n=1(because the value at (1,1) was less than 1.)
\end{flushleft}

\emptyline
\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{tvals:=[2];}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{tvals := [2];}{%
\[
\mathit{tvals} := [2]
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{A1:=ch(A,2,1);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{A1 := matrix([[1, 0, 1, 2], [2, 1, 2, -3]]);}{%
\[
\mathit{A1} :=  \left[ 
{\begin{array}{rrrr}
1 & 0 & 1 & 2 \\
2 & 1 & 2 & -3
\end{array}}
 \right] 
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{flushleft}
Repeat with new matrix. Here, the {\large value at (1,1) is bigger
than 1}, so we try (1,t), until sign changes.
\end{flushleft}

\emptyline
\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{fun(A1)(1,1);fun(A1)(1,2);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{2;}{%
\[
2
\]
%
}
\end{maplelatex}

\begin{maplelatex}
\mapleinline{inert}{2d}{-3;}{%
\[
-3
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{flushleft}
So we set t=1 and n=2 (because the value at (1,1) was bigger  than 1.)
\end{flushleft}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{tvals:=[op(tvals),1];}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{tvals := [2, 1];}{%
\[
\mathit{tvals} := [2, \,1]
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{A2:=ch(A1,1,2);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{A2 := matrix([[3, 1, 2, -1], [2, 1, -1, -3]]);}{%
\[
\mathit{A2} :=  \left[ 
{\begin{array}{rrrr}
3 & 1 & 2 & -1 \\
2 & 1 & -1 & -3
\end{array}}
 \right] 
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{flushleft}
Repeat! Again, we get t=1, n=1.
\end{flushleft}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{fun(A2)(1,1);fun(A2)(2,1);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{-3;}{%
\[
-3
\]
%
}
\end{maplelatex}

\begin{maplelatex}
\mapleinline{inert}{2d}{1;}{%
\[
1
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{tvals:=[op(tvals),1];}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{tvals := [2, 1, 1];}{%
\[
\mathit{tvals} := [2, \,1, \,1]
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{A3:=ch(A2,1,1);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{A3 := matrix([[3, 1, 2, 1], [5, 2, 1, -3]]);}{%
\[
\mathit{A3} :=  \left[ 
{\begin{array}{rrrr}
3 & 1 & 2 & 1 \\
5 & 2 & 1 & -3
\end{array}}
 \right] 
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{fun(A3)(1,1); }{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{1;}{%
\[
1
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
This is a special case. When the function evalutes to 1, then set t=1
and reverse the order of row operations (i.e. change n from 1 to 2 or
2 to 1.

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{tvals:=[op(tvals),1];}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{tvals := [2, 1, 1, 1];}{%
\[
\mathit{tvals} := [2, \,1, \,1, \,1]
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{A4:=ch(A3,1,2);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{A4 := matrix([[8, 3, 1, -2], [5, 2, -2, -3]]);}{%
\[
\mathit{A4} :=  \left[ 
{\begin{array}{rrrr}
8 & 3 & 1 & -2 \\
5 & 2 & -2 & -3
\end{array}}
 \right] 
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{fun(A4)(1,1);fun(A4)(2,1);fun(A4)(3,1);fun(A4)(4,1);fun(A4)(5,1);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{-6;}{%
\[
-6
\]
%
}
\end{maplelatex}

\begin{maplelatex}
\mapleinline{inert}{2d}{-7;}{%
\[
-7
\]
%
}
\end{maplelatex}

\begin{maplelatex}
\mapleinline{inert}{2d}{-6;}{%
\[
-6
\]
%
}
\end{maplelatex}

\begin{maplelatex}
\mapleinline{inert}{2d}{-3;}{%
\[
-3
\]
%
}
\end{maplelatex}

\begin{maplelatex}
\mapleinline{inert}{2d}{2;}{%
\[
2
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{flushleft}
Now we get t=4, n=1.
\end{flushleft}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{tvals:=[op(tvals),4];}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{tvals := [2, 1, 1, 1, 4];}{%
\[
\mathit{tvals} := [2, \,1, \,1, \,1, \,4]
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{A5:=ch(A4,4,1);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{A5 := matrix([[8, 3, 1, 2], [37, 14, 2, -3]]);}{%
\[
\mathit{A5} :=  \left[ 
{\begin{array}{rrrr}
8 & 3 & 1 & 2 \\
37 & 14 & 2 & -3
\end{array}}
 \right] 
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{seq(cat(A,i)=op(cat(A,i)),i=1..5);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{A1 = matrix([[1, 0, 1, 2], [2, 1, 2, -3]]), A2 = matrix([[3, 1, 2,
-1], [2, 1, -1, -3]]), A3 = matrix([[3, 1, 2, 1], [5, 2, 1, -3]]), A4
= matrix([[8, 3, 1, -2], [5, 2, -2, -3]]), A5 = matrix([[8, 3, 1, 2],
[37, 14, 2, -3]]);}{%
\maplemultiline{
\mathit{A1}= \left[ 
{\begin{array}{rrrr}
1 & 0 & 1 & 2 \\
2 & 1 & 2 & -3
\end{array}}
 \right] , \,\mathit{A2}= \left[ 
{\begin{array}{rrrr}
3 & 1 & 2 & -1 \\
2 & 1 & -1 & -3
\end{array}}
 \right] , \,\mathit{A3}= \left[ 
{\begin{array}{rrrr}
3 & 1 & 2 & 1 \\
5 & 2 & 1 & -3
\end{array}}
 \right] , \,\mathit{A4}= \left[ 
{\begin{array}{rrrr}
8 & 3 & 1 & -2 \\
5 & 2 & -2 & -3
\end{array}}
 \right] ,  \\
\mathit{A5}= \left[ 
{\begin{array}{rrrr}
8 & 3 & 1 & 2 \\
37 & 14 & 2 & -3
\end{array}}
 \right]  }
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{flushleft}
Note that A1 and A4 have a{\large  repeat of the second part}.  So,
now the pattern repeats!
\end{flushleft}

\emptyline
\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{convert(sqrt(7), confrac,10,'ans7');}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{[2, 1, 1, 1, 4, 1, 1, 1, 4, 1];}{%
\[
[2, \,1, \,1, \,1, \,4, \,1, \,1, \,1, \,4, \,1]
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{ans7;}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{[2, 3, 5/2, 8/3, 37/14, 45/17, 82/31, 127/48, 590/223, 717/271];}{%
\[
[2, \,3, \,{\displaystyle \frac {5}{2}} , \,{\displaystyle 
\frac {8}{3}} , \,{\displaystyle \frac {37}{14}} , \,
{\displaystyle \frac {45}{17}} , \,{\displaystyle \frac {82}{31}
} , \,{\displaystyle \frac {127}{48}} , \,{\displaystyle \frac {
590}{223}} , \,{\displaystyle \frac {717}{271}} ]
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{evalf(ans7);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{[2., 3., 2.500000000, 2.666666667, 2.642857143, 2.647058824,
2.645161290, 2.645833333, 2.645739910, 2.645756458];}{%
\maplemultiline{
[2., \,3., \,2.500000000, \,2.666666667, \,2.642857143, \,
2.647058824, \,2.645161290,  \\
2.645833333, \,2.645739910, \,2.645756458] }
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{seq(evalf[20](sqrt(7)-ans7[i]),i=1..nops(ans7));}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{.6457513110645905905, -.3542486889354094095, .1457513110645905905,
-.209153556020760762e-1, .28941682074477334e-2,
-.13075124648211742e-2, .5900207420099453e-3, -.820222687427428e-4,
.114007506892452e-4, -.51464999850553e-5;}{%
\maplemultiline{
0.6457513110645905905, \,-0.3542486889354094095, \,
0.1457513110645905905,  \\
-0.0209153556020760762, \,0.0028941682074477334, \,
-0.0013075124648211742,  \\
0.0005900207420099453, \,-0.0000820222687427428, \,
0.0000114007506892452,  \\
-0.51464999850553\,10^{-5} }
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\end{mapleinput}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\end{mapleinput}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\end{mapleinput}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\end{mapleinput}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\end{mapleinput}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\end{mapleinput}

\end{maplegroup}

\section{Case of 
\mapleinline{inert}{2d}{sqrt(12);}{%
$\sqrt{12}$%
}}

\begin{maplegroup}
\begin{flushleft}
\textbf{{\large We set D=12. This should be non square.}}
\end{flushleft}

\end{maplegroup}
\begin{maplegroup}
\begin{flushleft}
\textbf{{\large Starting matrix}}
\end{flushleft}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{A:=matrix(2,4,[1,0,1,0,0,1,0,-12]);tvals:=[];}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{A := matrix([[1, 0, 1, 0], [0, 1, 0, -12]]);}{%
\[
A :=  \left[ 
{\begin{array}{rrrr}
1 & 0 & 1 & 0 \\
0 & 1 & 0 & -12
\end{array}}
 \right] 
\]
%
}
\end{maplelatex}

\begin{maplelatex}
\mapleinline{inert}{2d}{tvals := [];}{%
\[
\mathit{tvals} := []
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{flushleft}
{\large }\QTR{Popup}{Check the value of fun at (1,1).}
\end{flushleft}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{fun(A)(x,y);fun(A)(1,1);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{x^2-12*y^2;}{%
\[
x^{2} - 12\,y^{2}
\]
%
}
\end{maplelatex}

\begin{maplelatex}
\mapleinline{inert}{2d}{-11;}{%
\[
-11
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{flushleft}
{\large \textbf{For a negative value (or \TEXTsymbol{<} 1), we
increase the first coordinate until sign changes. Add the tvalue just
before the change to the list.}}
\end{flushleft}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{seq([t,fun(A)(t,1)],t=1..5);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{[1, -11], [2, -8], [3, -3], [4, 4], [5, 13];}{%
\[
[1, \,-11], \,[2, \,-8], \,[3, \,-3], \,[4, \,4], \,[5, \,13]
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{flushleft}
\QTR{Popup}{Thus 3 is the turning point.}
\end{flushleft}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{tvals:=[op(tvals),3];}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{tvals := [3];}{%
\[
\mathit{tvals} := [3]
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{flushleft}
\QTR{Popup}{ch does the necessary row/col operations.}
\end{flushleft}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{A1:=ch(A,3,1);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{A1 := matrix([[1, 0, 1, 3], [3, 1, 3, -3]]);}{%
\[
\mathit{A1} :=  \left[ 
{\begin{array}{rrrr}
1 & 0 & 1 & 3 \\
3 & 1 & 3 & -3
\end{array}}
 \right] 
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{fun(A1)(1,1);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{4;}{%
\[
4
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{flushleft}
\textbf{{\large Since the value is bigger than 1, we increase the
second coordinate.}}
\end{flushleft}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{seq([t,fun(A1)(1,t)],t=1..5);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{[1, 4], [2, 1], [3, -8], [4, -23], [5, -44];}{%
\[
[1, \,4], \,[2, \,1], \,[3, \,-8], \,[4, \,-23], \,[5, \,-44]
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{tvals:=[op(tvals),2];A2:=ch(A1,2,2);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{tvals := [3, 2];}{%
\[
\mathit{tvals} := [3, \,2]
\]
%
}
\end{maplelatex}

\begin{maplelatex}
\mapleinline{inert}{2d}{A2 := matrix([[7, 2, 1, -3], [3, 1, -3, -3]]);}{%
\[
\mathit{A2} :=  \left[ 
{\begin{array}{rrrr}
7 & 2 & 1 & -3 \\
3 & 1 & -3 & -3
\end{array}}
 \right] 
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{fun(A2)(1,1);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{-8;}{%
\[
-8
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{seq([t,fun(A2)(t,1)],t=1..10);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{[1, -8], [2, -11], [3, -12], [4, -11], [5, -8], [6, -3], [7, 4], [8,
13], [9, 24], [10, 37];}{%
\[
[1, \,-8], \,[2, \,-11], \,[3, \,-12], \,[4, \,-11], \,[5, \,-8]
, \,[6, \,-3], \,[7, \,4], \,[8, \,13], \,[9, \,24], \,[10, \,37]
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{tvals:=[op(tvals),6];A3:=ch(A2,6,1);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{tvals := [3, 2, 6];}{%
\[
\mathit{tvals} := [3, \,2, \,6]
\]
%
}
\end{maplelatex}

\begin{maplelatex}
\mapleinline{inert}{2d}{A3 := matrix([[7, 2, 1, 3], [45, 13, 3, -3]]);}{%
\[
\mathit{A3} :=  \left[ 
{\begin{array}{rrrr}
7 & 2 & 1 & 3 \\
45 & 13 & 3 & -3
\end{array}}
 \right] 
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{fun(A3)(1,1);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{4;}{%
\[
4
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{seq([t,fun(A3)(1,t)],t=1..5);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{[1, 4], [2, 1], [3, -8], [4, -23], [5, -44];}{%
\[
[1, \,4], \,[2, \,1], \,[3, \,-8], \,[4, \,-23], \,[5, \,-44]
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{tvals:=[op(tvals),2];}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{tvals := [3, 2, 6, 2];}{%
\[
\mathit{tvals} := [3, \,2, \,6, \,2]
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{A4:=ch(A3,2,2);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{A4 := matrix([[97, 28, 1, -3], [45, 13, -3, -3]]);}{%
\[
\mathit{A4} :=  \left[ 
{\begin{array}{rrrr}
97 & 28 & 1 & -3 \\
45 & 13 & -3 & -3
\end{array}}
 \right] 
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{13;}{%
\[
13
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{seq(cat(A,i)=op(cat(A,i)),i=1..4);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{A1 = matrix([[1, 0, 1, 3], [3, 1, 3, -3]]), A2 = matrix([[7, 2, 1,
-3], [3, 1, -3, -3]]), A3 = matrix([[7, 2, 1, 3], [45, 13, 3, -3]]),
A4 = matrix([[97, 28, 1, -3], [45, 13, -3, -3]]);}{%
\[
\mathit{A1}= \left[ 
{\begin{array}{rrrr}
1 & 0 & 1 & 3 \\
3 & 1 & 3 & -3
\end{array}}
 \right] , \,\mathit{A2}= \left[ 
{\begin{array}{rrrr}
7 & 2 & 1 & -3 \\
3 & 1 & -3 & -3
\end{array}}
 \right] , \,\mathit{A3}= \left[ 
{\begin{array}{rrrr}
7 & 2 & 1 & 3 \\
45 & 13 & 3 & -3
\end{array}}
 \right] , \,\mathit{A4}= \left[ 
{\begin{array}{rrrr}
97 & 28 & 1 & -3 \\
45 & 13 & -3 & -3
\end{array}}
 \right] 
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{tvals;}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{[3, 2, 6, 2];}{%
\[
[3, \,2, \,6, \,2]
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\mapleresult
\begin{maplettyout}
Note that A4 and A2 share the same RHS.  So the sequence [2,6] will
repeat!
\end{maplettyout}

\end{maplegroup}
\begin{maplegroup}
\mapleresult
\begin{maplettyout}
\textbf{{\large Doublecheck using Maple directly!}}
\end{maplettyout}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{unassign('ans12');convert(sqrt(12),confrac,12,ans12);# calculates 12
"a"s.}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{[3, 2, 6, 2, 6, 2, 6, 2, 6, 2, 6, 2];}{%
\[
[3, \,2, \,6, \,2, \,6, \,2, \,6, \,2, \,6, \,2, \,6, \,2]
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{ans12;# successive continued fractions.}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{[3, 7/2, 45/13, 97/28, 627/181, 1351/390, 8733/2521, 18817/5432,
121635/35113, 262087/75658, 1694157/489061, 3650401/1053780];}{%
\[
[3, \,{\displaystyle \frac {7}{2}} , \,{\displaystyle \frac {45}{
13}} , \,{\displaystyle \frac {97}{28}} , \,{\displaystyle 
\frac {627}{181}} , \,{\displaystyle \frac {1351}{390}} , \,
{\displaystyle \frac {8733}{2521}} , \,{\displaystyle \frac {
18817}{5432}} , \,{\displaystyle \frac {121635}{35113}} , \,
{\displaystyle \frac {262087}{75658}} , \,{\displaystyle \frac {
1694157}{489061}} , \,{\displaystyle \frac {3650401}{1053780}} ]
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{evalf(\%);#evaluations.}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{[3., 3.500000000, 3.461538462, 3.464285714, 3.464088398, 3.464102564,
3.464101547, 3.464101620, 3.464101615, 3.464101615, 3.464101615,
3.464101615];}{%
\maplemultiline{
[3., \,3.500000000, \,3.461538462, \,3.464285714, \,3.464088398, 
\,3.464102564, \,3.464101547,  \\
3.464101620, \,3.464101615, \,3.464101615, \,3.464101615, \,
3.464101615] }
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{evalf[20](sqrt(12));}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{3.4641016151377545870;}{%
\[
3.4641016151377545870
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{seq(evalf[20](sqrt(12)-ans12[i]),i=1..12);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{.4641016151377545870, -.358983848622454130e-1, .25631535992930485e-2,
-.1840991479596987e-3, .132173476993384e-4, -.9489648095156e-6,
.681325979031e-7, -.48917004940e-8, .3512082936e-9, -.252156210e-10,
.18104001e-11, -.1299809e-12;}{%
\maplemultiline{
0.4641016151377545870, \,-0.0358983848622454130, \,
0.0025631535992930485,  \\
-0.0001840991479596987, \,0.0000132173476993384, \,
-0.9489648095156\,10^{-6},  \\
0.681325979031\,10^{-7}, \,-0.48917004940\,10^{-8}, \,
0.3512082936\,10^{-9},  \\
-0.252156210\,10^{-10}, \,0.18104001\,10^{-11}, \,-0.1299809\,10
^{-12} }
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\end{mapleinput}

\end{maplegroup}
\end{document}
%% End of Maple 18.00 Output
