PolySolve Logo

The Accurate Python Polynomial Solver

Finds stable, correct roots for high-degree polynomials where standard methods like NumPy fail due to numerical instability. Robust calculus and arithmetic included.

$ pip install polysolve

Get Started in 30 Seconds

import polysolve
# Create an object representing f(x) = 2x^2 - 3x - 5
f1 = polysolve.Function(2)
f1.set_coeffs([2, -3, -5])
# Find the approximate real roots using the
# fast, Numba-accelerated CPU solver.
roots = f1.get_real_roots()
print(roots)
# Expected accurate output: [-1. 2.5] (after clustering)
Numerically Stable Solver

Uses a robust genetic algorithm to find correct roots for high-degree polynomials where traditional methods like NumPy suffer from instability and fail.

CUDA Accelerated

Leverage your NVIDIA GPU for massive speedups on large datasets. Perfect for data science and research.

Numba Accelerated CPU

No GPU? No problem. The default solver is JIT-compiled with Numba and parallelized to be highly performant on your CPU.

Intuitive API

Use natural Python operators (+, -, *) to perform polynomial calculus and arithmetic effortlessly.

Accuracy Where It Matters Most

Standard libraries like NumPy can be fast for low degrees, but suffer from catastrophic numerical instability on high-degree polynomials, leading to massive errors. PolySolve‘s genetic algorithm is designed for stability, delivering accurate results you can trust.

NumPy Instability vs. PolySolve Stability
PolySolve Benchmark: Accuracy (MAE) vs NumPy

High Performance on CPU & GPU

Thanks to Numba, the PolySolve (CPU) solver is highly optimized. While NumPy is faster for simple, low-degree problems, PolySolve‘s performance scales far better, remaining fast and stable as polynomial complexity increases. And crucially, it provides the correct answer.

Performance vs. Problem Complexity
PolySolve Benchmark: Speed Comparison

CUDA Makes Accuracy Practical

PolySolve‘s CUDA acceleration provides a massive speedup (over 17x at degree 100) compared to its (already fast) Numba-powered CPU implementation. This makes it feasible to solve complex, high-degree polynomials accurately in seconds, not minutes.

PolySolve GPU vs. CPU Speedup
PolySolve Benchmark: GPU Speedup Factor

Benchmark Notes: The charts above compare PolySolve (v0.6.0) against NumPy on randomly generated polynomials of varying degrees. PolySolve‘s Genetic Algorithm was configured for high accuracy using these options: num_of_generations=150, data_size=1000000, and other tuning parameters. For full benchmark details and code, see the Documentation.