Post Reply 
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.

A little 'look ahead' on another platform (slow laptop using REXX, an interpreter language) showing the last 30 digits, time elapsed in seconds, iterations, and method.
requested 500 digits:
...673518857527248912279381830118358 4.056000 1643 Newton
...673518857527248912279381830119702 1.248000 1034 Madhava-Leibniz

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.
14159265358979323846264338327950288419716939937510582097494459230781640628620899​86280348253421170679
82148086513282306647093844609550582231725359408128481117450284102701938521105559​64462294895493038196
44288109756659334461284756482337867831652712019091456485669234603486104543266482​13393607260249141273
72458700660631558817488152092096282925409171536436789259036001133053054882046652​13841469519415116094
33057270365759591953092186117381932611793105118548074462379962749567351885752724​89122793818301194912"
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:

\[{\displaystyle {\frac {\pi }{4}}=1-{\frac {1}{3}}+{\frac {1}{5}}-{\frac {1}{7}}+\cdots +{\frac {(-1)^{n}}{2n+1}}+\cdots } {\frac {\pi }{4}}=1-{\frac {1}{3}}+{\frac {1}{5}}-{\frac {1}{7}}+\cdots +{\frac {(-1)^{n}}{2n+1}}+\cdots\]

which he obtained from the power series expansion of the arc-tangent function. However, what is most impressive is that he also gave a correction term, Rn, for the error after computing the sum up to n terms. Madhava gave three expressions for the correction term Rn,[4] namely

Rn = 1/(4n), or
Rn = n/(4n^2+ 1), or
Rn = (n^2 + 1)/(4n^3 + 5n).

where the third correction leads to highly accurate computations of π.

It is not clear how Madhava might have found these correction terms.

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 π.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Creating digits of pi - brickviking - 02-06-2018, 12:24 AM
RE: Creating digits of pi - Joe Horn - 02-06-2018, 01:38 AM
RE: Creating digits of pi - toml_12953 - 02-06-2018, 09:24 PM
RE: Creating digits of pi - brickviking - 02-06-2018, 10:38 PM
RE: Creating digits of pi - brickviking - 02-08-2018, 04:22 AM
RE: Creating digits of pi - toml_12953 - 02-08-2018, 01:02 PM
RE: Creating digits of pi - TASP - 02-07-2018, 10:30 PM
RE: Creating digits of pi - pier4r - 02-09-2018, 02:59 PM
RE: Creating digits of pi - emece67 - 02-10-2018, 09:14 PM
RE: Creating digits of pi - TASP - 02-11-2018, 12:12 AM
RE: Creating digits of pi - ttw - 02-12-2018, 03:59 AM
RE: Creating digits of pi - EdS2 - 02-17-2018, 12:27 PM
RE: Creating digits of pi - EdS2 - 02-21-2018, 11:01 AM
RE: Creating digits of pi - pier4r - 02-17-2018, 04:25 PM
RE: Creating digits of pi - brickviking - 02-17-2018, 09:27 PM
RE: Creating digits of pi - pier4r - 02-23-2018, 01:34 PM
RE: Creating digits of pi - SlideRule - 05-13-2018, 05:09 PM



User(s) browsing this thread: 1 Guest(s)