polynomial

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyCoefficients is returned if the coefficients is empty
	ErrEmptyCoefficients = errors.New("empty coefficient")
)

Functions

This section is empty.

Types

type Polynomial

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

Polynomial represents a polynomial of arbitrary degree

func NewPolynomial

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

NewPolynomial news a polynomial module fieldOrder. Warning: This function may produce modulo bias if applied directly to slices that have not previously undergone rejection sampling.

func RandomPolynomial

func RandomPolynomial(fieldOrder *big.Int, degree uint32) (*Polynomial, error)

RandomPolynomial randoms a polynomial with random coefficient

func RandomPolynomialWithSpecialValueAtPoint added in v1.0.2

func RandomPolynomialWithSpecialValueAtPoint(x *big.Int, specialValue *big.Int, fieldOrder *big.Int, degree uint32) (*Polynomial, error)

RandomPolynomialWithSpecialValueAtPoint gives a random polynomial f with the given degree with the condition: f(x) = specialValue.

func (*Polynomial) Degree

func (p *Polynomial) Degree() uint32

Degree returns the degree of the polynomial

func (*Polynomial) Differentiate

func (p *Polynomial) Differentiate(diffTime uint32) *Polynomial

Differentiate returns a differentiated function Given f(x) is a polynomial, then output is f^(diffTime)(x) mod field order Ex: f(x)=x^5+2*x^3, diffTime = 1 Then f^(1)(x)= 5*x^4+6*x^2 = 2*x^4.

func (*Polynomial) Evaluate

func (p *Polynomial) Evaluate(x *big.Int) *big.Int

Evaluate returns f(x) mod field order Given a polynomial f(x), then the output is f(x) Ex:f(3)=x^5+2*x^3, x=1, fieldOrder=3 Then f(1)=3=0 mod field order

func (*Polynomial) Get

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

Get gets the ith coefficients. If i is out of range, return nil.

func (*Polynomial) Len

func (p *Polynomial) Len() int

Len returns the length of coefficients

func (*Polynomial) SetConstant

func (p *Polynomial) SetConstant(value *big.Int)

SetConstant sets the constant term of the polynomial

Jump to

Keyboard shortcuts

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