Documentation

CslibFrontier.Computability.Circuit.Arithmetic.FormulaOps

Substitution into arithmetic formulas of unbounded fan-in #

Operations on the formulas Cslib.Circuits.Arithmetic.SPFormula of sum and product gates of unbounded fan-in, each with the polynomial it computes, a bound on its product-depth and a bound on its number of nodes.

SPFormula.substFormula G F replaces every input i of F by the formula G i; it computes the polynomial of F with the polynomials of the G i substituted for the variables. The product-depths add, and the number of nodes is at most the product of that of F and a common bound for the G i. Two families of formulas of product-depth zero are provided for G, so that substituting them does not increase the product-depth: SPFormula.constInput, an input or a constant for every input, and SPFormula.affineInput, the sum gate a i * x_{ρ i} + b i for every input i.

SPFormula.ofSparse p is the formula of product-depth at most one that writes a polynomial p as the sum of its monomials: a sum gate over the support of p, with the coefficients on its edges, of product gates of inputs, an input being repeated as often as its exponent.

Linear combinations of formulas indexed by a finite set are the sum gates Cslib.Circuits.Arithmetic.SPFormula.sumOn; no separate operation is defined for them.

The total degree of the polynomial of a formula is at most its number of nodes (SPFormula.totalDegree_polynomial_le_nodeCount).

Main definitions #

Main results #

References #

Substitution of formulas #

def Cslib.Circuits.Arithmetic.SPFormula.substFormula {K : Type u_1} {n m : ℕ} (G : Fin n → SPFormula K m) (F : SPFormula K n) :

Substitute the formula G i for every input i of F: the substitution Cslib.Circuits.Formula.bind of formulas.

The substituted formula computes the substituted polynomial.

theorem Cslib.Circuits.Arithmetic.SPFormula.productDepth_substFormula_le {K : Type u_1} {n m : ℕ} {G : Fin n → SPFormula K m} {B : ℕ} (hG : ∀ (i : Fin n), (G i).productDepth ≤ B) (F : SPFormula K n) :

Substituting formulas of product-depth at most B adds at most B to the product-depth.

theorem Cslib.Circuits.Arithmetic.SPFormula.nodeCount_substFormula_le {K : Type u_1} {n m : ℕ} {G : Fin n → SPFormula K m} {S : ℕ} (hG : ∀ (i : Fin n), Formula.nodeCount (G i) ≤ S) (hS : 1 ≤ S) (F : SPFormula K n) :

Substituting formulas of at most S nodes, with 1 ≤ S, multiplies the number of nodes by at most S.

Formulas of product-depth zero to substitute #

def Cslib.Circuits.Arithmetic.SPFormula.constInput {K : Type u_1} {n m : ℕ} (ρ : Fin n → Fin m ⊕ K) (i : Fin n) :

An input or a constant for every input: the input j where ρ i = .inl j and the constant a where ρ i = .inr a.

@[simp]

constInput ρ i computes the variable or the constant ρ i.

@[simp]
theorem Cslib.Circuits.Arithmetic.SPFormula.productDepth_constInput {K : Type u_1} {n m : ℕ} (ρ : Fin n → Fin m ⊕ K) (i : Fin n) :

An input or a constant has product-depth zero.

@[simp]
theorem Cslib.Circuits.Arithmetic.SPFormula.nodeCount_constInput {K : Type u_1} {n m : ℕ} (ρ : Fin n → Fin m ⊕ K) (i : Fin n) :

An input or a constant is one node.

def Cslib.Circuits.Arithmetic.SPFormula.affineInput {K : Type u_1} {n m : ℕ} [One K] (ρ : Fin n → Fin m) (a b : Fin n → K) (i : Fin n) :

The affine form a i * x_{ρ i} + b i for every input i: a sum gate over the input ρ i, with edge constant a i, and the constant 1, with edge constant b i.

@[simp]
theorem Cslib.Circuits.Arithmetic.SPFormula.polynomial_affineInput {K : Type u_1} {n m : ℕ} [CommSemiring K] (ρ : Fin n → Fin m) (a b : Fin n → K) (i : Fin n) :

affineInput ρ a b i computes a i * x_{ρ i} + b i.

@[simp]
theorem Cslib.Circuits.Arithmetic.SPFormula.productDepth_affineInput {K : Type u_1} {n m : ℕ} [One K] (ρ : Fin n → Fin m) (a b : Fin n → K) (i : Fin n) :

An affine form has product-depth zero.

@[simp]
theorem Cslib.Circuits.Arithmetic.SPFormula.nodeCount_affineInput {K : Type u_1} {n m : ℕ} [One K] (ρ : Fin n → Fin m) (a b : Fin n → K) (i : Fin n) :

An affine form has three nodes: the sum gate, the input and the constant 1.

The sum of monomials #

noncomputable def Cslib.Circuits.Arithmetic.SPFormula.ofSparse {K : Type u_1} {n : ℕ} [CommSemiring K] (p : MvPolynomial (Fin n) K) :

The sum of the monomials of p: a sum gate over the support of p, with the coefficients of p as edge constants, of product gates of inputs, the input i occurring s i times in the product gate of the monomial s.

@[simp]

The sum of monomials of p computes p.

The sum of monomials has product-depth at most one.

The sum of monomials of p has at most #p.support * (p.totalDegree + 1) + 1 nodes: one product gate and at most p.totalDegree inputs for each monomial, and the sum gate.

Degree and size #

The total degree of the polynomial of a formula is at most its number of nodes.