Circuit α
is a type of (partly normalized) Boolean circuits,
where α
gives the type of free variables in the circuit.
Morally, it represents a function Bool → ⋯ → Bool
, where the number of Bool
arguments is equal
to the arity of α
. See also eval
for the explicit conversion of a circuit to a similar function
- tru: {α : Type u} → Circuit α
- fals: {α : Type u} → Circuit α
- var: {α : Type u} → Bool → α → Circuit α
var b x
represents literalx
or the negated literat¬x
, depending on the value ofb
- and: {α : Type u} → Circuit α → Circuit α → Circuit α
- or: {α : Type u} → Circuit α → Circuit α → Circuit α
- xor: {α : Type u} → Circuit α → Circuit α → Circuit α
Instances For
Equations
Instances For
Equations
- c.varsFinset = { val := ↑c.vars, nodup := ⋯ }
Instances For
Equations
Instances For
Equations
- Circuit.tru.evalv x_2 = true
- Circuit.fals.evalv x_2 = false
- (Circuit.var b x_2).evalv f = if b = true then f x_2 ⋯ else !f x_2 ⋯
- (c₁.and c₂).evalv f = ((c₁.evalv fun (i : α) (hi : i ∈ c₁.vars) => f i ⋯) && c₂.evalv fun (i : α) (hi : i ∈ c₂.vars) => f i ⋯)
- (c₁.or c₂).evalv f = ((c₁.evalv fun (i : α) (hi : i ∈ c₁.vars) => f i ⋯) || c₂.evalv fun (i : α) (hi : i ∈ c₂.vars) => f i ⋯)
- (c₁.xor c₂).evalv f = ((c₁.evalv fun (i : α) (hi : i ∈ c₁.vars) => f i ⋯) ^^ c₂.evalv fun (i : α) (hi : i ∈ c₂.vars) => f i ⋯)
Instances For
Equations
- Circuit.ofBool b = if b = true then Circuit.tru else Circuit.fals
Instances For
Equations
- Circuit.instPreorder = Preorder.mk ⋯ ⋯ ⋯
Equations
- Circuit.tru.simplifyNot = Circuit.fals
- Circuit.fals.simplifyNot = Circuit.tru
- (a.xor b).simplifyNot = a.simplifyNot.xor b
- (a.and b).simplifyNot = a.simplifyNot.or b.simplifyNot
- (a.or b).simplifyNot = a.simplifyNot.and b.simplifyNot
- (Circuit.var b a).simplifyNot = Circuit.var (!b) a
Instances For
Equations
- Circuit.instComplement = { complement := Circuit.simplifyNot }
theorem
Circuit.varsFinset_simplifyXor
{α : Type u}
[DecidableEq α]
(c₁ : Circuit α)
(c₂ : Circuit α)
:
Equations
Instances For
Equations
Instances For
Equations
- Circuit.tru.sumVarsLeft = []
- Circuit.fals.sumVarsLeft = []
- (Circuit.var a (Sum.inl x_1)).sumVarsLeft = [x_1]
- (Circuit.var a (Sum.inr val)).sumVarsLeft = []
- (c₁.and c₂).sumVarsLeft = (c₁.sumVarsLeft ++ c₂.sumVarsLeft).dedup
- (c₁.or c₂).sumVarsLeft = (c₁.sumVarsLeft ++ c₂.sumVarsLeft).dedup
- (c₁.xor c₂).sumVarsLeft = (c₁.sumVarsLeft ++ c₂.sumVarsLeft).dedup
Instances For
Equations
- Circuit.tru.sumVarsRight = []
- Circuit.fals.sumVarsRight = []
- (Circuit.var a (Sum.inl x_1)).sumVarsRight = []
- (Circuit.var a (Sum.inr val)).sumVarsRight = [val]
- (c₁.and c₂).sumVarsRight = (c₁.sumVarsRight ++ c₂.sumVarsRight).dedup
- (c₁.or c₂).sumVarsRight = (c₁.sumVarsRight ++ c₂.sumVarsRight).dedup
- (c₁.xor c₂).sumVarsRight = (c₁.sumVarsRight ++ c₂.sumVarsRight).dedup
Instances For
theorem
Circuit.eval_eq_of_eq_on_vars
{α : Type u}
[DecidableEq α]
{c : Circuit α}
{f : α → Bool}
{g : α → Bool}
(_h : ∀ x ∈ c.vars, f x = g x)
:
c.eval f = c.eval g
@[simp]
theorem
Circuit.mem_vars_iff_mem_sumVarsLeft
{α : Type u}
{β : Type v}
[DecidableEq α]
[DecidableEq β]
{c : Circuit (α ⊕ β)}
{x : α}
:
@[simp]
theorem
Circuit.mem_vars_iff_mem_sumVarsRight
{α : Type u}
{β : Type v}
[DecidableEq α]
[DecidableEq β]
{c : Circuit (α ⊕ β)}
{x : β}
:
theorem
Circuit.eval_eq_of_eq_on_sumVarsLeft_right
{α : Type u}
{β : Type v}
[DecidableEq α]
[DecidableEq β]
{c : Circuit (α ⊕ β)}
{f : α ⊕ β → Bool}
{g : α ⊕ β → Bool}
(_h₁ : ∀ x ∈ c.sumVarsLeft, f (Sum.inl x) = g (Sum.inl x))
(_h₂ : ∀ x ∈ c.sumVarsRight, f (Sum.inr x) = g (Sum.inr x))
:
c.eval f = c.eval g
Equations
- Circuit.bOr [] x = Circuit.fals
- Circuit.bOr (a :: l) x = List.foldl (fun (c : Circuit β) (x_1 : α) => c ||| x x_1) (x a) l
Instances For
Equations
- Circuit.bAnd [] x = Circuit.tru
- Circuit.bAnd (a :: l) x = List.foldl (fun (c : Circuit β) (x_1 : α) => c &&& x x_1) (x a) l
Instances For
def
Circuit.assignVars
{α : Type u}
{β : Type v}
[DecidableEq α]
(c : Circuit α)
(_f : (a : α) → a ∈ c.vars → β ⊕ Bool)
:
Circuit β
Equations
- Circuit.tru.assignVars x_2 = Circuit.tru
- Circuit.fals.assignVars x_2 = Circuit.fals
- (Circuit.var b x_2).assignVars f = Sum.elim (Circuit.var b) (fun (c : Bool) => if (b ^^ c) = true then Circuit.fals else Circuit.tru) (f x_2 ⋯)
- (c₁.and c₂).assignVars f = (c₁.assignVars fun (x : α) (hx : x ∈ c₁.vars) => f x ⋯) &&& c₂.assignVars fun (x : α) (hx : x ∈ c₂.vars) => f x ⋯
- (c₁.or c₂).assignVars f = (c₁.assignVars fun (x : α) (hx : x ∈ c₁.vars) => f x ⋯) ||| c₂.assignVars fun (x : α) (hx : x ∈ c₂.vars) => f x ⋯
- (c₁.xor c₂).assignVars f = (c₁.assignVars fun (x : α) (hx : x ∈ c₁.vars) => f x ⋯) ^^^ c₂.assignVars fun (x : α) (hx : x ∈ c₂.vars) => f x ⋯
Instances For
theorem
Circuit.varsFinset_assignVars
{α : Type u}
{β : Type v}
[DecidableEq α]
[DecidableEq β]
(c : Circuit α)
(f : (a : α) → a ∈ c.vars → β ⊕ Bool)
:
theorem
Circuit.card_varsFinset_assignVars_lt
{α : Type u}
{β : Type v}
[DecidableEq α]
[DecidableEq β]
(c : Circuit α)
(f : (a : α) → a ∈ c.vars → β ⊕ Bool)
(a : α)
(ha : a ∈ c.vars)
(b : Bool)
(hfa : f a ha = Sum.inr b)
:
(c.assignVars f).varsFinset.card < c.varsFinset.card
def
Circuit.fst
{α : Type u_1}
{β : Type u_2}
[DecidableEq α]
[DecidableEq β]
(c : Circuit (α ⊕ β))
:
Circuit α
Equations
- One or more equations did not get rendered due to their size.
Instances For
def
Circuit.snd
{α : Type u_1}
{β : Type u_2}
[DecidableEq α]
[DecidableEq β]
(c : Circuit (α ⊕ β))
:
Circuit β
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Instances For
def
Circuit.single
{α : Type u}
[DecidableEq α]
{s : List α}
(x : (a : α) → a ∈ s → Bool)
:
Circuit α
Equations
- Circuit.single x = Circuit.bAnd s fun (i : α) => if hi : i ∈ s then Circuit.var (x i hi) i else Circuit.tru
Instances For
@[simp]
theorem
Circuit.eval_single
{α : Type u}
[DecidableEq α]
{s : List α}
(x : (a : α) → a ∈ s → Bool)
(g : α → Bool)
:
@[irreducible]
def
Circuit.nonemptyAux
{α : Type u}
[DecidableEq α]
(c : Circuit α)
(l : List α)
(_hL : c.vars = l)
:
Equations
Instances For
Equations
- c.nonempty = ↑(c.nonemptyAux c.vars ⋯)
Instances For
Instances For
instance
Circuit.instDecidableRelLeOfDecidableEq
{α : Type u}
[DecidableEq α]
:
DecidableRel fun (x1 x2 : Circuit α) => x1 ≤ x2
Equations
- c₁.instDecidableRelLeOfDecidableEq c₂ = decidable_of_iff (((~~~c₁).or c₂).always_true = true) ⋯