Accurate x - log(1+x)
|
05-09-2022, 12:41 AM
(This post was last modified: 02-03-2024 05:25 PM by Albert Chan.)
Post: #5
|
|||
|
|||
RE: Accurate x - log(1+x)
Let f(x) = x - log(1+x)
f(x) - f(-x) = (x - log(1+x)) - (-x - log(1-x)) = 2*(x - atanh(x)) LHS f(±x) never negative, thus possible massive cancellations. We can go from accurate (atanh(x)-x) to accurate (log(1+x)-x), but not in reverse. Code for RHS should be factored out. Note that I flipped the order, to be consistent throughout, func_sub(x) = func(x) - x I also use better pade approximation for atanh_sub_tiny(x), making it more useful by itself. Code: function atanh_sub_tiny(x) -- abserr ≈ 256/2760615 * x^15 Example, expression ((1+r)^-n - 1)/r + n lua> r, n = 1e-6, 1e3 lua> expm1(-n*log1p(r))/r + n --> error = 788 ULP 0.5003328749086222 lua> z = log1p_sub(r) lua> (expm1_sub(-n*(z+r)) - n*z)/r --> error = -1 ULP 0.5003328749087098 lua> mapm = require'mapm' lua> r = mapm.new(r) -- exact binary to decimal conversion lua> (((1+r)^-n - 1)/r + n):tofixed(20) 0.50033287490870967825 |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
Accurate x - log(1+x) - Albert Chan - 05-05-2022, 07:52 PM
RE: Accurate x - log(1+x) - Albert Chan - 05-05-2022, 08:18 PM
RE: Accurate x - log(1+x) - Albert Chan - 05-05-2022, 08:57 PM
RE: Accurate x - log(1+x) - Albert Chan - 05-06-2022, 02:03 PM
RE: Accurate x - log(1+x) - Albert Chan - 05-09-2022 12:41 AM
RE: Accurate x - log(1+x) - Albert Chan - 04-04-2023, 11:05 PM
|
User(s) browsing this thread: 1 Guest(s)