Documentation

CslibFrontier.Algorithms.WordRAM.TreeDecomposition.CSP.Model

Serialized finite-domain CSP model and DP specification over nice tree decompositions #

This module defines the pure data structures, post-order serialization, explicit ℕ-table DP (dpInstTree), tight active-variable entry bounds (activeForgetCount), and step/word envelopes shared by the Word-RAM nice-tree CSP modules.

Main definitions #

Main results #

Materialized constraint tables #

Materialized truth table of a single constraint over ℕ variable indices and domain Fin q.

Evaluate a ConstraintTable on a natural-valued assignment α : ℕ → ℕ.

def Cslib.Algorithms.WordRAM.TreeDecomposition.ConstraintTable.ofConstraint {Rel : Type u_1} {V : Type u_2} {q m : ℕ} (hq : 0 < q) (e : V ≃ Fin m) (sem : Rel → List (Fin q) → Bool) (c : Logic.PL.Constraint Rel V) :

Compile a Constraint Rel V into a materialized ConstraintTable q via e : V ≃ Fin m, deduplicating repeated variables in c.scope so table.length = q ^ |c.scope.toFinset|. This materialization is performed externally before Word-RAM execution.

theorem Cslib.Algorithms.WordRAM.TreeDecomposition.ConstraintTable.eval_ofConstraint {Rel : Type u_1} {V : Type u_2} {q m : ℕ} (hq : 0 < q) (e : V ≃ Fin m) (sem : Rel → List (Fin q) → Bool) (c : Logic.PL.Constraint Rel V) (σ : V → Fin q) (α : ℕ → ℕ) (hα : ∀ v ∈ c.scope, α ↑(e v) = ↑(σ v)) :
(ofConstraint hq e sem c).eval α = Logic.PL.Constraint.eval sem σ c

Post-order serialization of NiceTree ℕ and pure ℕ-table DP #

Post-order 4-word-per-node serialization of S starting at node index offset:

  • leaf → [0, 0, 0, 0]
  • introduce v child → encode child ++ [1, v, root(child), 0]
  • forget v child → encode child ++ [2, v, root(child), 0]
  • join left right → encode left ++ encode right ++ [3, 0, root(left), root(right)].

Post-order 4-word-per-node serialization of T : NiceTree ℕ rooted at T.size - 1.

Every word emitted by encodeNiceTreeAux offset T is bounded by max 3 (max (maxTreeVert T) (offset + T.size)).

Unified natural-valued DP table over ConstraintTable q matching both cspDecideTree (counting = false, {0, 1} entries) and cspCountTree (counting = true, ℕ entries).

@[simp]

dpInstTree emits q ^ (bagList T).length entries.

Number of forget nodes in T whose forgotten variable belongs to vars. Bounds the exponent of q in counting-mode DP entries (mem_dpInstTree_le), and equals ((T.subtreeVerts \ T.bag) ∩ vars.toFinset).card whenever T.LocalValid holds.

On any locally valid nice tree T, activeForgetCount vars T equals the number of distinct active variables already forgotten below the root bag of T.

On any locally valid nice tree T, activeForgetCount vars T ≤ vars.toFinset.card.

theorem Cslib.Algorithms.WordRAM.TreeDecomposition.mem_dpInstTree_le (counting : Bool) {q : ℕ} (cs : List (ConstraintTable q)) (vars : List ℕ) (T : SimpleGraph.NiceTree ℕ) (x : ℕ) :
x ∈ dpInstTree counting q cs vars T → x ≤ if counting = true then q ^ activeForgetCount vars T else 1

Entry magnitude bound for dpInstTree: ≤ 1 in decision mode and ≤ q ^ activeForgetCount vars T in counting mode.

Agreement of dpInstTree with cspCountTree and cspDecideTree #

TreeCSPInstance and FPT step bounds #

Worst-case table exponent across T: bounds (bagList S).length at all nodes and ((bagList child).erase v).length + 1 at forget nodes, while staying ≤ T.width + 1 whenever T.LocalValid holds.

FPT memoryCost bound for extensional CSP decision or single-word wide-word model counting on a pre-serialized nice tree decomposition of size numNodes and width ≤ k, domain size q, numCons = |F|, and varsLen = |F.vars| (total arity across all constraints): O(numNodes · q ^ (k + 1) · ((k + 1) ^ 2 + |F| + |F.vars| · (k + 1)) + numNodes · |F.vars|).

Post-normalization FPT memoryCost bound for the nice-tree DP phase on a nice tree of size ≤ (3 * k + 5) * (cardV + 1) produced externally by R.toNiceTreePruned. This bound covers only the nice-tree DP pass after external conversion and has no dependence on the input rooted decomposition's node count n; Word-RAM rooted-to-nice normalization remains open (#9170).

