<<Multisets`Multisets`

Multisets

Multisets[list, k]
       gives a list of all multisets containing at most k elements from list.

Multisets[list, {k}]
       gives all multisets containing exactly k elements.

Multisets[list, {l, m}]
       gives all multisets containing between l and m elements.

Multisets[list, {l, m, d}]
       gives all multisets containing l, l + d, ..., m elements.

Multisets[list, {{(Subscript[k, 1]), (Subscript[k, 2]), ...}}]
       gives all multisets containing (Subscript[k, 1]), (Subscript[k, 2]), ... elements.

Multisets[list, kspec, m]
       limits the result to multisets in which the multiplicity of each element is at most m.

Multisets[list, kspec, {l, m}]
       limits the result to multisets in which the multiplicity of each element is between l and m.

Multisets[list, kspec, {l, m, d}]
       limits the result to multisets in which the multiplicity of each element is restricted to l, l + d, ..., m.

Multisets[list, kspec, {{(Subscript[m, 1]), (Subscript[m, 2]), ...}}]
       limits the result to multisets in which the multiplicity of each element is restricted to (Subscript[m, 1]), (Subscript[m, 2]), ....

Multisets[list, kspec, mspec, c]
       limits the result to the first c multisets.

More Information

Multisets[n, kspec, ...] is equivalent to Multisets[Range[n], kspec, ...].

In Multisets[list, kspec, mspec, ...], a kspec or mspec of All corresponds to {0, Infinity}.

In Multisets[list, kspec, mspec, ...], a kspec or mspec of –k corresponds to {k, Infinity}.

Multisets[list, kspec, ...] orders the multisets with the shortest first, and later elements in list omitted first.

Length[Multisets[list, kspec, mspec]] is equivalent to NumberOfMultisets[list, kspec, mspec].

Examples

All possible multisets containing up to 3 elements:

Multisets[{a,b,c,d},3]

Multisets containing exactly 3 elements:

Multisets[4,{3}]

Multisets with an odd number of elements:

Multisets[{a,b,c},{1,5,2}]

Repeated elements are considered distinct:

Multisets[{a,b,b,a},2]

Multisets with at least two elements in which each element occurs at most twice:

Multisets[{a,b,c},-2,2]

Each element occurs an even number of times:

Multisets[{a,b,c,d},5,{0,Infinity,2}]

All multisets in which each element occurs once, twice or five times:

Multisets[{a,b,c},All,{{1,2,5}}]

The first 20 multisets with an even number of elements in which each element occurs an odd number of times:

Multisets[{0,1},{0,Infinity,2},{1,Infinity,2},20]

Potentially infinite lists of multisets:

Multisets[4,{1,Infinity,9},{5,Infinity,6}]
Multisets[5,{1,Infinity,9},{5,Infinity,6}]
Multisets[5,{1,Infinity,9},{5,Infinity,6},5]

NumberOfMultisets

NumberOfMultisets[list, kspec]
       gives the number of multisets of elements of list where the number of elements is specified by kspec.

NumberOfMultisets[list, kspec, mspec]
       gives the number of multisets where the number of elements is specified by kspec and the multiplicities by mspec.

See Multisets for the possible forms for kspec and mspec.

More Information

NumberOfMultisets[n, kspec, ...] is equivalent to NumberOfMultisets[Range[n], kspec, ...].

NumberOfMultisets supports symbolic calculations.

Examples

The number of multisets containing up to 10 elements:

NumberOfMultisets[{a,b,c,d},10]

The number of multisets containing exactly 12 elements:

NumberOfMultisets[11,{12}]

The number of multisets containing up to 300 elements, none of which occur more than 100 times:

NumberOfMultisets[3,300,100]

Some symbolic calculations:

NumberOfMultisets[n,All,m]

Assuming[n>0,NumberOfMultisets[n,{2n},n]]//TraditionalForm

NumberOfMultisets[a,{b}]/NumberOfMultisets[b,{a}]//FunctionExpand

Assuming[r≥0&&k≥0,NumberOfMultisets[3,{2r},r+k]]