Compositions Calculator

2^(n-1) ordered sums

CalculatorsFreeNo Signup
4.8(401 reviews)
All Tools

Loading tool...

About Compositions Calculator

A compositions calculator listing all ordered sums k₁+k₂+...+kₘ = n with kᵢ≥1. Unlike partitions, order matters: 2+1 ≠ 1+2. Total: 2^(n-1). Shows all compositions, counts by number of parts, and restricted compositions. Client-side.

Compositions Calculator Features

  • All compositions
  • Count 2^(n-1)
  • Parts count
  • Restricted
  • Weak compositions
Compositions of n: ordered sums k₁+...+kₘ=n with kᵢ≥1. Total: 2^(n-1) (stars and bars with order). Compositions of 3: 3, 2+1, 1+2, 1+1+1 = 4 = 2². With exactly k parts: C(n-1,k-1). Compositions relate to binary strings of length n-1.

How to Use

Enter n:

  • Count: 2^(n-1)
  • List: All compositions
  • By parts: Group by # of parts

Binary String Bijection

Each composition of n ↔ binary string of length n-1. Place 0/1 between consecutive 1's: 1 = 'cut here'. Example: 3+1+2 for n=6 ↔ 00101 (cuts after positions 3 and 4). This proves count = 2^(n-1).

Weak Compositions

If kᵢ≥0 (zeros allowed) with k parts: C(n+k-1,k-1) by stars and bars. Weak compositions of 3 into 3 parts: C(5,2)=10, including (0,0,3), (1,1,1), etc.

Step-by-Step Instructions

  1. 1Enter n.
  2. 2See count.
  3. 3List all.
  4. 4Group by parts.
  5. 5Try restrictions.

Compositions Calculator — Frequently Asked Questions

Why 2^(n-1)?+

Think of n as n dots in a row. There are n-1 gaps between consecutive dots. Each gap is either 'cut' or 'not cut' (2 choices each). Cutting creates parts. With n-1 binary choices: 2^(n-1) compositions.

How many compositions with exactly k parts?+

C(n-1,k-1). Proof: choose k-1 of the n-1 gaps to cut. This creates exactly k parts, each ≥1. These are the 'stars and bars' (strict version). Summing over k: Σ C(n-1,k-1) = 2^(n-1). ✓

What are restricted compositions?+

Add constraints: parts ≤ M, parts ∈ {1,2}, parts are odd, etc. Example: compositions of n into parts 1 and 2 count the Fibonacci sequence! F(n+1) such compositions exist. Generating functions handle general restrictions.

Share this tool: