This task performs the basic mathematical functions on 2 continued fractions. This requires the full version of matrix NG:
: <math>\begin{bmatrix}
  a_{12} & a_1 & a_2 & a \\
  b_{12} & b_1 & b_2 & b
\end{bmatrix}</math>
I may perform perform the following operations:
:Input the next term of continued fraction N<sub>1</sub>
:Input the next term of continued fraction N<sub>2</sub>
:Output a term of the continued fraction resulting from the operation.

I output a term if the integer parts of <math>\frac{a}{b}</math> and <math>\frac{a_1}{b_1}</math> and <math>\frac{a_2}{b_2}</math> and <math>\frac{a_{12}}{b_{12}}</math> are equal. Otherwise I input a term from continued fraction N<sub>1</sub> or continued fraction N<sub>2</sub>. If I need a term from N but N has no more terms I inject <math>\infty</math>.

When I input a term t from continued fraction N<sub>1</sub> I change my internal state:
: <math>\begin{bmatrix}
  a_{12} & a_1 & a_2 & a \\
  b_{12} & b_1 & b_2 & b \end{bmatrix}</math> is transposed thus <math>\begin{bmatrix}   a_2+a_{12}*t & a+a_1*t & a_{12} & a_1 \\
  b_2+b_{12}*t & b+b_1*t & b_{12} & b_1
\end{bmatrix}</math>

When I need a term from exhausted continued fraction N<sub>1</sub> I change my internal state:
: <math>\begin{bmatrix}
  a_{12} & a_1 & a_2 & a \\
  b_{12} & b_1 & b_2 & b \end{bmatrix}</math> is transposed thus <math>\begin{bmatrix}
  a_{12} & a_1 & a_{12} & a_1 \\
  b_{12} & b_1 & b_{12} & b_1
\end{bmatrix}</math>

When I input a term t from continued fraction N<sub>2</sub> I change my internal state:
: <math>\begin{bmatrix}
  a_{12} & a_1 & a_2 & a \\
  b_{12} & b_1 & b_2 & b \end{bmatrix}</math> is transposed thus <math>\begin{bmatrix}
  a_1+a_{12}*t & a_{12} & a+a_2*t & a_2 \\
  b_1+b_{12}*t & b_{12} & b+b_2*t & b_2
\end{bmatrix}</math>

When I need a term from exhausted continued fraction N<sub>2</sub> I change my internal state:
: <math>\begin{bmatrix}
  a_{12} & a_1 & a_2 & a \\
  b_{12} & b_1 & b_2 & b \end{bmatrix}</math> is transposed thus <math>\begin{bmatrix}
  a_{12} & a_{12} & a_2 & a_2 \\
  b_{12} & b_{12} & b_2 & b_2
\end{bmatrix}</math>

When I output a term t I change my internal state:
: <math>\begin{bmatrix}
  a_{12} & a_1 & a_2 & a \\
  b_{12} & b_1 & b_2 & b \end{bmatrix}</math> is transposed thus <math>\begin{bmatrix}
  b_{12} & b_1 & b_2 & b \\
  a_{12}-b_{12}*t & a_1-b_1*t & a_2-b_2*t & a-b*t
\end{bmatrix}</math>

When I need to choose to input from N<sub>1</sub> or N<sub>2</sub> I act:
: if b and b2 are zero I choose N<sub>1</sub>
: if b is zero I choose N<sub>2</sub>
: if b2 is zero I choose N<sub>2</sub>
: if abs(<math>\frac{a_1}{b_1}-\frac{a}{b})</math> is greater than abs(<math>\frac{a_2}{b_2}-\frac{a}{b})</math> I choose N<sub>1</sub>
: otherwise I choose N<sub>2</sub>

When performing arithmetic operation on two potentially infinite continued fractions it is possible to generate a rational number. eg <math>\sqrt{2}</math> * <math>\sqrt{2}</math> should produce 2. This will require either that I determine that my internal state is approaching infinity, or limiting the number of terms I am willing to input without producing any output.
