integerpolynomial

package
v0.0.2-0...-db6250e Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2020 License: CC0-1.0, CC0-1.0, CC0-1.0 Imports: 20 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AreEqual

func AreEqual(f *Element, g *Element) bool

AreEqual returns true iff the polynomials f and g have the same parent, and f = g.

func CmpLeadingMonomial

func CmpLeadingMonomial(f *Element, g *Element) (int, error)

CmpLeadingMonomial returns -1 if LM(f) < LM(g), 0 if LM(f) = LM(g), and +1 if LM(f) > LM(g), were LM denotes the leading monomial. Here f and g are non-zero polynomials with the same parent.

func CoefficientRing

func CoefficientRing(R *Parent) *integer.Parent

CoefficientRing returns the coefficient ring of the polynomial ring R.

func ExponentMonoid

func ExponentMonoid(R *Parent) *integervector.Parent

ExponentMonoid returns the exponent monoid of the polynomial ring R.

Types

type Element

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

Element describes a polynomial with integer coefficients.

func Add

func Add(f *Element, g *Element) (*Element, error)

Add returns the sum f + g of two polynomials f and g. This will return an error if f and g do not have the same parent.

func FromInt64Slice

func FromInt64Slice(R *Parent, initial int64, step int64, cs []int64) (*Element, error)

FromInt64Slice returns a univariate polynomial in R with coefficients from the slice cs. The exponents, which must all be non-negative, begin at degree "initial" and increase in degree by "step" (which can be positive or negative).

func FromIntSlice

func FromIntSlice(R *Parent, initial int64, step int64, cs []int) (*Element, error)

FromIntSlice returns a univariate polynomial in R with coefficients from the slice cs. The exponents, which must all be non-negative, begin at degree "initial" and increase in degree by "step" (which can be positive or negative).

func FromIntegerSlice

func FromIntegerSlice(R *Parent, initial int64, step int64, cs []*integer.Element) (*Element, error)

FromIntegerSlice returns a univariate polynomial in R with coefficients from the slice cs. The exponents, which must all be non-negative, begin at degree "initial" and increase in degree by "step" (which can be positive or negative).

func FromParallelInt64Slices

func FromParallelInt64Slices(R *Parent, cs []int64, es []int64) (*Element, error)

FromParallelInt64Slices returns a polynomial in the univariate polynomial ring R, with parallel slices of coefficients cs and exponents es.

func FromParallelIntSlices

func FromParallelIntSlices(R *Parent, cs []int, es []int) (*Element, error)

FromParallelIntSlices returns a polynomial in the univariate polynomial ring R, with parallel slices of coefficients cs and exponents es.

func FromParallelIntegerSlices

func FromParallelIntegerSlices(R *Parent, cs []*integer.Element, es []*integer.Element) (*Element, error)

FromParallelIntegerSlices returns a polynomial in the univariate polynomial ring R, with parallel slices of coefficients cs and exponents es.

func FromParallelSlices

func FromParallelSlices(R *Parent, cs []*integer.Element, es []*integervector.Element) (*Element, error)

FromParallelSlices returns a polynomial in the polynomial ring R, with parallel slices of coefficients cs and exponents es. The exponents should lie in the monoid of exponents of R.

func GobDecode

func GobDecode(dec *gob.Decoder) (*Element, error)

GobDecode reads the next value from the given gob.Decoder and decodes it as a polynomial.

func GobDecodeSlice

func GobDecodeSlice(dec *gob.Decoder) ([]*Element, error)

GobDecodeSlice reads the next value from the given gob.Decoder and decodes it as a slice of polynomials.

func Multiply

func Multiply(f *Element, g *Element) (*Element, error)

Multiply returns the product f * g of two polynomials f and g. This will return an error if f and g do not have the same parent.

func Negate

func Negate(f *Element) *Element

Negate returns the negation -f of the polynomial f.

func NthVariable

func NthVariable(R *Parent, n int) (*Element, error)

