Function: S = finiteset (a, b, …)
Function: S = finiteset (cellarray)
Function: emptyset = finiteset ()

Return a symbolic set containing the inputs without duplicates.

Example:

syms x y
S = finiteset(1, pi, x, 1, 1, x, x + y)
  ⇒ S = (sym) {1, π, x, x + y}
subs(S, x, pi)
  ⇒ ans = (sym) {1, π, y + π}

You can also use this to make the empty set:

finiteset()
  ⇒ ans = (sym) ∅

You cannot directly access elements of a set using indexing:

S(2)
  -| ??? 2 is out of bound ...

Instead you can first convert it to a cell (see ‘@sym/children’):

elements = children(S)
  ⇒ elements = (sym) [1  π  x  x + y]  (1×4 matrix)
elements(end)
  ⇒ ans = (sym) x + y

Careful, passing a matrix creates a set of matrices (rather than a set from the elements of the matrix):

finiteset([1 x 1 1])
  ⇒ ans = (sym) {[1  x  1  1]}
finiteset([1 pi], [1 x 1 1], [1 pi])
  ⇒ ans = (sym) {[1  π], [1  x  1  1]}

On the other hand, if you want to make a set from the elements of a matrix, first convert it to a cell array:

A = [1 x 1; 2 1 x];
finiteset(num2cell(A))
  ⇒ ans = (sym) {1, 2, x}

Sets can be nested:

finiteset(finiteset(), finiteset(finiteset()))
  ⇒ (sym) {∅, {∅}}

Note that cell arrays are not the same thing as sets (despite the similar rendering using { and }). For example, this creates a set containing a set:

finiteset(finiteset(1, 2, 3, 3))
  ⇒ ans = (sym) {{1, 2, 3}}

whereas passing a single cell array cellarray creates a set containing each element of cellarray:

finiteset({1, 2, 3, 3})
  ⇒ ans = (sym) {1, 2, 3}

(This is implemented mainly to enable the num2cell example above.)

See also: @sym/interval, @sym/ismember, @sym/children, @sym/union, @sym/intersect, @sym/setdiff, @sym/setxor.

Package: symbolic