Weak Composition Calculator

Stars and bars counting

CalculatorsFreeNo Signup
4.8(61 reviews)
All Tools

Loading tool...

About Weak Composition Calculator

A weak composition calculator counting ordered sequences of k non-negative integers summing to n. Formula: C(n+k-1, k-1) by stars and bars. Unlike strict compositions, parts can be zero. Shows all weak compositions for small values. Client-side.

Weak Composition Calculator Features

  • Count C(n+k-1,k-1)
  • Stars and bars
  • List all
  • Distribution
  • Comparison
Weak compositions of n into k parts: ordered k-tuples of non-negative integers summing to n. Count: C(n+k-1,k-1) by stars and bars. Example: n=3, k=2: (0,3),(1,2),(2,1),(3,0) = C(4,1)=4.

How to Use

Enter n and k:

  • Count: C(n+k-1,k-1)
  • List: All distributions
  • Stars/bars: Visual

Stars and Bars

n stars (items) and k-1 bars (dividers). Any arrangement gives a weak composition. Total positions: n+k-1. Choose k-1 for bars: C(n+k-1,k-1). Beautiful correspondence between arrangements and distributions!

Applications

Distributing identical items (cookies to children), polynomial terms (x+y+z)^n count, multivariate power series, integer lattice points, and random allocation problems all use weak compositions.

Step-by-Step Instructions

  1. 1Enter n items.
  2. 2Enter k bins.
  3. 3Compute count.
  4. 4View distributions.
  5. 5See stars/bars.

Weak Composition Calculator — Frequently Asked Questions

How does this differ from strict compositions?+

Strict: all parts ≥ 1, count = C(n-1,k-1). Weak: parts ≥ 0, count = C(n+k-1,k-1). Weak = strict of (n+k) into k parts, by substituting kᵢ'=kᵢ+1. The weak count is always larger.

What is stars and bars intuitively?+

Imagine n identical cookies and k children. Line up n cookies (stars ★) and place k-1 dividers (bars |) among them. Example: ★★|★||★★★ gives (2,1,0,3). Total arrangements: C(n+k-1,k-1).

What about upper bounds on parts?+

If each part kᵢ ≤ m, the count becomes more complex (inclusion-exclusion). No simple closed form exists. But generating functions handle it: coefficient of x^n in ((1-x^{m+1})/(1-x))^k.

Share this tool: