Documentation

CslibFrontier.Computability.Circuit.Rational.Affine

Rational hitting lists: affine realizations #

Every rational formula f has a linear realization: a square matrix Formula.pencil f of affine forms in the variables, indexed by a finite type Formula.Index f with f.nodeCount + 1 elements, together with a rational row and column. Wherever f is defined, the evaluated pencil is invertible and the row, inverse and column multiply to the value of f. Conversely, f is defined with an invertible value exactly when the pencils of its inverse nodes and of its augmented root are invertible (Formula.certificates_iff); no rational cancellation is performed.

Main definitions #

Main results #

References #

@[reducible, inline]

A constant coefficient and one rational coefficient per variable.

The affine form with the given constant and zero variable coefficients.

The affine coordinate form for one variable.

def Cslib.Circuits.Rational.Affine.eval {n : ℕ} {R : Type u_1} [Ring R] (c : ℚ →+* R) (X : Fin n → R) :

Evaluate an affine form in a rational algebra, with coefficients on the left.

@[simp]
theorem Cslib.Circuits.Rational.Affine.eval_constant {n : ℕ} {R : Type u_1} [Ring R] (c : ℚ →+* R) (X : Fin n → R) (a : ℚ) :
(eval c X) (constant a) = c a

The constant affine form constant a evaluates to c a.

@[simp]
theorem Cslib.Circuits.Rational.Affine.eval_variable {n : ℕ} {R : Type u_1} [Ring R] (c : ℚ →+* R) (X : Fin n → R) (i : Fin n) :
(eval c X) (varForm i) = X i

The coordinate affine form varForm i evaluates to X i.

def Cslib.Circuits.Rational.Affine.constMatrix {n : ℕ} {ι : Type u_2} {κ : Type u_3} (A : Matrix ι κ ℚ) :
Matrix ι κ (Form n)

Regard a rational matrix as a matrix of constant affine forms.

@[simp]
theorem Cslib.Circuits.Rational.Affine.eval_constMatrix {n : ℕ} {R : Type u_1} [Ring R] {ι : Type u_2} {κ : Type u_3} (c : ℚ →+* R) (X : Fin n → R) (A : Matrix ι κ ℚ) :
(constMatrix A).map ⇑(eval c X) = A.map ⇑c

Evaluating constMatrix A maps c over the entries of A.

The realization is defined by recursion on the native constructors input and gate, so that its index type reduces to sums of the index types of the arguments args j. The proofs below therefore also proceed by induction on the native constructors.

@[reducible]

The finite row and column index type of the formula's linear realization.

