IntervalArithmetic.jl
IntervalArithmetic.jl copied to clipboard
Powers of rational intervals
Is the following expected?
julia> using IntervalArithmetic
julia> a = interval(-1, 1)
[-1, 1]
julia> a^2 # looks good
[0, 1]
julia> a = interval(-1//1, 1//1)
[-1//1, 1//1]
julia> a^2 # expected: [0//1, 1//1]
[-1//1, 1//1]
``
The reason for this seems to be that if picks some fallback case from base (which uses power by squaring)
julia> a = interval(-1//1, 1//1)
[-1//1, 1//1]
julia> a ^ 2
[-1//1, 1//1]
julia> @which a ^ 2
^(x::Number, p::Integer) in Base at intfuncs.jl:291
julia> b = interval(-1, 1)
[-1, 1]
julia> b ^ 2
[0, 1]
julia> @which b ^ 2
^(a::Interval{Float64}, x::Integer) in IntervalArithmetic at /home/lferrant/.julia/packages/IntervalArithmetic/997vH/src/intervals/functions.jl:10
I guess this could be fixed by updating the type signature
Has there been any update on this? I am hitting this issue as well.
@schillic @agerlach
I do not think anyone got around to fix this. In fact, there are some discussion about restricting the bounds of Interval
to AbstractFloat
(see e.g. #495). It is still unclear whether having Interval{Rational{Int}}
is useful or not (since it also introduces some issues).
So out of curiosity, what are you using Interval{Rational{Int}}
for? Why not using Interval{Float64}
for instance? 🙂
I guess rational intervals can be useful for symbolical computations. Sure they are restricted to only rational operations, but that is probably enough for several applications (think e.g. matrix power).
Side note, we could always define
const FloatOrRat = Union{AbstractFloat, Rational}
and have
struct Interval{T <: FloatOrRat} <: Real # to reflect how it is now, does not imply I agree it should be suptype of Real :P
low::T
high::T
end
this would allow to keep rational and floats and avoid stack overflow issues we had in the past
I am not really using it. We just test our functionality also with Rational
s and so I stumbled upon this issue. In any case, the behavior seems wrong to me, so it should either be fixed or warned about in the documentation.
I was using it to validate a manually derived interval remainder for a Taylor model. I was getting much wider intervals numerically and wanted to test with rationals to quantify the effects due to round-off vs truncation.
So out of curiosity, what are you using
Interval{Rational{Int}}
for? Why not usingInterval{Float64}
for instance?
Interval{Rational{Int}}
are indeed very limited. Yet, within those limitations, they essentially avoid issues with rounding (for rational polynomials with rational coefficients). At least for the time being, I'm in favor of having them around.
That definitely sounds useful! Thanks for chiming in.
Side note, we could always define
const FloatOrRat = Union{AbstractFloat, Rational}
Seems like a good idea.
I am not really using it. We just test our functionality also with Rationals and so I stumbled upon this issue. In any case, the behavior seems wrong to me, so it should either be fixed or warned about in the documentation.
You are absolutely right. Side note: ^(a::Interval{Rational{Int64}}, x::Int64)
and ^(a::Interval{Rational{Int64}}, x::Float64)
are currently broken on the 1.0-dev branch.