Documentation

CslibFrontier.Computability.Circuit.Boolean.Tseitin

The Tseitin formula of a De Morgan circuit #

Tseitin's encoding turns a circuit into a formula in conjunctive normal form with one variable per wire Tseitin, Arora and Barak, Section 6.1. A gate w = op(a, b) contributes the clauses tseitinClause op w a b, which hold together exactly when w carries the value Op.value op a b of the gate (forall_eval_tseitinClause_iff). The clauses of the gates of a De Morgan gate list (Cslib.Circuits.Program.code) form tseitinCNF n gates, with gate g at wire n + g; an assignment satisfies it exactly when it is the evaluation of the list on its own values at the inputs (eval_tseitinCNF_eq_true_iff_evalCode).

tseitinSatCNF x n gates o adds unit clauses that fix the first inputs to the bits of x and the wire o to true. It is satisfiable exactly when some input extending x makes wire o true (satisfiable_tseitinSatCNF_iff); for x = [] and the output of a circuit, this is circuit satisfiability (satisfiable_tseitinSatCNF_circuit_iff).

The formula is laid out uniformly: every gate has exactly three clauses, and every clause has exactly three literals (length_of_mem_tseitinSatCNF), shorter clauses being padded by repeating a literal. Clause j of a gate depends only on its operation, on j and on the variables of the gate, so a circuit that computes a clause from its number (a succinct description of the formula) has a fixed output width. The frontier compiler (Cslib.Circuits.Frontier.Compiler.toCNF) instead numbers only the reachable wires, which preserves the number of models but is not uniform.

Main definitions #

Main results #

References #

The clauses of a gate #

theorem Cslib.Circuits.Boolean.interpretation_eq_value (gate : Op × List ℕ) (h : gate.2.length = signature.Arity gate.1) (f : ℕ → Bool) (d : Bool) :
(interpretation gate.1 fun (i : Fin (signature.Arity gate.1)) => gate.2[↑i]?.elim d f) = gate.1.value (f (gate.2.getD 0 0)) (f (gate.2.getD 1 0))

A gate code with as many arguments as its arity computes its operation on the values of its first two listed arguments.

def Cslib.Circuits.Boolean.tseitinClause {V : Type u_1} (op : Op) (w a b : V) (j : Fin 3) :

The Tseitin clauses of a gate w = op(a, b): three clauses of exactly three literals, which hold together exactly when w carries the value of the gate (forall_eval_tseitinClause_iff). A constant mentions only w, and a negation only w and a; shorter clauses are padded by repeating a literal.

theorem Cslib.Circuits.Boolean.mem_tseitinClause {V : Type u_1} {op : Op} {w a b v : V} {s : Bool} {j : Fin 3} (h : (v, s) ∈ tseitinClause op w a b j) :
v = w ∨ v = a ∨ v = b

Every variable occurring in tseitinClause op w a b j is w, a, or b.

@[simp]
theorem Cslib.Circuits.Boolean.length_tseitinClause {V : Type u_1} (op : Op) (w a b : V) (j : Fin 3) :
List.length (tseitinClause op w a b j) = 3

Every clause of a gate has three literals.

theorem Cslib.Circuits.Boolean.forall_eval_tseitinClause_iff {V : Type u_1} (op : Op) (w a b : V) (σ : V → Bool) :
(∀ (j : Fin 3), Logic.PL.Clause.eval σ (tseitinClause op w a b j) = true) ↔ σ w = op.value (σ a) (σ b)

The clauses of a gate hold exactly when its output carries its value.

@[simp]
theorem Cslib.Circuits.Boolean.relabel_tseitinClause {V : Type u_1} {W : Type u_2} (f : V → W) (op : Op) (w a b : V) (j : Fin 3) :
Logic.PL.Clause.relabel f (tseitinClause op w a b j) = tseitinClause op (f w) (f a) (f b) j

Relabelling the clauses of a gate relabels its variables.

The Tseitin formula of a gate list #

The clauses of a gate code gate at the wire w, reading its first two listed arguments.

The Tseitin formula of a De Morgan gate list on n inputs: the clauses of gate g say that wire n + g carries its value.

theorem Cslib.Circuits.Boolean.eval_gateClauses_eq_true_iff (w : ℕ) (gate : Op × List ℕ) (σ : ℕ → Bool) :
Logic.PL.CNF.eval σ (gateClauses w gate) = true ↔ σ w = gate.1.value (σ (gate.2.getD 0 0)) (σ (gate.2.getD 1 0))

