combinat::choose -- Computes all
k-subsets of a given set
Introductioncombinat::choose(set,k) computes all
k-subsets of the given set set
combinat::choose(N,k) computes all
k-subsets of the set setN where setN
= 1,2,...,N.
Call(s)combinat::choose(set,k)
combinat::choose(N,k)
Parametersset |
- | a set of domain type DOM_SET |
k |
- | a nonnegative integer |
N |
- | a nonnegative integer |
Returnscombinat::choose returns an expression sequence,
consisting of the computed subsets.
Example
1Compute all the subsets of a,b,c,d,e containing 3 elements
>> combinat::choose({a,b,c,d,e},3)
{c, d, e}, {b, d, e}, {a, d, e}, {b, c, e}, {a, c, e},
{a, b, e}, {b, c, d}, {a, c, d}, {a, b, d}, {a, b, c}
Example
2Compute all the subsets of 1,2,3 containing 2 elements
>> combinat::choose(3,2)
{2, 3}, {1, 3}, {1, 2}
Example
3It's not a good idea to compute the subsets containing -1 element
>> combinat::choose({a,3},-1)
Error: Second argument must be a nonnegative integer [combinat\
::choose]