polynomial

package module
v0.0.0-...-531bd0d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2023 License: MIT Imports: 2 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

polynomial

A small library for working with polynomials. Supports big numbers

Go Reference

Install

go get github.com/Rusih100/polynomial

Description

The library supports the following operations on polynomials:

  • Addition
  • Subtraction
  • Multiplication
  • Division with remainder
  • Taking coefficients modulo
  • String representation
  • String representation of a polynomial in the form of an array of its coefficients

Creating a polynomial

Creating a polynomial x^3 + 5x - 4

polyCoefficient := []*big.Int{ // x^3 + 5x - 4
  big.NewInt(-4),
  big.NewInt(5),
  big.NewInt(0),
  big.NewInt(1),
}

poly := polynomial.NewPolynomial(polyCoefficient) 

Example of addition

polyCoefficientOne := []*big.Int{ // 10x + 5
  big.NewInt(5),
  big.NewInt(10),
}

polyCoefficientTwo := []*big.Int{ // 3x^2 + 2x + 1
  big.NewInt(1),
  big.NewInt(2),
  big.NewInt(3),
}

polyOne := polynomial.NewPolynomial(polyCoefficientOne)
polyTwo := polynomial.NewPolynomial(polyCoefficientTwo)

result := new(polynomial.Polynomial)
result = result.Add(polyOne, polyTwo) // 3x^2 + 12x + 6

Documentation

https://pkg.go.dev/github.com/Rusih100/polynomial

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Polynomial

type Polynomial struct {
	// contains filtered or unexported fields
}

Polynomial - structure for a polynomial. The zero position of the coefficients array corresponds to the coefficient of the free term of the polynomial.

func NewPolynomial

func NewPolynomial(coefficients []*big.Int) *Polynomial

NewPolynomial - creates a polynomial and sets it an array of values when creating.

func (*Polynomial) Add

func (p *Polynomial) Add(_a, _b *Polynomial) *Polynomial

Add - adds two polynomials a and b and writes to c. Returns c.

func (*Polynomial) Get

func (p *Polynomial) Get(i int) *big.Int

Get - returns the coefficient of the polynomial.

func (*Polynomial) Mod

func (p *Polynomial) Mod(_a *Polynomial, _mod *big.Int) *Polynomial

Mod - takes the modulus for each coefficient of the polynomial a and writes the coefficients in c. Returns c.

func (*Polynomial) Mul

func (p *Polynomial) Mul(_a, _b *Polynomial) *Polynomial

Mul - multiplies two polynomials a and b and writes to c. Returns c.

func (*Polynomial) QuoRem

func (p *Polynomial) QuoRem(a, b *Polynomial) (quo, rem *Polynomial)

QuoRem - division with remainder of polynomial a by polynomial b. Sets the quotient of division to c. Returns the quotient and remainder.

func (*Polynomial) Set

func (p *Polynomial) Set(coefficients []*big.Int) *Polynomial

Set - sets an array of coefficients in c, and returns c. The zero position of the coefficients array corresponds to the coefficient of the free term of the polynomial.

func (*Polynomial) SetPolynomial

func (p *Polynomial) SetPolynomial(other *Polynomial) *Polynomial

SetPolynomial - sets an array of coefficients of the polynomial c based on the polynomial p. Returns c.

func (*Polynomial) String

func (p *Polynomial) String() string

String - returns a polynomial in the form of a string of the form x^3 + 2x - 1.

func (*Polynomial) StringCoefficients

func (p *Polynomial) StringCoefficients() string

StringCoefficients - returns a polynomial as a string of vector X(3 3 2).

func (*Polynomial) Sub

func (p *Polynomial) Sub(_a, _b *Polynomial) *Polynomial

Sub - subtracts the polynomial b from the polynomial a and writes it to c. Returns c.

func (*Polynomial) Value

func (p *Polynomial) Value(_x *big.Int) *big.Int

Value - returns the value of the polynomial for a specific x.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址