IntervalArithmetic.jl
IntervalArithmetic.jl copied to clipboard
Possible bug in powers
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
Real (noninteger) powers of negative numbers are undefined, so the input interval is truncated to 0.
What is the context in which this calculation occurs?
Maybe it is indeed a bug, but a problem arises with 0^(-1)
...
Cool, thanks.
I'm just computing powers of intervals, the truncation works for me. I guess it could return something imaginary in some situations?
I like how the empty set is returned for 1/0
I guess the correct result should be [-Inf, Inf]
, so it seems it is indeed a bug
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
I think whether to include negative numbers is just a choice, not a bug.
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)
.
Let's ask our beloved standard (p. 20):
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.
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!
I believe we can close this, now that decorations are the default #590.