Native Boolean gate lists and truth-table cofactors
DefinitionNativeMcspGateSemanticscomplexity-theory
A native Boolean circuit is a sequential gate list with relative register addresses. The operations are false, true, NOT, AND, OR, and copy, and missing register reads yield false. The newest register is the output. The interface gives the gate bound, fixing a block of address variables, and repeating a cofactor by ignoring that block.
Definition code
import Mathlib
set_option autoImplicit false
namespace PvsNP.NativeMcspGateSemantics
/-- Opcode and two operand addresses. -/
abbrev Gate := ℕ × ℕ × ℕ
/-- Constants, NOT, AND, OR, and copy. Out-of-range reads are total. -/
def gateValue (g : Gate) (w : List Bool) : Bool :=
let a := w[g.2.1]?.getD false
let b := w[g.2.2]?.getD false
if g.1 = 0 then false
else if g.1 = 1 then true
else if g.1 = 2 then !a
else if g.1 = 3 then a && b
else if g.1 = 4 then a || b
else a
private def appendGate (x : List Bool × Gate) : List Bool := gateValue x.2 x.1 :: x.1
/-- All inputs and derived wires, with the most recent result first. -/
def evalRegisters (g : List Gate) (w : List Bool) : List Bool :=
g.foldl (fun bits next => appendGate (bits, next)) w
/-- The newest wire is the default single circuit output. -/
def eval (g : List Gate) (w : List Bool) : Bool := (evalRegisters g w).head?.getD false
def wireAt (w : List Bool) (i : ℕ) : Bool := w[i]?.getD false
abbrev Table (n : ℕ) := (Fin n → Bool) → Bool
def gateBound {n : ℕ} (f : Table n) (s : ℕ) : Prop :=
∃ gs : List Gate, gs.length ≤ s ∧ ∀ a, eval gs (List.ofFn a) = f a
/-- Fix the input wires in the left summand, preserving the order named by the
right summand for the cofactor's input wires. -/
def cofactor {n k m : ℕ} (split : Fin n ≃ Fin k ⊕ Fin m) (pin : Fin k → Bool)
(f : Table n) : Table m :=
fun x => f (fun i => (split i).elim pin x)
/-- Extend a cofactor to the full set of input wires by ignoring the left summand. -/
def extendCofactor {n k m : ℕ} (split : Fin n ≃ Fin k ⊕ Fin m) (g : Table m) : Table n :=
fun a => g (fun j => a (split.symm (.inr j)))
end PvsNP.NativeMcspGateSemantics
Source
The native gate-list semantics used in jprove2me, PvsNPSuccinctCircuits.lean and PvsNPMcspPadding.lean.