Motivation
A constraint satisfaction problem over a fixed finite relational template H=(D;R1,…,Rs) asks about assignments of values in D to variables subject to constraints Ri(v1,…,vk). Counting the satisfying assignments exactly is the subject of the Dyer–Richerby dichotomy (DR): for every template it is either in FP or #P-complete, and the tractable templates are the strongly balanced ones. Counting modulo a prime p, written #pCSP(H), behaves differently: cancellations modulo p can make more templates tractable, and the classification has to explain how this depends on the algebra of H and on p.
Timeline of the conservative case, where H contains every unary subset of D:
- 2022, Bulatov and Kazeminia classify counting graph homomorphisms modulo every prime (BG).
- 2025, Kazeminia and Bulatov develop reductions and algorithms for modular counting CSPs over general relational structures, with a parity algorithm under conditions on the modular closure (KB).
- 2026, Bulatov and Kazeminia prove that a conservative template whose modular closure has no Mal'tsev polymorphism gives a #pP-complete problem, and give a polynomial-time algorithm at p=2 under the complementary condition (BK, BKF). The odd-prime conservative branch remained open.
- Xie (STOC 2027 submission) classifies that branch for every odd prime.
Setting
Let D be a finite nonempty set. A template H on D has finitely many relations Ri⊆Dki of any arity, nullary relations included. H is conservative if every subset U⊆D (including ∅ and D) is one of its unary relations. An instance has variables v0,…,vn−1 and a list of constraints; scopes may repeat variables, and isolated variables are allowed. #pCSP(H) maps an instance to its number of satisfying assignments σ:V→D, modulo p.
A ternary operation h is Mal'tsev if h(x,y,y)=h(y,y,x)=x. A polymorphism of H is an operation of any arity preserving every relation of H coordinatewise. A relation is in pp(H) if it is defined by a primitive positive formula: conjunctions of template atoms and equalities under ordinary existential quantifiers.
For R∈pp(H) and a grouping of its coordinates into x,y,z with x,y nonempty, the witness-count matrix is MR(a,b)=∣{c:(a,b,c)∈R}∣. A nonnegative matrix is block-rank-one if its positive support is a disjoint union of blocks Ai×Bi (pairwise disjoint row sets, pairwise disjoint column sets) on each of which it has rank one. H is strongly balanced if every MR is block-rank-one over the integers.
For a three-element C={c0,c1,d}⊆D with q(c0)=q(c1)=0 and q(d)=1,
QC={(z1,z2,z3,z4)∈C4: q(z1)⊕q(z2)⊕q(z3)⊕q(z4)=0},
one relation for each choice of the singleton fibre {d}.
Formalization targets
Goal: Theorem 1
For every finite nonempty D and every conservative H on D:
p∈{3,5}:#pCSP(H)∈FP if H has a Mal’tsev polymorphism, and #pP-complete otherwise;
p≥7 prime:#pCSP(H)∈FP if H is strongly balanced, and #pP-complete otherwise;
on the Mal'tsev branch, strong balance holds iff no QC is pp-definable, so strong balance is equivalent to "Mal'tsev and no QC∈pp(H)"; and the three criteria are decidable on finite codes of templates. Completeness is under polynomial-time Turing reductions. The statement fixes no template, no domain size and no prime.
Milestones
The milestones follow the proof in §14:
- hardness without Mal'tsev: Proposition 11, at every prime;
- the small-prime algorithm: Carbonnel's lemma [BM, Lemma 11] (as quoted), the normal form (Lemma 4), weighted affine Boolean sums over F3,F5 (Lemma 9), and the weighted algorithm (Theorem 2);
- extraction of QC: exact unique-witness compilation, the unweighted binary obstruction, uniform fibres on two-element domains, the minimal-domain matrix lemma, three-state obstruction extraction, and the intrinsic balance criterion;
- the large-prime branch: exact counting for strongly balanced templates [DR, Theorem 28] (as quoted), the modular NAND gadget, hardness from three-state parity, and strong balance ⇒ Mal'tsev [DR, Lemmas 29 and 5] (as quoted);
- decidability: the 41-ary finite arity test.
Significance
The theorem completes the classification of #pCSP(H) for conservative templates at every prime, p=2 having been settled by Bulatov and Kazeminia. It shows that the classification depends on the prime: for the three-state template consisting of QC and all unary subsets of C, the problem is in FP modulo 3 and 5 and #pP-complete modulo every prime p≥7, while exact counting is #P-complete. The weighted algorithm (Theorem 2) is a result in its own right: arbitrary unary Fp weights, zeros included, for every template with a conservative Mal'tsev polymorphism. The intrinsic criterion replaces the infinite family of witness-count matrices by finitely many pp-definability tests of a 41-tuple relation.
The result is proved on paper and has no machine-checked proof. Formalizing it gives the platform its first CSP layer (templates, instances, polymorphisms, pp-definability, gadgets), a polynomial-time Turing reduction model on the published Cook–Levin machines, a #pP class, and the first counting-complexity dichotomy. Three cited results (Carbonnel's lemma, [DR, Theorem 28], [DR, Lemmas 29 and 5]) are milestones in their own right, stated as this paper quotes them.
Difficulty
The first idea for p≥7 is to reduce the exact Dyer–Richerby dichotomy modulo p. That fails in the hardness direction: a non-block-rank-one integer matrix can become block-rank-one modulo p, and an exact #P-hardness reduction need not preserve residues. Hardness modulo p needs an unweighted gadget whose residues, not its integer counts, are those of a hard Boolean relation, and the matrices involved are invertible only at some primes; this is why p=3,5 and p≥7 have different answers.
At p=3,5 the first idea is Gaussian elimination, as for parity. It fails because the sums that arise are weighted sums over affine spaces with arbitrary F3 or F5 weights, zeros included, not sizes of affine spaces, and the reductions of the instance must preserve these weighted sums exactly. On the complexity side, every polynomial-time claim needs an actual machine, and every hardness claim needs a reduction that uses the actual oracle.
Formalization scope
Templates are ConsModCount.Template D: s relations indexed by Fin s, of arity arity i (0 allowed), as sets of tuples Fin (arity i) → D; theorems assume [Fintype D] [DecidableEq D] [Nonempty D]. Conservative means every U : Set D, including ∅, is a unary relation. Instances have n variables and a constraint list; scopes need not be injective. pp-formulas allow equality atoms and ordinary ∃ over D. Strong balance quantifies over every pp-definable relation of every arity and every grouping Fin k ≃ Fin r ⊕ Fin s ⊕ Fin t with r, s ≥ 1, with integer counts. Q C d is stated with C.card = 3 and d ∈ C.
FP, #P and reductions all use the published Cook–Levin machines: FP via CookLevin.IsPolyTimeComputable (residues in the library's unary code, exact counts in the published binary code NPBinary.encodeNat), #P via NQueensComp.NPC.InSharpP, and Turing reductions via a local oracle extension in which one oracle call costs one step, the answers are those of the actual oracle, and the step bound is c(∣x∣+1)d. Instances are coded with the number of variables in unary; non-codes map to 0. Part 4 is Mathlib ComputablePred on finite template codes over Fin n.
A formalization in which every function is polynomial-time, every string is a non-code, or the reduction chooses its own oracle would make parts 1–2 trivial; the definitions rule each of these out. The sanity files prove that the three-state example is conservative, has a Mal'tsev polymorphism and is not strongly balanced, and that a constant function is in FP through an explicit machine.
Contributions welcome: Cook–Levin machine constructions (counting assignments, Gaussian elimination over F2, the F5 quadratic-even elimination), closure of polynomial-time Turing reductions under composition, gadget substitution lemmas, and the universal-algebra layer for conservative minority algebras. The CSP, pp-definability and oracle layers are reusable beyond this mission.
Selected references
- C. Xie, Conservative Modular Counting at Every Odd Prime, STOC 2027 submission (manuscript sha256 c673b4cc…).
- A. A. Bulatov and A. Kazeminia, Modular Counting over 3-Element and Conservative Domains, STACS 2026, LIPIcs 364, 22:1–22:20. https://doi.org/10.4230/LIPIcs.STACS.2026.22 ; full version arXiv:2510.09950v1. https://arxiv.org/abs/2510.09950v1
- A. A. Bulatov and A. Kazeminia, Complexity classification of counting graph homomorphisms modulo a prime number, STOC 2022, 1024–1037. https://doi.org/10.1145/3519935.3520075
- A. Kazeminia and A. A. Bulatov, Modular Counting CSP: Reductions and Algorithms, STACS 2025, LIPIcs 327, 60:1–60:18. https://doi.org/10.4230/LIPIcs.STACS.2025.60
- M. Dyer and D. Richerby, An Effective Dichotomy for the Counting Constraint Satisfaction Problem, SIAM J. Comput. 42(3), 1245–1274, 2013. https://arxiv.org/abs/1003.3879v4
- M. Bodirsky and A. Moorhead, Conservative Maltsev Constraint Satisfaction Problems, arXiv:2505.11395v2, 2026. https://arxiv.org/abs/2505.11395v2
- J.-Y. Cai, X. Chen and P. Lu, Non-negative Weighted #CSPs: An Effective Complexity Dichotomy, arXiv:1012.5659. https://arxiv.org/abs/1012.5659
- J.-Y. Cai and D. P. Szabo, Bounded Degree Nonnegative Counting CSP, MFCS 2022, LIPIcs 241, 27:1–27:16. https://doi.org/10.4230/LIPIcs.MFCS.2022.27