Polynomials

Dense multivariate polynomials whose coefficients are stored in a fixed order defined by a MultiindexSet (Grlex-sorted).

MORFE.Polynomials.DensePolynomialType
DensePolynomial{T, NVAR, N, A}

Cache-friendly dense polynomial with a single contiguous coefficient array.

Type parameters

parammeaning
TScalar element type (Float64, ComplexF64, …). Must be a concrete bits type for best performance.
NVARNumber of input variables.
Nndims(coefficients). Number of axes: N = 1 for scalar, N = 2 for vector-valued, etc.
AConcrete array type (Array{T,N} normally; can be an Mmap array).

Fields

  • coefficients::A — shape (d1, …, d_{N-1}, L). The last axis indexes the L monomials in multiindex_set. Leading axes describe the coefficient shape (none for scalar, (K,) for a K-vector, etc.).
  • multiindex_set::MultiindexSet{NVAR} — Grlex-ordered monomial basis.
  • max_exponents::SVector{NVAR,Int} — per-variable max exponent (used to pre-allocate the power table in evaluate).
source
MORFE.Polynomials.DensePolynomialMethod
DensePolynomial(dict::Dict{Vector{Int}, SVector{K,T}}) where {K,T}

Vector-valued polynomial from an exponent → SVector dictionary. Coefficients are laid out column-by-column (parallel fill).

source
MORFE.Polynomials.DensePolynomialMethod
DensePolynomial(coeff_vec::Vector{SVector{K,T}}, mset)

Vector-valued polynomial from the old Vector{SVector} layout. Converts to a contiguous (K × L) matrix, filling columns in parallel.

source
Base.zeroMethod
zero(DensePolynomial{T}, mset)              # scalar
zero(DensePolynomial{T}, coeff_shape, mset) # tensor-valued
source
MORFE.Polynomials._monomial_vector!Method
_monomial_vector!(m, poly, vals)

Fill the pre-allocated vector m (length L) with the value of each monomial in poly.multiindex_set evaluated at vals. This is the central loop; called once per evaluate.

source
MORFE.Polynomials._precompute_powersMethod
_precompute_powers(T, vals, max_exps) -> NTuple of Vectors

For each variable j, store vals[j]^e for e = 0 … max_exps[j]. Avoids repeated ^ calls inside the inner loop.

source
MORFE.Polynomials.coeff_shapeMethod
coeff_shape(p) -> NTuple

Leading axes of the coefficient array. () for scalar, (K,) for K-vector, (m,n) for a matrix-valued polynomial, etc.

source
MORFE.Polynomials.coefficientMethod
coefficient(p, exp) -> scalar or view

Return the coefficient of the monomial with exponent exp. For scalar polynomials this is a T; for vector-valued it is a Vector{T} view into the backing array — no allocation.

source
MORFE.Polynomials.each_termMethod
each_term(poly) -> generator of (exponent, coefficient)

Yields (SVector{NVAR,Int}, coeff) for every nonzero monomial.

  • Scalar (N=1): coeff is a T.
  • Vector (N=2): coeff is a SubArray{T,1} view (no allocation).
source
MORFE.Polynomials.evaluateMethod
evaluate(poly::DensePolynomial{T,NVAR,1}, vals) -> T

Scalar polynomial evaluation: sum(c_i * m_i) without conjugation.

source
MORFE.Polynomials.evaluateMethod
evaluate(poly::DensePolynomial{T,NVAR,2}, vals, component::Int) -> T

Evaluate a single component of a vector-valued polynomial without allocating a full output vector.

source
MORFE.Polynomials.evaluateMethod
evaluate(poly::DensePolynomial{T,NVAR,2}, vals) -> Vector{T}

Vector-valued polynomial evaluation via BLAS gemv:

result = coefficients  (K × L)  *  m  (L,)  →  (K,)

A single BLAS call, no per-term allocation.

source
MORFE.Polynomials.evaluateMethod
evaluate(poly::DensePolynomial{T,NVAR,N}, vals) -> Array

General tensor-valued case: reshape to (prod(leading_dims), L), gemv, reshape back.

source
MORFE.Polynomials.extract_componentMethod
extract_component(poly::DensePolynomial{T,NVAR,2}, idx) -> DensePolynomial{T,NVAR,1}

Return the idx-th component as a scalar polynomial. The coefficient vector is a copy of row idx of the matrix.

source
MORFE.Polynomials.linear_matrix_of_polynomialMethod
linear_matrix_of_polynomial(poly::DensePolynomial{T,NVAR,2}) -> Matrix{T}

Return the (K × NVAR) matrix A such that the linear part equals A * x. Reads directly from the coefficient matrix — no intermediate arrays.

source
MORFE.Polynomials.mmap_polynomialMethod
mmap_polynomial(path, coeff_size::NTuple, T::Type, mset; write=false)

Return a DensePolynomial whose coefficient array is backed by a memory-mapped file at path. coeff_size is the leading axes of the coefficient array (empty () for scalar, (K,) for K-vector, …).

The OS page-cache handles RAM pressure automatically: only accessed pages are loaded, so polynomials larger than available RAM work transparently.

Example

# 5-vector polynomial with 1 000 000 monomials, stored on disk
p = mmap_polynomial("coeffs.bin", (5,), Float64, mset; write=true)
source
MORFE.Polynomials.similar_polyMethod
similar_poly(dict::Dict{SVector{NVAR,Int}, Vector{T}}) where {NVAR, T<:Number}

Vector-valued polynomial from a dictionary mapping exponents to Vector{T} coefficients. All vectors must have the same length K.

source