#polynomial #no-std

no-std rustnomial

A crate for working with polynomials

12 unstable releases (3 breaking)

0.3.2 Jun 27, 2021
0.3.1 Jun 27, 2021
0.2.0 Jan 16, 2021
0.1.0 Jan 16, 2021
0.0.7 Aug 11, 2020

#789 in Math

Download history 375/week @ 2023-12-06 476/week @ 2023-12-13 172/week @ 2023-12-20 25/week @ 2023-12-27 164/week @ 2024-01-03 368/week @ 2024-01-10 327/week @ 2024-01-17 261/week @ 2024-01-24 226/week @ 2024-01-31 253/week @ 2024-02-07 337/week @ 2024-02-14 338/week @ 2024-02-21 244/week @ 2024-02-28 250/week @ 2024-03-06 303/week @ 2024-03-13 136/week @ 2024-03-20

951 downloads per month

MIT license

205KB
5K SLoC

rustnomial

This crate provides utilities for operating on polynomials, including:

  • Parsing polynomials from strings, and creating strings from polynomials
  • Math operations with polynomials
  • Integration and derivation of polynomials
  • Finding polynomial roots

Examples

  • Parsing polynomials from / to strings:
use std::str::FromStr;

use rustnomial::{GenericPolynomial, Polynomial};

fn main() {
    let poly = Polynomial::<i32>::from_str("1+x^2-3+11x").unwrap();
    // x^2 + 11x - 2
    println!("{}", poly);
}
  • Integration
use rustnomial::integral;

fn main() {
    let poly = integral!(5., 2., 0.);
    // 1.6666666666666667x^3 + x^2 + C
    println!("{}", poly);
    // 2.666666666666667
    println!("{}", poly.eval(0., 1.));
}
  • Derivation
use rustnomial::derivative;

fn main() {
    let poly = derivative!(5., 2., 0.);
    // 10x + 2
    println!("{}", poly);
}
  • Rootfinding
use rustnomial::{GenericPolynomial, Polynomial};

fn main() {
    let poly = Polynomial::<f64>::new(vec![1., 2.]).pow(9) * Polynomial::new(vec![1., 3.]);
    // ManyRealRoots([-3.0, -2.0, -2.0, -2.0, -2.0, -2.0, -2.0, -2.0, -2.0, -2.0])
    println!("{:?}", poly.roots());
}

Dependencies

~625KB
~12K SLoC