Yet another π formula

01042021, 08:41 PM
(This post was last modified: 01042021 11:53 PM by Gerson W. Barbosa.)
Post: #1




Yet another π formula
The alternate sum of the factors of the Wallis product tends to \(\pi\)/4  1/2 as \(n\) tends to infinity:
\(\lim_{n\rightarrow \infty } \left [ \frac{1}{1\cdot 3}\frac{1}{3\cdot 5}+\frac{1}{5\cdot 7}\frac{1}{7\cdot 9}+\frac{1}{9\cdot 11}\frac{1}{11\cdot 13}+\frac{1}{13\cdot 15}\frac{1}{15 \cdot 17}\pm \cdots +\frac{(1)^{n1}}{4n^{2}1}\right ]=\frac{\pi }{4}\frac{1}{2}\) This converges to the constant significantly faster than the Wallis Product. For 12 correct digits of \(\pi\) it requires \(\sqrt{10^{12}}\) terms instead of the \(10^{12}\) terms required by Wallis. That's one million times as fast in this case, but obviously not enough for increasing numbers of digits. Fortunately, again, a correction continued fraction is possible which provides linear convergence, about 25/12 digits per term as the other formula. \(\pi = \lim_{n\rightarrow \infty } \left [4\left ( \frac{1}{2} + \sum_{k=1}^{n}\frac{(1)^{k1}}{4k^{2}1} \right )+\frac{(1)^{n}}{2n(n+1)+\frac{3}{2}\frac{3}{2n(n+1)+\frac{19}{2}\frac{60}{2n(n+1)+\frac{51}{2}\frac{315}{\frac{\ddots }{\cdots 2n(n+1)+\frac{8n(n1)+3}{2}\frac{n^{2}(4n^{2}1)}{2n(n+1)+\frac{8n(n+1)+3}{2}}} }}}}\right ]\) Tentatively, I think I can name this one as "Wasicki's formula" :) Well, at least while an older equivalent version doesn´t appear around. The algorithm is very simple, as tested on the HP75C: 10 INPUT N 15 C=0 20 D=6*N*(N+1)+3/2 25 E=8*N 30 M=4*N*N1 35 S=1 40 W=0 45 FOR K=1 TO N 50 W=WS/M 55 C=M*(M+1)/(4*(C+D)) 60 M=ME+4 65 D=DE 70 E=E8 75 S=S 80 NEXT K 85 DISP S*(4*W+1/(C+D))+2 >run ?5 3.14159265359 I can get one thousand digits in little more than one fourth of a second on my old desktop computer, using that algorithm: n = 480 3.1415926535 8979323846 2643383279 5028841971 6939937510 (0050) 5820974944 5923078164 0628620899 8628034825 3421170679 (0100) 8214808651 3282306647 0938446095 5058223172 5359408128 (0150) 4811174502 8410270193 8521105559 6446229489 5493038196 (0200) 4428810975 6659334461 2847564823 3786783165 2712019091 (0250) 4564856692 3460348610 4543266482 1339360726 0249141273 (0300) 7245870066 0631558817 4881520920 9628292540 9171536436 (0350) 7892590360 0113305305 4882046652 1384146951 9415116094 (0400) 3305727036 5759591953 0921861173 8193261179 3105118548 (0450) 0744623799 6274956735 1885752724 8912279381 8301194912 (0500) 9833673362 4406566430 8602139494 6395224737 1907021798 (0550) 6094370277 0539217176 2931767523 8467481846 7669405132 (0600) 0005681271 4526356082 7785771342 7577896091 7363717872 (0650) 1468440901 2249534301 4654958537 1050792279 6892589235 (0700) 4201995611 2129021960 8640344181 5981362977 4771309960 (0750) 5187072113 4999999837 2978049951 0597317328 1609631859 (0800) 5024459455 3469083026 4252230825 3344685035 2619311881 (0850) 7101000313 7838752886 5875332083 8142061717 7669147303 (0900) 5982534904 2875546873 1159562863 8823537875 9375195778 (0950) 1857780532 1712268066 1300192787 6611195909 2164201989 (1000) Runtime: 0.27 seconds Edited to correct a mistake, per Valentín Albillo’s note below. 

01042021, 11:21 PM
Post: #2




RE: Yet another π formula
(01042021 08:41 PM)Gerson W. Barbosa Wrote: This converges to the constant significantly faster than the Wallis Product. For 12 correct digits of \(\pi\) it requires \(\sqrt{10^{12}}\) terms instead of the \(10^{12}\) terms required by Nope. The square root evaluates to 10^{6} so it's 1,000,000 times as fast, not 1000 as you say. Regards. V. All My Articles & other Materials here: Valentin Albillo's HP Collection 

