Post Reply 
Yet another π formula
11-07-2021, 12:01 PM (This post was last modified: 11-07-2021 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 + (a-1/8)) * 8/3 + 3       (*)

Code:
OPTION ARITHMETIC DECIMAL_HIGH
10 INPUT  PROMPT "n = ":n
   LET x = 8*n+4
   LET a = 0
   LET b = 0
   FOR i = n TO 2 STEP -1
      LET t = 4*i*i-1
      LET a = a + (1+a)/t
      LET b = t / (x+b)
   NEXT i
   LET b = 2/(x-1+3/(x+b)) ! CF correction
   LET r = (a*b+b+(a-0.125)) * 8/3 + 3
   PRINT "Accurate digits ="; 1-LOG10(MAX(ABS(PI-r),1E-1000))
   GOTO 10
END

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


Messages In This Thread
Yet another π formula - Gerson W. Barbosa - 01-04-2021, 08:41 PM
RE: Yet another π formula - Albert Chan - 01-05-2021, 10:50 PM
RE: Yet another π formula - Albert Chan - 01-06-2021, 01:32 AM
RE: Yet another π formula - Albert Chan - 01-07-2021, 09:56 PM
RE: Yet another π formula - toml_12953 - 01-06-2021, 02:10 AM
RE: Yet another π formula - ttw - 01-06-2021, 03:44 AM
RE: Yet another π formula - Albert Chan - 01-09-2021, 09:22 PM
RE: Yet another π formula - Albert Chan - 11-06-2021, 06:28 PM



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