Documentation

CslibFrontier.Algorithms.WordRAM.TreeDecomposition.IndependentSet.NodeLayout

Node-descriptor layout, telescoping table-entry sum, and initNodesProg #

This module defines the memory-layout invariant NodeLayout for all numNodes + 1 bag descriptors and DP tables, the telescoping prefix-maximum potential prefixMaxSum that prevents 2 ^ numNodes table-entry growth, and the Word-RAM parser/allocator initNodesProg. It has no dependency on any bag-scan or DP-pass submodule (IndepScan, MaskOps, WeightScan, ChildPass, ParentPass, RootPass).

Main definitions #

Main results #

Memory layout invariant (NodeLayout) #

Memory-layout invariant over inst's input slices, 4-word node descriptors at descBase, and disjoint materialized DP tables tblList i of length 2 ^ |bagAt i|.

theorem Cslib.Algorithms.WordRAM.TreeDecomposition.NodeLayout.mono_frontier {inst : MWISInstance} {descBase : ℕ} {tblList : Fin (inst.numNodes + 1) → List ℕ} {s s' : DataStructure.Memory.State} (h : NodeLayout inst descBase tblList s) (hp : WordRAM.Realization.PreservesBelow s.frontier s s') :
NodeLayout inst descBase tblList s'

NodeLayout is preserved by allocations or writes at or above s.frontier.

theorem Cslib.Algorithms.WordRAM.TreeDecomposition.NodeLayout.update_table {inst : MWISInstance} {descBase : ℕ} {tblList : Fin (inst.numNodes + 1) → List ℕ} {s s' : DataStructure.Memory.State} (h : NodeLayout inst descBase tblList s) (p : Fin (inst.numNodes + 1)) (newP : List ℕ) (hnew_len : newP.length = 2 ^ (inst.bagAt p).length) (hfr : s'.frontier = s.frontier) (hout : ∀ (addr : ℕ), addr < s.mem (descBase + 4 * ↑p + 2) ∨ s.mem (descBase + 4 * ↑p + 2) + 2 ^ (inst.bagAt p).length ≤ addr → s'.mem addr = s.mem addr) (hholdP : WordRAM.Realization.HoldsIn (s.mem (descBase + 4 * ↑p + 2)) newP s') :
NodeLayout inst descBase (Function.update tblList p newP) s'

NodeLayout updates cleanly when node p's DP table is overwritten in-place.

Telescoping prefix-sum potential (prefixMaxSum) #

Sum of per-table maximum entries across nodes 0, …, m.

theorem Cslib.Algorithms.WordRAM.TreeDecomposition.prefixMaxSum_replicate_zero {n : ℕ} (len : Fin (n + 1) → ℕ) (m : ℕ) :
prefixMaxSum (fun (i : Fin (n + 1)) => List.replicate (len i) 0) m = 0

All-zero tables have prefixMaxSum = 0.

theorem Cslib.Algorithms.WordRAM.TreeDecomposition.foldl_max_le_prefixMaxSum {n : ℕ} (tblList : Fin (n + 1) → List ℕ) (i : Fin (n + 1)) {m : ℕ} (him : ↑i ≤ m) :
List.foldl max 0 (tblList i) ≤ prefixMaxSum tblList m

Node i's maximum table entry is bounded by prefixMaxSum tblList m whenever i ≤ m.

theorem Cslib.Algorithms.WordRAM.TreeDecomposition.prefixMaxSum_succ {n : ℕ} (tblList : Fin (n + 1) → List ℕ) {k : ℕ} (hk : k + 1 ≤ n) :
prefixMaxSum tblList (k + 1) = prefixMaxSum tblList k + List.foldl max 0 (tblList ⟨k + 1, ⋯⟩)

Splitting prefixMaxSum tblList (k + 1) off node k + 1 when k + 1 ≤ n.

theorem Cslib.Algorithms.WordRAM.TreeDecomposition.prefixMaxSum_update_le {n : ℕ} (tblList : Fin (n + 1) → List ℕ) {k B : ℕ} (hk : k + 1 ≤ n) (p : Fin (n + 1)) (hp_lt : ↑p < k + 1) (newP : List ℕ) (hnew : List.foldl max 0 newP ≤ List.foldl max 0 (tblList p) + B + List.foldl max 0 (tblList ⟨k + 1, ⋯⟩)) :
prefixMaxSum (Function.update tblList p newP) k ≤ prefixMaxSum tblList (k + 1) + B

Telescoping step: folding node k + 1's table into strictly earlier parent p < k + 1 increases the remaining prefix sum 0 .. k by at most B relative to 0 .. k + 1.

Node descriptor initialization (initNodesProg) #

Register arguments (rawBagsPtr, count) for initNodesProg.

  • rawBagsPtr : ℕ

    Base memory address of inst.bags.flatMap encodeBag.

  • count : ℕ

    Number of tree-decomposition nodes numNodes + 1.

Instances For

    Allocate 4 * args.count descriptor words, parse each length-prefixed bag, zero-allocate its 2 ^ bagLen-word DP table, and return descBase.

    theorem Cslib.Algorithms.WordRAM.TreeDecomposition.initNodesProg_spec {w : ℕ} (inst : MWISInstance) {s₀ : DataStructure.Memory.State} (hwt₀ : WordRAM.Realization.HoldsIn 3 inst.weights s₀) (hadj₀ : WordRAM.Realization.HoldsIn (3 + inst.numVerts) inst.adjMatrix s₀) (hpar₀ : WordRAM.Realization.HoldsIn (3 + inst.numVerts + inst.numVerts * inst.numVerts) inst.parents s₀) (hbags₀ : WordRAM.Realization.HoldsIn (3 + inst.numVerts + inst.numVerts * inst.numVerts + (inst.numNodes + 1)) (List.flatMap encodeBag inst.bags) s₀) (hfit_peak : WordRAM.Fits w (s₀.frontier + 4 * (inst.numNodes + 1) + (inst.numNodes + 1) * 2 ^ inst.maxBagLen)) (hfit_raw : WordRAM.Fits w s₀.frontier) :
    have rawBagsPtr := 3 + inst.numVerts + inst.numVerts * inst.numVerts + (inst.numNodes + 1); have count := inst.numNodes + 1; have s₁ := (DataStructure.Memory.spec 0).clientState s₀ (initNodesProg { rawBagsPtr := rawBagsPtr, count := count }); have descBase := (DataStructure.Memory.spec 0).clientResult s₀ (initNodesProg { rawBagsPtr := rawBagsPtr, count := count }); (DataStructure.Memory.spec w).ValidHistory s₀ ((DataStructure.Memory.spec w).clientHistory s₀ (initNodesProg { rawBagsPtr := rawBagsPtr, count := count })) ∧ descBase = s₀.frontier ∧ s₁.frontier ≤ s₀.frontier + 4 * count + count * 2 ^ inst.maxBagLen ∧ NodeLayout inst descBase (fun (i : Fin (inst.numNodes + 1)) => List.replicate (2 ^ (inst.bagAt i).length) 0) s₁ ∧ WordRAM.Realization.memoryCost (initNodesProg { rawBagsPtr := rawBagsPtr, count := count }) s₀ ≤ 1 + count * (2 ^ inst.maxBagLen + inst.maxBagLen + 6)

    initNodesProg establishes NodeLayout with zero-initialized tables in ≤ 1 + (numNodes + 1) * (2 ^ maxBagLen + maxBagLen + 6) memory operations.