NthVariable returns the n-th variable x_n in the polynomial ring R. Here variables are indexed from 0 to rk-1 (inclusive), where rk is the rank of R.

func One

func One(R *Parent) *Element

One returns the constant polynomial 1 of R.

func Power

func Power(f *Element, k *integer.Element) (*Element, error)

Power returns the power f^k of the polynomial f.

func PowerInt64

func PowerInt64(f *Element, k int64) (*Element, error)

PowerInt64 returns the power f^k of the polynomial f.

func Subtract

func Subtract(f *Element, g *Element) (*Element, error)

Subtract returns the difference f - g of two polynomials f and g. This will return an error if f and g do not have the same parent.

func Sum

func Sum(R *Parent, S ...*Element) (*Element, error)

Sum returns the sum of the polynomials in the slice S. All polynomials must have the same parent R. If S is empty, the zero element in R is returned.

func ToElement

func ToElement(R *Parent, f object.Element) (*Element, error)

ToElement returns f as an element in the polynomial ring R with integer coefficients, if f can naturally be regarded as belonging there.

func ToMonomial

func ToMonomial(R *Parent, m *integervector.Element) (*Element, error)

ToMonomial returns the monomial x^m in the polynomial ring R, where m is an element in the exponent monoid of R.

func ToTerm

func ToTerm(R *Parent, c *integer.Element, m *integervector.Element) (*Element, error)

ToTerm returns the term c * x^m in the polynomial ring R, where c is an element in the coefficient ring of R and m is an element in the exponent monoid of R.

func Variables

func Variables(R *Parent) []*Element

Variables returns the variables x_0,...,x_k of the polynomial ring R, where k+1 is equal to the rank of R.

func Zero

func Zero(R *Parent) *Element

Zero returns the zero polynomial of R.

func (*Element) Coefficient

func (f *Element) Coefficient(m *integervector.Element) (*integer.Element, error)

Coefficient returns the coefficient of the degree m term of the polynomial f, where m is an element of the exponent monoid. The returned coefficient will live in the coefficient ring of the parent polynomial ring.

func (*Element) Coefficients

func (f *Element) Coefficients() []*integer.Element

Coefficients returns a slice of coefficient of the polynomial f. Only the non-zero coefficient will be returned, hence the zero polynomial returns an empty slice. The returned coefficients will live in the coefficient ring of the parent polynomial ring.

func (*Element) CoefficientsAndExponents

func (f *Element) CoefficientsAndExponents() (cs []*integer.Element, es []*integervector.Element)

CoefficientsAndExponents returns parallel slices of coefficient cs and exponents es of the polynomial f. Only the terms with non-zero coefficient will be returned, hence the zero polynomial returns a pair of empty slices. The returned coefficients will live in the coefficient ring of the parent polynomial ring. The returned exponents will live in the exponent monoid of the parent polynomial ring, and are sorted in increasing order.

func (*Element) ConstantCoefficient

func (f *Element) ConstantCoefficient() *integer.Element

ConstantCoefficient returns the constant coefficient of the polynomial f. The returned coefficient will live in the coefficient ring of the parent polynomial ring.

func (*Element) Degree

func (f *Element) Degree() (*integervector.Element, error)

Degree returns the degree of the non-zero polynomial f. The degree is an element of the exponent monoid of the parent polynomial ring.

func (*Element) Derivative

func (f *Element) Derivative(k int) (*Element, error)

Derivative returns the formal partial derivative df/dx_k of the polynomial f. Here the variables x_i are indexed from 0 to rk-1 (inclusive), where rk is the rank of the parent.

func (*Element) Exponents

func (f *Element) Exponents() []*integervector.Element

Exponents returns a slice of exponents of the polynomial f. Only the exponents corresponding to terms with non-zero coefficient will be returned, hence the zero polynomial returns an empty slice. The returned exponents will live in the exponent monoid of the parent polynomial ring, and are sorted in increasing order.

func (*Element) GobDecode

func (f *Element) GobDecode(buf []byte) error

