Re: calculating PI
- From: Gary <LanceGary@xxxxxxxxx>
- Date: Mon, 29 Sep 2008 02:48:32 -0700 (PDT)
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
.
- Follow-Ups:
- Re: calculating PI
- From: news@xxxxxxxxxxxxxxx
- Re: calculating PI
- References:
- calculating PI
- From: David Williams
- Re: calculating PI
- From: Charles Richmond
- calculating PI
- Prev by Date: Re: another?
- Next by Date: Re: calculating PI
- Previous by thread: Re: calculating PI
- Next by thread: Re: calculating PI
- Index(es):
Relevant Pages
|