# Union

## Binary set union (UnionSet)

`LazySets.UnionSet`

— Type`UnionSet{N, S1<:LazySet{N}, S2<:LazySet{N}} <: LazySet{N}`

Type that represents the set union of two sets.

**Fields**

`X`

– set`Y`

– set

**Notes**

The union of convex sets is typically not convex.

`Base.:∪`

— Method`∪`

Alias for `UnionSet`

.

`LazySets.swap`

— Method`swap(cup::UnionSet)`

Return a new `UnionSet`

object with the arguments swapped.

**Input**

`cup`

– union of two sets

**Output**

A new `UnionSet`

object with the arguments swapped.

`LazySets.API.dim`

— Method`dim(cup::UnionSet)`

Return the dimension of the union of two sets.

**Input**

`cup`

– union of two sets

**Output**

The ambient dimension of the union of two sets.

`LazySets.API.σ`

— Method`σ(d::AbstractVector, cup::UnionSet; [algorithm]="support_vector")`

Return a support vector of the union of two sets in a given direction.

**Input**

`d`

– direction`cup`

– union of two sets`algorithm`

– (optional, default: "support*vector"): the algorithm to compute the support vector; if "support*vector", use the support vector of each argument; if "support_function" use the support function of each argument and evaluate the support vector of only one of them

**Output**

A support vector in the given direction.

**Algorithm**

The support vector of the union of two sets $X$ and $Y$ can be obtained as the vector that maximizes the support function of either $X$ or $Y$, i.e., it is sufficient to find the $\argmax(ρ(d, X), ρ(d, Y)])$ and evaluate its support vector.

The default implementation, with option `algorithm="support_vector"`

, computes the support vector of $X$ and $Y$ and then compares the support function using a dot product.

If the support function can be computed more efficiently, the alternative implementation `algorithm="support_function"`

can be used, which evaluates the support function of each set directly and then calls only the support vector of either $X$ *or* $Y$.

`LazySets.API.ρ`

— Method`ρ(d::AbstractVector, cup::UnionSet)`

Evaluate the support function of the union of two sets in a given direction.

**Input**

`d`

– direction`cup`

– union of two sets

**Output**

The evaluation of the support function in the given direction.

**Algorithm**

The support function of the union of two sets $X$ and $Y$ evaluates to the maximum of the support-function evaluations of $X$ and $Y$.

`LazySets.API.an_element`

— Method`an_element(cup::UnionSet)`

Return some element of the union of two sets.

**Input**

`cup`

– union of two sets

**Output**

An element in the union of two sets.

**Algorithm**

We use `an_element`

on the first non-empty wrapped set.

`Base.:∈`

— Method`∈(x::AbstractVector, cup::UnionSet)`

Check whether a given point is contained in the union of two sets.

**Input**

`x`

– point/vector`cup`

– union of two sets

**Output**

`true`

iff $x ∈ cup$.

`Base.isempty`

— Method`isempty(cup::UnionSet)`

Check whether the union of two sets is empty.

**Input**

`cup`

– union of two sets

**Output**

`true`

iff the union is empty.

`LazySets.API.isbounded`

— Method`isbounded(cup::UnionSet)`

Check whether the union of two sets is bounded.

**Input**

`cup`

– union of two sets

**Output**

`true`

iff the union is bounded.

`LazySets.API.vertices_list`

— Method```
vertices_list(cup::UnionSet; [apply_convex_hull]::Bool=false,
[backend]=nothing)
```

Return the list of vertices of the union of two sets.

**Input**

`cup`

– union of two sets`apply_convex_hull`

– (optional, default:`false`

) if`true`

, post-process the vertices using a convex-hull algorithm`backend`

– (optional, default:`nothing`

) backend for computing the convex hull (see argument`apply_convex_hull`

)

**Output**

The list of vertices, possibly reduced to the list of vertices of the convex hull.

## $n$-ary set union (UnionSetArray)

`LazySets.UnionSetArray`

