/
EmptySet.jl
263 lines (180 loc) · 4.62 KB
/
EmptySet.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
import Base: rand,
∈,
isempty
export EmptySet, ∅,
an_element,
linear_map
"""
EmptySet{N<:Real} <: LazySet{N}
Type that represents the empty set, i.e., the set with no elements.
"""
struct EmptySet{N<:Real} <: LazySet{N} end
# default constructor of type Float64
EmptySet() = EmptySet{Float64}()
"""
∅
An `EmptySet` instance of type `Float64`.
"""
const ∅ = EmptySet{Float64}()
# --- LazySet interface functions ---
"""
dim(∅::EmptySet)
Return the dimension of the empty set, which is -1 by convention.
### Input
- `∅` -- an empty set
### Output
`-1` by convention.
"""
function dim(∅::EmptySet)::Int
return -1
end
"""
σ(d::AbstractVector{N}, ∅::EmptySet{N}) where {N<:Real}
Return the support vector of an empty set.
### Input
- `d` -- direction
- `∅` -- an empty set
### Output
An error.
"""
function σ(d::AbstractVector{N}, ∅::EmptySet{N}) where {N<:Real}
error("the support vector of an empty set does not exist")
end
"""
isbounded(∅::EmptySet)::Bool
Determine whether an empty set is bounded.
### Input
- `∅` -- empty set
### Output
`true`.
"""
function isbounded(::EmptySet)::Bool
return true
end
"""
∈(x::AbstractVector{N}, ∅::EmptySet{N})::Bool where {N<:Real}
Check whether a given point is contained in an empty set.
### Input
- `x` -- point/vector
- `∅` -- empty set
### Output
The output is always `false`.
### Examples
```jldoctest
julia> ∈([1.0, 0.0], ∅)
false
```
"""
function ∈(x::AbstractVector{N}, ∅::EmptySet{N})::Bool where {N<:Real}
return false
end
"""
an_element(∅::EmptySet)
Return some element of an empty set.
### Input
- `∅` -- empty set
### Output
An error.
"""
function an_element(∅::EmptySet)
error("an empty set does not have any element")
end
"""
rand(::Type{EmptySet}; [N]::Type{<:Real}=Float64, [dim]::Int=0,
[rng]::AbstractRNG=GLOBAL_RNG, [seed]::Union{Int, Nothing}=nothing
)::EmptySet{N}
Create an empty set (note that there is nothing to randomize).
### Input
- `EmptySet` -- type for dispatch
- `N` -- (optional, default: `Float64`) numeric type
- `dim` -- (optional, default: 0) dimension (is ignored)
- `rng` -- (optional, default: `GLOBAL_RNG`) random number generator
- `seed` -- (optional, default: `nothing`) seed for reseeding
### Output
The (only) empty set of the given numeric type.
"""
function rand(::Type{EmptySet};
N::Type{<:Real}=Float64,
dim::Int=0,
rng::AbstractRNG=GLOBAL_RNG,
seed::Union{Int, Nothing}=nothing
)::EmptySet{N}
rng = reseed(rng, seed)
return EmptySet{N}()
end
"""
isempty(∅::EmptySet)::Bool
Return if the empty set is empty or not.
### Input
- `∅` -- empty set
### Output
`true`.
"""
function isempty(∅::EmptySet)::Bool
return true
end
"""
norm(S::EmptySet, [p]::Real=Inf)
Return the norm of an empty set.
It is the norm of the enclosing ball (of the given ``p``-norm) of minimal volume
that is centered in the origin.
### Input
- `S` -- empty set
- `p` -- (optional, default: `Inf`) norm
### Output
An error.
"""
function norm(S::EmptySet, p::Real=Inf)
error("an empty set does not have a norm")
end
"""
radius(S::EmptySet, [p]::Real=Inf)
Return the radius of an empty set.
It is the radius of the enclosing ball (of the given ``p``-norm) of minimal
volume with the same center.
### Input
- `S` -- empty set
- `p` -- (optional, default: `Inf`) norm
### Output
An error.
"""
function radius(S::EmptySet, p::Real=Inf)
error("an empty set does not have a radius")
end
"""
diameter(S::EmptySet, [p]::Real=Inf)
Return the diameter of an empty set.
It is the maximum distance between any two elements of the set, or,
equivalently, the diameter of the enclosing ball (of the given ``p``-norm) of
minimal volume with the same center.
### Input
- `S` -- empty set
- `p` -- (optional, default: `Inf`) norm
### Output
An error.
"""
function diameter(S::EmptySet, p::Real=Inf)
error("an empty set does not have a diameter")
end
"""
linear_map(M::AbstractMatrix{N}, ∅::EmptySet{N}) where {N}
Return the linear map of an empty set.
### Input
- `M` -- matrix
- `∅` -- empty set
### Output
The empty set.
"""
linear_map(M::AbstractMatrix{N}, ∅::EmptySet{N}) where {N} = ∅
"""
translate(∅::EmptySet{N}, v::AbstractVector{N}) where {N<:Real}
Translate (i.e., shift) an empty set by a given vector.
### Input
- `∅` -- empty set
- `v` -- translation vector
### Output
The empty set.
"""
function translate(∅::EmptySet{N}, v::AbstractVector{N}) where {N<:Real}
return ∅
end