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.

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

    Equations
    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

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

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

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

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

              Equations
              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).

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

                  Equations
                  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).

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

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

                        Equations
                        • One or more equations did not get rendered due to their size.
                        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).

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

                            Equations
                            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 $
                              Equations
                              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.

                                Equations
                                Instances For
                                  @[instance_reducible]
                                  Equations
                                  @[instance_reducible]
                                  instance CompPoly.CPolynomial.Raw.instOne {R : Type u_1} [One R] :
                                  One (Raw R)
                                  Equations
                                  @[instance_reducible]
                                  Equations
                                  @[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.

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

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

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

                                        Equations
                                        Instances For

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

                                          • mulLow : ℕ → Raw R → Raw R → Raw 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.

                                            Equations
                                            Instances For

                                              Convert degreeBound to a natural number by sending ⊥ to 0.

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

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

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

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

                                                      Equations
                                                      Instances For
                                                        @[instance_reducible]
                                                        Equations