GobDecode implements the gob.GobDecoder interface. Important: Take great care that you are decoding into a new *Element; the safe way to do this is to use the GobDecode(dec *gob.Decode) function. The decoded polynomial will lie in the default parent.

func (*Element) GobEncode

func (f *Element) GobEncode() ([]byte, error)

GobEncode implements the gob.GobEncoder interface.

func (*Element) Hash

func (f *Element) Hash() hash.Value

Hash returns a hash value for the polynomial f.

func (*Element) IsConstant

func (f *Element) IsConstant() (bool, *integer.Element)

IsConstant returns true iff the polynomial f is a constant polynomial. If true, also returns the constant (as an element in the coefficient ring of the parent polynomial ring).

func (*Element) IsEqualTo

func (f *Element) IsEqualTo(g *Element) bool

IsEqualTo returns true iff the polynomials f and g have the same parent, and f = g.

func (*Element) IsMonic

func (f *Element) IsMonic() bool

IsMonic returns true iff the polynomial f is monic (that is, if the leading coefficient of f is 1).

func (*Element) IsMonomial

func (f *Element) IsMonomial() bool

IsMonomial returns true iff the polynomial f is a monomial (that is, if f is of the form x^m for some m in the monoid of exponents).

func (*Element) IsNthVariable

func (f *Element) IsNthVariable(n int) (bool, error)

IsNthVariable returns true iff the polynomial f is the n-th variable x_n in the parent polynomial ring. Here variables are indexed from 0 to rk-1 (inclusive), where rk is the rank of the parent.

func (*Element) IsOne

func (f *Element) IsOne() bool

IsOne returns true iff f is the constant polynomial 1.

func (*Element) IsTerm

func (f *Element) IsTerm() bool

IsTerm returns true iff the polynomial f is a term (that is, if f is of the form c * x^m for some c in the coefficient ring, and m in the monoid of exponents).

func (*Element) IsZero

func (f *Element) IsZero() bool

IsZero returns true iff f is the zero polynomial.

func (*Element) LeadingCoefficient

func (f *Element) LeadingCoefficient() *integer.Element

LeadingCoefficient returns the leading coefficient of the polynomial f. The returned coefficient will live in the coefficient ring of the parent polynomial ring.

func (*Element) LeadingMonomial

func (f *Element) LeadingMonomial() (*Element, error)

LeadingMonomial returns the leading monomial of the non-zero polynomial f as an element of the polynomial ring.

func (*Element) LeadingTerm

func (f *Element) LeadingTerm() *Element

LeadingTerm returns the leading term of the polynomial f.

func (*Element) Negate

func (f *Element) Negate() *Element

Negate returns the negation -f of the polynomial f.

func (*Element) NthDerivative

func (f *Element) NthDerivative(k int, n int) (*Element, error)

NthDerivative returns the n-th formal partial derivative d^nf/dx_k^n of the polynomial f, where n is a non-negative integer. Here the variables x_i are indexed from 0 to rk-1 (inclusive), where rk is the rank of the parent.

func (*Element) Parent

func (f *Element) Parent() object.Parent

Parent returns the parent of the polynomial f.

func (*Element) Power

func (f *Element) Power(k *integer.Element) (*Element, error)

Power returns the power f^k of the polynomial f.

func (*Element) PowerInt64

func (f *Element) PowerInt64(k int64) (*Element, error)

PowerInt64 returns the power f^k of the polynomial f.

func (*Element) ScalarMultiplyByCoefficient

func (f *Element) ScalarMultiplyByCoefficient(a *integer.Element) (*Element, error)

ScalarMultiplyByCoefficient returns the product a * f of the polynomial f with a, where a is an element in the coefficient ring of the parent of f.

func (*Element) ScalarMultiplyByInt64

func (f *Element) ScalarMultiplyByInt64(n int64) *Element

ScalarMultiplyByInt64 returns the scalar multiple n * f of the polynomial f with the integer n, where this is defined to be f + ... + f (n times) if n is positive, -f - ... - f (|n| times) if n is negative, and 0 if n is zero.

func (*Element) ScalarMultiplyByInteger

