# Revision history [back]

A composition of a nonnegative integer n is an ordered list of positive integers with total sum n, so you can call Compositions, specifying the maximum term:

sage: P = Compositions(4, max_part=2)
sage: P.list()
[[2, 2], [2, 1, 1], [1, 2, 1], [1, 1, 2], [1, 1, 1, 1]]
sage: list(P)
[[2, 2], [2, 1, 1], [1, 2, 1], [1, 1, 2], [1, 1, 1, 1]]

sage: list(Compositions(7, max_part=3))
[[3, 3, 1], [3, 2, 2], [3, 2, 1, 1], [3, 1, 3], [3, 1, 2, 1], [3, 1, 1, 2], [3, 1, 1, 1, 1], [2, 3, 2], [2, 3, 1, 1], [2, 2, 3], [2, 2, 2, 1], [2, 2, 1, 2], [2, 2, 1, 1, 1], [2, 1, 3, 1], [2, 1, 2, 2], [2, 1, 2, 1, 1], [2, 1, 1, 3], [2, 1, 1, 2, 1], [2, 1, 1, 1, 2], [2, 1, 1, 1, 1, 1], [1, 3, 3], [1, 3, 2, 1], [1, 3, 1, 2], [1, 3, 1, 1, 1], [1, 2, 3, 1], [1, 2, 2, 2], [1, 2, 2, 1, 1], [1, 2, 1, 3], [1, 2, 1, 2, 1], [1, 2, 1, 1, 2], [1, 2, 1, 1, 1, 1], [1, 1, 3, 2], [1, 1, 3, 1, 1], [1, 1, 2, 3], [1, 1, 2, 2, 1], [1, 1, 2, 1, 2], [1, 1, 2, 1, 1, 1], [1, 1, 1, 3, 1], [1, 1, 1, 2, 2], [1, 1, 1, 2, 1, 1], [1, 1, 1, 1, 3], [1, 1, 1, 1, 2, 1], [1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 1, 1, 1]]


A composition of a nonnegative integer n is an ordered list of positive integers with total sum n, so you can call Compositions, specifying the maximum term:

sage: P = Compositions(4, max_part=2)
sage: P.list()
[[2, 2], [2, 1, 1], [1, 2, 1], [1, 1, 2], [1, 1, 1, 1]]
sage: list(P)
[[2, 2], [2, 1, 1], [1, 2, 1], [1, 1, 2], [1, 1, 1, 1]]

sage: list(Compositions(7, list(Compositions(12, length=7, max_part=3))
[[3, 3, 1], [3, 2, 2], [3, 2, 1, 1], [3, 1, 3], [3, 1, 2, 1], [3, 1, 1, 2], [3, 1, 1, 1, 1], [2, 3, 2], [2, 3, 1, 1], [2, 2, 3], [2, 2, 2, 1], [2, 2, 1, 2], [2, 2, 1, 1, 1], [2, 1, 3, 1], [2, 1, 2, 2], [2, 1, 2, 1, 1], [2, 1, 1, 3], [2, 1, 1, 2, 1], [2, 1, 1, 1, 2], [2, 1, 1, 1, 1, 1], [1, 3, 3], [1, 3, 2, 1], [1, 3, 1, 2], [1, 3, 1, 1, 1], [1, 2, 3, 1], [1, 2, 2, 2], [1, 2, 2, 1, 1], [1, 2, 1, 3], [1, 2, 1, 2, 1], [1, 2, 1, 1, 2], [1, 2, 1, 1, 1, 1], [1, 1, [3, 3, 2], [1, 1, 3, 1, 1], [1, 1, 2, 3], [1, 1, 2, 2, 1], [1, 1, 2, 1, 2], [1, 1, 2, 1, 1, 1], [1, 1, 1, [3, 3, 1], [1, 1, 1, 2, 2], [1, 1, 1, 2, 1, 1], [1, 1, 1, 1, 3], [1, 1, 1, 1, 2, 1], [1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 1, 1, 1]]
...