Represents a symbolic equality between two expression sides.

remarks

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(): EquationMethod

Rejects absolute value as an equation transformation.

remarks

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.

throws

core!UnsupportedOperationError Always; absolute value is not a supported equation operation.

Returns

Equation

buildFunction(argsArray?: string[]): (...args: number[]): numberMethod

Compiles 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

NameTypeDescription
argsArraystring[]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): EquationConstructor

Creates an equation from two expression objects.

remarks

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

NameTypeDescription
lhsExpressionExpression to store on the left-hand side.
rhsExpressionExpression to store on the right-hand side.

Returns

Equation

copy(): EquationMethod

Creates 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"Property

Parser entity tag used to identify equation values.

div(x: ExpressionInput): EquationMethod

Divides 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.

throws

core!UnsupportedOperationError If x is zero or is not numeric.

Parameters

NameTypeDescription
xExpressionInputNonzero 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): EquationMethod

Applies a callback to the two equation sides and rebuilds the equation from its results.

remarks

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.

throws

core!UnexpectedDataType Thrown when either callback result is not an Expression.

Parameters

NameTypeDescription
fn(e: ParserEntity, i?: string | number): ParserEntityTransformation applied to the left and right sides.

Returns

Equation — A new equation containing the callback results.

eq(eq: ParserEntity): booleanMethod

Compares this equation with another equation by comparing their residual expressions.

remarks

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

NameTypeDescription
eqParserEntityParser entity to compare with this equation.

Returns

boolean — true when eq is an equation and the two residual expressions compare equal.

evaluate(): EquationMethod

Numerically re-evaluates both equation sides.

Returns

Equation — A new equation containing evaluated copies of the two sides.

expand(): EquationMethod

Expands both sides of a copied equation.

Returns

Equation — A new equation containing the expanded left- and right-hand sides.

gt(eq: ParserEntity): booleanMethod

Orders this equation against another equation by comparing their residual expressions.

remarks

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

NameTypeDescription
eqParserEntityParser entity to compare with this equation.

Returns

boolean — true when eq is an equation and this residual compares greater.

gte(x: ParserEntity): booleanMethod

Residual-expression comparison corresponding to >=.

Parameters

NameTypeDescription
xParserEntityParser entity to compare with this equation.

Returns

boolean — true when Equation.gt or Equation.eq succeeds.

isEnumerable: booleanProperty

Indicates that equations are not elementwise enumerable parser aggregates.

isEquation(obj: unknown): objMethod

Tests whether a value carries Nerdamer's equation parser-entity tag.

remarks

This is a tag-based type guard rather than an instanceof check. It therefore recognizes compatible equation objects by their dataType value.

Parameters

NameTypeDescription
objunknownValue to inspect.

Returns

obj — true when the value is tagged as an equation.

LHS: ExpressionProperty

Mutable left-hand side expression stored by this equation.

lt(eq: ParserEntity): booleanMethod

Orders this equation against another equation by comparing their residual expressions.

remarks

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

NameTypeDescription
eqParserEntityParser entity to compare with this equation.

Returns

boolean — true when eq is an equation and this residual compares less.

lte(x: ParserEntity): booleanMethod

Residual-expression comparison corresponding to <=.

Parameters

NameTypeDescription
xParserEntityParser entity to compare with this equation.

Returns

boolean — true when Equation.lt or Equation.eq succeeds.

minus(x: ExpressionInput): EquationMethod

Subtracts the same value from both sides.

Parameters

NameTypeDescription
xExpressionInputValue to subtract from the left- and right-hand sides.

Returns

Equation — A new equation; the current equation is not modified.

plus(x: ExpressionInput): EquationMethod

Adds the same value to both sides.

Parameters

NameTypeDescription
xExpressionInputValue to add to the left- and right-hand sides.

Returns

Equation — A new equation; the current equation is not modified.

precision: numberProperty

Optional parser-entity precision metadata. Equation itself does not currently use this value when performing equation operations or formatting its sides.

RHS: ExpressionProperty

Mutable right-hand side expression stored by this equation.

solveFor(variable: ExpressionInput): SolutionSetMethod

Solves this equation for the requested variable.

remarks

The solver works from the equation's residual form, LHS - RHS = 0, and returns Nerdamer's SolutionSet. The equation itself is not modified.

Parameters

NameTypeDescription
variableExpressionInputVariable to solve for.

Returns

SolutionSet — The solver's solution set, including exclusions or root metadata it preserves.

text(): stringMethod

Returns the canonical text form LHS=RHS.

Returns

string — The two side representations joined by =.

times(x: ExpressionInput): EquationMethod

Multiplies 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.

throws

core!UnsupportedOperationError If x is zero or is not numeric.

Parameters

NameTypeDescription
xExpressionInputNonzero numeric value by which both sides are multiplied.

Returns

Equation — This equation after mutation.

toLHS(): EquationMethod

Rewrites this equation as an equivalent residual form with zero on the right.

remarks

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(): stringMethod

Returns the same canonical equation text as Equation.text.

Returns

string — The equation text representation.