diff --git a/src/Singleton.jl b/src/Singleton.jl index 112e0de6ed..76d3b4f4f4 100644 --- a/src/Singleton.jl +++ b/src/Singleton.jl @@ -3,7 +3,7 @@ import Base: ∈, ⊆ export Singleton """ - Singleton{N<:Real} <: LazySet + Singleton{N<:Real} <: AbstractSingleton{N} Type that represents a singleton, that is, a set with a unique element. @@ -11,95 +11,45 @@ Type that represents a singleton, that is, a set with a unique element. - `element` -- the only element of the set """ -struct Singleton{N<:Real} <: LazySet +struct Singleton{N<:Real} <: AbstractSingleton{N} element::Vector{N} end -""" - dim(S::Singleton)::Int - -Return the dimension of a singleton. -### Input +# --- AbstractSingleton interface functions --- -- `S` -- singleton -### Output - -The ambient dimension of the singleton. """ -function dim(S::Singleton)::Int - return length(S.element) -end + element(S::Singleton{N})::Vector{N} where {N<:Real} -""" - σ(d::AbstractVector{<:Real}, S::LazySets.Singleton{N})::Vector{N} where {N<:Real} - -Return the support vector of a singleton. +Return the element of a singleton. ### Input -- `d` -- direction -- `B` -- singleton +- `S` -- singleton ### Output -The support vector, which is the singleton's vector itself, irrespective of the -given direction. +The element of the singleton. """ -function σ(d::AbstractVector{<:Real}, - S::LazySets.Singleton{N})::Vector{N} where {N<:Real} +function element(S::Singleton{N})::Vector{N} where {N<:Real} return S.element end """ - ∈(x::AbstractVector{N}, S::Singleton{N})::Bool where {N<:Real} + element(S::Singleton{N}, i::Int)::N where {N<:Real} -Check whether a given point is contained in a singleton. +Return the i-th entry of the element of a singleton. ### Input -- `x` -- point/vector - `S` -- singleton +- `i` -- dimension ### Output -`true` iff ``x ∈ S``. - -### Notes - -This implementation performs an exact comparison, which may be insufficient with -floating point computations. - -### Examples - -```jldoctest -julia> S = Singleton([1., 1.]); - -julia> ∈([0.9, 1.1], S) -false -julia> ∈([1.0, 1.0], S) -true -``` -""" -function ∈(x::AbstractVector{N}, S::Singleton{N})::Bool where {N<:Real} - return x == S.element -end - -""" - ⊆(S::Singleton, set::LazySet)::Bool - -Check whether a given singleton is contained in a convex set. - -### Input - -- `S` -- singleton -- `set` -- convex set - -### Output - -`true` iff ``S ⊆ \\text{set}``. +The i-th entry of the element of the singleton. """ -function ⊆(S::Singleton, set::LazySet)::Bool - return ∈(S.element, set) +function element(S::Singleton{N}, i::Int)::N where {N<:Real} + return S.element[i] end diff --git a/src/ZeroSet.jl b/src/ZeroSet.jl index 27cf160428..c19d68bfdc 100644 --- a/src/ZeroSet.jl +++ b/src/ZeroSet.jl @@ -3,7 +3,7 @@ import Base.∈ export ZeroSet """ - ZeroSet <: LazySet + ZeroSet{N<:Real} <: AbstractSingleton{N} Type that represents the zero set, i.e., the set that only contains the origin. @@ -11,9 +11,54 @@ Type that represents the zero set, i.e., the set that only contains the origin. - `dim` -- the ambient dimension of this zero set """ -struct ZeroSet <: LazySet +struct ZeroSet{N<:Real} <: AbstractSingleton{N} dim::Int end +# type-less convenience constructor +ZeroSet(dim::Int) = ZeroSet{Float64}(dim) + + +# --- AbstractSingleton interface functions --- + + +""" + element(S::ZeroSet{N})::Vector{N} where {N<:Real} + +Return the element of a zero set. + +### Input + +- `S` -- zero set + +### Output + +The element of the zero set, i.e., a zero vector. +""" +function element(S::ZeroSet{N})::Vector{N} where {N<:Real} + return zeros(N, S.dim) +end + +""" + element(S::ZeroSet{N}, ::Int)::N where {N<:Real} + +Return the i-th entry of the element of a zero set. + +### Input + +- `S` -- zero set +- `i` -- dimension + +### Output + +The i-th entry of the element of the zero set, i.e., 0. +""" +function element(S::ZeroSet{N}, ::Int)::N where {N<:Real} + return zero(N) +end + + +# --- LazySet interface functions --- + """ dim(Z::ZeroSet)::Int @@ -33,7 +78,7 @@ function dim(Z::ZeroSet)::Int end """ - σ(d, Z) + σ(d::AbstractVector{N}, Z::ZeroSet)::Vector{N} where {N<:Real} Return the support vector of a zero set. @@ -51,7 +96,7 @@ function σ(d::AbstractVector{N}, Z::ZeroSet)::Vector{N} where {N<:Real} end """ - ∈(x::AbstractVector, Z::ZeroSet)::Bool + ∈(x::AbstractVector{N}, Z::ZeroSet{N})::Bool where {N<:Real} Check whether a given point is contained in a zero set. @@ -75,7 +120,7 @@ julia> ∈([0.0, 0.0], Z) true ``` """ -function ∈(x::AbstractVector{N}, Z::ZeroSet)::Bool where {N<:Real} +function ∈(x::AbstractVector{N}, Z::ZeroSet{N})::Bool where {N<:Real} @assert length(x) == dim(Z) zero_N = zero(N)