Documentation

CslibFrontier.Computability.Circuit.NNF.Basic

Negation normal form circuits, DNNF and d-DNNF #

A negation normal form circuit (NNF, also called a De Morgan circuit) over variables ι is a directed acyclic graph whose nodes are literals xᵢ or ¬xᵢ, constants, or fan-in-two ∧ and ∨ gates (Cslib.Circuits.NNF). Nodes are numbered 0, …, size - 1 and every gate's children have smaller numbers, so nodes are shared: the circuit is a DAG, not a formula, and its size is its number of nodes (gates, literals and constants alike). One node is the output.

These are the definitions of [ArenasBroadrickLiewVanDenBroeck2026, Section 3.1], with constant leaves also allowed, as in [Dar01]. Allowing constants only enlarges the class against which lower bounds hold.

Relation to DecomposableDAG and Circuit.IsDeterministicDecomposable. Cslib.Circuits.DecomposableDAG (CslibFrontier/Computability/Circuit/Decomposable.lean) is the semantic model of (not necessarily smooth) decomposable DAGs over an arbitrary alphabet. Every decomposable NNF embeds into it on the same node set via NNF.IsDecomposable.toDecomposableDAG (CslibFrontier/Computability/Circuit/NNF/Rectangle.lean), preserving acceptance and determinism, and specializing the general multi-partition rectangle cover theorem to DNNF size. Every NNF on Fin n also compiles into a De Morgan straight-line circuit via NNF.toCircuit (CslibFrontier/Computability/Circuit/Boolean/DeterministicDecomposable.lean), mapping d-DNNFs into Circuit.IsDeterministicDecomposable and hence into syntactically multilinear arithmetic circuits (NNF.exists_syntacticallyMultilinear). This file keeps the syntactic NNF model with literal leaves, explicit node sharing and node-count size matching the paper.

Evaluation and variable sets are both instances of one bottom-up fold (NNF.fold, with the unfolding equation NNF.fold_eq), defined by structural recursion on a bound for the node number, so concrete circuits evaluate by decide.

Main definitions #

Main results #

References #

inductive Cslib.Circuits.NNF.Gate (ι : Type u_1) (N : Type u_2) :
Type (max u_1 u_2)

A gate of a negation normal form circuit over the variables ι, with children among the nodes N.

  • lit {ι : Type u_1} {N : Type u_2} (i : ι) (b : Bool) : Gate ι N

    The literal xᵢ when b is true, ¬xᵢ when b is false.

  • const {ι : Type u_1} {N : Type u_2} (b : Bool) : Gate ι N

    A constant.

  • and {ι : Type u_1} {N : Type u_2} (l r : N) : Gate ι N

    A fan-in-two conjunction.

  • or {ι : Type u_1} {N : Type u_2} (l r : N) : Gate ι N

    A fan-in-two disjunction.

@[instance_reducible]
instance Cslib.Circuits.NNF.instDecidableEqGate {ι✝ : Type u_1} {N✝ : Type u_2} [DecidableEq ι✝] [DecidableEq N✝] :
DecidableEq (Gate ι✝ N✝)
def Cslib.Circuits.NNF.instDecidableEqGate.decEq {ι✝ : Type u_1} {N✝ : Type u_2} [DecidableEq ι✝] [DecidableEq N✝] (x✝ x✝¹ : Gate ι✝ N✝) :
Decidable (x✝ = x✝¹)
structure Cslib.Circuits.NNF (ι : Type u_1) (N : Type u_2) :
Type (max u_1 u_2)

A negation normal form circuit (NNF) over the variables ι on the nodes N: every node is a literal, a constant, or a fan-in-two ∧ or ∨ gate, a rank decreasing from each gate to its children makes the graph acyclic, and one node is the output. Nodes may be shared, so this is a DAG. For finite N, its size is the number of nodes (NNF.size).

  • gate : N → Gate ι N

    The gate at each node.

  • rank : N → ℕ

    A rank that decreases from each gate to its children.

  • and_lt (v l r : N) : self.gate v = Gate.and l r → self.rank l < self.rank v ∧ self.rank r < self.rank v

    The children of an ∧ gate have lower rank.

  • or_lt (v l r : N) : self.gate v = Gate.or l r → self.rank l < self.rank v ∧ self.rank r < self.rank v

    The children of an ∨ gate have lower rank.

  • root : N

    The output node.

def Cslib.Circuits.NNF.foldBelow {ι : Type u_1} {N : Type u_2} (C : NNF ι N) {α : Type u_3} (lit : ι → Bool → α) (const : Bool → α) (and or : α → α → α) (k : ℕ) (v : N) :
C.rank v < k → α

The bottom-up fold of an NNF below a node of number less than k, by structural recursion on k.

def Cslib.Circuits.NNF.fold {ι : Type u_1} {N : Type u_2} (C : NNF ι N) {α : Type u_3} (lit : ι → Bool → α) (const : Bool → α) (and or : α → α → α) (v : N) :
α

The bottom-up fold of an NNF at a node: leaves are mapped by lit and const, and gates combine the values of their children by and and or.

