Creating digits of pi
|
02-10-2018, 03:45 PM
(This post was last modified: 02-10-2018 03:48 PM by Gerson W. Barbosa.)
Post: #21
|
|||
|
|||
RE: Creating digits of pi
(02-10-2018 12:44 PM)Mike (Stgt) Wrote: Could someone of the interested (Decimal BASIC admirer, etc.) please confirm this Ramanujan–Sato of 1993 works? I fail with it, get Pi = 4.1748739, what is a bit too far off. Off by a factor of exactly 400/301: 4.1748739 * 301/400 = 3.1415926 Probably just a coincidence, but I would check this out with more digits. |
|||
02-10-2018, 04:42 PM
(This post was last modified: 02-10-2018 05:11 PM by toml_12953.)
Post: #22
|
|||
|
|||
RE: Creating digits of pi
(02-10-2018 12:44 PM)Mike (Stgt) Wrote: Could someone of the interested (Decimal BASIC admirer, etc.) please confirm this Ramanujan–Sato of 1993 works? I fail with it, get Pi = 4.1748739, what is a bit too far off. The quadratic convergence works: Code: OPTION ARITHMETIC DECIMAL_HIGH Tom L Cui bono? |
|||
02-10-2018, 05:19 PM
Post: #23
|
|||
|
|||
RE: Creating digits of pi
(02-10-2018 04:54 PM)Mike (Stgt) Wrote:I corrected my original code. It works now. Thanks!(02-10-2018 04:42 PM)toml_12953 Wrote: ... Something is off there somewhere. Tom L Cui bono? |
|||
02-10-2018, 05:25 PM
Post: #24
|
|||
|
|||
RE: Creating digits of pi
(02-10-2018 12:44 PM)Mike (Stgt) Wrote: Could someone of the interested (Decimal BASIC admirer, etc.) please confirm this Ramanujan–Sato of 1993 works? I fail with it, get Pi = 4.1748739, what is a bit too far off. Nope, the Wiki is correct. I used the constants featured there and this is the result I got: list 10 word -520:point -160 20 A=63365028312971999585426220+28337702140800842046825600*sqrt(5)+384*sqrt (5)*sqrt(10891728551171178200467436212395209160385656017+48709290865788102250773 38534541688721351255040*sqrt(5)) 30 B=7849910453496627210289749000+3510586678260932028965606400*sqrt(5)+2515 968*sqrt(3110)*sqrt(6260208323789001636993322654444020882161+2799650273060444296 577206890718825190235*sqrt(5)) 40 C=-214772995063512240-96049403338648032*sqrt(5)-1296*sqrt(5)*sqrt(109852 34579463550323713318473+4912746253692362754607395912*sqrt(5)) 50 clr time : S=0:N=0 60 T=S+!(6*N)/!(3*N)/(!(N)^3)*(A+N*B)/C^(3*N):if T<>S then S=T:inc N:goto 60 70 print sqrt((-C)^3)/S:print time1000 run 3.14159265358979323846264338327950288419716939937510582097494459230781640628620 89986280348253421170679821480865132823066470938446095505822317253594081284811174 50284102701938521105559644622948954930381964428810975665933446128475648233786783 16527120190914564856692346034861045432664821339360726024914127372458700660631558 81748815209209628292540917153643678925903600113305305488204665213841469519415116 09433057270365759591953092186117381932611793105118548074462379962749567351885752 72489122793818301194912983367336244065664308602139494639522473719070217986094370 27705392171762931767523846748184676694051320005681271452635608277857713427577896 09173637178721468440901224953430146549585371050792279689258923542019956112129021 96086403441815981362977477130996051870721134999999837 which gives 770 correct decimals (all featured) in 15-16 iterations, 8 milliseconds. Have a nice weekend. V. . All My Articles & other Materials here: Valentin Albillo's HP Collection |
|||
02-10-2018, 09:14 PM
(This post was last modified: 02-10-2018 09:20 PM by emece67.)
Post: #25
|
|||
|
|||
RE: Creating digits of pi
I've tested, using Python + the mpmath package, the nonic convergence method. It gives
Regards. |
|||
02-11-2018, 12:12 AM
Post: #26
|
|||
|
|||
RE: Creating digits of pi
Yeah, not helpful at all, but for some random digit of Pi in base 2, just guess.
50/50 chance of being right is good enough for me and I don't need to put the batteries back in my HP41 to do it. 2speed HP41CX,int2XMEM+ZEN, HPIL+DEVEL, HPIL+X/IO, I/R, 82143, 82163, 82162 -25,35,45,55,65,67,70,80 |
|||
02-11-2018, 11:21 PM
(This post was last modified: 02-11-2018 11:35 PM by Gerson W. Barbosa.)
Post: #27
|
|||
|
|||
RE: Creating digits of pi
(02-09-2018 07:27 PM)Gerson W. Barbosa Wrote: Now I get running times as lows as 0.2 seconds, but sometimes as high as 0.35 seconds. Code:
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420199 .2 seconds These are the more straightforward expressions for s0 and s1, but they're slower: Code:
|
|||
02-12-2018, 03:40 AM
Post: #28
|
|||
|
|||
RE: Creating digits of pi
(02-12-2018 01:38 AM)Mike (Stgt) Wrote: BTW, 1000 decimals in 10 minutes on an HP-49, that gives everyone the chance to keep count of it. Really fast (and compact), 5 seconds on the emulator! For real fun, I would try a 2500-year-old algorithm (with a small adjustment for speed) on my 50g. No problem waiting three hours for the glorious thousand digits :-) http://www.hpmuseum.org/cgi-sys/cgiwrap/...443#189221 There is also a 4-minute alternative (certainly more than 10 minutes on the 49G). Both programs require the LongFloat library, though. |
|||
02-12-2018, 03:59 AM
Post: #29
|
|||
|
|||
RE: Creating digits of pi
Some methods for decimal digits but not quite as nice as the base 16 version.
http://numbers.computation.free.fr/Const...ldigit.pdf https://arxiv.org/ftp/arxiv/papers/0912/0912.0303.pdf Makes a good test problem for compilers and hardware. |
|||
02-14-2018, 07:37 AM
Post: #30
|
|||
|
|||
RE: Creating digits of pi
(02-14-2018 04:55 AM)Mike (Stgt) Wrote: Just tried on an HP300s+ There's no last digit in π... ;) Greetings, Massimo -+×÷ ↔ left is right and right is wrong |
|||
02-14-2018, 11:06 AM
Post: #31
|
|||
|
|||
RE: Creating digits of pi
(02-14-2018 09:52 AM)Mike (Stgt) Wrote: BTW, it must be a good approximation so the 300s+ will take it as Pi, 355/113 is not good enough. It's very good. ln(640320)/sqrt(163) differs from pi/3 by only 7.39889E-17 (rounded of course). The simplest fraction that's even closer to pi/3 is 165707065/158238591 (error is 5.46945E-17). It's amazing what an insomniac brain will occupy itself with at 3:06AM. <0|ɸ|0> -Joe- |
|||
02-14-2018, 11:18 AM
Post: #32
|
|||
|
|||
RE: Creating digits of pi
(02-14-2018 09:52 AM)Mike (Stgt) Wrote:(02-14-2018 07:37 AM)Massimo Gnerucci Wrote: There's no last digit in π... Oh yes! Wolf in the fold. Greetings, Massimo -+×÷ ↔ left is right and right is wrong |
|||
02-14-2018, 07:24 PM
Post: #33
|
|||
|
|||
RE: Creating digits of pi
(02-12-2018 03:40 AM)Gerson W. Barbosa Wrote:(02-12-2018 01:38 AM)Mike (Stgt) Wrote: BTW, 1000 decimals in 10 minutes on an HP-49, that gives everyone the chance to keep count of it. I know it's "cheating", but LongFloat's built-in function FPI returns 1000 digits of PI in about 42 seconds on the HP50, about 1.1s on the emulator. :-) |
|||
02-14-2018, 11:57 PM
(This post was last modified: 02-15-2018 12:20 AM by Gerson W. Barbosa.)
Post: #34
|
|||
|
|||
RE: Creating digits of pi
(02-14-2018 07:24 PM)John Keith Wrote:(02-12-2018 03:40 AM)Gerson W. Barbosa Wrote: For real fun, I would try a 2500-year-old algorithm (with a small adjustment for speed) on my 50g. No problem waiting three hours for the glorious thousand digits :-) Less than 74 seconds on my HP 49G. But this is not about getting it fast, it's about testing a method that was available in India at least sinced the late 14th century. I believe the continued fraction which works as a correction to the very slowly convergent Madhava-Leibniz series (a.k.a. Gregory series), was known to Madhava. 20 terms of the series and 20 terms of the continued fraction would have yielded 30 correct digits, but the latter might be not practical for manual calculation, or they just thought it was not worth the effort. By using this method, a thousand digits can be computed in less than four hours (3h51m09s) on a 49G. I don't think they would have found that too slow back then :-) 1000 Code:
EVAL --> 31415926535897932384626433832795028841971693993751058209749445923078164062862 089986280348253421170679821480865132823066470938446095505822317253594081284811 174502841027019385211055596446229489549303819644288109756659334461284756482337 867831652712019091456485669234603486104543266482133936072602491412737245870066 063155881748815209209628292540917153643678925903600113305305488204665213841469 519415116094330572703657595919530921861173819326117931051185480744623799627495 673518857527248912279381830119491298336733624406566430860213949463952247371907 021798609437027705392171762931767523846748184676694051320005681271452635608277 857713427577896091736371787214684409012249534301465495853710507922796892589235 420199561121290219608640344181598136297747713099605187072113499999983729780499 510597317328160963185950244594553469083026425223082533446850352619311881710100 031378387528865875332083814206171776691473035982534904287554687311595628638823 537875937519577818577805321712268066130019278766111959092164201989.E-1000 s: 13868.7266 That's about the time it takes the HP 50g to get the equivalent algebraic expression. Expanding it would take much, much longer. 1000 Code:
EVAL --> Code:
EXPAND --> 209825968201627626286623454595828256626709353294427565693247490908723674963328 437446737220228925859354323920568231930674733184239295858288420011592440669384 872031012213258537332909445846000903747665658888180242434346594380978304852173 052403372808186145692544868234515711423406188811364772876865637765490919076434 392771210399189504646019426036882136493770586097156188551653562529227766165281 757151724133041036460071532563393677368044337870650100262757747252991375882380 250620201017085686160848392397092831545551473286217654554917628548452574061153 069975606948031055019988881584904506395644140050798077890023084451291894497326 051903961793213476739142633750444261417276165846644921102222993269581502224908 997341571378437977195178421097830535179345748645267789093772601974921499991845 401937587852170647321448405827097658859639498298473057686922497943250306778251 041916305052893735026021428385807394291381395492996962793986222406725018359953 072078004002223662842307399263336028649795843721429601453448755585367626557498 760685012488702797279250113419102483986306543454752334763491632369843706569991 047137574804721539328768935056574597269592669763395749629148319846053893268546 966267252153515482975568525561183612983615350523775562374113789568264561165733 980089432434864965104974017069056/ 667896800566637703395851118513503626141262321582626289553702325261623907354572 438254043502004959002868854942975857307918561401611054958654114240264009515552 200923163423327214742168578084961721459667457020661333684638926852020031848136 506591215222804140858795351641744040655966457807513342355269848746467904921756 092395537006240650450942873367057350825035314920399047941757674877322573778408 806778939307044804124356789509459360093717241638776925160070406891674464351926 499274636660943669592601023521686228225528199716726528231684826695828870347304 536961944452922511457510213498499968525892553651189414843449897338673657505718 626141672674142307483362631546562482632710881847919379078547871416496195345019 159779507094766464828561525894215976515907672692661978234580958904825570303785 429435771125352380855627325739133377789931371074249342603954029828721762250029 731123836036730436729508866487381850274816327061567345996978616965553971425079 225277549473507787885520688837580635372146777114593848029172095673038532289136 146665525606818535828272746221383566300894538111563291705413589743201178836426 902316517664023633837107436210497878988982635420985619424857564520193944361919 714122045000936522301890676982272649077234522014303978345842413157035790893429 82462406016044012038707143579375 1000 SWAP FXND DUP SIZE R->I ALOG OVER - PICK3 * SWAP IQUOT + ->STR DUP HEAD -51 FC? { "." } { "," } IFTE + SWAP TAIL + 1 ROT 2 + SUB EVAL --> 3.1415926535897932384626433832795028841971693993751058209749445923078164062862 089986280348253421170679821480865132823066470938446095505822317253594081284811 174502841027019385211055596446229489549303819644288109756659334461284756482337 867831652712019091456485669234603486104543266482133936072602491412737245870066 063155881748815209209628292540917153643678925903600113305305488204665213841469 519415116094330572703657595919530921861173819326117931051185480744623799627495 673518857527248912279381830119491298336733624406566430860213949463952247371907 021798609437027705392171762931767523846748184676694051320005681271452635608277 857713427577896091736371787214684409012249534301465495853710507922796892589235 420199561121290219608640344181598136297747713099605187072113499999983729780499 510597317328160963185950244594553469083026425223082533446850352619311881710100 031378387528865875332083814206171776691473035982534904287554687311595628638823 537875937519577818577805321712268066130019278766111959092164201989 Edited to (try to) fix some formatting |
|||
02-15-2018, 11:57 PM
(This post was last modified: 02-16-2018 03:37 AM by Gerson W. Barbosa.)
Post: #35
|
|||
|
|||
RE: Creating digits of pi
(02-14-2018 11:57 PM)Gerson W. Barbosa Wrote: By using this method, a thousand digits can be computed in less than four hours (3h51m09s) on a 49G. This version is slightly faster, 3h44m25s on the 49G (1h58m17s on the 50g, 2 minutes on the emulator). Code:
Formula: \(\frac{\pi }{4}\approx 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}}{...+\frac{...}{...+\frac{n^{2}}{4n}}}}}}}\) This gives \(\frac{3n}{2}\) correct digits (for even n). Algorithm: d = 1000 ; desired number of digits n = int(d/3) + 1 ; required number of iterations a = 2*n ; number of terms in the series and in the continued fractions on (n, in the above formula) b = 8*n ; part of the denominators in the cont'ed fraction, alternating with the previous constant (4n and n, in the formula) c = 4*n*n ; rightmost squared integer in the continued fraction (n² in the formula) d = 4*n - 1 ; rightmost denominator in the series (n-1 in the formula) s1 = 0 ; initialization of the first partial sum (terms of series) s2 = 0 ; initialization of the second partial sum (terms of the continued fraction) for i = 1 to n ; start loop s1 = s1 - 1/d + 1/(d - 2) ; both the terms of the series and the terms of the continued fraction are s2 = (c - d)/(a + c/(b + s2)) ; processed two at a time, starting from the respective rightmost terms c = c - 2*(d - 1) ; next squared integers in the continued fraction are computed by simple subtraction, d = d - 4 ; like the the next denominators in the series next i ; end loop s2 = 1/(b + s2) ; add leftmost term of the continued fraction to the respective partial sum pi = 4*(s1 + s2) ; add both partial sums together and multiply the result by 4 to get pi display pi ; display pi to d decimal places This gives \(3\) digits per iteration. Edited to fix a couple of typos Edited again to fix another typo per Mike’s message below |
|||
02-16-2018, 12:45 AM
(This post was last modified: 02-16-2018 12:47 AM by Gerson W. Barbosa.)
Post: #36
|
|||
|
|||
RE: Creating digits of pi
(02-15-2018 03:00 AM)Mike (Stgt) Wrote:(02-14-2018 11:57 PM)Gerson W. Barbosa Wrote: I believe the continued fraction which works as a correction to the very slowly convergent Madhava-Leibniz series (a.k.a. Gregory series), was known to Madhava. Thanks for the link! (even though it is surely more difficult for me to grasp it than to you). Although the plain Madhava-Leibnitz series is very slowly convergent to be of any practical use, when properly tweaked it can be used to compute one thousand digits or more on a relatively slow calculator like a 49G, for instance, in a reasonable time (by reasonable time I mean before the batteries drain out :-). I have first become aware of this fact by one of the Valentin Albillo's legendary mini-challenges. I think I could take that one now, but I fear it's a bit too late :-) Madhava himself gave three correction formulas to be used after a certain number of terms are evaluated. As I've already said, it is quite possible that he could have given as many of these correction terms as he wanted, by simply calculating approximants to the continued fraction. I found it empirically, by trial and error, but this can be done systematically, as show in this paper from Research India Publications. Gerson. |
|||
02-16-2018, 03:04 AM
(This post was last modified: 02-16-2018 03:52 AM by Gerson W. Barbosa.)
Post: #37
|
|||
|
|||
RE: Creating digits of pi
(02-16-2018 02:32 AM)Mike (Stgt) Wrote:(02-15-2018 11:57 PM)Gerson W. Barbosa Wrote: Algorithm: Sorry! There’s a typo in the first line after the end of loop. It should read s2 = 1/(b + s2) I will fix it. Gerson. PS.: I’ve just tested it on the 75, with n = int(d/3) + 1 1: 3.14285714286 3: 3.1415935416 6: 3.1415926543 9: 3.14159265359 |
|||
02-16-2018, 04:11 AM
Post: #38
|
|||
|
|||
RE: Creating digits of pi
(02-16-2018 03:39 AM)Mike (Stgt) Wrote:(02-16-2018 03:04 AM)Gerson W. Barbosa Wrote: s2 = 1/(b + s2) That’s essentially the same algorithm in my second program in post #38. For some reason I decided to rename S0 and S1 to S1 and S2, respectively, but my doublecheck (or lack of it) has failed. Hopefully the RPL program is ok (just a copy & paste matter). Gerson |
|||
02-17-2018, 12:27 PM
(This post was last modified: 02-17-2018 12:59 PM by EdS2.)
Post: #39
|
|||
|
|||
RE: Creating digits of pi
I just came across this nice approximation, by Ramanujan (of course)
∜(2143/22) = 3.14159265258... (more here including some different ways to express the same result.) Edit: this same approximation is mentioned in these older threads: CALCULATING MANY DIGITS OF PI (2004) Computing PI -- a simple programming problem (2006) Yet another 12C mini-challenge (pi) (2009) |
|||
02-17-2018, 03:02 PM
(This post was last modified: 02-18-2018 03:37 PM by Gerson W. Barbosa.)
Post: #40
|
|||
|
|||
RE: Creating digits of pi
(02-17-2018 12:27 PM)EdS2 Wrote: I just came across this nice approximation, by Ramanujan (of course) That's probably the only Ramanujan approximation that doesn't rely on any of his astounding theories. He just noticed that \(\pi ^{4}\) = 97.0409091034..., very close to 97.0409090909..., which when multiplied by 990 this gives 96435. Thus, \(\pi \approx \sqrt[4]{\frac{96435}{990}}\), or \(\pi \approx \sqrt[4]{\frac{2143}{22}}\). Likewise, \((e^{\pi })^{4}\) = \(e^{4\pi }\) = 286751.31313665..., which when multiplied by 99 gives 28388380.0005287... However, \(\frac{28388380}{99}\) is irreducible. Still, \(\frac{\ln \left ( \frac{28388380}{99} \right )}{4 }\) = 3.141592653585137 is an approximation to \(\pi\), although not nearly as good as Ramanujan's, as 10 digits and two operations are used to produce only 12 digits. For \(e^{\pi }\) I would suggest these two approximations: \(\frac{16\ln 878}{\ln\left ( 16\ln 878 \right )}\) = 23.14069263691337 and \(\frac{64146}{2772}\) = 23.14069264069264 the latter being a palindromic approximation. Of course, the natural logarithm of these are also approximations to \(\pi\). Gerson. Edited to fix a typo. ------------------------------------------------ PS: Like the ones for \(\pi\) and for \(e ^{\pi }\), the fourth power of \(\ln \pi\), 1.71716522553..., will make for another approximation. So now we have \(\pi \approx \sqrt[4]{\frac{96435}{990}}\), or \(\pi \approx \sqrt[4]{\frac{2143}{22}}\) = 3.141592652582646 (3589793) \(e^{\pi }\approx \sqrt[4]{\frac{28388380}{99}}\) = 23.14069263267153 (277926) \(\ln \pi \approx \sqrt[4]{\frac{170}{99}}\) = 1.14473096774 (2988585) The latter can be improved to obtain yet another approximation for \(\pi\), albeit a not so good one: \(\pi \approx e ^{\sqrt[4]{\frac{170-\frac{400}{622401}}{99}}}\) = 3.1415926535897932121 (384) |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)