Documentation

CslibFrontier.Algorithms.Lean.TreeDecomposition.IndependentSetFPT

An executable FPT program for maximum-weight independent set #

mwisFPT R w L is an executable pure program that computes the maximum total weight of an independent set of G, given a rooted tree decomposition R : G.RootedTreeDecomposition n, vertex weights w : V → ℕ and an ordering L of the bags (IsBagOrder R L). It materializes the tables of mwisValue (CslibFrontier.Algorithms.Lean.TreeDecomposition.IndependentSet) as arrays indexed by bit masks and stores them in a Vector over the nodes. mwisFPT_eq_mwisValue proves that it equals mwisValue R w, so it returns the optimum (isGreatest_mwisFPT).

Machine-level FPT running-time bounds on an array-encoded decomposition live in CslibFrontier.Algorithms.WordRAM.TreeDecomposition.IndependentSet.

The program #

The tables are indexed by bit masks over the ordered bags (ofMask, toMask). The nodes are processed in the order n, n - 1, …, 1, so every child is processed before its parent. Processing a node j with bag list LB and parent bag list LP (processNode) runs two loops:

The root pass (rootPass) returns the best weight plus table entry over the independent subsets of the root bag. getD_tablesFPT shows that the arrays agree with tables on every subset of every bag. It is proved one node at a time against step (getD_processNode). The only nontrivial step is that the child pass computes forget (getD_childPass_eq_forget).

Main definitions #

Main results #

References #

The passes #

The parent pass: for each parent mask s < c, add the best child entry agreeing with s to the old parent table.

def Cslib.Algorithms.Lean.TreeDecomposition.childPass {V : Type u_1} [DecidableEq V] (G : SimpleGraph V) [DecidableRel G.Adj] (w : V → ℕ) (LB LP : List V) (f init : Array ℕ) :

The child pass over the child masks t < c: for each independent child subset, update the entry of best at its parent-bag mask with the forgotten weight plus the child table entry.

def Cslib.Algorithms.Lean.TreeDecomposition.rootPass {V : Type u_1} [DecidableEq V] (G : SimpleGraph V) [DecidableRel G.Adj] (w : V → ℕ) (L : List V) (tbl : Array ℕ) :
ℕ → ℕ

The root pass over the root masks t < c: the best weight of an independent root subset plus its table entry.

The program #

def Cslib.Algorithms.Lean.TreeDecomposition.processNode {V : Type u_1} {G : SimpleGraph V} {n : ℕ} [DecidableEq V] [DecidableRel G.Adj] (R : G.RootedTreeDecomposition n) (w : V → ℕ) (L : Fin (n + 1) → List V) (st : Vector (Array ℕ) (n + 1)) (j : Fin (n + 1)) :
Vector (Array ℕ) (n + 1)

Process node j: build its message to its parent and add it to the parent's table.

def Cslib.Algorithms.Lean.TreeDecomposition.tablesFPT {V : Type u_1} {G : SimpleGraph V} {n : ℕ} [DecidableEq V] [DecidableRel G.Adj] (R : G.RootedTreeDecomposition n) (w : V → ℕ) (L : Fin (n + 1) → List V) :
ℕ → Vector (Array ℕ) (n + 1)

The tables after processing the nodes n, n - 1, …, n - t + 1.

def Cslib.Algorithms.Lean.TreeDecomposition.mwisFPT {V : Type u_1} {G : SimpleGraph V} {n : ℕ} [DecidableEq V] [DecidableRel G.Adj] (R : G.RootedTreeDecomposition n) (w : V → ℕ) (L : Fin (n + 1) → List V) :

The executable program: process every nonroot node, then combine at the root.

Correctness of the passes #

theorem Cslib.Algorithms.Lean.TreeDecomposition.size_childPass {V : Type u_1} [DecidableEq V] (G : SimpleGraph V) [DecidableRel G.Adj] (w : V → ℕ) (LB LP : List V) (f init : Array ℕ) (c : ℕ) :
(childPass G w LB LP f init c).size = init.size
theorem Cslib.Algorithms.Lean.TreeDecomposition.getD_childPass {V : Type u_1} [DecidableEq V] (G : SimpleGraph V) [DecidableRel G.Adj] (w : V → ℕ) {LB : List V} (hLB : LB.Nodup) (LP : List V) (f init : Array ℕ) (c : ℕ) {k : ℕ} (hk : k < init.size) :
(childPass G w LB LP f init c).getD k 0 = max (init.getD k 0) ({t ∈ Finset.range c | G.IsIndepSet ↑(ofMask LB t) ∧ toMask LP (ofMask LB t) = k}.sup fun (t : ℕ) => ∑ v ∈ ofMask LB t \ LP.toFinset, w v + f.getD t 0)

After the child masks t < c, the entry of best at a parent mask k is the best value over the independent child subsets with parent mask k.

