Arithmetic expressions compiled to circuits #
This module supplies a small reusable expression language for arithmetic
circuits. Compilation is tree-shaped: the left subtree is emitted first, the
right subtree is instantiated after it over the same original inputs, and the
root operation is appended last. The result is a circuit whose bundled
size is definitionally the expression gate count.
Tree-shaped arithmetic expressions with named constants.
- input {C : Type u} {n : ℕ} (index : Fin n) : Expression C n
- constant {C : Type u} {n : ℕ} (value : C) : Expression C n
- add {C : Type u} {n : ℕ} (left right : Expression C n) : Expression C n
- mul {C : Type u} {n : ℕ} (left right : Expression C n) : Expression C n
Instances For
Number of gates emitted by tree compilation. Inputs are free.
Equations
Instances For
Weighted number of binary arithmetic nodes. Constants are free, matching
Arithmetic.weightedCost; tree compilation realizes this cost exactly.
Equations
- One or more equations did not get rendered due to their size.
- Algebraic.Arithmetic.Expression.weightedCost addition multiplication (Algebraic.Arithmetic.Expression.input index) = 0
- Algebraic.Arithmetic.Expression.weightedCost addition multiplication (Algebraic.Arithmetic.Expression.constant value) = 0
Instances For
Number of multiplication nodes in an expression.
Equations
Instances For
Number of addition nodes in an expression.
Equations
Instances For
Evaluate an expression in an arbitrary arithmetic carrier.
Equations
- Algebraic.Arithmetic.Expression.eval constant input (Algebraic.Arithmetic.Expression.input index) = input index
- Algebraic.Arithmetic.Expression.eval constant input (Algebraic.Arithmetic.Expression.constant value) = constant value
- Algebraic.Arithmetic.Expression.eval constant input (left.add right) = Algebraic.Arithmetic.Expression.eval constant input left + Algebraic.Arithmetic.Expression.eval constant input right
- Algebraic.Arithmetic.Expression.eval constant input (left.mul right) = Algebraic.Arithmetic.Expression.eval constant input left * Algebraic.Arithmetic.Expression.eval constant input right
Instances For
A compiled expression program together with its result wire.
Emitted straight-line program.
Wire carrying the expression value.
Instances For
Compile an arithmetic expression to a straight-line program.
Equations
- One or more equations did not get rendered due to their size.
- (Algebraic.Arithmetic.Expression.input index).compile = { program := Cslib.Circuits.Program.empty, output := Cslib.Circuits.Wire.input index }
Instances For
The one-output circuit emitted for an expression.
Equations
Instances For
The circuit emitted for an expression has exactly the expression gate count.
Tree compilation preserves every binary arithmetic weighting exactly.
Exact multiplicative complexity of a compiled expression.
Exact additive complexity of a compiled expression.
Tree compilation preserves expression evaluation.
Circuit evaluation of a compiled expression is its direct evaluation.