-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3533 from JuliaReach/schillic/interval_more
Add more and better operations for `Interval`
- Loading branch information
Showing
21 changed files
with
234 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
function affine_map(M, X::Interval, v::AbstractVector; kwargs...) | ||
@assert size(M, 2) == 1 "cannot apply an affine map of dimension $(size(M, 2)) " * | ||
"to an interval" | ||
@assert size(M, 1) == length(v) "cannot apply an affine map of matrix dimension " * | ||
"$(size(M, 1)) and translation dimension $(length(v))" | ||
@inbounds if length(v) == 1 | ||
return Interval(M[1, 1] * X.dat + v[1]) | ||
end | ||
return translate(linear_map(M, X; kwargs...), v) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
function complement(X::Interval) | ||
N = eltype(X) | ||
L = HalfSpace(SingleEntryVector(1, 1, one(N)), min(X)) | ||
H = HalfSpace(SingleEntryVector(1, 1, -one(N)), -max(X)) | ||
return UnionSet(L, H) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
function convex_hull(I1::Interval, I2::Interval) | ||
return Interval(min(min(I1), min(I2)), max(max(I1), max(I2))) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
function distance(X::Interval, Y::Interval; p::Real=2) | ||
d = max(min(X) - max(Y), min(Y) - max(X)) | ||
if d < 0 | ||
return zero(d) | ||
end | ||
return d | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
function exponential_map(M::AbstractMatrix, X::Interval) | ||
@assert size(M) == (1, 1) "cannot apply an exponential map of dimension " * | ||
"$(size(M)) to an interval" | ||
@inbounds e = exp(M[1, 1]) | ||
return Interval(e * X.dat) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# the implementations here are equivalent to the default implementation for | ||
# `LazySet`, but more efficient than the more specific implementations for | ||
# subtypes | ||
|
||
function extrema(X::Interval, i::Int) | ||
@assert i == 1 "an interval has dimension 1, but the index is $i" | ||
return (min(X), max(X)) | ||
end | ||
|
||
function extrema(X::Interval) | ||
return ([min(X)], [max(X)]) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,8 @@ | ||
""" | ||
high(x::Interval) | ||
Return the higher coordinate of an interval set. | ||
### Input | ||
- `x` -- interval | ||
### Output | ||
function high(X::Interval, i::Int) | ||
@assert i == 1 "an interval has dimension 1, but the index is $i" | ||
return max(X) | ||
end | ||
|
||
A vector with the higher coordinate of the interval. | ||
""" | ||
function high(x::Interval) | ||
return [x.dat.hi] | ||
function high(X::Interval) | ||
return [max(X)] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
function ≈(I1::Interval, I2::Interval) | ||
return _isapprox(min(I1), min(I2)) && _isapprox(max(I1), max(I2)) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
function isequivalent(I1::Interval, I2::Interval) | ||
return I1 ≈ I2 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
function ⊂(X::Interval, Y::Interval, witness::Bool=false) | ||
if min(X) < min(Y) || max(X) > max(Y) | ||
return _witness_result_empty(witness, false, X, Y) | ||
end | ||
if min(X) > min(Y) | ||
return witness ? (true, low(Y)) : true | ||
elseif max(Y) > max(X) | ||
return witness ? (true, high(Y)) : true | ||
end | ||
return _witness_result_empty(witness, false, X, Y) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,8 @@ | ||
""" | ||
low(x::Interval) | ||
Return the lower coordinate of an interval set. | ||
### Input | ||
- `x` -- interval | ||
### Output | ||
function low(X::Interval, i::Int) | ||
@assert i == 1 "an interval has dimension 1, but the index is $i" | ||
return min(X) | ||
end | ||
|
||
A vector with the lower coordinate of the interval. | ||
""" | ||
function low(x::Interval) | ||
return [x.dat.lo] | ||
function low(X::Interval) | ||
return [min(X)] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
function norm(X::Interval, p::Real=Inf) | ||
return max(abs(min(X)), abs(max(X))) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
function permute(X::Interval, p::AbstractVector{Int}) | ||
@assert length(p) == 1 && p[1] == 1 "invalid permutation vector $p" | ||
return X | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
function project(X::Interval, block::AbstractVector{Int}; kwargs...) | ||
@assert length(block) == 1 && block[1] == 1 "invalid permutation vector $block" | ||
return X | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
function volume(X::Interval) | ||
return max(X) - min(X) | ||
end |
Oops, something went wrong.