From 417514e31bc32f08788d28e1b232804b58cc9f0e Mon Sep 17 00:00:00 2001 From: schillic Date: Mon, 22 Apr 2024 20:14:28 +0200 Subject: [PATCH] outsource documentation to API module --- docs/make.jl | 3 +- docs/src/lib/API.md | 100 ++ .../concrete_binary_operations/difference.md | 2 +- .../concrete_binary_operations/exact_sum.md | 1 - .../concrete_binary_operations/isdisjoint.md | 3 - .../concrete_binary_operations/issubset.md | 1 - .../minkowski_difference.md | 1 - docs/src/lib/interfaces/LazySet.md | 5 - src/API/API.jl | 96 ++ src/API/Binary/cartesian_product.jl | 23 + src/API/Binary/difference.jl | 23 + src/API/Binary/distance.jl | 25 + src/API/Binary/exact_sum.jl | 31 + src/API/Binary/intersection.jl | 23 + src/API/Binary/isapprox.jl | 25 + src/API/Binary/isdisjoint.jl | 31 + src/API/Binary/isequal.jl | 21 + src/API/Binary/isequivalent.jl | 15 + src/API/Binary/isstrictsubset.jl | 33 + src/API/Binary/issubset.jl | 23 + src/API/Binary/linear_combination.jl | 23 + src/API/Binary/minkowski_difference.jl | 36 + src/API/Binary/minkowski_sum.jl | 23 + src/API/LazySet.jl | 13 + src/API/Mixed/affine_map.jl | 16 + src/API/Mixed/exponential_map.jl | 15 + src/API/Mixed/in.jl | 15 + src/API/Mixed/is_interior_point.jl | 18 + src/API/Mixed/linear_map.jl | 15 + src/API/Mixed/permute.jl | 16 + src/API/Mixed/project.jl | 15 + src/API/Mixed/sample.jl | 19 + src/API/Mixed/scale!.jl | 15 + src/API/Mixed/scale.jl | 16 + src/API/Mixed/support_function.jl | 27 + src/API/Mixed/support_vector.jl | 21 + src/API/Mixed/translate!.jl | 15 + src/API/Mixed/translate.jl | 15 + src/API/Unary/an_element.jl | 14 + src/API/Unary/area.jl | 14 + src/API/Unary/complement.jl | 14 + src/API/Unary/concretize.jl | 19 + src/API/Unary/constraints.jl | 14 + src/API/Unary/constraints_list.jl | 14 + src/API/Unary/convex_hull.jl | 22 + src/API/Unary/diameter.jl | 21 + src/API/Unary/dim.jl | 14 + src/API/Unary/eltype.jl | 29 + src/API/Unary/extrema.jl | 52 + src/API/Unary/high.jl | 42 + src/API/Unary/is_polyhedral.jl | 19 + src/API/Unary/isbounded.jl | 18 + src/API/Unary/isboundedtype.jl | 18 + src/API/Unary/isconvextype.jl | 20 + src/API/Unary/isempty.jl | 18 + src/API/Unary/isoperation.jl | 18 + src/API/Unary/isoperationtype.jl | 18 + src/API/Unary/isuniversal.jl | 18 + src/API/Unary/low.jl | 42 + src/API/Unary/norm.jl | 20 + src/API/Unary/radius.jl | 20 + src/API/Unary/rand.jl | 20 + src/API/Unary/rectify.jl | 14 + src/API/Unary/reflect.jl | 14 + src/API/Unary/surface.jl | 14 + src/API/Unary/vertices.jl | 14 + src/API/Unary/vertices_list.jl | 14 + src/API/Unary/volume.jl | 14 + src/Approximations/Approximations.jl | 24 +- src/Approximations/template_directions.jl | 30 +- src/ConcreteOperations/cartesian_product.jl | 2 - src/ConcreteOperations/convex_hull.jl | 2 - src/ConcreteOperations/difference.jl | 44 +- src/ConcreteOperations/distance.jl | 6 - src/ConcreteOperations/exact_sum.jl | 13 - src/ConcreteOperations/intersection.jl | 2 - src/ConcreteOperations/isapprox.jl | 33 + src/ConcreteOperations/isdisjoint.jl | 7 - src/ConcreteOperations/isequal.jl | 33 + src/ConcreteOperations/isequivalent.jl | 34 + src/ConcreteOperations/isstrictsubset.jl | 27 +- src/ConcreteOperations/issubset.jl | 62 +- src/ConcreteOperations/linear_combination.jl | 11 +- .../minkowski_difference.jl | 20 - src/ConcreteOperations/minkowski_sum.jl | 2 - src/Interfaces/AbstractAffineMap.jl | 2 - src/Interfaces/AbstractCentrallySymmetric.jl | 5 +- .../AbstractCentrallySymmetricPolytope.jl | 6 +- src/Interfaces/AbstractHPolygon.jl | 9 +- src/Interfaces/AbstractHyperrectangle.jl | 6 +- .../AbstractPolyhedron_functions.jl | 5 - src/Interfaces/AbstractPolytope.jl | 7 +- src/Interfaces/AbstractSingleton.jl | 5 +- src/Interfaces/AbstractZonotope.jl | 4 +- src/Interfaces/LazySet.jl | 950 ++++-------------- src/Interfaces/aliases.jl | 4 +- src/LazyOperations/CartesianProduct.jl | 2 +- src/LazyOperations/CartesianProductArray.jl | 2 +- src/LazyOperations/Complement.jl | 6 +- src/LazyOperations/ConvexHull.jl | 3 - src/LazyOperations/ConvexHullArray.jl | 2 - src/LazyOperations/ExponentialMap.jl | 2 +- src/LazyOperations/Intersection.jl | 8 +- src/LazyOperations/InverseLinearMap.jl | 6 +- src/LazyOperations/LinearMap.jl | 4 +- src/LazyOperations/MinkowskiSum.jl | 2 +- src/LazyOperations/Rectification.jl | 2 - src/LazyOperations/ResetMap.jl | 1 - src/LazyOperations/SymmetricIntervalHull.jl | 3 +- src/LazyOperations/Translation.jl | 4 - src/LazyOperations/UnionSet.jl | 2 +- src/LazySets.jl | 41 +- src/Parallel/Parallel.jl | 2 - src/Sets/Ball1.jl | 3 - src/Sets/Ball2.jl | 7 +- src/Sets/BallInf.jl | 5 +- src/Sets/Ballp.jl | 3 - src/Sets/DensePolynomialZonotope.jl | 6 +- src/Sets/Ellipsoid.jl | 2 - src/Sets/EmptySet.jl | 8 +- src/Sets/HParallelotope.jl | 4 +- src/Sets/HPolyhedron.jl | 7 - src/Sets/HPolytope.jl | 7 +- src/Sets/HalfSpace.jl | 7 - src/Sets/Hyperplane.jl | 7 +- src/Sets/Hyperrectangle.jl | 2 - src/Sets/Interval.jl | 11 +- src/Sets/Line.jl | 13 +- src/Sets/Line2D.jl | 7 +- src/Sets/LineSegment.jl | 6 +- src/Sets/SimpleSparsePolynomialZonotope.jl | 2 +- src/Sets/Singleton.jl | 2 - src/Sets/SparsePolynomialZonotope.jl | 4 +- src/Sets/Star.jl | 3 +- src/Sets/Universe.jl | 4 - src/Sets/VPolygon.jl | 7 +- src/Sets/VPolytope.jl | 5 - src/Sets/ZeroSet.jl | 6 +- src/Sets/Zonotope.jl | 4 - src/convert.jl | 2 +- 140 files changed, 1821 insertions(+), 1190 deletions(-) create mode 100644 docs/src/lib/API.md create mode 100644 src/API/API.jl create mode 100644 src/API/Binary/cartesian_product.jl create mode 100644 src/API/Binary/difference.jl create mode 100644 src/API/Binary/distance.jl create mode 100644 src/API/Binary/exact_sum.jl create mode 100644 src/API/Binary/intersection.jl create mode 100644 src/API/Binary/isapprox.jl create mode 100644 src/API/Binary/isdisjoint.jl create mode 100644 src/API/Binary/isequal.jl create mode 100644 src/API/Binary/isequivalent.jl create mode 100644 src/API/Binary/isstrictsubset.jl create mode 100644 src/API/Binary/issubset.jl create mode 100644 src/API/Binary/linear_combination.jl create mode 100644 src/API/Binary/minkowski_difference.jl create mode 100644 src/API/Binary/minkowski_sum.jl create mode 100644 src/API/LazySet.jl create mode 100644 src/API/Mixed/affine_map.jl create mode 100644 src/API/Mixed/exponential_map.jl create mode 100644 src/API/Mixed/in.jl create mode 100644 src/API/Mixed/is_interior_point.jl create mode 100644 src/API/Mixed/linear_map.jl create mode 100644 src/API/Mixed/permute.jl create mode 100644 src/API/Mixed/project.jl create mode 100644 src/API/Mixed/sample.jl create mode 100644 src/API/Mixed/scale!.jl create mode 100644 src/API/Mixed/scale.jl create mode 100644 src/API/Mixed/support_function.jl create mode 100644 src/API/Mixed/support_vector.jl create mode 100644 src/API/Mixed/translate!.jl create mode 100644 src/API/Mixed/translate.jl create mode 100644 src/API/Unary/an_element.jl create mode 100644 src/API/Unary/area.jl create mode 100644 src/API/Unary/complement.jl create mode 100644 src/API/Unary/concretize.jl create mode 100644 src/API/Unary/constraints.jl create mode 100644 src/API/Unary/constraints_list.jl create mode 100644 src/API/Unary/convex_hull.jl create mode 100644 src/API/Unary/diameter.jl create mode 100644 src/API/Unary/dim.jl create mode 100644 src/API/Unary/eltype.jl create mode 100644 src/API/Unary/extrema.jl create mode 100644 src/API/Unary/high.jl create mode 100644 src/API/Unary/is_polyhedral.jl create mode 100644 src/API/Unary/isbounded.jl create mode 100644 src/API/Unary/isboundedtype.jl create mode 100644 src/API/Unary/isconvextype.jl create mode 100644 src/API/Unary/isempty.jl create mode 100644 src/API/Unary/isoperation.jl create mode 100644 src/API/Unary/isoperationtype.jl create mode 100644 src/API/Unary/isuniversal.jl create mode 100644 src/API/Unary/low.jl create mode 100644 src/API/Unary/norm.jl create mode 100644 src/API/Unary/radius.jl create mode 100644 src/API/Unary/rand.jl create mode 100644 src/API/Unary/rectify.jl create mode 100644 src/API/Unary/reflect.jl create mode 100644 src/API/Unary/surface.jl create mode 100644 src/API/Unary/vertices.jl create mode 100644 src/API/Unary/vertices_list.jl create mode 100644 src/API/Unary/volume.jl create mode 100644 src/ConcreteOperations/isapprox.jl create mode 100644 src/ConcreteOperations/isequal.jl create mode 100644 src/ConcreteOperations/isequivalent.jl diff --git a/docs/make.jl b/docs/make.jl index 291bfbe5bc..383ed247b5 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -5,7 +5,7 @@ import Polyhedra, Optim, ExponentialUtilities, TaylorModels, Distributions, include("init.jl") makedocs(; sitename="LazySets.jl", - modules=[LazySets, Approximations, LazySets.Parallel], + modules=[LazySets, LazySets.API, Approximations, LazySets.Parallel], format=Documenter.HTML(; prettyurls=get(ENV, "CI", nothing) == "true", assets=["assets/aligned.css"], size_threshold_warn=150 * 2^10), @@ -33,6 +33,7 @@ makedocs(; sitename="LazySets.jl", "Lazy Intersections" => "man/lazy_intersections.md" # ], + "API" => "lib/API.md", "Library" => Any["Set Interfaces" => [ # "lib/interfaces/overview.md", diff --git a/docs/src/lib/API.md b/docs/src/lib/API.md new file mode 100644 index 0000000000..e9c2fdcbf8 --- /dev/null +++ b/docs/src/lib/API.md @@ -0,0 +1,100 @@ +```@contents +Pages = ["API.md"] +Depth = 3 +``` + +```@meta +CurrentModule = LazySets.API +``` + +```@docs +API +``` + +# Set interface + +```@docs +LazySet +``` + +# Unary set functions + +```@docs +an_element(::LazySet) +area(::LazySet) +complement(::LazySet) +concretize(::LazySet) +constraints_list(::LazySet) +constraints(::LazySet) +convex_hull(::LazySet) +diameter(::LazySet, ::Real=Inf) +dim(::LazySet) +eltype(::Type{<:LazySet}) +eltype(::LazySet) +extrema(::LazySet, ::Int) +extrema(::LazySet) +high(::LazySet, ::Int) +high(::LazySet) +is_polyhedral(::LazySet) +isbounded(::LazySet) +isboundedtype(::Type{<:LazySet}) +isconvextype(::Type{<:LazySet}) +isempty(::LazySet, ::Bool=false) +isoperation(::LazySet) +isoperationtype(::Type{<:LazySet}) +isuniversal(::LazySet, ::Bool=false) +low(::LazySet, ::Int) +low(::LazySet) +norm(::LazySet, ::Real=Inf) +radius(::LazySet, ::Real=Inf) +rand(::Type{<:LazySet}) +rectify(::LazySet) +reflect(::LazySet) +surface(::LazySet) +vertices_list(::LazySet) +vertices(::LazySet) +volume(::LazySet) +``` + +# Mixed set functions + +```@docs +affine_map(::AbstractMatrix, ::LazySet, ::AbstractVector) +exponential_map(::AbstractMatrix, ::LazySet) +∈(::AbstractVector, ::LazySet) +is_interior_point(::AbstractVector{N}, ::LazySet; p=Inf, ε=_rtol(N)) where {N<:Real} +linear_map(::AbstractMatrix, ::LazySet) +permute(::LazySet, ::AbstractVector{Int}) +project(::LazySet, ::AbstractVector{Int}) +sample(::LazySet, ::Int) +scale(::Real, ::LazySet) +scale!(::Real, ::LazySet) +ρ(::AbstractVector, ::LazySet) +support_function +σ(::AbstractVector, ::LazySet) +support_vector +translate(::LazySet, ::AbstractVector) +translate!(::LazySet, ::AbstractVector) +``` + +# Binary set functions + +```@docs +cartesian_product(::LazySet, ::LazySet) +difference(::LazySet, ::LazySet) +distance(::LazySet, ::LazySet) +exact_sum(::LazySet, ::LazySet) +⊞ +intersection(::LazySet, ::LazySet) +≈(::LazySet, ::LazySet) +isdisjoint(::LazySet, ::LazySet) +is_intersection_empty +==(::LazySet, ::LazySet) +isequivalent(::LazySet, ::LazySet) +⊂(::LazySet, ::LazySet) +⊆(::LazySet, ::LazySet) +linear_combination(::LazySet, ::LazySet) +minkowski_difference(::LazySet, ::LazySet) +pontryagin_difference +minkowski_sum(::LazySet, ::LazySet) +``` diff --git a/docs/src/lib/concrete_binary_operations/difference.md b/docs/src/lib/concrete_binary_operations/difference.md index 8c0d171e03..4f63778d78 100644 --- a/docs/src/lib/concrete_binary_operations/difference.md +++ b/docs/src/lib/concrete_binary_operations/difference.md @@ -12,5 +12,5 @@ CurrentModule = LazySets ```@docs \(::LazySet, ::LazySet) difference(::Interval{N}, ::Interval) where {N} -difference(::AbstractHyperrectangle{N}, ::AbstractHyperrectangle) where {N} +difference(::AbstractHyperrectangle, ::AbstractHyperrectangle) ``` diff --git a/docs/src/lib/concrete_binary_operations/exact_sum.md b/docs/src/lib/concrete_binary_operations/exact_sum.md index dde1846be7..d193f92c38 100644 --- a/docs/src/lib/concrete_binary_operations/exact_sum.md +++ b/docs/src/lib/concrete_binary_operations/exact_sum.md @@ -10,6 +10,5 @@ CurrentModule = LazySets # Exact Sum ```@docs -⊞ exact_sum(::SparsePolynomialZonotope, ::SparsePolynomialZonotope) ``` diff --git a/docs/src/lib/concrete_binary_operations/isdisjoint.md b/docs/src/lib/concrete_binary_operations/isdisjoint.md index 2b54eb6650..5f63f83806 100644 --- a/docs/src/lib/concrete_binary_operations/isdisjoint.md +++ b/docs/src/lib/concrete_binary_operations/isdisjoint.md @@ -12,9 +12,6 @@ CurrentModule = LazySets The function `isdisjoint` checks whether the intersection of two sets is empty. It can optionally produce a witness if the intersection is nonempty. -!!! note - `is_intersection_empty` can be used as an alternative name to `isdisjoint`. - ## Examples We use the following four sets for illustration. diff --git a/docs/src/lib/concrete_binary_operations/issubset.md b/docs/src/lib/concrete_binary_operations/issubset.md index 4ad3f13efd..76a1a15926 100644 --- a/docs/src/lib/concrete_binary_operations/issubset.md +++ b/docs/src/lib/concrete_binary_operations/issubset.md @@ -98,7 +98,6 @@ plot1 ## Methods ```@docs -issubset ⊆(::LazySet, ::LazySet, ::Bool=false) ⊆(::LazySet, ::AbstractHyperrectangle, ::Bool=false) ⊆(::AbstractPolytope, ::LazySet, ::Bool=false) diff --git a/docs/src/lib/concrete_binary_operations/minkowski_difference.md b/docs/src/lib/concrete_binary_operations/minkowski_difference.md index 42e9385d11..53b5251df0 100644 --- a/docs/src/lib/concrete_binary_operations/minkowski_difference.md +++ b/docs/src/lib/concrete_binary_operations/minkowski_difference.md @@ -10,7 +10,6 @@ CurrentModule = LazySets # Minkowski Difference ```@docs -pontryagin_difference minkowski_difference(::LazySet, ::LazySet) minkowski_difference(::AbstractZonotope, ::AbstractZonotope) minkowski_difference(::AbstractHyperrectangle, ::AbstractHyperrectangle) diff --git a/docs/src/lib/interfaces/LazySet.md b/docs/src/lib/interfaces/LazySet.md index aade46b16f..6f50eb05c0 100644 --- a/docs/src/lib/interfaces/LazySet.md +++ b/docs/src/lib/interfaces/LazySet.md @@ -67,7 +67,6 @@ an_element(::LazySet) tosimplehrep(::LazySet) reflect(::LazySet) is_interior_point(::AbstractVector{N}, ::LazySet{N}; p=Inf, ε=_rtol(N)) where {N<:Real} -isoperationtype(::Type{<:LazySet}) isoperation(::LazySet) isequivalent(::LazySet, ::LazySet) surface(::LazySet) @@ -108,9 +107,7 @@ definition based on `σ` is used. ```@docs σ -support_vector ρ(::AbstractVector, ::LazySet) -support_function ``` ## Set functions that override Base functions @@ -118,8 +115,6 @@ support_function ```@docs ==(::LazySet, ::LazySet) ≈(::LazySet, ::LazySet) -copy(::LazySet) -eltype ``` ## Aliases for set types diff --git a/src/API/API.jl b/src/API/API.jl new file mode 100644 index 0000000000..64d5f50a90 --- /dev/null +++ b/src/API/API.jl @@ -0,0 +1,96 @@ +""" + API + +This module contains an API (application programming interface) for set +libraries. The module only defines and documents the general functions and does +not provide implementations. +""" +module API + +import Base: eltype, extrema, isdisjoint, isempty, ∈, ≈, ==, ⊆ +import Random: rand +import LinearAlgebra: norm +import SparseArrays: permute +import ReachabilityBase.Arrays: distance, rectify + +export +# unary set operations + an_element, area, complement, concretize, constraints_list, constraints, + convex_hull, diameter, dim, high, is_polyhedral, isbounded, + isboundedtype, isconvextype, isempty, isoperation, isoperationtype, + isuniversal, low, norm, radius, rectify, reflect, sample, + support_function, ρ, support_vector, σ, surface, vertices_list, vertices, + volume, +# mixed set operations (typically with vectors or matrices) + affine_map, exponential_map, is_interior_point, linear_map, project, + scale!, scale, support_function, ρ, support_vector, σ, translate!, + translate, +# binary set operations + cartesian_product, difference, distance, exact_sum, ⊞, intersection, + is_intersection_empty, isequivalent, ⊂, linear_combination, + minkowski_difference, pontryagin_difference, minkowski_sum + +include("LazySet.jl") + +include("Unary/an_element.jl") +include("Unary/area.jl") +include("Unary/complement.jl") +include("Unary/concretize.jl") +include("Unary/constraints_list.jl") +include("Unary/constraints.jl") +include("Unary/convex_hull.jl") +include("Unary/diameter.jl") +include("Unary/dim.jl") +include("Unary/eltype.jl") +include("Unary/extrema.jl") +include("Unary/high.jl") +include("Unary/is_polyhedral.jl") +include("Unary/isbounded.jl") +include("Unary/isboundedtype.jl") +include("Unary/isconvextype.jl") +include("Unary/isempty.jl") +include("Unary/isoperation.jl") +include("Unary/isoperationtype.jl") +include("Unary/isuniversal.jl") +include("Unary/low.jl") +include("Unary/norm.jl") +include("Unary/radius.jl") +include("Unary/rand.jl") +include("Unary/rectify.jl") +include("Unary/reflect.jl") +include("Unary/surface.jl") +include("Unary/vertices_list.jl") +include("Unary/vertices.jl") +include("Unary/volume.jl") + +include("Mixed/affine_map.jl") +include("Mixed/exponential_map.jl") +include("Mixed/in.jl") +include("Mixed/is_interior_point.jl") +include("Mixed/linear_map.jl") +include("Mixed/permute.jl") +include("Mixed/project.jl") +include("Mixed/sample.jl") +include("Mixed/scale!.jl") +include("Mixed/scale.jl") +include("Mixed/support_function.jl") +include("Mixed/support_vector.jl") +include("Mixed/translate!.jl") +include("Mixed/translate.jl") + +include("Binary/cartesian_product.jl") +include("Binary/difference.jl") +include("Binary/distance.jl") +include("Binary/exact_sum.jl") +include("Binary/intersection.jl") +include("Binary/isapprox.jl") +include("Binary/isdisjoint.jl") +include("Binary/isequal.jl") +include("Binary/isequivalent.jl") +include("Binary/isstrictsubset.jl") +include("Binary/issubset.jl") +include("Binary/linear_combination.jl") +include("Binary/minkowski_difference.jl") +include("Binary/minkowski_sum.jl") + +end # module diff --git a/src/API/Binary/cartesian_product.jl b/src/API/Binary/cartesian_product.jl new file mode 100644 index 0000000000..8159ab0618 --- /dev/null +++ b/src/API/Binary/cartesian_product.jl @@ -0,0 +1,23 @@ +""" + cartesian_product(X::LazySet, Y::LazySet) + +Compute the Cartesian product of two sets. + +### Input + +- `X` -- set +- `Y` -- set + +### Output + +A set representing the Cartesian product ``X × Y``. + +### Notes + +The Cartesian product of two sets ``X`` and ``Y`` is defined as + +```math + X × Y = \\{[x, y] \\mid x ∈ X, y ∈ Y\\}. +``` +""" +function cartesian_product(::LazySet, ::LazySet) end diff --git a/src/API/Binary/difference.jl b/src/API/Binary/difference.jl new file mode 100644 index 0000000000..62685d8f97 --- /dev/null +++ b/src/API/Binary/difference.jl @@ -0,0 +1,23 @@ +""" + difference(X::LazySet, Y::LazySet) + +Compute the set difference of two sets. + +### Input + +- `X` -- set +- `Y` -- set + +### Output + +A set representing the difference ``X ∖ Y``. + +### Notes + +The set difference is defined as: + +```math + X ∖ Y = \\{x \\mid x ∈ X \\text{ and } x ∉ Y \\} +``` +""" +function difference(::LazySet, ::LazySet) end diff --git a/src/API/Binary/distance.jl b/src/API/Binary/distance.jl new file mode 100644 index 0000000000..b63253911d --- /dev/null +++ b/src/API/Binary/distance.jl @@ -0,0 +1,25 @@ +""" + distance(X::LazySet, Y::LazySet; [p]::Real=2) + +Compute the standard distance (induced by the ``p``-norm) between two sets. + +### Input + +- `X` -- set +- `Y` -- set +- `p` -- (optional; default: `2`) value of the ``p``-norm + +### Output + +A real number representing the distance between `X` and `Y`. + +### Notes + +The standard distance is zero if the sets intersect and otherwise the ``p``-norm +of the shortest line segment between any pair of points. Formally, + +```math + \\inf_{x ∈ H_1, y ∈ H_2} \\{ d(x, y) \\}. +``` +""" +function distance(::LazySet, ::LazySet; p::Real=2) end diff --git a/src/API/Binary/exact_sum.jl b/src/API/Binary/exact_sum.jl new file mode 100644 index 0000000000..a0ca1d4a50 --- /dev/null +++ b/src/API/Binary/exact_sum.jl @@ -0,0 +1,31 @@ +""" + exact_sum(X::LazySet, Y::LazySet) + +Compute the exact sum of two parametric sets. + +### Input + +- `X` -- parametric set +- `Y` -- parametric set + +### Output + +A set representing the exact sum ``X ⊞ Y``. + +### Notes + +The convenience alias `⊞` is also available, which can be typed by +`\\boxplus`. +""" +function exact_sum(::LazySet, ::LazySet) end + +""" + ⊞(X::LazySet, Y::LazySet) + +Convenience alias for the (concrete) `exact_sum` function. + +### Notes + +"`⊞`" can be typed by `\\boxplus`. +""" +const ⊞ = exact_sum diff --git a/src/API/Binary/intersection.jl b/src/API/Binary/intersection.jl new file mode 100644 index 0000000000..8c7eb0de22 --- /dev/null +++ b/src/API/Binary/intersection.jl @@ -0,0 +1,23 @@ +""" + intersection(X::LazySet, Y::LazySet) + +Compute the intersection of two sets. + +### Input + +- `X` -- set +- `Y` -- set + +### Output + +A set representing the intersection ``X ∩ Y``. + +### Notes + +The intersection of two sets ``X`` and ``Y`` is defined as + +```math + X ∩ Y = \\{x \\mid x ∈ X \\text{ and } x ∈ Y\\}. +``` +""" +function intersection(::LazySet, ::LazySet) end diff --git a/src/API/Binary/isapprox.jl b/src/API/Binary/isapprox.jl new file mode 100644 index 0000000000..1b2ba6629a --- /dev/null +++ b/src/API/Binary/isapprox.jl @@ -0,0 +1,25 @@ +""" + ≈(X::LazySet, Y::LazySet) + +Check whether two sets of the same type are approximately equal. + +### Input + +- `X` -- set +- `Y` -- set of the same base type as `X` + +### Output + +`true` iff `X` is approximately equal to `Y`. + +### Notes + +The check is purely syntactic and the sets need to have the same base type, i.e., +`X::T1 ≈ Y::T2` always returns `false` even if `X` and `Y` represent the same +set. But `X::T{Int64} ≈ Y::T{Float64}` is a valid comparison. + +The convenience alias `isapprox` is also available. + +"`≈`" can be typed by `\\approx`. +""" +function ≈(::LazySet, ::LazySet) end diff --git a/src/API/Binary/isdisjoint.jl b/src/API/Binary/isdisjoint.jl new file mode 100644 index 0000000000..3401d8fd50 --- /dev/null +++ b/src/API/Binary/isdisjoint.jl @@ -0,0 +1,31 @@ +""" + isdisjoint(X::LazySet, Y::LazySet, [witness]::Bool=false) + +Check whether two sets are disjoint (i.e., do not intersect), and optionally +compute a witness. + +### Input + +- `X` -- set +- `Y` -- set +- `witness` -- (optional, default: `false`) compute a witness if activated + +### Output + +* If the `witness` option is deactivated: `true` iff ``X ∩ Y = ∅`` +* If the `witness` option is activated: + * `(true, [])` iff ``X ∩ Y = ∅`` + * `(false, v)` iff ``X ∩ Y ≠ ∅`` for some ``v ∈ X ∩ Y`` + +### Notes + +The convenience alias `is_intersection_empty` is also available. +""" +function isdisjoint(::LazySet, ::LazySet, ::Bool=false) end + +""" + is_intersection_empty(X::LazySet, Y::LazySet, [witness]::Bool=false) + +Convenience alias for the `isdisjoint` function. +""" +const is_intersection_empty = isdisjoint diff --git a/src/API/Binary/isequal.jl b/src/API/Binary/isequal.jl new file mode 100644 index 0000000000..66d3a7f4de --- /dev/null +++ b/src/API/Binary/isequal.jl @@ -0,0 +1,21 @@ +""" + ==(X::LazySet, Y::LazySet) + +Check whether two sets use exactly the same set representation. + +### Input + +- `X` -- set +- `Y` -- set + +### Output + +`true` iff `X` is equal to `Y`. + +### Notes + +The check is purely syntactic and the sets need to have the same base type, i.e., +`X::T1 == Y::T2` always returns `false` even if `X` and `Y` represent the same +set. But `X::T{Int64} == Y::T{Float64}` is a valid comparison. +""" +function ==(::LazySet, ::LazySet) end diff --git a/src/API/Binary/isequivalent.jl b/src/API/Binary/isequivalent.jl new file mode 100644 index 0000000000..ed8b472149 --- /dev/null +++ b/src/API/Binary/isequivalent.jl @@ -0,0 +1,15 @@ +""" + isequivalent(X::LazySet, Y::LazySet) + +Check whether two sets are equivalent, i.e., represent the same set of points. + +### Input + +- `X` -- set +- `Y` -- set + +### Output + +`true` iff `X` is equivalent to `Y` (up to numerical precision). +""" +function isequivalent(::LazySet, ::LazySet) end diff --git a/src/API/Binary/isstrictsubset.jl b/src/API/Binary/isstrictsubset.jl new file mode 100644 index 0000000000..e7a86e9231 --- /dev/null +++ b/src/API/Binary/isstrictsubset.jl @@ -0,0 +1,33 @@ +""" + ⊂(X::LazySet, Y::LazySet, [witness]::Bool=false) + +Check whether a set is a strict subset of another set, and optionally compute a +witness. + +### Input + +- `X` -- set +- `Y` -- set +- `witness` -- (optional, default: `false`) compute a witness if activated + +### Output + +* If the `witness` option is deactivated: `true` iff ``X ⊂ Y`` +* If the `witness` option is activated: + * `(true, v)` iff ``X ⊂ Y`` for some ``v ∈ Y ∖ X`` + * `(false, [])` iff ``X ⊂ Y`` does not hold + +### Notes + +Strict inclusion is sometimes written as `⊊`. The following identity holds: + +```math + X ⊂ Y ⇔ X ⊆ Y ∧ Y ⊈ X +``` + +### Algorithm + +The default implementation first checks inclusion of `X` in `Y` and then checks +noninclusion of `Y` in `X`: +""" +function ⊂(::LazySet, ::LazySet, ::Bool=false) end diff --git a/src/API/Binary/issubset.jl b/src/API/Binary/issubset.jl new file mode 100644 index 0000000000..6525a73f0a --- /dev/null +++ b/src/API/Binary/issubset.jl @@ -0,0 +1,23 @@ +""" + ⊆(X::LazySet, Y::LazySet, [witness]::Bool=false) + +Check whether a set is a subset of another set, and optionally compute a witness. + +### Input + +- `X` -- set +- `Y` -- set +- `witness` -- (optional, default: `false`) compute a witness if activated + +### Output + +* If the `witness` option is deactivated: `true` iff ``X ⊆ Y`` +* If the `witness` option is activated: + * `(true, [])` iff ``X ⊆ Y`` + * `(false, v)` iff ``X ⊈ Y`` for some ``v ∈ X ∖ Y`` + +### Notes + +The convenience alias `issubset` is also available. +""" +function ⊆(::LazySet, ::LazySet, ::Bool=false) end diff --git a/src/API/Binary/linear_combination.jl b/src/API/Binary/linear_combination.jl new file mode 100644 index 0000000000..7781f7a7ac --- /dev/null +++ b/src/API/Binary/linear_combination.jl @@ -0,0 +1,23 @@ +""" + linear_combination(X::LazySet, Y::LazySet) + +Compute the linear combination of two sets. + +### Input + +- `X` -- set +- `Y` -- set + +### Output + +A set representing the linear combination of `X` and `Y`. + +### Notes + +The linear combination of two sets ``X`` and ``Y`` is defined as + +```math + \\left\\{\\frac{1}{2}(1+λ)x + \\frac{1}{2}(1-λ)y \\mid x ∈ X, y ∈ Y, λ ∈ [-1, 1]\\right\\}. +``` +""" +function linear_combination(::LazySet, ::LazySet) end diff --git a/src/API/Binary/minkowski_difference.jl b/src/API/Binary/minkowski_difference.jl new file mode 100644 index 0000000000..7f8a39e395 --- /dev/null +++ b/src/API/Binary/minkowski_difference.jl @@ -0,0 +1,36 @@ +""" + minkowski_difference(X::LazySet, Y::LazySet) + +Compute the Minkowski difference of two sets. + +### Input + +- `X` -- set +- `Y` -- set + +### Output + +A set representing the Minkowski difference ``X ⊖ Y``. + +### Notes + +The Minkowski difference of two sets ``X`` and ``Y`` is defined as + +```math + X ⊖ Y = \\{x \\mid x + y ∈ X ~∀~y ∈ Y\\} +``` + +The convenience alias `pontryagin_difference` is also available. + +There is some inconsistency in the literature regarding the naming conventions. +In this library, both *Minkowski difference* and *Pontryagin difference* refer +to the geometric difference of two sets. +""" +function minkowski_difference(::LazySet, ::LazySet) end + +""" + pontryagin_difference(X::LazySet, Y::LazySet) + +Convenience alias for the `minkowski_difference` function. +""" +const pontryagin_difference = minkowski_difference diff --git a/src/API/Binary/minkowski_sum.jl b/src/API/Binary/minkowski_sum.jl new file mode 100644 index 0000000000..17a716fc0b --- /dev/null +++ b/src/API/Binary/minkowski_sum.jl @@ -0,0 +1,23 @@ +""" + minkowski_sum(X::LazySet, Y::LazySet) + +Compute the Minkowski sum of two sets. + +### Input + +- `X` -- set +- `Y` -- set + +### Output + +A set representing the Minkowski sum ``X ⊕ Y``. + +### Notes + +The Minkowski sum of two sets ``X`` and ``Y`` is defined as + +```math + X ⊕ Y = \\{x + y \\mid x ∈ X, y ∈ Y\\}. +``` +""" +function minkowski_sum(::LazySet, ::LazySet) end diff --git a/src/API/LazySet.jl b/src/API/LazySet.jl new file mode 100644 index 0000000000..317394cd8c --- /dev/null +++ b/src/API/LazySet.jl @@ -0,0 +1,13 @@ + +""" + LazySet + +Abstract type for a set of points. + +This type is not exported and is only used to define interface methods without +type piracy. + +The `LazySets` library defines its own set interface, which is also called +`LazySet`. +""" +abstract type LazySet end diff --git a/src/API/Mixed/affine_map.jl b/src/API/Mixed/affine_map.jl new file mode 100644 index 0000000000..a10612e9e7 --- /dev/null +++ b/src/API/Mixed/affine_map.jl @@ -0,0 +1,16 @@ +""" + affine_map(M::AbstractMatrix, X::LazySet, v::AbstractVector) + +Compute the affine map ``M · X + v``. + +### Input + +- `M` -- matrix +- `X` -- set +- `v` -- translation vector + +### Output + +A set representing the affine map ``M · X + v``. +""" +function affine_map(::AbstractMatrix, ::LazySet, ::AbstractVector) end diff --git a/src/API/Mixed/exponential_map.jl b/src/API/Mixed/exponential_map.jl new file mode 100644 index 0000000000..0331252dd1 --- /dev/null +++ b/src/API/Mixed/exponential_map.jl @@ -0,0 +1,15 @@ +""" + exponential_map(M::AbstractMatrix, X::LazySet) + +Compute the exponential map of `M` and `X`, i.e., ``eᴹ ⋅ X``. + +### Input + +- `M` -- matrix +- `X` -- set + +### Output + +A set representing the exponential map ``eᴹ ⋅ X``. +""" +function exponential_map(::AbstractMatrix, ::LazySet) end diff --git a/src/API/Mixed/in.jl b/src/API/Mixed/in.jl new file mode 100644 index 0000000000..8185446cad --- /dev/null +++ b/src/API/Mixed/in.jl @@ -0,0 +1,15 @@ +""" + ∈(x::AbstractVector, X::LazySet) + +Check whether a point lies in a set. + +### Input + +- `x` -- point/vector +- `X` -- set + +### Output + +`true` iff ``x ∈ X``. +""" +function ∈(::AbstractVector, ::LazySet) end diff --git a/src/API/Mixed/is_interior_point.jl b/src/API/Mixed/is_interior_point.jl new file mode 100644 index 0000000000..3ff19fb840 --- /dev/null +++ b/src/API/Mixed/is_interior_point.jl @@ -0,0 +1,18 @@ +""" + is_interior_point(v::AbstractVector{N}, X::LazySet; [p]=N(Inf), [ε]=_rtol(N)) where {N} + +Check whether a point is contained in the interior of a set. + +### Input + +- `v` -- point/vector +- `X` -- set +- `p` -- (optional; default: `N(Inf)`) norm of the ball used to apply the error + tolerance +- `ε` -- (optional; default: `_rtol(N)`) error tolerance of the check + +### Output + +`true` iff the point `v` is strictly contained in `X` with tolerance `ε`. +""" +function is_interior_point(::AbstractVector{N}, ::LazySet; p=N(Inf), ε=_rtol(N)) where {N} end diff --git a/src/API/Mixed/linear_map.jl b/src/API/Mixed/linear_map.jl new file mode 100644 index 0000000000..a1be60c149 --- /dev/null +++ b/src/API/Mixed/linear_map.jl @@ -0,0 +1,15 @@ +""" + linear_map(M::AbstractMatrix, X::LazySet) + +Compute the linear map ``M · X``. + +### Input + +- `M` -- matrix +- `X` -- set + +### Output + +A set representing the linear map ``M · X``. +""" +function linear_map(::AbstractMatrix, ::LazySet) end diff --git a/src/API/Mixed/permute.jl b/src/API/Mixed/permute.jl new file mode 100644 index 0000000000..b73f98fb6f --- /dev/null +++ b/src/API/Mixed/permute.jl @@ -0,0 +1,16 @@ +""" + permute(X::LazySet, p::AbstractVector{Int}) + +Permute the dimensions of a set according to a given permutation vector. + +### Input + +- `X` -- set +- `p` -- permutation vector + +### Output + +A new set corresponding to `X` where the dimensions have been permuted according +to `p`. +""" +function permute(::LazySet, ::AbstractVector{Int}) end diff --git a/src/API/Mixed/project.jl b/src/API/Mixed/project.jl new file mode 100644 index 0000000000..5ef61ba04a --- /dev/null +++ b/src/API/Mixed/project.jl @@ -0,0 +1,15 @@ +""" + project(X::LazySet, block::AbstractVector{Int}) + +Project a set to a given block by using a concrete linear map. + +### Input + +- `X` -- set +- `block` -- block structure - a vector with the dimensions of interest + +### Output + +A set representing the projection of `X` to block `block`. +""" +function project(::LazySet, ::AbstractVector{Int}) end diff --git a/src/API/Mixed/sample.jl b/src/API/Mixed/sample.jl new file mode 100644 index 0000000000..3eae1d21ab --- /dev/null +++ b/src/API/Mixed/sample.jl @@ -0,0 +1,19 @@ +""" + sample(X::LazySet, m::Int; + [rng]::AbstractRNG=GLOBAL_RNG, + [seed]::Union{Int,Nothing}=nothing) + +Compute samples from a set. + +### Input + +- `X` -- set +- `m` -- number of random samples +- `rng` -- (optional, default: `GLOBAL_RNG`) random number generator +- `seed` -- (optional, default: `nothing`) seed for reseeding + +### Output + +A vector of `m` elements in `X`. +""" +function sample(::LazySet, ::Int) end diff --git a/src/API/Mixed/scale!.jl b/src/API/Mixed/scale!.jl new file mode 100644 index 0000000000..837729f335 --- /dev/null +++ b/src/API/Mixed/scale!.jl @@ -0,0 +1,15 @@ +""" + scale!(α::Real, X::LazySet) + +Scale a set by modifying it. + +### Input + +- `α` -- scalar +- `X` -- set + +### Output + +The scaled set representing ``α ⋅ X``. +""" +function scale!(::Real, ::LazySet) end diff --git a/src/API/Mixed/scale.jl b/src/API/Mixed/scale.jl new file mode 100644 index 0000000000..1ecac84039 --- /dev/null +++ b/src/API/Mixed/scale.jl @@ -0,0 +1,16 @@ + +""" + scale(α::Real, X::LazySet) + +Compute the scaling of a set. + +### Input + +- `α` -- scalar +- `X` -- set + +### Output + +A set representing ``α ⋅ X``. +""" +function scale(::Real, ::LazySet) end diff --git a/src/API/Mixed/support_function.jl b/src/API/Mixed/support_function.jl new file mode 100644 index 0000000000..50b18c3691 --- /dev/null +++ b/src/API/Mixed/support_function.jl @@ -0,0 +1,27 @@ +""" + ρ(d::AbstractVector, X::LazySet) + +Evaluate the support function of a set in a given direction. + +### Input + +- `d` -- direction +- `X` -- set + +### Output + +The evaluation of the support function of `X` in direction `d`. + +### Notes + +A convenience alias `support_function` is also available. + +We have the following identity based on the support vector ``σ``: + +```math + ρ(d, X) = d ⋅ σ(d, X) +``` +""" +function ρ(::AbstractVector, ::LazySet) end + +const support_function = ρ diff --git a/src/API/Mixed/support_vector.jl b/src/API/Mixed/support_vector.jl new file mode 100644 index 0000000000..df9d41fecc --- /dev/null +++ b/src/API/Mixed/support_vector.jl @@ -0,0 +1,21 @@ +""" + σ(d::AbstractVector, X::LazySet) + +Compute a support vector of a set in a given direction. + +### Input + +- `d` -- direction +- `X` -- set + +### Output + +A support vector of `X` in direction `d`. + +### Notes + +A convenience alias `support_vector` is also available. +""" +function σ(::AbstractVector, ::LazySet) end + +const support_vector = σ diff --git a/src/API/Mixed/translate!.jl b/src/API/Mixed/translate!.jl new file mode 100644 index 0000000000..8ec004ca27 --- /dev/null +++ b/src/API/Mixed/translate!.jl @@ -0,0 +1,15 @@ +""" + translate!(X::LazySet, v::AbstractVector) + +Translate a set with a vector by modifying it. + +### Input + +- `X` -- set +- `v` -- vector + +### Output + +The translated set representing ``X + \\{v\\}``. +""" +function translate!(::LazySet, ::AbstractVector) end diff --git a/src/API/Mixed/translate.jl b/src/API/Mixed/translate.jl new file mode 100644 index 0000000000..b05a986056 --- /dev/null +++ b/src/API/Mixed/translate.jl @@ -0,0 +1,15 @@ +""" + translate(X::LazySet, v::AbstractVector) + +Compute the translation of a set with a vector. + +### Input + +- `X` -- set +- `v` -- vector + +### Output + +A set representing ``X + \\{v\\}``. +""" +function translate(::LazySet, ::AbstractVector) end diff --git a/src/API/Unary/an_element.jl b/src/API/Unary/an_element.jl new file mode 100644 index 0000000000..a964895f8b --- /dev/null +++ b/src/API/Unary/an_element.jl @@ -0,0 +1,14 @@ +""" + an_element(X::LazySet) + +Return some element of a nonempty set. + +### Input + +- `X` -- set + +### Output + +An element of `X` unless `X` is empty. +""" +function an_element(::LazySet) end diff --git a/src/API/Unary/area.jl b/src/API/Unary/area.jl new file mode 100644 index 0000000000..19c1abfb3d --- /dev/null +++ b/src/API/Unary/area.jl @@ -0,0 +1,14 @@ +""" + area(X::LazySet) + +Compute the area of a two-dimensional set. + +### Input + +- `X` -- two-dimensional set + +### Output + +A number representing the area of `X`. +""" +function area(::LazySet) end diff --git a/src/API/Unary/complement.jl b/src/API/Unary/complement.jl new file mode 100644 index 0000000000..45e0f00bce --- /dev/null +++ b/src/API/Unary/complement.jl @@ -0,0 +1,14 @@ +""" + complement(X::LazySet) + +Compute the complement of a set. + +### Input + +- `X` -- set + +### Output + +A set representing the complement of `X`. +""" +function complement(::LazySet) end diff --git a/src/API/Unary/concretize.jl b/src/API/Unary/concretize.jl new file mode 100644 index 0000000000..9947c8a69c --- /dev/null +++ b/src/API/Unary/concretize.jl @@ -0,0 +1,19 @@ +""" + concretize(X::LazySet) + +Construct a concrete representation of a (possibly lazy) set. + +### Input + +- `X` -- set + +### Output + +A concrete representation of `X` (as far as possible). + +### Notes + +Since not every lazy set has a concrete set representation in this library, the +result may still be partially lazy. +""" +function concretize(::LazySet) end diff --git a/src/API/Unary/constraints.jl b/src/API/Unary/constraints.jl new file mode 100644 index 0000000000..132fe942c1 --- /dev/null +++ b/src/API/Unary/constraints.jl @@ -0,0 +1,14 @@ +""" + constraints(X::LazySet) + +Construct an iterator over the constraints of a polyhedral set. + +### Input + +- `X` -- polyhedral set + +### Output + +An iterator over the constraints of `X`. +""" +function constraints(::LazySet) end diff --git a/src/API/Unary/constraints_list.jl b/src/API/Unary/constraints_list.jl new file mode 100644 index 0000000000..9238709ab5 --- /dev/null +++ b/src/API/Unary/constraints_list.jl @@ -0,0 +1,14 @@ +""" + constraints_list(X::LazySet) + +Compute a list of linear constraints of a polyhedral set. + +### Input + +- `X` -- polyhedral set + +### Output + +A list of the linear constraints of `X`. +""" +function constraints_list(::LazySet) end diff --git a/src/API/Unary/convex_hull.jl b/src/API/Unary/convex_hull.jl new file mode 100644 index 0000000000..700cb20c6a --- /dev/null +++ b/src/API/Unary/convex_hull.jl @@ -0,0 +1,22 @@ +""" + convex_hull(X::LazySet) + +Compute the convex hull of a set. + +### Input + +- `X` -- set + +### Output + +A set representing the convex hull of `X`. + +### Notes + +The convex hull of a set ``X`` is defined as + +```math + \\{λx + (1-λ)y \\mid x, y ∈ X, λ ∈ [0, 1]\\}. +``` +""" +function convex_hull(::LazySet) end diff --git a/src/API/Unary/diameter.jl b/src/API/Unary/diameter.jl new file mode 100644 index 0000000000..aa3ca81cd9 --- /dev/null +++ b/src/API/Unary/diameter.jl @@ -0,0 +1,21 @@ +""" + diameter(X::LazySet, [p]::Real=Inf) + +Return the diameter of a set. + +### Input + +- `X` -- set +- `p` -- (optional, default: `Inf`) norm + +### Output + +A real number representing the diameter. + +### Notes + +The diameter of a set 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. +""" +function diameter(::LazySet, ::Real=Inf) end diff --git a/src/API/Unary/dim.jl b/src/API/Unary/dim.jl new file mode 100644 index 0000000000..d707f238bd --- /dev/null +++ b/src/API/Unary/dim.jl @@ -0,0 +1,14 @@ +""" + dim(X::LazySet) + +Compute the ambient dimension of a set. + +### Input + +- `X` -- set + +### Output + +The ambient dimension of the set. +""" +function dim(::LazySet) end diff --git a/src/API/Unary/eltype.jl b/src/API/Unary/eltype.jl new file mode 100644 index 0000000000..4ef49c9d47 --- /dev/null +++ b/src/API/Unary/eltype.jl @@ -0,0 +1,29 @@ +""" + eltype(T::Type{<:LazySet}) + +Determine the numeric type of a set type. + +### Input + +- `T` -- set type + +### Output + +The numeric type of `T`. +""" +function eltype(::Type{<:LazySet}) end + +""" + eltype(X::LazySet) + +Determine the numeric type of a set. + +### Input + +- `X` -- set + +### Output + +The numeric type of `X`. +""" +function eltype(::LazySet) end diff --git a/src/API/Unary/extrema.jl b/src/API/Unary/extrema.jl new file mode 100644 index 0000000000..6855e4c60d --- /dev/null +++ b/src/API/Unary/extrema.jl @@ -0,0 +1,52 @@ +""" + extrema(X::LazySet, i::Int) + +Compute the lowest and highest coordinate of a set in a given dimension. + +### Input + +- `X` -- set +- `i` -- dimension + +### Output + +Two real numbers representing the lowest and highest coordinate of the set in +the given dimension. + +### Notes + +The result is equivalent to `(low(X, i), high(X, i))`, but sometimes it can be +computed more efficiently. + +The resulting values are the lower and upper ends of the projection. +""" +function extrema(::LazySet, ::Int) end + +""" + extrema(X::LazySet) + +Compute the lowest and highest coordinate of a set in each dimension. + +### Input + +- `X` -- set + +### Output + +Two vectors with the lowest and highest coordinates of `X` in each dimension. + +### Notes + +See also [`extrema(X::LazySet, i::Int)`](@ref). + +The result is equivalent to `(low(X), high(X))`, but sometimes it can be +computed more efficiently. + +The resulting points are the lowest and highest corners of the box +approximation, so they are not necessarily contained in `X`. + +### Algorithm + +The default implementation computes the extrema via `low` and `high`. +""" +function extrema(::LazySet) end diff --git a/src/API/Unary/high.jl b/src/API/Unary/high.jl new file mode 100644 index 0000000000..e17e0286ea --- /dev/null +++ b/src/API/Unary/high.jl @@ -0,0 +1,42 @@ +""" + high(X::LazySet, i::Int) + +Compute the highest coordinate of a set in a given dimension. + +### Input + +- `X` -- set +- `i` -- dimension + +### Output + +A real number representing the highest coordinate of the set in the given +dimension. + +### Notes + +The resulting value is the upper end of the projection. +""" +function high(::LazySet, ::Int) end + +""" + high(X::LazySet) + +Compute the highest coordinate of a set in each dimension. + +### Input + +- `X` -- set + +### Output + +A vector with the highest coordinate of the set in each dimension. + +### Notes + +See also `high(X::LazySet, i::Int)`. + +The result is the uppermost corner of the box approximation, so it is not +necessarily contained in `X`. +""" +function high(::LazySet) end diff --git a/src/API/Unary/is_polyhedral.jl b/src/API/Unary/is_polyhedral.jl new file mode 100644 index 0000000000..b21341251d --- /dev/null +++ b/src/API/Unary/is_polyhedral.jl @@ -0,0 +1,19 @@ +""" + is_polyhedral(X::LazySet) + +Check whether a set is polyhedral. + +### Input + +- `X` -- set + +### Output + +`true` only if the set is polyhedral. + +### Notes + +The answer is conservative, i.e., may sometimes be `false` even if the set is +polyhedral. +""" +function is_polyhedral(::LazySet) end diff --git a/src/API/Unary/isbounded.jl b/src/API/Unary/isbounded.jl new file mode 100644 index 0000000000..a90bc79026 --- /dev/null +++ b/src/API/Unary/isbounded.jl @@ -0,0 +1,18 @@ +""" + isbounded(X::LazySet) + +Check whether a set is bounded. + +### Input + +- `X` -- set + +### Output + +`true` iff the set is bounded. + +### Notes + +See also [`isboundedtype(::Type{<:LazySet})`](@ref). +""" +function isbounded(::LazySet) end diff --git a/src/API/Unary/isboundedtype.jl b/src/API/Unary/isboundedtype.jl new file mode 100644 index 0000000000..15295f3a07 --- /dev/null +++ b/src/API/Unary/isboundedtype.jl @@ -0,0 +1,18 @@ +""" + isboundedtype(T::Type{<:LazySet}) + +Check whether a set type only represents bounded sets. + +### Input + +- `T` -- set type + +### Output + +`true` iff the set type only represents bounded sets. + +### Notes + +See also [`isbounded(::LazySet)`](@ref). +""" +function isboundedtype(::Type{<:LazySet}) end diff --git a/src/API/Unary/isconvextype.jl b/src/API/Unary/isconvextype.jl new file mode 100644 index 0000000000..e430c80c94 --- /dev/null +++ b/src/API/Unary/isconvextype.jl @@ -0,0 +1,20 @@ +""" + isconvextype(T::Type{<:LazySet}) + +Check whether `T` is convex just by using type information. + +### Input + +- `T` -- subtype of `LazySet` + +### Output + +`true` iff the set type only represents convex sets. + +### Notes + +Since this operation only acts on types (not on values), it can return false +negatives, i.e., there may be instances where the set is convex, even though the +answer of this function is `false`. The examples below illustrate this point. +""" +function isconvextype(::Type{<:LazySet}) end diff --git a/src/API/Unary/isempty.jl b/src/API/Unary/isempty.jl new file mode 100644 index 0000000000..5573e13912 --- /dev/null +++ b/src/API/Unary/isempty.jl @@ -0,0 +1,18 @@ +""" + isempty(X::LazySet, witness::Bool=false) + +Check whether a set is empty. + +### Input + +- `X` -- set +- `witness` -- (optional, default: `false`) compute a witness if activated + +### Output + +* If the `witness` option is deactivated: `true` iff ``X = ∅`` +* If the `witness` option is activated: + * `(true, [])` iff ``X = ∅`` + * `(false, v)` iff ``X ≠ ∅`` for some ``v ∈ X`` +""" +function isempty(::LazySet, ::Bool=false) end diff --git a/src/API/Unary/isoperation.jl b/src/API/Unary/isoperation.jl new file mode 100644 index 0000000000..bce3a86b13 --- /dev/null +++ b/src/API/Unary/isoperation.jl @@ -0,0 +1,18 @@ +""" + isoperation(X::LazySet) + +Check whether a set is an instance of a (lazy) set operation. + +### Input + +- `X` -- set + +### Output + +`true` iff `X` is an instance of a set-based operation. + +### Notes + +See also [`isoperationtype(::Type{<:LazySet})`](@ref). +""" +function isoperation(::LazySet) end diff --git a/src/API/Unary/isoperationtype.jl b/src/API/Unary/isoperationtype.jl new file mode 100644 index 0000000000..a49528b6a8 --- /dev/null +++ b/src/API/Unary/isoperationtype.jl @@ -0,0 +1,18 @@ +""" + isoperationtype(T::Type{<:LazySet}) + +Check whether a set type is a (lazy) set operation. + +### Input + +- `T` -- set type + +### Output + +`true` iff the set type represents a set operation. + +### Notes + +See also [`isoperation(::LazySet)`](@ref). +""" +function isoperationtype(::Type{<:LazySet}) end diff --git a/src/API/Unary/isuniversal.jl b/src/API/Unary/isuniversal.jl new file mode 100644 index 0000000000..76293dd685 --- /dev/null +++ b/src/API/Unary/isuniversal.jl @@ -0,0 +1,18 @@ +""" + isuniversal(X::LazySet, witness::Bool=false) + +Check whether a set is universal. + +### Input + +- `X` -- set +- `witness` -- (optional, default: `false`) compute a witness if activated + +### Output + +* If the `witness` option is deactivated: `true` iff ``X = ℝ^n`` +* If the `witness` option is activated: + * `(true, [])` iff ``X = ℝ^n`` + * `(false, v)` iff ``X ≠ ℝ^n`` for some ``v ∉ X`` +""" +function isuniversal(::LazySet, ::Bool=false) end diff --git a/src/API/Unary/low.jl b/src/API/Unary/low.jl new file mode 100644 index 0000000000..1e2034fff7 --- /dev/null +++ b/src/API/Unary/low.jl @@ -0,0 +1,42 @@ +""" + low(X::LazySet, i::Int) + +Compute the lowest coordinate of a set in a given dimension. + +### Input + +- `X` -- set +- `i` -- dimension + +### Output + +A real number representing the lowest coordinate of the set in the given +dimension. + +### Notes + +The resulting value is the lower end of the projection. +""" +function low(::LazySet, ::Int) end + +""" + low(X::LazySet) + +Compute the lowest coordinates of a set in each dimension. + +### Input + +- `X` -- set + +### Output + +A vector with the lowest coordinate of the set in each dimension. + +### Notes + +See also `low(X::LazySet, i::Int)`. + +The result is the lowermost corner of the box approximation, so it is not +necessarily contained in `X`. +""" +function low(::LazySet) end diff --git a/src/API/Unary/norm.jl b/src/API/Unary/norm.jl new file mode 100644 index 0000000000..b7befc2761 --- /dev/null +++ b/src/API/Unary/norm.jl @@ -0,0 +1,20 @@ +""" + norm(X::LazySet, [p]::Real=Inf) + +Return the norm of a set. + +### Input + +- `X` -- set +- `p` -- (optional, default: `Inf`) norm + +### Output + +A real number representing the norm. + +### Notes + +The norm of a set is the norm of the enclosing ball (of the given ``p``-norm) of +minimal volume that is centered in the origin. +""" +function norm(::LazySet, ::Real=Inf) end diff --git a/src/API/Unary/radius.jl b/src/API/Unary/radius.jl new file mode 100644 index 0000000000..bf240c705c --- /dev/null +++ b/src/API/Unary/radius.jl @@ -0,0 +1,20 @@ +""" + radius(X::LazySet, [p]::Real=Inf) + +Return the radius of a set. + +### Input + +- `X` -- set +- `p` -- (optional, default: `Inf`) norm + +### Output + +A real number representing the radius. + +### Notes + +The radius of a set is the radius of the enclosing ball (of the given +``p``-norm) of minimal volume with the same center. +""" +function radius(::LazySet, ::Real=Inf) end diff --git a/src/API/Unary/rand.jl b/src/API/Unary/rand.jl new file mode 100644 index 0000000000..7aea83361d --- /dev/null +++ b/src/API/Unary/rand.jl @@ -0,0 +1,20 @@ +""" + rand(T::Type{<:LazySet}; [N]::Type{<:Real}=Float64, [dim]::Int=2, + [rng]::AbstractRNG=GLOBAL_RNG, [seed]::Union{Int, Nothing}=nothing + ) + +Create a random set of the given set type. + +### Input + +- `T` -- set type +- `N` -- (optional, default: `Float64`) numeric type +- `dim` -- (optional, default: 2) dimension +- `rng` -- (optional, default: `GLOBAL_RNG`) random number generator +- `seed` -- (optional, default: `nothing`) seed for reseeding + +### Output + +A random set of the given set type. +""" +function rand(::Type{<:LazySet}) end diff --git a/src/API/Unary/rectify.jl b/src/API/Unary/rectify.jl new file mode 100644 index 0000000000..0defd10d3b --- /dev/null +++ b/src/API/Unary/rectify.jl @@ -0,0 +1,14 @@ +""" + rectify(X::LazySet) + +Compute the rectification of a set. + +### Input + +- `X` -- set + +### Output + +A set representing the rectification of `X`. +""" +function rectify(::LazySet) end diff --git a/src/API/Unary/reflect.jl b/src/API/Unary/reflect.jl new file mode 100644 index 0000000000..d9b95fe6fe --- /dev/null +++ b/src/API/Unary/reflect.jl @@ -0,0 +1,14 @@ +""" + reflect(X::LazySet) + +Compute the reflection of a set in the origin. + +### Input + +- `X` -- set + +### Output + +A set representing the reflection ``-X``. +""" +function reflect(::LazySet) end diff --git a/src/API/Unary/surface.jl b/src/API/Unary/surface.jl new file mode 100644 index 0000000000..8882b89d0c --- /dev/null +++ b/src/API/Unary/surface.jl @@ -0,0 +1,14 @@ +""" + surface(X::LazySet) + +Compute the surface area of a set. + +### Input + +- `X` -- set + +### Output + +A real number representing the surface area of `X`. +""" +function surface(::LazySet) end diff --git a/src/API/Unary/vertices.jl b/src/API/Unary/vertices.jl new file mode 100644 index 0000000000..677e6d1250 --- /dev/null +++ b/src/API/Unary/vertices.jl @@ -0,0 +1,14 @@ +""" + vertices(X::LazySet) + +Construct an iterator over the vertices of a polytopic set. + +### Input + +- `X` -- polytopic set + +### Output + +An iterator over the vertices of `X`. +""" +function vertices(::LazySet) end diff --git a/src/API/Unary/vertices_list.jl b/src/API/Unary/vertices_list.jl new file mode 100644 index 0000000000..5e245e5c92 --- /dev/null +++ b/src/API/Unary/vertices_list.jl @@ -0,0 +1,14 @@ +""" + vertices_list(X::LazySet) + +Compute a list of vertices of a polytopic set. + +### Input + +- `X` -- polytopic set + +### Output + +A list of the vertices of `X`. +""" +function vertices_list(::LazySet) end diff --git a/src/API/Unary/volume.jl b/src/API/Unary/volume.jl new file mode 100644 index 0000000000..d912eaf56d --- /dev/null +++ b/src/API/Unary/volume.jl @@ -0,0 +1,14 @@ +""" + volume(X::LazySet) + +Compute the volume of a set. + +### Input + +- `X` -- set + +### Output + +A real number representing the volume of `X`. +""" +function volume(::LazySet) end diff --git a/src/Approximations/Approximations.jl b/src/Approximations/Approximations.jl index e4ddf255d4..facfba3b5f 100644 --- a/src/Approximations/Approximations.jl +++ b/src/Approximations/Approximations.jl @@ -5,20 +5,8 @@ Module `Approximations.jl` -- polygonal approximation of sets. """ module Approximations -using LazySets, ReachabilityBase.Arrays, Requires, LinearAlgebra, SparseArrays -import IntervalArithmetic as IA - -using ReachabilityBase.Comparison: _isapprox, _leq, _geq, _rtol, isapproxzero -using LazySets: default_lp_solver, _isbounded_stiemke, require, dim, linprog, - is_lp_optimal, _normal_Vector, default_sdp_solver, - get_exponential_backend, _expmv, second -using LazySets.JuMP: Model, set_silent, @variable, @constraint, optimize!, - value, @NLobjective, @objective - import Base: convert -import LazySets: project, □ - -using ..LazySets: @assert +import ..LazySets: dim, project, □ export approximate, ballinf_approximation, @@ -36,6 +24,16 @@ export approximate, CustomDirections, isbounding +using ..LazySets, ReachabilityBase.Arrays, Requires, LinearAlgebra, SparseArrays +import IntervalArithmetic as IA + +using ReachabilityBase.Comparison: _isapprox, _leq, _geq, _rtol, isapproxzero +using ..LazySets: default_lp_solver, _isbounded_stiemke, require, linprog, + is_lp_optimal, _normal_Vector, default_sdp_solver, + get_exponential_backend, _expmv, second, @assert +using ..LazySets.JuMP: Model, set_silent, @variable, @constraint, optimize!, + value, @NLobjective, @objective + include("box_approximation.jl") include("iterative_refinement.jl") include("symmetric_interval_hull.jl") diff --git a/src/Approximations/template_directions.jl b/src/Approximations/template_directions.jl index 08035fe522..80ff68d0e7 100644 --- a/src/Approximations/template_directions.jl +++ b/src/Approximations/template_directions.jl @@ -44,7 +44,7 @@ Returns the dimension of the generated directions. The ambient dimension of the generated directions. """ -function dim(ad::AbstractDirections) end +function LazySets.dim(::AbstractDirections) end """ isbounding(ad::AbstractDirections) @@ -76,7 +76,7 @@ The function can be applied to an instance of an `AbstractDirections` subtype or to the subtype itself. By default, the check on the instance falls back to the check on the subtype. """ -function isbounding(ad::Type{<:AbstractDirections}) +function isbounding(::Type{<:AbstractDirections}) return false end @@ -107,7 +107,7 @@ The function can be applied to an instance of an `AbstractDirections` subtype or to the subtype itself. By default, the check on the instance falls back to the check on the subtype. """ -function isnormalized(ad::Type{<:AbstractDirections}) +function isnormalized(::Type{<:AbstractDirections}) return false end @@ -135,11 +135,11 @@ Project a high-dimensional set to a given block using direction vectors. The polyhedral overapproximation of the projection of `S` in the given directions. """ -@inline function project(S::LazySet, - block::AbstractVector{Int}, - directions::Type{<:AbstractDirections}, - n::Int=dim(S); - kwargs...) +@inline function LazySets.project(S::LazySet, + block::AbstractVector{Int}, + directions::Type{<:AbstractDirections}, + n::Int=dim(S); + kwargs...) lm = project(S, block, LinearMap, n; kwargs...) return overapproximate(lm, directions(length(block))) end @@ -218,7 +218,7 @@ Base.eltype(::Type{BoxDirections{N,VN}}) where {N,VN} = VN Base.length(bd::BoxDirections) = 2 * bd.n # interface functions -dim(bd::BoxDirections) = bd.n +LazySets.dim(bd::BoxDirections) = bd.n isbounding(::Type{<:BoxDirections}) = true isnormalized(::Type{<:BoxDirections}) = true @@ -333,7 +333,7 @@ Base.eltype(::Type{OctDirections{N,VN}}) where {N,VN} = VN Base.length(od::OctDirections) = 2 * od.n^2 # interface functions -dim(od::OctDirections) = od.n +LazySets.dim(od::OctDirections) = od.n isbounding(::Type{<:OctDirections}) = true isnormalized(::Type{<:OctDirections}) = false @@ -473,7 +473,7 @@ Base.eltype(::Type{DiagDirections{N,VN}}) where {N,VN} = VN Base.length(dd::DiagDirections) = 2^dd.n # interface function -dim(dd::DiagDirections) = dd.n +LazySets.dim(dd::DiagDirections) = dd.n isbounding(::Type{<:DiagDirections}) = true isnormalized(::Type{<:DiagDirections}) = false @@ -572,7 +572,7 @@ Base.eltype(::Type{BoxDiagDirections{N,VN}}) where {N,VN} = VN Base.length(bdd::BoxDiagDirections) = bdd.n == 1 ? 2 : 2^bdd.n + 2 * bdd.n # interface function -dim(bdd::BoxDiagDirections) = bdd.n +LazySets.dim(bdd::BoxDiagDirections) = bdd.n isbounding(::Type{<:BoxDiagDirections}) = true isnormalized(::Type{<:BoxDiagDirections}) = false @@ -675,7 +675,7 @@ Base.eltype(::Type{PolarDirections{N,VN}}) where {N,VN} = VN Base.length(pd::PolarDirections) = pd.Nφ # interface functions -dim(pd::PolarDirections) = 2 +LazySets.dim(pd::PolarDirections) = 2 isbounding(pd::PolarDirections) = pd.Nφ > 2 isnormalized(::Type{<:PolarDirections}) = true @@ -790,7 +790,7 @@ Base.eltype(::Type{SphericalDirections{N,VN}}) where {N,VN} = VN Base.length(sd::SphericalDirections) = length(sd.stack) # interface functions -dim(::SphericalDirections) = 3 +LazySets.dim(::SphericalDirections) = 3 isbounding(sd::SphericalDirections) = sd.Nθ > 2 && sd.Nφ > 2 isnormalized(::Type{<:SphericalDirections}) = true @@ -887,7 +887,7 @@ Base.eltype(::Type{CustomDirections{N,VN}}) where {N,VN} = VN Base.length(cd::CustomDirections) = length(cd.directions) # interface functions -dim(cd::CustomDirections) = cd.n +LazySets.dim(cd::CustomDirections) = cd.n isbounding(cd::Type{<:CustomDirections}) = false # not a property of the type isbounding(cd::CustomDirections) = cd.bounded isnormalized(cd::Type{<:CustomDirections}) = false # not a property of the type diff --git a/src/ConcreteOperations/cartesian_product.jl b/src/ConcreteOperations/cartesian_product.jl index e266f4a59b..2d05e05a0b 100644 --- a/src/ConcreteOperations/cartesian_product.jl +++ b/src/ConcreteOperations/cartesian_product.jl @@ -1,5 +1,3 @@ -export cartesian_product - """ cartesian_product(X::LazySet, Y::LazySet; [backend]=nothing, [algorithm]::String="vrep") diff --git a/src/ConcreteOperations/convex_hull.jl b/src/ConcreteOperations/convex_hull.jl index 4cb06c0488..d37a49a31f 100644 --- a/src/ConcreteOperations/convex_hull.jl +++ b/src/ConcreteOperations/convex_hull.jl @@ -1,5 +1,3 @@ -export convex_hull - function default_convex_hull_algorithm(points) if length(points) != 0 && length(first(points)) == 2 return "monotone_chain" diff --git a/src/ConcreteOperations/difference.jl b/src/ConcreteOperations/difference.jl index cf4e862d5b..6e33bb6efa 100644 --- a/src/ConcreteOperations/difference.jl +++ b/src/ConcreteOperations/difference.jl @@ -1,35 +1,21 @@ -export difference - -# alias for set difference -import Base: \ - """ \\(X::LazySet, Y::LazySet) -Convenience alias for set difference. - -### Input - -- `X` -- first set -- `Y` -- second set - -### Output - -The set difference between `X` and `Y`. +Convenience alias for the `difference` function. ### Notes -If `X` and `Y` are intervals, `X \\ Y` is used in some libraries to denote -the left division, as the example below shows. However, it should not be -confused with the *set difference*. For example, +In this library, `X \\ Y` denotes the set difference. If `X` and `Y` are +intervals, in some libraries it denotes the left division, as the example below +shows. ```jldoctest julia> X = Interval(0, 2); Y = Interval(1, 4); -julia> X \\ Y # computing the set difference +julia> X \\ Y # compute the set difference Interval{Float64}([0, 1]) -julia> X.dat \\ Y.dat # computing the left division +julia> X.dat \\ Y.dat # underlying intervals compute the left division instead [0.5, ∞] ``` """ @@ -40,14 +26,6 @@ julia> X.dat \\ Y.dat # computing the left division Compute the set difference between two intervals. -The set difference is defined as: - -```math - X \\setminus Y = \\{x: x ∈ X \\text{ and } x ∉ Y \\} -``` - -The backslash symbol, `\\`, can be used as an alias. - ### Input - `X` -- first interval @@ -74,9 +52,9 @@ position, three different results may occur: contained in ``X``. To check for strict inclusion, we assume that the inclusion is strict and then -check if the resulting intervals that cover ``X`` (one to its left and one to -its right, let them be `L` and `R`), obtained by intersection with ``Y``, are -flat or not. Three cases may arise: +check whether the resulting intervals that cover ``X`` (one to its left and one +to its right, let them be `L` and `R`), obtained by intersection with ``Y``, are +flat. Three cases may arise: - If both `L` and `R` are flat then ``X = Y`` and the result is the empty set. - If only `L` is flat, then the result is `R`, the remaining interval not @@ -108,7 +86,7 @@ function difference(X::Interval{N}, Y::Interval) where {N} end """ - difference(X::AbstractHyperrectangle{N}, Y::AbstractHyperrectangle) where {N} + difference(X::AbstractHyperrectangle, Y::AbstractHyperrectangle) Compute the set difference between two hyperrectangular sets. @@ -132,7 +110,7 @@ union is in general not convex. This implementation uses `IntervalArithmetic.setdiff`. """ -function difference(X::AbstractHyperrectangle{N}, Y::AbstractHyperrectangle) where {N} +function difference(X::AbstractHyperrectangle, Y::AbstractHyperrectangle) Xib = convert(IA.IntervalBox, X) Yib = convert(IA.IntervalBox, Y) return UnionSetArray(convert.(Hyperrectangle, IA.setdiff(Xib, Yib))) diff --git a/src/ConcreteOperations/distance.jl b/src/ConcreteOperations/distance.jl index 6240a80871..4dd1bcff2f 100644 --- a/src/ConcreteOperations/distance.jl +++ b/src/ConcreteOperations/distance.jl @@ -1,5 +1,3 @@ -export distance - """ distance(H1::AbstractHyperrectangle, H2::AbstractHyperrectangle; [p]::Real=2) @@ -20,10 +18,6 @@ Compute the standard distance between two hyperrectangular sets, defined as The distance, which is zero if the sets intersect and otherwise the ``p``-norm of the shortest line segment between any pair of points. - -### Notes - -See also [`hausdorff_distance`](@ref) for an alternative distance notion. """ function distance(H1::AbstractHyperrectangle, H2::AbstractHyperrectangle; p::Real=2) diff --git a/src/ConcreteOperations/exact_sum.jl b/src/ConcreteOperations/exact_sum.jl index 50146f90f4..e3229f206e 100644 --- a/src/ConcreteOperations/exact_sum.jl +++ b/src/ConcreteOperations/exact_sum.jl @@ -1,5 +1,3 @@ -export exact_sum, ⊞ - """ exact_sum(P1::SparsePolynomialZonotope, P2::SparsePolynomialZonotope) @@ -36,14 +34,3 @@ function exact_sum(P1::SparsePolynomialZonotope, P2::SparsePolynomialZonotope) return SparsePolynomialZonotope(c, G, GI, E, idx) end - -""" - ⊞(X::LazySet, Y::LazySet) - -Unicode alias constructor for the (concrete) `exact_sum` function. - -### Notes - -Write `\\boxplus[TAB]` to enter this symbol. -""" -const ⊞ = exact_sum diff --git a/src/ConcreteOperations/intersection.jl b/src/ConcreteOperations/intersection.jl index a2a2f92e6f..e5c051e2ac 100644 --- a/src/ConcreteOperations/intersection.jl +++ b/src/ConcreteOperations/intersection.jl @@ -1,5 +1,3 @@ -export intersection - for T in [:LazySet, :AbstractSingleton, :Interval, :Universe, :LinearMap, :UnionSet, :UnionSetArray] @eval begin diff --git a/src/ConcreteOperations/isapprox.jl b/src/ConcreteOperations/isapprox.jl new file mode 100644 index 0000000000..145d8641c2 --- /dev/null +++ b/src/ConcreteOperations/isapprox.jl @@ -0,0 +1,33 @@ +""" +### Algorithm + +The default implementation recursively compares the fields of `X` and `Y` until +a mismatch is found. + +### Examples + +```jldoctest +julia> HalfSpace([1], 1) ≈ HalfSpace([1.0], 1.0) +true + +julia> HalfSpace([1], 1) ≈ HalfSpace([1.00000001], 0.99999999) +true + +julia> BallInf([0.0], 1.0) ≈ Hyperrectangle([0.0], [1.0]) +false +``` +""" +function ≈(X::LazySet, Y::LazySet) + # if the common supertype of X and Y is abstract, they cannot be compared + if isabstracttype(promote_type(typeof(X), typeof(Y))) + return false + end + + for f in fieldnames(typeof(X)) + if !_isapprox(getfield(X, f), getfield(Y, f)) + return false + end + end + + return true +end diff --git a/src/ConcreteOperations/isdisjoint.jl b/src/ConcreteOperations/isdisjoint.jl index 8c7e323150..d40d6ddafb 100644 --- a/src/ConcreteOperations/isdisjoint.jl +++ b/src/ConcreteOperations/isdisjoint.jl @@ -1,7 +1,3 @@ -import Base: isdisjoint - -export isdisjoint, is_intersection_empty - """ isdisjoint(X::LazySet, Y::LazySet, [witness]::Bool=false) @@ -44,9 +40,6 @@ function _isdisjoint_general(X::LazySet, Y::LazySet, witness::Bool=false) return witness ? (false, an_element(cap)) : false end -# alias -const is_intersection_empty = isdisjoint - # quick sufficient check that tries to find a separating hyperplane # the result `true` is also sufficient for non-convex sets function _isdisjoint_convex_sufficient(X::LazySet, Y::LazySet) diff --git a/src/ConcreteOperations/isequal.jl b/src/ConcreteOperations/isequal.jl new file mode 100644 index 0000000000..b2bca46600 --- /dev/null +++ b/src/ConcreteOperations/isequal.jl @@ -0,0 +1,33 @@ +""" +### Algorithm + +The default implementation recursively compares the fields of `X` and `Y` until +a mismatch is found. + +### Examples + +```jldoctest +julia> HalfSpace([1], 1) == HalfSpace([1.0], 1.0) +true + +julia> HalfSpace([1], 1) == HalfSpace([1.00000001], 0.99999999) +false + +julia> BallInf([0.0], 1.0) == Hyperrectangle([0.0], [1.0]) +false +``` +""" +function ==(X::LazySet, Y::LazySet) + # if the common supertype of X and Y is abstract, they cannot be compared + if isabstracttype(promote_type(typeof(X), typeof(Y))) + return false + end + + for f in fieldnames(typeof(X)) + if getfield(X, f) != getfield(Y, f) + return false + end + end + + return true +end diff --git a/src/ConcreteOperations/isequivalent.jl b/src/ConcreteOperations/isequivalent.jl new file mode 100644 index 0000000000..4af2e7e0c1 --- /dev/null +++ b/src/ConcreteOperations/isequivalent.jl @@ -0,0 +1,34 @@ +""" +### Algorithm + +The default implementation first checks `X ≈ Y`, which returns `true` if and +only if `X` and `Y` have the same base type and approximately the same values. +If that fails, the implementation checks the double inclusion `X ⊆ Y && Y ⊆ X`. + +### Examples + +```jldoctest +julia> X = BallInf([0.1, 0.2], 0.3); + +julia> Y = convert(HPolytope, X); + +julia> X == Y +false + +julia> isequivalent(X, Y) +true +``` +""" +function isequivalent(X::LazySet, Y::LazySet) + try # TODO temporary try-catch construct until ≈ is fixed for all set types + if X ≈ Y + return true + end + catch e + end + return _isequivalent_inclusion(X, Y) +end + +function _isequivalent_inclusion(X::LazySet, Y::LazySet) + return X ⊆ Y && Y ⊆ X +end diff --git a/src/ConcreteOperations/isstrictsubset.jl b/src/ConcreteOperations/isstrictsubset.jl index e694f12954..025f3592af 100644 --- a/src/ConcreteOperations/isstrictsubset.jl +++ b/src/ConcreteOperations/isstrictsubset.jl @@ -1,31 +1,12 @@ """ - ⊂(X::LazySet{N}, Y::LazySet, [witness]::Bool=false) where {N} - -Strict inclusion check of a set in another set. - -### Input - -- `X` -- first set -- `Y` -- second set -- `witness` -- (optional, default: `false`) compute a witness if activated - -### Output - -* If `witness` option is deactivated: `true` iff ``X ⊂ Y`` -* If `witness` option is activated: - * `(true, v)` iff ``X ⊂ Y`` and ``v ∈ Y \\setminus X`` - * `(false, [])` iff not ``X ⊂ Y`` - ### Algorithm -We check inclusion of `X` in `Y` and then check inclusion of `Y` in `X`: - -```math -X ⊂ Y \\Leftrightarrow X ⊆ Y \\land ¬ (Y ⊆ X) -``` +The default implementation first checks inclusion of `X` in `Y` and then checks +noninclusion of `Y` in `X`: """ -function ⊂(X::LazySet{N}, Y::LazySet, witness::Bool=false) where {N} +function ⊂(X::LazySet, Y::LazySet, witness::Bool=false) if witness + N = promote_type(eltype(X), eltype(Y)) res, w = ⊆(X, Y, witness) if res res, w = ⊆(Y, X, witness) diff --git a/src/ConcreteOperations/issubset.jl b/src/ConcreteOperations/issubset.jl index 13aac7ae88..401e1eb565 100644 --- a/src/ConcreteOperations/issubset.jl +++ b/src/ConcreteOperations/issubset.jl @@ -1,29 +1,3 @@ -import Base.issubset - -""" - issubset(X::LazySet, Y::LazySet, [witness]::Bool=false, args...) - -Alias for `⊆` (inclusion check). - -### Input - -- `X` -- set -- `Y` -- set -- `witness` -- (optional, default: `false`) compute a witness if activated - -### Output - -* If `witness` option is deactivated: `true` iff ``X ⊆ Y`` -* If `witness` option is activated: - * `(true, [])` iff ``X ⊆ Y`` - * `(false, v)` iff ``X ⊈ Y`` and ``v ∈ X \\setminus Y`` - -### Notes - -For more documentation see `⊆`. -""" -function issubset end - # this operation is invalid, but it is a common error, so we give a detailed # error message function ⊆(::AbstractVector, ::LazySet) @@ -41,38 +15,18 @@ end ⊆(X::IA.IntervalBox, Y::LazySet) = ⊆(convert(Hyperrectangle, X), Y) """ - ⊆(X::LazySet, P::LazySet, [witness]::Bool=false) - -Check whether a set is contained in a polyhedral set, and if not, optionally -compute a witness. - -### Input - -- `X` -- inner set -- `Y` -- outer polyhedral set -- `witness` -- (optional, default: `false`) compute a witness if activated - -### Output - -* If `witness` option is deactivated: `true` iff ``X ⊆ P`` -* If `witness` option is activated: - * `(true, [])` iff ``X ⊆ P`` - * `(false, v)` iff ``X ⊈ P`` and ``v ∈ X \\setminus P`` - -### Notes - -We require that `constraints_list(P)` is available. - ### Algorithm -We check inclusion of `X` in every constraint of `P`. +The default implementation assumes that `Y` is polyhedral, i.e., that +`constraints_list(Y)` is available, and checks inclusion of `X` in every +constraint of `Y`. """ -function ⊆(X::LazySet, P::LazySet, witness::Bool=false) - if is_polyhedral(P) - return _issubset_constraints_list(X, P, witness) +function ⊆(X::LazySet, Y::LazySet, witness::Bool=false) + if is_polyhedral(Y) + return _issubset_constraints_list(X, Y, witness) else - error("an inclusion check for the given combination of set types is " * - "not available") + throw(ArgumentError("an inclusion check for the given combination of " * + "set types is not available")) end end diff --git a/src/ConcreteOperations/linear_combination.jl b/src/ConcreteOperations/linear_combination.jl index 160423ca7f..762cb581cf 100644 --- a/src/ConcreteOperations/linear_combination.jl +++ b/src/ConcreteOperations/linear_combination.jl @@ -1,5 +1,3 @@ -export linear_combination - """ linear_combination(P1::SimpleSparsePolynomialZonotope, P2::SimpleSparsePolynomialZonotope) @@ -13,16 +11,11 @@ Compute the linear combination of two simple sparse polynomial zonotopes. ### Output -Linear combination of `P1` and `P2`. +A `SimpleSparsePolynomialZonotope` representing the linear combination of `P1` +and `P2`. ### Notes -The linear combination of two sets ``P₁`` and ``P₂`` is defined as - -```math -\\left\\{\\frac{1}{2}(1+λ)p₁ + \\frac{1}{2}(1-λ)p₂ \\mid p₁ ∈ P₁, p₂ ∈ P₂, λ ∈ [-1, 1]\\right\\}. -``` - This method implements the algorithm described in Proposition 3.1.25 of [1]. [1] N. Kochdumper. *Extensions of polynomial zonotopes and their application to diff --git a/src/ConcreteOperations/minkowski_difference.jl b/src/ConcreteOperations/minkowski_difference.jl index 07fda5d679..d93af38805 100644 --- a/src/ConcreteOperations/minkowski_difference.jl +++ b/src/ConcreteOperations/minkowski_difference.jl @@ -1,5 +1,3 @@ -export minkowski_difference, pontryagin_difference - """ minkowski_difference(P::LazySet, Q::LazySet) @@ -57,24 +55,6 @@ function minkowski_difference(P::LazySet, Q::LazySet) end end -""" - pontryagin_difference(X::LazySet, Y::LazySet) - -An alias for the function `minkowski_difference`. - -### Notes - -There is some inconsistency in the literature regarding the naming conventions. -In this library, both the names *Minkowski difference* and -*Pontryagin difference* refer to the geometric difference of two sets. -Mathematically: - -```math - X ⊖ Y = \\{z ∈ ℝ^n: z + v ∈ X ~∀~v ∈ Y\\} -``` -""" -const pontryagin_difference = minkowski_difference - for ST in [:LazySet, :AbstractZonotope, :AbstractHyperrectangle] # Minkowski difference with singleton is a translation @eval minkowski_difference(X::($ST), S::AbstractSingleton) = translate(X, -element(S)) diff --git a/src/ConcreteOperations/minkowski_sum.jl b/src/ConcreteOperations/minkowski_sum.jl index 41bb11a58d..95612a5e79 100644 --- a/src/ConcreteOperations/minkowski_sum.jl +++ b/src/ConcreteOperations/minkowski_sum.jl @@ -1,5 +1,3 @@ -export minkowski_sum - """ minkowski_sum(P::LazySet, Q::LazySet; [backend]=nothing, [algorithm]=nothing, [prune]=true) diff --git a/src/Interfaces/AbstractAffineMap.jl b/src/Interfaces/AbstractAffineMap.jl index 6b2b980abf..211c0ffaa8 100644 --- a/src/Interfaces/AbstractAffineMap.jl +++ b/src/Interfaces/AbstractAffineMap.jl @@ -1,5 +1,3 @@ -import Base: isempty, ∈ - export AbstractAffineMap, matrix, vector, set diff --git a/src/Interfaces/AbstractCentrallySymmetric.jl b/src/Interfaces/AbstractCentrallySymmetric.jl index 8dd04b6df9..ffecb2595f 100644 --- a/src/Interfaces/AbstractCentrallySymmetric.jl +++ b/src/Interfaces/AbstractCentrallySymmetric.jl @@ -1,8 +1,5 @@ -import Base.isempty - export AbstractCentrallySymmetric, - center, - an_element + center """ AbstractCentrallySymmetric{N} <: ConvexSet{N} diff --git a/src/Interfaces/AbstractCentrallySymmetricPolytope.jl b/src/Interfaces/AbstractCentrallySymmetricPolytope.jl index 2573907b64..0693f817e8 100644 --- a/src/Interfaces/AbstractCentrallySymmetricPolytope.jl +++ b/src/Interfaces/AbstractCentrallySymmetricPolytope.jl @@ -1,9 +1,5 @@ -import Base.isempty - export AbstractCentrallySymmetricPolytope, - center, - an_element, - vertices_list + center """ AbstractCentrallySymmetricPolytope{N} <: AbstractPolytope{N} diff --git a/src/Interfaces/AbstractHPolygon.jl b/src/Interfaces/AbstractHPolygon.jl index 0543d3594f..d1513cefee 100644 --- a/src/Interfaces/AbstractHPolygon.jl +++ b/src/Interfaces/AbstractHPolygon.jl @@ -1,14 +1,7 @@ -import Base: rand, - ∈ - export AbstractHPolygon, - an_element, isredundant, remove_redundant_constraints!, - addconstraint!, - vertices_list, - constraints_list, - isbounded + addconstraint! # This constant marks the threshold for the number of constraints of an # H-polygon above which we use a binary search to find the relevant constraint diff --git a/src/Interfaces/AbstractHyperrectangle.jl b/src/Interfaces/AbstractHyperrectangle.jl index f041ac41d8..62fef4ae2f 100644 --- a/src/Interfaces/AbstractHyperrectangle.jl +++ b/src/Interfaces/AbstractHyperrectangle.jl @@ -1,13 +1,9 @@ -import Base: ∈, split +import Base: split using Base: product export AbstractHyperrectangle, radius_hyperrectangle, - constraints_list, - low, high, isflat, - rectify, - volume, □ """ diff --git a/src/Interfaces/AbstractPolyhedron_functions.jl b/src/Interfaces/AbstractPolyhedron_functions.jl index ea228d2817..5d893a85cc 100644 --- a/src/Interfaces/AbstractPolyhedron_functions.jl +++ b/src/Interfaces/AbstractPolyhedron_functions.jl @@ -1,12 +1,7 @@ -import Base.∈ - export constrained_dimensions, tosimplehrep, remove_redundant_constraints, remove_redundant_constraints!, - linear_map, - an_element, - vertices_list, isfeasible isconvextype(::Type{<:AbstractPolyhedron}) = true diff --git a/src/Interfaces/AbstractPolytope.jl b/src/Interfaces/AbstractPolytope.jl index 99974b7837..1c8110f95e 100644 --- a/src/Interfaces/AbstractPolytope.jl +++ b/src/Interfaces/AbstractPolytope.jl @@ -1,9 +1,4 @@ -import Base.isempty - -export AbstractPolytope, - vertices_list, - isempty, - minkowski_sum +export AbstractPolytope """ AbstractPolytope{N} <: AbstractPolyhedron{N} diff --git a/src/Interfaces/AbstractSingleton.jl b/src/Interfaces/AbstractSingleton.jl index 2b2fefb14e..8bb9ccc68e 100644 --- a/src/Interfaces/AbstractSingleton.jl +++ b/src/Interfaces/AbstractSingleton.jl @@ -1,8 +1,5 @@ -import Base.∈ - export AbstractSingleton, - element, - an_element + element """ AbstractSingleton{N} <: AbstractHyperrectangle{N} diff --git a/src/Interfaces/AbstractZonotope.jl b/src/Interfaces/AbstractZonotope.jl index 1be97bd87c..c7400df5dd 100644 --- a/src/Interfaces/AbstractZonotope.jl +++ b/src/Interfaces/AbstractZonotope.jl @@ -1,12 +1,10 @@ -import Base: ∈, split +import Base: split export AbstractZonotope, genmat, generators, ngens, order, - translate, - translate!, togrep, split!, reduce_order diff --git a/src/Interfaces/LazySet.jl b/src/Interfaces/LazySet.jl index cc8496658b..3b8be2d206 100644 --- a/src/Interfaces/LazySet.jl +++ b/src/Interfaces/LazySet.jl @@ -1,45 +1,9 @@ -import Base: isempty, extrema, ==, ≈, copy, eltype, rationalize, ∈ -import Random.rand - export LazySet, - low, - high, basetype, - ρ, support_function, - σ, support_vector, - complement, - dim, - norm, - radius, - diameter, - an_element, - isbounded, - isboundedtype, neutral, absorbing, tosimplehrep, - isuniversal, - translate, - linear_map, - affine_map, - exponential_map, - reflect, - is_interior_point, - isempty, - isoperation, - isoperationtype, - isequivalent, - isconvextype, - is_polyhedral, - area, - surface, singleton_list, - concretize, - constraints, - vertices, - project, - rectify, - permute, chebyshev_center_radius, ○, flatten @@ -56,16 +20,16 @@ for using different numeric types. Every concrete `LazySet` must define the following method: -- `dim(S::LazySet)` -- the ambient dimension of `S` +- `dim(X::LazySet)` -- the ambient dimension of `X` While not strictly required, it is useful to define the following method: -- `σ(d::AbstractVector, S::LazySet)` -- the support vector of `S` in a given +- `σ(d::AbstractVector, X::LazySet)` -- the support vector of `X` in a given direction `d` The method -- `ρ(d::AbstractVector, S::LazySet)` -- the support function of `S` in a given +- `ρ(d::AbstractVector, X::LazySet)` -- the support function of `X` in a given direction `d` is optional because there is a fallback implementation relying on `σ`. @@ -181,42 +145,28 @@ A `Ellipsoid`s or `Ball2`s depending on the type of `a`. ### Notes -The function symbol can be typed via `\\bigcirc[TAB]`. +"`○`" can be typed by `\\bigcirc`. """ function ○(c, a) end """ - isconvextype(X::Type{<:LazySet}) - -Check whether the given `LazySet` type is convex. - -### Input - -- `X` -- subtype of `LazySet` - -### Output - -`true` if the given set type is guaranteed to be convex by using only type -information, and `false` otherwise. - -### Notes +### Algorithm -Since this operation only acts on types (not on values), it can return false -negatives, i.e., there may be instances where the set is convex, even though the -answer of this function is `false`. The examples below illustrate this point. +The default implementation returns `false`. All set types that can determine +convexity should override this behavior. ### Examples -A ball in the infinity norm is always convex, hence we get: +A ball in the infinity norm is always convex: ```jldoctest convex_types julia> isconvextype(BallInf) true ``` -For instance, the union (`UnionSet`) of two sets may in general be either convex -or not. Since convexity cannot be decided by just using type information, -`isconvextype` returns `false`. +The union (`UnionSet`) of two sets may in general be either convex or not. Since +convexity cannot be decided by just using type information, `isconvextype` +returns `false`. ```jldoctest convex_types julia> isconvextype(UnionSet) @@ -224,16 +174,16 @@ false ``` However, the type parameters of set operations allow to decide convexity in some -cases by falling back to the convexity information of the type of its arguments. -Consider for instance the lazy intersection. The intersection of two convex sets -is always convex, hence we get: +cases by falling back to the convexity information of the argument types. +Consider the lazy intersection. The intersection of two convex sets is always +convex: ```jldoctest convex_types julia> isconvextype(Intersection{Float64, BallInf{Float64}, BallInf{Float64}}) true ``` """ -isconvextype(X::Type{<:LazySet}) = false +isconvextype(::Type{<:LazySet}) = false # Polyhedra backend (fallback method) function default_polyhedra_backend(P::LazySet{N}) where {N} @@ -257,25 +207,9 @@ function _low(X::LazySet{N}, i::Int) where {N} end """ - low(X::LazySet) - -Return a vector with the lowest coordinates of the set in each canonical -direction. - -### Input - -- `X` -- set - -### Output - -A vector with the lower coordinate of the set in each dimension. - -### Notes - -See also `low(X::LazySet, i::Int)`. +### Algorithm -The result is the lowermost corner of the box approximation, so it is not -necessarily contained in `X`. +The default implementation applies `low` in each dimension. """ function low(X::LazySet) n = dim(X) @@ -294,25 +228,9 @@ function _high(X::LazySet{N}, i::Int) where {N} end """ - high(X::LazySet) - -Return a vector with the highest coordinate of the set in each canonical -direction. - -### Input - -- `X` -- set - -### Output - -A vector with the highest coordinate of the set in each dimension. - -### Notes - -See also `high(X::LazySet, i::Int)`. +### Algorithm -The result is the uppermost corner of the box approximation, so it is not -necessarily contained in `X`. +The default implementation applies `high` in each dimension. """ function high(X::LazySet) n = dim(X) @@ -320,27 +238,9 @@ function high(X::LazySet) end """ - extrema(X::LazySet, i::Int) - -Return the lower and higher coordinate of a set in a given dimension. - -### Input - -- `X` -- set -- `i` -- dimension of interest - -### Output - -The lower and higher coordinate of the set in the given dimension. - -### Notes - -The result is equivalent to `(low(X, i), high(X, i))`, but sometimes it can be -computed more efficiently. - ### Algorithm -The bounds are computed with `low` and `high`. +The default implementation computes the extrema via `low` and `high`. """ function extrema(X::LazySet, i::Int) l = low(X, i) @@ -349,32 +249,9 @@ function extrema(X::LazySet, i::Int) end """ - extrema(X::LazySet) - -Return two vectors with the lowest and highest coordinate of `X` in each -canonical direction. - -### Input - -- `X` -- set - -### Output - -Two vectors with the lowest and highest coordinates of `X` in each dimension. - -### Notes - -See also [`extrema(X::LazySet, i::Int)`](@ref). - -The result is equivalent to `(low(X), high(X))`, but sometimes it can be -computed more efficiently. - -The resulting points are the lowermost and uppermost corners of the box -approximation, so they are not necessarily contained in `X`. - ### Algorithm -The bounds are computed with `low` and `high` by default. +The default implementation computes the extrema via `low` and `high`. """ function extrema(X::LazySet) l = low(X) @@ -436,32 +313,16 @@ function _convex_hull_polytopes(X; kwargs...) end """ - eltype(::Type{<:LazySet{N}}) where {N} - -Return the numeric type (`N`) of the given set type. - -### Input - -- `T` -- set type - -### Output +### Algorithm -The numeric type of `T`. +The default implementation assumes that the first type parameter is `N`. """ eltype(::Type{<:LazySet{N}}) where {N} = N """ - eltype(::LazySet{N}) where {N} - -Return the numeric type (`N`) of the given set. - -### Input - -- `X` -- set - -### Output +### Algorithm -The numeric type of `X`. +The default implementation assumes that the first type parameter is `N`. """ eltype(::LazySet{N}) where {N} = N @@ -481,17 +342,17 @@ The base type of `T`. basetype(T::Type{<:LazySet}) = Base.typename(T).wrapper """ - basetype(S::LazySet) + basetype(X::LazySet) Return the base type of the given set (i.e., without type parameters). ### Input -- `S` -- set +- `X` -- set ### Output -The base type of `S`. +The base type of `X`. ### Examples @@ -508,80 +369,41 @@ julia> basetype(LinearMap(rand(2, 2), Z + Z)) LinearMap ``` """ -basetype(S::LazySet) = basetype(typeof(S)) +basetype(X::LazySet) = basetype(typeof(X)) """ - ρ(d::AbstractVector, S::LazySet) - -Evaluate the support function of a set in a given direction. - -### Input - -- `d` -- direction -- `S` -- set - -### Output +### Algorithm -The evaluation of the support function of the set `S` for the direction `d`. +The default implementation computes a support vector via `σ`. """ -function ρ(d::AbstractVector, S::LazySet) - return dot(d, σ(d, S)) +function ρ(d::AbstractVector, X::LazySet) + return dot(d, σ(d, X)) end """ - support_function - -Alias for the support function ρ. -""" -const support_function = ρ - -""" - σ - -Function to compute the support vector σ. -""" -function σ end - -""" - support_vector - -Alias for the support vector σ. -""" -const support_vector = σ - -""" - isboundedtype(T::Type{<:LazySet}) - -Check whether a set type only represents bounded sets. - -### Input - -- `T` -- set type - -### Output +### Notes -`true` if the set type only represents bounded sets. Note that some sets may still represent an unbounded set even though their type actually does not (example: [`HPolytope`](@ref), because the construction with non-bounding linear constraints is allowed). -### Notes +### Algorithm -By default this function returns `false`. -All set types that can determine boundedness should override this behavior. +The default implementation returns `false`. All set types that can determine +boundedness should override this behavior. """ -function isboundedtype(T::Type{<:LazySet}) +function isboundedtype(::Type{<:LazySet}) return false end """ - isbounded(S::LazySet) + isbounded(X::LazySet; [algorithm]="support_function") Check whether a set is bounded. ### Input -- `S` -- set +- `X` -- set - `algorithm` -- (optional, default: `"support_function"`) algorithm choice, possible options are `"support_function"` and `"stiemke"` @@ -594,24 +416,24 @@ Check whether a set is bounded. See the documentation of `_isbounded_unit_dimensions` or `_isbounded_stiemke` for details. """ -function isbounded(S::LazySet; algorithm="support_function") +function isbounded(X::LazySet; algorithm="support_function") if algorithm == "support_function" - return _isbounded_unit_dimensions(S) + return _isbounded_unit_dimensions(X) elseif algorithm == "stiemke" - return _isbounded_stiemke(constraints_list(S)) + return _isbounded_stiemke(constraints_list(X)) else throw(ArgumentError("unknown algorithm $algorithm")) end end """ - _isbounded_unit_dimensions(S::LazySet) + _isbounded_unit_dimensions(X::LazySet) Check whether a set is bounded in each unit dimension. ### Input -- `S` -- set +- `X` -- set ### Output @@ -621,9 +443,9 @@ Check whether a set is bounded in each unit dimension. This function asks for upper and lower bounds in each ambient dimension. """ -function _isbounded_unit_dimensions(S::LazySet) - @inbounds for i in 1:dim(S) - if isinf(low(S, i)) || isinf(high(S, i)) +function _isbounded_unit_dimensions(X::LazySet) + @inbounds for i in 1:dim(X) + if isinf(low(X, i)) || isinf(high(X, i)) return false end end @@ -631,277 +453,99 @@ function _isbounded_unit_dimensions(S::LazySet) end """ - is_polyhedral(S::LazySet) - -Trait for polyhedral sets. - -### Input - -- `S` -- set - -### Output - -`true` only if the set behaves like an [`AbstractPolyhedron`](@ref). - -### Notes +### Algorithm -The answer is conservative, i.e., may sometimes be `false` even if the set is -polyhedral. +The default implementation returns `false`. All set types that can determine the +polyhedral property should override this behavior. """ -function is_polyhedral(S::LazySet) +function is_polyhedral(::LazySet) return false end """ - norm(S::LazySet, [p]::Real=Inf) - -Return the norm of a 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` -- set -- `p` -- (optional, default: `Inf`) norm - -### Output +### Algorithm -A real number representing the norm. +The default implementation handles the case `p == Inf` using `extrema`. +Otherwise it checks whether `X` is polytopic, in which case it iterates over all +vertices. """ -function norm(S::LazySet, p::Real=Inf) +function norm(X::LazySet, p::Real=Inf) if p == Inf - l, h = extrema(S) + l, h = extrema(X) return max(maximum(abs, l), maximum(abs, h)) - elseif is_polyhedral(S) && isboundedtype(typeof(S)) - return maximum(norm(v, p) for v in vertices_list(S)) + elseif is_polyhedral(X) && isboundedtype(typeof(X)) + return maximum(norm(v, p) for v in vertices_list(X)) else error("the norm for this value of p=$p is not implemented") end end """ - radius(S::LazySet, [p]::Real=Inf) - -Return the radius of a set. -It is the radius of the enclosing ball (of the given ``p``-norm) of minimal -volume with the same center. - -### Input - -- `S` -- set -- `p` -- (optional, default: `Inf`) norm - -### Output +### Algorithm -A real number representing the radius. +The default implementation handles the case `p == Inf` using +`ballinf_approximation`. """ -function radius(S::LazySet, p::Real=Inf) +function radius(X::LazySet, p::Real=Inf) if p == Inf - return radius(Approximations.ballinf_approximation(S), p) + return radius(Approximations.ballinf_approximation(X), p) else error("the radius for this value of p=$p is not implemented") end end """ - diameter(S::LazySet, [p]::Real=Inf) - -Return the diameter of a 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` -- set -- `p` -- (optional, default: `Inf`) norm - -### Output - -A real number representing the diameter. -""" -function diameter(S::LazySet, p::Real=Inf) - return radius(S, p) * 2 -end - -""" - affine_map(M, X::LazySet, v::AbstractVector; kwargs...) - -Compute the concrete affine map ``M·X + v``. - -### Input - -- `M` -- linear map -- `X` -- set -- `v` -- translation vector - -### Output - -A set representing the affine map ``M·X + v``. - ### Algorithm -The implementation applies the functions `linear_map` and `translate`. +The default implementation applies the function `radius` and doubles the result. """ -function affine_map(M, X::LazySet, v::AbstractVector; kwargs...) - return translate(linear_map(M, X; kwargs...), v) +function diameter(X::LazySet, p::Real=Inf) + return radius(X, p) * 2 end """ - exponential_map(M::AbstractMatrix, X::LazySet) - -Compute the concrete exponential map of `M` and `X`, i.e., `exp(M) * X`. - -### Input - -- `M` -- matrix -- `X` -- set - -### Output - -A set representing the exponential map of `M` and `X`. - ### Algorithm -The implementation applies the functions `exp` and `linear_map`. +The default implementation calls `translate!` on a copy of `X`. """ -function exponential_map(M::AbstractMatrix, X::LazySet) - return linear_map(exp(M), X) +function translate(X::LazySet, v::AbstractVector) + Y = copy(X) + translate!(Y, v) + return Y end """ - an_element(S::LazySet) - -Return some element of a set. - -### Input - -- `S` -- set - -### Output - -An element of a set. - ### Algorithm -An element of the set is obtained by evaluating its support vector along -direction ``[1, 0, …, 0]``. -This may fail for unbounded sets. +The default implementation applies the functions `linear_map` and `translate`. """ -function an_element(S::LazySet) - return _an_element_lazySet(S) -end - -function _an_element_lazySet(S::LazySet) - N = eltype(S) - e₁ = SingleEntryVector(1, dim(S), one(N)) - return σ(e₁, S) +function affine_map(M, X::LazySet, v::AbstractVector; kwargs...) + return translate(linear_map(M, X; kwargs...), v) end """ - ==(X::LazySet, Y::LazySet) - -Check whether two sets use exactly the same set representation. - -### Input - -- `X` -- set -- `Y` -- set - -### Output - -- `true` iff `X` is equal to `Y`. - -### Notes - -The check is purely syntactic and the sets need to have the same base type. -For instance, `X::VPolytope == Y::HPolytope` returns `false` even if `X` and `Y` -represent the same polytope. -However `X::HPolytope{Int64} == Y::HPolytope{Float64}` is a valid comparison. - ### Algorithm -We recursively compare the fields of `X` and `Y` until a mismatch is found. - -### Examples - -```jldoctest -julia> HalfSpace([1], 1) == HalfSpace([1], 1) -true - -julia> HalfSpace([1], 1) == HalfSpace([1.0], 1.0) -true - -julia> Ball1([0.0], 1.0) == Ball2([0.0], 1.0) -false -``` +The default implementation applies the functions `exp` and `linear_map`. """ -function ==(X::LazySet, Y::LazySet) - # if the common supertype of X and Y is abstract, they cannot be compared - if isabstracttype(promote_type(typeof(X), typeof(Y))) - return false - end - - for f in fieldnames(typeof(X)) - if getfield(X, f) != getfield(Y, f) - return false - end - end - - return true +function exponential_map(M::AbstractMatrix, X::LazySet) + return linear_map(exp(M), X) end """ - ≈(X::LazySet, Y::LazySet) - -Check whether two sets of the same type are approximately equal. - -### Input - -- `X` -- set -- `Y` -- set of the same base type as `X` - -### Output - -- `true` iff `X` is equal to `Y`. - -### Notes - -The check is purely syntactic and the sets need to have the same base type. -For instance, `X::VPolytope ≈ Y::HPolytope` returns `false` even if `X` and `Y` -represent the same polytope. -However `X::HPolytope{Int64} ≈ Y::HPolytope{Float64}` is a valid comparison. - ### Algorithm -We recursively compare the fields of `X` and `Y` until a mismatch is found. - -### Examples - -```jldoctest -julia> HalfSpace([1], 1) ≈ HalfSpace([1], 1) -true - -julia> HalfSpace([1], 1) ≈ HalfSpace([1.00000001], 0.99999999) -true - -julia> Ball1([0.0], 1.0) ≈ Ball2([0.0], 1.0) -false -``` +The default implementation computes a support vector along direction +``[1, 0, …, 0]``. This may fail for unbounded sets. """ -function ≈(X::LazySet, Y::LazySet) - # if the common supertype of X and Y is abstract, they cannot be compared - if isabstracttype(promote_type(typeof(X), typeof(Y))) - return false - end - - for f in fieldnames(typeof(X)) - if !_isapprox(getfield(X, f), getfield(Y, f)) - return false - end - end +function an_element(X::LazySet) + return _an_element_lazySet(X) +end - return true +function _an_element_lazySet(X::LazySet) + N = eltype(X) + e₁ = SingleEntryVector(1, dim(X), one(N)) + return σ(e₁, X) end # hook into random API @@ -909,27 +553,11 @@ function rand(rng::AbstractRNG, ::SamplerType{T}) where {T<:LazySet} return rand(T; rng=rng) end -""" - copy(S::LazySet) - -Return a copy of a set by copying its values recursively. - -### Input - -- `S` -- set - -### Output - -A copy of `S`. - -### Notes - -This function computes a `copy` of each field in `S`. -See the documentation of `?copy` for further details. -""" -function copy(S::T) where {T<:LazySet} - args = [copy(getfield(S, f)) for f in fieldnames(T)] - BT = basetype(S) +# This function computes a `copy` of each field in `X`. See the documentation of +# `?copy` for further details. +function copy(X::T) where {T<:LazySet} + args = [copy(getfield(X, f)) for f in fieldnames(T)] + BT = basetype(X) return BT(args...) end @@ -975,7 +603,7 @@ available, i.e., that it can be written as ``P = \\{z ∈ ℝⁿ: ⋂ sᵢᵀz ≤ rᵢ, i = 1, ..., N\\}.`` This function can be used to implement the alternative definition of the -Minkowski Difference +Minkowski difference ```math A ⊖ B = \\{a − b \\mid a ∈ A, b ∈ B\\} = A ⊕ (-B) ``` @@ -993,34 +621,17 @@ function reflect(P::LazySet) end """ - is_interior_point(d::AbstractVector{N}, X::LazySet{N}; - p=N(Inf), ε=_rtol(N)) where {N} - -Check whether the point `d` is contained in the interior of the set `X`. - -### Input - -- `d` -- point -- `X` -- set -- `p` -- (optional; default: `N(Inf)`) norm of the ball used to apply the error - tolerance -- `ε` -- (optional; default: `_rtol(N)`) error tolerance of check - -### Output - -Boolean which indicates if the point `d` is contained in `X`. - ### Algorithm -The implementation checks if a `Ballp` of norm `p` with center `d` and radius -`ε` is contained in the set `X`. -This is a numerical check for `d ∈ interior(X)` with error tolerance `ε`. +The default implementation determines `v ∈ interior(X)` with error tolerance +`ε` by checking whether a `Ballp` of norm `p` with center `v` and radius `ε` is +contained in `X`. """ -function is_interior_point(d::AbstractVector{N}, X::LazySet{N}; - p=N(Inf), ε=_rtol(N)) where {N} - return Ballp(p, d, ε) ⊆ X +function is_interior_point(v::AbstractVector{N}, X::LazySet{N}; p=N(Inf), ε=_rtol(N)) where {N} + return Ballp(p, v, ε) ⊆ X end + """ plot_recipe(X::LazySet, [ε]) @@ -1058,7 +669,7 @@ function plot_recipe(X::LazySet, ε) @assert isconvextype(typeof(X)) "can only plot convex sets" if dim(X) == 1 - Y = convert(Interval, X) + Y = convert(LazySets.Interval, X) elseif dim(X) == 2 Y = overapproximate(X, ε) else @@ -1104,21 +715,9 @@ function _plot_recipe_3d_polytope(P::LazySet, N=eltype(P)) end """ - isoperation(X::LazySet) - -Check whether a set is an instance of a set operation or not. - -### Input - -- `X` -- set - -### Output - -`true` if `X` is an instance of a set-based operation and `false` otherwise. - -### Notes +### Algorithm -This fallback implementation checks whether the set type of the input is an +The default implementation checks whether the set type of the input is an operation type using [`isoperationtype(::Type{<:LazySet})`](@ref). ### Examples @@ -1139,117 +738,27 @@ end # common error function isoperation(::Type{<:LazySet}) - return error("`isoperation` cannot be applied to a " * - "set type; use `isoperationtype` instead") -end - -""" - isoperationtype(X::Type{<:LazySet}) - -Check whether the given set type is an operation or not. - -### Input - -- `X` -- set type - -### Output - -`true` if the given set type is a set operation and `false` otherwise. - -### Notes - -This fallback implementation returns an error that `isoperationtype` is not -implemented. Subtypes of `LazySet` should dispatch on this function as required. - -See also [`isoperation(X<:LazySet)`](@ref). - -### Examples - -```jldoctest -julia> isoperationtype(BallInf) -false - -julia> isoperationtype(LinearMap) -true -``` -""" -function isoperationtype(X::Type{<:LazySet}) - return error("`isoperationtype` is not implemented for type $X") + throw(ArgumentError("`isoperation` cannot be applied to a set type; use " * + "`isoperationtype` instead")) end # common error function isoperationtype(::LazySet) - return error("`isoperationtype` cannot be applied to a " * - "set instance; use `isoperation` instead") -end - -""" - isequivalent(X::LazySet, Y::LazySet) - -Check whether two sets are equal in the mathematical sense, i.e., equivalent. - -### Input - -- `X` -- set -- `Y` -- set - -### Output - -`true` iff `X` is equivalent to `Y` (up to some precision). - -## Algorithm - -First we check `X ≈ Y`, which returns `true` if and only if `X` and `Y` have the -same type and approximately the same values (checked with `LazySets._isapprox`). -If that fails, we check the double inclusion `X ⊆ Y && Y ⊆ X`. - -### Examples - -```jldoctest -julia> X = BallInf([0.1, 0.2], 0.3); - -julia> Y = convert(HPolytope, X); - -julia> X == Y -false - -julia> isequivalent(X, Y) -true -``` -""" -function isequivalent(X::LazySet, Y::LazySet) - try # TODO temporary try-catch construct until ≈ is fixed for all set types - if X ≈ Y - return true - end - catch e - end - return _isequivalent_inclusion(X, Y) -end - -function _isequivalent_inclusion(X::LazySet, Y::LazySet) - return X ⊆ Y && Y ⊆ X + throw(ArgumentError("`isoperationtype` cannot be applied to a set " * + "instance; use `isoperation` instead")) end """ - surface(X::LazySet) - -Compute the surface area of a set. - -### Input - -- `X` -- set - -### Output +### Algorithm -A real number representing the surface area of `X`. +The default implementation applies `area` for two-dimensional sets. """ function surface(X::LazySet) if dim(X) == 2 return area(X) else - throw(ArgumentError("the surface function is only implemented for " * - "two-dimensional sets, but the given set is $(dim(X))-dimensional")) + throw(ArgumentError("the `surface` function is only implemented for two-dimensional" * + "sets, but the given set is $(dim(X))-dimensional")) end end @@ -1371,65 +880,38 @@ function singleton_list(P::LazySet) end """ - concretize(X::LazySet) - -Construct a concrete representation of a (possibly lazy) set. - -### Input - -- `X` -- set - -### Output - -A concrete representation of `X` (as far as possible). - -### Notes +### Algorithm -Since not every lazy set has a concrete set representation in this library, the -result may be partially lazy. +The default implementation returns `X`. All relevant lazy set types should +override this behavior, typically by recursively calling `concretize` on the +set arguments. """ function concretize(X::LazySet) return X end """ - constraints(X::LazySet) - -Construct an iterator over the constraints of a polyhedral set. - -### Input - -- `X` -- polyhedral set - -### Output +### Algorithm -An iterator over the constraints of `X`. +The default implementation computes all constraints via `constraints_list`. """ function constraints(X::LazySet) return _constraints_fallback(X) end -""" - vertices(X::LazySet) - -Construct an iterator over the vertices of a polytopic set. - -### Input - -- `X` -- polytopic set +function _constraints_fallback(X::LazySet) + return VectorIterator(constraints_list(X)) +end -### Output +""" +### Algorithm -An iterator over the vertices of `X`. +The default implementation computes all vertices via `vertices_list`. """ function vertices(X::LazySet) return _vertices_fallback(X) end -function _constraints_fallback(X::LazySet) - return VectorIterator(constraints_list(X)) -end - function _vertices_fallback(X::LazySet) return VectorIterator(vertices_list(X)) end @@ -1495,113 +977,100 @@ function load_delaunay_MiniQhull() end # load_delaunay_MiniQhull """ - complement(X::LazySet) - -Return the complement of a polyhedral set. - -### Input - -- `X` -- polyhedral set - -### Output - -A `UnionSetArray` of half-spaces, i.e., the output is the union of the linear -constraints which are obtained by complementing each constraint of `X`. - ### Algorithm -The principle used in this implementation is that for any pair of sets -``(X, Y)`` we have that ``(X ∩ Y)^C = X^C ∪ Y^C``. In particular, we can apply -this rule for each constraint that defines a polyhedral set. Hence the concrete -complement can be represented as the set union of the complement of each -constraint. +The default implementation assumes that `X` is polyhedral and returns a +`UnionSetArray` of `HalfSpace`s, i.e., the output is the union of the linear +constraints which are obtained by complementing each constraint of `X`. For any +pair of sets ``(X, Y)`` we have the identity ``(X ∩ Y)^C = X^C ∪ Y^C``. We can +apply this identity for each constraint that defines a polyhedral set. """ function complement(X::LazySet) return UnionSetArray(constraints_list(Complement(X))) end """ - project(S::LazySet, block::AbstractVector{Int}, [::Nothing=nothing], - [n]::Int=dim(S); [kwargs...]) + project(X::LazySet, block::AbstractVector{Int}, [::Nothing=nothing], + [n]::Int=dim(X); [kwargs...]) Project a set to a given block by using a concrete linear map. ### Input -- `S` -- set +- `X` -- set - `block` -- block structure - a vector with the dimensions of interest -- `nothing` -- (default: `nothing`) -- `n` -- (optional, default: `dim(S)`) ambient dimension of the set `S` +- `nothing` -- (default: `nothing`) needed for dispatch +- `n` -- (optional, default: `dim(X)`) ambient dimension of the set `X` ### Output -A set representing the projection of the set `S` to block `block`. +A set representing the projection of `X` to block `block`. ### Algorithm We apply the function `linear_map`. """ -@inline function project(S::LazySet, block::AbstractVector{Int}, - ::Nothing=nothing, n::Int=dim(S); kwargs...) - return _project_linear_map(S, block, n; kwargs...) +@inline function project(X::LazySet, block::AbstractVector{Int}, + ::Nothing=nothing, n::Int=dim(X); kwargs...) + return _project_linear_map(X, block, n; kwargs...) end -@inline function _project_linear_map(S::LazySet{N}, block::AbstractVector{Int}, - n::Int=dim(S); kwargs...) where {N} +@inline function _project_linear_map(X::LazySet{N}, block::AbstractVector{Int}, + n::Int=dim(X); kwargs...) where {N} M = projection_matrix(block, n, N) - return linear_map(M, S) + return linear_map(M, X) end """ - project(S::LazySet, block::AbstractVector{Int}, set_type::Type{TS}, - [n]::Int=dim(S); [kwargs...]) where {TS<:LazySet} + project(X::LazySet, block::AbstractVector{Int}, set_type::Type{T}, + [n]::Int=dim(X); [kwargs...]) where {T<:LazySet} Project a set to a given block and set type, possibly involving an overapproximation. ### Input -- `S` -- set +- `X` -- set - `block` -- block structure - a vector with the dimensions of interest - `set_type` -- target set type -- `n` -- (optional, default: `dim(S)`) ambient dimension of the set `S` +- `n` -- (optional, default: `dim(X)`) ambient dimension of the set `X` ### Output A set of type `set_type` representing an overapproximation of the projection of -`S`. +`X`. ### Algorithm -1. Project the set `S` with `M⋅S`, where `M` is the identity matrix in the block +1. Project the set `X` with `M⋅X`, where `M` is the identity matrix in the block coordinates and zero otherwise. 2. Overapproximate the projected set using `overapproximate` and `set_type`. """ -@inline function project(S::LazySet, block::AbstractVector{Int}, - set_type::Type{TS}, n::Int=dim(S); - kwargs...) where {TS<:LazySet} - lm = project(S, block, LinearMap, n) +@inline function project(X::LazySet, block::AbstractVector{Int}, + set_type::Type{T}, n::Int=dim(X); + kwargs...) where {T<:LazySet} + lm = project(X, block, LinearMap, n) return overapproximate(lm, set_type) end """ - project(S::LazySet, block::AbstractVector{Int}, - set_type_and_precision::Pair{T, N}, [n]::Int=dim(S); + project(X::LazySet, block::AbstractVector{Int}, + set_type_and_precision::Pair{T, N}, [n]::Int=dim(X); [kwargs...]) where {T<:UnionAll, N<:Real} Project a set to a given block and set type with a certified error bound. ### Input -- `S` -- set +- `X` -- set - `block` -- block structure - a vector with the dimensions of interest - `set_type_and_precision` -- pair `(T, ε)` of a target set type `T` and an error bound `ε` for approximation -- `n` -- (optional, default: `dim(S)`) ambient dimension of the set `S` +- `n` -- (optional, default: `dim(X)`) ambient dimension of the set `X` ### Output -A set representing the epsilon-close approximation of the projection of `S`. +A set representing the epsilon-close approximation of the projection of `X`. ### Notes @@ -1610,100 +1079,87 @@ must be two-dimensional. ### Algorithm -1. Project the set `S` with `M⋅S`, where `M` is the identity matrix in the block +1. Project the set `X` with `M⋅X`, where `M` is the identity matrix in the block coordinates and zero otherwise. 2. Overapproximate the projected set with the given error bound `ε`. """ -@inline function project(S::LazySet, block::AbstractVector{Int}, - set_type_and_precision::Pair{T,N}, n::Int=dim(S); +@inline function project(X::LazySet, block::AbstractVector{Int}, + set_type_and_precision::Pair{T,N}, n::Int=dim(X); kwargs...) where {T<:UnionAll,N<:Real} set_type, ε = set_type_and_precision - @assert length(block) == 2 && set_type == HPolygon "currently only 2D " * - "HPolygon projection is supported" + @assert length(block) == 2 && set_type == HPolygon "currently only 2D HPolygon " * + "projection is supported" - lm = project(S, block, LinearMap, n) + lm = project(X, block, LinearMap, n) return overapproximate(lm, set_type, ε) end """ - project(S::LazySet, block::AbstractVector{Int}, ε::Real, [n]::Int=dim(S); + project(X::LazySet, block::AbstractVector{Int}, ε::Real, [n]::Int=dim(X); [kwargs...]) -Project a set to a given block and set type with a certified error bound. +Project a set to a given block and set type with an error bound. ### Input -- `S` -- set +- `X` -- set - `block` -- block structure - a vector with the dimensions of interest - `ε` -- error bound for approximation -- `n` -- (optional, default: `dim(S)`) ambient dimension of the set `S` +- `n` -- (optional, default: `dim(X)`) ambient dimension of the set `X` ### Output -A set representing the epsilon-close approximation of the projection of `S`. +A set representing the epsilon-close approximation of the projection of `X`. ### Algorithm -1. Project the set `S` with `M⋅S`, where `M` is the identity matrix in the block +1. Project the set `X` with `M⋅X`, where `M` is the identity matrix in the block coordinates and zero otherwise. 2. Overapproximate the projected set with the given error bound `ε`. The target set type is chosen automatically. """ -@inline function project(S::LazySet, block::AbstractVector{Int}, ε::Real, - n::Int=dim(S); kwargs...) +@inline function project(X::LazySet, block::AbstractVector{Int}, ε::Real, + n::Int=dim(X); kwargs...) # currently we only support HPolygon if length(block) == 2 set_type = HPolygon else - throw(ArgumentError("ε-close approximation is only supported for 2D " * - "blocks")) + throw(ArgumentError("ε-close approximation is only supported for 2D blocks")) end - return project(S, block, set_type => ε, n) + return project(X, block, set_type => ε, n) end """ - rectify(X::LazySet, [concrete_intersection]::Bool=false) - -Concrete rectification of a set. - -### Input - -- `X` -- set -- `concrete_intersection` -- (optional, default: `false`) flag to compute - concrete intersections for intermediate results - -### Output - -A set corresponding to the rectification of `X`, which is in general a union of -linear maps of intersections. - ### Algorithm For each dimension in which `X` is both positive and negative, we split `X` into -these two parts. Additionally we project the negative part to zero. +these two parts and then project the negative part to zero. """ function rectify(X::LazySet, concrete_intersection::Bool=false) return to_union_of_projections(Rectification(X), concrete_intersection) end """ - rationalize(::Type{T}, X::LazySet{<:AbstractFloat}, tol::Real) - where {T<:Integer} + rationalize(::Type{T}, X::LazySet, tol::Real) where {T<:Integer} -Approximate a set of floating-point numbers as a set whose entries are rationals -of the given integer type. +Approximate a set represented with floating-point numbers as a set represented +with rationals of the given integer type. ### Input - `T` -- (optional, default: `Int`) integer type to represent the rationals -- `X` -- set which has floating-point components +- `X` -- set represented by floating-point components - `tol` -- (optional, default: `eps(N)`) tolerance of the result; each rationalized component will differ by no more than `tol` with respect to the floating-point value ### Output -A set of the same base type of `X` where each numerical component is of -type `Rational{T}`. +A set of the same base type as `X` where each numerical component is of type +`Rational{T}`. + +### Algorithm + +The default implementation rationalizes each field. """ function rationalize(::Type{T}, X::LazySet{<:AbstractFloat}, tol::Real) where {T<:Integer} m = length(fieldnames(typeof(X))) @@ -1726,23 +1182,6 @@ function rationalize(::Type{T}, X::AbstractVector{<:LazySet{<:AbstractFloat}}, return rationalize.(Ref(T), X, Ref(tol)) end -""" - permute(X::LazySet, p::AbstractVector{Int}) - -Permute the dimensions of a set according to a given permutation vector. - -### Input - -- `X` -- set -- `p` -- permutation vector - -### Output - -A new set corresponding to `X` where the dimensions have been permuted according -to `p`. -""" -function permute end - """ chebyshev_center_radius(P::LazySet{N}; [backend]=default_polyhedra_backend(P), @@ -1892,7 +1331,7 @@ Check whether a polyhedral set is empty. ### Notes The default value of the `backend` is set internally and depends on whether the -`use_polyhedra_interface` option is set or not. +`use_polyhedra_interface` option is set. If the option is set, we use `default_polyhedra_backend(P)`. Witness production is not supported if `use_polyhedra_interface` is `true`. @@ -1903,7 +1342,7 @@ The algorithm sets up a feasibility LP for the constraints of `P`. If `use_polyhedra_interface` is `true`, we call `Polyhedra.isempty`. Otherwise, we set up the LP internally. """ -function isempty(P::LazySet{N}, +function isempty(P::LazySet{N}, # type parameter must be present for Documenter witness::Bool=false; use_polyhedra_interface::Bool=false, solver=nothing, @@ -1994,22 +1433,9 @@ function _linear_map_center(M::AbstractMatrix, X::LazySet) end """ - scale(α::Real, X::LazySet) - -Concrete scaling of a set. - -### Input - -- `α` -- scalar -- `X` -- set - -### Output - -A new set of the same type (if possible). - -### Notes +### Algorithm -This fallback method calls `scale!` on a copy of `X`. +The default implementation calls `scale!` on a copy of `X`. """ function scale(α::Real, X::LazySet) Y = copy(X) @@ -2031,8 +1457,10 @@ function tovrep(X::LazySet) return VPolytope(vertices_list(X)) end +# The default implementation throws an error because Julia's default behavior +# leads to an error that is hard to understand. function ∈(::AbstractVector, X::LazySet) - throw(ArgumentError("membership check for set type $(basetype(X)) not implemented")) + throw(ArgumentError("membership check for set type $(basetype(X)) is not implemented")) end function linear_map_inverse(A::AbstractMatrix, P::LazySet) diff --git a/src/Interfaces/aliases.jl b/src/Interfaces/aliases.jl index f88bc106f7..da3c2a5093 100644 --- a/src/Interfaces/aliases.jl +++ b/src/Interfaces/aliases.jl @@ -9,7 +9,7 @@ An alias for compact set types. ### Notes Most lazy operations are not captured by this alias because whether their result -is compact or not depends on the argument(s). +is compact depends on the argument(s). """ const CompactSet = Union{AbstractCentrallySymmetric, AbstractPolytope, @@ -25,7 +25,7 @@ An alias for non-compact set types. ### Notes Most lazy operations are not captured by this alias because whether their result -is non-compact or not depends on the argument(s). +is non-compact depends on the argument(s). """ const NonCompactSet = Union{HalfSpace, Hyperplane, diff --git a/src/LazyOperations/CartesianProduct.jl b/src/LazyOperations/CartesianProduct.jl index 80947f7b22..1338909bc7 100644 --- a/src/LazyOperations/CartesianProduct.jl +++ b/src/LazyOperations/CartesianProduct.jl @@ -1,4 +1,4 @@ -import Base: *, ∈, isempty +import Base: * export CartesianProduct, CartesianProduct!, diff --git a/src/LazyOperations/CartesianProductArray.jl b/src/LazyOperations/CartesianProductArray.jl index 8d2bed46f1..5eab1a8528 100644 --- a/src/LazyOperations/CartesianProductArray.jl +++ b/src/LazyOperations/CartesianProductArray.jl @@ -1,4 +1,4 @@ -import Base: *, ∈, isempty +import Base: * export CartesianProductArray, array, diff --git a/src/LazyOperations/Complement.jl b/src/LazyOperations/Complement.jl index 53869797eb..4a8df7d608 100644 --- a/src/LazyOperations/Complement.jl +++ b/src/LazyOperations/Complement.jl @@ -1,8 +1,4 @@ -import Base: ∈, - isempty - -export Complement, - complement +export Complement """ Complement{N, S<:LazySet{N}} <: LazySet{N} diff --git a/src/LazyOperations/ConvexHull.jl b/src/LazyOperations/ConvexHull.jl index 6b1c348704..60d29a8f65 100644 --- a/src/LazyOperations/ConvexHull.jl +++ b/src/LazyOperations/ConvexHull.jl @@ -1,7 +1,4 @@ -import Base.isempty - export ConvexHull, CH, - convex_hull, convex_hull!, ConvexHull!, swap diff --git a/src/LazyOperations/ConvexHullArray.jl b/src/LazyOperations/ConvexHullArray.jl index bd77c03020..6d06c407ad 100644 --- a/src/LazyOperations/ConvexHullArray.jl +++ b/src/LazyOperations/ConvexHullArray.jl @@ -1,5 +1,3 @@ -import Base.isempty - export ConvexHullArray, CHArray, array diff --git a/src/LazyOperations/ExponentialMap.jl b/src/LazyOperations/ExponentialMap.jl index fd2496a3e6..a8399dd81a 100644 --- a/src/LazyOperations/ExponentialMap.jl +++ b/src/LazyOperations/ExponentialMap.jl @@ -1,4 +1,4 @@ -import Base: *, size, ∈ +import Base: *, size export SparseMatrixExp, ExponentialMap, diff --git a/src/LazyOperations/Intersection.jl b/src/LazyOperations/Intersection.jl index 4169a935d4..4b148ad7aa 100644 --- a/src/LazyOperations/Intersection.jl +++ b/src/LazyOperations/Intersection.jl @@ -1,12 +1,10 @@ -import Base: isempty, ∈, ∩ +import Base: ∩ export Intersection, isempty_known, set_isempty!, swap, - use_precise_ρ, - constraints_list, - linear_map + use_precise_ρ """ IntersectionCache @@ -18,7 +16,7 @@ Container for information cached by a lazy `Intersection` object. - `isempty` -- is the intersection empty? There are three possible states, encoded as `Int8` values -1, 0, 1: - * ``-1`` - it is currently unknown whether the intersection is empty or not + * ``-1`` - it is currently unknown whether the intersection is empty * ``0`` - intersection is not empty * ``1`` - intersection is empty """ diff --git a/src/LazyOperations/InverseLinearMap.jl b/src/LazyOperations/InverseLinearMap.jl index d9a613b551..e7f24132f4 100644 --- a/src/LazyOperations/InverseLinearMap.jl +++ b/src/LazyOperations/InverseLinearMap.jl @@ -1,8 +1,6 @@ -import Base: *, ∈, isempty +import Base: * -export InverseLinearMap, - an_element, - constraints_list +export InverseLinearMap """ InverseLinearMap{N, S<:LazySet{N}, NM, MAT<:AbstractMatrix{NM}} diff --git a/src/LazyOperations/LinearMap.jl b/src/LazyOperations/LinearMap.jl index d6d892efff..1ff8007edc 100644 --- a/src/LazyOperations/LinearMap.jl +++ b/src/LazyOperations/LinearMap.jl @@ -1,8 +1,6 @@ -import Base: *, ∈, isempty +import Base: * export LinearMap, - an_element, - constraints_list, Projection """ diff --git a/src/LazyOperations/MinkowskiSum.jl b/src/LazyOperations/MinkowskiSum.jl index 9df9a1edb5..d03f723fbe 100644 --- a/src/LazyOperations/MinkowskiSum.jl +++ b/src/LazyOperations/MinkowskiSum.jl @@ -1,4 +1,4 @@ -import Base: +, getindex, isempty +import Base: +, getindex export MinkowskiSum, ⊕, MinkowskiSum!, diff --git a/src/LazyOperations/Rectification.jl b/src/LazyOperations/Rectification.jl index 354c73935d..a26f69e5d2 100644 --- a/src/LazyOperations/Rectification.jl +++ b/src/LazyOperations/Rectification.jl @@ -1,5 +1,3 @@ -import Base: ∈ - export Rectification """ diff --git a/src/LazyOperations/ResetMap.jl b/src/LazyOperations/ResetMap.jl index 054c46adbf..846161c790 100644 --- a/src/LazyOperations/ResetMap.jl +++ b/src/LazyOperations/ResetMap.jl @@ -1,5 +1,4 @@ using LazySets.Arrays: find_unique_nonzero_entry -import Base: isempty export ResetMap diff --git a/src/LazyOperations/SymmetricIntervalHull.jl b/src/LazyOperations/SymmetricIntervalHull.jl index 2d955aa7cc..59977ccb5d 100644 --- a/src/LazyOperations/SymmetricIntervalHull.jl +++ b/src/LazyOperations/SymmetricIntervalHull.jl @@ -1,5 +1,4 @@ -export SymmetricIntervalHull, ⊡, - an_element +export SymmetricIntervalHull, ⊡ """ SymmetricIntervalHull{N, S<:LazySet{N}} <: AbstractHyperrectangle{N} diff --git a/src/LazyOperations/Translation.jl b/src/LazyOperations/Translation.jl index 86aaafed0c..ea5275c057 100644 --- a/src/LazyOperations/Translation.jl +++ b/src/LazyOperations/Translation.jl @@ -1,9 +1,5 @@ -import Base: isempty export Translation, - an_element, - constraints_list, - linear_map, center """ diff --git a/src/LazyOperations/UnionSet.jl b/src/LazyOperations/UnionSet.jl index 3b0b7cd5b7..04c2fdf1e6 100644 --- a/src/LazyOperations/UnionSet.jl +++ b/src/LazyOperations/UnionSet.jl @@ -1,4 +1,4 @@ -import Base: isempty, ∈, ∪ +import Base: ∪ export UnionSet, swap diff --git a/src/LazySets.jl b/src/LazySets.jl index 9205557fc9..7c57a4abac 100644 --- a/src/LazySets.jl +++ b/src/LazySets.jl @@ -1,24 +1,40 @@ module LazySets -using LinearAlgebra, RecipesBase, Reexport, Requires, SparseArrays +using Reexport + +include("API/API.jl") +@reexport using .API +import .API: eltype, extrema, isdisjoint, isempty, \, ∈, ≈, ==, ⊆, + rand, norm, permute, distance, rectify, + affine_map, an_element, area, complement, concretize, constraints_list, + constraints, convex_hull, diameter, dim, exponential_map, high, + is_interior_point, is_polyhedral, isbounded, isboundedtype, isconvextype, + isempty, isoperation, isoperationtype, isuniversal, linear_map, low, + norm, project, radius, rectify, reflect, sample, scale, scale!, + support_function, ρ, support_vector, σ, surface, translate, translate!, + vertices_list, vertices, volume, + cartesian_product, difference, distance, exact_sum, ⊞, intersection, + is_intersection_empty, isequivalent, ⊂, linear_combination, + minkowski_difference, pontryagin_difference, minkowski_sum + +import Base: copy, rationalize, \ +import LinearAlgebra: ×, normalize, normalize! +import RecipesBase: apply_recipe + +export Arrays +export ×, normalize, subtypes + +using LinearAlgebra, RecipesBase, Requires, SparseArrays import GLPK, JuMP, Random, ReachabilityBase import IntervalArithmetic as IA using IntervalArithmetic: mince -import IntervalArithmetic: radius, ⊂ using LinearAlgebra: checksquare -import LinearAlgebra: norm, ×, normalize, normalize! using Random: AbstractRNG, GLOBAL_RNG, SamplerType, shuffle, randperm -import RecipesBase: apply_recipe -import SparseArrays: permute @static if VERSION < v"1.9" stack(vecs) = hcat(vecs...) end -export Arrays -export ×, normalize, ⊂, - subtypes - # ================ # ReachabilityBase # ================ @@ -33,9 +49,7 @@ using ReachabilityBase.Iteration using ReachabilityBase.Commutative using ReachabilityBase.Distribution using ReachabilityBase.Subtypes - using ReachabilityBase.Arrays -import .Arrays: distance, rectify, rationalize # ================= # External packages @@ -157,9 +171,12 @@ include("ConcreteOperations/difference.jl") include("ConcreteOperations/distance.jl") include("ConcreteOperations/exact_sum.jl") include("ConcreteOperations/intersection.jl") +include("ConcreteOperations/isapprox.jl") include("ConcreteOperations/isdisjoint.jl") -include("ConcreteOperations/issubset.jl") +include("ConcreteOperations/isequal.jl") +include("ConcreteOperations/isequivalent.jl") include("ConcreteOperations/isstrictsubset.jl") +include("ConcreteOperations/issubset.jl") include("ConcreteOperations/linear_combination.jl") include("ConcreteOperations/minkowski_difference.jl") include("ConcreteOperations/minkowski_sum.jl") diff --git a/src/Parallel/Parallel.jl b/src/Parallel/Parallel.jl index 58c23577d8..e965bb2311 100644 --- a/src/Parallel/Parallel.jl +++ b/src/Parallel/Parallel.jl @@ -1,5 +1,3 @@ -__precompile__(true) - """ Module `Parallel.jl` -- LazySets algorithms that are parallelized. """ diff --git a/src/Sets/Ball1.jl b/src/Sets/Ball1.jl index e9e9bae75b..3846934a3b 100644 --- a/src/Sets/Ball1.jl +++ b/src/Sets/Ball1.jl @@ -1,6 +1,3 @@ -import Base: rand, - ∈ - export Ball1 """ diff --git a/src/Sets/Ball2.jl b/src/Sets/Ball2.jl index 9de9e4aca4..d469dfb645 100644 --- a/src/Sets/Ball2.jl +++ b/src/Sets/Ball2.jl @@ -1,9 +1,4 @@ -import Base: rand, - ∈ - -export Ball2, - sample, - volume +export Ball2 """ Ball2{N<:AbstractFloat, VN<:AbstractVector{N}} <: AbstractBallp{N} diff --git a/src/Sets/BallInf.jl b/src/Sets/BallInf.jl index 5656d5193d..e2f29e2fa3 100644 --- a/src/Sets/BallInf.jl +++ b/src/Sets/BallInf.jl @@ -1,7 +1,4 @@ -import Base.rand - -export BallInf, - volume +export BallInf const BALLINF_THRESHOLD_ρ = 30 # threshold value in `ρ` const BALLINF_THRESHOLD_VOLUME = 50 # threshold value in `volume` diff --git a/src/Sets/Ballp.jl b/src/Sets/Ballp.jl index f24fd32cbc..a1e7f64e3d 100644 --- a/src/Sets/Ballp.jl +++ b/src/Sets/Ballp.jl @@ -1,6 +1,3 @@ -import Base: rand, - ∈ - export Ballp """ diff --git a/src/Sets/DensePolynomialZonotope.jl b/src/Sets/DensePolynomialZonotope.jl index 24cdf71fd4..1f564f17c6 100644 --- a/src/Sets/DensePolynomialZonotope.jl +++ b/src/Sets/DensePolynomialZonotope.jl @@ -1,10 +1,6 @@ export DensePolynomialZonotope, - dim, - σ, polynomial_order, - order, - linear_map, - scale + order """ DensePolynomialZonotope{N, VT, VMT, MT} <: AbstractPolynomialZonotope{N} diff --git a/src/Sets/Ellipsoid.jl b/src/Sets/Ellipsoid.jl index 3a60c22791..26cba323db 100644 --- a/src/Sets/Ellipsoid.jl +++ b/src/Sets/Ellipsoid.jl @@ -1,5 +1,3 @@ -import Base.rand - export Ellipsoid, shape_matrix diff --git a/src/Sets/EmptySet.jl b/src/Sets/EmptySet.jl index 4c70e673ec..03b005dd42 100644 --- a/src/Sets/EmptySet.jl +++ b/src/Sets/EmptySet.jl @@ -1,10 +1,4 @@ -import Base: rand, - ∈, - isempty - -export EmptySet, ∅, - an_element, - linear_map +export EmptySet, ∅ """ EmptySet{N} <: ConvexSet{N} diff --git a/src/Sets/HParallelotope.jl b/src/Sets/HParallelotope.jl index 11d0483240..7296b4bec6 100644 --- a/src/Sets/HParallelotope.jl +++ b/src/Sets/HParallelotope.jl @@ -1,13 +1,11 @@ export HParallelotope, directions, offset, - dim, base_vertex, extremal_vertices, center, genmat, - generators, - constraints_list + generators """ HParallelotope{N, VN<:AbstractVector{N}, MN<:AbstractMatrix{N}} <: AbstractZonotope{N} diff --git a/src/Sets/HPolyhedron.jl b/src/Sets/HPolyhedron.jl index fb8c71577e..0e8dad3128 100644 --- a/src/Sets/HPolyhedron.jl +++ b/src/Sets/HPolyhedron.jl @@ -1,13 +1,6 @@ -import Base: rand, - convert - export HPolyhedron, - dim, σ, ∈, addconstraint!, - constraints_list, tohrep, tovrep, - convex_hull, - cartesian_product, remove_redundant_constraints, remove_redundant_constraints!, constrained_dimensions, diff --git a/src/Sets/HPolytope.jl b/src/Sets/HPolytope.jl index 6bd4a21581..f30e62d188 100644 --- a/src/Sets/HPolytope.jl +++ b/src/Sets/HPolytope.jl @@ -1,9 +1,4 @@ -import Base.rand -import Base.rationalize - -export HPolytope, - vertices_list, - isbounded +export HPolytope """ HPolytope{N, VN<:AbstractVector{N}} <: AbstractPolytope{N} diff --git a/src/Sets/HalfSpace.jl b/src/Sets/HalfSpace.jl index 3162be3beb..7192d8d846 100644 --- a/src/Sets/HalfSpace.jl +++ b/src/Sets/HalfSpace.jl @@ -1,11 +1,4 @@ -import Base: rand, - ∈, - isempty, - convert - export HalfSpace, LinearConstraint, - an_element, - complement, constrained_dimensions, halfspace_left, halfspace_right, iscomplement diff --git a/src/Sets/Hyperplane.jl b/src/Sets/Hyperplane.jl index 22ea5d04fc..27b313adb4 100644 --- a/src/Sets/Hyperplane.jl +++ b/src/Sets/Hyperplane.jl @@ -1,9 +1,4 @@ -import Base: rand, - ∈, - isempty - -export Hyperplane, - an_element +export Hyperplane """ Hyperplane{N, VN<:AbstractVector{N}} <: AbstractPolyhedron{N} diff --git a/src/Sets/Hyperrectangle.jl b/src/Sets/Hyperrectangle.jl index 973d931efb..2198871ee8 100644 --- a/src/Sets/Hyperrectangle.jl +++ b/src/Sets/Hyperrectangle.jl @@ -1,5 +1,3 @@ -import Base.rand - export Hyperrectangle """ diff --git a/src/Sets/Interval.jl b/src/Sets/Interval.jl index fe93e9224d..6c83c83780 100644 --- a/src/Sets/Interval.jl +++ b/src/Sets/Interval.jl @@ -1,11 +1,8 @@ -import Base: +, -, *, ∈, ⊆, rand, min, max +import Base: +, -, *, min, max export Interval, - dim, σ, center, - vertices_list, - isflat, - linear_map -constraints_list + center, + isflat """ Interval{N} <: AbstractHyperrectangle{N} @@ -650,7 +647,7 @@ function rectify(x::Interval{N}) where {N} return x else # lower end is negative - return Interval(zero(N), max(x.dat.hi, zero(N))) + return Interval(zero(N), Base.max(x.dat.hi, zero(N))) end end diff --git a/src/Sets/Line.jl b/src/Sets/Line.jl index 29d1e45016..eef5750aea 100644 --- a/src/Sets/Line.jl +++ b/src/Sets/Line.jl @@ -1,11 +1,4 @@ -import Base: rand, - ∈, - isempty - -export Line, - an_element, - translate, - translate! +export Line """ Line{N, VN<:AbstractVector{N}} <: AbstractPolyhedron{N} @@ -213,7 +206,7 @@ function constraints_list(L::Line) return out end -function _parameters(L::Line{N,VN}) where {N,VN} +function _parameters(::Line{N,VN}) where {N,VN} return (N, VN) end @@ -399,7 +392,7 @@ end """ isempty(L::Line) -Check whether a line is empty or not. +Check whether a line is empty. ### Input diff --git a/src/Sets/Line2D.jl b/src/Sets/Line2D.jl index e1129e98ed..2e1239ab35 100644 --- a/src/Sets/Line2D.jl +++ b/src/Sets/Line2D.jl @@ -1,9 +1,4 @@ -import Base: rand, - ∈, - isempty - -export Line2D, - an_element +export Line2D """ Line2D{N, VN<:AbstractVector{N}} <: AbstractPolyhedron{N} diff --git a/src/Sets/LineSegment.jl b/src/Sets/LineSegment.jl index f37899577c..8728ec9055 100644 --- a/src/Sets/LineSegment.jl +++ b/src/Sets/LineSegment.jl @@ -1,9 +1,5 @@ -import Base: rand, - ∈ - export LineSegment, - halfspace_left, halfspace_right, - constraints_list + halfspace_left, halfspace_right """ LineSegment{N, VN<:AbstractVector{N}} <: AbstractZonotope{N} diff --git a/src/Sets/SimpleSparsePolynomialZonotope.jl b/src/Sets/SimpleSparsePolynomialZonotope.jl index 98bc790bac..6a15829c94 100644 --- a/src/Sets/SimpleSparsePolynomialZonotope.jl +++ b/src/Sets/SimpleSparsePolynomialZonotope.jl @@ -1,5 +1,5 @@ export SimpleSparsePolynomialZonotope, PolynomialZonotope, expmat, nparams, - linear_map, quadratic_map, remove_redundant_generators + quadratic_map, remove_redundant_generators """ SimpleSparsePolynomialZonotope{N, VN<:AbstractVector{N}, diff --git a/src/Sets/Singleton.jl b/src/Sets/Singleton.jl index 1f83dce0f4..4a07534680 100644 --- a/src/Sets/Singleton.jl +++ b/src/Sets/Singleton.jl @@ -1,5 +1,3 @@ -import Base.rand - export Singleton """ diff --git a/src/Sets/SparsePolynomialZonotope.jl b/src/Sets/SparsePolynomialZonotope.jl index 819cacccff..00bb3df6af 100644 --- a/src/Sets/SparsePolynomialZonotope.jl +++ b/src/Sets/SparsePolynomialZonotope.jl @@ -1,6 +1,6 @@ export SparsePolynomialZonotope, expmat, nparams, ngens_dep, ngens_indep, - genmat_dep, genmat_indep, indexvector, polynomial_order, translate, - linear_map, quadratic_map, remove_redundant_generators, reduce_order, ρ + genmat_dep, genmat_indep, indexvector, polynomial_order, quadratic_map, + remove_redundant_generators, reduce_order """ SparsePolynomialZonotope{N, VN<:AbstractVector{N}, MN<:AbstractMatrix{N}, diff --git a/src/Sets/Star.jl b/src/Sets/Star.jl index 95b20ca8e9..fe445b2243 100644 --- a/src/Sets/Star.jl +++ b/src/Sets/Star.jl @@ -2,8 +2,7 @@ export Star, center, basis, predicate, - intersection!, - dim + intersection! """ Star{N, VN<:AbstractVector{N}, MN<:AbstractMatrix{N}, PT<:AbstractPolyhedron{N}} <: AbstractPolyhedron{N} diff --git a/src/Sets/Universe.jl b/src/Sets/Universe.jl index 0aad22b603..3c5cdb468c 100644 --- a/src/Sets/Universe.jl +++ b/src/Sets/Universe.jl @@ -1,7 +1,3 @@ -import Base: rand, - ∈, - isempty - export Universe """ diff --git a/src/Sets/VPolygon.jl b/src/Sets/VPolygon.jl index 4386d27036..3b3765c0fb 100644 --- a/src/Sets/VPolygon.jl +++ b/src/Sets/VPolygon.jl @@ -1,11 +1,6 @@ -import Base: rand, - ∈ - export VPolygon, remove_redundant_vertices, - remove_redundant_vertices!, - linear_map, - project + remove_redundant_vertices! # heuristic to define the method used to compute the support vector of a polygon # in vertex representation; if the number of vertices of the polygon is smaller diff --git a/src/Sets/VPolytope.jl b/src/Sets/VPolytope.jl index d16898a22a..41b5b16ce2 100644 --- a/src/Sets/VPolytope.jl +++ b/src/Sets/VPolytope.jl @@ -1,9 +1,4 @@ -import Base: rand, - ∈ - export VPolytope, - vertices_list, - linear_map, remove_redundant_vertices, tohrep, tovrep diff --git a/src/Sets/ZeroSet.jl b/src/Sets/ZeroSet.jl index 96d75ff060..3a10b0303f 100644 --- a/src/Sets/ZeroSet.jl +++ b/src/Sets/ZeroSet.jl @@ -1,8 +1,4 @@ -import Base: rand, - ∈ - -export ZeroSet, - linear_map +export ZeroSet """ ZeroSet{N} <: AbstractSingleton{N} diff --git a/src/Sets/Zonotope.jl b/src/Sets/Zonotope.jl index 78805b4347..58b6b8f47c 100644 --- a/src/Sets/Zonotope.jl +++ b/src/Sets/Zonotope.jl @@ -1,8 +1,4 @@ -import Base: rand - export Zonotope, - scale, - scale!, reduce_order, remove_zero_generators, remove_redundant_generators diff --git a/src/convert.jl b/src/convert.jl index 4ab0ca59d0..7b9448da96 100644 --- a/src/convert.jl +++ b/src/convert.jl @@ -1192,7 +1192,7 @@ function load_taylormodels_convert_polynomial_zonotope() pol = polynomial(TMi) rem = remainder(TMi) c[i] = IA.mid(rem) + constant_term(pol) - GI_diag[i] = radius(rem) + GI_diag[i] = IA.radius(rem) for (order, term_order) in enumerate(pol.coeffs) # we skip the first (= constant) term if order == 1 || iszero(term_order)