Documentation

CslibFrontier.Algorithms.Lean.TreeDecomposition.BagMask

Subsets of a bag as bit masks #

Executable dynamic programs over a tree decomposition index the subsets of a bag by bit masks. Given an ordering L : List V of a bag, ofMask L m is the subset whose i-th entry is selected by bit i of m, and toMask L S is the mask of S. When L has no repetitions these are inverse bijections between Finset.range (2 ^ L.length) and the subsets of L.toFinset.

The library has other mask encodings: Cslib.Algorithms.Lean.Yates.maskSet and Cslib.Algorithms.MatrixMultiplication.Schonhage.MaskTable.maskSet for subsets of Fin n, Cslib.Complexity.maskSelect for a list of Boolean selectors, and Mathlib's Nat.bitIndices. None of them maps numeric masks to subsets of an arbitrary list of vertices by the recursion on its head that the scan helpers below follow, so the encoding is defined here.

The module also provides the pure scan helpers that executable programs run on masks: membership by a linear scan of a bag, the parent-bag mask of a child subset, its restriction, the weight of the entries that are forgotten, and an independence test. Their values are specified against ofMask/toMask, while machine-level running-time bounds live in CslibFrontier.Algorithms.WordRAM.TreeDecomposition.IndependentSet.

SimpleGraph.RootedTreeDecomposition stores its bags as Finsets, which have no executable order. IsBagOrder R L states that L i lists the vertices of R.bag i without repetition, and sortedBags R is such an ordering for a linearly ordered vertex type.

Main definitions #

Main results #

Subsets of a bag as bit masks #

The subset of the list L selected by the bit mask m: bit i of m selects L[i].

The bit mask of the elements of L that lie in S: bit i is set when L[i] ∈ S.

theorem Cslib.Algorithms.Lean.TreeDecomposition.ofMask_cons {V : Type u_1} [DecidableEq V] (v : V) (L : List V) (m : ℕ) :
ofMask (v :: L) m = if m % 2 = 1 then insert v (ofMask L (m / 2)) else ofMask L (m / 2)
theorem Cslib.Algorithms.Lean.TreeDecomposition.toMask_cons {V : Type u_1} [DecidableEq V] (v : V) (L : List V) (S : Finset V) :
toMask (v :: L) S = (if v ∈ S then 1 else 0) + 2 * toMask L S
theorem Cslib.Algorithms.Lean.TreeDecomposition.mem_ofMask_cons {V : Type u_1} [DecidableEq V] {v x : V} {L : List V} {m : ℕ} :
x ∈ ofMask (v :: L) m ↔ m % 2 = 1 ∧ x = v ∨ x ∈ ofMask L (m / 2)
theorem Cslib.Algorithms.Lean.TreeDecomposition.toMask_congr {V : Type u_1} [DecidableEq V] {L : List V} {S T : Finset V} (h : ∀ x ∈ L, x ∈ S ↔ x ∈ T) :
toMask L S = toMask L T
theorem Cslib.Algorithms.Lean.TreeDecomposition.toMask_ofMask {V : Type u_1} [DecidableEq V] {L : List V} (hL : L.Nodup) {m : ℕ} (hm : m < 2 ^ L.length) :
toMask L (ofMask L m) = m

Scan helpers on masks #

Membership test by a linear scan of L.

Membership in the subset of L selected by the mask m, by a linear scan of L.

The parent-bag mask of the child subset selected by t: for each entry u of the parent bag LP, test whether u is selected in the child bag LB.

The parent-bag mask of S ∩ B, where S is the parent subset selected by s and B is the set of entries of the child bag LB.

def Cslib.Algorithms.Lean.TreeDecomposition.forgetWeight {V : Type u_1} [DecidableEq V] (w : V → ℕ) (LP : List V) :
List V → ℕ → ℕ

The total weight of the entries selected by t from the child bag LB that are not in the parent bag LP.

Whether x has no neighbour in the subset of L selected by m.

Whether the subset of L selected by m is independent.

Orderings of the bags #

L lists the bags of R: each L i lists the vertices of R.bag i without repetition.

Instances For
    @[instance_reducible]

    The bags of R sorted in increasing order.

    Specifications of the scan helpers #

    @[simp]
    theorem Cslib.Algorithms.Lean.TreeDecomposition.keyMask_eq_toMask {V : Type u_1} [DecidableEq V] (LB LP : List V) (t : ℕ) :
    keyMask LB LP t = toMask LP (ofMask LB t)
    theorem Cslib.Algorithms.Lean.TreeDecomposition.restrictMask_eq_toMask {V : Type u_1} [DecidableEq V] (LB : List V) {LP : List V} (hLP : LP.Nodup) (s : ℕ) :
    restrictMask LB LP s = toMask LP (ofMask LP s ∩ LB.toFinset)
    theorem Cslib.Algorithms.Lean.TreeDecomposition.forgetWeight_eq_sum {V : Type u_1} [DecidableEq V] (w : V → ℕ) (LP : List V) {LB : List V} (hLB : LB.Nodup) (t : ℕ) :
    forgetWeight w LP LB t = ∑ v ∈ ofMask LB t \ LP.toFinset, w v
    theorem Cslib.Algorithms.Lean.TreeDecomposition.noAdjMask_eq_true_iff {V : Type u_1} [DecidableEq V] (G : SimpleGraph V) [DecidableRel G.Adj] (x : V) (L : List V) (m : ℕ) :
    noAdjMask G x L m = true ↔ ∀ y ∈ ofMask L m, ¬G.Adj x y