Creating digits of pi
|
02-17-2018, 04:25 PM
(This post was last modified: 02-17-2018 04:25 PM by pier4r.)
Post: #41
|
|||
|
|||
RE: Creating digits of pi
(02-14-2018 07:37 AM)Massimo Gnerucci Wrote: There's no last digit in π... https://www.smbc-comics.com/?id=3639 (02-17-2018 12:27 PM)EdS2 Wrote: Edit: this same approximation is mentioned in these older threads: It is impressive how many nice contributions the computation of PI stimulates. So far the best search string to find interesting - for my perspective - content here if I want to dig in the past is: site:hpmuseum.org challenge OR contest OR puzzle OR pi OR constant OR solution OR answer I would like to use site:hpmuseum.org challenge OR contest OR puzzle OR pi OR constant OR (math problem) But parentheses do not work with google at the moment. Wikis are great, Contribute :) |
|||
02-17-2018, 09:27 PM
(This post was last modified: 02-17-2018 09:28 PM by brickviking.)
Post: #42
|
|||
|
|||
RE: Creating digits of pi
(02-17-2018 04:25 PM)pier4r Wrote: I would like to use (For parentheses,) I use "these things" instead. Never worked a lick for me, but hey... YMMAW. (Post 16 2 YX 9 2 YX -) Regards, BrickViking HP-50g |Casio fx-9750G+ |Casio fx-9750GII (SH4a) |
|||
02-21-2018, 11:01 AM
(This post was last modified: 02-21-2018 04:39 PM by EdS2.)
Post: #43
|
|||
|
|||
RE: Creating digits of pi
(02-17-2018 03:02 PM)Gerson W. Barbosa Wrote:(02-17-2018 12:27 PM)EdS2 Wrote: I just came across this nice approximation, by Ramanujan (of course) Hmm, would a mathematical genius look at a decimal expansion? I would hope for some rather more sophisticated source of the insight - but do we know, or can we ever know, where this approximation came from? I can't resist sharing this other one from Ramanujan, which agrees to 18 digits apparently but with only 12 digits in the expression: \(\pi \approx \frac{12}{\sqrt{190}}\log\big((2\sqrt{2}+\sqrt{10})(3+\sqrt{10})\big)\) As continued fractions: 3; 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 2, 1, 1, 2, 2, 2, 2, ... vs 3; 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 2, 1, 1, 2, 2, 1, 2, ... Edit: found this one in Ramanujan's papers - see TABLE II here. |
|||
02-23-2018, 01:34 PM
Post: #44
|
|||
|
|||
RE: Creating digits of pi
(02-11-2018 12:12 AM)TASP Wrote: Yeah, not helpful at all, but for some random digit of Pi in base 2, just guess. For a single digit, yes. For multiple digits you need to be increasingly lucky. For 2 digits a guess may be correct 25% of the time. 3 digits, 12,5% of the time. 4 digits 6.25% etc... Wikis are great, Contribute :) |
|||
05-12-2018, 01:42 AM
(This post was last modified: 06-01-2018 12:27 AM by Gerson W. Barbosa.)
Post: #45
|
|||
|
|||
RE: Creating digits of pi
(02-15-2018 11:57 PM)Gerson W. Barbosa Wrote: Formula: Sorry to post again in this relatively old thread, but I think it still fits here. Yesterday, while googling for Madhava's correction terms (which are simply the first convergents of the continued fraction above, itself not unbeknownst to Hindu mathematicians of that time, according to some sources), I found a 5-hundred-year old infinite series for \(\pi\), by Nilakantha: \(\frac{\pi}{8} = \frac{1}{1\cdot 3} + \frac{1}{5\cdot 7 } + \frac{1}{9\cdot 11} +\frac{1}{13\cdot 15}+\cdots =\sum_{n=1}^{\infty}\frac{1}{\left ( 4n-3 \right )\left ( 4n-1 \right )}\) ( Pride of India: A Glimpse Into India's Scientific Heritage, page 53 ) It's a small improvement of Madhava's original series (there are other two in the reference above). It can overwhelmingly be accelerated by a continuous fraction as well: \(\frac{\pi}{8} \approx \frac{1}{1\cdot 3} + \frac{1}{5\cdot 7 } + \frac{1}{9\cdot 11} +\frac{1}{13\cdot15}+\cdots+\frac{1}{\left ( 4n-3 \right )\left ( 4n-1 \right )} +\frac{1}{16n+\frac{1}{n+\frac{4}{16n+\frac{9}{n+\frac{16}{\ddots +\frac{\ddots}{\ddots+\frac{n^{2}}{n\left [ 16-15\left ( n\bmod 2\right ) \right ]}}}}}}}\) Being a non-alternating series, it is somewhat more simple to program, giving slightly more than two digits per iteration, when only one term of the series and one term of the continued fraction are processed at a time, starting from the respective last terms: OPTION ARITHMETIC DECIMAL_HIGH INPUT PROMPT "Number of decimal places: ":f LET t = TIME LET k = CEIL((f + 1)*12/25) LET s = 0 LET a = 16*k*(k - 1) + 3 LET b = 32*k LET c = 0 LET n = k*k LET m = 2*k - 1 LET d = k*(16 - 15*MOD(k,2)) LET e = 15*k*(2*MOD(k,2) - 1) FOR i = 1 TO k LET s = s + 1/a LET b = b - 32 LET a = a - b LET c = n/(c + d) LET n = n - m LET m = m - 2 LET d = d + e LET e = -e NEXT i LET c = 1/(c + d) LET r = TIME - t LET p$ = STR$(8*(s + c)) PRINT p$(1:2); FOR i = 3 TO f + 2 PRINT p$(i:i); IF MOD((i - 2),10) = 0 THEN PRINT " "; IF MOD((i - 2),100) = 0 THEN PRINT " "; END IF NEXT i IF MOD (i - 3,100) <> 0 OR f = 0 THEN PRINT PRINT "Runtime: "; PRINT USING "0.##": r; PRINT " seconds" END Number of decimal places: 999 3.1415926535 8979323846 2643383279 5028841971 6939937510 5820974944 5923078164 0628620899 8628034825 3421170679 8214808651 3282306647 0938446095 5058223172 5359408128 4811174502 8410270193 8521105559 6446229489 5493038196 4428810975 6659334461 2847564823 3786783165 2712019091 4564856692 3460348610 4543266482 1339360726 0249141273 7245870066 0631558817 4881520920 9628292540 9171536436 7892590360 0113305305 4882046652 1384146951 9415116094 3305727036 5759591953 0921861173 8193261179 3105118548 0744623799 6274956735 1885752724 8912279381 8301194912 9833673362 4406566430 8602139494 6395224737 1907021798 6094370277 0539217176 2931767523 8467481846 7669405132 0005681271 4526356082 7785771342 7577896091 7363717872 1468440901 2249534301 4654958537 1050792279 6892589235 4201995611 2129021960 8640344181 5981362977 4771309960 5187072113 4999999837 2978049951 0597317328 1609631859 5024459455 3469083026 4252230825 3344685035 2619311881 7101000313 7838752886 5875332083 8142061717 7669147303 5982534904 2875546873 1159562863 8823537875 9375195778 1857780532 1712268066 1300192787 6611195909 216420198 Runtime: 0.30 seconds The 12/25 factor to determine the required number of terms may not be exact. I expected it to be 1/2 from the first tests, but I cannot confirm it to be correct the thousand-digit evaluation which is possible in Decimal BASIC. Edited to remove Text Size large option from one of the formulas (which was stopping the page from opening is some Apple devices with iOS 11) Edited to replace mid$ and left$ with their ANSI equivalents, per Tom L's suggestion below. Also, output format has been changed to display digits in groups of ten. 06-01-2018, 12:27 AM PS: (HP 50g) RPL versions: 1) Built-in LongInt version %%HP: T(3)A(R)F(.); \<< R\->I PUSH RAD -105 CF -3 CF DUP 1 + 12 * 25 / CEIL DUPDUP 1 - * 16 * 3 + OVER 32 * ROT DUPDUP SQ UNROT DUP + 1 - OVER DUP 2 MOD 15 * NEG 16 + * ROT DUPDUP 2 MOD 2 * 1 - * 15 * 0 8 ROLLD 7 ROLL ROT 0 UNROT 8 ROLL 1 ROT START UNROT DUP INV ROT + ROT 32 - ROT OVER - 7 PICK 9 ROLL 7 PICK + / 8 ROLLD 7 ROLL 7 PICK - 7 ROLLD 6 ROLL 2 - 6 ROLLD 5 ROLL 5 PICK + 5 ROLLD 4 ROLL NEG 4 ROLLD SWAP NEXT 8 ROLL 6 ROLL + INV 4 ROLL + 6 ROLLD 5 DROPN 8 * EXPAND FXND PICK3 ALOG OVER - PICK3 * SWAP IQUOT + \->STR DUP HEAD -51 FC? { "." } { "," } IFTE + SWAP TAIL + 1 ROT 2 + SUB POP \>> It will become extremely slow for increasing number of digits: 100 digits: 54.77 seconds 200 digits: 437.91 seconds 500 digits: 20583.40 seconds 2) LongFloat version %%HP: T(3)A(D)F(.); \<< DUP 2. + 'DIGITS' STO 12. * 25. / CEIL DUPDUP 1. - * 16. * 3. + OVER 32. * ROT DUPDUP SQ UNROT DUP + 1. - OVER DUP 2. MOD 15. * NEG 16. + * ROT DUPDUP 2. MOD 2. * 1. - * 15. * 0. R\<-\->F 8. ROLLD 7. ROLL ROT 0. R\<-\->F UNROT 8. ROLL 1. ROT START UNROT DUP R\<-\->F FINV ROT FADD ROT 32. - ROT OVER - 7. PICK R\<-\->F 9. ROLL 7. PICK R\<-\->F FADD FDIV 8. ROLLD 7. ROLL 7. PICK - 7. ROLLD 6. ROLL 2. - 6. ROLLD 5. ROLL 5. PICK + 5. ROLLD 4. ROLL NEG 4. ROLLD SWAP NEXT 8. ROLL 6. ROLL R\<-\->F FADD FINV 4. ROLL FADD 6. ROLLD 5. DROPN 8. R\<-\->F FMULT -1. 'DIGITS' STO+ ZZ\<-\->F DROP \->STR DUP HEAD -51. FC? { "." } { "," } IFTE + SWAP TAIL + \>> 100 digits: 24.98 seconds 200 digits: 83.11 seconds 500 digits: 731.91 seconds 1000 digits: 5111.75 seconds 2000 digits: 851.03 seconds (on the emulator, @ 2.6 GHz) 3. 14159265358979323846264338327950288419716939937510 58209749445923078164062862089986280348253421170679 82148086513282306647093844609550582231725359408128 48111745028410270193852110555964462294895493038196 44288109756659334461284756482337867831652712019091 45648566923460348610454326648213393607260249141273 72458700660631558817488152092096282925409171536436 78925903600113305305488204665213841469519415116094 33057270365759591953092186117381932611793105118548 07446237996274956735188575272489122793818301194912 98336733624406566430860213949463952247371907021798 60943702770539217176293176752384674818467669405132 00056812714526356082778577134275778960917363717872 14684409012249534301465495853710507922796892589235 42019956112129021960864034418159813629774771309960 51870721134999999837297804995105973173281609631859 50244594553469083026425223082533446850352619311881 71010003137838752886587533208381420617177669147303 59825349042875546873115956286388235378759375195778 18577805321712268066130019278766111959092164201989 38095257201065485863278865936153381827968230301952 03530185296899577362259941389124972177528347913151 55748572424541506959508295331168617278558890750983 81754637464939319255060400927701671139009848824012 85836160356370766010471018194295559619894676783744 94482553797747268471040475346462080466842590694912 93313677028989152104752162056966024058038150193511 25338243003558764024749647326391419927260426992279 67823547816360093417216412199245863150302861829745 55706749838505494588586926995690927210797509302955 32116534498720275596023648066549911988183479775356 63698074265425278625518184175746728909777727938000 81647060016145249192173217214772350141441973568548 16136115735255213347574184946843852332390739414333 45477624168625189835694855620992192221842725502542 56887671790494601653466804988627232791786085784383 82796797668145410095388378636095068006422512520511 73929848960841284886269456042419652850222106611863 06744278622039194945047123713786960956364371917287 46776465757396241389086583264599581339047802759010 |
|||
05-12-2018, 03:18 AM
Post: #46
|
|||
|
|||
RE: Creating digits of pi
(05-12-2018 01:42 AM)Gerson W. Barbosa Wrote: The 12/25 factor to determine the required number of terms may not be exact. I expected it to be 1/2 from the first tests, but I cannot confirm it to be correct the thousand-digit evaluation which is possible in Decimal BASIC. If you want to maintain compatibility with ANSI BASIC and possibly future versions of Decimal BASIC, change PRINT left$(p$,2); to PRINT p$(1:2); and PRINT mid$(p$,i,1); to PRINT p$(i:i); left$, right$ and mid$ aren't in the ANSI standard and may go away in future versions of Decimal BASIC. Tom L Cui bono? |
|||
05-12-2018, 03:47 AM
(This post was last modified: 05-12-2018 03:56 AM by Gerson W. Barbosa.)
Post: #47
|
|||
|
|||
RE: Creating digits of pi
(05-12-2018 03:18 AM)toml_12953 Wrote: If you want to maintain compatibility with ANSI BASIC and possibly future versions of Decimal BASIC, change It's a pity, though. LEFT$, RIGHT$ and MID$ are so much more intuitive! Anyway, thanks for the information. I'll edit the program tomorrow on the computer. Speaking of compatibility, there's no way I can read this page on any of my Apple devices, except on the old iPhone 4 I'm using right now. Not sure whether it's my fault or Apple's... |
|||
05-12-2018, 03:12 PM
(This post was last modified: 05-12-2018 03:23 PM by Gerson W. Barbosa.)
Post: #48
|
|||
|
|||
RE: Creating digits of pi
(05-12-2018 01:42 AM)Gerson W. Barbosa Wrote: ... I found a 5-hundred-year old infinite series for \(\pi\), by Nilakantha: Just for the record, probably already known, obtained by simply following the previous models: \[\frac{\pi}{48} = \frac{1}{1\cdot 3\cdot 5 } - \frac{1}{7\cdot 9 \cdot 11 } + \frac{1}{13\cdot 15\cdot 17 } - \frac{1}{19\cdot 21\cdot 23}\pm \cdots =\sum_{n=1}^{\infty}\frac{\left (-1 \right )^{n+1}}{\left ( 6n-5 \right )\left ( 6n-3 \right )\left ( 6n-1 \right ) }\] The first correction term appears to be \(\left (-1 \right )^{n}\left (432n^{3}+600n \right )^{-1}\). This might make for a more efficient solution (when compared to the previous one). |
|||
05-12-2018, 03:41 PM
Post: #49
|
|||
|
|||
RE: Creating digits of pi
(05-12-2018 03:47 AM)Gerson W. Barbosa Wrote: Speaking of compatibility, there's no way I can read this page on any of my Apple devices, except on the old iPhone 4 I'm using right now. Not sure whether it's my fault or Apple's... http://www.hpmuseum.org/forum/thread-10733.html |
|||
05-13-2018, 05:09 PM
(This post was last modified: 05-13-2018 05:09 PM by SlideRule.)
Post: #50
|
|||
|
|||
RE: Creating digits of pi
I find … [attachment=5932]… a useful publication.
BEST! SlideRule |
|||
05-13-2018, 08:26 PM
(This post was last modified: 05-13-2018 08:28 PM by Gerson W. Barbosa.)
Post: #51
|
|||
|
|||
RE: Creating digits of pi
(05-13-2018 05:09 PM)SlideRule Wrote: I find … … a useful publication. I don't know it, but I am sure it is. Thanks for the book suggestion! Regarding the latest kind of series I've been experimenting with, I've found out that Wolfram Alpha is a good verifying tool. Just submit them to W|A and it will tell what it evaluates to. For instance, sum(k=1, ∞, (-1)^(k + 1)/((6k - 5)(6k - 3)(6k - 1))) = π/48 and sum(k=1, ∞, 1/((8k - 7)(8k - 5)(8k - 3)(8k - 1))) = π(2 - √2)/192 I'll stick to the former because I intend to use it in the hp 50g with no external libraries. Also, it can be implemented with only one division and one multiplication per term. Best regards, Gerson. -------------------------- >LIST 10 DESTROY ALL 12 INPUT K @ IF K=0 THEN END 15 S=0 @ Z=2*MOD(K,2)-1 @ W=Z 20 A=K*(K*(216*K-324)+138)-15 25 N=K*K @ M=2*K-1 30 FOR I=1 TO K 35 S=S+Z/A @ Z=-Z 40 N=N-M @ M=M-2 45 E=648*N+30 @ A=A-E 50 NEXT I 55 DISP 48*S;48*(S-W/(K*K*(432*K+600))) 60 GOTO 12 >RUN ? 1 3.2 3.15348837209 ? 2 3.13073593074 3.13893265205 ? 3 3.14521556875 3.14240262923 ? 4 3.13998510127 3.14127376106 ? 5 3.14243720856 3.14174155638 ? 10 3.14148304058 3.14158060156 ? 100 3.14159254249 3.14159265208 ? 372 3.14159265144 3.14159265359 ? 1500 3.14159265356 3.14159265359 I have yet to find the correcting continued fraction. The second value uses only the first correction term, which is not good enough for my purpose. |
|||
05-16-2018, 12:21 AM
Post: #52
|
|||
|
|||
RE: Creating digits of pi
(05-13-2018 08:26 PM)Gerson W. Barbosa Wrote: Also, it can be implemented with only one division and one multiplication per term. With one division only, actually. The other slightly more complex series might require at least one division and one multiplication per term, though: INPUT PROMPT "Number of terms: ":k LET s = 0 LET z = 2*MOD(k,2) - 1 LET a = k*(k*(216*k - 324) + 138) - 15 LET g = 648*k*k LET h = 648*(2*k - 1) FOR i = 1 TO k LET s = s + z/a LET z = -z LET g = g - h LET h = h - 1296 LET e = g + 30 LET a = a - e NEXT i LET p = 48*s ! s = 1/15 - 1/693 + 1/3315 - 1/9177 + 1/19575 -+ ... PRINT "pi ~ "; p ! or s = 1/(1*3*5) - 1/(7*9*11) + 1/(13*15*17) -+ ... END Number of terms: 1130 pi ~ 3.14159265351279 ================= INPUT PROMPT "Number of terms: ":k LET s = 0 LET a = k*(k*(k*(4096*k + 8192) + 5504) + 1408) + 105 LET g = 64*k*k LET h = 64*(2*k - 1) LET j = 256*k LET e = j*(64*k*k + 11) FOR i = 1 TO k LET a = a - e LET s = s + 1/a LET g = g - h LET h = h - 128 LET j = j - 256 LET e = j*(g + 11) NEXT i LET p = 192*s/(2 - SQR(2)) ! s = 1/105 + 1/19305 + 1/156009 + 1/606825 + 1/1666665 + ... PRINT "pi ~ "; p ! or s = 1/(1*3*5*7) + 1/(9*11*13*15) + 1/(17*19*21*23) + ... END Number of terms: 702 pi ~ 3.14159265351269 |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 3 Guest(s)