theorem Cslib.Circuits.NNF.foldBelow_congr {ι : Type u_1} {N : Type u_2} (C : NNF ι N) {α : Type u_3} (lit : ι → Bool → α) (const : Bool → α) (and or : α → α → α) (k k' : ℕ) (v : N) (h : C.rank v < k) (h' : C.rank v < k') :
C.foldBelow lit const and or k v h = C.foldBelow lit const and or k' v h'
theorem Cslib.Circuits.NNF.fold_eq {ι : Type u_1} {N : Type u_2} (C : NNF ι N) {α : Type u_3} (lit : ι → Bool → α) (const : Bool → α) (and or : α → α → α) (v : N) :
C.fold lit const and or v = match C.gate v with | Gate.lit i b => lit i b | Gate.const b => const b | Gate.and l r => and (C.fold lit const and or l) (C.fold lit const and or r) | Gate.or l r => or (C.fold lit const and or l) (C.fold lit const and or r)

Unfolding the fold at a node by its gate.

def Cslib.Circuits.NNF.eval {ι : Type u_1} {N : Type u_2} (C : NNF ι N) (x : ι → Bool) :
N → Bool

The value of a node on the assignment x.

def Cslib.Circuits.NNF.toFun {ι : Type u_1} {N : Type u_2} (C : NNF ι N) (x : ι → Bool) :

The function computed by the circuit: the value of its output node.

def Cslib.Circuits.NNF.size {ι : Type u_1} {N : Type u_2} (_C : NNF ι N) [Fintype N] :

The size of a circuit on finitely many nodes: its number of nodes.

theorem Cslib.Circuits.NNF.eval_lit {ι : Type u_1} {N : Type u_2} {C : NNF ι N} {x : ι → Bool} {v : N} {i : ι} {b : Bool} (h : C.gate v = Gate.lit i b) :
C.eval x v = (x i == b)
theorem Cslib.Circuits.NNF.eval_const {ι : Type u_1} {N : Type u_2} {C : NNF ι N} {x : ι → Bool} {v : N} {b : Bool} (h : C.gate v = Gate.const b) :
C.eval x v = b
theorem Cslib.Circuits.NNF.eval_and {ι : Type u_1} {N : Type u_2} {C : NNF ι N} {x : ι → Bool} {v l r : N} (h : C.gate v = Gate.and l r) :
C.eval x v = (C.eval x l && C.eval x r)
theorem Cslib.Circuits.NNF.eval_or {ι : Type u_1} {N : Type u_2} {C : NNF ι N} {x : ι → Bool} {v l r : N} (h : C.gate v = Gate.or l r) :
C.eval x v = (C.eval x l || C.eval x r)
theorem Cslib.Circuits.NNF.induction_on {ι : Type u_1} {N : Type u_2} {C : NNF ι N} {P : N → Prop} (h : ∀ (v : N), (∀ (u : N), C.rank u < C.rank v → P u) → P v) (v : N) :
P v

Induction on nodes: a property holding at every node whose children satisfy it holds at every node.

def Cslib.Circuits.NNF.vars {ι : Type u_1} {N : Type u_2} (C : NNF ι N) [DecidableEq ι] :
N → Finset ι

The variables mentioned by the subcircuit below a node.

theorem Cslib.Circuits.NNF.vars_lit {ι : Type u_1} {N : Type u_2} {C : NNF ι N} [DecidableEq ι] {v : N} {i : ι} {b : Bool} (h : C.gate v = Gate.lit i b) :
C.vars v = {i}
theorem Cslib.Circuits.NNF.vars_const {ι : Type u_1} {N : Type u_2} {C : NNF ι N} [DecidableEq ι] {v : N} {b : Bool} (h : C.gate v = Gate.const b) :
C.vars v = ∅
theorem Cslib.Circuits.NNF.vars_and {ι : Type u_1} {N : Type u_2} {C : NNF ι N} [DecidableEq ι] {v l r : N} (h : C.gate v = Gate.and l r) :
C.vars v = C.vars l ∪ C.vars r
theorem Cslib.Circuits.NNF.vars_or {ι : Type u_1} {N : Type u_2} {C : NNF ι N} [DecidableEq ι] {v l r : N} (h : C.gate v = Gate.or l r) :
C.vars v = C.vars l ∪ C.vars r
theorem Cslib.Circuits.NNF.card_vars_le_one_of_not_gate {ι : Type u_1} {N : Type u_2} {C : NNF ι N} [DecidableEq ι] {v : N} (h : ∀ (l r : N), C.gate v ≠ Gate.and l r ∧ C.gate v ≠ Gate.or l r) :
(C.vars v).card ≤ 1

A node mentions at most one variable when it is a literal or a constant.

theorem Cslib.Circuits.NNF.eval_congr {ι : Type u_1} {N : Type u_2} {C : NNF ι N} [DecidableEq ι] {x y : ι → Bool} (v : N) (h : ∀ i ∈ C.vars v, x i = y i) :
C.eval x v = C.eval y v

Locality. The value of a node depends only on the variables it mentions.

def Cslib.Circuits.NNF.IsDecomposable {ι : Type u_1} {N : Type u_2} (C : NNF ι N) [DecidableEq ι] :

A circuit is decomposable (a DNNF) when the two children of each of its ∧ gates mention disjoint sets of variables.

def Cslib.Circuits.NNF.IsDeterministic {ι : Type u_1} {N : Type u_2} (C : NNF ι N) :

A circuit is deterministic when the two children of each of its ∨ gates are never both true. A deterministic DNNF is a d-DNNF.