Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Powers of rational intervals #515

Closed
schillic opened this issue Apr 5, 2022 · 8 comments · Fixed by #567
Closed

Powers of rational intervals #515

schillic opened this issue Apr 5, 2022 · 8 comments · Fixed by #567
Labels

Comments

@schillic
Copy link
Contributor

schillic commented Apr 5, 2022

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]
``
@lucaferranti
Copy link
Member

lucaferranti commented Apr 5, 2022

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

@agerlach
Copy link

Has there been any update on this? I am hitting this issue as well.

@OlivierHnt
Copy link
Member

@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? 🙂

@lucaferranti
Copy link
Member

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

@schillic
Copy link
Contributor Author

schillic commented Feb 8, 2023

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.

@agerlach
Copy link

agerlach commented Feb 8, 2023

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.

@lbenet
Copy link
Member

lbenet commented Feb 8, 2023

So out of curiosity, what are you using Interval{Rational{Int}} for? Why not using Interval{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.

@OlivierHnt
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants