Residual values for De Morgan circuits #
Partial evaluation represents a Boolean value by a constant or a possibly negated wire. This module contains the local Boolean simplifier and the small proof-carrying constructions that realize such values inside a De Morgan program. Whole-program restriction is deliberately kept in a separate module.
A Boolean constant or a signed wire in a residual program.
- constant {n g : ℕ} (value : Bool) : ResidualValue n g
- wire {n g : ℕ} (negated : Bool) (wire : Wire n g) : ResidualValue n g
Instances For
Equations
- One or more equations did not get rendered due to their size.
- Algebraic.DeMorgan.instDecidableEqResidualValue.decEq (Algebraic.DeMorgan.ResidualValue.constant a) (Algebraic.DeMorgan.ResidualValue.constant b) = if h : a = b then h ▸ isTrue ⋯ else isFalse ⋯
- Algebraic.DeMorgan.instDecidableEqResidualValue.decEq (Algebraic.DeMorgan.ResidualValue.constant value) (Algebraic.DeMorgan.ResidualValue.wire negated wire) = isFalse ⋯
- Algebraic.DeMorgan.instDecidableEqResidualValue.decEq (Algebraic.DeMorgan.ResidualValue.wire negated wire) (Algebraic.DeMorgan.ResidualValue.constant value) = isFalse ⋯
Instances For
Evaluate a residual value in a residual program.
Equations
- One or more equations did not get rendered due to their size.
- Algebraic.DeMorgan.ResidualValue.eval program input (Algebraic.DeMorgan.ResidualValue.constant value) = value
Instances For
Transport a residual value through a wire map.
Equations
- Algebraic.DeMorgan.ResidualValue.mapWires wireMap (Algebraic.DeMorgan.ResidualValue.constant value) = Algebraic.DeMorgan.ResidualValue.constant value
- Algebraic.DeMorgan.ResidualValue.mapWires wireMap (Algebraic.DeMorgan.ResidualValue.wire negated residualWire) = Algebraic.DeMorgan.ResidualValue.wire negated (wireMap residualWire)
Instances For
Boolean negation of a residual value.
Equations
- (Algebraic.DeMorgan.ResidualValue.constant value).negate = Algebraic.DeMorgan.ResidualValue.constant !value
- (Algebraic.DeMorgan.ResidualValue.wire negated residualWire).negate = Algebraic.DeMorgan.ResidualValue.wire (!negated) residualWire
Instances For
Replace every wire in a residual value by another residual value. This is the small substitution operation used to state that partial evaluation follows zero-cost origin chains.
Equations
- (Algebraic.DeMorgan.ResidualValue.constant value_1).bindWires values = Algebraic.DeMorgan.ResidualValue.constant value_1
- (Algebraic.DeMorgan.ResidualValue.wire negated residualWire).bindWires values = if negated = true then (values residualWire).negate else values residualWire
Instances For
The two charged De Morgan connectives.
Instances For
Operation symbol corresponding to a charged connective.
Equations
Instances For
The value which makes a binary operation independent of its other input.
Equations
Instances For
Simplify a binary De Morgan gate. none means both signed inputs are genuinely
needed and the charged gate must be retained.
Equations
- One or more equations did not get rendered due to their size.
- Algebraic.DeMorgan.simplifyBinary Algebraic.DeMorgan.BinaryOp.and (Algebraic.DeMorgan.ResidualValue.constant false) right = some (Algebraic.DeMorgan.ResidualValue.constant false)
- Algebraic.DeMorgan.simplifyBinary Algebraic.DeMorgan.BinaryOp.and left (Algebraic.DeMorgan.ResidualValue.constant false) = some (Algebraic.DeMorgan.ResidualValue.constant false)
- Algebraic.DeMorgan.simplifyBinary Algebraic.DeMorgan.BinaryOp.and (Algebraic.DeMorgan.ResidualValue.constant true) right = some right
- Algebraic.DeMorgan.simplifyBinary Algebraic.DeMorgan.BinaryOp.and left (Algebraic.DeMorgan.ResidualValue.constant true) = some left
- Algebraic.DeMorgan.simplifyBinary Algebraic.DeMorgan.BinaryOp.or (Algebraic.DeMorgan.ResidualValue.constant true) right = some (Algebraic.DeMorgan.ResidualValue.constant true)
- Algebraic.DeMorgan.simplifyBinary Algebraic.DeMorgan.BinaryOp.or left (Algebraic.DeMorgan.ResidualValue.constant true) = some (Algebraic.DeMorgan.ResidualValue.constant true)
- Algebraic.DeMorgan.simplifyBinary Algebraic.DeMorgan.BinaryOp.or (Algebraic.DeMorgan.ResidualValue.constant false) right = some right
- Algebraic.DeMorgan.simplifyBinary Algebraic.DeMorgan.BinaryOp.or left (Algebraic.DeMorgan.ResidualValue.constant false) = some left
Instances For
A false argument annihilates an AND gate, in either input position.
A true argument annihilates an OR gate, in either input position.
Any constant argument makes a binary De Morgan gate simplifiable.
Two signed forms of one residual value always make a binary gate simplify.
simplifyBinary preserves the value of a gate whenever it succeeds.
Materialization #
A free constant line.
Equations
- Algebraic.DeMorgan.constantLine false = { op := Algebraic.DeMorgan.Op.false, wires := Fin.elim0 }
- Algebraic.DeMorgan.constantLine true = { op := Algebraic.DeMorgan.Op.true, wires := Fin.elim0 }
Instances For
A free identity line.
Equations
- Algebraic.DeMorgan.identityLine sourceWire = { op := Algebraic.DeMorgan.Op.id, wires := fun (x : Fin (Algebraic.DeMorgan.signature.Arity Algebraic.DeMorgan.Op.id)) => sourceWire }
Instances For
A free negation line.
Equations
- Algebraic.DeMorgan.notLine sourceWire = { op := Algebraic.DeMorgan.Op.not, wires := fun (x : Fin (Algebraic.DeMorgan.signature.Arity Algebraic.DeMorgan.Op.not)) => sourceWire }
Instances For
A charged binary line.
Equations
- Algebraic.DeMorgan.binaryLine Algebraic.DeMorgan.BinaryOp.and left right = { op := Algebraic.DeMorgan.Op.and, wires := fun (i : Fin (1 + 1)) => Fin.cases left (fun (x : Fin 1) => right) i }
- Algebraic.DeMorgan.binaryLine Algebraic.DeMorgan.BinaryOp.or left right = { op := Algebraic.DeMorgan.Op.or, wires := fun (i : Fin (1 + 1)) => Fin.cases left (fun (x : Fin 1) => right) i }
Instances For
Every argument wire of a binary line is one of its two named inputs.
Every binary AND line is determined by its two arguments.
Every binary OR line is determined by its two arguments.
Applying a binary line to an arbitrary wire valuation reads its two inputs.
Materialize a residual value as a wire, adding only zero-cost gates and embedding every old wire into the extended program.
- gateCount : ℕ
Gate count of the extended program.
Extended program.
- embedding : Wire.Renaming n g self.gateCount
Inclusion of all old wires.
Wire carrying the materialized value.
- embedding_eq (input : Fin n → Bool) (sourceWire : Wire n g) : self.result.trace interpretation input (self.embedding.apply sourceWire) = program.trace interpretation input sourceWire
The embedding preserves every old wire.
- output_eq (input : Fin n → Bool) : self.result.trace interpretation input self.output = ResidualValue.eval program input value
The output wire realizes
value. Materialization has zero charged cost.
Instances For
Materialize a constant or signed wire using at most one free gate.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Retain a genuinely binary gate after materializing its signed arguments. The extension adds exactly one unit of charged cost.
- gateCount : ℕ
Gate count of the extended program.
Extended program ending in the retained charged gate.
- embedding : Wire.Renaming n g self.gateCount
Inclusion of all old wires.
Output of the retained gate.
- embedding_eq (input : Fin n → Bool) (sourceWire : Wire n g) : self.result.trace interpretation input (self.embedding.apply sourceWire) = program.trace interpretation input sourceWire
The embedding preserves every old wire.
- output_eq (input : Fin n → Bool) : self.result.trace interpretation input self.output = op.eval (ResidualValue.eval program input left) (ResidualValue.eval program input right)
The output has the requested binary semantics.
Retaining the gate adds exactly one unit of charged cost.
Instances For
Materialize two signed arguments and append their charged gate.
Equations
- One or more equations did not get rendered due to their size.