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. Jenkins–Traub can be selected explicitly for real
coefficients without changing the default. Exact real-rational inputs with repeated factors
use square-free decomposition to preserve their root multiplicities.
The solver raises the global decimal.js precision to at least the requested
precision while roots runs (see precisionBlock), so a higher user
precision is kept, and restores the previous precision before returning.
The working precision controls the numerical work, while epsilon
controls convergence and cleanup of numerical noise. Roots are returned
once per polynomial degree. Exact rational repeated roots are reconstructed
from square-free factors; other repeated roots can remain 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 | Complex[], 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 | Complex[] | 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 | Minimum working decimal.js precision used while finding roots. |
epsilon | Decimal | Numerical convergence tolerance. Defaults to 1e-14. |
Returns
roots(asExpressions?: true, method?: PolynomialMethod): 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. |
method | PolynomialMethod | Numerical method: aberth (default) or
jenkinsTraub (real coefficients only; throws on incomplete solves). |
Returns
Expression[] — One root value per effective polynomial degree, including repeated
numerical approximations for repeated roots.
validatedRoots(asExpressions?: true, method?: PolynomialMethod): 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 | — |
method | PolynomialMethod | — |
