Nick Craig-Wood's Pages - Latest Commentshttp://nickcw.disqus.com/enWed, 01 Mar 2017 20:25:51 -0000Re: Pi - Machinhttp://www.craig-wood.com/nick/articles/pi-machin#comment-3181916193<p>You could determine the number of iterations and assume worst case truncation on each iteration, and use that as an error estimate. For example, if it took 100,000 iterations, then assume the actual result is 100,000 less than what the code calculated, so just drop off the last 5 or 6 digits. To avoid issues with missed carries, you could include a few more "guard" digits to be safe. I used 16 extra digits for ~285,000 iterations, but this was more than needed, 8 digits would probably have been enough.</p>rcgldrWed, 01 Mar 2017 20:25:51 -0000Re: Pi - Machinhttp://www.craig-wood.com/nick/articles/pi-machin#comment-3181900338<p>Regarding the 1 trillion digits on a super computer, it took 157 hours for one of the 4 term series (starting with 1/57). 64 nodes of the super computer's 144 nodes were used (no explanation for choosing to use 64), each with it's own processor and 16GB ram. This would allow the series to be calculated in parallel, producing 64 times as many bits per iteration versus a single node. I updated my post above to include a link to the groups result.</p><p><a href="http://www.super-computing.org/pi_current.html" rel="nofollow noopener" title="http://www.super-computing.org/pi_current.html">http://www.super-computing....</a><br></p>rcgldrWed, 01 Mar 2017 20:12:13 -0000Re: Pi - Machinhttp://www.craig-wood.com/nick/articles/pi-machin#comment-3180595569<p>Hi,</p><p>some last digits are wrong, how can I make sure to display only right digits ?</p>LrntWed, 01 Mar 2017 05:48:11 -0000Re: Pi - Machinhttp://www.craig-wood.com/nick/articles/pi-machin#comment-3036277293<p>I solved it do you know how I did it well find out why to build perfect tolerance machines when I studied we used .003 ansi standards as I design now .0000000000000000000000000000000000000000000000000000 is needed</p>Craig BrashearMon, 05 Dec 2016 10:05:58 -0000Re: Pi - Machinhttp://www.craig-wood.com/nick/articles/pi-machin#comment-3013014014<p>Example calculation of pi using arctan, with error bounds indicated in brackets (we require the fact that floor(x/n)=floor(floor(x)/n) if x is real and n is a positive integer):<br></p><pre>pi/4 = arctan(1/2) + arctan(1/3)<br>arctan(x) = x^1/1 - x^3/3 + x^5/5 - x^7/7 + ...<br><br> 2000000000 /1<br>+2000000000 2000000000 [0,0]<br> 500000000 /3<br>- 166666666 1833333334 [-1,0]<br> 125000000 /5<br>+ 25000000 1858333334 [-1,0]<br> 31250000 /7<br>- 4464285 1853869049 [-2,0]<br> 7812500 /9<br>+ 868055 1854737104 [-2,1]<br> 1953125 /11<br>- 177556 1854559548 [-3,1]<br> 488281 /13<br>+ 37560 1854597108 [-3,2]<br> 122070 /15<br>- 8138 1854588970 [-4,2]<br> 30517 /17<br>+ 1795 1854590765 [-4,3]<br> 7629 /19<br>- 401 1854590364 [-5,3]<br> 1907 /21<br>+ 90 1854590454 [-5,4]<br> 476 /23<br>- 20 1854590434 [-6,4]<br> 119 /25<br>+ 4 1854590438 [-6,5]<br> 29 /27<br>- 1 1854590437 [-7,5]<br><br> 1333333333 /1<br>+1333333333 1333333333 [0,1]<br> 148148148 /3<br>- 49382716 1283950617 [-1,1]<br> 16460905 /5<br>+ 3292181 1287242798 [-1,2]<br> 1828989 /7<br>- 261284 1286981514 [-2,2]<br> 203221 /9<br>+ 22580 1287004094 [-2,3]<br> 22580 /11<br>- 2052 1287002042 [-3,3]<br> 2508 /13<br>+ 192 1287002234 [-3,4]<br> 278 /15<br>- 18 1287002216 [-4,4]<br> 30 /17<br>+ 1 1287002217 [-4,5]<br><br>1854590437+1287002216=3141592653 [-11,9]<br>1854590438+1287002217=3141592655 [-10,10]<br><br>3141592642 < 10^9 pi < 3141592665<br>pi = 3.1415926...<br></pre>Nit PickMon, 21 Nov 2016 09:16:23 -0000Re: Pi - Chudnovskyhttp://www.craig-wood.com/nick/articles/pi-chudnovsky#comment-2775547078<p>changing "sqrtC = (10005*one_squared).sqrt()" to "sqrtC = isqrt(10005*one_squared)" and adding "from gmpy2 import isqrt" will allow the script to run correctly.</p>William DoverSun, 10 Jul 2016 12:04:39 -0000Re: Pi - Machinhttp://www.craig-wood.com/nick/articles/pi-machin#comment-2728936175<p>Python implements Karatsuba multiplication which is pretty good for not enormous numbers. GMP(y) deals with the FFT multiplication you are right. Feel free to email me if you have more questions! Nick</p>Nick Craig-WoodMon, 13 Jun 2016 17:14:47 -0000Re: Pi - Machinhttp://www.craig-wood.com/nick/articles/pi-machin#comment-2728919721<p>Thanks for replying so quickly and for confirming my suspicion.<br>I'm working to implement some of the ideas in your excellent pages for myself, just for the fun of it. Learning curve-wise, I've noticed that there's an stupendous increment as soon as binary splitting becomes involved, since this is also the point where FFT-multiplication is required. There's no mention of FFT in your pages, however, but I assume it's the main working principle of the gmpy-library.</p>ArnoMon, 13 Jun 2016 17:05:39 -0000Re: Pi - Machinhttp://www.craig-wood.com/nick/articles/pi-machin#comment-2728219584<p>An interesting idea to use the standard formula like that by multiplying with -(2n-1) and dividing by (2n+1)*x*x - if you implement it like that then it will probably be about the same speed you are right. This might have some effect on the precision though...</p>Nick Craig-WoodMon, 13 Jun 2016 11:00:41 -0000Re: Pi - Machinhttp://www.craig-wood.com/nick/articles/pi-machin#comment-2722004092<p>I fail to see how the 'accelerated formula' really accerelates things.<br>With the accelerated version you have to multiply with 2n and divide by (2n+1)*(x*x+1) to obtain the next term.<br>But with the standard formula you can do that by multiplying with -(2n-1) and dividing by (2n+1)*x*x.<br>So there seems to be really no difference. Or is there something I'm missing?</p>ArnoThu, 09 Jun 2016 14:38:20 -0000Re: Pi - Chudnovskyhttp://www.craig-wood.com/nick/articles/pi-chudnovsky#comment-2521129960<p>I have doubts that there is a mistake in the second program (<a href="http://pi_chudnovsky_bs.py" rel="nofollow noopener" title="pi_chudnovsky_bs.py">pi_chudnovsky_bs.py</a>) - it should be "one = 10**(2*digits)" as in the last program. If you do not double the digits - then for odd number of digits function returns wrong result (starting with "99....")</p>Ivo GelovThu, 18 Feb 2016 07:51:01 -0000Re: Pi - Gregory's Serieshttp://www.craig-wood.com/nick/articles/pi-gregorys-series#comment-2441323117<p>Hi,<br>we have to take the advantage of big numbers that are the default for Python, no need for other library</p><p>#PI = 1 - 1/3 + 1/5 - 1/7 + 1 / 9 ....</p><p>fileName = "PI.txt"</p><p>digits = 1000</p><p>UNU = 1</p><p>for i in range(0, digits):</p><p> UNU = 10 * UNU</p><p>PI = 0</p><p>sign = 1</p><p>print("Start")</p><p>for i in range(0, 100000000):</p><p> PI = PI + sign * (UNU // (2 * i + 1))</p><p> sign = -sign</p><p>print("Stop")</p><p>file = open(fileName, 'w')</p><p>PI = 4 * PI</p><p>file.write("PI = 3.{0}".format(PI % UNU))</p>Constantin AgavriloaieTue, 05 Jan 2016 14:43:26 -0000Re: Pi - Chudnovskyhttp://www.craig-wood.com/nick/articles/pi-chudnovsky#comment-2358811002<p>I found out how this value is calculated. For details and extra insite into calculating Pi please visit my blog at <a href="http://moduscalculi.blogspot.ca/2015/11/how-to-calculate-pi.html" rel="nofollow noopener" title="http://moduscalculi.blogspot.ca/2015/11/how-to-calculate-pi.html">http://moduscalculi.blogspo...</a></p>naraphimFri, 13 Nov 2015 20:21:13 -0000Re: Pi - Chudnovskyhttp://www.craig-wood.com/nick/articles/pi-chudnovsky#comment-2340426771<p>I HAVE A PROBLEM LIKE THIS CAN YOU HELP ME ?</p><p>Calculate π's value by using the following series:</p><p>π = 3 + 4/(2*3*4) - 4/(4*5*6) + 4/(6*7*8) - 4/(8*9*10) + 4/(10*11*12) - 4/(12*13*14) ...</p><p>Stop the iteration when current term becomes less than 0.0000001 and then report (print) calculated value.</p>Salim MahdumTue, 03 Nov 2015 07:12:03 -0000Re: Pi - Chudnovskyhttp://www.craig-wood.com/nick/articles/pi-chudnovsky#comment-2313740714<p>Can someone please show all the steps to arrive at the final form of a_k/a_k-1<br>\begin{eqnarry*}<br>\frac{a_{a_{k}}{a_{k-1}}<br>\end{eqnarry*}<br>thank you</p>naraphimSun, 18 Oct 2015 13:31:02 -0000Re: Pi - Archimedeshttp://www.craig-wood.com/nick/articles/pi-archimedes#comment-2282612408<p>This is a nice (and valid) procedure, but it's not the one used by Archimedes. The method above first appears in the work of Liu Hui in the 3rd c. AD. Archimedes' method uses a different approach based on Elements VI.3, and for the inscribed polygons uses an angle with a diameter as one side rather than a radius. Heath's translation is in the public domain and you can find it online in a number of places.</p>ChuckWed, 30 Sep 2015 16:06:19 -0000Re: Pi - Machinhttp://www.craig-wood.com/nick/articles/pi-machin#comment-1925268588<p>Hello Nick: Is there a fast way of computing the sine of an angle (such as AGM method), so that this "Beeler Formula" can be used to calculate Pi very efficiently, since it converges quintically, or order 5 with each iteration! :</p><p> ⁿₐ₊₁=ⁿₐ+sin(ⁿₐ)+1/6(sin³)ⁿₐ</p><p>Sorry, if I sound very naïve, since I'm NOT a mathematician but just a hobbyist! Thanks for your time.</p>Sol WardaTue, 24 Mar 2015 10:37:15 -0000Re: Pi - Chudnovskyhttp://www.craig-wood.com/nick/articles/pi-chudnovsky#comment-1914553606<p>Suggestion to Nick: The next time you publish this technote with the gmp-chudnovsky.c source link, please explain how one should efficiently compile and link this program. What follows should be valid universally for Linux (works fine in the current Xubuntu). Adaptable for Mac (Unix-based) using tools from either the <a href="http://www.macports.org/" rel="nofollow noopener" title="http://www.macports.org/">http://www.macports.org/</a> project or the <a href="http://www.finkproject.org/" rel="nofollow noopener" title="http://www.finkproject.org/">http://www.finkproject.org/</a> project.</p><p>A. Install GNU MP<br>==============</p><p>1. Decompress the referenced "gmp library" (download from <a href="http://gmplib.org" rel="nofollow noopener" title="http://gmplib.org">http://gmplib.org</a>) into a user folder (E.g. /home/texadactyl/gmplib).<br>2. Inside the top level folder:</p><p> ./configure<br> make<br> make check<br> sudo make install</p><p> Be sure that no errors have occured on any of the steps before proceeding to the next step.</p><p>B. Build gmp-chudnovsky<br>====================</p><p>1. Go into the folder where all the source files extracted from this web page reside.<br>2. For an intel i3, i5, or i7, this will compile and link an efficient executable for gmp-chudnovsky.c:</p><p> gcc -std=gnu99 -O2 -pedantic -fomit-frame-pointer -m64 -mtune=corei7 -march=corei7 \<br> -o gmp-chudnovsky gmp-chudnovsky.c -L/usr/local/lib/ -lgmp -lm</p><p>Note that the i3/i5/i7 parameters optimizes for that particular platform. How did I figure the tuning gcc parameters out? I watched the compile for tests/t-bswap.c which is also a user-level main program.</p>texadactylWed, 18 Mar 2015 15:49:39 -0000Re: Pi - Machinhttp://www.craig-wood.com/nick/articles/pi-machin#comment-1870731551<p>Hello Nick: Thanks for the reply. Here is a multi-precision calculator that I actually commissioned from a software engineer in Argentina & it can handle numbers up to a million digits. And in scientific notation, it can handle up to 10^billion!. However, you need to download "Java plug-in", since it's written in Java. Hope, you will find it useful:</p><p><a href="http://www.alpertron.com.ar/BIGCALC.HTM" rel="nofollow noopener" title="http://www.alpertron.com.ar/BIGCALC.HTM">http://www.alpertron.com.ar...</a></p>Sol WardaMon, 23 Feb 2015 09:43:45 -0000Re: Pi - Machinhttp://www.craig-wood.com/nick/articles/pi-machin#comment-1870457024<p>Thanks Sol, I haven't seen that formula before - very interesting! You couldn't use the technique above to calculate it though as it would need multi-precision floating point arithmetic to maintain the precision of x^n while using the arctan formula. I'll have a think to see if I can work out an efficient way of calculating it.</p>Nick Craig-WoodMon, 23 Feb 2015 05:13:47 -0000Re: Pi - Machinhttp://www.craig-wood.com/nick/articles/pi-machin#comment-1861987090<p>Hello Nick: I wonder if you are familiar with this one-term arctan formula to calculate Pi to as many decimal places as you want:</p><p>Pi/24=arctan (1/(sqrt(2)+sqrt(3)+sqrt(6)+2)=1/7.595......etc. Iterate the denominator at right as follows:</p><p>Pi/24.2=7.595....+sqrt((7.595...)^2+1)=1/15.257... etc. " " " " " "</p><p>.</p><p>.</p><p>.</p><p>Pi/24.2^21=arctan(1/16021061.1463225945........etc.). Then simply take the reciprocal of the right hand side and evaluate arctan using Gregory series(x-x^3/3+x^5/5-x^7/7.....etc.). Then multiply the result by 24.2^21 and you get Pi to as many decimal places as you wish.<br>THE LAST ITERATION GIVES YOU APPROX. 15 ACCURATE DIGITS WITH EACH TERM OF THE GREGORY SERIES!!!. SO THAT TO CALCULATE 1,000,000 DIGITS, ALL YOU NEED IS 1,000,000/15 OR 66,667 TERMS!!. HOPE YOU FIND IT INTERESTING. THANKS.</p>Sol WardaWed, 18 Feb 2015 11:46:53 -0000Re: Pi - Archimedeshttp://www.craig-wood.com/nick/articles/pi-archimedes#comment-1624953019<p>you are very good at python. Can you tell me how to decompress .z archive file in python. Thank you.</p>VidWed, 08 Oct 2014 06:15:33 -0000Re: Pi - Archimedeshttp://www.craig-wood.com/nick/articles/pi-archimedes#comment-1619743475<p>Great work. I loved your diagrams!</p>AdrianSat, 04 Oct 2014 14:39:09 -0000Re: Pi - Chudnovskyhttp://www.craig-wood.com/nick/articles/pi-chudnovsky#comment-1288361554<p>It looks like the interface to gmpy2 has changed slightly :-( You've made the correct fix according to my investigations. I'll update this page in due course with the fix.</p><p>Thank you very much for bringing that to my attention.</p><p>PS glad you enjoyed the series - I like to see pi enthusiasm :-)</p>Nick Craig-WoodMon, 17 Mar 2014 10:55:50 -0000Re: Pi - Chudnovskyhttp://www.craig-wood.com/nick/articles/pi-chudnovsky#comment-1286653137<p>Hello!</p><p>These are very nice articles for Pi lovers. I'm fascinated with Pi and although I still can't make my head around Gregory's series for arctan, I have orgasms while my mid-2010 MacBook Pro calculates millions of places of Pi in seconds. Even though I won't make any practical use of these algorithms since a few places of Pi is enough for everyday work, maybe I can learn from the technics you show and apply them in other projects.</p><p>And just because I'm so in love with Pi, I tried every little Python program from these series and all worked except the last one. The gmpy2 optimized version.</p><p>Is the following line correct? sqrtC = (10005*one_squared).sqrt()</p><p>I get: AttributeError: 'mpz' object has no attribute 'sqrt'</p><p>I changed the line to: sqrtC = gmpy2.isqrt(10005*one_squared), and got it working, but this was pure luck since gmpy2.sqrt() gives wrong digits of Pi and math.sqrt can't cast from mpz to float.</p><p>BTW, I'm using Python 3.3.5 and gmpy2 2.0.3.</p><p>Thanks and best regards,</p><p>Norberto</p>NorbertoSun, 16 Mar 2014 03:47:44 -0000