func (f *Element) ScalarMultiplyByInteger(n *integer.Element) *Element

ScalarMultiplyByInteger returns the scalar multiple n * f of the polynomial f with the integer n, where this is defined to be f + ... + f (n times) if n is positive, -f - ... - f (|n| times) if n is negative, and 0 if n is zero.

func (*Element) String

func (f *Element) String() string

String returns a string representation of the polynomial f.

func (*Element) Terms

func (f *Element) Terms() []*Element

Terms returns the non-zero terms of the polynomial f, sorted in increasing exponent order.

func (*Element) Valuation

func (f *Element) Valuation() (*integervector.Element, error)

Valuation returns the exponent of the smallest non-zero term of the non-zero polynomial f. This is returned as an element of the exponent monoid of the parent polynomial ring.

type Parent

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

Parent describes a polynomial ring with integer coefficients.

func DefaultRing

func DefaultRing(rk int, order monomialorder.Type) (*Parent, error)

DefaultRing returns the default polynomial ring over ZZ of given rank and monomial order.

func DefaultUnivariateRing

func DefaultUnivariateRing() *Parent

DefaultUnivariateRing returns the default univariate polynomial ring over ZZ.

func NewRing

func NewRing(rk int, order monomialorder.Type) (*Parent, error)

NewRing returns a new polynomial ring over ZZ of given rank and monomial order.

func NewUnivariateRing

func NewUnivariateRing() *Parent

NewUnivariateRing returns a new univariate polynomial ring over ZZ.

func (*Parent) Add

Add returns the sum f + g of the polynomials f and g in the ring R.

func (*Parent) AreEqual

func (R *Parent) AreEqual(f object.Element, g object.Element) (bool, error)

AreEqual returns true iff f and g are both contained in the polynomial ring R, and f = g.

func (*Parent) AssignName

func (R *Parent) AssignName(name string)

AssignName assigns a name to the polynomial ring R to be used in printing.

func (*Parent) AssignVariableName

func (R *Parent) AssignVariableName(name string, i int) error

AssignVariableName assigns a name to the i-th variable of the polynomial ring R to be used in printing. The variables are indexed from 0 up to rank - 1 (inclusive).

func (*Parent) CmpLeadingMonomial

func (R *Parent) CmpLeadingMonomial(f object.Element, g object.Element) (int, error)

CmpLeadingMonomial returns -1 if LM(f) < LM(g), 0 if LM(f) = LM(g), and +1 if LM(f) > LM(g), were LM denotes the leading monomial, and f and g are non-zero {{polynomials}}s in the ring R.

func (*Parent) Coefficient

func (R *Parent) Coefficient(f object.Element, m object.Element) (object.Element, error)

Coefficient returns the coefficient of the degree m term of the polynomial f, where m is an element of the exponent monoid of R. The returned coefficient will live in the coefficient ring of R.

func (*Parent) CoefficientRing

func (R *Parent) CoefficientRing() ring.Interface

CoefficientRing returns the ring of coefficients of the polynomial ring R.

func (*Parent) Coefficients

func (R *Parent) Coefficients(f object.Element) ([]object.Element, error)

Coefficients returns a slice of coefficient of the polynomial f. Only the non-zero coefficient will be returned, hence the zero polynomial returns an empty slice. The returned coefficients will live in the coefficient ring of R.

func (*Parent) CoefficientsAndExponents

func (R *Parent) CoefficientsAndExponents(f object.Element) (cs []object.Element, es []object.Element, err error)

CoefficientsAndExponents returns two parallel slices of coefficients cs and exponents es of the polynomial f. Only the non-zero coefficient will be returned, hence the zero polynomial returns as pair of empty slice. The returned coefficients cs will live in the coefficient ring of R. The returned exponents es will live in the exponent monoid of R, and are sorted in increasing order.

func (*Parent) ConstantCoefficient

func (R *Parent) ConstantCoefficient(f object.Element) (object.Element, error)

ConstantCoefficient returns the constant coefficient of the polynomial f. The returned coefficient will live in the coefficient ring of R.

