polyring

package
v0.0.0-...-86e0768 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2021 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DivMod

func DivMod(a Polynomial, b Polynomial, p *gmp.Int, q, r *Polynomial) (err error)

DivMod sets computes q, r such that a = b*q + r. This is an implementation of Euclidean division. The complexity is O(n^3)!!

func VecInit

func VecInit(vec []*gmp.Int)

VecInit makes all input vector values zero

func VecPrint

func VecPrint(vec []*gmp.Int)

VecPrint prints an input vector

func VecRand

func VecRand(vec []*gmp.Int, p *gmp.Int, rnd *rand.Rand)

VecRand produces a random vector using a random state

Types

type Polynomial

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

Polynomial struct

func FromString

func FromString(s string) Polynomial

FromString returns a polynomial from an input string

func FromVec

func FromVec(coeff ...int64) Polynomial

FromVec returns a polynomial from an input vector

func New

func New(degree int) (Polynomial, error)

New returns a polynomial P(x) = 0 with capacity degree + 1

func NewConstant

func NewConstant(c int64) Polynomial

NewConstant creates a constant polynomial P(x) = c

func NewEmpty

func NewEmpty() Polynomial

NewEmpty creates a constant polynomial P(x) = 0

func NewOne

func NewOne() Polynomial

NewOne creates a constant polynomial P(x) = 1

func NewRand

func NewRand(degree int, rand *rand.Rand, n *gmp.Int) (Polynomial, error)

NewRand returns a randomized polynomial with specified degree coefficients are pesudo-random numbers in [0, n)

func (*Polynomial) Add

func (poly *Polynomial) Add(op1 Polynomial, op2 Polynomial) error

Add sets poly to op1 + op2

func (*Polynomial) AddMul

func (poly *Polynomial) AddMul(poly2 Polynomial, k *gmp.Int)

AddMul sets poly to poly + poly2 * k (k being a scalar)

func (*Polynomial) AddSelf

func (poly *Polynomial) AddSelf(op Polynomial) error

AddSelf sets poly to poly + op

func (Polynomial) DeepCopy

func (poly Polynomial) DeepCopy() Polynomial

DeepCopy copies the source polynomial into a variable polynomial

func (*Polynomial) Div2

func (poly *Polynomial) Div2(op1 Polynomial, op2 Polynomial) error

Div2 sets poly to op1 / op2. **op2 must be of format x+a ** Complexity is O(deg1)

func (Polynomial) EvalMod

func (poly Polynomial) EvalMod(x *gmp.Int, p *gmp.Int, result *gmp.Int)

EvalMod returns poly(x) using Horner's rule. If p != nil, returns poly(x) mod p

func (Polynomial) EvalModArray

func (poly Polynomial) EvalModArray(x []*gmp.Int, mod *gmp.Int, results []*gmp.Int)

EvalModArray returns poly[x[1]], ..., poly[x[n]]

func (Polynomial) GetAllCoefficients

func (poly Polynomial) GetAllCoefficients() (all []*gmp.Int)

GetAllCoefficients returns a copy of all coefficients

func (Polynomial) GetCap

func (poly Polynomial) GetCap() int

GetCap returns length of a polynomial

func (Polynomial) GetCoefficient

func (poly Polynomial) GetCoefficient(i int) (gmp.Int, error)

GetCoefficient returns coeff[i]

func (Polynomial) GetDegree

func (poly Polynomial) GetDegree() int

GetDegree returns the degree, ignoring removing leading zeroes

func (Polynomial) GetLeadingCoefficient

func (poly Polynomial) GetLeadingCoefficient() gmp.Int

GetLeadingCoefficient returns the coefficient of the highest degree of the variable

func (Polynomial) GetPtrToConstant

func (poly Polynomial) GetPtrToConstant() *gmp.Int

GetPtrToConstant returns a pointer to coeff[0]

func (*Polynomial) GrowCapTo

func (poly *Polynomial) GrowCapTo(cap int)

GrowCapTo increases the size of a polynomial to cap given

func (Polynomial) IsSame

func (poly Polynomial) IsSame(op Polynomial) bool

IsSame returns op == poly

func (Polynomial) IsZero

func (poly Polynomial) IsZero() bool

IsZero returns if poly == 0

func (*Polynomial) Mod

func (poly *Polynomial) Mod(p *gmp.Int)

Mod sets poly to poly % p

func (*Polynomial) Mul

func (poly *Polynomial) Mul(op1 Polynomial, op2 Polynomial) error

Mul set poly to op1 * op2

func (*Polynomial) MulSelf

func (poly *Polynomial) MulSelf(op Polynomial) error

MulSelf set poly to poly * op

func (*Polynomial) One

func (poly *Polynomial) One()

One sets the constant to one

func (Polynomial) Print

func (poly Polynomial) Print(title ...string)

Print the polynomial

func (Polynomial) PrintDegree

func (poly Polynomial) PrintDegree(title ...string)

PrintDegree prints a degree of a polynomial

func (*Polynomial) Rand

func (poly *Polynomial) Rand(rand *rand.Rand, mod *gmp.Int)

Rand sets the polynomial coefficients to a pseudo-random number in [0, n) WARNING: Rand makes sure that the highest coefficient is not zero

func (*Polynomial) Reset

func (poly *Polynomial) Reset()

Reset sets the coefficients to zeroes

func (*Polynomial) ResetTo

func (poly *Polynomial) ResetTo(other Polynomial)

ResetTo sets polynomial to input polynomial given by user

func (*Polynomial) SetCoefficient

func (poly *Polynomial) SetCoefficient(i int, ci int64) error

SetCoefficient sets the poly.coeff[i] to ci

func (*Polynomial) SetCoefficientBig

func (poly *Polynomial) SetCoefficientBig(i int, ci *gmp.Int) error

SetCoefficientBig sets the poly.coeff[i] to ci (a gmp Integer)

func (Polynomial) String

func (poly Polynomial) String() string

Converts to a string representation. Can be converted back using SetString 6 + 3x + 2x^2 => "6;3;2"

func (*Polynomial) Sub

func (poly *Polynomial) Sub(op1 Polynomial, op2 Polynomial) error

Sub sets poly to op1 - op2

func (*Polynomial) SubSelf

func (poly *Polynomial) SubSelf(op Polynomial) error

SubSelf sets poly to poly - op

func (Polynomial) ToString

func (poly Polynomial) ToString() string

ToString returns a string from an input polynomial

Jump to

Keyboard shortcuts

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