The clauses of a gate code hold exactly when its wire carries its value.

theorem Cslib.Circuits.Boolean.eval_tseitinCNF_eq_true_iff (n : ℕ) (gates : List (Op × List ℕ)) (σ : ℕ → Bool) :
Logic.PL.CNF.eval σ (tseitinCNF n gates) = true ↔ ∀ (g : ℕ) (hg : g < gates.length), σ (n + g) = gates[g].1.value (σ (gates[g].2.getD 0 0)) (σ (gates[g].2.getD 1 0))

An assignment satisfies the Tseitin formula exactly when every gate wire carries the value of its gate.

theorem Cslib.Circuits.Boolean.eval_tseitinCNF_eq_true_iff_evalCode {n : ℕ} {gates : List (Op × List ℕ)} (h : Program.IsCodeFrom signature n 0 gates) (σ : ℕ → Bool) :
Logic.PL.CNF.eval σ (tseitinCNF n gates) = true ↔ ∀ w < n + gates.length, σ w = (evalCode interpretation false (List.ofFn fun (i : Fin n) => σ ↑i) gates).getD w false

The satisfying assignments of the Tseitin formula of a well-formed gate list are its evaluations: every wire carries the value that the list computes from the inputs.

Satisfiability with a fixed input prefix #

The unit clause of a literal, padded to three literals.

@[simp]

The unit clause of a literal holds when the literal does.

Circuit satisfiability with a fixed input prefix, as a formula: unit clauses fix the wire o to true and the inputs i < x.length to x[i], and the Tseitin clauses of gates follow.

theorem Cslib.Circuits.Boolean.eval_mapIdx_unitClause_eq_true_iff (x : List Bool) (σ : ℕ → Bool) :
Logic.PL.CNF.eval σ (List.mapIdx (fun (i : ℕ) (b : Bool) => unitClause (i, b)) x) = true ↔ ∀ (i : ℕ) (hi : i < x.length), σ i = x[i]

The unit clauses fixing the inputs i < x.length to x[i].

theorem Cslib.Circuits.Boolean.eval_tseitinSatCNF_eq_true_iff (x : List Bool) (n : ℕ) (gates : List (Op × List ℕ)) (o : ℕ) (σ : ℕ → Bool) :
Logic.PL.CNF.eval σ (tseitinSatCNF x n gates o) = true ↔ σ o = true ∧ (∀ (i : ℕ) (hi : i < x.length), σ i = x[i]) ∧ Logic.PL.CNF.eval σ (tseitinCNF n gates) = true

An assignment satisfies tseitinSatCNF when it makes wire o true, agrees with x on the first inputs and satisfies the Tseitin formula.

theorem Cslib.Circuits.Boolean.satisfiable_tseitinSatCNF_iff {x : List Bool} {n : ℕ} {gates : List (Op × List ℕ)} {o : ℕ} (h : Program.IsCodeFrom signature n 0 gates) (hx : x.length ≤ n) (ho : o < n + gates.length) :
(tseitinSatCNF x n gates o).Satisfiable ↔ ∃ (y : List Bool), y.length = n ∧ x <+: y ∧ evalOutput y gates o = true

Satisfiability with a fixed input prefix: for a well-formed gate list on n inputs and a wire o of it, tseitinSatCNF x n gates o is satisfiable exactly when some input of length n extending x makes wire o true.

Circuit satisfiability as a formula: the Tseitin formula of a single-output De Morgan circuit, with the output fixed to true and the inputs fixed to the bits of x, is satisfiable exactly when some input extending x makes the circuit output true.

theorem Cslib.Circuits.Boolean.getD_evalCode_append_of_lt {x : List Bool} {gates rest : List (Op × List ℕ)} {i : ℕ} (hi : i < x.length + gates.length) :

Evaluating more De Morgan gates preserves the values of the wires computed so far.

Size #

theorem Cslib.Circuits.Boolean.length_of_mem_tseitinSatCNF {x : List Bool} {n : ℕ} {gates : List (Op × List ℕ)} {o : ℕ} {C : Logic.PL.Clause ℕ} (hC : C ∈ tseitinSatCNF x n gates o) :

Every clause of tseitinSatCNF has exactly three literals.

theorem Cslib.Circuits.Boolean.length_tseitinSatCNF (x : List Bool) (n : ℕ) (gates : List (Op × List ℕ)) (o : ℕ) :
List.length (tseitinSatCNF x n gates o) = 1 + x.length + 3 * gates.length

tseitinSatCNF has one clause for the output, one for each fixed input and three for each gate.