Documentation

CompPoly.Bivariate.Basic

Computable Bivariate Polynomials #

This file defines CBivariate R, the computable representation of bivariate polynomials with coefficients in R. The type is CPolynomial (CPolynomial R), i.e. polynomials in Y with coefficients that are polynomials in X, matching Mathlib's R[X][Y] (i.e. Polynomial (Polynomial R)).

The design is intended to be compatible with:

def CompPoly.CBivariate (R : Type u_1) [Zero R] :
Type u_1

Computable bivariate polynomials: F[X][Y] as CPolynomial (CPolynomial R).

Each p : CBivariate R is a polynomial in Y whose coefficients are univariate polynomials in X. The outer structure is indexed by powers of Y, the inner by powers of X.

Instances For
    theorem CompPoly.CBivariate.ext {R : Type u_1} [Zero R] {p q : CBivariate R} (h : p = q) :
    p = q

    Extensionality: two bivariate polynomials are equal if their underlying values are.

    theorem CompPoly.CBivariate.ext_iff {R : Type u_1} [Zero R] {p q : CBivariate R} :
    p = q p = q
    @[implicit_reducible]

    Coerce to the underlying univariate polynomial (in Y) with polynomial coefficients.

    @[implicit_reducible]

    The zero bivariate polynomial is canonical.

    @[implicit_reducible]
    instance CompPoly.CBivariate.instBEq {R : Type u_1} [Zero R] [BEq R] :
    @[implicit_reducible]
    @[implicit_reducible]

    Additive structure on CBivariate R

    @[implicit_reducible]

    Ring structure on CBivariate R (for ring equiv with Mathlib in ToPoly).

    @[implicit_reducible]
    @[implicit_reducible]
    @[implicit_reducible]
    def CompPoly.CBivariate.CC {R : Type u_1} [Zero R] [BEq R] [LawfulBEq R] (r : R) :

    Constant as a bivariate polynomial. Mathlib: Polynomial.Bivariate.CC.

    Instances For

      The variable X (inner variable). As bivariate: polynomial in Y with single coeff X at Y^0.

      Instances For

        The variable Y (outer variable). Monomial Y^1 with coefficient 1.

        Instances For
          def CompPoly.CBivariate.monomialXY {R : Type u_1} [Semiring R] [BEq R] [LawfulBEq R] [Nontrivial R] [DecidableEq R] (n m : ) (c : R) :

          Monomial c * X^n * Y^m. ArkLib: Polynomial.Bivariate.monomialXY.

          Instances For
            def CompPoly.CBivariate.coeff {R : Type u_1} [Zero R] (f : CBivariate R) (i j : ) :
            R

            Coefficient of X^i Y^j in the bivariate polynomial. Here i is the X-exponent (inner) and j is the Y-exponent (outer). ArkLib: Polynomial.Bivariate.coeff f i j.

            Instances For

              The Y-support: indices j such that the coefficient of Y^j is nonzero.

              Instances For

                The X-support: indices i such that the coefficient of X^i is nonzero (i.e. some monomial X^i Y^j has nonzero coefficient).

                Instances For

                  The Y-degree (degree when viewed as a polynomial in Y). ArkLib: Polynomial.Bivariate.natDegreeY.

                  Instances For
                    def CompPoly.CBivariate.natDegreeX {R : Type u_1} [Zero R] [BEq R] (f : CBivariate R) :

                    The X-degree: maximum over all Y-coefficients of their degree in X. ArkLib: Polynomial.Bivariate.natDegreeX.

                    Instances For

                      Total degree: max over monomials of (deg_X + deg_Y). ArkLib: Polynomial.Bivariate.totalDegree.

                      Instances For
                        def CompPoly.CBivariate.natWeightedDegree {R : Type u_1} [Zero R] [BEq R] (f : CBivariate R) (u v : ) :

                        The (u, v)-weighted degree: max over monomials of u * deg_X + v * deg_Y.

                        Instances For
                          def CompPoly.CBivariate.evalX {R : Type u_1} [Semiring R] [BEq R] [LawfulBEq R] [DecidableEq R] (a : R) (f : CBivariate R) :

                          Evaluate in the first variable (X) at a, yielding a univariate polynomial in Y. ArkLib: Polynomial.Bivariate.evalX.

                          Instances For
                            def CompPoly.CBivariate.evalY {R : Type u_1} [Semiring R] [BEq R] [LawfulBEq R] [Nontrivial R] (a : R) (f : CBivariate R) :

                            Evaluate in the second variable (Y) at a, yielding a univariate polynomial in X. ArkLib: Polynomial.Bivariate.evalY.

                            Folds the Y-coefficients of f with a raw Horner pattern (smulRight a then addRaw), trimming once at the end. This avoids paying one CPolynomial.mul and one CPolynomial.add trim per Y-coefficient.

                            Instances For

                              Evaluate in the second variable (Y) at a using Horner's method, yielding a univariate polynomial in X.

                              Instances For
                                def CompPoly.CBivariate.evalEval {R : Type u_1} [Semiring R] [BEq R] [LawfulBEq R] [Nontrivial R] (x y : R) (f : CBivariate R) :
                                R

                                Full evaluation at (x, y): p(x, y). Inner variable X at x, outer variable Y at y. Equivalently (evalY y f).eval x. Mathlib: Polynomial.evalEval.

                                See CBivariate.eval_y_horner_eq_eval_y in CompPoly/Bivariate/ToPoly.lean for agreement between evalY and evalYHorner.

                                Instances For
                                  def CompPoly.CBivariate.evalEvalHornerYThenX {R : Type u_1} [Semiring R] [BEq R] [LawfulBEq R] [Nontrivial R] (x y : R) (p : CBivariate R) :
                                  R

                                  Full evaluation at (x, y) using Horner in Y, then Horner in X on the intermediate univariate polynomial.

                                  Instances For
                                    def CompPoly.CBivariate.evalEvalHornerXThenY {R : Type u_1} [Semiring R] (x y : R) (p : CBivariate R) :
                                    R

                                    Full evaluation at (x, y) by evaluating each X-coefficient polynomial at x, then Horner-evaluating the resulting scalar polynomial in Y.

                                    Instances For

                                      Swap the roles of X and Y. ArkLib/Mathlib: Polynomial.Bivariate.swap. TODO a more efficient implementation

                                      Instances For

                                        Leading coefficient when viewed as a polynomial in Y. ArkLib: Polynomial.Bivariate.leadingCoeffY.

                                        Instances For

                                          Leading coefficient when viewed as a polynomial in X. The coefficient of X^(degreeX f): a polynomial in Y.

                                          Instances For
                                            @[simp]
                                            theorem CompPoly.CBivariate.coeff_eq_coeff_coeff {R : Type u_1} [Zero R] (f : CBivariate R) (i j : ) :

                                            CBivariate.coeff as two composed CPolynomial.coeff.

                                            theorem CompPoly.CBivariate.coeff_add {R : Type u_1} [Semiring R] [BEq R] [LawfulBEq R] [Nontrivial R] (p q : CBivariate R) (i j : ) :
                                            (p + q).coeff i j = p.coeff i j + q.coeff i j

                                            Bivariate coefficients are additive.

                                            theorem CompPoly.CBivariate.coeff_finset_sum {R : Type u_1} [Semiring R] [BEq R] [LawfulBEq R] [Nontrivial R] {ι : Type u_2} [DecidableEq ι] (s : Finset ι) (f : ιCBivariate R) (i j : ) :
                                            (s.sum f).coeff i j = ts, (f t).coeff i j

                                            Bivariate coefficients distribute over finite sums.

                                            theorem CompPoly.CBivariate.coeff_monomialXY {R : Type u_1} [Semiring R] [BEq R] [LawfulBEq R] [Nontrivial R] [DecidableEq R] (a b : ) (c : R) (i j : ) :
                                            (monomialXY a b c).coeff i j = if i = a j = b then c else 0

                                            Coefficient of a bivariate monomial c * X^a * Y^b.

                                            theorem CompPoly.CBivariate.coeff_monomialY {R : Type u_1} [Semiring R] [BEq R] [LawfulBEq R] [Nontrivial R] [DecidableEq R] (m : ) (c : CPolynomial R) (i j : ) :

                                            Coefficient of Y^m * c(X) as a bivariate polynomial.

                                            theorem CompPoly.CBivariate.eq_iff_coeff {R : Type u_1} [Zero R] [BEq R] [LawfulBEq R] {p q : CBivariate R} :
                                            p = q ∀ (i j : ), p.coeff i j = q.coeff i j

                                            Two bivariate polynomials are equal iff all their coefficients agree.

                                            The total degree is the (1, 1)-weighted degree.

                                            The X-degree is the (1, 0)-weighted degree.

                                            The Y-degree is the (0, 1)-weighted degree.

                                            theorem CompPoly.CBivariate.natWeightedDegree_monomialXY {R : Type u_1} [BEq R] [LawfulBEq R] [Nontrivial R] [Semiring R] [DecidableEq R] {n m : } {c : R} (hc : c 0) (u v : ) :
                                            (monomialXY n m c).natWeightedDegree u v = u * n + v * m

                                            The weighted degree of a nonzero monomial c * X^n * Y^m is u * n + v * m where u is the weight of X and v the weight of Y.

                                            The weighted degree of the zero polynomial is zero.

                                            theorem CompPoly.CBivariate.natWeightedDegree_le_iff {R : Type u_1} [BEq R] [Semiring R] (f : CBivariate R) (u v d : ) :
                                            f.natWeightedDegree u v d jf.supportY, u * ((↑f).coeff j).natDegree + v * j d

                                            The weighted degree is at most d iff every Y-support index satisfies the weighted bound.

                                            theorem CompPoly.CBivariate.natWeightedDegree_le_iff_coeff {R : Type u_1} [BEq R] [LawfulBEq R] [Semiring R] (f : CBivariate R) (u v d : ) :
                                            f.natWeightedDegree u v d ∀ (i j : ), f.coeff i j 0u * i + v * j d

                                            The weighted degree is at most d iff every monomial index satisfies the weighted bound.

                                            theorem CompPoly.CBivariate.natWeightedDegree_CC {R : Type u_1} [BEq R] [LawfulBEq R] [Semiring R] {r : R} (u v : ) :

                                            The natWeightedDegree of a constant bivariate polynomial CBivariate.CC is zero.

                                            The weighted degree of a sum is at most the max of the weighted degrees.