From: Fred W. Helenius Subject: Re: calculating Pi to n decimal places Date: Thu, 09 Mar 2000 17:20:13 -0500 Newsgroups: alt.math.recreational,sci.math Summary: [missing] "David C. Ullrich" wrote: > That's very interesting but when I try it it seems to be an algorithm >for calculating -1.912 instead of pi. Is there a typo in the post, or did >I make an error in the de-pseudification or what? The error was in the original post, but I show the correction in your version. > (Actual Python code: >a = 1.0 >b = 1.0 / (sqrt(2)) >t = (1.0 / 4 ) >x = 1.0 >while abs(a-b) > 0.0001: > y = a > a = (a + b) / 2 > b = 2 / sqrt(b * y) This line is bogus; it should be b = sqrt(b * y) . > t = t - (x * (y - a ) ** 2) > x = 2 * x > >print ((a + b) ** 2) / (4*t) >.) The correct algorithm and a C implementation may be found at Kurt Van den Branden's "Fun with Pi" page: http://gallery.uunet.be/kurtvdb/pi.html -- Fred W. Helenius ============================================================================== From: "Michael Greaney" Subject: Re: calculating Pi to n decimal places Date: Sat, 11 Mar 2000 08:48:43 -0000 Newsgroups: alt.math.recreational,sci.math Here is an algorithm due to John Borwein and Peter Borwein (I'm sorry I don't remember the book I found it in):- Let x = sqrt(2) y = sqrt(x) pi = 2 + x then carry out the following iteration until the desired result is achieved x=(sqrt(x) + 1/sqrt(x)) / 2 pi = pi * (x + 1) / (y + 1) y = (y * sqrt(x) + 1/sqrt(x)) / (y + 1) The eleventh iteration gives 5000 decimal places. ============================================================================== From: Simon Subject: Re: calculating Pi to n decimal places Date: Thu, 09 Mar 2000 10:22:33 GMT Newsgroups: alt.math.recreational,sci.math For, say, 678 places the following is efficient: > Digits:=700: y:=sqrt(2.0)-1: p2:=6-4*sqrt(2.0): for n from 1 to 4 do a:=sqrt(sqrt(1-y^4)): y:=(1-a)/(1+a): p2:=p2*(1+y)^4-y*(1+y+y^2)*2^(2*n+1) od: 1/p2; Darryl Preen wrote: > > Please repost the formula to do this? I thought i saved it but obviously > not. > > Thanks in advance > > Darryl -- Dr Simon Fitzpatrick, Shenton Park, Western Australia Mathematician and International Correspondence Chess Master http://www.q-net.net.au/~dsf/Simon.html ============================================================================== From: thorinn@diku.dk (Lars Henrik Mathiesen) Subject: Re: Help with Pi-program Date: 27 Apr 2000 16:56:54 +0200 Newsgroups: sci.math Christian Eriksson writes: >This pi-program is written in c++ by Dik T. Winter at CWI. I can't reach >him so I need anyone else to help me. >The program is only 160 character and can calculate pi to 800 digits. >With small modifications I >have managed to make it calculate pi to 16276 digits. It converge >quickly. If you make it calculate pi to 4 digits it gives 3,141 and 8 >digits it gives 3,1415926. I need to know wich formula that is used by >the program for calculating pi. It can't be >Machins formula : pi=16arctan(1/5)-4arctan(1/239). >I need to know wich formula that is used. I would be very grateful if >anyone could help me with this. >The program looks like this: > 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);} >Thanks >Christian Eriksson >christian.eriksson@mbox302.swipnet.se This is a straightforward use of the formula \pi/2 = 1 + 1·2/1·3 + 1·2·3/1·3·5 + 1·2·3·4/1·3·5·7 + ..., using 2800 - 14N terms to calculate the group of four digits with LSD weight 10^{1-4N}. (More or less... each cell in the array f actually holds a residue of the term value at the current precision plus the most significant part of the sum of lower order terms). If it was coded more clearly this would actually be a nice example of multiprecision integer programming. But even then it would most definitely not be a good general algorithm. By fiddling with the number of iterations and the constant 14 you can probably get it to produce correct results for most digit counts, but it has no mechanism to check correctness itself. 800 just happens to be one of the lengths where it works. Lars Mathiesen (U of Copenhagen CS Dep) (Humour NOT marked)