Boolean circuits
Lax429075.Circuits · concepts/Lax429075/Circuits.lean · lax-429075
No public endorsements yet.
Loading review…
Sign in with ORCIDNatural Language Statement
Definition
A circuit is a finite sequence of input, constant, negation, conjunction, and disjunction gates. Every wire refers to an earlier gate, and the output is a gate of the circuit. A satisfying wire assignment respects every gate and makes the output true.
Concept map
In the paper
- page 2 of this submission's paper
Lean source view on GitHub
| 1 | import Lax429075.CNF |
| 2 | |
| 3 | /-! |
| 4 | --- |
| 5 | title: Boolean circuits |
| 6 | type: definition |
| 7 | --- |
| 8 | A circuit is a finite sequence of input, constant, negation, conjunction, |
| 9 | and disjunction gates. Every wire refers to an earlier gate, and the output |
| 10 | is a gate of the circuit. A satisfying wire assignment respects every gate |
| 11 | and makes the output true. |
| 12 | -/ |
| 13 | |
| 14 | namespace Lax429075.Circuits |
| 15 | |
| 16 | open CNF |
| 17 | |
| 18 | inductive Gate |
| 19 | | input |
| 20 | | constant (value : Bool) |
| 21 | | neg (a : ℕ) |
| 22 | | conj (a b : ℕ) |
| 23 | | disj (a b : ℕ) |
| 24 | deriving DecidableEq |
| 25 | |
| 26 | def Gate.inputs : Gate → List ℕ |
| 27 | | .input | .constant _ => [] |
| 28 | | .neg a => [a] |
| 29 | | .conj a b | .disj a b => [a, b] |
| 30 | |
| 31 | structure Circuit where |
| 32 | gates : List Gate |
| 33 | output : Fin gates.length |
| 34 | ordered : ∀ g i, (g, i) ∈ gates.zipIdx → ∀ j ∈ g.inputs, j < i |
| 35 | |
| 36 | def Gate.check (ρ : Assignment) (i : ℕ) : Gate → Bool |
| 37 | | .input => true |
| 38 | | .constant b => ρ i == b |
| 39 | | .neg a => ρ i == !(ρ a) |
| 40 | | .conj a b => ρ i == (ρ a && ρ b) |
| 41 | | .disj a b => ρ i == (ρ a || ρ b) |
| 42 | |
| 43 | def check (C : Circuit) (ρ : Assignment) : Bool := |
| 44 | ρ C.output && C.gates.zipIdx.all (fun gi => gi.1.check ρ gi.2) |
| 45 | |
| 46 | def Satisfiable (C : Circuit) : Prop := ∃ ρ, check C ρ = true |
| 47 | |
| 48 | end Lax429075.Circuits |
| 49 |
Discussion
Ask a question or add context. Endorsements and structured flags are kept in the review panel above.
0 comments