combinat::cartesianProduct – cartesian products

The library combinat::cartesianProduct provides functions for counting and generating elements of cartesian products of sets.

→ Examples

Superdomain

Dom::BaseDomain

Categories

Cat::CombinatorialClass

Axioms

Ax::systemRep

Details:

Entries

"domtype"

The MuPAD domain used to represent cartesian products: DOM_LIST

Methods

isA – test if an object is a cartesian product

combinat::cartesianProduct::isA(any type cp, <set or list or nonnegative integer S1, ...,set or list or nonnegative integer Sk>)

Returns whether the object cp is an element of a cartesian product.

If optional arguments are present, returns whether cp is a an element of the cartesian product math.

count – number of elements of a cartesian product

combinat::cartesianProduct::count(set S1, set S2, ...,set Sk)

Returns the number of elements of the cartesian product math.

generator – generator for the elements of a cartesian product

combinat::cartesianProduct::generator(set S1, set S2, ...,set Sk)

Returns a generator for the elements of the cartesian product math.

list – list of the elements of a cartesian product

combinat::cartesianProduct::list(set S1, set S2, ...,set Sk)

Returns the list of the elements of the cartesian product math.

Example 1:

In this example we show how to check whether we have an element of a cartesian product of some sets. The sets can be represented either by a list, a set or a non negative integer.

combinat::cartesianProduct::isA([2, 3, 4], {1, 2}, [a, 3], 7);

combinat::cartesianProduct::isA([2, 3, 4, d], 2, 3, 4, {a, d});

combinat::cartesianProduct::isA([2, 3, 4, d], 2, 1, 4, {a, d});

combinat::cartesianProduct::isA([2, 3, 4, d], 2, 3);

math

math

math

math

If no optional argument is provided (i.e. the sets), the function tests whether an object makes sense as an element of a cartesian product.

combinat::cartesianProduct::isA([2, 3, 4, d]);

combinat::cartesianProduct::isA([ ]);

combinat::cartesianProduct::isA(a);

math

math

math

Example 2:

There are math elements in the cartesian product of the sets {1,2,3} and {a,b,c,d}:

combinat::cartesianProduct::count({1,2,3},{a,b,c,d});

math

Here is the list:

combinat::cartesianProduct::list({1,2,3},{a,b,c,d});

math

When you want to run through the elements of a cartesian product you can generate them one by one to save memory:

g := combinat::cartesianProduct::generator({1,2},{a,b}):

g(); g(); g(); g(); g()

math

math

math

math

math

Typically, this would be used as follows:

g := combinat::cartesianProduct::generator({1,2},{a,b}):

while (p := g()) <> FAIL do print(p): end:

[1, a]

 

[1, b]

 

[2, a]

 

[2, b]

 

Example 3:

Each input set can be represented by a set, a list, or a number:

combinat::cartesianProduct::list({a,b},[x,y],2);

math

The empty cartesian product has one element:

combinat::cartesianProduct::list();

math

When any one of the sets is empty, the cartesian product is also empty:

combinat::cartesianProduct::list(2,0);

math

The cartesian product is not commutative:

combinat::cartesianProduct::list({Diamondsuit},2);

combinat::cartesianProduct::list(2,{Diamondsuit})

math

math

Example 4:

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

combinat::cartesianProduct::list(

          {Diamondsuit,Heartsuit,Spadesuit,Clubsuit},

          {7,8,9,10})

math