Bases of Boolean operations #
This file defines bit strings, families of Boolean functions, and the bases of Boolean operations over which circuits are built.
Each basis is also a CSLib signature, so CSLib's circuits
(Cslib.Circuits.Circuit, straight-line programs over a signature) can be
built over it without changing its cost model. An operation symbol of
B.signature is a whole gate kind of B: an operation, a fan-in that the
operation allows, and a negation flag for each input. Its interpretation
B.interpretation negates the flagged inputs and applies the operation, so
negations stay free, and a basis with unbounded fan-in becomes a signature with
infinitely many operation symbols. CSLib's size over B.signature is thus this
library's convention (one unit per gate, whatever its fan-in or negation
pattern), not the size over CSLib's De Morgan basis, which charges negation
gates; Complexitylib.Interop.Cslib.Circuit relates the two.
Main definitions #
BitString— a string of bits of a specific lengthBoolFunFamily— a family of Boolean functions indexed by input lengthArity— an arity constraint for the operations of a basisBasis— a basis of Boolean operations with arity constraintsBasis.GateKind,Basis.signature,Basis.interpretation— a basis as a CSLib signature and its Boolean interpretation
A BitString of length n.
Equations
- Complexity.BitString n = (Fin n → Bool)
Instances For
A family of Boolean functions indexed by input length N.
Each member maps N-bit strings to a single output bit.
Equations
- Complexity.BoolFunFamily = ((N : ℕ) → Complexity.BitString N → Bool)
Instances For
Equations
- Complexity.instReprArity = { reprPrec := Complexity.instReprArity.repr }
Equations
- One or more equations did not get rendered due to their size.
- Complexity.instReprArity.repr Complexity.Arity.unbounded prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "Complexity.Arity.unbounded")).group prec✝
Instances For
Equations
- Complexity.instDecidableEqArity.decEq Complexity.Arity.unbounded Complexity.Arity.unbounded = isTrue ⋯
- Complexity.instDecidableEqArity.decEq Complexity.Arity.unbounded (Complexity.Arity.exactly k) = isFalse ⋯
- Complexity.instDecidableEqArity.decEq Complexity.Arity.unbounded (Complexity.Arity.upto k) = isFalse ⋯
- Complexity.instDecidableEqArity.decEq (Complexity.Arity.exactly k) Complexity.Arity.unbounded = isFalse ⋯
- Complexity.instDecidableEqArity.decEq (Complexity.Arity.exactly a) (Complexity.Arity.exactly b) = if h : a = b then h ▸ isTrue ⋯ else isFalse ⋯
- Complexity.instDecidableEqArity.decEq (Complexity.Arity.exactly k) (Complexity.Arity.upto k_1) = isFalse ⋯
- Complexity.instDecidableEqArity.decEq (Complexity.Arity.upto k) Complexity.Arity.unbounded = isFalse ⋯
- Complexity.instDecidableEqArity.decEq (Complexity.Arity.upto k) (Complexity.Arity.exactly k_1) = isFalse ⋯
- Complexity.instDecidableEqArity.decEq (Complexity.Arity.upto a) (Complexity.Arity.upto b) = if h : a = b then h ▸ isTrue ⋯ else isFalse ⋯
Instances For
Whether n satisfies an arity constraint.
Equations
- Complexity.Arity.unbounded.satisfiedBy x✝ = True
- (Complexity.Arity.exactly k).satisfiedBy x✝ = (x✝ = k)
- (Complexity.Arity.upto k).satisfiedBy x✝ = (x✝ ≤ k)
Instances For
Equations
- One or more equations did not get rendered due to their size.
A basis of Boolean operations.
Each operation has an arity constraint and an evaluation function that computes the output bit from any valid number of input bits.
- Op : Type
The type of operations (e.g., AND, OR, NOT).
The arity constraint for each operation.
Evaluate an operation on
ninput bits, given thatnsatisfies the arity.
Instances For
A gate kind of the basis B: an operation, a fan-in that the operation
allows, and a negation flag for each input.
- op : B.Op
The basis operation.
- fanIn : ℕ
The number of inputs.
- arityOk : (B.arity self.op).satisfiedBy self.fanIn
The operation allows this fan-in.
Which inputs are negated before the operation is applied.
Instances For
The interpretation of a basis's signature: a gate kind negates the flagged
inputs and applies its operation, exactly as Gate.eval does
(Basis.interpretation_kind in Complexitylib.Circuits.StraightLine).