Sparse multivariate polynomial over integer coefficients.

remarks

Monomials are stored in a mutable map from canonical exponent keys to

`bigint`

coefficients. Variable indices, rather than names, define the polynomial ring; every polynomial combined by an algorithm must use the same index-to-name mapping. Exponents are expected to be non-negative integers, but construction helpers do not validate that invariant. The constructor copies the supplied map, so MultiPoly.clone has independent term storage. The public MultiPoly.terms property, on the other hand, exposes the live map. Direct edits must use canonical keys and remove zero coefficients; MultiPoly.setCoeff is the safer choice for ordinary updates. This is the exact representation used by the advanced Groebner layer. It does not represent rational coefficients directly; expression-facing adapters clear denominators before conversion.

Members

constant(c: bigint): MultiPolyMethod

Creates a constant polynomial, omitting storage for zero.

Parameters

NameTypeDescription
cbigintInteger constant.

Returns

MultiPoly

constantTerm(): bigintMethod

Returns the constant coefficient, or zero when absent.

Returns

bigint

MultiPoly(terms?: Map<string, bigint>): MultiPolyConstructor

Creates a polynomial by copying the supplied term map.

Parameters

NameTypeDescription
termsMap<string, bigint>Initial canonical-monomial-key to integer-coefficient map.

Returns

MultiPoly

degree(varIndex: number): numberMethod

Returns the greatest exponent of one variable.

Parameters

NameTypeDescription
varIndexnumberVariable index to inspect.

Returns

number — `-1` for zero; otherwise a non-negative degree.

getCoeff(exponents: number[]): bigintMethod

Returns a monomial coefficient from dense exponents.

Parameters

NameTypeDescription
exponentsnumber[]Exponents indexed by variable number.

Returns

bigint — The stored coefficient, or zero when absent.

isConstant(): booleanMethod

Tests whether this polynomial is zero or contains only a constant term.

Returns

boolean

isZero(): booleanMethod

Tests whether the term map is empty.

Returns

boolean

leadingCoeff(varIndex: number): MultiPolyMethod

Extracts the coefficient of the highest power of one variable. The selected variable is removed from those leading terms, so the coefficient is itself returned as a new polynomial in the remaining variables.

Parameters

NameTypeDescription
varIndexnumberVariable whose greatest power is selected and removed.

Returns

MultiPoly — A new polynomial in the remaining variables.

monomial(coeff: bigint, exponents: number[]): MultiPolyMethod

Creates the monomial

`coeff * x₀^e₀ * x₁^e₁ * ...`

.

Parameters

NameTypeDescription
coeffbigintInteger coefficient.
exponentsnumber[]Exponents indexed by variable number.

Returns

MultiPoly

setCoeff(exponents: number[], coeff: bigint): voidMethod

Sets or removes a monomial coefficient in place.

Parameters

NameTypeDescription
exponentsnumber[]Dense exponents indexed by variable number.
coeffbigintInteger coefficient; zero removes the monomial.

Returns

void

terms: Map<string, bigint>Property

Live term map keyed by canonical monomial strings.

text(varNames: string[]): stringMethod

Formats this polynomial using caller-supplied variable names.

Parameters

NameTypeDescription
varNamesstring[]Names aligned with variable indices; missing names fall back to `xN`.

Returns

string — Deterministic text ordered by descending total degree and canonical key.

totalDegree(): numberMethod

Returns the maximum sum of exponents among all monomials.

Returns

number — `-1` for the zero polynomial.

trim(): voidMethod

Removes zero-coefficient entries from the live term map in place.

Returns

void

variable(varIndex: number): MultiPolyMethod

Creates the single-variable polynomial

`xᵢ`

.

Parameters

NameTypeDescription
varIndexnumberVariable index to raise to the first power.

Returns

MultiPoly

variables(): Set<number>Method

Collects variable indices with at least one nonzero exponent.

Returns

Set<number> — A new set of variable indices.

zero(): MultiPolyMethod

Creates the zero polynomial with empty term storage.

Returns

MultiPoly