One-hot CNF compilation for fixed-arity finite-domain CSPs #
Given a finite-domain CSP instance F : CSP Rel ℕ over Fin q on declared variables 0, …, N - 1,
CSP.toOneHotCNF q N F sem introduces q Boolean variables v * q + a (a < q) for each source
variable v < N:
CNF.exactlyOneconstraints enforce a unique valuea < qfor everyv < N;- for each constraint
(R, vs) ∈ Fand each disallowed tuplets : List (Fin q)of lengthvs.length(sem R ts = false), the clause(vs.zip ts).map (fun (v, a) => (v * q + a, false))forbids that local assignment.
For fixed domain size q ≥ 1 and arity bound k, the compiled formula uses q * N variables
(linear in N), clauses of width at most max q (max k 2), and preserves exact solution counts
with an explicit assignment bijection (CSP.toOneHotCNFEquiv).
Main definitions #
Cslib.Logic.PL.CSP.finTuples: allFin q-valued lists of a given length.Cslib.Logic.PL.Constraint.toOneHotCNF,Cslib.Logic.PL.Constraint.toOneHotCNFBounded: per-constraint one-hot forbidden-tuple clauses and their width-guarded variant.Cslib.Logic.PL.CSP.toOneHotCNF,Cslib.Logic.PL.CSP.toOneHotCNFBounded: one-hot CNF compilation onN * qBoolean variables and its width-guarded variant.Cslib.Logic.PL.CSP.toOneHotCNFEquiv: explicit bijection between satisfying assignments onFinset.range (N * q)and solutions ofFonFinset.range N.
Main results #
Cslib.Logic.PL.CSP.length_clause_toOneHotCNF_le,Cslib.Logic.PL.CSP.length_clause_toOneHotCNFBounded_le,Cslib.Logic.PL.CSP.validDeclaredInput_toOneHotCNFBounded: clause width at mostmax q (max k 2)and declared-variable bounds.Cslib.Logic.PL.CSP.vars_toOneHotCNF_toFinset: exact occurring variable setrange (N * q)for0 < q.Cslib.Logic.PL.CSP.eval_toOneHotCNF,Cslib.Logic.PL.CSP.modelCountOn_toOneHotCNF,Cslib.Logic.PL.CSP.modelCount_toOneHotCNF,Cslib.Logic.PL.CSP.modelCountOn_toOneHotCNFBounded: exact evaluation and model-count preservation.
References #
Width-guarded one-hot forbidden-tuple clauses: emits toOneHotCNF when c.scope.length ≤ k,
and [] otherwise.
If every constraint scope has length at most k, every clause of toOneHotCNF q N F sem
has width at most max q (max k 2).
When all variables of F are < N, every variable of toOneHotCNF q N F sem is < N * q.
When 0 < q and all variables of F are < N, the occurring variables of toOneHotCNF are
precisely Finset.range (N * q).
Evaluation correctness of toOneHotCNF: for 0 < q, σ satisfies toOneHotCNF q N F sem
iff every v < N has a unique true one-hot bit a < q and the induced assignment satisfies F.
Explicit assignment bijection for toOneHotCNF: when 0 < q and all variables of F
are < N, declared solutions of F on Finset.range N biject with satisfying assignments of
toOneHotCNF q N F sem on Finset.range (N * q).