Post Reply 
Yet another π formula
Yesterday, 05:57 PM (This post was last modified: Yesterday 08:02 PM by Albert Chan.)
Post: #31
RE: Yet another π formula
Hi, EdS2

Here are improvements over your BBC Basic code.

1. k! / (2k+1)!!, numerator and denominator get huge very quickly
    We can let T = N/D, eliminate possible overflow issue.
2. 2k+1 replaced by 2k+p with p=1, for usage flexibility (see example below)
3. Instead of add last term for better pi estimate, I use Aitken extrapolated result.
4. Added plain 2*S pi estimate for comparison

Code:
10 print "Calculate Pi with double factorial"
20 L=21:P=1:T=1/P:S=T
30 for K=1 to L
40 D=2+P/K:T=T/D:S=S+T
50 print 2*(S+T/(D-1)), 2*S
60 next

BTW, my original Aitken code is this.
Code:
40 T0=T:T=T*K/(2*K+P):S=S+T
50 print 2*(S+T*T/(T0-T))

But I like D = 2+P/K ≈ 2 version better.

It clearly showed T=T/D shrink to about half, thus sum accuaracy doubled per step.
Also, it showed why add last term T to S improve estimate. Correction T/(D-1) ≈ T

(Yesterday 01:28 PM)Albert Chan Wrote:  pi/2 = (2 - 2/3 + 2/5 - 2/7 + 2/9) - 9!! * sum(k!/(2k+11)!!, k=0..inf)

lua> s1 = (2 - 2/3 + 2/5 - 2/7 + 2/9)
lua> s2 = 1/11*(1 + 1/13*(1 + 2/15*(1 + 3/17*(1 + 4/19*(1 + 5/21*(1 + 6/23))))))
lua> (s1-s2)*2
3.141594380253689

For this example, we change 1 line (run on DOS ubasic)
Note: we start from k=1, thus k=0 correction goes to S.

20 L=6:P=11:T=-1/P:S=2-2/3+2/5-2/7+2/9+T
run
Calculate Pi with double factorial
 3.1427128427128427129    3.1438783438783438784
 3.1417266494189571114    3.1420135420135420136
 3.1416139416139416141    3.1416844593315181551
 3.1415967039496451264    3.1416151787668815534
 3.1415935285904326155    3.1415986833943490292
 3.1415928614981610796    3.1415943802536883708
OK
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 - Albert Chan - 11-25-2024, 10:01 PM
RE: Yet another π formula - Albert Chan - Yesterday, 01:32 AM
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
RE: Yet another π formula - Thomas Klemm - 11-24-2024, 01:59 PM
RE: Yet another π formula - Albert Chan - 11-25-2024, 01:47 PM
RE: Yet another π formula - Albert Chan - Yesterday, 01:28 PM
RE: Yet another π formula - Ren - 11-25-2024, 01:08 AM
RE: Yet another π formula - Thomas Klemm - 11-25-2024, 06:47 PM
RE: Yet another π formula - EdS2 - Yesterday, 02:09 PM
RE: Yet another π formula - Albert Chan - Yesterday 05:57 PM
RE: Yet another π formula - AnnoyedOne - Yesterday, 02:19 PM
RE: Yet another π formula - C.Ret - Yesterday, 03:42 PM
RE: Yet another π formula - AnnoyedOne - Yesterday, 05:37 PM
RE: Yet another π formula - EdS2 - Today, 09:14 AM



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