Documentation ¶
Index ¶
- func DivMod(a Polynomial, b Polynomial, p *gmp.Int, q, r *Polynomial) (err error)
- func VecInit(vec []*gmp.Int)
- func VecPrint(vec []*gmp.Int)
- func VecRand(vec []*gmp.Int, p *gmp.Int, rnd *rand.Rand)
- type Polynomial
- func (poly *Polynomial) Add(op1 Polynomial, op2 Polynomial) error
- func (poly *Polynomial) AddMul(poly2 Polynomial, k *gmp.Int)
- func (poly *Polynomial) AddSelf(op Polynomial) error
- func (poly Polynomial) DeepCopy() Polynomial
- func (poly *Polynomial) Div2(op1 Polynomial, op2 Polynomial) error
- func (poly Polynomial) EvalMod(x *gmp.Int, p *gmp.Int, result *gmp.Int)
- func (poly Polynomial) EvalModArray(x []*gmp.Int, mod *gmp.Int, results []*gmp.Int)
- func (poly Polynomial) GetAllCoefficients() (all []*gmp.Int)
- func (poly Polynomial) GetCap() int
- func (poly Polynomial) GetCoefficient(i int) (gmp.Int, error)
- func (poly Polynomial) GetDegree() int
- func (poly Polynomial) GetLeadingCoefficient() gmp.Int
- func (poly Polynomial) GetPtrToConstant() *gmp.Int
- func (poly *Polynomial) GrowCapTo(cap int)
- func (poly Polynomial) IsSame(op Polynomial) bool
- func (poly Polynomial) IsZero() bool
- func (poly *Polynomial) Mod(p *gmp.Int)
- func (poly *Polynomial) Mul(op1 Polynomial, op2 Polynomial) error
- func (poly *Polynomial) MulSelf(op Polynomial) error
- func (poly *Polynomial) One()
- func (poly Polynomial) Print(title ...string)
- func (poly Polynomial) PrintDegree(title ...string)
- func (poly *Polynomial) Rand(rand *rand.Rand, mod *gmp.Int)
- func (poly *Polynomial) Reset()
- func (poly *Polynomial) ResetTo(other Polynomial)
- func (poly *Polynomial) SetCoefficient(i int, ci int64) error
- func (poly *Polynomial) SetCoefficientBig(i int, ci *gmp.Int) error
- func (poly Polynomial) String() string
- func (poly *Polynomial) Sub(op1 Polynomial, op2 Polynomial) error
- func (poly *Polynomial) SubSelf(op Polynomial) error
- func (poly Polynomial) ToString() string
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)!!
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 NewRand ¶
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 ¶
EvalMod returns poly(x) using Horner's rule. If p != nil, returns poly(x) mod p
func (Polynomial) EvalModArray ¶
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) 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) 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) 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