Video failed to load

Ranked Subset Convolution: Enforce Disjointness with One Extra Dimension

502 words
3 minutes
Ranked Subset Convolution: Enforce Disjointness with One Extra Dimension

Many hard bitmask problems ask you to split a set into disjoint roles. A subset zeta transform efficiently handles unions, but a union is not necessarily a partition. Ranked subset convolution adds exactly the information needed to tell them apart.

Assume basic subset enumeration and zeta transforms. Our target is

h(S)=∑T⊆Sf(T)g(S∖T).h(S)=\sum_{T\subseteq S} f(T)g(S\setminus T).

Computing this independently for every SS costs ∑S2∣S∣=3n\sum_S2^{|S|}=3^n. The fast method costs O(n22n)O(n^2 2^n) over a ring with subtraction.

Why the tempting transform fails#

Define f^(S)=∑T⊆Sf(T)\widehat f(S)=\sum_{T\subseteq S}f(T) and similarly for gg. Multiplying the transformed values enumerates pairs A,B⊆SA,B\subseteq S. After Mobius inversion, it selects pairs with A∪B=SA\cup B=S, but it does not exclude A∩B≠∅A\cap B\ne\varnothing.

For S={a,b}S=\{a,b\}, the pair A={a},B={a,b}A=\{a\},B=\{a,b\} survives that union condition. It is invalid for our partition because aa was used twice. The missing invariant is the total number of used elements.

Rank the inputs#

Create layers fk(S)=f(S)f_k(S)=f(S) when ∣S∣=k|S|=k, and zero otherwise. Zeta-transform each layer:

Fk(S)=∑T⊆S, ∣T∣=kf(T).F_k(S)=\sum_{T\subseteq S,\ |T|=k}f(T).

At each mask, multiply these short polynomials in rank:

Ck(S)=∑j=0kFj(S)Gk−j(S).C_k(S)=\sum_{j=0}^k F_j(S)G_{k-j}(S).

Now Mobius-invert every rank layer over subsets. Its value ck(S)c_k(S) counts pairs with union exactly SS and ∣A∣+∣B∣=k|A|+|B|=k. Finally select h(S)=c∣S∣(S)h(S)=c_{|S|}(S).

Why does that last equality enforce disjointness? Because

∣A∣+∣B∣=∣A∪B∣+∣A∩B∣.|A|+|B|=|A\cup B|+|A\cap B|.

If the union already equals SS, choosing rank ∣S∣|S| forces the intersection to be empty. We used a scalar measurement to recover a structural constraint.

Explore weighted partitions#

Let the universe have three elements. Give a set weight f(T)=1+∑i∈T(i+1)f(T)=1+\sum_{i\in T}(i+1) and g(T)=2∣T∣g(T)=2^{|T|}. The lab lists every ordered partition of a chosen mask. The two sides have separate roles, so exchanging them generally changes the contribution.

For S = {a, b}, the four partitions contribute 4 + 4 + 6 + 4 = 18. Enable JavaScript to explore all eight masks.

This tiny enumeration is the independent specification against which the fast transform should be tested. It is intentionally different from the internal rank representation.

Implementation shape#

put f[S] in layer popcount(S)
put g[S] in layer popcount(S)
zeta-transform every layer
for each S:
multiply the rank polynomials at S, keeping ranks 0..n
Mobius-invert every output layer
answer[S] = output[popcount(S)][S]

The C++ companion implements this as subset_convolution. It accepts equal power-of-two arrays, including a length-one universe with no elements. Modular subtraction must be normalized; unsigned underflow is not a substitute for subtraction in the intended field.

Memory often becomes the real constraint#

Each of the three layer tables uses (n+1)2n(n+1)2^n coefficients. For n=20n=20 and four-byte coefficients, that is about 84 MiB per table before vector overhead. Three simultaneous tables can exceed a 256 MiB limit. Reusing layers, streaming selected outputs, or exploiting a problem-specific sparse support can matter more than a small constant optimization in the transform loops.

Do not replace arithmetic addition with min and expect the same algorithm: Mobius inversion needs additive inverses. Min-plus subset convolution is a different problem, with different assumptions and bounds.

Exercise. Let ff count valid nonempty connected groups. Explain how repeated subset convolution can count ordered decompositions into kk groups. Then determine what extra argument is needed to turn ordered groups into unordered groups; dividing by k!k! requires a field where this factorial is invertible and a symmetry argument that actually applies.

Support & Share

If this article helped you, please share or support!

Sponsor
Ranked Subset Convolution: Enforce Disjointness with One Extra Dimension
https://blog.wsh.moe/posts/ranked-subset-convolution/
Author
Wsh
Published at
2026-10-24

Comments

LEAVE A NOTE

Join the conversation

Markdown supported

Be kind. Good conversations start with you.

Conversation

Loading conversation…

Comments powered by Waline

Profile Image of the Author
Wsh
Nice to meet you! Hello, I'm Wsh.
Announcement
Any news or updates will be shared here, so check back anytime! Thanks for stopping by, meow >.<
Categories
Tags
Site Statistics
Posts
27
Categories
7
Tags
69
Total Words
124,615
Running Days
0 days
Last Activity
0 days ago
Site Info
Build Platform
Vercel
Blog Version
Firefly v6.16.8
License
CC BY-NC-SA 4.0
Table of Contents