Continued fraction/Arithmetic: Difference between revisions

From Rosetta Code
Content added Content deleted
Line 15: Line 15:
Consider a matrix NG:
Consider a matrix NG:
: <math>\begin{bmatrix}
: <math>\begin{bmatrix}
a_12 & a_1 & a_2 & a \\
a_{12} & a_1 & a_2 & a \\
b_12 & b_1 & b_2 & b
b_{12} & b_1 & b_2 & b
\end{bmatrix}
\end{bmatrix}
</math>
</math>
and a function G(matrix NG, Number N<sub>1</sub>, Number N<sub>2</sub>)
and a function G(matrix NG, Number N<sub>1</sub>, Number N<sub>2</sub>)
which returns:
which returns:
: <math>\frac{a_12*N_1*N_2 + a_1*N_1 + a_2*N_2 + a}{b_12*N_1*N_2 + b_1*N_1 + a_2*N_2 + b}</math>
: <math>\frac{a_{12}*N_1*N_2 + a_1*N_1 + a_2*N_2 + a}{b_{12}*N_1*N_2 + b_1*N_1 + a_2*N_2 + b}</math>
: Convince yourself that NG = :
: Convince yourself that NG = :
: <math>\begin{bmatrix}
: <math>\begin{bmatrix}

Revision as of 11:34, 6 February 2013

By popular demand, see Talk:Continued fraction#creating_a_continued_fraction and Talk:Continued fraction#Arithmetics.3F.3F, or be careful what you ask for.

This page is a placeholder for several subtasks which will eventually implement a function:

G(matrix NG, Continued Fraction N1, Continued Fraction N2)

which will perform basic mathmatical operations on continued fractions.

For these tasks continued fractions will be of the form:

so each may be described by the notation []

Continued fraction arithmetic/Continued fraction r2cf(Rational N)

During these tasks I shall use the function described in this task to create continued fractions from rational numbers.

Matrix NG

Consider a matrix NG:

and a function G(matrix NG, Number N1, Number N2) which returns:

Convince yourself that NG = :
adds N1 to N2
subtracts N2 from N1
multiplies N1 by N2
divides N1 by N2
calculates (3*N1 + 4) * (7*N2 - 5)
Note that with N1 = 22, N2 = 7, and NG = :
I could define the solution to be N1 = 1, N2 = 1 and NG = :
So I can define arithmetic as operations on this matrix which make a12, a1, a2, b12, b1, b2 zero and read the answer from a and b. This is more interesting when N1 and N2 are continued fractions, which is the subject of the following tasks.


  • Investigate G(matrix NG, Contined Fraction N)
  • The complete solution G(matrix NG, Continued Fraction N1, Continued Fraction N2)
  • Compare two continued fractions