Continued fraction: Difference between revisions

Content added Content deleted
Line 1,584: Line 1,584:


{{FormulaeEntry|page=https://formulae.org/?script=examples/Continued_fraction}}
{{FormulaeEntry|page=https://formulae.org/?script=examples/Continued_fraction}}

The following function definition creates a continued fraction:

[[File:Fōrmulæ - Continued fraction 01.png]]

The function accepts the following parameters:

{| class="wikitable" style="margin:auto"
|-
! Parameter !! Description
|-
| a₀ || Value for a₀
|-
| λa || Lambda expression to define aᵢ
|-
| λb || Lambda expression to define bᵢ
|-
| depth || Depth to calculate the continued fraction
|}

Since Fōrmulæ arithmetic simplifies numeric results as they are generated, the result is not a continued fraction by default.

If we want to create the structure, we can introduce the parameters as string or text expressions (or lambda expressions that produce them). Because string or text expressions are not reduced when they are operands of additions and divisions, the structure is preserved, such as follows:

[[File:Fōrmulæ - Continued fraction 02.png]]

[[File:Fōrmulæ - Continued fraction 03.png]]

Case 1. <math>\sqrt 2</math>

In this case

* a₀ is 1
* λa is n ↦ 2
* λb is n ↦ 1

Let us show the results as a table, for several levels of depth (1 to 10).

The columns are:

* The depth
* The "textual" call, in order to generate the structure
* The normal (numeric) call. Since arithmetic operations are exact by default, it is usually a rational number.
* The value of the normal (numeric) call, forced to be shown as a decimal number, by using the Math.Numeric expression (the N(x) expression)

[[File:Fōrmulæ - Continued fraction 04.png]]

[[File:Fōrmulæ - Continued fraction 05.png]]

Case 2. <math>e</math>

In this case

* a₀ is 2
* λa is n ↦ n
* λb is n ↦ n - 1

[[File:Fōrmulæ - Continued fraction 06.png]]

[[File:Fōrmulæ - Continued fraction 07.png]]

Case 3. <math>\pi</math>

In this case

* a₀ is 3
* λa is n ↦ 6
* λb is n ↦ 2(n - 1)²

[[File:Fōrmulæ - Continued fraction 08.png]]

[[File:Fōrmulæ - Continued fraction 09.png]]


=={{header|Go}}==
=={{header|Go}}==