Giter Site home page Giter Site logo

intervalsets.jl's Introduction

IntervalSets.jl

Interval Sets for Julia

Build Status

Coverage Status

This package represents intervals of an ordered set. For an interval spanning from a to b, all values x that lie between a and b are defined as being members of the interval.

This package is intended to implement a "minimal" foundation for intervals upon which other packages might build. In particular, we encourage type-piracy for the reason that only one interval package can unambiguously define the .. and ± operators (see below).

Currently this package defines one concrete type, Interval. These define the set spanning from a to b, meaning the interval is defined as the set {x} satisfying a ≤ x ≤ b. This is sometimes written [a,b] (mathematics syntax, not Julia syntax) or a..b.

Optionally, Interval{L,R} can represent open and half-open intervals. The type parameters L and R correspond to the left and right endpoint respectively. The notation ClosedInterval is short for Interval{:closed,:closed}, while OpenInterval is short for Interval{:open,:open}. For example, the interval Interval{:open,:closed} corresponds to the set {x} satisfying a < x ≤ b.

Usage

You can construct ClosedIntervals in a variety of ways:

julia> using IntervalSets

julia> ClosedInterval{Float64}(1,3)
1.0..3.0

julia> 0.5..2.5
0.5..2.5

julia> 1.5±1
0.5..2.5

Similarly, you can construct OpenIntervals and Interval{:open,:closed}s, and Interval{:closed,:open}:

julia> OpenInterval{Float64}(1,3)
1.0..3.0 (open)

julia> OpenInterval(0.5..2.5)
0.5..2.5 (open)

julia> Interval{:open,:closed}(1,3)
1..3 (open–closed)

The ± operator may be typed as \pm<TAB> (using Julia's LaTeX syntax tab-completion).

Intervals also support the expected set operations:

julia> 1.75  1.5±1  # \in<TAB>; can also use `in`
true

julia> 0  1.5±1
false

julia> 1  OpenInterval(0..1)
false

julia> intersect(1..5, 3..7)   # can also use `a ∩ b`, where the symbol is \cap<TAB>
3..5

julia> isempty(intersect(1..5, 10..11))
true

julia> (0.25..5)  (3..7.4)    # \cup<TAB>; can also use union()
0.25..7.4

julia> isclosedset(0.5..2.0)
true

julia> isopenset(OpenInterval(0.5..2.5))
true

julia> isleftopen(2..3)
false

When computing the union, the result must also be an interval:

julia> (0.25..5)  (6..7.4)
------ ArgumentError ------------------- Stacktrace (most recent call last)

 [1] — union(::IntervalSets.ClosedInterval{Float64}, ::IntervalSets.ClosedInterval{Float64}) at closed.jl:34

ArgumentError: Cannot construct union of disjoint sets.

intervalsets.jl's People

Contributors

ararslan avatar carlolucibello avatar cstjean avatar daanhb avatar dlfivefifty avatar femtocleaner[bot] avatar github-actions[bot] avatar hyrodium avatar jagot avatar juliatagbot avatar kdw503 avatar mcabbott avatar mronian avatar simondanisch avatar staticfloat avatar timholy avatar tpapp avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.