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 intentionally 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 deliberate 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 if a caller intentionally wants to transform each side and accepts responsibility for the changed equation semantics.
UnsupportedOperationError Always; absolute value is not a supported equation operation.
Returns
add(x: NerdamerInput): EquationMethodLegacy alias for Equation.plus.
Parameters
| Name | Type | Description |
|---|---|---|
x | NerdamerInput | Value to add to both sides. |
Returns
Equation — A new equation; the receiver is not modified.
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 of the equation by the given value.
The receiver is not modified. Division is applied independently to each side. Dividing by an expression that can be zero may change the admissible solution set; this method does not attach or track nonzero-domain restrictions for the divisor.
Parameters
| Name | Type | Description |
|---|---|---|
x | ExpressionInput | Value by which both sides are divided. |
Returns
Equation — A new equation containing the divided sides.
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.
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: NerdamerInput): EquationMethodSubtracts the same value from both sides.
Parameters
| Name | Type | Description |
|---|---|---|
x | NerdamerInput | Value to subtract from the left- and right-hand sides. |
Returns
Equation — A new equation; the receiver is not modified.
multiply(x: NerdamerInput): EquationMethodLegacy alias for Equation.times.
Like Equation.times, this operation mutates the equation in place.
Parameters
| Name | Type | Description |
|---|---|---|
x | NerdamerInput | Value by which both sides are multiplied. |
Returns
Equation — This equation after mutation.
plus(x: NerdamerInput): EquationMethodAdds the same value to both sides.
Parameters
| Name | Type | Description |
|---|---|---|
x | NerdamerInput | Value to add to the left- and right-hand sides. |
Returns
Equation — A new equation; the receiver 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: NerdamerInput): EquationMethodLegacy alias for Equation.minus.
Parameters
| Name | Type | Description |
|---|---|---|
x | NerdamerInput | Value to subtract from both sides. |
Returns
Equation — A new equation; the receiver is not modified.
text(): stringMethodReturns the canonical text form
`LHS=RHS`.
Returns
string — The two side representations joined by `=`.
times(x: NerdamerInput): EquationMethodMultiplies both sides in place by the same value.
Unlike Equation.plus, Equation.minus, and Equation.div, this method mutates
`LHS`and
`RHS`on the current equation and returns
`this`. Multiplication by an expression that can be zero may introduce solutions; this method does not track a nonzero-domain condition for the multiplier.
Parameters
| Name | Type | Description |
|---|---|---|
x | NerdamerInput | Value by which both sides are multiplied. |
Returns
Equation — This equation after replacing both sides with their products.
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 receiver is not modified. The result has the form
`LHS - RHS = 0`and is the form 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.
