Documentation

CslibFrontier.Computability.Circuit.NNF.ReadOnce

Read-once branching programs as d-DNNFs and decomposable DAGs #

A read-once branching program P of length L with states S over the alphabet Bool (Cslib.BranchingPrograms.ReadOnceProgram), together with a variable order ord : Fin L → ι, computes x ↦ P.eval (x ∘ ord): an ordered binary decision diagram reading x (ord 0), x (ord 1), …. When the order is injective, this function is computed by a d-DNNF with (L + 1) |S| + 2L + 2L |S| nodes (ReadOnceProgram.toNNF, ReadOnceProgram.card_nnfNode), the compilation of ordered binary decision diagrams into d-DNNFs [ArenasBroadrickLiewVanDenBroeck2026, Fact 3.3].

The circuit has a node (t, q) for each time t ≤ L and state q, computing whether the program accepts from state q at time t (ReadOnceProgram.eval_state): at t = L it is the constant accept q, and before it is (¬x_{ord t} ∧ (t + 1, step t q false)) ∨ (x_{ord t} ∧ (t + 1, step t q true)). The ∨ is deterministic because its children disagree on x_{ord t}, and the ∧ is decomposable because ord t is not read again.

Over an arbitrary finite alphabet U, the same construction compiles a read-once program (an ordered multi-valued decision diagram, MDD) directly into a deterministic DecomposableDAG ι U (ReadOnceProgram.toDecomposableDAG, ReadOnceProgram.accepted_toDecomposableDAG, ReadOnceProgram.isDeterministic_toDecomposableDAG) of size 2 L |S| |U| (ReadOnceProgram.size_toDecomposableDAG), which is also smooth whenever ord is surjective (ReadOnceProgram.isSmooth_toDecomposableDAG).

Programs reading a list of labelled variables with a label-dependent transition (ReadOnceProgram.ofList, ReadOnceProgram.listOrder) evaluate by a left fold over the list (ReadOnceProgram.eval_ofList).

Main definitions #

Main results #

References #

@[reducible, inline]

The nodes of the d-DNNF of a program: states at each time, literals at each time, and the conjunctions of a literal with the next state.

def Cslib.BranchingPrograms.ReadOnceProgram.nnfGate {L : ℕ} {S : Type u_1} {ι : Type u_2} (P : ReadOnceProgram L S Bool) (ord : Fin L → ι) :

The gate at a node of the d-DNNF of a program.

The rank of a node: decreasing along time.

theorem Cslib.BranchingPrograms.ReadOnceProgram.nnfGate_and {L : ℕ} {S : Type u_1} {ι : Type u_2} (P : ReadOnceProgram L S Bool) (ord : Fin L → ι) {v l r : NNFNode L S} (h : P.nnfGate ord v = Circuits.NNF.Gate.and l r) :
theorem Cslib.BranchingPrograms.ReadOnceProgram.nnfGate_or {L : ℕ} {S : Type u_1} {ι : Type u_2} (P : ReadOnceProgram L S Bool) (ord : Fin L → ι) {v l r : NNFNode L S} (h : P.nnfGate ord v = Circuits.NNF.Gate.or l r) :
def Cslib.BranchingPrograms.ReadOnceProgram.toNNF {L : ℕ} {S : Type u_1} {ι : Type u_2} (P : ReadOnceProgram L S Bool) (ord : Fin L → ι) :

The d-DNNF of a program reading the variables in the order ord.

theorem Cslib.BranchingPrograms.ReadOnceProgram.eval_state {L : ℕ} {S : Type u_1} {ι : Type u_2} (P : ReadOnceProgram L S Bool) (ord : Fin L → ι) (x : ι → Bool) (k : ℕ) (t : Fin (L + 1)) (q : S) :
L - ↑t = k → (P.toNNF ord).eval x (Sum.inl (t, q)) = P.accept (P.runFrom (x ∘ ord) (↑t) q)

The state nodes compute the program: the node (t, q) accepts exactly when the program accepts from the state q at time t.

theorem Cslib.BranchingPrograms.ReadOnceProgram.toFun_toNNF {L : ℕ} {S : Type u_1} {ι : Type u_2} (P : ReadOnceProgram L S Bool) (ord : Fin L → ι) (x : ι → Bool) :
(P.toNNF ord).toFun x = P.eval (x ∘ ord)

The circuit computes the program on the variables in the order ord.

theorem Cslib.BranchingPrograms.ReadOnceProgram.vars_state_subset {L : ℕ} {S : Type u_1} {ι : Type u_2} (P : ReadOnceProgram L S Bool) (ord : Fin L → ι) [DecidableEq ι] (k : ℕ) (t : Fin (L + 1)) (q : S) :
L - ↑t = k → (P.toNNF ord).vars (Sum.inl (t, q)) ⊆ Finset.image ord {j : Fin L | ↑t ≤ ↑j}

The state node at time t mentions only the variables read from time t on.

theorem Cslib.BranchingPrograms.ReadOnceProgram.isDecomposable_toNNF {L : ℕ} {S : Type u_1} {ι : Type u_2} (P : ReadOnceProgram L S Bool) (ord : Fin L → ι) [DecidableEq ι] (hord : Function.Injective ord) :

The circuit is decomposable when the order reads every variable at most once.

theorem Cslib.BranchingPrograms.ReadOnceProgram.isDeterministic_toNNF {L : ℕ} {S : Type u_1} {ι : Type u_2} (P : ReadOnceProgram L S Bool) (ord : Fin L → ι) :

The circuit is deterministic: the two branches of a state node disagree on the variable read.

Size: the d-DNNF of a program of length L with |S| states has (L + 1) |S| + 2L + 2L |S| nodes.

Programs reading a list of labelled variables #

def Cslib.BranchingPrograms.ReadOnceProgram.ofList {S : Type u_1} {ι : Type u_2} {Λ : Type u_3} (items : List (ι × Λ)) (start : S) (step : Λ → S → Bool → S) (accept : S → Bool) :

The program reading the list items of labelled variables in order, moving from state s to step λ s b on reading the value b of a variable labelled λ.

def Cslib.BranchingPrograms.ReadOnceProgram.listOrder {ι : Type u_2} {Λ : Type u_3} (items : List (ι × Λ)) :
Fin items.length → ι

The variable order of a list of labelled variables.

The order of a list of distinct variables is injective.

theorem Cslib.BranchingPrograms.ReadOnceProgram.eval_ofList {S : Type u_1} {ι : Type u_2} {Λ : Type u_3} (items : List (ι × Λ)) (start : S) (step : Λ → S → Bool → S) (accept : S → Bool) (x : ι → Bool) :
(ofList items start step accept).eval (x ∘ listOrder items) = accept (List.foldl (fun (s : S) (a : ι × Λ) => step a.2 s (x a.1)) start items)

List programs evaluate by a fold over the labelled variables.

Multi-valued read-once programs as decomposable DAGs #

@[reducible, inline]
abbrev Cslib.BranchingPrograms.ReadOnceProgram.DAGNode (L : ℕ) (S : Type u_1) (U : Type u_2) :
Type (max u_2 u_1)

The nodes of the decomposable DAG (MDD) of a read-once program over alphabet U: states at each time, letter tests at each time, and products of a letter test with the next state.

def Cslib.BranchingPrograms.ReadOnceProgram.toDecomposableDAG {L : ℕ} {S : Type u_1} {U : Type u_2} {ι : Type u_3} (P : ReadOnceProgram L S U) (ord : Fin L → ι) [Fintype U] [DecidableEq S] [DecidableEq U] (hord : Function.Injective ord) :

Compile a read-once branching program over an arbitrary finite alphabet U (an ordered MDD) under an injective variable order into a deterministic DecomposableDAG.

theorem Cslib.BranchingPrograms.ReadOnceProgram.accepted_toDecomposableDAG {L : ℕ} {S : Type u_1} {U : Type u_2} {ι : Type u_3} (P : ReadOnceProgram L S U) (ord : Fin L → ι) [Fintype U] [DecidableEq S] [DecidableEq U] (hord : Function.Injective ord) :
(P.toDecomposableDAG ord hord).accepted = {x : ι → U | P.eval (x ∘ ord) = true}

Correctness of the MDD compilation: P.toDecomposableDAG ord hord accepts exactly the inputs accepted by P under the variable order ord.

theorem Cslib.BranchingPrograms.ReadOnceProgram.isDeterministic_toDecomposableDAG {L : ℕ} {S : Type u_1} {U : Type u_2} {ι : Type u_3} (P : ReadOnceProgram L S U) (ord : Fin L → ι) [Fintype U] [DecidableEq S] [DecidableEq U] (hord : Function.Injective ord) :

Determinism of the MDD compilation: distinct outgoing letters at each state node are disjoint.

theorem Cslib.BranchingPrograms.ReadOnceProgram.isSmooth_toDecomposableDAG {L : ℕ} {S : Type u_1} {U : Type u_2} {ι : Type u_3} (P : ReadOnceProgram L S U) (ord : Fin L → ι) [Fintype U] [DecidableEq S] [DecidableEq U] (hord : Function.Injective ord) (hsurj : Function.Surjective ord) :

Smoothness of the MDD compilation: every union is already smooth, so the DAG is smooth over all coordinates whenever ord is surjective (in particular for ord = id).

theorem Cslib.BranchingPrograms.ReadOnceProgram.size_toDecomposableDAG {L : ℕ} {S : Type u_1} {U : Type u_2} {ι : Type u_3} (P : ReadOnceProgram L S U) (ord : Fin L → ι) [Fintype S] [Fintype U] [DecidableEq S] [DecidableEq U] (hord : Function.Injective ord) :

Size of the MDD compilation: L |S| |U| union edges and L |S| |U| products, for a total size of 2 L |S| |U|.