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

Possible bug in powers

Open AnderGray opened this issue 3 years ago • 11 comments

If x = [-1,1], y = [-1,1]

The program gives me x^y => [0, Inf].

But (-1)^(-1) = -1, which is lower than 0.

Is my understanding wrong, but I think -1 should be in the result.

Cheers, A

AnderGray avatar Mar 04 '21 20:03 AnderGray

Real (noninteger) powers of negative numbers are undefined, so the input interval is truncated to 0.

dpsanders avatar Mar 04 '21 20:03 dpsanders

What is the context in which this calculation occurs?

dpsanders avatar Mar 04 '21 20:03 dpsanders

Maybe it is indeed a bug, but a problem arises with 0^(-1)...

lbenet avatar Mar 04 '21 20:03 lbenet

Cool, thanks.

I'm just computing powers of intervals, the truncation works for me. I guess it could return something imaginary in some situations?

AnderGray avatar Mar 04 '21 20:03 AnderGray

I like how the empty set is returned for 1/0

AnderGray avatar Mar 04 '21 20:03 AnderGray

I guess the correct result should be [-Inf, Inf], so it seems it is indeed a bug

lbenet avatar Mar 04 '21 21:03 lbenet

It can't return complex numbers since that would be type-unstable. That's the same reason that Julia does not do this:

julia> (-1.0)^-2.1
ERROR: DomainError with -1.0:
Exponentiation yielding a complex result requires a complex argument.
Replace x^y with (x+0im)^y, Complex(x)^y, or similar.
Stacktrace:
 [1] throw_exp_domainerror(x::Float64)
   @ Base.Math ./math.jl:37
 [2] ^(x::Float64, y::Float64)
   @ Base.Math ./math.jl:901
 [3] top-level scope
   @ REPL[6]:1

dpsanders avatar Mar 04 '21 21:03 dpsanders

I think whether to include negative numbers is just a choice, not a bug.

dpsanders avatar Mar 04 '21 21:03 dpsanders

I think the chose to not include negative numbers: https://github.com/JuliaIntervals/IntervalArithmetic.jl/blob/b70940dabdbefd8eb4be32d7bde6df72174dd3f7/src/intervals/functions.jl#L209-L211

If I recall correctly, we simply avoided the cases like (-1)^(0.5).

lbenet avatar Mar 05 '21 20:03 lbenet

Let's ask our beloved standard (p. 20): image

So basically we can do whatever we want when some input are outside the domain of the point function.

It may actually be a good use case for a decorated interval, since if I remember correctly they should track that kind of things and be able to tell something strange happened there. I'm not sure if it has been fully implemented yet though.

Kolaru avatar Mar 05 '21 23:03 Kolaru

Yes, I agree on both points. This is, in fact, already implemented:

julia> using IntervalArithmetic

julia> @format true;   # show decdorations

julia> x = DecoratedInterval(-1..1)
[-1, 1]_com

julia> x^x
[0, ∞]_trv   

trv means "something may have happened during the interval evaluation of the function on that input domain", for example the truncation of the domain that did actually happen!

dpsanders avatar Mar 06 '21 00:03 dpsanders

I believe we can close this, now that decorations are the default #590.

OlivierHnt avatar Dec 01 '23 23:12 OlivierHnt