Represents one coefficient-monomial term in a Polynomial.

remarks

A term stores an

`Expression`

coefficient, a mutable variable-to-power record, and a sorted copy of the supplied variable names. The coefficient and a power object supplied to the constructor are retained by reference; Term.copy creates independent copies of both. Multidegree, total power, expression, and value text are computed lazily and cached. Arithmetic methods return new terms and refresh their derived degree fields. Direct mutation of Term.coeff, Term.powers, or the setter overload of Term.deg does not invalidate every cached field, so callers should prefer a copied/reconstructed term when cached values may already have been read.

Members

canAddOrSubtract(t: Term): booleanMethod

Tests whether two terms have the same unit-coefficient monomial.

Parameters

NameTypeDescription
tTermTerm to compare.

Returns

boolean — Whether their rendered variable-and-power components match.

coeff: ExpressionProperty

Mutable symbolic coefficient.

Term(coeff: string | Expression, powers: string | PowersObject, variables: string[]): TermConstructor

Creates a term from a coefficient and monomial powers.

Parameters

NameTypeDescription
coeffstring | ExpressionExpression coefficient or parser text. Existing expressions are retained.
powersstring | PowersObjectPower record or comma-separated degrees aligned with `variables`. An object power record is retained by reference.
variablesstring[]Variable order to interpret string powers. The term stores a sorted copy.

Returns

Term

copy(): TermMethod

Creates an independently mutable copy of this term.

Returns

Term — A term with copied coefficient, powers, and variable array. Lazy caches are rebuilt on demand.

dataType: "TRM"Property

Runtime tag used by Nerdamer's term type guard.

deg(v: string): numberMethod

Returns the degree of one variable.

Parameters

NameTypeDescription
vstringVariable whose power is read.

Returns

number — The stored power, or zero when the variable is absent.

diff(variable: string, n: number): TermMethod

Differentiates this term with respect to one variable.

Parameters

NameTypeDescription
variablestringDifferentiation variable.
nnumberNon-negative derivative order.

Returns

Term — A new differentiated term, or a zero term when `n` exceeds the power.

difference(term: Term): number[]Method

Subtracts another term's multidegree from this term's multidegree.

Parameters

NameTypeDescription
termTermTerm whose degree tuple is subtracted.

Returns

number[] — A new component-wise difference array in this term's variable order.

div(t: Term): TermMethod

Divides this term by the provided term

Parameters

NameTypeDescription
tTermDivisor term.

Returns

Term — A new quotient term; negative powers are permitted by this low-level operation.

divides(t: Term): booleanMethod

Checks if one term can divide another.

Parameters

NameTypeDescription
tTermCandidate dividend term.

Returns

boolean — Whether every power in this term is no greater than the corresponding power in `t`.

eq(t: Term): booleanMethod

Checks for equality with another Term

Parameters

NameTypeDescription
tTermTerm to compare.

Returns

boolean — Whether coefficient and monomial quotient equal one.

eqNumber(n: string | number): booleanMethod

Tests whether this is a constant term equal to a number.

Parameters

NameTypeDescription
nstring | numberNumeric value to compare with the coefficient.

Returns

boolean

expression: ExpressionProperty

Lazily cached expression representation.

getExpression(): ExpressionMethod

Returns a lazily constructed expression for this term.

Returns

Expression — The cached internal expression reference.

getMultidegArray(): number[]Method

Returns this term's multidegree in its stored variable order.

Returns

number[] — The cached internal degree array.

getTotalPower(): numberMethod

Returns the sum of powers in this term.

Returns

number — The cached total degree.

getValueString(useVariables?: string[]): stringMethod

Formats the monomial with a unit coefficient.

Parameters

NameTypeDescription
useVariablesstring[]Optional variable order used for this rendering.

Returns

string — Parser text such as `x^2*y`, or `1` for a constant term.

isConstant(): booleanMethod

Tests whether every stored variable power is zero.

Returns

boolean — Whether the term is constant, independent of its coefficient value.

isTerm(obj: unknown): objMethod

Checks if the given object is a Term

Parameters

NameTypeDescription
objunknownValue to test.

Returns

obj — Whether `obj` carries Nerdamer's term discriminator.

isZero(): booleanMethod

Tests whether the coefficient is zero.

Returns

boolean — Whether the term's symbolic coefficient is zero.

LCM(t: Term, withCoeff: boolean): TermMethod

Calculates the LCM of two terms with numeric coefficients TODO: Extend to non-numeric coefficients

Parameters

NameTypeDescription
tTermOther monomial term.
withCoeffbooleanInclude the exact numeric coefficient LCM instead of using one.

Returns

Term — A new term containing maximum powers for the union of variables.

length: numberProperty

Number of variables whose power is positive.

max(): stringMethod

Returns the variable name with the greatest stored power.

Returns

string

min(): stringMethod

Returns the variable name with the least stored power.

Returns

string

multideg(variables: string[]): number[]Method

Calculates the multidegree array

Parameters

NameTypeDescription
variablesstring[]Variable order for the result.

Returns

number[] — A new power array, using zero for missing variables.

multidegArray: number[]Property

Lazily cached multidegree in variables order.

powers: PowersObjectProperty

Mutable powers keyed by variable name.

text(useVariables?: string[]): stringMethod

Gets the text representation of the monomial

Parameters

NameTypeDescription
useVariablesstring[]Optional variable rendering order.

Returns

string — Canonical parser text for the coefficient and monomial.

times(x: Term): TermMethod

Multiplies this term with the given term

Parameters

NameTypeDescription
xTermMultiplier term.

Returns

Term — A new term with multiplied coefficients and added powers.

toString(): stringMethod

Returns the same parser text as Term.text.

Returns

string

totalPower: numberProperty

Lazily cached sum of all stored powers.

valueString: stringProperty

Lazily cached unit-coefficient monomial text.

variables: string[]Property

Sorted variable names used for multidegree and rendering order.