Re: calculating PI





Charles Richmond wrote:
David Williams wrote:
-> I always liked the Montecarlo method for determining PI!

It's awfully slow, though!

I came across the following little thing on an old disk. It calculates
PI to amazing precision very quickly. I think someone gave it to me.
Maybe I understood it then, but not now. Can anyone tell me, please?

dow

-----------------------------------------

' PI calculator
DEFINT C, Z
DEFLNG D
DEFDBL P-T
P = 0
Q = 0
R = 0
S = 0
T = 0
D = 1
Z = 2
CLS
PRINT 4# * ATN(1)
FOR C = 1 TO 1000
T = S
S = R
R = Q
Q = P
P = P + 1 / D
Z = -Z
D = Z - D
NEXT
PRINT (P + 4 * (Q + S) + 6 * R + T) / 4
END

------------------------------------------------

Bob Bishop's Apple Pi program for Apple BASIC was published
in the Aug/Sep 1978 issue of Micro magazine. You can find
the two page article (with source code) at:

http://www.geocities.com/robertjamesbishop/ApplePi/index.html


You should be able to convert this easily to other BASIC's.


The "Micro" article starts by saying that the ancients (150 AD) knew
PI "this accurately" (3.1416). But of course the had no "decimal
point" system - so they must have written it as a fraction or a sum of
fractions.

I always go through a chain of reflections - forgive my stupidity -
when thinking about calculating pi to a huge number of decimal points.
The first is that such accuracy has no practical use, even when
calculating the trajectories of interplanetary probes. So why do it?
One purpose is to show the power of an algorithm (great), another is
to study the digits that make up this transcendental number. Clearly
there can be no repeating "cycle' in the digits or we could describe
the number accurately in fewer than an infinite number of decimal
points. That sounds like a random number. But of course pi is not a
random number - by definition it is highly determined by being part of
pi, and can be predicted and determined by the algorithm used to
calculate the many digits we so proudly examine. So, pi is completely
determined, yet without pattern. Hmm. How then to define a random
number? I think one author suggested that we look at the length of the
algorithm needed to generate the number. Clearly the algorithms to
calulate pi are not that long for we can post code to do the job in
this forum. But a truly random number, that would require a line of
code for each new decimal point digit, and so the algorithm would be
as long as the number. Sounds great, until one remembers how long it
took to find the algorithms to calculate pi. One reason for using
montecarlo methods (indeed the reason for their modern incarnation)
was the difficulty of finding efficient algorithms for solving the
equations necesary for making the nuclear bomb. So even if we are
confident that there is a method of solving a problem it may still
elude us, and we have to resort to indirect methods. Further, it is
clear that the length of an algorithm needed to generate a random
number must be highly related to our ignorance - the more ingenious
and well informed we are the more we may be able to create a more
compact algorithm. So ultimately, is pi and a random number different
only by the quotient of our ignorance?

Sorry to ramble.

Lance
.



Relevant Pages

  • "Algorithmic Randomness, Quantum Physics, and Incompleteness"
    ... all finite sequences are to be found infinitely often and ... different members of the infinite set of random numbers. ... Just using random numbers with initial digits 1 thru 9, ... it generated by a shorter input algorithm than the length ...
    (sci.logic)
  • Re: BigNum -- Floating Point
    ... > It means the memory required for representing a number is just ... write an RSA algorithm, for example. ... interest might be something like pi...in base N...to M digits. ... >> wouldn't the gcd() itself need to be able to handle bigints? ...
    (comp.programming)
  • Re: BCD List to HEX List
    ... nibbles, shifting, and adding, Those are pretty simple, so I asked ... algorithm what the algorithm is intended to achieve ... ... input was a list of decimal digits. ... was to go from BCD to a normal binary integer, ...
    (comp.lang.python)
  • Re: BCD List to HEX List
    ... nibbles, shifting, and adding, Those are pretty simple, so I asked ... algorithm what the algorithm is intended to achieve ... ... that he had lists of digits rather than an integer datatype. ... input was a list of decimal digits. ...
    (comp.lang.python)
  • Re: singleton vs static
    ... it broadcasts the digits to Martians... ... this might be an algorithm that returns n ... All you need is sufficient analysis to be able ... test involving one time through the loop is sufficient to conclude that the ...
    (comp.object)