Compositions of an integer
This functionality does not run in MATLAB.
combinat::compositions(n
, <MinPart = k
>, <MaxPart = l
>, <Length = m
>)
combinat::compositions(n)
returns all compositions
of the nonnegative integer n
.
A composition of a nonnegative integer n
is
a list of positive integers with total sum n
.
We output all compositions of the integer 4:
combinat::compositions(4)
It is possible to output only the compositions of a certain length:
combinat::compositions(4, Length=2)
The options MinPart
and MaxPart
can
be used to set constraints on the sizes of all parts. Using MaxPart
,
you can select compositions having only small entries. This is the
list of the compositions of 4 with
all parts at most 2:
combinat::compositions(4, MaxPart=2)
MinPart
is complementary to MaxPart
and
selects compositions having only large parts (it takes a nonnegative
value). This is the list of the compositions of 4 with
all parts at least 2:
combinat::compositions(4, MinPart=2)
By default, the parts of a composition have to be positive.
This can be changed using the option MinPart
. In
the following example, the options Length
and MinPart
are
combined together to obtain the list of the compositions of 4 with 3 nonnegative
parts:
combinat::compositions(4, Length=3, MinPart=0)
If no length is given, MinPart=0
is not allowed.

Nonnegative integer 

Option, specified as Return only compositions consisting of integers greater or equal
than 

Option, specified as Return only compositions consisting of integers less or equal
than 

Option, specified as Return only compositions consisting of exactly 