Skip to content

WeakCompositions ​

The weak compositions of nn into kk parts: ordered sequences of kk non-negative integers summing to nn, unlike IntegerCompositions where every part must be positive.

✓ checked against that system · ! checked, with disagreements (hover a chip)OEISA178300✓
WeakCompositions(n, k)the (n+k−1k−1)\binom{n+k-1}{k-1} sequences of kk non-negative parts summing to nn
CombinatoricaCompositions[n, k]
Typed signatures
TypePackageApplies
(integer<0..>, integer<0..>) -> indexed_collection<list<integer>>combinatoricsalways

Domain: Collections

Examples

Basic #

(62)=15\binom{6}{2} = 15

live ↗
InCount(WeakCompositions(4,3))\mathrm{Count}(\mathrm{WeakCompositions}(4, 3))Out1515

Parts may be zero

live ↗
InTake(WeakCompositions(2,2),3)\mathrm{Take}(\mathrm{WeakCompositions}(2, 2), 3)Out[[0,2],[1,1],[2,0]]\bigl\lbrack\bigl\lbrack0, 2\bigr\rbrack, \bigl\lbrack1, 1\bigr\rbrack, \bigl\lbrack2, 0\bigr\rbrack\bigr\rbrack
About
Examples2
Checked againstCombinatorica 2 agree
CrosswalkOEISCombinatorica

Implementation

mappedcombinatoricapackages/oracle/src/mappings.ts

Combinatorica's Compositions[n, k] allows zero parts: ours is WeakCompositions, not the strict IntegerCompositions.

See also: IntegerCompositions