Calculators
Integer Composition Calculator
Count exact ordered sums with a fixed number of positive or nonnegative integer parts, privately in your browser.
Enter a total and number of parts from 0 to 1000. Order matters: 1 + 4 and 4 + 1 are different. Compare positive parts (at least 1) with nonnegative parts (zeros allowed). Results stay in your browser.
Count ordered sums with stars and bars
An integer composition writes n as an ordered sum of k parts. Order matters: 1 + 4 and 4 + 1 are different compositions of 5 into two parts. With positive parts, each part is at least 1 and the count is C(n − 1, k − 1) when n ≥ k ≥ 1; otherwise it is zero. With nonnegative parts, zeros are allowed and the stars-and-bars count is C(n + k − 1, k − 1) for k ≥ 1. For n = 5 and k = 2, there are 4 positive compositions and 6 nonnegative compositions. For n = 0 and positive k, there are no positive compositions and one all-zero nonnegative composition. With zero parts, the empty sum gives one composition only when n = 0; other totals give zero. These counts differ from integer partitions, where order does not matter, and from set partitions, which group distinct items. Inputs accept whole numbers from 0 to 1000 using one to four digits. Leading zeros and surrounding whitespace are accepted; signs, decimals, separators and scientific notation are rejected. Exact BigInt binomial arithmetic preserves every result digit. Inputs are not uploaded or stored.
Frequently Asked Questions
Everything you need to know about this tool, how it works, and privacy.
Does the order of parts matter?
Yes. For total 3 and two positive parts, 1 + 2 and 2 + 1 count separately. Use the Partition Number Calculator for unordered sums.
What is the difference between positive and nonnegative parts?
Positive parts must be at least 1. Nonnegative parts may be zero. For total 5 and two parts, there are 4 positive compositions and 6 nonnegative compositions.
How are zero total and zero parts handled?
Zero parts give one empty composition for total zero, and zero compositions otherwise. With a positive number of parts and total zero, only the nonnegative model has one all-zero composition.
Are large counts exact and private?
Yes. Inputs from 0 to 1000 use exact browser BigInt arithmetic. No inputs are uploaded or stored.