Represents one coefficient-monomial term in a Polynomial.
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): booleanMethodTests whether two terms have the same unit-coefficient monomial.
Parameters
| Name | Type | Description |
|---|---|---|
t | Term | Term to compare. |
Returns
boolean — Whether their rendered variable-and-power components match.
coeff: ExpressionPropertyMutable symbolic coefficient.
Term(coeff: string | Expression, powers: string | PowersObject, variables: string[]): TermConstructorCreates a term from a coefficient and monomial powers.
Parameters
| Name | Type | Description |
|---|---|---|
coeff | string | Expression | Expression coefficient or parser text. Existing expressions are retained. |
powers | string | PowersObject | Power record or comma-separated degrees aligned with `variables`. An object power record is retained by reference. |
variables | string[] | Variable order to interpret string powers. The term stores a sorted copy. |
Returns
copy(): TermMethodCreates 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"PropertyRuntime tag used by Nerdamer's term type guard.
deg(v: string): numberMethodReturns the degree of one variable.
Parameters
| Name | Type | Description |
|---|---|---|
v | string | Variable whose power is read. |
Returns
number — The stored power, or zero when the variable is absent.
diff(variable: string, n: number): TermMethodDifferentiates this term with respect to one variable.
Parameters
| Name | Type | Description |
|---|---|---|
variable | string | Differentiation variable. |
n | number | Non-negative derivative order. |
Returns
Term — A new differentiated term, or a zero term when `n` exceeds the power.
difference(term: Term): number[]MethodSubtracts another term's multidegree from this term's multidegree.
Parameters
| Name | Type | Description |
|---|---|---|
term | Term | Term whose degree tuple is subtracted. |
Returns
number[] — A new component-wise difference array in this term's variable order.
Divides this term by the provided term
Parameters
| Name | Type | Description |
|---|---|---|
t | Term | Divisor term. |
Returns
Term — A new quotient term; negative powers are permitted by this low-level operation.
divides(t: Term): booleanMethodChecks if one term can divide another.
Parameters
| Name | Type | Description |
|---|---|---|
t | Term | Candidate dividend term. |
Returns
boolean — Whether every power in this term is no greater than the corresponding power in `t`.
eq(t: Term): booleanMethodChecks for equality with another Term
Parameters
| Name | Type | Description |
|---|---|---|
t | Term | Term to compare. |
Returns
boolean — Whether coefficient and monomial quotient equal one.
eqNumber(n: string | number): booleanMethodTests whether this is a constant term equal to a number.
Parameters
| Name | Type | Description |
|---|---|---|
n | string | number | Numeric value to compare with the coefficient. |
Returns
boolean
expression: ExpressionPropertyLazily cached expression representation.
getExpression(): ExpressionMethodReturns a lazily constructed expression for this term.
Returns
Expression — The cached internal expression reference.
getMultidegArray(): number[]MethodReturns this term's multidegree in its stored variable order.
Returns
number[] — The cached internal degree array.
getTotalPower(): numberMethodReturns the sum of powers in this term.
Returns
number — The cached total degree.
getValueString(useVariables?: string[]): stringMethodFormats the monomial with a unit coefficient.
Parameters
| Name | Type | Description |
|---|---|---|
useVariables | string[] | Optional variable order used for this rendering. |
Returns
string — Parser text such as `x^2*y`, or `1` for a constant term.
isConstant(): booleanMethodTests whether every stored variable power is zero.
Returns
boolean — Whether the term is constant, independent of its coefficient value.
isTerm(obj: unknown): objMethodChecks if the given object is a Term
Parameters
| Name | Type | Description |
|---|---|---|
obj | unknown | Value to test. |
Returns
obj — Whether `obj` carries Nerdamer's term discriminator.
isZero(): booleanMethodTests whether the coefficient is zero.
Returns
boolean — Whether the term's symbolic coefficient is zero.
Calculates the LCM of two terms with numeric coefficients TODO: Extend to non-numeric coefficients
Parameters
| Name | Type | Description |
|---|---|---|
t | Term | Other monomial term. |
withCoeff | boolean | Include the exact numeric coefficient LCM instead of using one. |
Returns
Term — A new term containing maximum powers for the union of variables.
length: numberPropertyNumber of variables whose power is positive.
max(): stringMethodReturns the variable name with the greatest stored power.
Returns
string
min(): stringMethodReturns the variable name with the least stored power.
Returns
string
multideg(variables: string[]): number[]MethodCalculates the multidegree array
Parameters
| Name | Type | Description |
|---|---|---|
variables | string[] | Variable order for the result. |
Returns
number[] — A new power array, using zero for missing variables.
multidegArray: number[]PropertyLazily cached multidegree in variables order.
powers: PowersObjectPropertyMutable powers keyed by variable name.
text(useVariables?: string[]): stringMethodGets the text representation of the monomial
Parameters
| Name | Type | Description |
|---|---|---|
useVariables | string[] | Optional variable rendering order. |
Returns
string — Canonical parser text for the coefficient and monomial.
Multiplies this term with the given term
Parameters
| Name | Type | Description |
|---|---|---|
x | Term | Multiplier term. |
Returns
Term — A new term with multiplied coefficients and added powers.
toString(): stringMethodReturns the same parser text as Term.text.
Returns
string
totalPower: numberPropertyLazily cached sum of all stored powers.
valueString: stringPropertyLazily cached unit-coefficient monomial text.
variables: string[]PropertySorted variable names used for multidegree and rendering order.
