Creating digits of pi
|
02-08-2018, 11:48 PM
(This post was last modified: 02-08-2018 11:49 PM by Gerson W. Barbosa.)
Post: #12
|
|||
|
|||
RE: Creating digits of pi
(02-08-2018 12:26 PM)Mike (Stgt) Wrote:(02-08-2018 04:22 AM)brickviking Wrote: ... on that platform, but would still eventually run into problems. Madhava-Leibniz is interesting, especially because it's from the XIVth century. And yet we can use it on the HP-50g to compute 500 digits, if we are not in a hurry: 500 « PUSH RAD -105 CF -3 CF DUP .653 * 1.74 + IP R->I DUP 2 MOD + DUP 4 * OVER DUPDUP 1 - 1 FOR i i SQ SWAP / PICK3 + ROT SWAP -1 STEP INV NIP UNROT + 1 - 3 0 UNROT FOR i i INV i 2 - INV - + -4 STEP - 4 * EXPAND FXND DUP SIZE R->I ALOG OVER - PICK3 * SWAP IQUOT + ->STR DUP HEAD -51 FC? { "." } { "," } IFTE + SWAP TAIL + 1 ROT 2 + SUB POP » TEVAL --> 2: "3. 1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679 8214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196 4428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273 7245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094 3305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912" 1: s:21533.1807 21533 seconds on my HP-50g (almost 6 hours!) This is much longer than it should be, as I am using no external long-float library (only the built-in Long Int in UserRPL). By using an arbitrary precision library, the running time might be significantly decreased. Quoting from the Wikipedia article on Madhava of Sangamagrama: Quote:This text attributes most of the expansions to Madhava, and gives the following infinite series expansion of π, now known as the Madhava-Leibniz series: Perhaps that Wikipedia article should be updated. The next correction terms are Rn = (4n^3 + 13n)/(16n^4 + 56n^2 +9), Rn = (4n^4 + 29n^2 + 16)/(16n^5 + 120n^3 + 89n) and Rn = (16n^5 + 216n^3 + 389n)/(64n^6 + 880n^4 + 1756n^2 + 225) Madhava's correction terms are simply the first three approximants to the continued fraction in the following expression, from an old thread: \[\frac{\pi }{4}= 1-\frac{1}{3}+\frac{1}{5}-\frac{1}{7}+\cdots +\frac{1}{2n-3}-\frac{1}{2n-1}+\frac{1}{4n+\frac{1^{2}}{n+\frac{2^{2}}{4n+\frac{3^{2}}{n+\frac{4^{2}}{4n+... }}}}}\] From observation, 2*d/3 terms of the series and the corresponding correction term (or the evaluation of the same number of terms of the continued fraction) are necessary to obtain d correct decimal places of π. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)