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

Partial update to IntervalArithmetic v0.21 #192

Closed
wants to merge 2 commits into from
Closed

Partial update to IntervalArithmetic v0.21 #192

wants to merge 2 commits into from

Conversation

schillic
Copy link

@schillic schillic commented Aug 27, 2023

I tried to upgrade IntervalArithmetic to v0.21 but failed with several blockers. I pushed this so somebody with more knowledge can continue. Below are the blocking problems I found.

Problems

@OlivierHnt
Copy link
Member

Sorry I do not know this repository well. Where is the issue with the conversion with Compl? Typically, for compatibility with 0.21, convert(Interval, a) should be interval(a) and, similarly, convert(Interval{T}, a) should read interval(T, a).

About the third item in your list, is it about

@testset "Automatic slope expansion" begin
for T in [Float64, BigFloat]
s = interval(T(0.75), T(1.75))
example = Slopes{T}[]
push!(example, Slopes(x->((x + sin(x)) * exp(-x^2)), s, mid(s), interval(T(-2.8), T(0.1))))
push!(example, Slopes(x->(x^4 - 10x^3 + 35x^2 - 50x + 24), s, mid(s), interval(T(-44), T(38.5))))
push!(example, Slopes(x->((log(x + 1.25) - 0.84x) ^ 2), s, mid(s), interval(T(-0.16), T(0.44))))
push!(example, Slopes(x->(0.02x^2 - 0.03exp(-(20(x - 0.875))^2)), s, mid(s), interval(T(0.03), T(0.33))))
push!(example, Slopes(x->(exp(x^2)), s, mid(s), interval(T(6.03), T(33.23))))
push!(example, Slopes(x->(x^4 - 12x^3 + 47x^2 - 60x - 20exp(-x)), s, mid(s), interval(T(-39), T(65.56))))
push!(example, Slopes(x->(x^6 - 15x^4 + 27x^2 + 250), s, mid(s), interval(T(-146.9), T(67.1))))
push!(example, Slopes(x->(atan(cos(tan(x)))), s, mid(s), interval(T(1), T(2))))
push!(example, Slopes(x->(asin(cos(acos(sin(x))))), s, mid(s), interval(T(1.36), T(∞))))

? If so, things like interval(T(...), T(...)) should be written interval(T, ..., ...).

@schillic
Copy link
Author

About the third item in your list, is it about

@testset "Automatic slope expansion" begin
for T in [Float64, BigFloat]
s = interval(T(0.75), T(1.75))
example = Slopes{T}[]
push!(example, Slopes(x->((x + sin(x)) * exp(-x^2)), s, mid(s), interval(T(-2.8), T(0.1))))
push!(example, Slopes(x->(x^4 - 10x^3 + 35x^2 - 50x + 24), s, mid(s), interval(T(-44), T(38.5))))
push!(example, Slopes(x->((log(x + 1.25) - 0.84x) ^ 2), s, mid(s), interval(T(-0.16), T(0.44))))
push!(example, Slopes(x->(0.02x^2 - 0.03exp(-(20(x - 0.875))^2)), s, mid(s), interval(T(0.03), T(0.33))))
push!(example, Slopes(x->(exp(x^2)), s, mid(s), interval(T(6.03), T(33.23))))
push!(example, Slopes(x->(x^4 - 12x^3 + 47x^2 - 60x - 20exp(-x)), s, mid(s), interval(T(-39), T(65.56))))
push!(example, Slopes(x->(x^6 - 15x^4 + 27x^2 + 250), s, mid(s), interval(T(-146.9), T(67.1))))
push!(example, Slopes(x->(atan(cos(tan(x)))), s, mid(s), interval(T(1), T(2))))
push!(example, Slopes(x->(asin(cos(acos(sin(x))))), s, mid(s), interval(T(1.36), T(∞))))

? If so, things like interval(T(...), T(...)) should be written interval(T, ..., ...).

No, that part was fine. I changed it anyway now. And also added some more fixes.

Where is the issue with the conversion with Compl? Typically, for compatibility with 0.21, convert(Interval, a) should be interval(a) and, similarly, convert(Interval{T}, a) should read interval(T, a).

This all happens internally in automatic promotion. Below is an example from a failing test:

Xc = Complex(X, X)
f(z) = z^3 - 1

# Default
rts = roots(f, Xc)

In the call to roots the function f is executed with a IntervalRootFinding.Compl{Interval{Float64}}, argument . Then f says to subtract 1. So Julia calls the method
-(x::IntervalRootFinding.Compl{Interval{Float64}}, y::Int64),
which itself calls the promotion rule.
I tried to fix this by adding another promotion rule, but then got stuck in ForwardDiff with yet another promotion issue.

@OlivierHnt
Copy link
Member

OlivierHnt commented Aug 29, 2023

Mhmm so since promotion between Number and interval types are disallowed, the fix may be to define f(z) = z^2 - interval(1) (since promotion between Compl and interval seems to work).

@schillic
Copy link
Author

Mhmm so since promotion between Number and interval types are disallowed, the fix may be to define f(z) = z^2 - interval(1) (since promotion between Compl and interval seems to work).

To me the whole point of interval arithmetic is that you can plug an interval into a function that expects a number and it will just work. Having to explicitly write interval(1) means I have to define a new function for that purpose. This is not convenient, and often not even possible if the code lives in another package.

But since this is not my package, I let you decide how to fix things. As I said, feel free to continue from this branch if you want.

@OlivierHnt
Copy link
Member

OlivierHnt commented Aug 29, 2023

Thank you very much for your input on this and taking the time to open this draft 🙂

We do allow the mixing +,*,-(::Interval, ::Number), so instead of redefining f, what could be done is to define the methods +,*,-(::Compl{<:Interval}, ::Number)...
That being said, since I do not know this package well, I am also not sure what is the exact purpose of Compl. @lbenet, @Kolaru, would defining a ComplexInterval type in IntervalArithmetic.jl be better in the long run? In particular, can such a struct completely replace the need of Compl?

@schillic schillic mentioned this pull request Jun 17, 2024
@Kolaru Kolaru closed this Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants