Code Monkey home page Code Monkey logo

sparsepolynomialgo's Introduction

Sparse Polynomial (SparsePolynomial Go)

A Go-Language package for working with sparse polynomials.

Features

  • Create polynomials from a map of coefficients
  • Add, subtract, multiply, divide, and take the remainder of polynomials
  • Evaluate polynomials at a point
  • Take the derivative of a polynomial
  • Take the integral of a polynomial
  • Take the inverse of a polynomial
  • Show a polynomial as a string
  • Find biggest degree of a polynomial

Using

// Create a sparse polynomial
p := NewSparsePolynomial()
p.Add(0, big.NewInt(1))
p.Add(1, big.NewInt(2))
p.Add(2, big.NewInt(3))
p.Add(3, big.NewInt(4))
p.Add(4, big.NewInt(5))
p.Add(5, big.NewInt(6))

// Print the sparse polynomial
fmt.Println(p)

// Evaluate the sparse polynomial at x = 2
fmt.Println(p.Evaluate(big.NewInt(2)))

// Create a sparse polynomial
p2 := NewSparsePolynomial()
p2.Add(0, big.NewInt(1))
p2.Add(1, big.NewInt(2))
p2.Add(2, big.NewInt(3))
p2.Add(3, big.NewInt(4))
p2.Add(4, big.NewInt(5))
p2.Add(5, big.NewInt(6))

// Print the sparse polynomial
fmt.Println(p2)

// Evaluate the sparse polynomial at x = 2
fmt.Println(p2.Evaluate(big.NewInt(2)))

// Addition
fmt.Println(p.Addition(p2))

// Subtraction
fmt.Println(p.Subtraction(p2))

// Multiplication
fmt.Println(p.Multiplication(p2))

// Division
fmt.Println(p.Division(p2))

// Modulus
fmt.Println(p.Modulus(p2))

// Integral
fmt.Println(p.Integral())

// Derivative
fmt.Println(p.Derivative())

// Inverse
fmt.Println(p.Inverse())

See Wikipedia for more information.

© Copyright 2022, Max Base

sparsepolynomialgo's People

Contributors

basemax avatar

Watchers

 avatar  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.