01042021, 11:36 PM
Post: #3




RE: Yet another π formula
(01042021 11:21 PM)Valentin Albillo Wrote:(01042021 08:41 PM)Gerson W. Barbosa Wrote: This converges to the constant significantly faster than the Wallis Product. For 12 correct digits of \(\pi\) it requires \(\sqrt{10^{12}}\) terms instead of the \(10^{12}\) terms required by You are right, thanks! I was thinking of the n=1000 example I had just checked on my smartphone when I wrote that. I’d like to have checked the sum of the first 1000000 terms on Free42, but my program would fail short of n = 100000. Hopefully the rest is correct. Best regards, Gerson. 

01052021, 10:50 PM
Post: #4




RE: Yet another π formula
(01042021 08:41 PM)Gerson W. Barbosa Wrote: The alternate sum of the factors of the Wallis product tends to \(\pi\)/4  1/2 as \(n\) tends to infinity: Where does this limit comes from ? CAS can get pi/4  1/2, but the "proof" felt cheating. Cas> expand(sum(1/((4*k3)*(4*k1))1/((4*k1)*(4*k+1)),k = (1 .. ∞))) → 1/4*π1/2  I find this remarkable formula for approximating the sum of alternating series. Example: above pi formula, for 1000 terms To reduce errors, do the sum in pairs, and backwards. lua> s = 0 lua> for k=500,1,1 do c=4*k1; s=s+4/(c*(c*c4)) end lua> (s + 0.5) * 4 3.141592154089668 Add correction, from next 3 terms: lua> function term(k) return (1)^(k1)/(4*k*k1) end lua> f1, f2, f3 = term(1001), term(1002), term(1003) lua> s = s + (7*f1  f2  2*f3)/12  alternate series correction lua> (s + 0.5) * 4 3.141592653588056 lua> pi 3.141592653589793 

01062021, 12:53 AM
Post: #5




RE: Yet another π formula
(01052021 10:50 PM)Albert Chan Wrote:(01042021 08:41 PM)Gerson W. Barbosa Wrote: The alternate sum of the factors of the Wallis product tends to \(\pi\)/4  1/2 as \(n\) tends to infinity: Sum(n=1, inf, (1)^(n1)/(4n^21)) (WolframAlpha) 

01062021, 01:32 AM
Post: #6




RE: Yet another π formula
Quote:\(\lim_{n\rightarrow \infty } \left [ \frac{1}{1\cdot 3}\frac{1}{3\cdot 5}+\frac{1}{5\cdot 7}\frac{1}{7\cdot 9}+\frac{1}{9\cdot 11}\frac{1}{11\cdot 13}+\frac{1}{13\cdot 15}\frac{1}{15 \cdot 17}\pm \cdots +\frac{(1)^{n1}}{4n^{2}1}\right ]=\frac{\pi }{4}\frac{1}{2}\) Proof: atan(x) = x  x^3/3 + x^5/5  x^7/7 + ... atan(1) = pi/4 = 1  1/3 + 1/5  1/7 + ... 2*I = 2/(1*3)  2/(3*5) + 2/(5*7)  2/(7*9) + ... = (11/3)  (1/31/5) + (1/51/7)  (1/71/9) + ... = (11/3+1/51/7+...) + (1/3+1/51/7+...) = pi/4 + (pi/4  1) → I = pi/4  1/2 

01062021, 02:10 AM
Post: #7




RE: Yet another π formula
(01042021 08:41 PM)Gerson W. Barbosa Wrote: The algorithm is very simple, as tested on the HP75C: How do you get all those digits? There's only one DISP statement. What is the precision of the interpreter on your PC? Tom L Cui bono? 

01062021, 02:41 AM
Post: #8




RE: Yet another π formula
(01062021 02:10 AM)toml_12953 Wrote:(01042021 08:41 PM)Gerson W. Barbosa Wrote: The algorithm is very simple, as tested on the HP75C: Sorry, I forgot to mention I was using Decimal BASIC at maximum precision (1000 digits). 

01062021, 03:44 AM
Post: #9




