[Previous] [Next] [Contents]

[ImplState=stable,TestState=stable,DocState=deprecated]

## `combinat::cartesian` -- cartesian product of sets (deprecated)

#### Introduction

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

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, ..., setk)`

#### Parameters

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

#### Returns

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

#### Details

- The cartesian product of the given sets `set1`, `set2` is the set set1 x set2 x ... x setk of all k-tuples [x1,x2,...,xk] with xn in setn for each 1<=n<=k.

- `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::warnDeprecated(FALSE):
       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], [Diamondsuit, 7], [Diamondsuit, 8],

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

             [Heartsuit, 8], [Heartsuit, 9], [Heartsuit, 10]}

The function `combinat::cartesian` is deprecated:

    >> old_val:=combinat::warnDeprecated(TRUE):
       combinat::cartesian({Diamondsuit,Heartsuit,Spadesuit,Clubsuit},{7,8,9,10});
       combinat::warnDeprecated(old_val):

          Warning: combinat::cartesian(s1,s2,...) is obsolete.
          Please use 'combinat::cartesianProduct::list(s1,s2,...)' inste\
          ad. [combinat::cartesian]

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

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

             [Spadesuit, 10], [Diamondsuit, 7], [Diamondsuit, 8],

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

             [Heartsuit, 8], [Heartsuit, 9], [Heartsuit, 10]}

Here is the recommended replacement:

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

          [[Diamondsuit, 7], [Diamondsuit, 8], [Diamondsuit, 9],

             [Diamondsuit, 10], [Heartsuit, 7], [Heartsuit, 8],

             [Heartsuit, 9], [Heartsuit, 10], [Spadesuit, 7],

             [Spadesuit, 8], [Spadesuit, 9], [Spadesuit, 10],

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

Note that the result is returned as a list.

#### 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], [Diamondsuit, 1],

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

             [Heartsuit, 2], [Heartsuit, 3]}

Here is the recommended replacement:

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

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

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

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

             [Clubsuit, 1], [Clubsuit, 2], [Clubsuit, 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]}

[Previous] [Next] [Contents]

MuPAD Combinat, an open source algebraic combinatorics package