Permutation / Combination / Subset Generator Field Guide: When Multinomial Divisor, Generating-Function Coefficient, and the Empty-Set Corner Case Decide Whether Your Multiset Count Lands at 12 or 24

Permutation, Combination, Subset Generator field guide — three streams decide your count is correct

Three output streams decide whether your enumerator is the textbook one. When a multiset has repeated elements — three As, two Bs, one C — your count of permutations has to collapse duplicates via the multinomial divisor Π(mᵢ!), your combinations have to be distinct k-sub-multisets counted by the generating-function coefficient, and your subsets have to total Π(mᵢ + 1) including the empty set. Get any of those three wrong and your “combinations of 4 from {A,A,B,C}” reads as 4 instead of 2. The Permutation / Combination / Subset Generator (With Repeats) tool at Elysia Tools gives you all three streams in lexicographic order, deduplicated, with the math under the hood spelled out so you can audit every count.

If you only need single-mode arithmetic — the C(n,k) answer or the n! of a permutation — the simpler Combination Calculator covers that. The generator here is for the cases where the items aren’t distinct, where the count crosses a factorial ceiling, or where you need to see the actual list rather than just the number.

What the three output streams actually count

The generator has three modes, and each one answers a different question about the same input multiset. Permutations tell you every ordered arrangement — including arrangements that look identical when items repeat. Combinations tell you every unordered selection of k items, drawn from the multiset, without replacement, counted by the generating-function coefficient C_multiset(n, k) which equals the usual C(n, k) when items are distinct and shrinks otherwise. Subsets tell you every sub-multiset including the empty set, with the count Π(mᵢ + 1) baked into the display.

When the input is {A, B, C} with three distinct items, all three counts coincide in their “no-repeat” corner: 6 permutations, 3 combinations of 2, and 8 subsets including empty. The interesting case starts when an item appears twice.

Why “permutations of {A, A, B}” is 3, not 6

The naïve count 3! = 6 double-counts because swapping the two As doesn’t produce a new arrangement. The corrected formula n! / Π(mᵢ!) gives 3! / (2! · 1!) = 3. The canonical list is AAB, ABA, BAA. The generator uses next_permutation on the sorted multiset, which visits every distinct permutation exactly once and stops at the lexicographic ceiling — the same algorithm Knuth covers in TAOCP Volume 4A.

Why permutations of multiset A,A,B,C is 12 not 24 — five-tile formula breakdown showing multinomial divisor

If you skip the divisor and call 3! = 6 “permutations of AAB”, your downstream code will over-count by exactly the multinomial factor, and every binomial probability you compute off that count inherits the error. For a multiset with frequencies (2, 3, 1), the divisor is 2! · 3! · 1! = 12, so n! / 12 — that’s how 720 becomes 60 for a 6-element multiset with that frequency pattern.

The combination formula when items repeat: generating-function coefficients

When you ask the generator for combinations of 3 from {A, A, B, C}, it does not return C(4, 3) = 4. It returns 2: {AAB, ABC}. The formula is the coefficient of x^k in Π(1 + x + x² + … + x^(mᵢ)) — the generating function where each item contributes a polynomial term equal to its multiplicity. For distinct items, that product reduces to (1 + x)^n and the coefficient is C(n, k). For repeats, the polynomial for an item with multiplicity mᵢ is (1 + x + … + x^mᵢ), and the product’s x^k coefficient gives the distinct-k-sub-multisets count.

Combinations of k from a multiset — generating-function coefficient audit, two-column checklist and result

This is why the generator requires 1 ≤ k ≤ n for combination mode — k = 0 and k = n are corner cases that the subset mode handles more cleanly (the empty set and the full multiset itself).

Subsets total Π(mᵢ + 1) — the empty set is included