theorem Cslib.Algorithms.Lean.TreeDecomposition.getD_childPass_eq_forget {V : Type u_1} [DecidableEq V] (G : SimpleGraph V) [DecidableRel G.Adj] (w : V → ℕ) {LB LP : List V} (hLB : LB.Nodup) (f : Array ℕ) (g : Finset V → ℕ) (hfg : ∀ t < 2 ^ LB.length, f.getD t 0 = g (ofMask LB t)) {S : Finset V} (hS : S ⊆ LP.toFinset) :
(childPass G w LB LP f (Array.replicate (2 ^ LP.length) 0) (2 ^ LB.length)).getD (toMask LP (S ∩ LB.toFinset)) 0 = forget G w LB.toFinset LP.toFinset g S

Started from a zero table, the child pass computes forget on every parent subset.

theorem Cslib.Algorithms.Lean.TreeDecomposition.size_parentPass {V : Type u_1} [DecidableEq V] (LB LP : List V) (old best : Array ℕ) (c : ℕ) :
(parentPass LB LP old best c).size = c
theorem Cslib.Algorithms.Lean.TreeDecomposition.getD_parentPass {V : Type u_1} [DecidableEq V] (LB : List V) {LP : List V} (hLP : LP.Nodup) (old best : Array ℕ) {c s : ℕ} (hs : s < c) :
(parentPass LB LP old best c).getD s 0 = old.getD s 0 + best.getD (toMask LP (ofMask LP s ∩ LB.toFinset)) 0
theorem Cslib.Algorithms.Lean.TreeDecomposition.rootPass_eq_sup {V : Type u_1} [DecidableEq V] (G : SimpleGraph V) [DecidableRel G.Adj] (w : V → ℕ) {L : List V} (hL : L.Nodup) (tbl : Array ℕ) (c : ℕ) :
rootPass G w L tbl c = {t ∈ Finset.range c | G.IsIndepSet ↑(ofMask L t)}.sup fun (t : ℕ) => ∑ v ∈ ofMask L t, w v + tbl.getD t 0

Correctness #

theorem Cslib.Algorithms.Lean.TreeDecomposition.getD_processNode {V : Type u_1} {G : SimpleGraph V} {n : ℕ} [DecidableEq V] [DecidableRel G.Adj] (R : G.RootedTreeDecomposition n) (w : V → ℕ) {L : Fin (n + 1) → List V} (hL : IsBagOrder R L) (st : Vector (Array ℕ) (n + 1)) (g : Fin (n + 1) → Finset V → ℕ) (hg : ∀ (i : Fin (n + 1)), ∀ s < 2 ^ (L i).length, st[i].getD s 0 = g i (ofMask (L i) s)) (j i : Fin (n + 1)) {s : ℕ} (hs : s < 2 ^ (L i).length) :
(processNode R w L st j)[i].getD s 0 = step R w g j i (ofMask (L i) s)

One step of the program refines step: if the materialized tables agree with g on every subset of every bag, then after processing j they agree with step R w g j.

theorem Cslib.Algorithms.Lean.TreeDecomposition.getD_tablesFPT {V : Type u_1} {G : SimpleGraph V} {n : ℕ} [DecidableEq V] [DecidableRel G.Adj] (R : G.RootedTreeDecomposition n) (w : V → ℕ) {L : Fin (n + 1) → List V} (hL : IsBagOrder R L) (t : ℕ) (i : Fin (n + 1)) {s : ℕ} (hs : s < 2 ^ (L i).length) :
(tablesFPT R w L t)[i].getD s 0 = tables R w t i (ofMask (L i) s)

The materialized tables agree with the specification tables of CslibFrontier.Algorithms.Lean.TreeDecomposition.IndependentSet on every subset of every bag.

theorem Cslib.Algorithms.Lean.TreeDecomposition.mwisFPT_eq_mwisValue {V : Type u_1} {G : SimpleGraph V} {n : ℕ} [DecidableEq V] [DecidableRel G.Adj] (R : G.RootedTreeDecomposition n) (w : V → ℕ) {L : Fin (n + 1) → List V} (hL : IsBagOrder R L) :
mwisFPT R w L = mwisValue R w

Correctness. The executable program computes the value of the dynamic program.

theorem Cslib.Algorithms.Lean.TreeDecomposition.isGreatest_mwisFPT {V : Type u_1} {G : SimpleGraph V} {n : ℕ} [DecidableEq V] [DecidableRel G.Adj] (R : G.RootedTreeDecomposition n) (w : V → ℕ) {L : Fin (n + 1) → List V} (hL : IsBagOrder R L) :
IsGreatest {x : ℕ | ∃ (I : Finset V), G.IsIndepSet ↑I ∧ ∑ v ∈ I, w v = x} (mwisFPT R w L)

The executable program computes the maximum weight of an independent set.

theorem Cslib.Algorithms.Lean.TreeDecomposition.mwisFPT_one_eq_indepNum {V : Type u_1} {G : SimpleGraph V} {n : ℕ} [DecidableEq V] [DecidableRel G.Adj] (R : G.RootedTreeDecomposition n) {L : Fin (n + 1) → List V} (hL : IsBagOrder R L) :
mwisFPT R (fun (x : V) => 1) L = G.indepNum

With unit weights the executable program computes the independence number.