Accurate x - log(1+x)
|
05-05-2022, 07:52 PM
(This post was last modified: 05-06-2022 05:20 AM by Albert Chan.)
Post: #1
|
|||
|
|||
Accurate x - log(1+x)
(04-27-2020 07:54 PM)Albert Chan Wrote: I tried to re-use my formula, for log(probability of no repetition) We have correct formula for ln_P(n,s), but numerically very hard to evaluate with big n. It would be nice if we can accurately calculate x - log1p(x) For small x, we can sum taylor/pade series. log1p(x) = 2*atanh(x/(x+2)) Code: function tinyx_sub_log1p(x) -- x - log1p(x) y = x/(x+2) ≈ x/(0+2) = x/2 abs_err(z) ≈ (1/13 - 9/121) * y^12 ≈ (4/1573) * (x/2)^12 = x^12/1610752 (x-2z) ≈ x - 2/3*y² ≈ x - 2/3*(x²/4) = x - x²/6 ≈ x relerr = abs_err(2z)/(x-2z) ≈ x^11/805376 relerr(x=0.1000) ≈ 1.24e-17, below Free42 Binary machine epsilon relerr(x=0.0025) ≈ 2.96e-35, below Free42 Decimal machine epsilon For big x, we use "half-angle" formula for log1p Keep reducing log1p argument, until we can use tinyx_sub_log1p log1p(x) = 2 * log1p(√(1+x) - 1) = 2 * log1p(x / (√(1+x) + 1)) Let y=sqrt(1+x), z = (y-1) = x/(y+1) Let f(x) = x - log1p(x) f(x) = z*(y+1) - 2*log1p(z) = z*(y-1) + 2*f(z) = z^2 + 2*f(z) Both RHS terms are non-negative, without cancellation errors. Code: function x_sub_log1p(x) |
|||
« 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)