Documentation

Complexitylib.Circuits.Frontier.Linear.Linearize

Linearizing polynomial circuits #

Affine circuits compute affine functions (Frontier.exists_affine_trace): in a circuit over the affine basis, the value of every wire is an affine function of the input.

Linearization (Frontier.exists_affine_circuit). Over an infinite field, a circuit with polynomial operations that computes a linear map x ↦ M x can be replaced by a circuit over the affine basis, with the same wires, that computes the same map. Each gate is replaced by its first-order Taylor expansion at the point its arguments take when the input is zero (Frontier.taylorOp, Frontier.linearize).

To see why this works, evaluate the circuit over the dual numbers F[ε], where ε² = 0, at the input ε x. Because the operations are polynomials, a gate whose arguments are z + ε v takes the value P(z) + ε ∑_a ∂_a P(z) v_a (Frontier.snd_aeval_dualNumber), and z is the value of the arguments at the zero input. So where the circuit takes the value a + ε b at ε x, the linearized circuit takes the value a + b at x (Frontier.trace_linearize). Over an infinite field a polynomial is determined by its values, so the polynomial computed at an output is the linear form ∑_j M_{ij} X_j, whose value at ε x is ε (M x)_i.

theorem Complexity.Frontier.exists_affine_trace {F : Type u_1} {n s : ℕ} [CommRing F] (p : Cslib.Circuits.Program (affineSignature F) n s) (w : Cslib.Circuits.Wire n s) :
∃ (L : (Fin n → F) →ₗ[F] F) (b : F), ∀ (x : Fin n → F), p.trace (affineInterpretation F) x w = L x + b

Affine circuits compute affine functions.

Polynomial interpretations over algebras #

noncomputable def Complexity.Frontier.polynomialInterpretation {F : Type u_1} {σ : Cslib.Circuits.Signature} [CommRing F] (P : (o : σ.Op) → MvPolynomial (Fin (σ.Arity o)) F) (R : Type u_2) [CommRing R] [Algebra F R] :

The interpretation over an F-algebra R in which each operation o substitutes its arguments into the polynomial P o. Every polynomial interpretation over F is of this form, for a suitable choice of the polynomials P.

