While this submission is a draft, it cannot be used by other submissions.

The circuit value problem

Lax535992.CircuitValue · concepts/Lax535992/CircuitValue.lean · lax-535992

definition

Loading review…

Sign in with ORCID

Community review

Flags

Each flag is tied to a public ORCID identity and explains why this concept may be incorrect.

No flags have been submitted.

    Community review

    Flag this concept

    State precisely what appears incorrect. This explanation will be public under your ORCID name.

    No source line selected.

    Natural 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
    3 concepts; 16 descendants hidden
    100%
    Proven claimDefinitionThis conceptRelated conceptA → B: B builds on A

    Lean source view on GitHub

    1import Mathlib.ModelTheory.Semantics
    2import Lax904597.Problems
    3import Lax485149.Problems
    4
    5/-!
    6---
    7title: The circuit value problem
    8type: definition
    9---
    10An instance is a Boolean circuit given as a structure: its elements are
    11gates, each possibly marked as a constant true, a constant false, a
    12conjunction, a disjunction or a negation, some gates are marked as outputs,
    13and two binary relations wire a gate to its left and right arguments, a
    14negation reading its left argument. The values of the gates are derived
    15inductively, on two rails: a constant has its value; a conjunction is true
    16when a left and a right argument are true, and false when some argument is
    17false; a disjunction dually; a negation is true when its argument is false
    18and false when it is true. The derivation is a least fixed point, so a gate
    19on a cycle, or with missing arguments, derives no value. The instance is a
    20yes-instance of CVP when some output gate derives the value true; CVP is the
    21decision problem of the structures isomorphic to such an instance.
    22-/
    23
    24namespace Lax535992.CircuitValue
    25
    26open Lax904597.Problems Lax485149.Problems
    27
    28open FirstOrder
    29
    30open FirstOrder.Language
    31
    32/-- The relation symbols of the language. -/
    33inductive 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
    54kind, one marking the output, and two binary predicates wiring a gate to its
    55arguments. -/
    56def circuit : FirstOrder.Language :=
    57 ⟨fun _ => Empty, circuitRel⟩
    58
    59instance instIsRelationalCircuit : FirstOrder.Language.IsRelational circuit := fun _ =>
    60 (inferInstance : IsEmpty Empty)
    61
    62/-- `isTrue g`: the element `g` is a constant input gate holding `1`. -/
    63abbrev circIsTrue : circuit.Relations 1 :=
    64 .isTrue
    65
    66/-- `isFalse g`: the element `g` is a constant input gate holding `0`. -/
    67abbrev circIsFalse : circuit.Relations 1 :=
    68 .isFalse
    69
    70/-- `isAnd g`: the element `g` is a conjunction gate. -/
    71abbrev circIsAnd : circuit.Relations 1 :=
    72 .isAnd
    73
    74/-- `isOr g`: the element `g` is a disjunction gate. -/
    75abbrev circIsOr : circuit.Relations 1 :=
    76 .isOr
    77
    78/-- `isNot g`: the element `g` is a negation gate, its argument read off
    79 `left`. -/
    80abbrev circIsNot : circuit.Relations 1 :=
    81 .isNot
    82
    83/-- `out g`: the element `g` is an output gate. -/
    84abbrev circOut : circuit.Relations 1 :=
    85 .out
    86
    87/-- `left g x`: the gate `g` takes `x` as its first argument. -/
    88abbrev circLeft : circuit.Relations 2 :=
    89 .left
    90
    91/-- `right g x`: the gate `g` takes `x` as its second argument. -/
    92abbrev circRight : circuit.Relations 2 :=
    93 .right
    94
    95open FirstOrder
    96
    97open Language Structure
    98
    99section Semantics
    100
    101variable {A : Type} [circuit.Structure A]
    102
    103/-- **The value derivable at a gate**, as one inductive family indexed by the
    104value 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
    106the *least* pair of rails closed under the gate rules, so a gate whose
    107arguments derive nothing – including one on a cycle – derives nothing.
    108
    109The rules are the usual ones read in both polarities: a conjunction is true
    110when both arguments are, false as soon as one is; a disjunction dually; a
    111negation swaps the rails. -/
    112inductive 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
    144variable (A) in
    145/-- A `Language.circuit`-structure is a yes-instance when some output gate
    146derives the value `1`. -/
    147def CircuitAccepts : Prop :=
    148 ∃ g : A, RelMap circOut ![g] ∧ GateVal true g
    149
    150end Semantics
    151
    152/-- CVP, the circuit value problem: does some output gate evaluate to `1`? -/
    153def CVP : DecisionProblem circuit := DecisionProblem.ofPred fun A _ => CircuitAccepts A
    154
    155end Lax535992.CircuitValue
    156

    Discussion

    Ask a question or add context. Endorsements and structured flags are kept in the review panel above.

    Loading discussion…