MultiPoly
Sparse multivariate polynomial over integer coefficients.
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
clone(): MultiPolyMethodCreates an independent copy of the term map.
Returns
constant(c: bigint): MultiPolyMethodCreates a constant polynomial, omitting storage for zero.
Parameters
| Name | Type | Description |
|---|---|---|
c | bigint | Integer constant. |
Returns
constantTerm(): bigintMethodReturns the constant coefficient, or zero when absent.
Returns
bigint
MultiPoly(terms?: Map<string, bigint>): MultiPolyConstructorCreates a polynomial by copying the supplied term map.
Parameters
| Name | Type | Description |
|---|---|---|
terms | Map<string, bigint> | Initial canonical-monomial-key to integer-coefficient map. |
Returns
degree(varIndex: number): numberMethodReturns the greatest exponent of one variable.
Parameters
| Name | Type | Description |
|---|---|---|
varIndex | number | Variable index to inspect. |
Returns
number — `-1` for zero; otherwise a non-negative degree.
getCoeff(exponents: number[]): bigintMethodReturns a monomial coefficient from dense exponents.
Parameters
| Name | Type | Description |
|---|---|---|
exponents | number[] | Exponents indexed by variable number. |
Returns
bigint — The stored coefficient, or zero when absent.
isConstant(): booleanMethodTests whether this polynomial is zero or contains only a constant term.
Returns
boolean
isZero(): booleanMethodTests whether the term map is empty.
Returns
boolean
leadingCoeff(varIndex: number): MultiPolyMethodExtracts 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
| Name | Type | Description |
|---|---|---|
varIndex | number | Variable whose greatest power is selected and removed. |
Returns
MultiPoly — A new polynomial in the remaining variables.
monomial(coeff: bigint, exponents: number[]): MultiPolyMethodCreates the monomial
`coeff * x₀^e₀ * x₁^e₁ * ...`.
Parameters
| Name | Type | Description |
|---|---|---|
coeff | bigint | Integer coefficient. |
exponents | number[] | Exponents indexed by variable number. |
Returns
one(): MultiPolyMethodCreates the constant polynomial one.
Returns
setCoeff(exponents: number[], coeff: bigint): voidMethodSets or removes a monomial coefficient in place.
Parameters
| Name | Type | Description |
|---|---|---|
exponents | number[] | Dense exponents indexed by variable number. |
coeff | bigint | Integer coefficient; zero removes the monomial. |
Returns
void
terms: Map<string, bigint>PropertyLive term map keyed by canonical monomial strings.
text(varNames: string[]): stringMethodFormats this polynomial using caller-supplied variable names.
Parameters
| Name | Type | Description |
|---|---|---|
varNames | string[] | Names aligned with variable indices; missing names fall back to `xN`. |
Returns
string — Deterministic text ordered by descending total degree and canonical key.
totalDegree(): numberMethodReturns the maximum sum of exponents among all monomials.
Returns
number — `-1` for the zero polynomial.
trim(): voidMethodRemoves zero-coefficient entries from the live term map in place.
Returns
void
variable(varIndex: number): MultiPolyMethodCreates the single-variable polynomial
`xᵢ`.
Parameters
| Name | Type | Description |
|---|---|---|
varIndex | number | Variable index to raise to the first power. |
Returns
variables(): Set<number>MethodCollects variable indices with at least one nonzero exponent.
Returns
Set<number> — A new set of variable indices.
zero(): MultiPolyMethodCreates the zero polynomial with empty term storage.
