How to create PI sequentially in Ruby

Out of pure interest, I’m interested in how to create PI sequentially, so that instead of the number created after the result of the process, allow numbers to be displayed as the process itself is created. If so, then the number can be produced by myself, and I could implement garbage collection on previously seen numbers, creating an endless series. The result is just the number generated every second that follows the Pi row.

Here is what I found screening through the Internet:

This is a popular computer algorithm similar to the Machin algorithm:

def arccot(x, unity) xpow = unity / x n = 1 sign = 1 sum = 0 loop do term = xpow / n break if term == 0 sum += sign * (xpow/n) xpow /= x*x n += 2 sign = -sign end sum end def calc_pi(digits = 10000) fudge = 10 unity = 10**(digits+fudge) pi = 4*(4*arccot(5, unity) - arccot(239, unity)) pi / (10**fudge) end digits = (ARGV[0] || 10000).to_i p calc_pi(digits) 
+4
source share
2 answers

To expand Moron's answer: what the Bailey-Borwain-Pluff formula does for you is that it allows you to calculate the binary (or equivalently hexadecimal) digits of pi without calculating all the digits in front of you. This formula was used to calculate the four inch pi bit ten years ago. This is 0. (I'm sure you were on the edge of your place to find out.)

This is not the same as a low memory algorithm, a dynamic algorithm for computing bits or digits pi, which I think can mean "sequentially." I don’t think anyone knows how to do this in base 10 or base 2, although the BPP algorithm can be considered as a partial solution.

Well, some of the iterative formulas for pi are also similar to a sequential algorithm, in the sense that there is an iteration that produces more digits with each round. However, this is also only a partial solution, because, as a rule, the number of digits doubles or triples with each step. This way you will wait with a lot of numbers for a while, and a lot more numbers will come quickly.

In fact, I don’t know if there is a low memory algorithm effective for generating digits of any standard irrational number. Even for e, you might think that the standard infinite series is an effective formula and that it has low memory. But at first it only looks with low memory, and in fact there are also faster algorithms for calculating many e digits.

+3
source

Perhaps you can work with hexadecimal? David Bailey, Peter Borwein, and Simon Pluff discovered the formula for the nth digit after the decimal point in the hexadecimal expansion of pi.

Formula:

Hexadecimal decomposition pi http://www.sciencenews.org/sn_arc98/2_28_98/math228.jpg

You can read more about this here: http://www.andrews.edu/~calkins/physics/Miracle.pdf

The question of whether such a formula exists for base 10 remains open.

Additional information: http://www.sciencenews.org/sn_arc98/2_28_98/mathland.htm

+4
source

Source: https://habr.com/ru/post/1314145/


All Articles