The circuit value problem
Lax535992.CircuitValue · concepts/Lax535992/CircuitValue.lean · lax-535992
No public endorsements yet.
Loading review…
Sign in with ORCIDNatural Language Statement
Definition
An instance is a Boolean circuit given as a structure: its elements are gates, each possibly marked as a constant true, a constant false, a conjunction, a disjunction or a negation, some gates are marked as outputs, and two binary relations wire a gate to its left and right arguments, a negation reading its left argument. The values of the gates are derived inductively, on two rails: a constant has its value; a conjunction is true when a left and a right argument are true, and false when some argument is false; a disjunction dually; a negation is true when its argument is false and false when it is true. The derivation is a least fixed point, so a gate on a cycle, or with missing arguments, derives no value. The instance is a yes-instance of CVP when some output gate derives the value true; CVP is the decision problem of the structures isomorphic to such an instance.
Concept map
Lean source view on GitHub
| 1 | import Mathlib.ModelTheory.Semantics |
| 2 | import Lax904597.Problems |
| 3 | import Lax485149.Problems |
| 4 | |
| 5 | /-! |
| 6 | --- |
| 7 | title: The circuit value problem |
| 8 | type: definition |
| 9 | --- |
| 10 | An instance is a Boolean circuit given as a structure: its elements are |
| 11 | gates, each possibly marked as a constant true, a constant false, a |
| 12 | conjunction, a disjunction or a negation, some gates are marked as outputs, |
| 13 | and two binary relations wire a gate to its left and right arguments, a |
| 14 | negation reading its left argument. The values of the gates are derived |
| 15 | inductively, on two rails: a constant has its value; a conjunction is true |
| 16 | when a left and a right argument are true, and false when some argument is |
| 17 | false; a disjunction dually; a negation is true when its argument is false |
| 18 | and false when it is true. The derivation is a least fixed point, so a gate |
| 19 | on a cycle, or with missing arguments, derives no value. The instance is a |
| 20 | yes-instance of CVP when some output gate derives the value true; CVP is the |
| 21 | decision problem of the structures isomorphic to such an instance. |
| 22 | -/ |
| 23 | |
| 24 | namespace Lax535992.CircuitValue |
| 25 | |
| 26 | open Lax904597.Problems Lax485149.Problems |
| 27 | |
| 28 | open FirstOrder |
| 29 | |
| 30 | open FirstOrder.Language |
| 31 | |
| 32 | /-- The relation symbols of the language. -/ |
| 33 | inductive circuitRel : ℕ → Type where |
| 34 | /-- `isTrue g`: the element `g` is a constant input gate holding `1`. -/ |
| 35 | | isTrue : circuitRel 1 |
| 36 | /-- `isFalse g`: the element `g` is a constant input gate holding `0`. -/ |
| 37 | | isFalse : circuitRel 1 |
| 38 | /-- `isAnd g`: the element `g` is a conjunction gate. -/ |
| 39 | | isAnd : circuitRel 1 |
| 40 | /-- `isOr g`: the element `g` is a disjunction gate. -/ |
| 41 | | isOr : circuitRel 1 |
| 42 | /-- `isNot g`: the element `g` is a negation gate, its argument read off |
| 43 | `left`. -/ |
| 44 | | isNot : circuitRel 1 |
| 45 | /-- `out g`: the element `g` is an output gate. -/ |
| 46 | | out : circuitRel 1 |
| 47 | /-- `left g x`: the gate `g` takes `x` as its first argument. -/ |
| 48 | | left : circuitRel 2 |
| 49 | /-- `right g x`: the gate `g` takes `x` as its second argument. -/ |
| 50 | | right : circuitRel 2 |
| 51 | deriving DecidableEq |
| 52 | |
| 53 | /-- The relational language of Boolean circuits: one unary predicate per gate |
| 54 | kind, one marking the output, and two binary predicates wiring a gate to its |
| 55 | arguments. -/ |
| 56 | def circuit : FirstOrder.Language := |
| 57 | ⟨fun _ => Empty, circuitRel⟩ |
| 58 | |
| 59 | instance instIsRelationalCircuit : FirstOrder.Language.IsRelational circuit := fun _ => |
| 60 | (inferInstance : IsEmpty Empty) |
| 61 | |
| 62 | /-- `isTrue g`: the element `g` is a constant input gate holding `1`. -/ |
| 63 | abbrev circIsTrue : circuit.Relations 1 := |
| 64 | .isTrue |
| 65 | |
| 66 | /-- `isFalse g`: the element `g` is a constant input gate holding `0`. -/ |
| 67 | abbrev circIsFalse : circuit.Relations 1 := |
| 68 | .isFalse |
| 69 | |
| 70 | /-- `isAnd g`: the element `g` is a conjunction gate. -/ |
| 71 | abbrev circIsAnd : circuit.Relations 1 := |
| 72 | .isAnd |
| 73 | |
| 74 | /-- `isOr g`: the element `g` is a disjunction gate. -/ |
| 75 | abbrev circIsOr : circuit.Relations 1 := |
| 76 | .isOr |
| 77 | |
| 78 | /-- `isNot g`: the element `g` is a negation gate, its argument read off |
| 79 | `left`. -/ |
| 80 | abbrev circIsNot : circuit.Relations 1 := |
| 81 | .isNot |
| 82 | |
| 83 | /-- `out g`: the element `g` is an output gate. -/ |
| 84 | abbrev circOut : circuit.Relations 1 := |
| 85 | .out |
| 86 | |
| 87 | /-- `left g x`: the gate `g` takes `x` as its first argument. -/ |
| 88 | abbrev circLeft : circuit.Relations 2 := |
| 89 | .left |
| 90 | |
| 91 | /-- `right g x`: the gate `g` takes `x` as its second argument. -/ |
| 92 | abbrev circRight : circuit.Relations 2 := |
| 93 | .right |
| 94 | |
| 95 | open FirstOrder |
| 96 | |
| 97 | open Language Structure |
| 98 | |
| 99 | section Semantics |
| 100 | |
| 101 | variable {A : Type} [circuit.Structure A] |
| 102 | |
| 103 | /-- **The value derivable at a gate**, as one inductive family indexed by the |
| 104 | value being derived: `GateVal true g` says that `g` evaluates to `1`, |
| 105 | `GateVal false g` that it evaluates to `0`. Being an inductive predicate, it is |
| 106 | the *least* pair of rails closed under the gate rules, so a gate whose |
| 107 | arguments derive nothing – including one on a cycle – derives nothing. |
| 108 | |
| 109 | The rules are the usual ones read in both polarities: a conjunction is true |
| 110 | when both arguments are, false as soon as one is; a disjunction dually; a |
| 111 | negation swaps the rails. -/ |
| 112 | inductive GateVal : Bool → A → Prop |
| 113 | /-- A constant `1` input derives `true`. -/ |
| 114 | | constTrue {g : A} (h : RelMap circIsTrue ![g]) : GateVal true g |
| 115 | /-- A constant `0` input derives `false`. -/ |
| 116 | | constFalse {g : A} (h : RelMap circIsFalse ![g]) : GateVal false g |
| 117 | /-- A conjunction with both arguments true derives `true`. -/ |
| 118 | | andTrue {g l r : A} (hg : RelMap circIsAnd ![g]) (hl : RelMap circLeft ![g, l]) |
| 119 | (hr : RelMap circRight ![g, r]) (vl : GateVal true l) (vr : GateVal true r) : |
| 120 | GateVal true g |
| 121 | /-- A conjunction with a false first argument derives `false`. -/ |
| 122 | | andFalseLeft {g l : A} (hg : RelMap circIsAnd ![g]) (hl : RelMap circLeft ![g, l]) |
| 123 | (vl : GateVal false l) : GateVal false g |
| 124 | /-- A conjunction with a false second argument derives `false`. -/ |
| 125 | | andFalseRight {g r : A} (hg : RelMap circIsAnd ![g]) (hr : RelMap circRight ![g, r]) |
| 126 | (vr : GateVal false r) : GateVal false g |
| 127 | /-- A disjunction with a true first argument derives `true`. -/ |
| 128 | | orTrueLeft {g l : A} (hg : RelMap circIsOr ![g]) (hl : RelMap circLeft ![g, l]) |
| 129 | (vl : GateVal true l) : GateVal true g |
| 130 | /-- A disjunction with a true second argument derives `true`. -/ |
| 131 | | orTrueRight {g r : A} (hg : RelMap circIsOr ![g]) (hr : RelMap circRight ![g, r]) |
| 132 | (vr : GateVal true r) : GateVal true g |
| 133 | /-- A disjunction with both arguments false derives `false`. -/ |
| 134 | | orFalse {g l r : A} (hg : RelMap circIsOr ![g]) (hl : RelMap circLeft ![g, l]) |
| 135 | (hr : RelMap circRight ![g, r]) (vl : GateVal false l) (vr : GateVal false r) : |
| 136 | GateVal false g |
| 137 | /-- A negation with a false argument derives `true`. -/ |
| 138 | | notTrue {g i : A} (hg : RelMap circIsNot ![g]) (hi : RelMap circLeft ![g, i]) |
| 139 | (vi : GateVal false i) : GateVal true g |
| 140 | /-- A negation with a true argument derives `false`. -/ |
| 141 | | notFalse {g i : A} (hg : RelMap circIsNot ![g]) (hi : RelMap circLeft ![g, i]) |
| 142 | (vi : GateVal true i) : GateVal false g |
| 143 | |
| 144 | variable (A) in |
| 145 | /-- A `Language.circuit`-structure is a yes-instance when some output gate |
| 146 | derives the value `1`. -/ |
| 147 | def CircuitAccepts : Prop := |
| 148 | ∃ g : A, RelMap circOut ![g] ∧ GateVal true g |
| 149 | |
| 150 | end Semantics |
| 151 | |
| 152 | /-- CVP, the circuit value problem: does some output gate evaluate to `1`? -/ |
| 153 | def CVP : DecisionProblem circuit := DecisionProblem.ofPred fun A _ => CircuitAccepts A |
| 154 | |
| 155 | end Lax535992.CircuitValue |
| 156 |
Builds on
Used by
Lax535992.CircuitValueInvarianceLax535992.CircuitValuePTIMECompleteLax535992.DeterministicMachineInvarianceLax535992.DeterministicMachinePTIMECompleteLax535992.GameInvarianceLax535992.GamePTIMECompleteLax535992.HornIsLeastFixedPointLax535992.HornSatInvarianceLax535992.HornSatPTIMECompleteLax535992.ImmermanVardiLax535992.InflationaryIsLeastFixedPointLax535992.LeastFixedPointComplementLax535992.NLSubsetPTIMELax535992.PTIMEClosureLax535992.PTIMEEqCoPTIMELax535992.PTIMESubsetNP
From Mathlib
Discussion
Ask a question or add context. Endorsements and structured flags are kept in the review panel above.
0 comments