Post Reply 
Wallis' product exploration
02-08-2020, 02:42 PM
Post: #3
RE: Wallis' product exploration
(02-08-2020 02:13 AM)Albert Chan Wrote:  You can check the result with a direct formula, for n terms, here

Really interesting document, thanks! I'll send it to my cousin.
(By the way I won't say using factorial or double factorial is a "direct formula", as it is an iteration also. But... of course if there were a direct formula for PI, nobody would have tried to calculate its decimals with years and years of computing! Smile )
I used the double factorial function of Wolfram Alpha to evaluate pi for n=10, then 100, ... and compare with my algorithm accuracy.
Code:

2/(2*n+1)*((2*n)!!/(2*n-1)!!)^2 where n=10
Wolfram & Free42 agree with the following values:
n=10: 3.06770380664[...more digits with Wolfram but I fixed accuracy on 12]
n=100: 3.13378749063
n=1E3: 3.14080774603
n=1E6: 3.14159186819
n=1E8: 3.14159264574

I can conclude I have no problems of accuracy with.
With Free42 on iPhone XR it takes approximately 6 minutes to compute for 1E8.

(02-08-2020 02:13 AM)Albert Chan Wrote:  Or, using lgamma(), we have

\(\log \left(2 \prod _{k=1} ^{k=n} {4k^2 \over 4k^2-1}\right) =
4\log(\Gamma(n)) - 2\log(\Gamma(2n)) + n \log(16) + 2 \log(n) - \log(4n+2) \)

Example, using log1p and sum the logarithm of the terms backwards, this matched above formula

lua> require'mathx'
lua> log1p = mathx.log1p
lua> s=0; for i=100e6, 1, -1 do s = s - log1p(-1/(4*i*i)) end
lua> = 2*math.exp(s)
3.1415926457358117
I found quite the same for Free42 and Wolfram ! n=1E8: 3.14159264574

Now with the help of your link to calculus7.org and Wolfram, I computed approx. values of PI with the faster converging formula:
Code:

(4*n+3)*((2*n)!!/(2*n+1)!!)^2 where n=10
n=10: 3.14074437347[... 12 significant numbers]
n=100: 3.14158298190
n=1E3: 3.14159255556
n=1E4: 3.14159265261 -> better accuracy than 1st algorithm and n=1E8
n=1E5: 3.14159265358
n=1E6: 3.14159265359 -> 12 significant digits, it will not change anymore

Yes it is a good version of the algorithm.

Next step (tonight?) I'll try to create an optimized algorithm to compute the fractions of double factorials (!!) on Free42.

Thanks again for your reply, Albert.
Regards.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Wallis' product exploration - pinkman - 02-07-2020, 10:55 PM
RE: Wallis' product exploration - pinkman - 02-08-2020 02:42 PM
RE: Wallis' product exploration - Allen - 02-08-2020, 07:13 PM
RE: Wallis' product exploration - Allen - 02-08-2020, 08:58 PM
RE: Wallis' product exploration - pinkman - 02-09-2020, 05:44 AM
RE: Wallis' product exploration - Allen - 02-08-2020, 08:13 PM
RE: Wallis' product exploration - Allen - 02-09-2020, 01:08 PM
RE: Wallis' product exploration - Allen - 02-09-2020, 01:57 PM
RE: Wallis' product exploration - Allen - 02-09-2020, 03:08 PM
RE: Wallis' product exploration - pinkman - 02-09-2020, 02:14 PM
RE: Wallis' product exploration - EdS2 - 02-10-2020, 10:35 AM
RE: Wallis' product exploration - pinkman - 02-11-2020, 10:02 AM
RE: Wallis' product exploration - pinkman - 02-12-2020, 10:01 PM



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