Documentation

Complexitylib.Algebraic.Basis.DeMorgan.CSLib

Conversions to CSLib's Boolean basis #

CSLib counts constants, negations, conjunctions, and disjunctions as gates. Our De Morgan basis also has an identity operation and supports weighted costs. The realizations below preserve all outputs: importing a CSLib circuit preserves its gate count, while exporting a De Morgan circuit removes identity gates. Neither conversion identifies standardCost with CSLib size, since constants are free under standardCost.

@[simp]

Each CSLib De Morgan operation is simulated by exactly one gate of this library's De Morgan basis.

@[simp]

Importing a CSLib circuit preserves the number of internal gates.

Weighted logical-gate cost is at most the imported CSLib gate count.

@[simp]

The CSLib simulation of each operation uses toBooleanGateCount gates.

theorem Algebraic.DeMorgan.toBoolean_size_le {n m : ℕ} (circuit : Circuit signature n m) :
(toBoolean.compile circuit).size ≤ circuit.size

Removing identity gates never increases the internal gate count.

theorem Algebraic.DeMorgan.boolean_computes_iff {n : ℕ} (circuit : Circuit Cslib.Circuits.Boolean.signature n 1) (function : Cslib.BooleanFunction n) :
(circuit.Computes Cslib.Circuits.Boolean.interpretation fun (input : Fin n → Bool) (x : Fin 1) => function input) ↔ circuit.ComputesWith Cslib.Circuits.Boolean.interpretation fun (input : Fin n → Bool) (x : Fin 1) => function input

CSLib's Circuit.Computes and this library's Circuit.ComputesWith are the same predicate, so this holds by Iff.rfl. It is definitional and kept only for compatibility with code written against the earlier, scalar CSLib predicate.

theorem Algebraic.DeMorgan.fromBoolean_computes {n : ℕ} (circuit : Circuit Cslib.Circuits.Boolean.signature n 1) (function : Cslib.BooleanFunction n) :
((fromBoolean.compile circuit).ComputesWith interpretation fun (input : Fin n → Bool) (x : Fin 1) => function input) ↔ circuit.Computes Cslib.Circuits.Boolean.interpretation fun (input : Fin n → Bool) (x : Fin 1) => function input

The imported De Morgan circuit computes function on its single output exactly when the CSLib circuit does.

theorem Algebraic.DeMorgan.toBoolean_computes {n : ℕ} (circuit : Circuit signature n 1) (function : ScalarFunction Bool n) :
((toBoolean.compile circuit).Computes Cslib.Circuits.Boolean.interpretation fun (input : Fin n → Bool) (x : Fin 1) => function input) ↔ circuit.ComputesWith interpretation fun (input : Fin n → Bool) (x : Fin 1) => function input

The exported CSLib circuit computes function on its single output exactly when the De Morgan circuit does.