SparsePolynomial
Sparse polynomial with bigint coefficients and bigint exponents. The variable count is part of the polynomial rather than inferred from its support. Exponent vectors therefore have one exact entry for every variable, including zero polynomials and constants. The internal map key is an encoding detail and is never exposed or parsed by polynomial algorithms.
Members
add(other: SparsePolynomial): SparsePolynomialMethodAdds another polynomial in the same ring. Like monomials are combined exactly and zero coefficients are removed from the returned polynomial.
Parameters
| Name | Type | Description |
|---|---|---|
other | SparsePolynomial | — |
Returns
coefficient(exponents: readonly bigint[]): bigintMethodReturns the coefficient of one monomial.
Parameters
| Name | Type | Description |
|---|---|---|
exponents | readonly bigint[] | Exact exponent vector for the requested monomial. |
Returns
bigint
coefficientIn(variableIndex: number, exponent: bigint): SparsePolynomialMethodReturns the coefficient polynomial at one exact power of a selected variable. The selected variable remains in the ring with exponent zero so recursive algorithms can preserve the original coordinate layout.
Parameters
| Name | Type | Description |
|---|---|---|
variableIndex | number | — |
exponent | bigint | — |
Returns
compareMonomials(a: readonly bigint[], b: readonly bigint[], order: MonomialOrder): numberMethodCompares exponent vectors using the three global monomial orders required by the polynomial algorithms.
Parameters
| Name | Type | Description |
|---|---|---|
a | readonly bigint[] | — |
b | readonly bigint[] | — |
order | MonomialOrder | — |
Returns
number
constant(variableCount: number, coefficient: bigint): SparsePolynomialMethodCreates a constant polynomial in a ring with variableCount variables.
Parameters
| Name | Type | Description |
|---|---|---|
variableCount | number | — |
coefficient | bigint | — |
Returns
constantTerm(): bigintMethodReturns the constant coefficient, or zero when the constant monomial is absent.
Returns
bigint
SparsePolynomial(variableCount: number, terms: Iterable<Readonly<{ … }>>): SparsePolynomialConstructorCreates a sparse polynomial in a ring with a fixed number of variables. Duplicate monomials are combined and zero coefficients are removed.
Parameters
| Name | Type | Description |
|---|---|---|
variableCount | number | Number of variables in the polynomial ring. |
terms | Iterable<Readonly<{ … }>> | Terms with exponent vectors of exactly variableCount entries. |
Returns
content(): bigintMethodReturns the positive greatest common divisor of all coefficients. The zero polynomial has coefficient content zero.
Returns
bigint
degree(variableIndex: number): bigint | nullMethodReturns the degree in one variable. The zero polynomial has no degree and returns null.
Parameters
| Name | Type | Description |
|---|---|---|
variableIndex | number | — |
Returns
bigint | null
derivative(variableIndex: number): SparsePolynomialMethodDifferentiates with respect to one ring variable. Coefficients and exponents stay in bigint arithmetic, including exponents above JavaScript's safe-integer range.
Parameters
| Name | Type | Description |
|---|---|---|
variableIndex | number | — |
Returns
divideByMonomial(divisor: SparsePolynomialTerm): SparsePolynomial | nullMethodDivides every term by one monomial when the quotient stays in the integer polynomial ring. Returns null when any coefficient or exponent is not exactly divisible.
Parameters
| Name | Type | Description |
|---|---|---|
divisor | SparsePolynomialTerm | — |
Returns
SparsePolynomial | null
divideByScalarExact(divisor: bigint): SparsePolynomialMethodDivides all coefficients by an integer scalar.
RangeError When the scalar is zero or does not divide every coefficient.
Parameters
| Name | Type | Description |
|---|---|---|
divisor | bigint | — |
Returns
divideExact(divisor: SparsePolynomial, order: MonomialOrder): SparsePolynomial | nullMethodDivides by one polynomial using exact integer coefficient arithmetic. Returns null as soon as the current leading term is not exactly divisible by the divisor leading term. A successful result therefore has zero remainder in the selected monomial order.
Parameters
| Name | Type | Description |
|---|---|---|
divisor | SparsePolynomial | — |
order | MonomialOrder | — |
Returns
SparsePolynomial | null
equals(other: SparsePolynomial): booleanMethodReturns whether both polynomials have the same ring and exact nonzero terms.
Parameters
| Name | Type | Description |
|---|---|---|
other | SparsePolynomial | — |
Returns
boolean
evaluateVariable(variableIndex: number, value: bigint): SparsePolynomialMethodSubstitutes one variable with an exact integer while retaining the same ring. Terms that become like terms after substitution are combined in the result.
Parameters
| Name | Type | Description |
|---|---|---|
variableIndex | number | — |
value | bigint | — |
Returns
evaluateVariables(variableIndices: readonly number[], values: readonly bigint[]): SparsePolynomialMethodSubstitutes several variables with exact integers in one sparse traversal. The selected coordinates remain in the polynomial ring with exponent zero.
Parameters
| Name | Type | Description |
|---|---|---|
variableIndices | readonly number[] | — |
values | readonly bigint[] | — |
Returns
isConstant(): booleanMethodReturns whether the polynomial is zero or contains only a constant term.
Returns
boolean
isZero(): booleanMethodReturns whether the polynomial has no nonzero terms.
Returns
boolean
leadingCoefficientIn(variableIndex: number): SparsePolynomial | nullMethodReturns the coefficient polynomial of the highest power of one variable. The selected coordinate remains present with exponent zero.
Parameters
| Name | Type | Description |
|---|---|---|
variableIndex | number | — |
Returns
SparsePolynomial | null
leadingTerm(order: MonomialOrder): Readonly<{ … }> | nullMethodReturns the leading term under the requested monomial order. Variable priority follows exponent-vector index order.
Parameters
| Name | Type | Description |
|---|---|---|
order | MonomialOrder | — |
Returns
Readonly<{ … }> | null
mapCoefficients(mapper: (coefficient: bigint): bigint): SparsePolynomialMethodApplies an exact bigint transformation to every stored coefficient while preserving the existing monomial keys and exponent vectors.
Parameters
| Name | Type | Description |
|---|---|---|
mapper | (coefficient: bigint): bigint | — |
Returns
maxAbsoluteCoefficient(): bigintMethodReturns the largest absolute coefficient, or zero for the zero polynomial.
Returns
bigint
monomial(variableCount: number, coefficient: bigint, exponents: readonly bigint[]): SparsePolynomialMethodCreates a one-term polynomial.
Parameters
| Name | Type | Description |
|---|---|---|
variableCount | number | — |
coefficient | bigint | — |
exponents | readonly bigint[] | — |
Returns
monomialScaleSubtract(leftScalar: bigint, leftMonomialExponents: readonly bigint[], other: SparsePolynomial, rightScalar: bigint, rightMonomialExponents: readonly bigint[]): SparsePolynomialMethodComputes the difference of two monomial-scaled polynomials in one sparse traversal. This avoids constructing the monomial factors and multiplication results used by fraction-free S-polynomials.
Parameters
| Name | Type | Description |
|---|---|---|
leftScalar | bigint | — |
leftMonomialExponents | readonly bigint[] | — |
other | SparsePolynomial | — |
rightScalar | bigint | — |
rightMonomialExponents | readonly bigint[] | — |
Returns
multiply(other: SparsePolynomial): SparsePolynomialMethodMultiplies by another polynomial in the same ring. Monomial exponents are added as bigints. The constructor combines products that land on the same monomial and removes coefficients that cancel to zero.
Parameters
| Name | Type | Description |
|---|---|---|
other | SparsePolynomial | — |
Returns
negate(): SparsePolynomialMethodReturns the additive inverse of this polynomial.
Returns
normalizeLeadingSign(order: MonomialOrder): SparsePolynomialMethodMakes the leading coefficient positive without changing coefficient content.
Parameters
| Name | Type | Description |
|---|---|---|
order | MonomialOrder | — |
Returns
pow(exponent: bigint): SparsePolynomialMethodRaises the polynomial to a non-negative exact integer power.
Parameters
| Name | Type | Description |
|---|---|---|
exponent | bigint | — |
Returns
primitivePart(): SparsePolynomialMethodDivides by positive coefficient content while preserving the polynomial sign.
Returns
scale(scalar: bigint): SparsePolynomialMethodMultiplies every coefficient by an exact integer scalar.
Parameters
| Name | Type | Description |
|---|---|---|
scalar | bigint | — |
Returns
scaleSubtractMonomial(leftScalar: bigint, other: SparsePolynomial, rightScalar: bigint, monomialExponents: readonly bigint[]): SparsePolynomialMethodComputes a scaled subtraction where the right polynomial is also multiplied by one monomial. This avoids constructing the two scaled intermediate polynomials used by fraction-free reduction.
Parameters
| Name | Type | Description |
|---|---|---|
leftScalar | bigint | — |
other | SparsePolynomial | — |
rightScalar | bigint | — |
monomialExponents | readonly bigint[] | — |
Returns
subtract(other: SparsePolynomial): SparsePolynomialMethodSubtracts another polynomial in the same ring.
Parameters
| Name | Type | Description |
|---|---|---|
other | SparsePolynomial | — |
Returns
termCount(): numberAPINumber of stored nonzero terms.
Returns
number
terms(): readonly Readonly<{ … }>[]MethodReturns a copy of the stored terms. The exponent arrays themselves are frozen so callers cannot alter polynomial storage.
Returns
readonly Readonly<{ … }>[]
totalDegree(): bigint | nullMethodReturns the largest total degree among the stored monomials. The zero polynomial has no total degree and returns null.
Returns
bigint | null
variable(variableCount: number, variableIndex: number): SparsePolynomialMethodCreates the variable at variableIndex with coefficient one.
Parameters
| Name | Type | Description |
|---|---|---|
variableCount | number | — |
variableIndex | number | — |
Returns
variableCount: numberPropertyNo description is available yet.
variables(): readonly number[]MethodReturns the variable indices that occur with a positive exponent.
Returns
readonly number[]
zero(variableCount: number): SparsePolynomialMethodCreates the zero polynomial in a ring with variableCount variables.
Parameters
| Name | Type | Description |
|---|---|---|
variableCount | number | — |