Instances For
    @[reducible]

    The index type of a realization is finite.

    @[reducible]

    The index type of a realization has decidable equality.

    The realization of a formula has one more row than the formula has nodes.

    The left row of the formula's linear realization.

    The right column of the formula's linear realization.

    The affine matrix pencil built recursively from a rational formula.

    @[reducible, inline]
    abbrev Cslib.Circuits.Rational.Formula.realized {n : ℕ} {R : Type u_1} [Ring R] (c : ℚ →+* R) (X : Fin n → R) (f : Formula n) :

    Evaluate all entries of the formula's affine pencil.

    @[reducible, inline]
    abbrev Cslib.Circuits.Rational.Formula.rowR {n : ℕ} {R : Type u_1} [Ring R] (c : ℚ →+* R) (f : Formula n) :

    Map the realization's rational row into the target ring.

    @[reducible, inline]
    abbrev Cslib.Circuits.Rational.Formula.colR {n : ℕ} {R : Type u_1} [Ring R] (c : ℚ →+* R) (f : Formula n) :

    Map the realization's rational column into the target ring.

    @[reducible, inline]

    Represent a scalar as a one-by-one matrix.

    theorem Cslib.Circuits.Rational.Formula.Eval.realization {n : ℕ} {R : Type u_1} [Ring R] (c : ℚ →+* R) (X : Fin n → R) {f : Formula n} {v : R} (hv : Eval c X f v) :
    ∃ (M : Matrix f.Index f.Index R), realized c X f * M = 1 ∧ M * realized c X f = 1 ∧ rowR c f * M * colR c f = scalar v

    Exact affine realization of every defined formula: the evaluated pencil is invertible, and the row, its inverse and the column multiply to the value.

    The inverse nodes of a formula, as a list retaining occurrences rather than distinct subexpressions.

    @[simp]

    A variable leaf has no inverse nodes.

    @[simp]

    A constant leaf has no inverse nodes.

    @[simp]

    The inverse nodes of add f g are those of f followed by those of g.

    @[simp]

    The inverse nodes of mul f g are those of f followed by those of g.

    @[simp]

    The inverse nodes of inv f are inv f followed by those of f.

    The inverse nodes together with the augmented root inv f, which is a certificate pencil and not a new counted gate.

    theorem Cslib.Circuits.Rational.Formula.Eval.augmented_isUnit_iff {n : ℕ} {R : Type u_1} [Ring R] (c : ℚ →+* R) (X : Fin n → R) {f : Formula n} {a : R} (ha : Eval c X f a) :

    At a defined point, the augmented pencil is invertible exactly when the value is.

    theorem Cslib.Circuits.Rational.Formula.eval_of_inverseNodes_units {n : ℕ} {R : Type u_1} [Ring R] (c : ℚ →+* R) (X : Fin n → R) (f : Formula n) (hu : ∀ h ∈ f.inverseNodes, IsUnit (realized c X h)) :
    ∃ (a : R), Eval c X f a

    If the realized pencil of every inverse node of f is a unit, then f evaluates to some value at X.

    theorem Cslib.Circuits.Rational.Formula.certificates_iff {n : ℕ} {R : Type u_1} [Ring R] (c : ℚ →+* R) (X : Fin n → R) (f : Formula n) :
    (∀ h ∈ f.certificates, IsUnit (realized c X h)) ↔ ∃ (a : R), Eval c X f a ∧ IsUnit a

    Full original-tree definedness and invertible final value are equivalent to invertibility of all affine-pencil certificates. No rational cancellation is performed.

    Every inverse node of f has at most f.nodeCount nodes.

    A formula with at most s nodes has at most s + 1 certificates, each of dimension at most 2 * s + 1.

    def Cslib.Circuits.Rational.Affine.coeff {n : ℕ} (a : Form n) :
    Fin (n + 1) → ℚ

    The homogeneous coefficient, with index zero reserved for the constant term.

    def Cslib.Circuits.Rational.Affine.homogeneous {n : ℕ} {R : Type u_1} [Ring R] (c : ℚ →+* R) (Z : Fin (n + 1) → R) (a : Form n) :
    R

    Evaluate the homogeneous form on an extra constant coordinate.

    theorem Cslib.Circuits.Rational.Affine.homogeneous_one {n : ℕ} {R : Type u_1} [Ring R] (c : ℚ →+* R) (X : Fin n → R) (a : Form n) :
    homogeneous c (fun (i : Fin (n + 1)) => Fin.cases 1 X i) a = (eval c X) a

    Setting the homogenizing coordinate to 1 recovers ordinary affine evaluation.

    theorem Cslib.Circuits.Rational.Affine.normalized_pencil_unit {n : ℕ} {R : Type u_1} [Ring R] {ι : Type u_2} [Fintype ι] [DecidableEq ι] [Algebra ℚ R] (L : Matrix ι ι (Form n)) (Z : Fin (n + 1) → R) (z : Rˣ) (hz : ↑z = Z 0) (hL : IsUnit (L.map (homogeneous (algebraMap ℚ R) Z))) :
    IsUnit (L.map ⇑(eval (algebraMap ℚ R) fun (i : Fin n) => ↑z⁻¹ * Z i.succ))

    If Z 0 is a unit z and the homogenized pencil is a unit, then the normalized affine pencil at i ↦ z⁻¹ * Z i.succ is a unit.

    theorem Cslib.Circuits.Rational.Affine.eval_reindex {n : ℕ} {K : Type u_2} [Field K] [CharZero K] {ι : Type u_3} {ι' : Type u_4} {κ : Type u_5} [Fintype κ] [DecidableEq κ] (L : Matrix ι ι (Form n)) (X : Fin n → Matrix κ κ K) (e : ι ≃ ι') :
    ((Matrix.reindex e e) L).map ⇑(eval (algebraMap ℚ (Matrix κ κ K)) X) = (Matrix.reindex e e) (L.map ⇑(eval (algebraMap ℚ (Matrix κ κ K)) X))

    Reindexing a pencil's coefficients does not alter its matrix evaluation.

    theorem Cslib.Circuits.Rational.Affine.homogeneous_flat {n : ℕ} {K : Type u_2} [Field K] [CharZero K] {ι : Type u_3} {κ : Type u_4} [Fintype ι] [Fintype κ] [DecidableEq κ] (L : Matrix ι ι (Form n)) (Z : Fin (n + 1) → Matrix κ κ K) :
    (Matrix.compRingEquiv ι κ K) (L.map (homogeneous (algebraMap ℚ (Matrix κ κ K)) Z)) = fun (a b : ι × κ) => ∑ r : Fin (n + 1), (algebraMap ℚ K) (coeff (L a.1 b.1) r) * Z r a.2 b.2

    Homogeneous affine coefficients give exactly the ordinary Kronecker pencil.