{"id":1540,"date":"2017-03-16T00:06:37","date_gmt":"2017-03-16T04:06:37","guid":{"rendered":"http:\/\/codinggorilla.domemtech.com\/?p=1540"},"modified":"2017-03-19T09:05:39","modified_gmt":"2017-03-19T13:05:39","slug":"a-belated-happy-pi-day","status":"publish","type":"post","link":"http:\/\/165.227.223.229\/index.php\/2017\/03\/16\/a-belated-happy-pi-day\/","title":{"rendered":"A belated Happy Pi Day!"},"content":{"rendered":"<p>Honestly, is there any better way to spend a day (or two) on <a href=\"https:\/\/en.wikipedia.org\/wiki\/Pi_Day\" target=\"_blank\">Pi Day<\/a> (March 14 = &#8220;3.14&#8221;) than to write some code to compute the value of <a href=\"https:\/\/en.wikipedia.org\/wiki\/Pi\" target=\"_blank\">Pi<\/a>?!<\/p>\n<p><!--more--><\/p>\n<p>You may remember from your math coursework <a href=\"http:\/\/www.pi314.net\/eng\/newton.php\" target=\"_blank\">Newton&#8217;s Formula<\/a>, which is easy to implement:<\/p>\n<p><img loading=\"lazy\" class=\"mathtex-equation-editor alignnone\" src=\"http:\/\/chart.apis.google.com\/chart?cht=tx&amp;chl=%5Cpi%20%3D%206%20%5Csum%20_%7Bn%3D0%7D%20%5E%7B%5Cinfty%7D%20%5Cfrac%7B(2n)!%7D%7B(2%5E%7B4n%2B1%7D)(n!)%5E%7B2%7D%20(2n%2B1)%7D\" alt=\"\\pi = 6 \\sum\\limits_{n=0}^{\\infty}\\frac{(2n)!}{(2^{4n+1})(n!)^{2} (2n+1)}\" width=\"216\" height=\"45\" align=\"absmiddle\" \/><\/p>\n<p>Or, you may have seen\u00c2\u00a0the <a href=\"http:\/\/mathfaculty.fullerton.edu\/mathews\/n2003\/montecarlopimod.html\" target=\"_blank\">Monte Carlo method<\/a>. You could &#8220;speed this up&#8221; using a CUDA GPU implementation, e.g., http:\/\/cacs.usc.edu\/education\/cs596\/src\/cuda\/pi.cu:<\/p>\n\n<p>Unfortunately, while these are easy to implement, they are terrible algorithms, converging on the value of Pi very, very slowly indeed&#8211;even using the parallelism of GPUs.\u00c2\u00a0Although I&#8217;ve read about <a href=\"https:\/\/en.wikipedia.org\/wiki\/Chudnovsky_algorithm\" target=\"_blank\">Chudnovsky&#8217;s Formula<\/a>, I never tried it, probably because I had my priorities wrong. Beside, all of these require an arbitrary precision math package, which I didn&#8217;t have.<\/p>\n<p>But, it turns out there are some: <a href=\"http:\/\/mpir.org\/\" target=\"_blank\">MPIR (Multiple Precision Integers and Rationals)<\/a>, <a href=\"http:\/\/wezeku.github.io\/Mpir.NET\/\" target=\"_blank\">MPIR.NET<\/a>, and <a href=\"https:\/\/www.nuget.org\/packages\/LongCalc\/\" target=\"_blank\">LongCalc<\/a><\/p>\n<p>So, I wish everybody a belated Pi Day with a simple C# program that uses LongCalc (Mpir.NET\/MPIR).<\/p>\n\n<pre>3.1415926535897932384626433...<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Honestly, is there any better way to spend a day (or two) on Pi Day (March 14 = &#8220;3.14&#8221;) than to write some code to compute the value of Pi?!<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/posts\/1540"}],"collection":[{"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/comments?post=1540"}],"version-history":[{"count":0,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/posts\/1540\/revisions"}],"wp:attachment":[{"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/media?parent=1540"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/categories?post=1540"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/tags?post=1540"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}