@@ -20,11 +20,18 @@ function isequal_interval(x::Interval, y::Interval)
20
20
isnai (x) | isnai (y) && return false
21
21
return isequal_interval (bareinterval (x), bareinterval (y))
22
22
end
23
+ isequal_interval (x:: Complex{<:Interval} , y:: Complex{<:Interval} ) = isequal_interval (real (x), real (y)) & isequal_interval (imag (x), imag (y))
24
+ isequal_interval (x:: Complex{<:Interval} , y:: Interval ) = isequal_interval (real (x), y) & isthinzero (imag (x))
25
+ isequal_interval (x:: Interval , y:: Complex{<:Interval} ) = isequal_interval (x, real (y)) & isthinzero (imag (y))
26
+
27
+ function isequal_interval (x:: AbstractVector , y:: AbstractVector )
28
+ n = length (x)
29
+ m = length (y)
30
+ n == m || return throw (DimensionMismatch (" dimensions must match: x has length $n , y has length $m " ))
31
+ return all (t -> isequal_interval (t[1 ], t[2 ]), zip (x, y))
32
+ end
23
33
24
34
isequal_interval (x, y, z, w... ) = isequal_interval (x, y) & isequal_interval (y, z, w... )
25
- isequal_interval (x:: Complex , y:: Complex ) = isequal_interval (real (x), real (y)) & isequal_interval (imag (x), imag (y))
26
- isequal_interval (x:: Complex , y:: Real ) = isequal_interval (real (x), y) & isthinzero (imag (x))
27
- isequal_interval (x:: Real , y:: Complex ) = isequal_interval (x, real (y)) & isthinzero (imag (y))
28
35
29
36
isequal_interval (x) = Base. Fix2 (isequal_interval, x)
30
37
@@ -41,16 +48,46 @@ function issubset_interval(x::Interval, y::Interval)
41
48
isnai (x) | isnai (y) && return false
42
49
return issubset_interval (bareinterval (x), bareinterval (y))
43
50
end
51
+ issubset_interval (x:: Complex{<:Interval} , y:: Complex{<:Interval} ) = issubset_interval (real (x), real (y)) & issubset_interval (imag (x), imag (y))
52
+ issubset_interval (x:: Complex{<:Interval} , y:: Interval ) = issubset_interval (real (x), y) & isthinzero (imag (x))
53
+ issubset_interval (x:: Interval , y:: Complex{<:Interval} ) = issubset_interval (x, real (y)) & in_interval (0 , imag (y))
54
+
55
+ function issubset_interval (x:: AbstractVector , y:: AbstractVector )
56
+ n = length (x)
57
+ m = length (y)
58
+ n == m || return throw (DimensionMismatch (" dimensions must match: x has length $n , y has length $m " ))
59
+ return all (t -> issubset_interval (t[1 ], t[2 ]), zip (x, y))
60
+ end
44
61
45
62
issubset_interval (x, y, z, w... ) = issubset_interval (x, y) & issubset_interval (y, z, w... )
46
- issubset_interval (x:: Complex , y:: Complex ) = issubset_interval (real (x), real (y)) & issubset_interval (imag (x), imag (y))
47
- issubset_interval (x:: Complex , y:: Real ) = issubset_interval (real (x), y) & isthinzero (imag (x))
48
- issubset_interval (x:: Real , y:: Complex ) = issubset_interval (x, real (y)) & in_interval (0 , imag (y))
63
+
64
+ """
65
+ isstrictsubset(x, y)
66
+
67
+ Test whether `x` is a strict subset of `y`. If `x` and `y` are intervals, this
68
+ is semantically equivalent to `isinterior(x, y)`. If `x` and `y` are vectors,
69
+ `x` must be a subset of `y` with at least one of their component being a strict
70
+ subset.
71
+
72
+ See also: [`isinterior`](@ref).
73
+ """
74
+ isstrictsubset (x:: BareInterval , y:: BareInterval ) = isinterior (x, y)
75
+
76
+ isstrictsubset (x:: Interval , y:: Interval ) = isinterior (x, y)
77
+ isstrictsubset (x:: Complex{<:Interval} , y:: Complex{<:Interval} ) =
78
+ (isstrictsubset (real (x), real (y)) & issubset_interval (imag (x), imag (y))) | (issubset_interval (real (x), real (y)) & isstrictsubset (imag (x), imag (y)))
79
+ isstrictsubset (x:: Complex{<:Interval} , y:: Interval ) = isstrictsubset (real (x), y) & isthinzero (imag (x))
80
+ isstrictsubset (x:: Interval , y:: Complex{<:Interval} ) = isstrictsubset (x, real (y)) & in_interval (0 , imag (y))
81
+
82
+ isstrictsubset (x:: AbstractVector , y:: AbstractVector ) = issubset_interval (x, y) & any (t -> isstrictsubset (t[1 ], t[2 ]), zip (x, y))
83
+
84
+ isstrictsubset (x, y, z, w... ) = isstrictsubset (x, y) & isstrictsubset (y, z, w... )
49
85
50
86
"""
51
87
isinterior(x, y)
52
88
53
- Test whether `x` is in the interior of `y`.
89
+ Test whether `x` is in the interior of `y`. If `x` and `y` are intervals, this
90
+ is semantically equivalent to `isstrictsubset(x, y)`.
54
91
55
92
Implement the `interior` function of the IEEE Standard 1788-2015 (Table 9.3).
56
93
@@ -63,6 +100,9 @@ function isinterior(x::Interval, y::Interval)
63
100
isnai (x) | isnai (y) && return false
64
101
return isinterior (bareinterval (x), bareinterval (y))
65
102
end
103
+ isinterior (x:: Complex{<:Interval} , y:: Complex{<:Interval} ) = isinterior (real (x), real (y)) & isinterior (imag (x), imag (y))
104
+ isinterior (:: Complex{<:Interval} , :: Interval ) = false
105
+ isinterior (x:: Interval , y:: Complex{<:Interval} ) = isinterior (x, real (y)) & isinterior (zero (x), imag (y))
66
106
67
107
function isinterior (x:: AbstractVector , y:: AbstractVector )
68
108
n = length (x)
@@ -72,33 +112,33 @@ function isinterior(x::AbstractVector, y::AbstractVector)
72
112
end
73
113
74
114
isinterior (x, y, z, w... ) = isinterior (x, y) & isinterior (y, z, w... )
75
- isinterior (x:: Complex , y:: Complex ) =
76
- (isinterior (real (x), real (y)) & issubset_interval (imag (x), imag (y))) |
77
- (issubset_interval (real (x), real (y)) & isinterior (imag (x), imag (y)))
78
- isinterior (x:: Complex , y:: Real ) = isinterior (real (x), y) & isthinzero (imag (x))
79
- isinterior (x:: Real , y:: Complex ) = isinterior (x, real (y)) & in_interval (0 , imag (y))
80
115
81
116
"""
82
- isstrictsubset (x, y)
117
+ isdisjoint_interval (x, y)
83
118
84
- Test whether `x` is a strict subset of `y`. If `x` and `y` are intervals, this
85
- is semantically equivalent to `isinterior(x, y)`. If `x` and `y` are vectors, at
86
- least one component of `x` must be in the interior of `y`.
119
+ Test whether `x` and `y` have no common elements.
87
120
88
- See also: [`isinterior`](@ref ).
121
+ Implement the `disjoint` function of the IEEE Standard 1788-2015 (Table 9.3 ).
89
122
"""
90
- isstrictsubset (x:: BareInterval , y:: BareInterval ) = isinterior (x, y)
123
+ isdisjoint_interval (x:: BareInterval , y:: BareInterval ) =
124
+ isempty_interval (x) | isempty_interval (y) | _strictlessprime (sup (y), inf (x)) | _strictlessprime (sup (x), inf (y))
91
125
92
- isstrictsubset (x:: Interval , y:: Interval ) = isinterior (x, y)
126
+ function isdisjoint_interval (x:: Interval , y:: Interval )
127
+ isnai (x) | isnai (y) && return false
128
+ return isdisjoint_interval (bareinterval (x), bareinterval (y))
129
+ end
130
+ isdisjoint_interval (x:: Complex{<:Interval} , y:: Complex{<:Interval} ) = isdisjoint_interval (real (x), real (y)) | isdisjoint_interval (imag (x), imag (y))
131
+ isdisjoint_interval (x:: Complex{<:Interval} , y:: Interval ) = isdisjoint_interval (real (x), y) | ! in_interval (0 , imag (x))
132
+ isdisjoint_interval (x:: Interval , y:: Complex{<:Interval} ) = isdisjoint_interval (x, real (y)) | ! in_interval (0 , imag (y))
93
133
94
- isstrictsubset (x:: AbstractVector , y:: AbstractVector ) = isinterior (x, y) & any (t -> isinterior (t[1 ], t[2 ]), zip (x, y))
134
+ function isdisjoint_interval (x:: AbstractVector , y:: AbstractVector )
135
+ n = length (x)
136
+ m = length (y)
137
+ n == m || return throw (DimensionMismatch (" dimensions must match: x has length $n , y has length $m " ))
138
+ return any (t -> isdisjoint_interval (t[1 ], t[2 ]), zip (x, y))
139
+ end
95
140
96
- isstrictsubset (x, y, z, w... ) = isstrictsubset (x, y) & isstrictsubset (y, z, w... )
97
- isstrictsubset (x:: Complex , y:: Complex ) =
98
- (isstrictsubset (real (x), real (y)) & issubset_interval (imag (x), imag (y))) |
99
- (issubset_interval (real (x), real (y)) & isstrictsubset (imag (x), imag (y)))
100
- isstrictsubset (x:: Complex , y:: Real ) = isstrictsubset (real (x), y) & isthinzero (imag (x))
101
- isstrictsubset (x:: Real , y:: Complex ) = isstrictsubset (x, real (y)) & in_interval (0 , imag (y))
141
+ isdisjoint_interval (x, y, z, w... ) = isdisjoint_interval (x, y) & isdisjoint_interval (y, z, w... )
102
142
103
143
"""
104
144
isweakless(x, y)
@@ -159,24 +199,6 @@ function strictprecedes(x::Interval, y::Interval)
159
199
return strictprecedes (bareinterval (x), bareinterval (y))
160
200
end
161
201
162
- """
163
- isdisjoint_interval(x, y)
164
-
165
- Test whether `x` and `y` have no common elements.
166
-
167
- Implement the `disjoint` function of the IEEE Standard 1788-2015 (Table 9.3).
168
- """
169
- isdisjoint_interval (a:: BareInterval , b:: BareInterval ) =
170
- isempty_interval (a) | isempty_interval (b) | _strictlessprime (sup (b), inf (a)) | _strictlessprime (sup (a), inf (b))
171
-
172
- function isdisjoint_interval (x:: Interval , y:: Interval )
173
- isnai (x) | isnai (y) && return false
174
- return isdisjoint_interval (bareinterval (x), bareinterval (y))
175
- end
176
-
177
- isdisjoint_interval (x:: Complex , y:: Complex ) =
178
- isdisjoint_interval (real (x), real (y)) | isdisjoint_interval (imag (x), imag (y))
179
-
180
202
"""
181
203
in_interval(x, y)
182
204
@@ -189,22 +211,19 @@ function in_interval(x::Number, y::BareInterval)
189
211
return inf (y) ≤ x ≤ sup (y)
190
212
end
191
213
in_interval (x:: Complex , y:: BareInterval ) = in_interval (real (x), y) & iszero (imag (x))
214
+ in_interval (x:: Interval , y:: BareInterval ) = throw (MethodError (in_interval, (x, y)))
215
+ in_interval (:: BareInterval , :: BareInterval ) =
216
+ throw (ArgumentError (" `in_interval` is purposely not supported for two interval arguments. See instead `issubset_interval`" ))
192
217
193
218
function in_interval (x:: Number , y:: Interval )
194
219
isnai (y) && return false
195
220
return in_interval (x, bareinterval (y))
196
221
end
197
-
198
- in_interval (:: BareInterval , :: BareInterval ) =
199
- throw (ArgumentError (" `in_interval` is purposely not supported for two interval arguments. See instead `issubset_interval`" ))
200
-
222
+ in_interval (x:: Number , y:: Complex{<:Interval} ) = in_interval (x, real (y)) & in_interval (0 , imag (y))
223
+ in_interval (x:: Complex , y:: Complex{<:Interval} ) = in_interval (real (x), real (y)) & in_interval (imag (x), imag (y))
201
224
in_interval (:: Interval , :: Interval ) =
202
225
throw (ArgumentError (" `in_interval` is purposely not supported for two interval arguments. See instead `issubset_interval`" ))
203
226
204
- in_interval (x:: Complex , y:: Complex ) = in_interval (real (x), real (y)) & in_interval (imag (x), imag (y))
205
- in_interval (x:: Complex , y:: Number ) = in_interval (real (x), y) & iszero (imag (x))
206
- in_interval (x:: Number , y:: Complex ) = in_interval (x, real (y)) & in_interval (0 , imag (y))
207
-
208
227
in_interval (x) = Base. Fix2 (in_interval, x)
209
228
210
229
"""
@@ -220,8 +239,9 @@ function isempty_interval(x::Interval)
220
239
isnai (x) && return false
221
240
return isempty_interval (bareinterval (x))
222
241
end
242
+ isempty_interval (x:: Complex{<:Interval} ) = isempty_interval (real (x)) | isempty_interval (imag (x))
223
243
224
- isempty_interval (x:: Complex ) = isempty_interval ( real (x)) & isempty_interval ( imag (x) )
244
+ isempty_interval (x:: AbstractVector ) = any ( isempty_interval, x )
225
245
226
246
"""
227
247
isentire_interval(x)
@@ -236,8 +256,7 @@ function isentire_interval(x::Interval)
236
256
isnai (x) && return false
237
257
return isentire_interval (bareinterval (x))
238
258
end
239
-
240
- isentire_interval (x:: Complex ) = isentire_interval (real (x)) & isentire_interval (imag (x))
259
+ isentire_interval (x:: Complex{<:Interval} ) = isentire_interval (real (x)) & isentire_interval (imag (x))
241
260
242
261
"""
243
262
isnai(x)
@@ -247,8 +266,7 @@ Test whether `x` is an NaI (Not an Interval).
247
266
isnai (:: BareInterval ) = false
248
267
249
268
isnai (x:: Interval ) = decoration (x) == ill
250
-
251
- isnai (x:: Complex ) = isnai (real (x)) & isnai (imag (x))
269
+ isnai (x:: Complex{<:Interval} ) = isnai (real (x)) & isnai (imag (x))
252
270
253
271
"""
254
272
isbounded(x)
@@ -261,8 +279,7 @@ function isbounded(x::Interval)
261
279
isnai (x) && return false
262
280
return isbounded (bareinterval (x))
263
281
end
264
-
265
- isbounded (x:: Complex ) = isbounded (real (x)) & isbounded (imag (x))
282
+ isbounded (x:: Complex{<:Interval} ) = isbounded (real (x)) & isbounded (imag (x))
266
283
267
284
"""
268
285
isunbounded(x)
@@ -275,8 +292,7 @@ function isunbounded(x::Interval)
275
292
isnai (x) && return false
276
293
return isunbounded (bareinterval (x))
277
294
end
278
-
279
- isunbounded (x:: Complex ) = isunbounded (real (x)) | isunbounded (imag (x))
295
+ isunbounded (x:: Complex{<:Interval} ) = isunbounded (real (x)) | isunbounded (imag (x))
280
296
281
297
"""
282
298
iscommon(x)
@@ -292,8 +308,7 @@ function iscommon(x::Interval)
292
308
isnai (x) && return false
293
309
return iscommon (bareinterval (x))
294
310
end
295
-
296
- iscommon (x:: Complex ) = iscommon (real (x)) & iscommon (imag (x))
311
+ iscommon (x:: Complex{<:Interval} ) = iscommon (real (x)) & iscommon (imag (x))
297
312
298
313
"""
299
314
isatomic(x)
@@ -309,8 +324,7 @@ function isatomic(x::Interval)
309
324
isnai (x) && return false
310
325
return isatomic (bareinterval (x))
311
326
end
312
-
313
- isatomic (x:: Complex ) = isatomic (real (x)) & isatomic (imag (x))
327
+ isatomic (x:: Complex{<:Interval} ) = isatomic (real (x)) & isatomic (imag (x))
314
328
315
329
"""
316
330
isthin(x)
@@ -325,8 +339,7 @@ function isthin(x::Interval)
325
339
isnai (x) && return false
326
340
return isthin (bareinterval (x))
327
341
end
328
-
329
- isthin (x:: Complex ) = isthin (real (x)) & isthin (imag (x))
342
+ isthin (x:: Complex{<:Interval} ) = isthin (real (x)) & isthin (imag (x))
330
343
331
344
"""
332
345
isthin(x, y)
@@ -335,17 +348,14 @@ Test whether `x` contains only `y`.
335
348
"""
336
349
isthin (x:: BareInterval , y:: Number ) = inf (x) == sup (x) == y
337
350
isthin (x:: BareInterval , y:: Complex ) = isthin (x, real (y)) & iszero (imag (y))
351
+ isthin (x:: BareInterval , y:: Interval ) = throw (MethodError (isthin, (x, y)))
338
352
339
353
function isthin (x:: Interval , y:: Number )
340
354
isnai (x) && return false
341
355
return isthin (bareinterval (x), y)
342
356
end
343
-
344
- isthin (x:: Complex , y:: Complex ) = isthin (real (x), real (y)) & isthin (imag (x), imag (y))
345
- isthin (x:: Complex , y:: Number ) = isthin (real (x), real (y)) & isthinzero (imag (x))
346
- isthin (x:: Number , y:: Complex ) = isthin (real (x), real (y)) & iszero (imag (y))
347
-
348
- isthin (x:: BareInterval , y:: Interval ) = throw (MethodError (isthin, (x, y)))
357
+ isthin (x:: Complex{<:Interval} , y:: Number ) = isthin (real (x), y) & isthinzero (imag (x))
358
+ isthin (x:: Complex{<:Interval} , y:: Complex ) = isthin (real (x), real (y)) & isthin (imag (x), imag (y))
349
359
350
360
"""
351
361
isthinzero(x)
@@ -358,8 +368,7 @@ function isthinzero(x::Interval)
358
368
isnai (x) && return false
359
369
return isthinzero (bareinterval (x))
360
370
end
361
-
362
- isthinzero (x:: Complex ) = isthinzero (real (x)) & isthinzero (imag (x))
371
+ isthinzero (x:: Complex{<:Interval} ) = isthinzero (real (x)) & isthinzero (imag (x))
363
372
364
373
"""
365
374
isthinone(x)
@@ -372,8 +381,7 @@ function isthinone(x::Interval)
372
381
isnai (x) && return false
373
382
return isthinone (bareinterval (x))
374
383
end
375
-
376
- isthinone (x:: Complex ) = isthinone (real (x)) & isthinzero (imag (x))
384
+ isthinone (x:: Complex{<:Interval} ) = isthinone (real (x)) & isthinzero (imag (x))
377
385
378
386
"""
379
387
isthininteger(x)
@@ -386,5 +394,4 @@ function isthininteger(x::Interval)
386
394
isnai (x) && return false
387
395
return isthininteger (bareinterval (x))
388
396
end
389
-
390
- isthininteger (x:: Complex ) = isthininteger (real (x)) & isthinzero (imag (x))
397
+ isthininteger (x:: Complex{<:Interval} ) = isthininteger (real (x)) & isthinzero (imag (x))
0 commit comments