Partial evaluation of AC0 circuits #
This module rebuilds arbitrary-fan-in AC0 programs after a Boolean partial assignment. Fixed inputs and forced gates are represented as residual Boolean constants, while genuinely live values are represented by wires over the compact namespace of live variables.
The local connective simplifier is deliberately algebraic. An absorbing constant forces an AND or OR gate; otherwise neutral constants are discarded and the remaining wires feed one residual gate. No truth-table search or finite-circuit optimization is involved.
The arbitrary-fan-in operation associated with a connective.
Equations
Instances For
The neutral Boolean for a connective.
Instances For
The Boolean which forces a connective independently of other inputs.
Instances For
Boolean semantics of an arbitrary-fan-in connective.
Equations
Instances For
Source logical depth of an arbitrary-fan-in connective.
Equations
Instances For
A Boolean constant or a wire in a partially evaluated AC0 program.
- constant {n g : ℕ} (value : Bool) : ResidualValue n g
- wire {n g : ℕ} (wire : Wire n g) : ResidualValue n g
Instances For
Equations
- Algebraic.AC0.instDecidableEqResidualValue.decEq (Algebraic.AC0.ResidualValue.constant a) (Algebraic.AC0.ResidualValue.constant b) = if h : a = b then h ▸ isTrue ⋯ else isFalse ⋯
- Algebraic.AC0.instDecidableEqResidualValue.decEq (Algebraic.AC0.ResidualValue.constant value) (Algebraic.AC0.ResidualValue.wire wire) = isFalse ⋯
- Algebraic.AC0.instDecidableEqResidualValue.decEq (Algebraic.AC0.ResidualValue.wire wire) (Algebraic.AC0.ResidualValue.constant value) = isFalse ⋯
- Algebraic.AC0.instDecidableEqResidualValue.decEq (Algebraic.AC0.ResidualValue.wire a) (Algebraic.AC0.ResidualValue.wire b) = if h : a = b then h ▸ isTrue ⋯ else isFalse ⋯
Instances For
Evaluate a residual value in a residual program.
Equations
- Algebraic.AC0.ResidualValue.eval program input (Algebraic.AC0.ResidualValue.constant value) = value
- Algebraic.AC0.ResidualValue.eval program input (Algebraic.AC0.ResidualValue.wire sourceWire) = program.trace Algebraic.AC0.interpretation input sourceWire
Instances For
Transport a residual value through a wire map.
Equations
- Algebraic.AC0.ResidualValue.mapWires wireMap (Algebraic.AC0.ResidualValue.constant value) = Algebraic.AC0.ResidualValue.constant value
- Algebraic.AC0.ResidualValue.mapWires wireMap (Algebraic.AC0.ResidualValue.wire sourceWire) = Algebraic.AC0.ResidualValue.wire (wireMap sourceWire)
Instances For
Return the represented wire, if the value is nonconstant.
Equations
- (Algebraic.AC0.ResidualValue.constant value).wire? = none
- (Algebraic.AC0.ResidualValue.wire sourceWire).wire? = some sourceWire
Instances For
Logical depth of a residual value, assigning depth zero to constants.
Equations
- Algebraic.AC0.ResidualValue.logicalDepth program (Algebraic.AC0.ResidualValue.constant value) = 0
- Algebraic.AC0.ResidualValue.logicalDepth program (Algebraic.AC0.ResidualValue.wire sourceWire) = program.trace Algebraic.AC0.logicalDepthInterpretation (fun (x : Fin n) => 0) sourceWire
Instances For
Mapping residual wires preserves evaluation when the wire map preserves the preceding program trace.
Mapping residual wires preserves logical depth when the wire map preserves the preceding depth trace.
The nonconstant arguments of a gate, in their original order.
Equations
Instances For
A connective gate whose constant arguments have been removed.
Equations
- Algebraic.AC0.residualLine Algebraic.AC0.Connective.and wires = { op := Algebraic.AC0.Op.and wires.length, wires := wires.get }
- Algebraic.AC0.residualLine Algebraic.AC0.Connective.or wires = { op := Algebraic.AC0.Op.or wires.length, wires := wires.get }
Instances For
Result of locally simplifying one charged connective gate.
- value {n g : ℕ} (result : ResidualValue n g) : GateReduction n g
- line {n g : ℕ} (result : Line signature n g) : GateReduction n g
Instances For
Evaluate a local gate reduction against its preceding program.
Equations
- Algebraic.AC0.GateReduction.eval program input (Algebraic.AC0.GateReduction.value result) = Algebraic.AC0.ResidualValue.eval program input result
- Algebraic.AC0.GateReduction.eval program input (Algebraic.AC0.GateReduction.line result) = result.eval Algebraic.AC0.interpretation input (program.eval Algebraic.AC0.interpretation input)
Instances For
Whether the reduction retains one charged gate.
Equations
- (Algebraic.AC0.GateReduction.value result).cost = 0
- (Algebraic.AC0.GateReduction.line result).cost = 1
Instances For
Charged AND/OR cost contributed by a local gate reduction.
Equations
- (Algebraic.AC0.GateReduction.value result).chargedCost = 0
- (Algebraic.AC0.GateReduction.line result).chargedCost = Algebraic.AC0.andOrCost result.op
Instances For
Logical depth contributed by a local gate reduction.
Equations
- One or more equations did not get rendered due to their size.
- Algebraic.AC0.GateReduction.logicalDepth program (Algebraic.AC0.GateReduction.value result) = Algebraic.AC0.ResidualValue.logicalDepth program result
Instances For
Simplify one arbitrary-fan-in AND or OR from already restricted arguments.
Equations
- One or more equations did not get rendered due to their size.
Instances For
If a gate is not forced, every constant argument is its connective's neutral value.
Removing neutral constants from a non-forced connective preserves its Boolean value.
An absorbing residual constant forces the original connective.
If no argument is a wire and the connective is not forced, all arguments are neutral and so is the gate output.
The local simplifier exactly preserves the value of an arbitrary-fan-in AND or OR gate.
Local connective simplification never contributes more than one charged gate.
Local connective simplification does not increase logical depth when each residual argument is no deeper than its source argument.
A unary NOT gate on a residual value: constants are folded and wires retain one zero-cost NOT line.
Equations
- One or more equations did not get rendered due to their size.
- Algebraic.AC0.simplifyNot (Algebraic.AC0.ResidualValue.constant value_1) = Algebraic.AC0.GateReduction.value (Algebraic.AC0.ResidualValue.constant !value_1)
Instances For
Simplify an AC0 line after assigning a residual value to every wire it reads.
Equations
- One or more equations did not get rendered due to their size.
- Algebraic.AC0.simplifyLine { op := Algebraic.AC0.Op.not, wires := wires } x✝ = Algebraic.AC0.simplifyNot (x✝ (wires 0))
Instances For
Line simplification preserves the operation's value under the residual wire valuation.
A simplified line costs no more charged gates than its source line.
A simplified line is no deeper than its source line when every represented wire is no deeper than the corresponding source wire.
Whole-program restriction #
The residual representation of one original input.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A proof-carrying partial evaluation of every wire in an AC0 program.
- gateCount : ℕ
Number of gates in the residual program.
Residual program over exactly the live variables.
- values : Wire n g → ResidualValue rho.liveCount self.gateCount
Constant-or-wire representation of every source wire.
- trace_eq (input : Fin rho.liveCount → Bool) (sourceWire : Wire n g) : ResidualValue.eval self.result input (self.values sourceWire) = source.trace interpretation (rho.toLiveInputSubstitution.apply input) sourceWire
Every represented wire has its exact restricted semantics.
- logicalDepth_le (sourceWire : Wire n g) : ResidualValue.logicalDepth self.result (self.values sourceWire) ≤ source.trace logicalDepthInterpretation (fun (x : Fin n) => 0) sourceWire
Every residual wire is no deeper than the source wire it represents.
Partial evaluation does not increase the total gate count.
Partial evaluation does not increase charged AND/OR cost.
Instances For
Restriction of the empty program compactly reindexes its live inputs.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Evaluate a source line through a restriction of its preceding program.
Delete the new last source gate because its residual value is already available.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Retain the new last source gate as one residual line. Earlier residual wires are embedded into the extended program.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Simplify and append one source line to a restricted prefix.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Partially evaluate every gate of an AC0 program under rho, rebuilding it
over exactly the live input coordinates.
Equations
- Algebraic.AC0.restrictProgram rho Cslib.Circuits.Program.empty = Algebraic.AC0.ProgramRestriction.empty rho
- Algebraic.AC0.restrictProgram rho (source.gate line) = (Algebraic.AC0.restrictProgram rho source).append line
Instances For
Residual circuits #
An AC0 program whose designated outputs may be Boolean constants. Keeping constants explicit is necessary for exact cost monotonicity: restricting a zero-gate projection can produce a constant function.
Internal residual program.
- outputs : Fin m → ResidualValue n g
Constant-or-wire representative of each designated output.
Instances For
Evaluate all designated residual outputs.
Equations
- circuit.eval input output = Algebraic.AC0.ResidualValue.eval circuit.program input (circuit.outputs output)
Instances For
Charged AND/OR cost of a residual circuit.
Equations
- circuit.cost = Cslib.Circuits.Program.cost Algebraic.AC0.andOrCost circuit.program
Instances For
Logical depth of every residual output, with constant outputs at depth zero.
Equations
- circuit.logicalOutputDepths output = Algebraic.AC0.ResidualValue.logicalDepth circuit.program (circuit.outputs output)
Instances For
Maximum logical depth of a residual output.
Equations
- circuit.logicalDepth = Fin.foldl m (fun (depth : ℕ) (output : Fin m) => max depth (circuit.logicalOutputDepths output)) 0
Instances For
A one-output residual circuit's depth is its sole output depth.
A circuit-level partial evaluation over the compact namespace of live variables.
- gateCount : ℕ
Number of gates in the residual circuit.
- result : ResidualCircuit rho.liveCount self.gateCount m
Residual circuit, including explicit constant outputs.
- eval_eq (input : Fin rho.liveCount → Bool) : self.result.eval input = source.eval interpretation (rho.toLiveInputSubstitution.apply input)
Exact pointwise semantics under the compact input substitution.
- logicalOutputDepths_le (output : Fin m) : self.result.logicalOutputDepths output ≤ Circuit.logicalOutputDepths source output
Every residual output is no deeper than its source output.
Partial evaluation does not increase total gate count.
Partial evaluation does not increase charged AND/OR cost.
Instances For
Partially evaluate an arbitrary-output AC0 circuit under rho.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Exact residual-circuit restriction does not increase logical depth.
The compact residual circuit also realizes the original same-width restriction after projecting a complete input to its live coordinates.
Materializing a one-output residual circuit #
A nullary gate realizing a Boolean constant.
Equations
- Algebraic.AC0.constantLine false = { op := Algebraic.AC0.Op.or 0, wires := Fin.elim0 }
- Algebraic.AC0.constantLine true = { op := Algebraic.AC0.Op.and 0, wires := Fin.elim0 }
Instances For
Materializing the sole output of a residual circuit as an ordinary wire requires at most one nullary constant gate.
Ordinary one-output circuit.
Materialization preserves the residual output.
Materializing a constant output adds at most one logical level.
At most one gate is added.
At most one charged constant gate is added.
Instances For
Gate count of the ordinary circuit.
Instances For
Convert a one-output residual circuit into an ordinary circuit. Wire outputs are free; constant outputs receive one nullary AND or OR gate.
Equations
- One or more equations did not get rendered due to their size.
Instances For
An ordinary one-output circuit obtained by partial evaluation. The single unit of possible overhead is exactly the cost of materializing a constant output as a wire.
Ordinary circuit over exactly the live variables.
- eval_eq (input : Fin rho.liveCount → Bool) : self.result.eval interpretation input = source.eval interpretation (rho.toLiveInputSubstitution.apply input)
Exact pointwise semantics under the compact input substitution.
Restriction plus constant-output materialization adds at most one logical level.
Restriction and output materialization add at most one gate overall.
Charged AND/OR cost grows by at most the one constant-output gate.
Instances For
Gate count of the materialized restricted circuit.
Instances For
Partially evaluate a one-output AC0 circuit and materialize its output as an ordinary circuit wire.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Same-width semantics of the materialized restricted circuit.