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.

remarks

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): PolynomialSolverConstructor

Creates a polynomial root solver.

throws

core!UnexpectedInputError If symbolic input is multivariate, uses a variable different from variable, or has nonnumeric coefficients.

Parameters

NameTypeDescription
inputstring | Expression | Decimal[] | PolynomialA polynomial expression, Polynomial, polynomial string, or ascending-power Decimal coefficients.
variablestringVariable expected in polynomial or string input. It is used to reject a conflicting variable or multivariate polynomial.
precisionnumberWorking decimal.js precision used while finding roots.
epsilonDecimalNumerical convergence tolerance. Defaults to 1e-14.

Returns

PolynomialSolver

roots(asExpressions?: true): Expression[]Method

Computes 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

NameTypeDescription
asExpressionstrueWhether 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[]Method

Computes roots numerically, rejects candidates with an excessive polynomial residual, and converts accepted values only after numerical validation is complete.

Parameters

NameTypeDescription
asExpressionstrue—

Returns

Expression[]