Skip to content

Conversation

@AnderGray
Copy link

Are you guys interested in an implementation of Multi-Intervals?

Multi-Intervals are sets of reals defined by unions of disjoint intervals. This PR includes:

  • Constructors, which remove any empty sets and envelope intervals which intersect
  • Arithmetic of Multi-Intervals, including with intervals and scalars
  • Complement functions

Usage:

    julia> a = interval(0,2)  interval(3,3.6)  interval(3.5,4)
    [0, 2]  [3, 4]

    julia> b = interval(1,2)  interval(4,5)  ∅
    [1, 2]  [4, 5]

    julia> c = a * b 
    [0, 10]  [12, 20]
    
    julia> complement(c)
    [-∞, 0]  [10, 12]  [20, ∞]

Note that the arithmetic doesn't broadcast on the elements of the multi-interval, but does every combination. The result is then condensed if any intervals overlap.

I'm agnostic to the name "Multi-Interval", it's what we call them but maybe there's a better name.

This is a draft and just includes a stand alone file which uses IntervalArithmetic.jl, and does not yet integrate it into the module.

Extension to interval boxes should also be possible.

@dpsanders
Copy link
Member

This is a great idea; in fact I had an implementation somewhere.

I actually think this belongs in a different package, though. Personally I would call this IntervalUnion, but I quite like MultiInterval.
Have you seen the papers by Schichl et al. on this stuff?

@AnderGray
Copy link
Author

Sure, maybe it's better standalone!

Mincing and boxes would have to be figured out, as well as subset-hood and stuff. But I don't think it's difficult.
I haven't, can you send a reference?

@dpsanders
Copy link
Member

@Kolaru
Copy link
Member

Kolaru commented Apr 2, 2021

I think it is definitely very cool. Please let us know here if you decide to turn that into its own package, especially if you would like some feedbacks.

Here are few of them already:

  • The Julia standard style is to use snake_case for function names and CamelCase for types.
  • Performance may become a real issue quickly when the number of intervals in the union grows (I expect exponential growth in the number of intervals in some cases). You may want to consider strategies to deal with that early in the developpment process (e.g. limiting the number of intervals in the union).

@dpsanders
Copy link
Member

Here's another relevant paper, where they try to deal with the point raised by @Kolaru by introducing criteria for joining together boxes in the union:

https://link.springer.com/chapter/10.1007/978-3-030-31041-7_14

@AnderGray
Copy link
Author

AnderGray commented Apr 2, 2021

Thanks for the references and feedback. I'll have a read through them. I'm thinking I like Interval Unions more, since they're called this in the lit.

  • Cheers, I wasn't aware that was the style! I'll make the changes
  • Definitely. My first thought was finding which intervals are closest together (complements with the smallest widths) and enveloping them until a max number is reached. The suggestion by @dpsanders is probably more sophisticated

Again agnostic about it being it's own package.

Pros: Users of IntervalArithmetic don't need it in general. And it would be easier to manage if it was stand alone.

Cons: I can think of two situations where you get multi-intervals from standard intervals:

  • sqrt
  • Conditional statements with intervals

For example consider the following function:

function interval_ifs(A)
    if A < 3
        A = A + 2 
    else
        A = A - 2
    end
    return A
end

A = interval(0,5)
interval_ifs(A)

I believe that the answer should be [-2, 1] U [5, 7].

In cases with uncertain conditional statements, I think the interval should be bisected at 3, with each part going down different branches and then unioned afterwards. Similar for while and for loops.

Although we can't do this yet, I think with Julia's metaprogamming we should be able to do some nice stuff. Maybe even with Intermediate representation: https://github.com/FluxML/IRTools.jl

IntervalUnions would play a role I think, but you could also envelop the union and get [-2, 7] and stay with intervals

@dpsanders
Copy link
Member

We definitely do not want to mix up interval unions with normal intervals. You should have to explicitly start with an interval union to explicitly allow interval unions in the result. So it makes sense for it to be a separate package.

@AnderGray
Copy link
Author

I agree. Thanks!

@AnderGray
Copy link
Author

IntervalUnionArithmetic.jl has been created

@dpsanders dpsanders closed this May 5, 2021
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

Successfully merging this pull request may close these issues.

3 participants