— TypeUnionSetArray{N, S<:LazySet{N}} <: LazySet{N}

Type that represents the set union of a finite number of sets.

**Fields**

`array`

– array of sets

**Notes**

The union of convex sets is typically not convex.

`LazySets.API.dim`

— Methoddim(cup::UnionSetArray)

Return the dimension of the union of a finite number of sets.

**Input**

`cup`

– union of a finite number of sets

**Output**

The ambient dimension of the union of a finite number of sets, or `0`

if there is no set in the array.

`LazySets.array`

— Methodarray(cup::UnionSetArray)

Return the array of the union of a finite number of sets.

**Input**

`cup`

– union of a finite number of sets

**Output**

The array of the union.

`LazySets.API.σ`

— Methodσ(d::AbstractVector, cup::UnionSetArray; [algorithm]="support_vector")

Return a support vector of the union of a finite number of sets in a given direction.

**Input**

`d`

– direction`cup`

– union of a finite number of sets`algorithm`

– (optional, default: "support*vector"): the algorithm to compute the support vector; if "support*vector", use the support vector of each argument; if "support_function", use the support function of each argument and evaluate the support vector of only one of them

**Output**

A support vector in the given direction.

**Algorithm**

The support vector of the union of a finite number of sets $X₁, X₂, ...$ can be obtained as the vector that maximizes the support function, i.e., it is sufficient to find the $\argmax([ρ(d, X₂), ρ(d, X₂), ...])$ and evaluate its support vector.

The default implementation, with option `algorithm="support_vector"`

, computes the support vector of all $X₁, X₂, ...$ and then compares the support function using the dot product.

If the support function can be computed more efficiently, the alternative implementation `algorithm="support_function"`

can be used, which evaluates the support function of each set directly and then calls only the support vector of one of the $Xᵢ$.

`LazySets.API.ρ`

— Methodρ(d::AbstractVector, cup::UnionSetArray)

Evaluate the support function of the union of a finite number of sets in a given direction.

**Input**

`d`

– direction`cup`

– union of a finite number of sets

**Output**

The evaluation of the support function in the given direction.

**Algorithm**

The support function of the union of a finite number of sets $X₁, X₂, ...$ can be obtained as the maximum of $ρ(d, X₂), ρ(d, X₂), ...$.

`LazySets.API.an_element`

— Methodan_element(cup::UnionSetArray)

Return some element of the union of a finite number of sets.

**Input**

`cup`

– union of a finite number of sets

**Output**

An element in the union of a finite number of sets.

**Algorithm**

We use `an_element`

on the first non-empty wrapped set.

`Base.:∈`

— Method∈(x::AbstractVector, cup::UnionSetArray)

Check whether a given point is contained in the union of a finite number of sets.

**Input**

`x`

– point/vector`cup`

– union of a finite number of sets

**Output**

`true`

iff $x ∈ cup$.

`Base.isempty`

— Methodisempty(cup::UnionSetArray)

Check whether the union of a finite number of sets is empty.

**Input**

`cup`

– union of a finite number of sets

**Output**

`true`

iff the union is empty.

`LazySets.API.isbounded`

— Methodisbounded(cup::UnionSetArray)

Check whether the union of a finite number of sets is bounded.

**Input**

`cup`

– union of a finite number of sets

**Output**

`true`

iff the union is bounded.

`LazySets.API.vertices_list`

— Method```
vertices_list(cup::UnionSetArray; [apply_convex_hull]::Bool=false,
[backend]=nothing)
```

Return a list of vertices of the union of a finite number of sets.

**Input**

`cup`

– union of a finite number of sets`apply_convex_hull`

– (optional, default:`false`

) if`true`

, post-process the vertices using a convex-hull algorithm`backend`

– (optional, default:`nothing`

) backend for computing the convex hull (see argument`apply_convex_hull`

)

**Output**

A list of vertices, possibly reduced to the list of vertices of the convex hull.