home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!seismo!darwin.sura.net!jvnc.net!princeton!ginger.princeton.edu!tao
- From: tao@ginger.princeton.edu (Terry Tao)
- Newsgroups: sci.math
- Subject: Re: Calculating pi: help!
- Message-ID: <1992Oct14.194009.27975@Princeton.EDU>
- Date: 14 Oct 92 19:40:09 GMT
- References: <Bw304E.LKu@mentor.cc.purdue.edu> <7557@charon.cwi.nl> <stephen.719088307@mont>
- Sender: news@Princeton.EDU (USENET News System)
- Organization: Princeton University
- Lines: 74
- Originator: news@nimaster
- Nntp-Posting-Host: ginger.princeton.edu
-
- In article <stephen.719088307@mont>, stephen@mont.cs.missouri.edu (Stephen Montgomery-Smith) writes:
- |> In <7557@charon.cwi.nl> dik@cwi.nl (Dik T. Winter) writes:
- |>
- |> >int a=10000,b,c=2800,d,e,f[2801],g;main(){for(;b-c;)f[b++]=a/5;for(;d=0,g=c*2;c
- |> >-=14,printf("%.4d",e+d/a),e=d%a)for(b=c;d+=f[b]*a,f[b]=d%--g,d/=g--,--b;d*=b);}
- |>
- |>
- |> I would be very interested to know how this program works.
- |>
- |> Stephen
- |>
-
- One note about the program: it assumes that b, d, e, and g are initialized to 0.
-
- in pseudo code the rather compact program does the following:
-
- set a as the constant 10000
- set c as 2800
-
- set f[b] = a/5 for all b from 0 to c-1
-
- while c is positive
- set b = c, d = 0, g = 2*c
- while b is positive
- d is multipled by b
- d is incremented by a*f[b]
- f[b] becomes d mod g-1
- d is divided by g-1
- g is decremented by 2
- b is decremented by 1
- end while
- subtract 14 from c
- print as four digits the integer part of e+d/a
- e becomes d mod a
- end while
-
- in BASIC the program is equivalent to (note: don't try to run this program!)
-
- DEFINT A-E
- DEFDDBL P,X
- DIM F(2800)
-
- CONST DIGIT_CHUNK 4
- CONST A = 10^DIGIT_CHUNK
- CONST DIGITS = 800
- CONST CMAX = DIGITS/DIGIT_CHUNK * 14
- X = 1/A
-
- FOR B = 0 TO CMAX-1: F(B) = A/5: NEXT B
-
- FOR C = CMAX TO 0 STEP -14
- D=0
- FOR B = C TO 1 STEP -1
- D = D * B
- D = D + A*F(B)
- F[B] = D MOD (2*B-1)
- D = INT(D/(2*B-1))
- NEXT B
- PI = PI + D*X
- X = X/A
- NEXT C
- ?PI
-
-
- However, the actual device used to calculate pi here is still obscure to me.
- After eliminating the clever mechanisms for dealing with remainders of fractions
- with integers, I think when you come right down to it we are using a formula of
- the form (I've probably made a few minor mistakes, but this is what it should be)
-
- pi = \sum_{c = 1}^\infty 1/5 \prod_{b = 1}^{c*14} b / (2*b-1)
-
- But I've never heard of this formula or anything like it! why the 14 and the 5?
-
- Terry
-