theorem Cslib.Algorithms.WordRAM.TreeDecomposition.cspNiceStepBound_mono {q n₁ n₂ k₁ k₂ v₁ v₂ c₁ c₂ : ℕ} (hq : 0 < q) (hn : n₁ ≤ n₂) (hk : k₁ ≤ k₂) (hv : v₁ ≤ v₂) (hc : c₁ ≤ c₂) :
cspNiceStepBound q n₁ k₁ v₁ c₁ ≤ cspNiceStepBound q n₂ k₂ v₂ c₂

Serialized finite-domain extensional CSP instance with a pre-serialized nice tree decomposition for Word-RAM execution.

Flat word encoding loaded into State.init: [mode, q, |vars|, |constraints|, tree.size] ++ vars ++ encodeNiceTree tree ++ constraints.

Root DP answer (1/0 for satisfiability when counting = false, exact model count when counting = true).

Total arity across all materialized constraints.

Maximum variable index occurring in vars, tree, or any constraint scope.

Maximum DP entry value: 1 in decision mode, q ^ activeForgetCount vars tree in counting mode (which equals q ^ F.numVars on valid nice tree decompositions of F.primalGraph, independent of redundant tree nodes).

Sufficient word bound covering all memory frontiers, node/bag/table indices, variable names, and DP entry values.

def Cslib.Algorithms.WordRAM.TreeDecomposition.TreeCSPInstance.ofNiceTree {Rel : Type u_1} {V : Type u_2} {m : ℕ} (counting : Bool) (q : ℕ) (hq : 0 < q) (e : V ≃ Fin m) (sem : Rel → List (Fin q) → Bool) (F : Logic.PL.CSP Rel V) (T : SimpleGraph.NiceTree V) :

Compile a CSP Rel V and NiceTree V into a TreeCSPInstance via e : V ≃ Fin m, materializing deduplicated constraint truth tables externally.

def Cslib.Algorithms.WordRAM.TreeDecomposition.TreeCSPInstance.ofNice {Rel : Type u_1} {V : Type u_2} [DecidableEq V] {m : ℕ} (counting : Bool) (q : ℕ) (hq : 0 < q) (e : V ≃ Fin m) (sem : Rel → List (Fin q) → Bool) (F : Logic.PL.CSP Rel V) (N : F.primalGraph.NiceTreeDecomposition) :

Compile a CSP Rel V and NiceTreeDecomposition of F.primalGraph.

def Cslib.Algorithms.WordRAM.TreeDecomposition.TreeCSPInstance.ofToNiceTreePruned {Rel : Type u_1} {V : Type u_2} [LinearOrder V] {m n : ℕ} (counting : Bool) (q : ℕ) (hq : 0 < q) (e : V ≃ Fin m) (sem : Rel → List (Fin q) → Bool) (F : Logic.PL.CSP Rel V) (R : F.primalGraph.RootedTreeDecomposition n) :