Equations
Instances For
    theorem Complexity.Frontier.polynomialInterpretation_apply {F : Type u_1} {σ : Cslib.Circuits.Signature} [CommRing F] (P : (o : σ.Op) → MvPolynomial (Fin (σ.Arity o)) F) (R : Type u_2) [CommRing R] [Algebra F R] (o : σ.Op) (x : Fin (σ.Arity o) → R) :

    An operation of a polynomial interpretation substitutes its arguments into its polynomial.

    theorem Complexity.Frontier.map_trace_polynomialInterpretation {F : Type u_1} {n s : ℕ} {σ : Cslib.Circuits.Signature} [CommRing F] (P : (o : σ.Op) → MvPolynomial (Fin (σ.Arity o)) F) {R : Type u_2} {S : Type u_3} [CommRing R] [Algebra F R] [CommRing S] [Algebra F S] (φ : R →ₐ[F] S) (p : Cslib.Circuits.Program σ n s) (x : Fin n → R) (w : Cslib.Circuits.Wire n s) :
    φ (p.trace (polynomialInterpretation P R) x w) = p.trace (polynomialInterpretation P S) (fun (j : Fin n) => φ (x j)) w

    Evaluation of a program with polynomial operations commutes with algebra homomorphisms.

    First-order Taylor expansion #

    The real part of a polynomial at a dual number is its value at the real parts.

    Taylor expansion over the dual numbers. The dual part of P(z + ε v) is ∑_a ∂_a P(z) v_a.

    noncomputable def Complexity.Frontier.taylorOp {F : Type u_1} [CommRing F] {k : ℕ} (P : MvPolynomial (Fin k) F) (z : Fin k → F) :

    The affine operation computing the first-order Taylor expansion of P at z, y ↦ P(z) + ∑_a ∂_a P(z) (y_a - z_a).

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      theorem Complexity.Frontier.affineInterpretation_taylorOp {F : Type u_1} [CommRing F] {k : ℕ} (P : MvPolynomial (Fin k) F) (z y : Fin k → F) :

      The value of the first-order Taylor expansion of P at z.

      Linearization #

      noncomputable def Complexity.Frontier.linearize {F : Type u_1} {n : ℕ} {σ : Cslib.Circuits.Signature} [CommRing F] (P : (o : σ.Op) → MvPolynomial (Fin (σ.Arity o)) F) {s : ℕ} :

      The linearization of a program whose operations are the polynomials P: the program over the affine basis with the same wires, in which each gate is replaced by its first-order Taylor expansion at the point that its arguments take on the zero input.

      Equations
      Instances For
        theorem Complexity.Frontier.arity_lines_linearize {F : Type u_1} {n s : ℕ} {σ : Cslib.Circuits.Signature} [CommRing F] (P : (o : σ.Op) → MvPolynomial (Fin (σ.Arity o)) F) (p : Cslib.Circuits.Program σ n s) (g : Fin s) :

        Linearization preserves the arity of every gate.

        theorem Complexity.Frontier.innerGates_linearize {F : Type u_1} {n s : ℕ} {σ : Cslib.Circuits.Signature} [CommRing F] (P : (o : σ.Op) → MvPolynomial (Fin (σ.Arity o)) F) (p : Cslib.Circuits.Program σ n s) :

        Linearization preserves the inner gates.

        theorem Complexity.Frontier.fanInAtMost_linearize {F : Type u_1} {n s : ℕ} {σ : Cslib.Circuits.Signature} [CommRing F] (P : (o : σ.Op) → MvPolynomial (Fin (σ.Arity o)) F) (p : Cslib.Circuits.Program σ n s) (r : ℕ) :

        Linearization preserves fan-in.

        theorem Complexity.Frontier.fst_trace_dualNumber {F : Type u_1} {n s : ℕ} {σ : Cslib.Circuits.Signature} [CommRing F] (P : (o : σ.Op) → MvPolynomial (Fin (σ.Arity o)) F) (p : Cslib.Circuits.Program σ n s) (x : Fin n → F) (w : Cslib.Circuits.Wire n s) :

        The real part of the value of a wire at the input ε x is its value at the zero input.

        theorem Complexity.Frontier.trace_linearize {F : Type u_1} {n s : ℕ} {σ : Cslib.Circuits.Signature} [CommRing F] (P : (o : σ.Op) → MvPolynomial (Fin (σ.Arity o)) F) (p : Cslib.Circuits.Program σ n s) (x : Fin n → F) (w : Cslib.Circuits.Wire n s) :

        The linearized program. Where the original program takes the value a + ε b at the input ε x, the linearized program takes the value a + b at the input x.

        theorem Complexity.Frontier.trace_output_dualNumber {F : Type u_1} {n m : ℕ} {σ : Cslib.Circuits.Signature} [CommRing F] (P : (o : σ.Op) → MvPolynomial (Fin (σ.Arity o)) F) [IsDomain F] [Infinite F] (c : Cslib.Circuits.Circuit σ n m) (M : Matrix (Fin m) (Fin n) F) (hc : c.Computes (polynomialInterpretation P F) fun (x : Fin n → F) => M.mulVec x) (x : Fin n → F) (i : Fin m) :

        Over an infinite field, a circuit with polynomial operations that computes x ↦ M x takes the value ε (M x)_i at its output i on the input ε x.

        theorem Complexity.Frontier.exists_affine_circuit {F : Type u_1} {n m : ℕ} [Field F] [Infinite F] {σ : Cslib.Circuits.Signature} {I : Cslib.Circuits.Interpretation σ F} (hI : IsPolynomial I) (c : Cslib.Circuits.Circuit σ n m) (M : Matrix (Fin m) (Fin n) F) (hc : c.Computes I fun (x : Fin n → F) => M.mulVec x) :
        ∃ (c' : Cslib.Circuits.Circuit (affineSignature F) n m), c'.size = c.size ∧ c'.innerSize = c.innerSize ∧ (∀ (r : ℕ), c.FanInAtMost r → c'.FanInAtMost r) ∧ c'.Computes (affineInterpretation F) fun (x : Fin n → F) => M.mulVec x

        Linearization. Over an infinite field, a circuit with polynomial operations computing a linear map is matched by a circuit over the affine basis computing the same map, with the same number of gates, the same inner gates, and the same fan-in.