Giter Site home page Giter Site logo

polynomial-rs's People

Contributors

adamnemecek avatar daichimukai avatar dependabot[bot] avatar gifnksm avatar konsumlamm avatar orukusaki avatar xoloki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

polynomial-rs's Issues

Avoid cloning where possible

Most methods and trait impls use a lot of cloning. This is not desirable when using BigInt or BigRational for coefficients, so it would be nice to avoid cloning where possible.

Ideas for const polynomials?

Right now polynomial requires a Vec. It would be useful to have either a smallvec or a fixed array to avoid heap allocations.

This would let me write a library that exports polynomials as constants. IE the first complete elliptic integral for use in high-performance simulations.

Any of [T; N] or &'static T would be useful.

Incorrect polynomial fitment

The degree 2 polynomial to $f(0)=3849; f(1)=34331; f(2)=95175$ is incorrectly fitted.

This library returns: $3848 + 15303 x + 15180 x^2 $
The correct result is: $3849 + 15301 x + 15181 x^2 $
Error: $-1 + 2x -1x^2$
This can be verified by res-subsituting the variables. In particular, the error in $f(0)$ is trivial

Wolframalpha gives the correct result

Reproduction

Cargo.toml

[dependencies]
polynomial = "0.2.6"

src/main.rs

use polynomial::Polynomial;
fn main() {
    let xs = vec![0, 1, 2];
    let ys = vec![3849, 34331, 95175];

    let poly = Polynomial::lagrange(&xs, &ys).unwrap();
    println!("{}", poly.pretty("x")); //3848+15303*x+15180*x^2
}

This was found during AOC Day21, and was responsible for quite some hours of debugging :^|

Evaluation using Horner's method

Currently the implementation of Polynomial::eval seems not optimal. We can always apply the property of Distributivity of multiplication over addition to reduce the computational complexity.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.