Post Reply 
Stoneham's series
06-07-2024, 08:54 PM (This post was last modified: 06-08-2024 03:20 PM by Albert Chan.)
Post: #9
RE: Stoneham's series
(06-07-2024 07:55 PM)Johnh Wrote:  Jovial JRPN15 incremented to 2,664,645 and got to a Pi estimate of 3.141607465.

Jovial wins the test, much faster, doing over 1.3 million loops in a minute!, though not much extra convergence is achieved with this formula for all the extra cycles.

The problem is (1 - 1/b^2), when b goes big ... it is rounded to 1.
Doing product directly over-estimated what the algorithm should offer.

(1 - a) * (1 - b) = 1 - a - b + a*b = 1 - (a + (1-a)*b)

Code:
function p(n) -- 1 - product((1-1/b^2), b = 3 .. n step 2)
    local a = 0
    for b=3,n,2 do a = a + (1-a)/(b*b) end
    return a
end

lua> p(2664645)
0.21460168922870704
lua> (1-_) * 4
3.141593243085172

Or, we do product backwards, for more accuracy.
Code:
function q(n) -- 1 - product((1-1/b^2), b = n-(n+1)%2 .. 3 step -2)
    local a = 0
    for b=n-(n+1)%2,3,-2 do a = a + (1-a)/(b*b) end
    return a
end

lua> q(2664645)
0.2146016892287097
lua> (1-_) * 4
3.141593243085161


For reference, this is without rounding error (40 digits shown)

3.141593243085161166771739970151562977338...
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Stoneham's series - ttw - 06-04-2024, 01:31 PM
RE: Stoneham's series - KeithB - 06-04-2024, 02:20 PM
RE: Stoneham's series - Nigel (UK) - 06-04-2024, 03:37 PM
RE: Stoneham's series - Thomas Klemm - 06-04-2024, 03:34 PM
RE: Stoneham's series - Thomas Klemm - 06-04-2024, 07:57 PM
RE: Stoneham's series - Albert Chan - 06-04-2024, 08:44 PM
RE: Stoneham's series - Thomas Klemm - 06-05-2024, 04:20 AM
RE: Stoneham's series - Johnh - 06-07-2024, 07:55 PM
RE: Stoneham's series - Albert Chan - 06-07-2024 08:54 PM
RE: Stoneham's series - Johnh - 06-08-2024, 03:07 AM
RE: Stoneham's series - Johnh - 06-08-2024, 05:02 AM
RE: Stoneham's series - Albert Chan - 06-08-2024, 05:16 PM
RE: Stoneham's series - Gerson W. Barbosa - 06-09-2024, 10:36 PM
RE: Stoneham's series - Albert Chan - 06-11-2024, 05:12 PM
RE: Stoneham's series - Gerson W. Barbosa - 06-12-2024, 07:01 PM
RE: Stoneham's series - Gerson W. Barbosa - 06-14-2024, 05:42 PM
RE: Stoneham's series - Gerson W. Barbosa - 06-18-2024, 05:42 AM
RE: Stoneham's series - Namir - 06-09-2024, 10:55 PM
RE: Stoneham's series - Gerson W. Barbosa - 06-09-2024, 11:04 PM
RE: Stoneham's series - Gerson W. Barbosa - 06-11-2024, 02:31 AM



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