Surjection Counter

Σ(-1)^i·C(k,i)·(k-i)^n

CalculatorsFreeNo Signup
4.7(604 reviews)
All Tools

Loading tool...

About Surjection Counter

A surjection counter computing the number of onto functions from [n] to [k] using inclusion-exclusion: S(n,k) = Σ(-1)^i·C(k,i)·(k-i)^n. Related to Stirling numbers of the second kind: S(n,k) = k!·S₂(n,k). Client-side.

Surjection Counter Features

  • Surjection count
  • Inclusion-exclusion
  • Stirling link
  • Step-by-step
  • Both directions
Surjections from [n] to [k]: functions where every element in [k] is hit. Count by inclusion-exclusion: Σ(-1)^i·C(k,i)·(k-i)^n for i=0..k. Equals k!·S₂(n,k) where S₂ is Stirling 2nd kind. For k=n: = n! (bijections = derangements × 0 + permutations).

How to Use

Enter n (domain) and k (codomain):

  • Count: Number of surjections
  • Steps: Each inclusion-exclusion term
  • Stirling: S₂(n,k) connection

Inclusion-Exclusion

Total functions: k^n. Subtract those missing ≥1 element. Add back those missing ≥2. Etc. Term i: (-1)^i · C(k,i) · (k-i)^n = # functions missing at least i specific targets.

Stirling Connection

S₂(n,k) = surjections / k! = # ways to partition [n] into k non-empty subsets. The surjection count assigns labels (k! orderings) to each partition.

Step-by-Step Instructions

  1. 1Enter domain size n.
  2. 2Enter codomain size k.
  3. 3Compute surjections.
  4. 4View IE steps.
  5. 5Check Stirling.

Surjection Counter — Frequently Asked Questions

When do surjections exist?+

Only when n ≥ k (pigeonhole: can't cover k elements with fewer than k inputs). For n < k, surjection count = 0. For n = k, count = k! (bijections only). For n > k, count grows rapidly.

How is this related to Stirling numbers?+

S₂(n,k) = (1/k!)·Σ(-1)^i·C(k,i)·(k-i)^n. Each surjection corresponds to a partition of [n] into k labeled non-empty blocks. Removing labels (dividing by k!) gives Stirling numbers of the second kind.

What's a practical application?+

Distributing n distinct objects into k distinct non-empty boxes. Also: hash function collision analysis (probability all k bins are non-empty with n balls), the coupon collector problem, and chromatic polynomials in graph theory.

Share this tool: