Set Functions (10)

Set theory operations

setCartesian
Create the cartesian product of two (multi)sets. Multi-dimension arrays will be converted to single-dimension arrays and the values will be sorted in ascending order before the operation.
Syntax
setCartesian(set1 | set2)
Type Signatures
Array | Matrix, Array | Matrix
Parameters
NameTypeDescription
a1Array | MatrixA (multi)set
a2Array | MatrixA (multi)set
Returns
Array | Matrix — The cartesian product of two (multi)sets
Examples
setCartesian([1
2
setDifference
Create the difference of two (multi)sets: every element of set1, that is not the element of set2. Multi-dimension arrays will be converted to single-dimension arrays before the operation.
Syntax
setDifference(set1 | set2)
Type Signatures
Array | Matrix, Array | Matrix
Parameters
NameTypeDescription
a1Array | MatrixA (multi)set
a2Array | MatrixA (multi)set
Returns
Array | Matrix — The difference of two (multi)sets
Examples
setDifference([1
2
3
4
setDistinct
Collect the distinct elements of a multiset. A multi-dimension array will be converted to a single-dimension array before the operation.
Syntax
setDistinct(set)
Type Signatures
Array | Matrix
Parameters
NameTypeDescription
aArray | MatrixA multiset
Returns
Array | Matrix — A set containing the distinct elements of the multiset
Examples
setDistinct([1
1
1
2
2
See Also
setMultiplicity
setIntersect
Create the intersection of two (multi)sets. Multi-dimension arrays will be converted to single-dimension arrays before the operation.
Syntax
setIntersect(set1 | set2)
Type Signatures
Array | Matrix, Array | Matrix
Parameters
NameTypeDescription
a1Array | MatrixA (multi)set
a2Array | MatrixA (multi)set
Returns
Array | Matrix — The intersection of two (multi)sets
Examples
setIntersect([1
2
3
4
setIsSubset
Check whether a (multi)set is a subset of another (multi)set: every element of set1 is the element of set2. Multi-dimension arrays will be converted to single-dimension arrays before the operation.
Syntax
setIsSubset(set1 | set2)
Type Signatures
Array | Matrix, Array | Matrix
Parameters
NameTypeDescription
a1Array | MatrixA (multi)set
a2Array | MatrixA (multi)set
Returns
boolean — Returns true when a1 is a subset of a2, returns false otherwise
Examples
setIsSubset([1
2
setMultiplicity
Count the multiplicity of an element in a multiset. A multi-dimension array will be converted to a single-dimension array before the operation.
Syntax
setMultiplicity(element | set)
Type Signatures
number | BigNumber | Fraction | Complex, Array | Matrix
Parameters
NameTypeDescription
enumber | BigNumber | Fraction | ComplexAn element in the multiset
aArray | MatrixA multiset
Returns
number — The number of how many times the multiset contains the element
Examples
setMultiplicity(1
[1
2
2
4
See Also
setDistinct setSize
setPowerset
Create the powerset of a (multi)set: the powerset contains very possible subsets of a (multi)set. A multi-dimension array will be converted to a single-dimension array before the operation.
Syntax
setPowerset(set)
Type Signatures
Array | Matrix
Parameters
NameTypeDescription
aArray | MatrixA (multi)set
Returns
Array — The powerset of the (multi)set
Examples
setPowerset([1
2
3
See Also
setCartesian
setSize
Count the number of elements of a (multi)set. When the second parameter "unique" is true, count only the unique values. A multi-dimension array will be converted to a single-dimension array before the operation.
Syntax
setSize(set) | setSize(set | unique)
Type Signatures
Array | Matrix, Array | Matrix, boolean
Parameters
NameTypeDescription
aArray | MatrixA multiset
uniquebooleanIf true, only the unique values are counted. False by default
Returns
number — The number of elements of the (multi)set
Examples
setSize([1
2
2
4
setSymDifference
Create the symmetric difference of two (multi)sets. Multi-dimension arrays will be converted to single-dimension arrays before the operation.
Syntax
setSymDifference(set1 | set2)
Type Signatures
Array | Matrix, Array | Matrix
Parameters
NameTypeDescription
a1Array | MatrixA (multi)set
a2Array | MatrixA (multi)set
Returns
Array | Matrix — The symmetric difference of two (multi)sets
Examples
setSymDifference([1
2
3
4
setUnion
Create the union of two (multi)sets. Multi-dimension arrays will be converted to single-dimension arrays before the operation.
Syntax
setUnion(set1 | set2)
Type Signatures
Array | Matrix, Array | Matrix
Parameters
NameTypeDescription
a1Array | MatrixA (multi)set
a2Array | MatrixA (multi)set
Returns
Array | Matrix — The union of two (multi)sets
Examples
setUnion([1
2
3
4