Unary operations on sets

In this section we show which typical set operations this library supports.

The following table lists all operations that take one set as argument in the columns. In the rows we list all set types, both the interfaces (where we abbreviate the Abstract prefix), the basic set types, and the lazy set operations, each sorted alphabetically. The table entries have the following meaning.

  • "x" indicates that the operation is implemented for the respective set type.
  • "i" indicates that the operation is inherited from a supertype.
  • "(·)" indicates that the operation is partly implemented/inherited.
type ↓ \ operation →dimρσan_elementisemptyisboundedlinear_maptranslatenormradiusdiameter
Interfaces
LazySetxxxx
APolytopeiixxxi
ACentrallySymmetricxixxxi
ACentrallySymmetricPolytopeiiixiii
APolygonxiiiiii
AHyperrectangleiixixiiixxi
AHPolygoniixxiiii
ASingletoniixixiixiii
Basic set types
Ball1iixixiiixi
Ball2iixixiixi
BallInfiiiiiiiixixi
Ballpiixixiixi
Ellipsoidixxixiixi
EmptySetxixxxxxxxxx
HalfSpacexxxxxxxxi
HPolygon/HPolygonOptiixiiiiixi
HPolyhedronxxxixxxxxi
HPolytopexxxixxixxi
Hyperplanexxxxxxxxi
Hyperrectangleiiiiiiiixiii
Intervalxixxxiiixiii
Line2Dxixxxxxxi
LineSegmentxixxxiiixi
Singletoniiiiiiiixiii
Universexxxxxxxxxxx
VPolygoniixxxiixxi
VPolytopexixixiixxi
ZeroSetxixixiixxiii
Zonotopeixxixiixxi
Lazy set operation types
CartesianProductxxxixxxi
CartesianProductArrayxxxixxxi
ConvexHullxxxixxi
ConvexHullArrayxxxixxi
ExponentialMapxxxixxxi
ExponentialProjectionMapxixixxi
Intersectionxxixxxi
IntersectionArrayxiixxi
LinearMapxxxxxxxi
MinkowskiSumxxxixxi
MinkowskiSumArrayxxxixxi
CachedMinkowskiSumArrayxixixxi
ResetMapxxxxxi
SymmetricIntervalHullxixiiiiiiii
Translationxxxxxxxi
Non-convex operations
Complementxxx
Rectificationxi(x)xxxx
UnionSetxxxxxxx
UnionSetArrayxxxxxxx

Examples

We use the following four sets for illustration.

using LazySets, LazySets.Approximations, Plots
B1 = Ball1(-ones(2), 1.)
B2 = Ball2(ones(2), 1.)
BI = BallInf(zeros(2), 1.)
H = Hyperrectangle(ones(2), ones(2))
sets = [B1, B2, BI, H]

function plot_sets(sets)
    for S in sets
        println(S)
        plot!(S, 1e-2, fillalpha=0.1)
    end
end

function plot_points(points, prefix)
    for i in eachindex(points)
        p = points[i]
        num_occur = length(findfirst(x -> x == p, points[1:i]))
        x = p[1]
        y = p[2]
        if num_occur == 1
            x += 0.15
        elseif num_occur == 2
            y += 0.15
        elseif num_occur == 3
            x -= 0.15
        else
            y -= 0.15
        end
        plot!(Singleton(p))
        plot!(annotations=(x, y, text("$(prefix)$(i)")))
    end
end

plot1 = plot()
plot_sets(sets)
plot1
Example block output

dim

This function returns the dimension of the set.

dim(B1), dim(B2), dim(BI), dim(H)
(2, 2, 2, 2)

ρ/σ

These functions return the support function resp. the support vector of the set.

an_element

This function returns some element in the set. Consecutive calls to this function typically return the same element.

an_element(B1), an_element(B2), an_element(BI), an_element(H)
([-1.0, -1.0], [1.0, 1.0], [0.0, 0.0], [1.0, 1.0])

This function checks containment of a given vector in the set. The operator can be used in infix notation (v ∈ S) and in inverse operand order (S ∋ v). Alias: in

p1 = [1.5, 1.5]
p2 = [0.1, 0.1]
p3 = [-0.9, -0.8]
points = [p1, p2, p3]

for p in [p1, p2, p3]
    println("$p ∈ (B1, B2, BI, H)? ($(p ∈ B1), $(p ∈ B2), $(p ∈ BI), $(p ∈ H))")
end
[1.5, 1.5] ∈ (B1, B2, BI, H)? (false, true, false, true)
[0.1, 0.1] ∈ (B1, B2, BI, H)? (false, false, true, true)
[-0.9, -0.8] ∈ (B1, B2, BI, H)? (true, false, true, false)
plot1 = plot()
plot_sets(sets)
plot_points(points, "p")
plot1
Example block output

isempty

This function checks if the set is empty.

linear_map

This function applies a concrete linear map to the set. The resulting set may be of a different type.

norm

This function returns the norm of a set. It is defined as the norm of the enclosing ball (of the given norm) of minimal volume centered in the origin.

# print 1-norm, 2-norm, and infinity norm (if available)
println(("-", "-", norm(B1, Inf)))
println(("-", "-", norm(B2, Inf)))
println((norm(BI, 1), norm(BI, 2), norm(BI, Inf)))
println((norm(H, 1), norm(H, 2), norm(H, Inf)))
("-", "-", 2.0)
("-", "-", 2.0)
(2.0, 1.4142135623730951, 1.0)
(4.0, 2.8284271247461903, 2.0)

radius

This function returns the radius of a set. It is defined as the radius of the enclosing ball (of the given norm) of minimal volume with the same center.

radius(B1), radius(B2), radius(BI), radius(H)
(1.0, 1.0, 1.0, 1.0)

diameter

This function returns the diameter of a set. It is defined as the diameter of the enclosing ball (of the given norm) of minimal volume with the same center. The implementation is inherited for all set types if the norm is the infinity norm, in which case the result is defined as twice the radius.

diameter(B1), diameter(B2), diameter(BI), diameter(H)
(2.0, 2.0, 2.0, 2.0)