From 60a80b5baad1a2bd9d18f7843d449b4056593ad1 Mon Sep 17 00:00:00 2001 From: Neven Sajko Date: Wed, 30 Jul 2025 17:42:03 +0200 Subject: [PATCH 1/2] improve `_log1pmx_ker` internal documentation on the polynomial Note which function the polynomial approximation approximates in a comment in the source code. Might be useful if someone decided to search for a slightly different polynomial. --- src/basicfuns.jl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/basicfuns.jl b/src/basicfuns.jl index 5cc0df2..02d5d81 100644 --- a/src/basicfuns.jl +++ b/src/basicfuns.jl @@ -353,6 +353,11 @@ function _log1pmx_ker(x::T) where T <: Union{Float32, Float64} 0.11201972567415432, 0.143418239946679) end + # Mathematically equivalent to: + # + # ```julia + # w = 2 * (atanh(r) - r) / r^3 + # ``` w = evalpoly(t, p) hxsq = x*x/2 muladd(r, muladd(w, t, hxsq), -hxsq) From a81f2b62cf76246eb32886d0163c8f7b7f003466 Mon Sep 17 00:00:00 2001 From: Neven Sajko Date: Sat, 9 Aug 2025 05:37:41 +0200 Subject: [PATCH 2/2] implement suggestion --- src/basicfuns.jl | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/basicfuns.jl b/src/basicfuns.jl index 02d5d81..d1d10d1 100644 --- a/src/basicfuns.jl +++ b/src/basicfuns.jl @@ -337,6 +337,8 @@ end # parameters foudn via Remez.jl, specifically: # g(x) = evalpoly(x, big(2)./ntuple(i->2i+1, 50)) # p = T.(Tuple(ratfn_minimax(g, (1e-3, (.425/(.425+2))^2), 8, 0)[1])) +# A closed form for the Taylor series, after a variable change, is +# 2 * (atanh(x) - x) / x^3 function _log1pmx_ker(x::T) where T <: Union{Float32, Float64} r = x / (x+2) t = r*r @@ -353,11 +355,6 @@ function _log1pmx_ker(x::T) where T <: Union{Float32, Float64} 0.11201972567415432, 0.143418239946679) end - # Mathematically equivalent to: - # - # ```julia - # w = 2 * (atanh(r) - r) / r^3 - # ``` w = evalpoly(t, p) hxsq = x*x/2 muladd(r, muladd(w, t, hxsq), -hxsq)