func (*Parent) Contains

func (R *Parent) Contains(f object.Element) bool

Contains returns true iff f is a polynomial in the ring R, or can naturally be regarded as such. Note that we do not allow a natural isomorphism between two different polynomial rings.

func (*Parent) Degree

func (R *Parent) Degree(f object.Element) (object.Element, error)

Degree returns the degree of the non-zero polynomial f. The returned exponent will live in the exponent monoid of R.

func (*Parent) Derivative

func (R *Parent) Derivative(f object.Element, k int) (object.Element, error)

Derivative returns the formal partial derivative df/dx_k of the polynomial f. Here the variables x_i are indexed from 0 to rk-1 (inclusive), where rk is the rank of the exponent monoid of R.

func (*Parent) ExponentMonoid

func (R *Parent) ExponentMonoid() polynomial.ExponentMonoid

ExponentMonoid returns the monoid of exponents of the polynomial ring R.

func (*Parent) Exponents

func (R *Parent) Exponents(f object.Element) ([]object.Element, error)

Exponents returns a slice of exponents of the polynomial f. Only the exponents corresponding to terms with non-zero coefficient will be returned, hence the zero polynomial returns an empty slice. The returned exponents will live in the exponent monoid of R, and are sorted in increasing order.

func (*Parent) FromParallelSlices

func (R *Parent) FromParallelSlices(cs []object.Element, es []object.Element) (*Element, error)

FromParallelSlices returns a polynomial in the polynomial ring R, with parallel slices of coefficients cs and exponents es. The coefficients should lie in the coefficient ring of R, and the exponents should lie in the exponents ring of R.

func (*Parent) IsConstant

func (R *Parent) IsConstant(f object.Element) (bool, object.Element, error)

IsConstant returns true iff f is a constant polynomial in the polynomial ring R. If true, also returns the constant (as an element in the coefficient ring of R).

func (*Parent) IsMonic

func (R *Parent) IsMonic(f object.Element) (bool, error)

IsMonic returns true iff f is a monic polynomial (that is, if the leading coefficient of f is 1).

func (*Parent) IsMonomial

func (R *Parent) IsMonomial(f object.Element) (bool, error)

IsMonomial returns true iff the polynomial f is a monomial (that is, if f is of the form x^m for some m in the exponent monoid of R).

func (*Parent) IsNthVariable

func (R *Parent) IsNthVariable(f object.Element, n int) (bool, error)

IsNthVariable returns true iff the polynomial f is the n-th variable x_n in the polynomial ring R. Here variables are indexed from 0 to rk-1 (inclusive), where rk is the rank of R.

func (*Parent) IsOne

func (R *Parent) IsOne(f object.Element) (bool, error)

IsOne returns true iff f is the constant polynomial 1 in the polynomial ring R.

func (*Parent) IsTerm

func (R *Parent) IsTerm(f object.Element) (bool, error)

IsTerm returns true iff the polynomial f is a term (that is, if f is of the form c * x^n for some c in the coefficient ring of R and m in the exponent monoid of R).

func (*Parent) IsZero

func (R *Parent) IsZero(f object.Element) (bool, error)

IsZero returns true iff f is the zero element in the polynomial ring R.

func (*Parent) LeadingCoefficient

func (R *Parent) LeadingCoefficient(f object.Element) (object.Element, error)

LeadingCoefficient returns the leading coefficient of the polynomial f. The returned coefficient will live in the coefficient ring of R.

func (*Parent) LeadingMonomial

func (R *Parent) LeadingMonomial(f object.Element) (object.Element, error)

LeadingMonomial returns the leading monomial of the non-zero polynomial f.

func (*Parent) LeadingTerm

func (R *Parent) LeadingTerm(f object.Element) (object.Element, error)

LeadingTerm returns the leading term of the polynomial f.

func (*Parent) Multiply

func (R *Parent) Multiply(f object.Element, g object.Element) (object.Element, error)

Multiply returns the product f * g of the polynomials f and g in the polynomial ring R.

