The following operations on sets can be performed with operators: Union, difference, symmetric difference, inclusion and intersection. Elements can be aded or removed from the set with the Include or Exclude operators. The operators needed for this are listed in table (9.6).
Operator | Action |
+ | Union |
- | Difference |
* | Intersection |
>< | Symmetric difference |
<= | Contains |
include | include an element in the set |
exclude | exclude an element from the set |
The set type of the operands must be the same, or an error will be generated by the compiler.
The following program gives some valid examples of set operations:
As can be seen, the union is equivalent to a binary OR, while the intersection is equivalent to a binary AND, and the summetric difference equals a XOR operation.
The Include and Exclude operations are equivalent to a union or a difference with a set of 1 element. Thus,
is equivalent to
and
is equivalent to