Post Reply 
complex log
02-07-2024, 12:49 AM (This post was last modified: 02-07-2024 01:22 AM by Albert Chan.)
Post: #2
RE: complex log
Code:
dd = require'dd' -- David Bailey's double-double
function ratio_relerr(n, lo, hi)
    local e1, e2, x = 0, 0
    for i = 1,n do
        repeat x = lo + (hi-lo)*random() until x~=1
        local g = dd.new(x)
        g = g*g-1; e1 = e1 + abs(((g-(x+1)*(x-1))/g):tonumber())
        x = x - 1; e2 = e2 + abs(((g-(2*x + x*x))/g):tonumber())
    end
    return e1/e2
end

.5 < h < 3
min(|x|) = sqrt(.5/2) = 0.5
max(|x|) = sqrt(3/1) ≈ 1.732

lua> ratio_relerr(1e6, .5, 1)
1.1272738159812026
lua> ratio_relerr(1e6, 1, 1.732)
1.4886689516224851
lua> ratio_relerr(1e6, .5, 1.732)
1.3195779095764026

OP Clog, (h=|x|-1, 2*h + h*h) statistically more accurate than (x+1)*(x-1)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
complex log - Albert Chan - 02-07-2024, 12:47 AM
RE: complex log - Albert Chan - 02-07-2024 12:49 AM
RE: complex log - Albert Chan - 02-07-2024, 11:24 PM
RE: complex log - Albert Chan - 02-07-2024, 11:03 AM
RE: complex log - Albert Chan - 02-08-2024, 09:04 PM
RE: complex log - Albert Chan - 02-10-2024, 09:55 PM
RE: complex log - Albert Chan - 02-11-2024, 06:32 PM



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