func (*Parent) Negate

func (R *Parent) Negate(f object.Element) (object.Element, error)

Negate returns -f, where f is a polynomial in the ring R.

func (*Parent) NthDerivative

func (R *Parent) NthDerivative(f object.Element, k int, n int) (object.Element, error)

NthDerivative returns the n-th formal partial derivative d^nf/dx_k^n of the polynomial f, where n is a non-negative integer. Here the variables x_i are indexed from 0 to rk-1 (inclusive), where rk is the rank of the exponent monoid of R.

func (*Parent) NthVariable

func (R *Parent) NthVariable(n int) (*Element, error)

NthVariable returns the n-th variable x_n in the polynomial ring R. Here variables are indexed from 0 to rk-1 (inclusive), where rk is the rank of R.

func (*Parent) One

func (R *Parent) One() object.Element

One returns the constant polynomial 1 of the polynomial ring R.

func (*Parent) Power

func (R *Parent) Power(f object.Element, k *integer.Element) (object.Element, error)

Power returns f^k, where k is a non-negative integer and f is a polynomial in the ring R.

func (*Parent) ScalarMultiplyByCoefficient

func (R *Parent) ScalarMultiplyByCoefficient(c object.Element, f object.Element) (object.Element, error)

ScalarMultiplyByCoefficient returns the product c * f, where c is an element in the coefficient ring of R, and f is an element of the polynomial ring R.

func (*Parent) ScalarMultiplyByInteger

func (R *Parent) ScalarMultiplyByInteger(c *integer.Element, f object.Element) (object.Element, error)

ScalarMultiplyByInteger returns c * f, where this is defined to be f + ... + f (c times) if c is positive, -f - ... - f (|c| times) if c is negative, and 0 if c is zero. Here f is an element of the polynomial ring R.

func (*Parent) String

func (R *Parent) String() string

String returns a string representation of the polynomial ring R.

func (*Parent) Subtract

func (R *Parent) Subtract(f object.Element, g object.Element) (object.Element, error)

Subtract returns the difference f - g of the polynomials f and g in the ring R.

func (*Parent) Sum

func (R *Parent) Sum(S ...object.Element) (object.Element, error)

Sum returns the sum of the polynomials in the slice S. All polynomials must have the same parent R. If S is empty, the zero element in the polynomial ring R is returned.

func (*Parent) Terms

func (R *Parent) Terms(f object.Element) ([]object.Element, error)

Terms returns the non-zero terms of the polynomial f, sorted in increasing exponent order.

func (*Parent) ToElement

func (R *Parent) ToElement(f object.Element) (object.Element, error)

ToElement returns f as an element in the polynomial ring R, or an error if f cannot naturally be regarded as an element of R.

func (*Parent) ToMonomial

func (R *Parent) ToMonomial(m object.Element) (object.Element, error)

ToMonomial returns the monomial x^m in the polynomial ring R, where m lies in the exponent monoid of R.

func (*Parent) ToTerm

func (R *Parent) ToTerm(c object.Element, m object.Element) (object.Element, error)

ToTerm returns the term c * x^m in the polynomial ring R, where c lies in the coefficient ring of R and m lies in the exponent monoid of R.

func (*Parent) Valuation

func (R *Parent) Valuation(f object.Element) (object.Element, error)

Valuation returns the exponent of the smallest non-zero term of the non-zero polynomial f. This is returned as an element of the exponent monoid of R.

func (*Parent) VariableName

func (R *Parent) VariableName(i int) (string, error)

VariableName returns the name to be used in printing of the i-th variable of the polynomial ring R. The variables are indexed from 0 up to rank - 1 (inclusive).

func (*Parent) Variables

func (R *Parent) Variables() []object.Element

Variables returns the variables x_0,...,x_k of the polynomial ring R, where k+1 is equal to the rank of R.

func (*Parent) Zero

func (R *Parent) Zero() object.Element

Zero returns the zero element of the polynomial ring R.

Jump to

Keyboard shortcuts

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