TaylorModels.jl icon indicating copy to clipboard operation
TaylorModels.jl copied to clipboard

Unexpected `evaluate` behavior with non-Float64 numbers

Open schillic opened this issue 1 year ago • 4 comments

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]

schillic avatar Jan 25 '24 22:01 schillic

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 avatar Jan 25 '24 22:01 lbenet

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 avatar Jan 25 '24 22:01 lbenet

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.

lbenet avatar Jan 25 '24 22:01 lbenet

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.

schillic avatar Jan 26 '24 06:01 schillic