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

Unbounded isapprox

Open aplavin opened this issue 3 years ago • 6 comments

Currently, isapprox relative tolerance is based on the maximum of interval endpoints. This makes a lot of sense for finite intervals, but is kinda weird for infinities:

julia> (-1e10..Inf) ≈ (1e10..Inf)
true

Do you think this can be fixed/improved in a consistent manner?

aplavin avatar Dec 19 '22 14:12 aplavin

I guess the real question is what is "relative" wrt what?

I assume you are happy that (0..1) ≈ (1e(-13)..1) returns true even though 0 ≈ 1e(-13) returns false. So this means we can't just check if both endpoints are approximately equal.

But I agree your example returning true is not right.

dlfivefifty avatar Dec 19 '22 20:12 dlfivefifty

Yes, I think the behavior for finite intervals is correct and totally expected.

I guess the real question is what is "relative" wrt what?

Agree, and don't have a solution ready. That's why an issue and not a PR.

aplavin avatar Dec 19 '22 20:12 aplavin

It doesn't actually help with this problem but looking at the code the choice of relative tolerance looks wrong: I think maxabs should be based on the widths of the intervals not the size of the endpoints...

dlfivefifty avatar Dec 19 '22 21:12 dlfivefifty

Then we'd get weird situations when L1 ≈ L2 and R1 ≈ R2, but (L1..R1) ≉ (L2..R2). Eg for 1e10...(1e10+3) and (1e10+1)..(1e10+2).

aplavin avatar Dec 19 '22 21:12 aplavin

I don't think that's a "weird situation" at all... and in fact those two intervals do not look approximately equal.

dlfivefifty avatar Dec 19 '22 21:12 dlfivefifty

What about 1e10..(1e10+1) and nextfloat(1e10)..(1e10+1)?

aplavin avatar Dec 19 '22 21:12 aplavin