Documentation

Complexitylib.Algebraic.Basis.Arithmetic.Expression

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.

inductive Algebraic.Arithmetic.Expression (C : Type u) (n : ℕ) :

Tree-shaped arithmetic expressions with named constants.

Instances For
    @[reducible]

    Number of gates emitted by tree compilation. Inputs are free.

    Equations
    Instances For
      @[reducible]
      def Algebraic.Arithmetic.Expression.weightedCost {C : Type u_1} {n : ℕ} (addition multiplication : ℕ) :
      Expression C n → ℕ

      Weighted number of binary arithmetic nodes. Constants are free, matching Arithmetic.weightedCost; tree compilation realizes this cost exactly.

      Equations
      Instances For
        @[reducible]

        Number of multiplication nodes in an expression.

        Equations
        Instances For
          @[reducible]

          Number of addition nodes in an expression.

          Equations
          Instances For
            def Algebraic.Arithmetic.Expression.eval {R : Type u_1} {C : Type u_2} {n : ℕ} [Add R] [Mul R] (constant : C → R) (input : Fin n → R) :
            Expression C n → R

            Evaluate an expression in an arbitrary arithmetic carrier.

            Equations
            Instances For
              structure Algebraic.Arithmetic.Expression.Compilation {C : Type u_1} {n : ℕ} (expression : Expression C n) :
              Type u_1

              A compiled expression program together with its result wire.

              Instances For
                def Algebraic.Arithmetic.Expression.compile {C : Type u_1} {n : ℕ} (expression : Expression C n) :
                expression.Compilation

                Compile an arithmetic expression to a straight-line program.

                Equations
                Instances For
                  def Algebraic.Arithmetic.Expression.circuit {C : Type u_1} {n : ℕ} (expression : Expression C n) :

                  The one-output circuit emitted for an expression.

                  Equations
                  Instances For
                    @[simp]
                    theorem Algebraic.Arithmetic.Expression.size_circuit {C : Type u_1} {n : ℕ} (expression : Expression C n) :
                    expression.circuit.size = expression.gateCount

                    The circuit emitted for an expression has exactly the expression gate count.

                    theorem Algebraic.Arithmetic.Expression.compile_weightedCost {C : Type u_1} {n : ℕ} (addition multiplication : ℕ) (expression : Expression C n) :
                    Program.cost (Arithmetic.weightedCost addition multiplication) expression.compile.program = weightedCost addition multiplication expression

                    Tree compilation preserves every binary arithmetic weighting exactly.

                    @[simp]

                    Exact multiplicative complexity of a compiled expression.

                    @[simp]
                    theorem Algebraic.Arithmetic.Expression.circuit_additionCost {C : Type u_1} {n : ℕ} (expression : Expression C n) :
                    expression.circuit.cost additionCost = expression.additionCount

                    Exact additive complexity of a compiled expression.

                    theorem Algebraic.Arithmetic.Expression.compile_trace {R : Type u_1} {C : Type u_2} {n : ℕ} [Add R] [Mul R] (constant : C → R) (input : Fin n → R) (expression : Expression C n) :
                    expression.compile.program.trace (interpretation constant) input expression.compile.output = eval constant input expression

                    Tree compilation preserves expression evaluation.

                    theorem Algebraic.Arithmetic.Expression.circuit_eval {R : Type u_1} {C : Type u_2} {n : ℕ} [Add R] [Mul R] (constant : C → R) (input : Fin n → R) (expression : Expression C n) :
                    expression.circuit.eval (interpretation constant) input 0 = eval constant input expression

                    Circuit evaluation of a compiled expression is its direct evaluation.