combinat::subsets – subsets of a set
The library combinat::subsets provides functions for counting, generating, and manipulating the subsets of a set.
Superdomain
Categories
Axioms
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 .
Returns the number of subsets of s of size k.
Returns the number of subsets of 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 .
Returns a generator for the subsets of s of size k.
Returns a generator for the subsets of 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 .
Returns the list of the subsets of s of size k.
Returns the list of the subsets of 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 .
Returns the first subset of s of size k, or FAIL if there is none.
Returns the first subset of 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 .
Returns the last subset of s of size k.
Returns the last subset of 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 .
Returns a random subset of of size k.
Complexity in time and memory: without size argument, and with (Floyd's algorithm).
There are subsets of 1,2,3:
combinat::subsets::count(3);
combinat::subsets::count({1,2,3})
There are subsets of size in a set of size :
combinat::subsets::count(6,2);
combinat::subsets::count({a,b,c,d,e,f},2)
Here is the list of the subsets of a,b,c,d,e of size :
combinat::subsets::list({a,b,c,d,e}, 3)
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);
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);
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()
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}