Giter Site home page Giter Site logo

mpolynomial's Introduction

Multi-dimensional Polynomials

Build Status

Peform operations with multivariate polynomials such as replacement and multiplication in rust. With this library one can import polynomial functions into rust in an easy way and perform simple operations end evaluations.

The supported type for the coefficients are:

  • f64 (real and complex)
  • f128 (real and complex)
  • num::BigRational

There is a parser that imports expressions from string into num::BigRational:

extern crate mpolynomial;

use mpolynomial::MPolynomial;
use mpolynomial::parser::parse_expression;
use num::{BigInt, BigRational};

fn main() {
    let var_names = vec![
        String::from("x1"),
        String::from("x2"),
        String::from("x3"),
        String::from("x4"),
    ];

    // Geometric Series
    let mpoly_str = "(1-x1^11)^2";
    let factor_str = "(1-x1)^2";
    let res_str = "(1+x1+x1^2+x1^3+x1^4+x1^5+x1^6+x1^7+x1^8+x1^9+x1^10)^2";

    let mut mpoly = parse_expression(mpoly_str, &var_names);
    let factor = parse_expression(factor_str, &var_names);
    let res = parse_expression(res_str, &var_names);

    mpoly.exact_division(&factor).unwrap();
    assert_eq!(res.to_str(&var_names), mpoly.to_str(&var_names));

    // Multivariate
    let mpoly_str = "(11 x1^32 + 12 x2 + 99 x3 + 21 x1*x4)^10";
    let factor_str = "(11 x1**32 + 12 x2 + 99 x3 + 21 x1*x4)^8";

    let factor = parse_expression(factor_str, &var_names);
    let mut mpoly = parse_expression(mpoly_str, &var_names);

    mpoly.exact_division(&factor).unwrap();
    //println!("{}", mpoly);
    let mut res_str = String::new();
    res_str += "+9801*x3^2+2376*x2^1*x3^1+144*x2^2+4158*x1^1*x3^1*x4^1";
    res_str += "+504*x1^1*x2^1*x4^1+441*x1^2*x4^2+2178*x1^32*x3^1";
    res_str += "+264*x1^32*x2^1+462*x1^33*x4^1+121*x1^64";
    assert_eq!(res_str, format!("{}", mpoly));
}

Here is a list of the function implemented for the structure MPolynomial:

  • add: add a monomial to the polynomial
  • update: update the coefficient of a monomial
  • replace: replace one variable with a linear polynomial (e.g. x1-> c+2x1+3x2)
  • mult: multiply the current polynomial by another and overwrite
  • exact_division: divide by one of the factors of the polynomial (otherwise fails)
  • euclidean_division: returns both the quotient and remainder of the division
  • multivariate_gcd: compute the gcd of two polynomial
  • ...
  • ...

mpolynomial's People

Contributors

apelloni avatar

Watchers

 avatar

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.