Crates.io | polynomial-roots |
lib.rs | polynomial-roots |
version | 1.0.0 |
source | src |
created_at | 2023-01-06 23:21:33.021416 |
updated_at | 2024-01-04 13:47:31.527127 |
description | Find the real roots of huge polynomials in milliseconds |
homepage | |
repository | https://github.com/TiagoCavalcante/polynomial-roots |
max_upload_size | |
id | 752668 |
size | 17,420 |
Find the real roots of huge polynomials in milliseconds
cargo build --release
The coefficients are in degree-ascending order, that is: $x^0 + x^1 + x^2 + x^3 + \cdots$
The coefficients are passed space-separated, therefore to solve the polynomial $3 - 9x + x^3$ you need to run the program the following way:
$ cargo install polynomial-roots
$ polynomial-roots
3 -9 0 1
{ -3.154523; 0.33760893; 2.816914; }
(note: don't forget the zero coefficients)
The roots are found using the linear formula ($\dfrac{-b}{a}$), the quadratic formula ($\dfrac{-b \pm \sqrt{b^2 - 4 a c}}{2 a}$), or the false position method over the Cauchy's bound. It can solve polynomials of any degree.
If you aren't getting all the roots you should modify the constants from the file src/constants.rs
. You can DECREASE PARTITION_SIZE
and INCREASE ITERATIONS
. That will make the program slower, but with the right tweaks it can solve any polynomial.