How to resolve the algorithm Continued fraction/Arithmetic/G(matrix ng, continued fraction n) step by step in the 11l programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Continued fraction/Arithmetic/G(matrix ng, continued fraction n) step by step in the 11l programming language

Table of Contents

Problem Statement

This task investigates mathmatical operations that can be performed on a single continued fraction. This requires only a baby version of NG: I may perform perform the following operations: I output a term if the integer parts of

a b

{\displaystyle {\frac {a}{b}}}

and

a

1

b

1

{\displaystyle {\frac {a_{1}}{b_{1}}}}

are equal. Otherwise I input a term from N. If I need a term from N but N has no more terms I inject

{\displaystyle \infty }

. When I input a term t my internal state:

[

a

1

a

b

1

b

]

{\displaystyle {\begin{bmatrix}a_{1}&a\b_{1}&b\end{bmatrix}}}

is transposed thus

[

a +

a

1

∗ t

a

1

b +

b

1

∗ t

b

1

]

{\displaystyle {\begin{bmatrix}a+a_{1}*t&a_{1}\b+b_{1}*t&b_{1}\end{bmatrix}}}

When I output a term t my internal state:

[

a

1

a

b

1

b

]

{\displaystyle {\begin{bmatrix}a_{1}&a\b_{1}&b\end{bmatrix}}}

is transposed thus

[

b

1

b

a

1

b

1

∗ t

a − b ∗ t

]

{\displaystyle {\begin{bmatrix}b_{1}&b\a_{1}-b_{1}t&a-bt\end{bmatrix}}}

When I need a term t but there are no more my internal state:

[

a

1

a

b

1

b

]

{\displaystyle {\begin{bmatrix}a_{1}&a\b_{1}&b\end{bmatrix}}}

is transposed thus

[

a

1

a

1

b

1

b

1

]

{\displaystyle {\begin{bmatrix}a_{1}&a_{1}\b_{1}&b_{1}\end{bmatrix}}}

I am done when b1 and b are zero. Demonstrate your solution by calculating: Using a generator for

2

{\displaystyle {\sqrt {2}}}

(e.g., from Continued fraction) calculate

1

2

{\displaystyle {\frac {1}{\sqrt {2}}}}

. You are now at the starting line for using Continued Fractions to implement Arithmetic-geometric mean without ulps and epsilons. The first step in implementing Arithmetic-geometric mean is to calculate

1 +

1

2

2

{\displaystyle {\frac {1+{\frac {1}{\sqrt {2}}}}{2}}}

do this now to cross the starting line and begin the race.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Continued fraction/Arithmetic/G(matrix ng, continued fraction n) step by step in the 11l programming language

Source code in the 11l programming language

T NG
   Int a1, a, b1, b
   F (a1, a, b1, b)
      .a1 = a1
      .a  = a
      .b1 = b1
      .b  = b

   F ingress(n)
      (.a, .a1) = (.a1, .a + .a1 * n)
      (.b, .b1) = (.b1, .b + .b1 * n)

   F needterm()
      R (.b == 0 | .b1 == 0) | !(.a I/ .b == .a1 I/ .b1)

   F egress()
      V n = .a I/ .b
      (.a, .b) = (.b, .a - .b * n)
      (.a1, .b1) = (.b1, .a1 - .b1 * n)
      R n

   F egress_done()
      I .needterm()
         (.a, .b) = (.a1, .b1)
      R .egress()

   F done()
      R .b == 0 & .b1 == 0

F r2cf(=n1, =n2)
   [Int] r
   L n2 != 0
      (n1, V t1_n2) = (n2, divmod(n1, n2))
      n2 = t1_n2[1]
      r [+]= t1_n2[0]
   R r

V data = [(‘[1;5,2] + 1/2’,      2,1,0,2, (13, 11)),
          (‘[3;7] + 1/2’,        2,1,0,2, (22,  7)),
          (‘[3;7] divided by 4’, 1,0,0,4, (22,  7))]

L(string, a1, a, b1, b, r) data
   print(‘#<20->’.format(string), end' ‘’)
   V op = NG(a1, a, b1, b)
   L(n) r2cf(r[0], r[1])
      I !op.needterm()
         print(‘ ’op.egress(), end' ‘’)
      op.ingress(n)
   L
      print(‘ ’op.egress_done(), end' ‘’)
      I op.done()
         L.break
   print()

  

You may also check:How to resolve the algorithm Parsing/RPN to infix conversion step by step in the EchoLisp programming language
You may also check:How to resolve the algorithm Input loop step by step in the Python programming language
You may also check:How to resolve the algorithm Sorting algorithms/Patience sort step by step in the Icon programming language
You may also check:How to resolve the algorithm Mutual recursion step by step in the Liberty BASIC programming language
You may also check:How to resolve the algorithm Thue-Morse step by step in the jq programming language