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

Possible bug in powers #441

Closed
AnderGray opened this issue Mar 4, 2021 · 12 comments
Closed

Possible bug in powers #441

AnderGray opened this issue Mar 4, 2021 · 12 comments

Comments

@AnderGray
Copy link

AnderGray commented Mar 4, 2021

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.

@dpsanders
Copy link
Member

dpsanders commented Mar 4, 2021

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

@dpsanders
Copy link
Member

What is the context in which this calculation occurs?

@lbenet
Copy link
Member

lbenet commented Mar 4, 2021

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

@AnderGray
Copy link
Author

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
Copy link
Author

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

@lbenet
Copy link
Member

lbenet commented Mar 4, 2021

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

@dpsanders
Copy link
Member

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
Copy link
Member

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

@lbenet
Copy link
Member

lbenet commented Mar 5, 2021

I think the chose to not include negative numbers:

domain = Interval{T}(0, Inf)
a = a domain

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

@Kolaru
Copy link
Collaborator

Kolaru commented Mar 5, 2021

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.

@dpsanders
Copy link
Member

dpsanders commented Mar 6, 2021

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!

@OlivierHnt
Copy link
Member

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

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

No branches or pull requests

5 participants