Subsets mode returns every sub-multiset including the empty set. For {A, A, B, C} with frequencies (2, 1, 1), the count is (2 + 1) · (1 + 1) · (1 + 1) = 12. The list: ∅, A, A, AA, B, AB, AAB, C, AC, AAC, BC, ABC, AAC. Wait — that’s the multiset-subset listing where each sub-multiset appears once even if it has multiple derivation paths. The generator dedups so “A” appears once even though it can be picked via the first or second A.

The empty set is always included by convention — it matches the algebraic identity Π(mᵢ + 1) when k = 0 across all items. If your application expects “non-empty subsets”, subtract 1 from the count and drop the ∅ entry from the list.

The display cap is 200 entries, but the counts stay exact

When you ask for permutations of a 10-item multiset with frequencies (3, 2, 2, 2, 1), the count is 10! / (3! · 2! · 2! · 2! · 1!) = 151,200. The generator caps the rendered list at 200 entries — it shows the first 200 in lexicographic order and reports the exact total. The cap exists because rendering 151K strings blows past any browser’s tolerance, but the count is computed by the multinomial formula not by walking the list, so the display limit doesn’t corrupt the answer.

If you need the full list rather than just the count, you have two paths: narrow the multiset until the count fits under 200, or use a different tool that streams to a file. The generator is the right choice for math correctness and lexicographic preview, not for bulk export.

When this generator disagrees with a hand-rolled loop

The two failure modes are: (1) over-counting from skipping the multinomial divisor, which the generator never does; and (2) missing the generating-function reduction in combination mode, where a hand-rolled itertools.combinations_with_replacement call will return the right list but won’t dedup identical-item selections when the input multiset itself contains duplicates. Python’s combinations_with_replacement("AAB", 2) returns 3 entries: AA, AB, BB — but the multiset-subset count for {A,A,B} at k=2 is 2 (AA, AB), not 3, because BB is impossible from a multiset with one B.

Four multisets where the tool dedups and a hand-rolled loop over-counts — comparison card

The generator handles both: the multinomial divisor dedups identical permutations, and the generating-function coefficient dedups identical combinations. If you find yourself computing 3 when the tool reports 2 for “combinations of 2 from AAB”, trust the tool and trace your code — the most likely culprit is combinations_with_replacement being applied to a multiset without a dedup pass.

The empty-set corner case and what k = n actually means

The generator enforces 1 ≤ k ≤ n in combination mode for a reason: k = 0 is the empty selection (better expressed via subsets mode) and k = n is “the entire multiset” (also better expressed as a single subset). If you ask for combinations of 4 from {A, A, B, C}, k = n = 4 returns exactly one entry: {A, A, B, C} itself. The generating-function coefficient at x^4 in (1 + x + x²)(1 + x)(1 + x) is 1, matching.

The empty set ∅ is included in subset mode by convention, contributing 1 to the total Π(mᵢ + 1) count. If your downstream application expects non-empty subsets only, subtract 1 and drop ∅ from the rendered list — but keep it in the count formula unless you’re certain the application ignores the empty-set case.

Where this fits between Pascal’s Triangle and the Binomial Distribution

The generator sits in a small family of combinatorics tools. For the closed-form C(n,k) value of a single combination without enumerating the list, the Combination Calculator is faster. For the row-by-row construction of binomial coefficients — the standard way to read off Pascal’s-triangle values — Pascal’s Triangle Generator does that. For the probability mass function P(X = k) for k successes in n trials with success probability p, the Binomial Distribution Calculator handles that.

The generator here is the connector — the tool you reach for when you need to actually look at the list of permutations or combinations, when the items repeat, or when the count itself is the answer you want spelled out. It pairs naturally with Pascal’s Triangle when you’re verifying that C(n, k) = C(n, n-k) on a multiset: the generating-function coefficient gives you the multiset count, and Pascal’s row gives you the distinct-item baseline, so the ratio between the two is the multiplicity correction.

Explore more combinatorial tools at Elysia Tools.

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply

    Your email address will not be published. Required fields are marked *