## `intersect, minus, union` -- operators for sets and intervals

#### Introduction

`intersect` computes the intersection of sets and intervals.

`minus` computes the difference between sets and intervals.

`union` computes the union of sets and intervals.

#### Call(s)

set1 intersect set2 `_intersect(set1, set2...)`
set1 minus set2 `_minus(set1, set2)`
set1 union set2 `_union(set1, set2...)`

#### Parameters

`set1, set2, ...` | - | finite sets of type `DOM_SET`, or intervals of type `Dom::Interval`, or arithmetical expressions

#### Returns

a set, an interval, a symbolic expression of type `"_intersect"`, `"_minus"`, `"_union"`, or `universe`.

### Overloadable:

`set1`, `set2`, `...`

#### Related Functions

`universe`

#### Details

- `set1 intersect set2` is equivalent to `_intersect(set1, set2)`.
- `set1 minus set2` is equivalent to `_minus(set1, set2)`.
- `set1 union set2` is equivalent to `_union(set1, set2)`.
- The precedences of `intersect`, `minus`, `union` are as follows: The operator `intersect` is stronger binding than `minus`, i.e,
  `set1 intersect set2 minus set3` = `(set 1 intersect set2) minus set3`.
  The operator `minus` is stronger binding than `union`, i.e.,
  `set1 minus set2 union set3` = `(set1 minus set2) union set3`.
  Further,
  `set1 minus set2 minus set3` = `(set 1 minus set2) minus set3`.
  If in doubt, use brackets to make sure that the expression is parsed as desired.
- If sets or intervals are specified by symbolic expressions involving identifiers or indexed identifiers, then symbolic calls of `_intersect`, `_minus`, `_union` are returned. On the screen, they are represented via the operator notation `set1 intersect set2` etc.

- On finite sets of type `DOM_SET`, these operators act in a purely syntactical way. E.g., `{1}minus {x}` simplifies to `{1}`. Mathematically, this result may not be correct in general, because `x` might represent the value 1.

- On intervals of type `Dom::Interval`, these operators act in a semantical way. In particular, properties of identifiers are taken into account.
- `_intersect()` returns `universe` (of type `stdlib::Universe`) which represents the set of all mathematical objects.
- `_union()` returns the empty set `{}`.
- `_intersect` is a function of the system kernel.
- `_minus` is a function of the system kernel.
- `_union` is a function of the system kernel.

#### Example 1

`intersect`, `minus`, and `union` operate on finite sets:

    >> {x, 1, 5} intersect {x, 1, 3, 4},
       {x, 1, 5} union {x, 1, 3, 4},
       {x, 1, 5} minus {x, 1, 3, 4}

                           {x, 1}, {x, 1, 3, 4, 5}, {5}

For symbolic sets, specified as identifiers or indexed identifiers, symbolic calls are returned:

    >> {1, 2} union A union {2, 3}

                                 {1, 2, 3} union A

Note that the set operations act on finite sets in a purely syntactical way. In the following call, `x` does not match any of the numbers 1, 2, 3 syntactically:

    >> {1, 2, 3} minus {1, x}

                                      {2, 3}

#### Example 2

`intersect`, `minus`, and `union` are overloaded by the domain `Dom::Interval`:

    >> Dom::Interval([0, 1]) union Dom::Interval(1, 4)

                                      [0, 4[

    >> Dom::Interval([0, 1]) union Dom::Interval(4, infinity)

                            [0, 1] union ]4, infinity[

    >> Dom::Interval(2, infinity) intersect Dom::Interval([1, 3])

                                      ]2, 3]

    >> {PI/2, 2, 2.5, 3} intersect Dom::Interval(1,3)

                                  {         PI }
                                  { 2, 2.5, -- }
                                  {         2  }

    >> Dom::Interval(1, PI) minus {2, 3}

                         ]3, PI[ union ]1, 2[ union ]2, 3[

In contrast to finite sets of type `DOM_SET`, the interval domain works semantically. It takes `properties` into account:

    >> Dom::Interval(-1, 1) minus {x}

                               ]x, 1[ union ]-1, x[

    >> assume(x > 2): Dom::Interval(-1, 1) minus {x}

                                      ]-1, 1[

    >> unassume(x):

#### Example 3

The following list provides a collection of sets:

    >> L := [{a, b}, {1, 2, a, c}, {3, a, b}, {a, c}]:

The functional equivalent `_intersect` of the `intersect` operator accepts an arbitray number of arguments. Thus, the intersection of all sets in `L` can be computed as follows:

    >> _intersect(op(L))

                                        {a}

The union of all sets in `L` is:

    >> _union(op(L))

                                {a, b, c, 1, 2, 3}

    >> delete L:

#### Example 4

`universe` represents the set of all mathematical objects:

    >> _intersect()

                                     universe

#### Changes

- no changes

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000