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`

. Polynomial and string inputs are converted to that representation 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 | Decimal[] | Polynomial, variable?: string, precision: number, epsilon?: Decimal): PolynomialSolverConstructor

Creates a polynomial root solver.

throws

UnexpectedInputError If a string input is multivariate or uses a variable different from

`variable`

.

Parameters

NameTypeDescription
inputstring | Decimal[] | PolynomialA polynomial, a polynomial string, or ascending-power coefficients.
variablestringVariable expected in a string input. It is used to reject a conflicting or multivariate string.
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.