You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This package represents intervals of an ordered set. For an interval
11
-
spanning from `a` to `b`, all values `x` that lie between `a` and `b`
12
-
are defined as being members of the interval.
13
-
14
-
Currently this package defines one concrete type, `Interval`.
15
-
These define the set spanning from `a` to `b`, meaning the
16
-
interval is defined as the set `{x}` satisfying `a ≤ x ≤ b`. This is
17
-
sometimes written `[a,b]` (mathematics syntax, not Julia syntax) or
18
-
`a..b`.
19
-
20
-
Optionally, `Interval{L,R}` can represent open and half-open intervals. The type
21
-
parameters `L` and `R` correspond to the left and right endpoint respectively.
22
-
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`.
23
-
24
-
## Usage
25
-
26
-
You can construct `ClosedInterval`s in a variety of ways:
10
+
## Quick start
27
11
28
12
```julia
29
13
julia>using IntervalSets
30
14
31
-
julia>ClosedInterval{Float64}(1,3)
15
+
julia>i1 =1.0..3.0
32
16
1.0..3.0
33
17
34
-
julia>0.5..2.5
35
-
0.5..2.5
36
-
37
-
julia>1.5±1
38
-
0.5..2.5
39
-
```
40
-
41
-
Similarly, you can construct `OpenInterval`s and `Interval{:open,:closed}`s, and `Interval{:closed,:open}`:
42
-
```julia
43
-
julia>OpenInterval{Float64}(1,3)
44
-
1.0..3.0 (open)
45
-
46
-
julia>OpenInterval(0.5..2.5)
47
-
0.5..2.5 (open)
48
-
49
-
julia>Interval{:open,:closed}(1,3)
50
-
1..3 (open-closed)
51
-
```
52
-
53
-
The `±` operator may be typed as `\pm<TAB>` (using Julia's LaTeX
54
-
syntax tab-completion).
55
-
56
-
Intervals also support the expected set operations:
57
-
58
-
```julia
59
-
julia>1.75∈1.5±1# \in<TAB>; can also use `in`
60
-
true
61
-
62
-
julia>0∈1.5±1
63
-
false
64
-
65
-
julia>1∈OpenInterval(0..1)
66
-
false
67
-
68
-
julia>intersect(1..5, 3..7) # can also use `a ∩ b`, where the symbol is \cap<TAB>
69
-
3..5
18
+
julia> i2 =OpenInterval(0..4)
19
+
0..4 (open)
70
20
71
-
julia>isempty(intersect(1..5, 10..11))
21
+
julia>i1 ⊆ i2
72
22
true
73
23
74
-
julia> (0.25..5) ∪ (3..7.4) # \cup<TAB>; can also use union()
75
-
0.25..7.4
76
-
77
-
julia>isclosedset(0.5..2.0)
78
-
true
79
-
80
-
julia>isopenset(OpenInterval(0.5..2.5))
81
-
true
82
-
83
-
julia>isleftopen(2..3)
24
+
julia> i2 ⊆ i1
84
25
false
85
26
```
86
27
87
-
When computing the union, the result must also be an interval:
88
-
```julia
89
-
julia> (0.25..5) ∪ (6..7.4)
90
-
ERROR: ArgumentError: Cannot construct union of disjoint sets.
0 commit comments