Documentation

CompPoly.Multivariate.Operations

Computable multivariate polynomials (extended operations) #

Operations on CMvPolynomial that depend on ring instances from MvPolyEquiv.lean, such as monomial orders, leading terms, restriction, variable renaming, and substitution.

The core type and basic operations (CMvPolynomial, C, X, coeff, eval, etc.) are in CMvPolynomial.lean. The CommSemiring and CommRing instances are in MvPolyEquiv.lean.

Main definitions #

Leading-term operations #

Monomial ordering typeclass for n variables.

Provides a way to compare monomials for determining leading terms.

Instances

    Baseline degree of a monomial.

    Currently this is the ordinary total degree and is independent of MonomialOrder.compare.

    Instances For

      Leading monomial of a polynomial according to a monomial order.

      Returns none for the zero polynomial.

      Instances For

        Leading term of a polynomial according to a monomial order.

        Returns 0 for the zero polynomial, and otherwise returns the monomial with leading monomial and leading coefficient.

        Instances For
          def CPoly.CMvPolynomial.leadingCoeff {n : } {R : Type u_2} [Zero R] [MonomialOrder n] (p : CMvPolynomial n R) :
          R

          Leading coefficient of a polynomial according to a monomial order.

          Returns 0 for the zero polynomial.

          Instances For

            Packaged form of leadingCoeff: it is the coefficient at the optional leading monomial, defaulting to 0 when no leading monomial exists.

            Evaluation and substitution #

            def CPoly.CMvPolynomial.aeval {n : } {R : Type u_2} {σ : Type u_3} [CommSemiring R] [CommSemiring σ] [Algebra R σ] (f : Fin nσ) (p : CMvPolynomial n R) :
            σ

            Algebra evaluation: evaluates polynomial in an algebra.

            Given an algebra σ over R and a function f : Fin n → σ, evaluates the polynomial.

            Instances For
              @[simp]
              theorem CPoly.CMvPolynomial.aeval_eq_eval₂ {n : } {R : Type u_2} {σ : Type u_3} [CommSemiring R] [CommSemiring σ] [Algebra R σ] (f : Fin nσ) (p : CMvPolynomial n R) :
              aeval f p = eval₂ (algebraMap R σ) f p
              @[simp]
              theorem CPoly.CMvPolynomial.aeval_C {n : } {R : Type u_2} {σ : Type u_3} [CommSemiring R] [BEq R] [LawfulBEq R] [CommSemiring σ] [Algebra R σ] (f : Fin nσ) (c : R) :
              aeval f (C c) = (algebraMap R σ) c
              @[simp]
              theorem CPoly.CMvPolynomial.aeval_add {n : } {R : Type u_2} {σ : Type u_3} [CommSemiring R] [BEq R] [LawfulBEq R] [CommSemiring σ] [Algebra R σ] (f : Fin nσ) (p q : CMvPolynomial n R) :
              aeval f (p + q) = aeval f p + aeval f q
              @[simp]
              theorem CPoly.CMvPolynomial.aeval_mul {n : } {R : Type u_2} {σ : Type u_3} [CommSemiring R] [BEq R] [LawfulBEq R] [CommSemiring σ] [Algebra R σ] (f : Fin nσ) (p q : CMvPolynomial n R) :
              aeval f (p * q) = aeval f p * aeval f q
              @[simp]
              theorem CPoly.CMvPolynomial.aeval_zero {n : } {R : Type u_2} {σ : Type u_3} [CommSemiring R] [BEq R] [LawfulBEq R] [CommSemiring σ] [Algebra R σ] (f : Fin nσ) :
              aeval f 0 = 0
              @[simp]
              theorem CPoly.CMvPolynomial.aeval_one {n : } {R : Type u_2} {σ : Type u_3} [CommSemiring R] [BEq R] [LawfulBEq R] [CommSemiring σ] [Algebra R σ] (f : Fin nσ) :
              aeval f 1 = 1
              @[simp]
              theorem CPoly.CMvPolynomial.aeval_pow {n : } {R : Type u_2} {σ : Type u_3} [CommSemiring R] [BEq R] [LawfulBEq R] [CommSemiring σ] [Algebra R σ] (f : Fin nσ) (p : CMvPolynomial n R) (k : ) :
              aeval f (p ^ k) = aeval f p ^ k
              @[simp]
              theorem CPoly.CMvPolynomial.aeval_neg {n : } {R : Type u_2} {σ : Type u_3} [CommRing R] [BEq R] [LawfulBEq R] [CommRing σ] [Algebra R σ] (f : Fin nσ) (p : CMvPolynomial n R) :
              aeval f (-p) = -aeval f p
              @[simp]
              theorem CPoly.CMvPolynomial.aeval_sub {n : } {R : Type u_2} {σ : Type u_3} [CommRing R] [BEq R] [LawfulBEq R] [CommRing σ] [Algebra R σ] (f : Fin nσ) (p q : CMvPolynomial n R) :
              aeval f (p - q) = aeval f p - aeval f q
              def CPoly.CMvPolynomial.bind₁ {n m : } {R : Type u_2} [CommSemiring R] [BEq R] [LawfulBEq R] (f : Fin nCMvPolynomial m R) (p : CMvPolynomial n R) :

              Substitution: substitutes polynomials for variables.

              Given f : Fin n → CMvPolynomial m R, substitutes f i for variable X i.

              Instances For
                theorem CPoly.CMvPolynomial.bind₁_eq_aeval {n m : } {R : Type u_2} [CommSemiring R] [BEq R] [LawfulBEq R] (f : Fin nCMvPolynomial m R) (p : CMvPolynomial n R) :
                bind₁ f p = aeval f p

                The computable substitution bind₁ agrees with algebraic evaluation.

                @[simp]
                theorem CPoly.CMvPolynomial.bind₁_C {n m : } {R : Type u_2} [CommSemiring R] [BEq R] [LawfulBEq R] (f : Fin nCMvPolynomial m R) (c : R) :
                bind₁ f (C c) = C c
                @[simp]
                theorem CPoly.CMvPolynomial.bind₁_add {n m : } {R : Type u_2} [CommSemiring R] [BEq R] [LawfulBEq R] (f : Fin nCMvPolynomial m R) (p q : CMvPolynomial n R) :
                bind₁ f (p + q) = bind₁ f p + bind₁ f q
                @[simp]
                theorem CPoly.CMvPolynomial.bind₁_mul {n m : } {R : Type u_2} [CommSemiring R] [BEq R] [LawfulBEq R] (f : Fin nCMvPolynomial m R) (p q : CMvPolynomial n R) :
                bind₁ f (p * q) = bind₁ f p * bind₁ f q

                Core operations #

                def CPoly.CMvPolynomial.rename {n m : } {R : Type u_2} [Zero R] [Add R] [BEq R] [LawfulBEq R] (f : Fin nFin m) (p : CMvPolynomial n R) :

                Rename variables using a function.

                Given f : Fin n → Fin m, renames variable X i to X (f i).

                Instances For
                  def CPoly.CMvPolynomial.sumToIter {n : } {R : Type u_2} [Zero R] [Add R] [BEq R] [LawfulBEq R] (p : CMvPolynomial n R) :

                  Iterative reconstruction of a polynomial by folding over terms.

                  Instances For

                    Bridge and transport lemmas (technical) #

                    theorem CPoly.CMvPolynomial.X_eq_monomial {k : } {R : Type u_2} [CommSemiring R] [BEq R] [LawfulBEq R] (i : Fin k) :
                    X i = monomial (Vector.ofFn fun (j : Fin k) => if j = i then 1 else 0) 1

                    C and eval₂ as ring homomorphisms #

                    @[simp]
                    theorem CPoly.CMvPolynomial.eval₂_C {n : } {R : Type u_2} {S : Type u_3} [CommSemiring R] [BEq R] [LawfulBEq R] [CommSemiring S] (f : R →+* S) (vs : Fin nS) (c : R) :
                    eval₂ f vs (C c) = f c
                    @[simp]
                    theorem CPoly.CMvPolynomial.eval₂_X {n : } {R : Type u_2} {S : Type u_3} [CommSemiring R] [BEq R] [LawfulBEq R] [CommSemiring S] (f : R →+* S) (vs : Fin nS) (i : Fin n) :
                    eval₂ f vs (X i) = vs i
                    @[simp]
                    theorem CPoly.CMvPolynomial.eval₂Hom_C {n : } {R : Type u_2} {S : Type u_3} [CommSemiring R] [BEq R] [LawfulBEq R] [CommSemiring S] (f : R →+* S) (vs : Fin nS) (c : R) :
                    (eval₂Hom f vs) (C c) = f c
                    @[simp]
                    theorem CPoly.CMvPolynomial.eval₂Hom_X {n : } {R : Type u_2} {S : Type u_3} [CommSemiring R] [BEq R] [LawfulBEq R] [CommSemiring S] (f : R →+* S) (vs : Fin nS) (i : Fin n) :
                    (eval₂Hom f vs) (X i) = vs i
                    theorem CPoly.CMvPolynomial.ringHom_ext {n : } {R : Type u_2} [CommSemiring R] [BEq R] [LawfulBEq R] {T : Type u_3} [Semiring T] {f g : CMvPolynomial n R →+* T} (hC : ∀ (c : R), f (C c) = g (C c)) (hX : ∀ (i : Fin n), f (X i) = g (X i)) :
                    f = g

                    Two ring homomorphisms out of CMvPolynomial n R are equal once they agree on the constants and on every variable.

                    @[simp]
                    theorem CPoly.CMvPolynomial.aeval_X {n : } {R : Type u_2} {σ : Type u_3} [CommSemiring R] [BEq R] [LawfulBEq R] [CommSemiring σ] [Algebra R σ] (f : Fin nσ) (i : Fin n) :
                    aeval f (X i) = f i
                    @[simp]
                    theorem CPoly.CMvPolynomial.bind₁_X {n m : } {R : Type u_2} [CommSemiring R] [BEq R] [LawfulBEq R] (f : Fin nCMvPolynomial m R) (i : Fin n) :
                    bind₁ f (X i) = f i
                    @[simp]
                    theorem CPoly.CMvPolynomial.bind₁_id {n : } {R : Type u_2} [CommSemiring R] [BEq R] [LawfulBEq R] (p : CMvPolynomial n R) :
                    bind₁ (fun (i : Fin n) => X i) p = p
                    theorem CPoly.CMvPolynomial.list_foldl_add_comm {β : Type u_2} {K : Type u_3} {V : Type u_4} [AddCommMonoid β] (g : KVβ) (l : List (K × V)) (init : β) :
                    List.foldl (fun (acc : β) (pair : K × V) => acc + g pair.1 pair.2) init l = List.foldl (fun (acc : β) (pair : K × V) => g pair.1 pair.2 + acc) init l
                    theorem CPoly.CMvPolynomial.foldl_add_comm {β : Type u_2} [AddCommMonoid β] {k : } {R' : Type u_3} (g : CMvMonomial kR'β) (t : Std.ExtTreeMap (CMvMonomial k) R' compare) :
                    Std.ExtTreeMap.foldl (fun (acc : β) (m : CMvMonomial k) (c : R') => acc + g m c) 0 t = Std.ExtTreeMap.foldl (fun (acc : β) (m : CMvMonomial k) (c : R') => g m c + acc) 0 t

                    API lemmas for sumToIter #

                    @[simp]

                    The computable substitution bind₁ agrees with Mathlib substitution after transporting through fromCMvPolynomial.

                    Equivalence between npow and npowBySq #

                    Lawful.npow (defined in Multivariate/Lawful.lean) is the naive O(k) specification; Lawful.npowBySq is the O(log k) repeated-squaring implementation. We prove pointwise equality here so that the NatPow instance can be safely routed through the fast version.

                    The proofs need mul_assoc / mul_one / mul_comm, which are only available once the CommSemiring (CMvPolynomial n R) instance has been built — that is why these lemmas live in Operations.lean rather than in Lawful.lean.

                    theorem CPoly.Lawful.npow_add {n : } {R : Type u_2} [CommSemiring R] [BEq R] [LawfulBEq R] (p : Lawful n R) (a b : ) :
                    npow (a + b) p = npow a p * npow b p

                    Additive law for the naive npow: $p^{a+b} = p^a \cdot p^b$.

                    theorem CPoly.Lawful.npowBySq_eq_npow {n : } {R : Type u_2} [CommSemiring R] [BEq R] [LawfulBEq R] (p : Lawful n R) (k : ) :
                    p.npowBySq k = npow k p

                    The fast repeated-squaring npowBySq agrees pointwise with the naive npow. This is the equivalence that lets the NatPow (Lawful n R) instance be routed through npowBySq without changing observable behavior.