Chapter 10. Set Theory in GEL

Using Sets

Genius has some basic set theoretic functionality built in. Currently a set is just a vector (or a matrix). Every distinct object is treated as a different element.

Using Sets

Just like vectors, objects in sets can include numbers, strings, `null`, matrices and vectors. It is planned in the future to have a dedicated type for sets, rather than using vectors. Note that floating point numbers are distinct from integers, even if they appear the same. That is, Genius will treat `0` and `0.0` as two distinct elements. The `null` is treated as an empty set.

To build a set out of a vector, use the `MakeSet` function. Currently, it will just return a new vector where every element is unique.

````genius> ``MakeSet([1,2,2,3])`
= [1, 2, 3]
```

Similarly there are functions `Union`, `Intersection`, `SetMinus`, which are rather self explanatory. For example:

````genius> ``Union([1,2,3], [1,2,4])`
= [1, 2, 4, 3]
```

Note that no order is guaranteed for the return values. If you wish to sort the vector you should use the `SortVector` function.

For testing membership, there are functions `IsIn` and `IsSubset`, which return a boolean value. For example:

````genius> ``IsIn (1, [0,1,2])`
= true
```

The input `IsIn(x,X)` is of course equivalent to `IsSubset([x],X)`. Note that since the empty set is a subset of every set, `IsSubset(null,X)` is always true.