views:

101

answers:

2

Out of pure interested, I'm curious how to create PI sequentially so that instead of the number being produced after the outcome of the process, allow the numbers to display as the process itself is being generated. If this is the case, then the number could produce itself, and I could implement garbage collection on previously seen numbers thus creating an infinite series. The outcome is just a number being generated every second that follows the series of Pi.

Here's what I've found sifting through the internets :

This it the popular computer-friendly algorithm, The Machin-like 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  A: 

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

The formula is:

Hexadecimal expansion of pi

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

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

More info: http://www.sciencenews.org/sn_arc98/2_28_98/mathland.htm

Moron
+2  A: 

To expand on "Moron's" answer: What the Bailey-Borwein-Plouffe formula does for you is that it lets you compute binary (or equivalently hex) digits of pi without computing all of the digits before it. This formula was used to compute the quadrillionth bit of pi ten years ago. It's a 0. (I'm sure that you were on the edge of your seat to find out.)

This is not the same thing as a low-memory, dynamic algorithm to compute the bits or digits of pi, which I think what you could mean by "sequentially". I don't think that anyone knows how to do that in base 10 or in base 2, although the BPP algorithm can be viewed as a partial solution.

Well, some of the iterative formula for pi are also sort-of like a sequential algorithm, in the sense that there is an iteration that produces more digits with each round. However, it's also only a partial solution, because typically the number of digits doubles or triples with each step. So you'd wait with a lot of digits for a while, and the whoosh a lot more digits come quickly.

In fact, I don't know if there is any low-memory, efficient algorithm to produce digits of any standard irrational number. Even for e, you'd think that the standard infinite series is an efficient formula and that it's low-memory. But it only looks low memory at the beginning, and actually there are also faster algorithms to compute many digits of e.

Greg Kuperberg
interesting :) I heard about that quadrillionth bit of pi from a guy at work, he was also not sure why anyone would need to know it...
ldog
Honestly no one in pure mathematics really cares about any of these megacomputations such as Mersenne primes or the zillionth digit of pi. The algorithms are considered interesting. For instance, it is not known whether the digits of pi use all 16 hex digits or all 10 decimal digits infinitely often. Of course everyone believes it, but no one can prove it. The BPP algorithm could be a useful clue for that problem.
Greg Kuperberg
@Greg: We can definitely give algorithms for find nth digit (any base, not just binary or decimal) after decimal point of sqrt(2) which does not have to rely on previous digits. Perhaps you would be interested in reading: http://stackoverflow.com/questions/2963392/0-1-knapsack-with-irrational-weights/2968021#2968021
Moron
You might be interested in this paper: http://www.cs.nyu.edu/exact/doc/pi-log.pdf
Moron
Yes, it is interesting!
Greg Kuperberg