PolynomialSolver
Finds all complex roots of a univariate polynomial numerically.
Coefficient arrays use ascending powers: the element at index k is the
coefficient of x^k. Expression, Polynomial, and string inputs are converted directly
to numerical complex coefficients before solving. Linear and quadratic inputs are handled
directly; higher degrees use simultaneous Aberth iteration followed by
Newton refinement.
The solver temporarily changes the global decimal.js precision while
roots runs and restores the previous precision before returning.
The requested precision controls the numerical work, while epsilon
controls convergence and cleanup of numerical noise. Roots are returned
once per polynomial degree, so repeated roots can appear as repeated nearby
approximations.
This class finds numerical roots; it does not certify completeness or exact
multiplicities for ill-conditioned polynomials.
Examples
const solver = new PolynomialSolver('x^2+1', 'x');
const roots = solver.roots();Members
PolynomialSolver(input: string | Expression | Decimal[] | Polynomial, variable?: string, precision: number, epsilon?: Decimal): PolynomialSolverConstructorCreates a polynomial root solver.
core!UnexpectedInputError If symbolic input is multivariate, uses a
variable different from variable, or has nonnumeric coefficients.
Parameters
| Name | Type | Description |
|---|---|---|
input | string | Expression | Decimal[] | Polynomial | A polynomial expression, Polynomial, polynomial string, or ascending-power Decimal coefficients. |
variable | string | Variable expected in polynomial or string input. It is used to reject a conflicting variable or multivariate polynomial. |
precision | number | Working decimal.js precision used while finding roots. |
epsilon | Decimal | Numerical convergence tolerance. Defaults to 1e-14. |
Returns
roots(asExpressions?: true): Expression[]MethodComputes the roots of the configured polynomial.
Leading zero coefficients are ignored. A constant or zero coefficient
array produces an empty result. Passing false returns the numeric
Complex values directly; otherwise each root is converted to an
Expression after restoring the caller's Decimal precision.
Parameters
| Name | Type | Description |
|---|---|---|
asExpressions | true | Whether to convert roots to symbolic expressions.
Defaults to true. |
Returns
Expression[] — One root value per effective polynomial degree, including repeated
numerical approximations for repeated roots.
validatedRoots(asExpressions?: true): Expression[]MethodComputes roots numerically, rejects candidates with an excessive polynomial residual, and converts accepted values only after numerical validation is complete.
Parameters
| Name | Type | Description |
|---|---|---|
asExpressions | true | — |