External-preprocessing convenience wrapper compiling a CSP Rel V and RootedTreeDecomposition of F.primalGraph by running R.toNiceTreePruned and ConstraintTable.ofConstraint outside the Word-RAM before serialization. This is not a Word-RAM encoding of R (the machine never sees R or its node count n; #9170).

theorem Cslib.Algorithms.WordRAM.TreeDecomposition.TreeCSPInstance.result_ofNiceTree_count {Rel : Type u_1} {V : Type u_2} [DecidableEq V] {q m : ℕ} (hq : 0 < q) (e : V ≃ Fin m) (sem : Rel → List (Fin q) → Bool) (F : Logic.PL.CSP Rel V) (T : SimpleGraph.NiceTree V) :
theorem Cslib.Algorithms.WordRAM.TreeDecomposition.TreeCSPInstance.result_ofNiceTree_decide {Rel : Type u_1} {V : Type u_2} [DecidableEq V] {q m : ℕ} (hq : 0 < q) (e : V ≃ Fin m) (sem : Rel → List (Fin q) → Bool) (F : Logic.PL.CSP Rel V) (T : SimpleGraph.NiceTree V) :
theorem Cslib.Algorithms.WordRAM.TreeDecomposition.TreeCSPInstance.result_ofNice_count {Rel : Type u_1} {V : Type u_2} [DecidableEq V] {q m : ℕ} (hq : 0 < q) (e : V ≃ Fin m) (sem : Rel → List (Fin q) → Bool) (F : Logic.PL.CSP Rel V) (N : F.primalGraph.NiceTreeDecomposition) :
(ofNice true q hq e sem F N).result = Logic.PL.CSP.modelCount sem F
theorem Cslib.Algorithms.WordRAM.TreeDecomposition.TreeCSPInstance.result_ofNice_decide {Rel : Type u_1} {V : Type u_2} [DecidableEq V] {q m : ℕ} (hq : 0 < q) (e : V ≃ Fin m) (sem : Rel → List (Fin q) → Bool) (F : Logic.PL.CSP Rel V) (N : F.primalGraph.NiceTreeDecomposition) :
(ofNice false q hq e sem F N).result = 1 ↔ Logic.PL.CSP.Satisfiable sem F
theorem Cslib.Algorithms.WordRAM.TreeDecomposition.TreeCSPInstance.maxEntryBound_ofNice_eq {Rel : Type u_1} {V : Type u_2} [DecidableEq V] {q m : ℕ} (hq : 0 < q) (e : V ≃ Fin m) (sem : Rel → List (Fin q) → Bool) (F : Logic.PL.CSP Rel V) (N : F.primalGraph.NiceTreeDecomposition) :
(ofNice true q hq e sem F N).maxEntryBound = q ^ F.numVars

On any valid nice tree decomposition of F.primalGraph, the counting-mode entry bound maxEntryBound equals q ^ F.numVars (independent of redundant tree nodes).

theorem Cslib.Algorithms.WordRAM.TreeDecomposition.TreeCSPInstance.wordBound_ofNice_le {Rel : Type u_1} {V : Type u_2} [DecidableEq V] {q m k : ℕ} (hq : 0 < q) (counting : Bool) (e : V ≃ Fin m) (sem : Rel → List (Fin q) → Bool) (F : Logic.PL.CSP Rel V) (N : F.primalGraph.NiceTreeDecomposition) (hk : N.width ≤ k) :
(ofNice counting q hq e sem F N).wordBound ≤ 5 + F.vars.length + 4 * N.size + List.length F * (2 + (k + 1) + q ^ (k + 1)) + 8 + 4 * N.size + N.size * (k + 3 + q ^ (k + 1)) + q * q ^ (k + 1) + m + if counting = true then q ^ F.numVars else 1

Closed-form upper bound on (ofNice counting q hq e sem F N).wordBound. In decision mode (counting = false), the entry term is 1, so logarithmic word width w = O(log(m + N.size + |F.vars| + |F| + q ^ (k + 1))) suffices even with repeated variables in constraint scopes. In counting mode (counting = true), the entry term is q ^ F.numVars (independent of redundant tree nodes), requiring single-word width w > F.numVars · log₂ q.

theorem Cslib.Algorithms.WordRAM.TreeDecomposition.TreeCSPInstance.wordBound_ofToNiceTreePruned_le {Rel : Type u_1} {V : Type u_2} [LinearOrder V] {q m n k : ℕ} (hq : 0 < q) (counting : Bool) (e : V ≃ Fin m) (sem : Rel → List (Fin q) → Bool) (F : Logic.PL.CSP Rel V) (R : F.primalGraph.RootedTreeDecomposition n) (hk : R.width ≤ k) :
have N_ub := (3 * k + 5) * (m + 1); (ofToNiceTreePruned counting q hq e sem F R).wordBound ≤ 5 + F.vars.length + 4 * N_ub + List.length F * (2 + (k + 1) + q ^ (k + 1)) + 8 + 4 * N_ub + N_ub * (k + 3 + q ^ (k + 1)) + q * q ^ (k + 1) + m + if counting = true then q ^ F.numVars else 1

Closed-form upper bound on (ofToNiceTreePruned counting q hq e sem F R).wordBound via R.toNiceTreePruned_size_le and R.toNiceTreePruned_width_le.

theorem Cslib.Algorithms.WordRAM.TreeDecomposition.TreeCSPInstance.stepBound_ofNice_le {Rel : Type u_1} {V : Type u_2} [DecidableEq V] {q m k : ℕ} (hq : 0 < q) (counting : Bool) (e : V ≃ Fin m) (sem : Rel → List (Fin q) → Bool) (F : Logic.PL.CSP Rel V) (N : F.primalGraph.NiceTreeDecomposition) (hk : N.width ≤ k) :
(ofNice counting q hq e sem F N).stepBound ≤ cspNiceStepBound q N.size k F.vars.length (List.length F)
theorem Cslib.Algorithms.WordRAM.TreeDecomposition.TreeCSPInstance.stepBound_ofToNiceTreePruned_le {Rel : Type u_1} {V : Type u_2} [LinearOrder V] {q m n k : ℕ} (hq : 0 < q) (counting : Bool) (e : V ≃ Fin m) (sem : Rel → List (Fin q) → Bool) (F : Logic.PL.CSP Rel V) (R : F.primalGraph.RootedTreeDecomposition n) (hk : R.width ≤ k) :

Post-normalization step bound for ofToNiceTreePruned (≤ cspPrunedNiceStepBound, independent of the rooted decomposition's node count n; #9170).

Monotonicity of maxTreeVert into the left child of join.

Monotonicity of maxTreeVert into the right child of join.

Monotonicity of maxTableExp into the left child of join.

Monotonicity of maxTableExp into the right child of join.

Monotonicity of activeForgetCount into the left child of join.

Monotonicity of activeForgetCount into the right child of join.