combinat::subsets – subsets of a set

The library combinat::subsets provides functions for counting, generating, and manipulating the subsets of a set.

→ Examples

Superdomain

Dom::BaseDomain

Categories

Cat::CombinatorialClass

Axioms

Ax::systemRep

Entries

"domtype"

The MuPAD domain used to represent subsets: DOM_SET

count – number of subsets

combinat::subsets::count(set s)

combinat::subsets::count(nonnegative integer n)

combinat::subsets::count(set s, nonnegative integer k)

combinat::subsets::count(nonnegative integer n, nonnegative integer k)

Returns the number of subsets of s.

Returns the number of subsets of math.

Returns the number of subsets of s of size k.

Returns the number of subsets of math of size k.

generator – generator for subsets

combinat::subsets::generator(set s)

combinat::subsets::generator(nonnegative integer n)

combinat::subsets::generator(set s, nonnegative integer k)

combinat::subsets::generator(nonnegative integer n, nonnegative integer k)

Returns a generator for the subsets of s.

Returns a generator for the subsets of math.

Returns a generator for the subsets of s of size k.

Returns a generator for the subsets of math of size k.

list – list of the subsets

combinat::subsets::list(set s)

combinat::subsets::list(nonnegative integer n)

combinat::subsets::list(set s, nonnegative integer k)

combinat::subsets::list(nonnegative integer n, nonnegative integer k)

Returns the list of the subsets of s.

Returns the list of the subsets of math.

Returns the list of the subsets of s of size k.

Returns the list of the subsets of math of size k.

first – first subset

combinat::subsets::first(set s)

combinat::subsets::first(nonnegative integer n)

combinat::subsets::first(set s, nonnegative integer k)

combinat::subsets::first(nonnegative integer n, nonnegative integer k)

Returns the first subset of s.

Returns the first subset of math.

Returns the first subset of s of size k, or FAIL if there is none.

Returns the first subset of math of size k, or FAIL if there is none.

last – last subset

combinat::subsets::last(set s)

combinat::subsets::last(nonnegative integer n)

combinat::subsets::last(set s, nonnegative integer k)

combinat::subsets::last(nonnegative integer n, nonnegative integer k)

Returns the last subset of s.

Returns the last subset of math.

Returns the last subset of s of size k.

Returns the last subset of math of size k.

random – random subset

combinat::subsets::random(set s)

combinat::subsets::random(set s, nonnegative integer k)

combinat::subsets::random(nonnegative integer n)

combinat::subsets::random(nonnegative integer n, nonnegative integer k)

Returns a random subset of s.

Returns a random subset of s of size k.

Returns a random subset of math.

Returns a random subset of math of size k.

Complexity in time and memory: math without size argument, and math with (Floyd's algorithm).

Example 1:

There are math subsets of 1,2,3:

combinat::subsets::count(3);

combinat::subsets::count({1,2,3})

math

math

There are math subsets of size math in a set of size math:

combinat::subsets::count(6,2);

combinat::subsets::count({a,b,c,d,e,f},2)

math

math

Here is the list of the subsets of a,b,c,d,e of size math:

combinat::subsets::list({a,b,c,d,e}, 3)

math

You can use the functions combinat::subsets::first and combinat::subsets::last to get the “first” and “last” subset of a set:

combinat::subsets::first(4);

combinat::subsets::first({1,2,3,4});

combinat::subsets::first(4,2);

combinat::subsets::first({1,2,3,4},2);

combinat::subsets::last(4);

combinat::subsets::last({1,2,3,4});

combinat::subsets::last(4,2);

combinat::subsets::last({1,2,3,4},2);

math

math

math

math

math

math

math

math

The specified size for the subsets can exceed the size of the set itself:

combinat::subsets::count({1,2,3}, 4);

combinat::subsets::list({1,2,3}, 4);

combinat::subsets::first({1,2,3}, 4);

math

math

math

When you want to run through the subsets of a set, you can generate them one by one to save memory:

g := combinat::subsets::generator(3):

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

math

math

math

math

math

math

Typically, this would be used as follows:

g := combinat::subsets::generator(4,2):

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

{1, 2}

 

{1, 3}

 

{1, 4}

 

{2, 3}

 

{2, 4}

 

{3, 4}