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

The number written by a Boolean circuit

Lax366625.NumberedCircuits · concepts/Lax366625/NumberedCircuits.lean · lax-366625

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 as for the circuit value problem, whose output gates each hold one binary digit, together with a binary relation comparing the output gates. When that relation is a linear order on the output gates, the number written by the circuit is ∑2r(g)\sum 2^{r(g)} over the output gates gg that derive the value 11, r(g)r(g) being the number of output gates below gg; otherwise it is 00.

    Concept map
    7 concepts; 12 descendants hidden
    100%
    Proven claimDefinitionThis conceptRelated conceptA → B: B builds on A

    Lean source view on GitHub

    1import Mathlib.Algebra.BigOperators.Finprod
    2import Mathlib.SetTheory.Cardinal.Finite
    3import Mathlib.Order.PiLex
    4import Mathlib.Data.Prod.Lex
    5import Mathlib.Data.Fintype.EquivFin
    6import Mathlib.ModelTheory.Order
    7import Mathlib.ModelTheory.Semantics
    8import Mathlib.ModelTheory.Complexity
    9import Mathlib.Tactic.FinCases
    10import Mathlib.Logic.Equiv.Fin.Basic
    11import Mathlib.ModelTheory.Syntax
    12import Lax535992.CircuitValue
    13import Lax366625.CountingProblems
    14
    15/-!
    16---
    17title: The number written by a Boolean circuit
    18type: definition
    19---
    20An instance is a Boolean circuit as for the circuit value problem, whose
    21output gates each hold one binary digit, together with a binary relation
    22comparing the output gates. When that relation is a linear order on the
    23output gates, the number written by the circuit is ∑2r(g)\sum 2^{r(g)} over the
    24output gates gg that derive the value 11, r(g)r(g) being the number of output
    25gates below gg; otherwise it is 00.
    26-/
    27
    28namespace Lax366625.NumberedCircuits
    29
    30open Lax535992.CircuitValue
    31
    32open FirstOrder
    33
    34open FirstOrder.Language
    35
    36/-- The relation symbols of the language. -/
    37inductive numCircuitRel : ℕ → Type where
    38/-- `isTrue g`: the element `g` is a constant input gate holding `1`. -/
    39 | isTrue : numCircuitRel 1
    40/-- `isFalse g`: the element `g` is a constant input gate holding `0`. -/
    41 | isFalse : numCircuitRel 1
    42/-- `isAnd g`: the element `g` is a conjunction gate. -/
    43 | isAnd : numCircuitRel 1
    44/-- `isOr g`: the element `g` is a disjunction gate. -/
    45 | isOr : numCircuitRel 1
    46/-- `isNot g`: the element `g` is a negation gate, its argument read off
    47 `left`. -/
    48 | isNot : numCircuitRel 1
    49/-- `out g`: the element `g` is an output gate, holding one digit. -/
    50 | out : numCircuitRel 1
    51/-- `left g x`: the gate `g` takes `x` as its first argument. -/
    52 | left : numCircuitRel 2
    53/-- `right g x`: the gate `g` takes `x` as its second argument. -/
    54 | right : numCircuitRel 2
    55/-- `below h g`: the digit held by `h` is at most as significant as the one
    56 held by `g`. -/
    57 | below : numCircuitRel 2
    58 deriving DecidableEq
    59
    60/-- The relational language of Boolean circuits writing a number: the symbols
    61of circuits, and a comparison of the output gates. -/
    62def numCircuit : FirstOrder.Language :=
    63 ⟨fun _ => Empty, numCircuitRel⟩
    64
    65instance instIsRelationalNumCircuit : FirstOrder.Language.IsRelational numCircuit := fun _ =>
    66 (inferInstance : IsEmpty Empty)
    67
    68/-- `isTrue g`: the element `g` is a constant input gate holding `1`. -/
    69abbrev ncIsTrue : numCircuit.Relations 1 :=
    70 .isTrue
    71
    72/-- `isFalse g`: the element `g` is a constant input gate holding `0`. -/
    73abbrev ncIsFalse : numCircuit.Relations 1 :=
    74 .isFalse
    75
    76/-- `isAnd g`: the element `g` is a conjunction gate. -/
    77abbrev ncIsAnd : numCircuit.Relations 1 :=
    78 .isAnd
    79
    80/-- `isOr g`: the element `g` is a disjunction gate. -/
    81abbrev ncIsOr : numCircuit.Relations 1 :=
    82 .isOr
    83
    84/-- `isNot g`: the element `g` is a negation gate, its argument read off
    85 `left`. -/
    86abbrev ncIsNot : numCircuit.Relations 1 :=
    87 .isNot
    88
    89/-- `out g`: the element `g` is an output gate, holding one digit. -/
    90abbrev ncOut : numCircuit.Relations 1 :=
    91 .out
    92
    93/-- `left g x`: the gate `g` takes `x` as its first argument. -/
    94abbrev ncLeft : numCircuit.Relations 2 :=
    95 .left
    96
    97/-- `right g x`: the gate `g` takes `x` as its second argument. -/
    98abbrev ncRight : numCircuit.Relations 2 :=
    99 .right
    100
    101/-- `below h g`: the digit held by `h` is at most as significant as the one
    102 held by `g`. -/
    103abbrev ncBelow : numCircuit.Relations 2 :=
    104 .below
    105
    106open FirstOrder
    107
    108open Language Structure
    109
    110/-- Forgetting the comparison of the outputs: the vocabulary of circuits, read
    111in the vocabulary of circuits writing a number. -/
    112def circuitOfNum : circuit →ᴸ numCircuit where
    113 onFunction := fun {_} f => isEmptyElim f
    114 onRelation := fun {n} R =>
    115 match n, R with
    116 | _, .isTrue => ncIsTrue
    117 | _, .isFalse => ncIsFalse
    118 | _, .isAnd => ncIsAnd
    119 | _, .isOr => ncIsOr
    120 | _, .isNot => ncIsNot
    121 | _, .out => ncOut
    122 | _, .left => ncLeft
    123 | _, .right => ncRight
    124
    125/-- A circuit writing a number is a circuit. -/
    126instance numCircuitStructure (A : Type) [numCircuit.Structure A] :
    127 circuit.Structure A :=
    128 circuitOfNum.reduct A
    129
    130section Semantics
    131
    132variable {A : Type} [numCircuit.Structure A]
    133
    134/-- The output gate `g` holds the digit `1`. -/
    135def OutBit (g : A) : Prop :=
    136 RelMap ncOut ![g] ∧ GateVal true g
    137
    138/-- `h` is an output gate strictly below `g`. -/
    139def LowerOut (g h : A) : Prop :=
    140 RelMap ncOut ![h] ∧ h ≠ g ∧ RelMap ncBelow ![h, g]
    141
    142/-- The rank of a gate among the outputs: the number of output gates strictly
    143below it. -/
    144noncomputable def outRank (g : A) : ℕ :=
    145 Nat.card {h : A // LowerOut g h}
    146
    147variable (A) in
    148/-- **The comparison of the outputs is a linear order on them**: reflexive,
    149transitive, antisymmetric and total among the output gates. -/
    150def OutOrder : Prop :=
    151 (∀ p : A, RelMap ncOut ![p] → RelMap ncBelow ![p, p]) ∧
    152 (∀ p q r : A, RelMap ncOut ![p] → RelMap ncOut ![q] → RelMap ncOut ![r] →
    153 RelMap ncBelow ![p, q] → RelMap ncBelow ![q, r] → RelMap ncBelow ![p, r]) ∧
    154 (∀ p q : A, RelMap ncOut ![p] → RelMap ncOut ![q] →
    155 RelMap ncBelow ![p, q] → RelMap ncBelow ![q, p] → p = q) ∧
    156 ∀ p q : A, RelMap ncOut ![p] → RelMap ncOut ![q] →
    157 RelMap ncBelow ![p, q] ∨ RelMap ncBelow ![q, p]
    158
    159variable (A) in
    160open Classical in
    161/-- **The number written by a circuit**: each output gate deriving the value
    162`1` contributes two to the power of its rank among the outputs; `0` unless the
    163outputs are linearly ordered. -/
    164noncomputable def circuitNumber : ℕ :=
    165 if OutOrder A then ∑ᶠ g : A, if OutBit g then 2 ^ outRank g else 0 else 0
    166
    167end Semantics
    168
    169open Lax366625.CountingProblems
    170
    171/-- **The number written by a circuit**, as a counting problem. -/
    172noncomputable def CircuitNumber : CountingProblem numCircuit :=
    173 CountingProblem.ofFun fun A _ => circuitNumber A
    174
    175end Lax366625.NumberedCircuits
    176

    Discussion

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

    Loading discussion…