## `combinat::cartesian` -- Cartesian product of sets

#### Introduction

`combinat::cartesian``(set1, set2, ..., setN)` computes the cartesian product of the given sets `set1`, `set2`, ..., `setN`.

For every positive integer n, the set {1, ..., n} may be denoted by `n`, and `0` may be written instead of the empty set.

#### Call(s)

`combinat::cartesian(set1, set2, ..., setN)`

#### Parameters

`set1, set2, ..., setN` | - | Sets of domain type `DOM_SET`, or nonnegative integers.

#### Returns

A set of domain type `DOM_SET` containing N-tuples of domain type `DOM_LIST`, where N is the number of arguments.

#### Details

- The cartesian product of the given sets `set1`, `set2` is the set set1 x set2 x ... x setN of all N-tuples [x1,x2,...,xN] with xn in setn for each 1<=n<=N.
- `combinat::cartesian`() is not commutative, as demonstrated in example 3.

#### Example 1

Which cards exist, if you have the following suits and numbers available?

    >> combinat::cartesian({Diamondsuit,Heartsuit,Spadesuit,Clubsuit},{7,8,9,10})

          {[Clubsuit, 7], [Clubsuit, 8], [Clubsuit, 9], [Clubsuit, 10],

             [Spadesuit, 7], [Spadesuit, 8], [Spadesuit, 9],

             [Spadesuit, 10], [Heartsuit, 7], [Heartsuit, 8],

             [Heartsuit, 9], [Heartsuit, 10], [Diamondsuit, 7],

             [Diamondsuit, 8], [Diamondsuit, 9], [Diamondsuit, 10]}

#### Example 2

The same as above, but with other numbers:

    >> combinat::cartesian({Diamondsuit,Heartsuit,Spadesuit,Clubsuit},3)

          {[Clubsuit, 1], [Clubsuit, 2], [Clubsuit, 3], [Spadesuit, 1],

             [Spadesuit, 2], [Spadesuit, 3], [Heartsuit, 1],

             [Heartsuit, 2], [Heartsuit, 3], [Diamondsuit, 1],

             [Diamondsuit, 2], [Diamondsuit, 3]}

#### Example 3

The cartesian product isn't commutative:

    >> combinat::cartesian({Diamondsuit},2); combinat::cartesian(2,{Diamondsuit})

                       {[Diamondsuit, 1], [Diamondsuit, 2]}

                       {[1, Diamondsuit], [2, Diamondsuit]}

#### Changes

- no changes

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