JuliaIntervals / TaylorModels.jl

Rigorous function approximation using Taylor models in Julia
Other
63 stars 14 forks source link

Unexpected `evaluate` behavior with non-Float64 numbers #158

Open schillic opened 5 months ago

schillic commented 5 months ago

Is it expected that evaluate gives vastly different results when using non-Float64 numbers?

julia> using TaylorModels

julia> function eval(N)
    t = TaylorModels.Taylor1(3)
    q₁ = 1 + 2 * t + 2 * t^2
    I = interval(N(0), N(0))
    D = interval(N(-1), N(1))
    x0 = mid(D)
    TM = TaylorModels.TaylorModel1(q₁, I, x0, D)
    return evaluate(TM, domain(TM))
end;

julia> eval(Float64)
[-1, 5]

julia> eval(Float32)
[-3, 5]

julia> eval(Rational{Int})
[-3, 5]
lbenet commented 5 months ago

Thanks for reporting; that is indeed weird. I'll have a look, and I'll get back here.

Note that since lot is going on in IntervalArithmetic, and that has consequences in TaylorSeries, lots of changes will occur here...

lbenet commented 5 months ago

The problem seems to be in TaylorSeries:

julia> D32 = interval(-1f0, 1f0)
[-1f0, 1f0]

julia> D = interval(-1.0, 1.0)
[-1, 1]

julia> t = Taylor1(3)
 1.0 t + 𝒪(t⁴)

julia> q₁ =  1 + 2*t + 2*t^2
 1.0 + 2.0 t + 2.0 t² + 𝒪(t⁴)

julia> q₁(D)
[-1, 5]

julia> q₁(D32)
[-3, 5]

julia> evaluate(t^2, D)
[0, 1]

julia> evaluate(t^2, D32)
[-1, 1]
lbenet commented 5 months ago

The problem seems to be in TaylorSeries:

Noup, the problem is in IntervalArithmetic v0.20.9: somehow, squaring doesn't work for Interval{Float32}

julia> D^2
[0, 1]

julia> D32^2
[-1f0, 1f0]

julia> @which D32^2
^(x::Number, p::Integer)
     @ Base intfuncs.jl:311

The problem is solved in current master of IntervalArithmetic.

schillic commented 5 months ago

Thanks for working this out! Then there is nothing we can do for now and this should eventually get resolved when the new version is supported. I leave it to you to keep this issue open as a reminder or close it.