Continued fraction: Difference between revisions

Content added Content deleted
(→‎{{header|Perl 6}}: extra credit)
Line 725: Line 725:


The ''continued-fraction'' function thus returns a lazy list of functions where the variable plays the role of the «<math>\ddots</math>» symbol in the usual representation. The main advantage is that the definition of the function does not need to know for which rank n it is computed. This is arguably closer to the mathematical definition.
The ''continued-fraction'' function thus returns a lazy list of functions where the variable plays the role of the «<math>\ddots</math>» symbol in the usual representation. The main advantage is that the definition of the function does not need to know for which rank n it is computed. This is arguably closer to the mathematical definition.

'''Extra credit''':
The value of <math>\pi/2</math> can be related to a pseudo-continued fraction of the harmonic sequence:
:<math>\pi/2 = 1 + \cfrac{1}{1 + \cfrac{1}{1/2 + \cfrac{1}{1/3+ \ddots}}}</math>

With the same code as above, this could be written:

<lang Perl 6>printf "π/2 ≈ %.9f\n", continued-fraction((1 X/ 1, 1 .. *), (1 xx *))[1000](Inf);</lang>


=={{header|PL/I}}==
=={{header|PL/I}}==