JuliaDiff/TaylorSeries.jl

Taylor1 all zero for function that includes negative integer powers

SebastianAment opened this issue · 4 comments

I ran into a problem when computing the Taylor series of the differentiable function f whenever α is an integer. Simply rephrasing the function using inv and positive powers of α solves the problem. I am using Julia 1.6.

using TaylorSeries

α = 2.0
f(r) = (1 + r / (2*α))^(-α)
g(r) = inv(1 + r / (2*α))^α

x = randn()^2
t = Taylor1(3)
println(f(x+t))
println(g(x+t))

Thanks a lot for reporting this! I can reproduce the bug, also in Julia 1.5.2. I think the problem is in pow!.

Using the solution proposed in #270, and slightly adapting your example, yields the following:

julia> using TaylorSeries

julia> f(r, α=2.0) = (1 + r / (2*α))^(-α);

julia> g(r, α=2.0) = inv(1 + r / (2*α))^α;

julia> x = 1.5;

julia> t = Taylor1(3);

julia> isapprox(getcoeff.(f(x+t), 0:t.order), getcoeff.(g(x+t), 0:t.order), rtol=eps())
true

julia> isapprox(getcoeff.(f(x+t, 2.5), 0:t.order), getcoeff.(g(x+t, 2.5), 0:t.order), rtol=eps())
true

I'll bump a new patch version.

Great to hear, that was a fast fix!

It's merged now; have a bit of patience to have the new (patch) version in place.