Function reference · Solving

solve

Solves an expression or equation for a variable and returns the solutions as a SolutionSet.

Nerdamer's solver is not limited to polynomial roots. It combines exact symbolic isolation, polynomial solving, supported radical and rational transformations, complex arithmetic, periodic families, and numerical root finding for equations that do not reduce to a closed symbolic form.

Expressions are treated as equations equal to zero; explicit equations can be supplied directly. Candidate roots are checked against the source equation in supported transformations so denominator singularities and extraneous roots introduced while isolating radicals or logarithms can be rejected.

The solver returns distinct solutions in a SolutionSet rather than a plain JavaScript array.

Examples

These examples use Nerdamer Notation.

Derive the quadratic formula while preserving symbolic parameters.

solve(a*x^2+b*x+c,x)
// → {(1/2)*a^-1*(-b+(b^2-4*a*c)^(1/2)), (1/2)*a^-1*(-b-(b^2-4*a*c)^(1/2))}

Return the complete periodic family. _n is Nerdamer's reserved integer index, so this represents x=n*pi for every integer n.

solve(sin(x),x)
// → {_n*pi}

Store the periodic SolutionSet, then evaluate the family at n=0 with a substitution local to evaluate. Use : to assign sol; = constructs an equation.

sol: solve(sin(x),x); evaluate(sol,{_n=>0})
// → {0}

Invert an exponential with a symbolic compound base; the result is equivalent to log(y)/log(a+b).

solve((a+b)^x=y,x)
// → {log(y)*log(a+b)^-1}

Solve a rational-transcendental equation while excluding x=0, where the original denominator vanishes.

solve(0=(x^2-2)/(e^x-1),x)
// → {2^(1/2), -2^(1/2)}

Isolate a radical and verify the surviving branch against the original equation.

solve(x-sqrt(x+1)=5,x)
// → {8}

Solve a logarithmic equation and reject roots that violate the original logarithm domains.

solve(log(x-1)+log(x+3)+log(3)=log(15),x)
// → {2}

Solve directly over complex values.

solve((z+5)/(3-i)=2-5*i,z)
// → {-4-17*i}

Find both real roots when the unknown also appears in an exponent, including the nontrivial numerical root near 0.309906932380691 and the exact root 4.

solve(x=2^x/4,x)
// → {0.30990693238069053546, 4}

Isolate velocity in the relativistic kinetic-energy equation and return the two symbolic velocity branches.

solve(E_k=m*c^2*((1-v^2/c^2)^(-1/2)-1),v)
// → {-c^2*(c^-2*(1-c^4*m^2*((E_k^2+2*c^2*m*E_k+c^4*m^2)^-1)))^(1/2), c^2*(c^-2*(1-c^4*m^2*((E_k^2+2*c^2*m*E_k+c^4*m^2)^-1)))^(1/2)}

Interfaces

The same operation is available through the interfaces below.

Nerdamer Notation · nerdamer API · Direct API

Nerdamer Notation

Use this form inside input passed to nerdamer(...).

solve(expressionOrEquation, variable)

Parameters

  • expressionOrEquation — Expression or equation to solve.
  • variable — Variable to solve for.

nerdamer.solve

Call the operation through the default nerdamer import.

nerdamer.solve(input: Equation | ExpressionInput, variable?: ExpressionInput, _options?: FunctionSolverOptions): SolutionSet

Parameters

NameTypeDescription
inputEquation | ExpressionInputExpression or equation to solve.
variableExpressionInputVariable to solve for. When omitted, input preparation infers it where possible.
_optionsFunctionSolverOptionsReserved numerical-solver options.

Returns

SolutionSet — A SolutionSet. The special all expression represents an identity that is true for every value of the variable.

Browse the nerdamer API →

Direct JavaScript / TypeScript API

Import the operation directly from its package entry point.

import { solve } from 'nerdamer/solve';
solve(input: Equation | ExpressionInput, variable?: ExpressionInput, _options?: FunctionSolverOptions): SolutionSet

Parameters

NameTypeDescription
inputEquation | ExpressionInputExpression or equation to solve.
variableExpressionInputVariable to solve for. When omitted, input preparation infers it where possible.
_optionsFunctionSolverOptionsReserved numerical-solver options.

Returns

SolutionSet — A SolutionSet. The special all expression represents an identity that is true for every value of the variable.

Browse nerdamer/solve →

Notes

  • _n is Nerdamer's reserved integer family parameter. In {_n*pi}, substituting _n=-2,-1,0,1,2,... gives ..., -2*pi, -pi, 0, pi, 2*pi, ... and therefore all roots of sin(x)=0.
  • In Nerdamer Scripting, a periodic SolutionSet can be stored and evaluated with sol: solve(sin(x),x); evaluate(sol,{_n=>0}), which returns {0}. The : operator stores sol; = denotes an equation and is not assignment syntax.
  • The {_n=>0} Dictionary entry is local to evaluate. It does not assign the reserved _n name globally, so _n:0 remains invalid.
  • To select a member of a periodic family in JavaScript / TypeScript, take the returned family expression and substitute an integer for _n: const solutions = nerdamer.solve('sin(x)', 'x'); const family = solutions.elements[0]; family.subst('_n', 2).text() returns 2*pi.
  • Some non-polynomial equations require numerical root finding; those solutions can therefore be approximate rather than exact symbolic expressions.

← Back to Function reference