RE: Yet another π formula
One problem for all methods is that the last few iterations may dominate in that these must be done to really large precision. Some years ago (about the time of the first trillion digits computation) it was noted that the last division of sizes around 1,000,000, leading to the 1,000,000,000,000 digits takes most of the time in the computation. It completely dominated (at that time) the computation of the previous terms.
Fast (fourth order) methods were not much faster than first order or second order computations. The online stuff nice (but it's base 16) and requires a trillion digit base conversion at the end. 

01072021, 12:57 PM
(This post was last modified: 01072021 12:58 PM by Gerson W. Barbosa.)
Post: #10




RE: Yet another π formula
(01062021 01:32 AM)Albert Chan Wrote:Quote:\(\lim_{n\rightarrow \infty } \left [ \frac{1}{1\cdot 3}\frac{1}{3\cdot 5}+\frac{1}{5\cdot 7}\frac{1}{7\cdot 9}+\frac{1}{9\cdot 11}\frac{1}{11\cdot 13}+\frac{1}{13\cdot 15}\frac{1}{15 \cdot 17}\pm \cdots +\frac{(1)^{n1}}{4n^{2}1}\right ]=\frac{\pi }{4}\frac{1}{2}\) Great! The continued fraction part is left unproved, however. But that would not be easy, I presume. 

01072021, 09:56 PM
(This post was last modified: 01092021 08:35 PM by Albert Chan.)
Post: #11




RE: Yet another π formula
(01072021 12:57 PM)Gerson W. Barbosa Wrote: Great! The continued fraction part is left unproved, however. But that would not be easy, I presume. "Wasicki's formula" had first term converge to pi, correction converge to 0. QED As to the gain of 25/12 digits per term, it tested OK even with 10,000 digits precision. Code: def test_pi(n, cf=0, c=0, s=0): >>> from gmpy2 import * >>> get_context().precision = 34000 # > 10000 dec. digits >>> pi = const_pi() >>> >>> for n in range(1000,4001,1000): print n, format(pi  test_pi(n), 'g') ... 1000 2.19966e2091 2000 2.92237e4181 3000 3.88382e6271 4000 5.16203e8361 

01082021, 01:05 AM
Post: #12




RE: Yet another π formula
(01072021 09:56 PM)Albert Chan Wrote:(01072021 12:57 PM)Gerson W. Barbosa Wrote: Great! The continued fraction part is left unproved, however. But that would not be easy, I presume. Were the correction term simply 1/(2n*(n + 1)) then this proof would still hold. Perhaps I should say “prove that the continuous fraction is equivalent to the optimal correction polynomial expression to the series”. That would be really hard, at least for me. If you find a valid proof then the formula should be renamed as “WasickiChan Formula” or more appropriately “ChanWasicki Formula”. Anyone can easily find such formulae. Anyone or anything – even Mathematica and W/A can, I think. But only a few can prove them. Anyway nowadays these formulae are just useless mathematical curiosities. (01072021 09:56 PM)Albert Chan Wrote: As to the gain of 25/12 digits per term, it tested OK even with 10,000 digits precision. Thank you for performing these tests. Much appreciated! 

01082021, 01:24 AM
Post: #13




RE: Yet another π formula
(01072021 09:56 PM)Albert Chan Wrote:(01072021 12:57 PM)Gerson W. Barbosa Wrote: Great! The continued fraction part is left unproved, however. But that would not be easy, I presume. Were the correction term simply 1/(2n*(n + 1)) then this proof would still hold. Perhaps I should say “prove that the continuous fraction is equivalent to the optimal correction polynomial expression to the series”. That would be really hard, at least for me. If you find a valid proof then the formula should be renamed as “WasickiChan Formula” or more appropriately “ChanWasicki Formula”. Anyone can easily find such formulae. Anyone or anything – even Mathematica and W/A can, I think. But only a few can prove them. Anyway nowadays these formulae are just useless mathematical curiosities. (01072021 09:56 PM)Albert Chan Wrote: As to the gain of 25/12 digits per term, it tested OK even with 10,000 digits precision. Thank you for performing these tests. Much appreciated! 

01092021, 09:22 PM
(This post was last modified: 11062021 04:21 PM by Albert Chan.)
Post: #14




RE: Yet another π formula
Hi, Gerson W. Barbosa
I don't know how to quantify "optimal" correction. May be you want to proof this instead ? \(\pi = \displaystyle\left( 2 + 4\sum_{k=1}^{n}\frac{(1)^{k1}}{4k^{2}1} \right ) + \lim_{k\rightarrow \infty }\left(\frac{(1)^{n}} {b\;\;\frac{3}{\large b+8\;\; \frac{60}{\frac{\ddots }{b+4k(k1)\;\;\frac{k^2 (4k^21)}{ b+4k(k+1) }}}}}\right) ,\quad b = 2n(n+1) + {3\over2}\) This is not a proof, but I am convinced that above is true. Nice work First, try n=0, i.e. summation term = 0. Relied only on limit, convergence rate is bad, but it is indeed approach pi. >>> from gmpy2 import * >>> get_context().precision = 1000 # ~ 300 dec. digits >>> pi = const_pi() >>> for i in range(7): print i, format(pi  test_pi(n = 0, cf = 10**i), 'g') ... 0 0.297148 1 0.0675375 2 0.00772836 3 0.000784124 4 7.85271e05 5 7.85385e06 6 7.85397e07 Now, try combination of summation and limit. >>> for i in range(7): print i, format(pi  test_pi(n = 9, cf = 10**i), 'g') ... 0 5.30332e21 1 1.07719e25 2 1.47115e39 3 8.06555e58 4 9.64229e77 5 9.81688e96 6 9.83452e115 >>> for i in range(7): print i, format(pi  test_pi(n = 10, cf = 10**i), 'g') ... 0 4.18442e23 1 5.76716e28 2 6.21078e43 3 4.82312e63 4 5.98619e84 5 6.11764e105 6 6.13095e126 Note: test_pi() from previous post, modified to allow extra cf terms, beyond n. Note: unlike summation term, CF correction convergence is onesided. 

01102021, 02:57 PM
(This post was last modified: 01102021 03:12 PM by Gerson W. Barbosa.)
Post: #15




RE: Yet another π formula
Hello, Albert Chan,
(01092021 09:22 PM)Albert Chan Wrote: First, try n=0, i.e. summation term = 0. I did that about seven years ago ( https://www.hpmuseum.org/forum/post9194.html#pid9194 ). Then I noticed that optimal result (best approximation using the least number of terms) is obtained when the number of terms of the series is equal to the number of terms of the continued fraction. ln(2) = 1  1/2 + 1/3  1/4 + ... + (1)^(n + 1)/n + 1/((2*n+1) + CF) CF: numeratorₖ = k*k; denominatorₖ = 2*n + 1; k = 1 to ∞ n = 2 k = 1 ln(2) ~ 1  1/2 + (1)^(1 + 1)/((2*2+1)+1*1/(2*2+1)) ~ 9/13 ~ 0.69(23076923076923076923076923076923) n = 2 k = 10^6 ln(2) ~ 0.693147180559945309417232121458(3016) n = 2 k = 10^7 ln(2) ~ 0.6931471805599453094172321214581766 Here we need 10^7 terms of the continued fraction to correct ln(2) ~ 1/2 to 34 digits. On the other hand we get the same result with n = 22 and k = 22. Perhaps the correction CF for the Wallis Product is easier to prove, since the equivalent polynomial expressions of the first few terms of the CF match those described in this paper. More details in the beginning of this post. 

11062021, 06:28 PM
(This post was last modified: 11072021 11:09 AM by Albert Chan.)
Post: #16




RE: Yet another π formula
This pi formula is very similar to zeta(2) alternating sum formula
(11052021 03:55 PM)Albert Chan Wrote:(10312021 03:40 PM)Albert Chan Wrote: Let s = (1)^n, x=n*n+n+1, T's = triangular number... Apply the same idea here, we have this for estimating PI Code: OPTION ARITHMETIC DECIMAL_HIGH p (pairs) = 100 Accurate digits = 308.79106444764398 p (pairs) = 101 Accurate digits = 311.85336518362854 p (pairs) = 300 Accurate digits = 921.2386113713281 p (pairs) = 301 Accurate digits = 924.30082763127136 For p=326, it reached 1000 digits full precision. 

11072021, 12:01 PM
(This post was last modified: 11072021 12:45 PM by Albert Chan.)
Post: #17




RE: Yet another π formula
Wallis product part is *very slowly* converging; probably not a good idea to cut down CF terms.
Another issue is to limit rounding erors of Wallis product. To improve accuracy, we keep track of partial product, less 1. (1+a)*(1+1/t)  1 = a + (1+a)/t To recover pi, we just add back 1 (after loops finished) pi ≈ (1+a)*(1+b)*8/3 = (a*b + b + (a1/8)) * 8/3 + 3 (*) Code: OPTION ARITHMETIC DECIMAL_HIGH n = 100 Accurate digits = 211.18296908289588 n = 101 Accurate digits = 213.27288787760364 n = 300 Accurate digits = 629.16112325948984 n = 301 Accurate digits = 631.25100446831984 For n=478, it reached 1000 digits full precision. Previous version take more total terms (3p=3*326=978) vs here (2n=2*478=956) But, pairwise sum can be greatly simplified → Previous version is faster, by about 30% (*) By Sterbenz lemma, term (a1/8) is exact n<2: it never enter the loop, thus a = 0 n=2: a = 16/15  1 = 1/15, within [1/16,1/4] With more products, a is increasing. limit(a, n=inf) = 3/8*pi  1 ≈ 1/5.6 ≤ 1/4 

« Next Oldest  Next Newest »

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