Documentation

CslibFrontier.Computability.Circuit.Arithmetic

Affine, polynomial and arithmetic bases #

Three ways of computing over a commutative semiring F:

The affine and arithmetic bases are polynomial. Over a finite field every operation is a polynomial, so the distinction matters only over infinite fields, where it is essential: an infinite field admits injections F × F → F, through which a single wire can carry any amount of information.

In an arithmetic circuit the constants are leaves, and Cslib.Circuits.Circuit.innerSize counts exactly the additions and multiplications.

Main definitions #

Main results #

References #

@[reducible, inline]

The affine basis over F: an operation of arity k is a vector of k coefficients and a constant.

An affine operation with coefficients a and constant b computes x ↦ ∑ i, a i * x i + b.

@[simp]
theorem Cslib.Circuits.affineInterpretation_apply (F : Type u) [Semiring F] (k : ℕ) (a : Fin k → F) (b : F) (x : Fin k → F) :
affineInterpretation F ⟨k, (a, b)⟩ x = ∑ i : Fin k, a i * x i + b

An affine operation with arity k, coefficients a and constant b.

inductive Cslib.Circuits.ArithOp (F : Type u) :

The operations of the arithmetic basis.

Instances For
    @[reducible, inline]

    The arity of an arithmetic operation: two for addition and multiplication, zero for a constant.

    @[reducible, inline]

    The arithmetic basis: addition and multiplication of arity two, and constants of arity zero.

    def Cslib.Circuits.arithInterpretationWith (F : Type u) {R : Type u_1} [Add R] [Mul R] (constant : F → R) :

    Addition and multiplication in R, with constant symbols interpreted by constant. For example, MvPolynomial.C interprets field constants as constant polynomials.

    Instances For

      Addition, multiplication and constants.

      @[simp]
      theorem Cslib.Circuits.arithInterpretationWith_add {F : Type u} {R : Type u_1} [Add R] [Mul R] (constant : F → R) (x : Fin 2 → R) :
      arithInterpretationWith F constant ArithOp.add x = x 0 + x 1

      Evaluating .add under arithInterpretationWith adds the two arguments.

      @[simp]
      theorem Cslib.Circuits.arithInterpretationWith_mul {F : Type u} {R : Type u_1} [Add R] [Mul R] (constant : F → R) (x : Fin 2 → R) :
      arithInterpretationWith F constant ArithOp.mul x = x 0 * x 1

      Evaluating .mul under arithInterpretationWith multiplies the two arguments.

      @[simp]
      theorem Cslib.Circuits.arithInterpretationWith_const {F : Type u} {R : Type u_1} [Add R] [Mul R] (constant : F → R) (c : F) (x : Fin 0 → R) :
      arithInterpretationWith F constant (ArithOp.const c) x = constant c

      Evaluating .const c under arithInterpretationWith applies constant to c.

      Multiplications cost one; additions and constants are free. Multiplication by a scalar still costs one.

      Additions cost one; multiplications and constants are free.

      theorem Cslib.Circuits.Circuit.eval₂_arithInterpretationWith_mvPolynomial {F : Type u} {S : Type u_1} {R : Type u_2} [CommSemiring S] [CommSemiring R] {n m : ℕ} (c : Circuit (arithSignature F) n m) (constant : F → S) (f : S →+* R) (x : Fin n → R) (j : Fin m) :

      Evaluating the formal polynomial computed by a circuit, with coefficients in S, along a ring homomorphism f : S →+* R agrees with evaluating the circuit in R with the constants mapped by f.

      theorem Cslib.Circuits.Circuit.eval_arithInterpretationWith_mvPolynomial {F : Type u} {R : Type u_1} [CommSemiring R] {n m : ℕ} (c : Circuit (arithSignature F) n m) (constant : F → R) (x : Fin n → R) (j : Fin m) :

      Evaluating the formal polynomial computed by a circuit agrees with evaluating the circuit in the coefficient semiring. The converse need not hold over a finite field.

      An interpretation is polynomial when every operation is given by a polynomial in its arguments.

      Arithmetic circuits have fan-in at most two.