HP-42S (Free42, DM-42) mini-challenge – Wallis Product
|
07-13-2020, 08:33 PM
(This post was last modified: 07-16-2020 11:07 AM by Gerson W. Barbosa.)
Post: #29
|
|||
|
|||
RE: HP-42S (Free42, DM-42) mini-challenge – Wallis Product
(07-13-2020 07:04 AM)Werner Wrote: The limit of my routine on Free42 is 10203, which is quite a lot larger though. Yes, I had noticed that. The farther you can go, the better, no problem a few extra bytes. I thought I would need more, but n = 1000 on Free42 was enough for me to find out that \[\frac{2\pi }{\pi -2W_{n}}= 8n+5+\frac{3}{8n+4+\frac{15}{8n+4+\frac{35}{8n+4+\frac{63}{8n+4+\frac{99}{\ddots } }}}}\] The denominators of the continued fraction in the right-hand side of the expression are easily recognizable. If \(\pi\) is isolated and the continued fraction, taken with only the first three terms, is factored we get \[\pi \approx W_{n}\cdot \frac{4096n^{4}+8704n^{3}+10304n^{2}+6224n+1473}{4096n^{4}+7680n^{3}+8768n^{2}+4656n+945 }\] or \[\pi \approx W_{n}\cdot \frac{n^{4}+\frac{17}{8}n^{3}+\frac{161}{64}n^{2}+\frac{389}{256}n+\frac{1473}{4096}}{n^{4}+\frac{15}{8}n^{3}+\frac{137}{64}n^{2}+\frac{291}{256}n+\frac{945}{4096}}\] The above polynomial exactly matches the best approximation polynomial presented in the paper linked by Thibault here, which is kind of a loose proof that the formula holds. Notice that the method used by the author is not suitable for the obtention of higher order approximation polynomials. Given the regularity of the continued fraction such polynomials are easily obtainable, but they are not necessary as the continued fraction allows for easier programming. We are now ready to present the new, the astounding, the amazing... and the unknown Wallis-Wasicki formula :-) Well, since it was easy to get with virtually no math, I don't think it might be that unknown. If any of you find it in a book or over the internet, please let me know so I can name it properly. \[\pi = W_{n}\cdot \left ( 2+\frac{4}{8n+3+\frac{3}{8n+4+\frac{15}{8n+4+\frac{35}{8n+4+\frac{63}{\ddots }}}} } \right )\] where \(W_{n}\) is the Wallis Product evaluated to n terms. Or, written as an approximation, \[\pi \approx \left ( \frac{4}{3} \times \frac{16}{15}\times \frac{36}{35}\times\frac{64}{63} \times \cdots \times \frac{ 4n ^{2}}{ 4n ^{2}-1}\right ) \left ( 2+\frac{4}{8n+3+\frac{3}{8n+4+\frac{15}{8n+4+ \frac{35}{8n+4 + \frac{63}{\dots\frac{\ddots }{8n+4+\frac{4n^{2}-1}{8n+4}}} }}} } \right )\] This is of course exact when n → ∞ This appears to produce slightly more than two decimal digits per term, I don't know the exact rate of convergence but the computation of 1000 decimal digits of pi required 478 iterations. Because that has rendered the older formula obsolete, I decided to rewrite my just optimized HP-42S/Free42 program above in this thread. This is the first, still unoptimized version: Code:
01: 3.140740740740740740740740740740741 02: 3.141598489616110761485210824417872 03: 3.141592609971230454956940475005568 04: 3.141592653927057641418818559928142 05: 3.141592653587141242124980978994893 06: 3.141592653589814292336411237641248 07: 3.141592653589793070317559127943467 08: 3.141592653589793239810871784159143 09: 3.141592653589793238451802835169985 10: 3.141592653589793238462730724196084 11: 3.141592653589793238462642678516210 12: 3.141592653589793238462643388972955 13: 3.141592653589793238462643383233466 14: 3.141592653589793238462643383279871 15: 3.141592653589793238462643383279500 16: 3.141592653589793238462643383279502 For readability, here is an HP-75C version: Code:
According to Pi: A Source Book, by Lennart Berggren, Jonathan Borwein and Peter Borwein, "not even 100 years of computing on a supercomputer programmed to add or multiply the terms of either sequence [Wallis' Product (1665) and Gregory's Series (1671)] would yield 100 digits of pi" (page 113). And yet, with the simple correction factor above, 1000 digits of \(\pi\) can be computed in less than half a second on an ordinary desktop computer running Decimal BASIC: Code:
number of decimal digits: 1000 n = 478 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 2164201989 Runtime: 0.43 seconds Best regards, Gerson. ——— P.S.: Stack-only HP-42S/Free42 version: Code:
5 XEQ W → Y: 3.00217595456 X: 3.14159265359 ~ 1.7 seconds on the real HP-42S. ——— P.P.S.: We can save four bytes and four steps, if all we want is the best \(\pi\) approximation: Code:
5 XEQ W → 3.14159265358 ( ~ 1.6 seconds ) The Wallis Product approximation is still accessible after program completion: RCL ÷ . ST L 2 ÷ → 3.00217595456 |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)