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

When is an Interval infinite? [ definition of isinf() ] #168

Closed
gwater opened this issue Jun 29, 2018 · 16 comments
Closed

When is an Interval infinite? [ definition of isinf() ] #168

gwater opened this issue Jun 29, 2018 · 16 comments
Labels
1.0 Planned for the major 1.0 release

Comments

@gwater
Copy link
Contributor

gwater commented Jun 29, 2018

The current definition of isinf() has raised questions here and here. We should settle these discussions here and find a meaningful (and useful) definition for isinf() or remove the method if we cannot.

For reference, the current definition:

isentire(x::Interval) = x.lo == -Inf && x.hi == Inf
isinf(x::Interval) = isentire(x)
@lbenet
Copy link
Member

lbenet commented Jun 29, 2018

Thanks for opening this issue (rather than moving this elsewhere in IntervalRootFinding).

Just to state what I already proposed, in my opinion isinf(x::Interval) should be defined as isinf(x::Interval) = !isfinite(x).

@dpsanders
Copy link
Member

isinf in Julia means very specifically that the "value is infinite".

I don't think there is a useful version of this for intervals, so the method should probably be removed.

@gwater
Copy link
Contributor Author

gwater commented Jun 29, 2018

There are only two valid cases in my opinion:

  • an interval contains only finite numbers
  • an interval contains both one or more infinities and finite numbers

In the first case I think it's clear that isinf() should return false. In the second case I think no meaningful value can be returned because the specific number which is described by the interval could be either infinite or not. Returning true would be misleading.

Therefore I think isinf() should not be defined at all for intervals, or better yet, it should raise an error.

@lbenet
Copy link
Member

lbenet commented Jun 29, 2018

Since isinf(a) has a method in Base foe a::Real, probably the best way out is to throw an error.

@gwater
Copy link
Contributor Author

gwater commented Jun 29, 2018

If it is not defined; isinf() will fall back to the definition in Base which is

isinf(x::Real) = !isnan(x) & !isfinite(x)

@dpsanders
Copy link
Member

OK, let's throw an error.

@gwater
Copy link
Contributor Author

gwater commented Jun 29, 2018

Tricky question: Do we always throw an error or only when the interval contains an infinity?

@dpsanders
Copy link
Member

I was wondering that. I have a feeling it will be more useful to always throw an error, so that you find out fast if an algorithm is or not suitable for using with intervals.

@gwater
Copy link
Contributor Author

gwater commented Jun 29, 2018

On the other hand it might break algorithms which are working fine at the moment (as long as you don't throw infinities at them).

@dpsanders
Copy link
Member

Right, but that might break if an infinity gets in there in an inconvenient moment. Tricky one.

@gwater
Copy link
Contributor Author

gwater commented Jun 29, 2018

I think as a user I would prefer an algorithm to work until it hits an actual problem. And then I could catch the error and deal with it in some way.

@dpsanders
Copy link
Member

Yes that's a good point. It seems weird to throw an error from the isinf function precisely when the interval is of infinite length (which, as above, is not the same as "being infinite"), but maybe that's actually what we should do then.

@gwater
Copy link
Contributor Author

gwater commented Jun 29, 2018

Now, as I think through this: Doesn't all of this apply to isfinite(), too? And more generally to the question of comparisons raised in #165? It might be feasible to raise errors in many undecidable cases and prevent algorithms silently failing (while allowing them to run in decidable cases).

@gwater
Copy link
Contributor Author

gwater commented Jun 30, 2018

To me isinf(), isfinite(), iszero(), etc. are all questions about numbers not intervals but sometimes we can say something about the numbers contained in the intervals. So I would propose the following principle: reduce questions about numbers contained in intervals to questions about the intervals themselves.

To illustrate, consider these definitions:

function isfinite(x::Interval)
    isbounded(x) && return true
    throw(InexactError())
end

isinf(x::Interval) = !isfinite(x)

function iszero{T}(x::Interval{T})
    x.lo == x.hi == zero(T) && return true
    throw(InexactError())
end

(Sidenote: isbounded() doesn't exist yet but it should because !isunbounded() does not catch NaNs.)

@lbenet
Copy link
Member

lbenet commented Jun 30, 2018

I like the idea!

It would be a good idea to catch cases that include NaIs ([NaN,NaN]).

@OlivierHnt
Copy link
Member

On master branch we chose to be very conservative with boolean functions to prevent silent errors. Using Interval as a drop-in replacement of a Number in a code should yield an error.
In this regard, the functions isinf, etc. are no longer intended to be supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.0 Planned for the major 1.0 release
Projects
None yet
Development

No branches or pull requests

5 participants