Documentation

CompPoly.Univariate.Raw.Ops

Raw Univariate Polynomial Operations #

Operations and evaluation lemmas for raw computable univariate polynomials.

def CompPoly.CPolynomial.Raw.eval₂ {R : Type u_1} {S : Type u_3} [Semiring R] [Semiring S] (f : R →+* S) (x : S) (p : Raw R) :
S

Evaluates a CPolynomial.Raw at x : S using a ring homomorphism f : R →+* S.

Computes f(a₀) + f(a₁) * x + f(a₂) * x² + ... where aᵢ are the coefficients.

Instances For
    @[inline, specialize #[]]
    def CompPoly.CPolynomial.Raw.eval₂Horner {R : Type u_1} {S : Type u_3} [Semiring R] [Semiring S] (f : R →+* S) (x : S) (p : Raw R) :
    S

    Evaluates a CPolynomial.Raw at x : S using Horner's method.

    Computes f(aₙ) + x * (f(aₙ₋₁) + x * (... + x * f(a₀))) via a right fold.

    Instances For
      @[inline, specialize #[]]
      def CompPoly.CPolynomial.Raw.eval {R : Type u_1} [Semiring R] (x : R) (p : Raw R) :
      R

      Evaluates a CPolynomial.Raw at a given value

      Instances For
        @[inline, specialize #[]]
        def CompPoly.CPolynomial.Raw.addRaw {R : Type u_1} [Zero R] [Add R] (p q : Raw R) :
        Raw R

        Raw addition: pointwise sum of coefficient arrays (padded to equal length).

        The result may have trailing zeros and should be trimmed for canonical form.

        Instances For
          @[inline, specialize #[]]
          def CompPoly.CPolynomial.Raw.add {R : Type u_1} [Zero R] [Add R] [BEq R] (p q : Raw R) :
          Raw R

          Addition of two CPolynomial.Raws, with result trimmed.

          Instances For
            @[inline, specialize #[]]
            def CompPoly.CPolynomial.Raw.smul {R : Type u_1} [Mul R] (r : R) (p : Raw R) :
            Raw R

            Scalar multiplication: multiplies each coefficient by r.

            Instances For
              @[inline, specialize #[]]
              def CompPoly.CPolynomial.Raw.smulRight {R : Type u_1} [Mul R] (r : R) (p : Raw R) :
              Raw R

              Right scalar multiplication: multiplies each coefficient by r on the right.

              Corresponds to p.toPoly * Polynomial.C r, in contrast to smul which corresponds to Polynomial.C r * p.toPoly. The distinction matters in non-commutative semirings.

              Instances For
                @[inline, specialize #[]]
                def CompPoly.CPolynomial.Raw.nsmulRaw {R : Type u_1} [Semiring R] (n : ) (p : Raw R) :
                Raw R

                Raw scalar multiplication by a natural number (may have trailing zeros).

                Instances For
                  @[inline, specialize #[]]
                  def CompPoly.CPolynomial.Raw.nsmul {R : Type u_1} [Semiring R] [BEq R] (n : ) (p : Raw R) :
                  Raw R

                  Scalar multiplication of CPolynomial.Raw by a natural number, with result trimmed.

                  Instances For
                    @[inline, specialize #[]]
                    def CompPoly.CPolynomial.Raw.mulPowX {R : Type u_1} [Zero R] (i : ) (p : Raw R) :
                    Raw R

                    Multiplication by X^i: shifts coefficients right by i positions (prepends i zeros).

                    Instances For
                      @[inline, specialize #[]]
                      def CompPoly.CPolynomial.Raw.mulX {R : Type u_1} [Zero R] (p : Raw R) :
                      Raw R

                      Multiplication of a CPolynomial.Raw by X, reduces to mulPowX 1.

                      Instances For
                        @[inline, specialize #[]]
                        def CompPoly.CPolynomial.Raw.mulRaw {R : Type u_1} [Semiring R] (p q : Raw R) :
                        Raw R

                        Multiplication accumulator using the naive O(n²) algorithm: Σᵢ (aᵢ * q) * X^i.

                        The partial sums are combined with the untrimmed addRaw, so the result may carry trailing zeros and should be trimmed for canonical form. Deferring the trim to the end (see mul) avoids an O(size) scan after every partial sum.

                        Instances For
                          @[inline, specialize #[]]
                          def CompPoly.CPolynomial.Raw.mul {R : Type u_1} [Semiring R] [BEq R] (p q : Raw R) :
                          Raw R

                          Multiplication using the naive O(n²) algorithm: Σᵢ (aᵢ * q) * X^i.

                          Trims only once, at the end of the convolution fold, rather than after every partial sum (mulRaw does the untrimmed accumulation).

                          Instances For
                            @[inline, specialize #[]]
                            def CompPoly.CPolynomial.Raw.pow {R : Type u_1} [Semiring R] [BEq R] (p : Raw R) (n : ) :
                            Raw R

                            Exponentiation of a CPolynomial.Raw by a natural number n via repeated multiplication. This is the specification; powBySq is the efficient O(log n) implementation.

                            Instances For
                              @[irreducible, inline, specialize #[]]

                              Repeated-squaring core that accumulates with the untrimmed mulRaw, deferring the canonicalization trim to the outer powBySq wrapper. The output may carry trailing zeros and is not in canonical form.

                              For $ n > 0 $, computes $ p ^ n $ by recursing on $ n / 2 $:

                              • If $ n $ is even: $ (p ^ {n/2})^2 $
                              • If $ n $ is odd: $ p \cdot (p ^ {n/2})^2 $
                              Instances For
                                @[inline, specialize #[]]
                                def CompPoly.CPolynomial.Raw.powBySq {R : Type u_1} [Semiring R] [BEq R] (p : Raw R) (n : ) :
                                Raw R

                                Exponentiation via repeated squaring: $ O(\log n) $ multiplications instead of $ O(n) $. Delegates to powBySqUntrimmed and trims only once at the end, rather than after every squaring step.

                                Instances For
                                  @[implicit_reducible]
                                  @[implicit_reducible]
                                  instance CompPoly.CPolynomial.Raw.instOne {R : Type u_1} [One R] :
                                  One (Raw R)
                                  @[implicit_reducible]
                                  instance CompPoly.CPolynomial.Raw.instAddOfZeroOfBEq {R : Type u_1} [Zero R] [Add R] [BEq R] :
                                  Add (Raw R)
                                  @[implicit_reducible]
                                  @[implicit_reducible]
                                  @[implicit_reducible]
                                  @[implicit_reducible]
                                  @[implicit_reducible]
                                  @[inline, specialize #[]]
                                  def CompPoly.CPolynomial.Raw.truncate {R : Type u_1} [Zero R] (k : ) (p : Raw R) :
                                  Raw R

                                  Keep only the stored coefficients with index < k.

                                  Instances For
                                    @[inline, specialize #[]]
                                    def CompPoly.CPolynomial.Raw.takeLow {R : Type u_1} [Zero R] (k : ) (p : Raw R) :
                                    Raw R

                                    Return exactly the first k coefficients, padding missing coefficients with zero.

                                    Instances For
                                      @[inline, specialize #[]]
                                      def CompPoly.CPolynomial.Raw.reverse {R : Type u_1} [Zero R] (n : ) (p : Raw R) :
                                      Raw R

                                      Reverse the first n coefficients, padding missing coefficients with zero.

                                      Instances For
                                        @[inline, specialize #[]]
                                        def CompPoly.CPolynomial.Raw.mulLowConvolution {R : Type u_1} [Semiring R] (k : ) (p q : Raw R) :
                                        Raw R

                                        Low product computed by the coefficient convolution formula.

                                        Instances For

                                          Backend for computing the low k coefficients of a raw product.

                                          • mulLow : Raw RRaw RRaw R

                                            Return the low k coefficients of p * q.

                                          • size_le (k : ) (p q : Raw R) : Array.size (self.mulLow k p q) k

                                            The backend does not return coefficients at degree >= k.

                                          • coeff_of_lt (k : ) (p q : Raw R) (i : ) : i < k(self.mulLow k p q).coeff i = (p * q).coeff i

                                            Low coefficients agree with ordinary raw multiplication.

                                          Instances For

                                            Upper bound on degree: size - 1 if non-empty, if empty.

                                            Instances For

                                              Convert degreeBound to a natural number by sending to 0.

                                              Instances For
                                                def CompPoly.CPolynomial.Raw.monic {R : Type u_1} [Zero R] [One R] [BEq R] (p : Raw R) :

                                                Check if a CPolynomial.Raw is monic, i.e. its leading coefficient is 1.

                                                Instances For
                                                  def CompPoly.CPolynomial.Raw.divX {R : Type u_1} (p : Raw R) :
                                                  Raw R

                                                  Pseudo-division by X: removes the constant term and shifts remaining coefficients left.

                                                  Instances For
                                                    @[inline, specialize #[]]
                                                    def CompPoly.CPolynomial.Raw.neg {R : Type u_1} [Neg R] (p : Raw R) :
                                                    Raw R

                                                    Negation of a CPolynomial.Raw.

                                                    Instances For
                                                      @[inline, specialize #[]]
                                                      def CompPoly.CPolynomial.Raw.sub {R : Type u_1} [Zero R] [Add R] [Neg R] [BEq R] (p q : Raw R) :
                                                      Raw R

                                                      Subtraction of two CPolynomial.Raws.

                                                      Instances For
                                                        @[implicit_reducible]
                                                        instance CompPoly.CPolynomial.Raw.instNeg {R : Type u_1} [Neg R] :
                                                        Neg (Raw R)
                                                        @[implicit_reducible]
                                                        @[implicit_reducible]