Equation
Represents a symbolic equality between two expression sides.
An Equation stores its left- and right-hand sides as public Expression
references. The constructor does not copy those expressions, so mutating a supplied
expression later, or mutating Equation.LHS or Equation.RHS directly,
changes the equation. Use Equation.copy when an independent equation is needed.
Arithmetic methods apply an operation to both sides, but that does not by itself prove
that the transformed equation has exactly the same solution set. For example, multiplying
or dividing by an expression whose value may be zero requires additional domain reasoning.
Solver-facing code should account for those mathematical conditions.
Absolute value is not supported as an equation rewrite because applying it
independently to both sides can change the solution set. Equation.abs remains only
as a compatibility member of the general parser-entity surface and always throws. Callers
performing a non-equivalent transformation can use Equation.each explicitly.
Equation comparisons reduce each equation to its residual LHS - RHS and then use the
corresponding Expression comparison. They compare those residual expressions;
they do not establish logical or solution-set equivalence between arbitrary equations.
Examples
const equation = new Equation(Expression.create('x + 1'), Expression.create(3));
equation.text(); // "1+x=3"
equation.toLHS().text(); // "-2+x=0"Members
abs(): EquationMethodRejects absolute value as an equation transformation.
Replacing a = b with |a| = |b| is not generally solution-set preserving. This
method remains on Equation so the general ParserEntity surface can retain
its historical abs() member without reintroducing the unsafe transformation.
Use Equation.each explicitly to transform
each side and accepts responsibility for the changed equation semantics.
core!UnsupportedOperationError Always; absolute value is not a supported equation operation.
Returns
add(x: ExpressionInput): EquationMethodLegacy alias for Equation.plus.
Parameters
| Name | Type | Description |
|---|---|---|
x | ExpressionInput | Value to add to both sides. |
Returns
Equation — A new equation; the current equation is not modified.
buildFunction(argsArray?: string[]): (...args: number[]): numberMethodCompiles this value to a native JavaScript-number function when the parsed result
is an Expression.
Structured parser results expose this method so values returned by nerdamer(...)
have one consistent TypeScript surface, but they cannot be compiled as scalar
functions and throw core!UnexpectedDataType when called.
Parameters
| Name | Type | Description |
|---|---|---|
argsArray | string[] | Optional variable names in positional call order. |
Returns
(...args: number[]): number — A JavaScript-number function compiled from the scalar expression.
Equation(lhs: Expression, rhs: Expression): EquationConstructorCreates an equation from two expression objects.
The supplied expressions are stored by reference rather than copied. This preserves object identity but also means subsequent mutation of either expression is visible through the equation.
Parameters
| Name | Type | Description |
|---|---|---|
lhs | Expression | Expression to store on the left-hand side. |
rhs | Expression | Expression to store on the right-hand side. |
Returns
copy(): EquationMethodCreates an independent copy of this equation and both expression sides.
Returns
Equation — A new equation whose left- and right-hand expressions are deep copies.
dataType: "EQN"PropertyParser entity tag used to identify equation values.
diff(variable?: ExpressionInput, n?: number | Expression): EquationMethodNo description is available yet.
Parameters
| Name | Type | Description |
|---|---|---|
variable | ExpressionInput | — |
n | number | Expression | — |
Returns
div(x: ExpressionInput): EquationMethodDivides both sides by the same nonzero number. A symbolic divisor is rejected because Nerdamer cannot assume that it is nonzero for every solution of the equation.
core!UnsupportedOperationError If x is zero or is not numeric.
Parameters
| Name | Type | Description |
|---|---|---|
x | ExpressionInput | Nonzero numeric value by which both sides are divided. |
Returns
Equation — A new equation; the current equation is not modified.
each(fn: (e: ParserEntity, i?: string | number): ParserEntity): EquationMethodApplies a callback to the two equation sides and rebuilds the equation from its results.
The callback receives the stored left- and right-hand Expression references
directly, with indices 0 and 1 respectively. Returned expressions are stored by
reference in a new equation. The callback can therefore mutate the original equation
if it mutates either argument before returning.
Both callback results must be expressions. Other parser entities are rejected after
the callback has run.
core!UnexpectedDataType Thrown when either callback result is not an Expression.
Parameters
| Name | Type | Description |
|---|---|---|
fn | (e: ParserEntity, i?: string | number): ParserEntity | Transformation applied to the left and right sides. |
Returns
Equation — A new equation containing the callback results.
eq(eq: ParserEntity): booleanMethodCompares this equation with another equation by comparing their residual expressions.
Each equation is copied and rewritten as LHS - RHS = 0, then the two residual
expressions are compared with Expression.eq. Equations with the same
solution set are not necessarily equal by this method; for example, scaling an
equation by a nonzero constant changes its residual expression.
Parameters
| Name | Type | Description |
|---|---|---|
eq | ParserEntity | Parser entity to compare with this equation. |
Returns
boolean — true when eq is an equation and the two residual expressions compare equal.
evaluate(): EquationMethodNumerically re-evaluates both equation sides.
Returns
Equation — A new equation containing evaluated copies of the two sides.
expand(): EquationMethodExpands both sides of a copied equation.
Returns
Equation — A new equation containing the expanded left- and right-hand sides.
factor(): EquationMethodNo description is available yet.
Returns
gt(eq: ParserEntity): booleanMethodOrders this equation against another equation by comparing their residual expressions.
Both equations are rewritten as LHS - RHS = 0, and the resulting expressions are
compared with Expression.gt. This is an ordering of residual expressions,
not a statement that one equation or solution set is logically greater than another.
Parameters
| Name | Type | Description |
|---|---|---|
eq | ParserEntity | Parser entity to compare with this equation. |
Returns
boolean — true when eq is an equation and this residual compares greater.
gte(x: ParserEntity): booleanMethodResidual-expression comparison corresponding to >=.
Parameters
| Name | Type | Description |
|---|---|---|
x | ParserEntity | Parser entity to compare with this equation. |
Returns
boolean — true when Equation.gt or Equation.eq succeeds.
integrate(variable?: ExpressionInput): EquationMethodNo description is available yet.
Parameters
| Name | Type | Description |
|---|---|---|
variable | ExpressionInput | — |
Returns
isEnumerable: booleanPropertyIndicates that equations are not elementwise enumerable parser aggregates.
isEquation(obj: unknown): objMethodTests whether a value carries Nerdamer's equation parser-entity tag.
This is a tag-based type guard rather than an instanceof check. It therefore
recognizes compatible equation objects by their dataType value.
Parameters
| Name | Type | Description |
|---|---|---|
obj | unknown | Value to inspect. |
Returns
obj — true when the value is tagged as an equation.
LHS: ExpressionPropertyMutable left-hand side expression stored by this equation.
lt(eq: ParserEntity): booleanMethodOrders this equation against another equation by comparing their residual expressions.
Both equations are rewritten as LHS - RHS = 0, and the resulting expressions are
compared with Expression.lt. This is an ordering of residual expressions,
not a statement that one equation or solution set is logically less than another.
Parameters
| Name | Type | Description |
|---|---|---|
eq | ParserEntity | Parser entity to compare with this equation. |
Returns
boolean — true when eq is an equation and this residual compares less.
lte(x: ParserEntity): booleanMethodResidual-expression comparison corresponding to <=.
Parameters
| Name | Type | Description |
|---|---|---|
x | ParserEntity | Parser entity to compare with this equation. |
Returns
boolean — true when Equation.lt or Equation.eq succeeds.
minus(x: ExpressionInput): EquationMethodSubtracts the same value from both sides.
Parameters
| Name | Type | Description |
|---|---|---|
x | ExpressionInput | Value to subtract from the left- and right-hand sides. |
Returns
Equation — A new equation; the current equation is not modified.
multiply(x: ExpressionInput): EquationMethodLegacy alias for Equation.times.
Parameters
| Name | Type | Description |
|---|---|---|
x | ExpressionInput | Nonzero numeric value by which both sides are multiplied. |
Returns
Equation — This equation after mutation.
numeric(precision?: ExpressionInput): EquationMethodNo description is available yet.
Parameters
| Name | Type | Description |
|---|---|---|
precision | ExpressionInput | — |
Returns
plus(x: ExpressionInput): EquationMethodAdds the same value to both sides.
Parameters
| Name | Type | Description |
|---|---|---|
x | ExpressionInput | Value to add to the left- and right-hand sides. |
Returns
Equation — A new equation; the current equation is not modified.
precision: numberPropertyOptional parser-entity precision metadata.
Equation itself does not currently use this value when performing equation
operations or formatting its sides.
RHS: ExpressionPropertyMutable right-hand side expression stored by this equation.
simplify(): EquationMethodNo description is available yet.
Returns
solveFor(variable: ExpressionInput): SolutionSetMethodSolves this equation for the requested variable.
The solver works from the equation's residual form, LHS - RHS = 0, and
returns Nerdamer's SolutionSet. The equation itself is not modified.
Parameters
| Name | Type | Description |
|---|---|---|
variable | ExpressionInput | Variable to solve for. |
Returns
SolutionSet — The solver's solution set, including exclusions or root metadata it preserves.
subst(value: ExpressionInput, withValue: ExpressionInput): EquationMethodNo description is available yet.
Parameters
| Name | Type | Description |
|---|---|---|
value | ExpressionInput | — |
withValue | ExpressionInput | — |
Returns
subtract(x: ExpressionInput): EquationMethodLegacy alias for Equation.minus.
Parameters
| Name | Type | Description |
|---|---|---|
x | ExpressionInput | Value to subtract from both sides. |
Returns
Equation — A new equation; the current equation is not modified.
text(): stringMethodReturns the canonical text form LHS=RHS.
Returns
string — The two side representations joined by =.
times(x: ExpressionInput): EquationMethodMultiplies both sides by the same nonzero number. A symbolic multiplier is rejected because it may be zero for some solutions and add solutions that were not present in the original equation.
core!UnsupportedOperationError If x is zero or is not numeric.
Parameters
| Name | Type | Description |
|---|---|---|
x | ExpressionInput | Nonzero numeric value by which both sides are multiplied. |
Returns
Equation — This equation after mutation.
toLHS(): EquationMethodRewrites this equation as an equivalent residual form with zero on the right.
The equation and both sides are copied before RHS is subtracted from LHS, so the
current equation is not modified. The result has the form LHS - RHS = 0 and is used
by solver preparation and the equation comparison methods.
Returns
Equation — A new equation with the residual expression on the left and zero on the right.
toString(): stringMethodReturns the same canonical equation text as Equation.text.
Returns
string — The equation text representation.
