Documentation

Complexity.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.

Instances For

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

    Instances For

      The affine coordinate form for one variable.

      Instances For
        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.

        Instances For
          @[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
          @[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
          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.

          Instances For
            @[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

            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.

              Instances For

                The right column of the formula's linear realization.

                Instances For

                  The affine matrix pencil built recursively from a rational formula.

                  Instances For
                    @[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.

                    Instances For
                      @[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.

                      Instances For
                        @[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.

                        Instances For
                          @[reducible, inline]

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

                          Instances For
                            theorem Cslib.Circuits.Rational.Formula.realized_add {n : ℕ} {R : Type u_1} [Ring R] (c : ℚ →+* R) (X : Fin n → R) (a : Fin (ratSignature.Arity RatOp.add) → Formula n) :
                            realized c X (Formula.gate RatOp.add a) = Matrix.fromBlocks (realized c X (a 0)) 0 0 (realized c X (a 1))
                            theorem Cslib.Circuits.Rational.Formula.realized_mul {n : ℕ} {R : Type u_1} [Ring R] (c : ℚ →+* R) (X : Fin n → R) (m : Fin (ratSignature.Arity RatOp.mul) → Formula n) :
                            realized c X (Formula.gate RatOp.mul m) = Matrix.fromBlocks (realized c X (m 0)) (-colR c (m 0) * rowR c (m 1)) 0 (realized c X (m 1))
                            theorem Cslib.Circuits.Rational.Formula.realized_inv {n : ℕ} {R : Type u_1} [Ring R] (c : ℚ →+* R) (X : Fin n → R) (b : Fin (ratSignature.Arity RatOp.inv) → Formula n) :
                            realized c X (Formula.gate RatOp.inv b) = Matrix.fromBlocks (realized c X (b 0)) (colR c (b 0)) (rowR c (b 0)) 0
                            theorem Cslib.Circuits.Rational.Formula.realized_input {n : ℕ} {R : Type u_1} [Ring R] (c : ℚ →+* R) (X : Fin n → R) (i : Fin n) :
                            theorem Cslib.Circuits.Rational.Formula.realized_const {n : ℕ} {R : Type u_1} [Ring R] (c : ℚ →+* R) (X : Fin n → R) (q : ℚ) (args : Fin (ratSignature.Arity (RatOp.const q)) → Formula n) :
                            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.

                            Instances For

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

                              Instances For
                                theorem Cslib.Circuits.Rational.Formula.Eval.pencil_isUnit {n : ℕ} {R : Type u_1} [Ring R] (c : ℚ →+* R) (X : Fin n → R) {f : Formula n} {a : R} (ha : Eval c X f a) :
                                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.inverseNodes_units {n : ℕ} {R : Type u_1} [Ring R] (c : ℚ →+* R) (X : Fin n → R) {f : Formula n} {a : R} (ha : Eval c X f a) (h : Formula n) :
                                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
                                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.

                                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.

                                Instances For
                                  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.

                                  Instances For
                                    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
                                    theorem Cslib.Circuits.Rational.Affine.normalized {n : ℕ} {R : Type u_1} [Ring R] [Algebra ℚ R] (Z : Fin (n + 1) → R) (u : R) (hu : Z 0 * u = 1) (a : Form n) :
                                    homogeneous (algebraMap ℚ R) Z a = Z 0 * (eval (algebraMap ℚ R) fun (i : Fin n) => u * Z i.succ) a
                                    theorem Cslib.Circuits.Rational.Affine.normalized_pencil {n : ℕ} {R : Type u_1} [Ring R] {ι : Type u_2} [Fintype ι] [DecidableEq ι] [Algebra ℚ R] (L : Matrix ι ι (Form n)) (Z : Fin (n + 1) → R) (u : R) (hu : Z 0 * u = 1) :
                                    L.map (homogeneous (algebraMap ℚ R) Z) = (Matrix.scalar ι) (Z 0) * L.map ⇑(eval (algebraMap ℚ R) fun (i : Fin n) => u * Z i.succ)
                                    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))
                                    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.