Documentation
¶
Overview ¶
Package groebner implements exact computer algebra over sparse multivariate polynomials with rational coefficients (math/big.Rat).
The package provides a full toolkit for ideal theory in the polynomial ring Q[x_1, ..., x_n]: monomials as integer exponent vectors, configurable monomial orders (lexicographic, graded lexicographic, graded reverse lexicographic, weighted and block/elimination orders), polynomial arithmetic (addition, subtraction, multiplication, powers, scalar and monomial multiplication), evaluation over the rationals and over the complex numbers, formal derivatives, multivariate division with remainder, S-polynomials, and Buchberger's algorithm (with the coprime-leading-term and chain criteria) for computing Gröbner bases.
On top of Gröbner bases the package computes reduced and minimal Gröbner bases, decides ideal membership, and performs the standard ideal operations: sum, product, intersection, quotient (colon ideal), and elimination ideals. For zero-dimensional systems it can decide finiteness of the variety and numerically approximate all complex solutions by triangular back-solving combined with a self-contained Durand–Kerner univariate root finder.
All arithmetic on coefficients is exact. Only the numerical variety solver works with floating point (complex128) and it takes a caller-supplied random seed so results are reproducible.
Index ¶
- Variables
- func CloneRat(r *big.Rat) *big.Rat
- func CompareGrevlex(a, b Monomial) int
- func CompareGrlex(a, b Monomial) int
- func CompareLex(a, b Monomial) int
- func Divides(g, f Poly, o Order) bool
- func InIdeal(f Poly, gens []Poly, o Order) bool
- func IsGroebnerBasis(g []Poly, o Order) bool
- func IsReducible(f Poly, divisors []Poly, o Order) bool
- func MonomialLess(o Order, a, b Monomial) bool
- func NewRat(a, b int64) *big.Rat
- func RatFromInt(a int64) *big.Rat
- func RatFromString(s string) (*big.Rat, bool)
- func RatIsOne(r *big.Rat) bool
- func RatIsZero(r *big.Rat) bool
- func RatToFloat(r *big.Rat) float64
- func RealSolutions(sols [][]complex128, imagTol float64) [][]float64
- func SolveUnivariate(coeffs []complex128, seed int64) []complex128
- func SolveZeroDimensional(gens []Poly, seed int64, tol float64) ([][]complex128, error)
- type DivisionResult
- type Ideal
- func (id Ideal) Contains(f Poly) bool
- func (id Ideal) Eliminate(k int) Ideal
- func (id Ideal) Equal(other Ideal) bool
- func (id Ideal) Generators() []Poly
- func (id Ideal) GroebnerBasis() []Poly
- func (id Ideal) Intersect(other Ideal) Ideal
- func (id Ideal) IsUnit() bool
- func (id Ideal) IsZero() bool
- func (id Ideal) IsZeroDimensional() bool
- func (id Ideal) Nvars() int
- func (id Ideal) Order() Order
- func (id Ideal) Product(other Ideal) Ideal
- func (id Ideal) Quotient(other Ideal) Ideal
- func (id Ideal) QuotientBasis() ([]Monomial, bool)
- func (id Ideal) QuotientElem(h Poly) Ideal
- func (id Ideal) ReducedGroebnerBasis() []Poly
- func (id Ideal) Solve(seed int64, tol float64) ([][]complex128, error)
- func (id Ideal) Sum(other Ideal) Ideal
- func (id Ideal) VectorSpaceDimension() (int, bool)
- func (id Ideal) WithOrder(o Order) Ideal
- type Monomial
- func (m Monomial) Clone() Monomial
- func (m Monomial) Coprime(o Monomial) bool
- func (m Monomial) Degree() int
- func (m Monomial) Div(o Monomial) (Monomial, bool)
- func (m Monomial) Divides(o Monomial) bool
- func (m Monomial) Equal(o Monomial) bool
- func (m Monomial) Exp(i int) int
- func (m Monomial) Format(vars []string) string
- func (m Monomial) GCD(o Monomial) Monomial
- func (m Monomial) IsConstant() bool
- func (m Monomial) LCM(o Monomial) Monomial
- func (m Monomial) Max(o Monomial) Monomial
- func (m Monomial) Mul(o Monomial) Monomial
- func (m Monomial) Nvars() int
- func (m Monomial) Pow(k int) Monomial
- func (m Monomial) String() string
- func (m Monomial) Support() []int
- func (m Monomial) TotalDegree() int
- type Order
- type Poly
- func AddSlice(n int, ps []Poly) Poly
- func Buchberger(gens []Poly, o Order) []Poly
- func Constant(n int, c *big.Rat) Poly
- func ConstantInt(n int, c int64) Poly
- func DivideOne(f, g Poly, o Order) (quotient, remainder Poly)
- func EliminationIdeal(gens []Poly, k int, o Order) []Poly
- func ExactQuotient(f, g Poly, o Order) (Poly, bool)
- func FromTerm(n int, t Term) Poly
- func GroebnerBasis(gens []Poly, o Order) []Poly
- func MinimalGroebnerBasis(g []Poly, o Order) []Poly
- func MonomialPoly(n int, m Monomial) Poly
- func NewPoly(n int, terms ...Term) Poly
- func NormalForm(f Poly, g []Poly, o Order) Poly
- func One(n int) Poly
- func ReducedGroebnerBasis(gens []Poly, o Order) []Poly
- func Remainder(f Poly, divisors []Poly, o Order) Poly
- func SPolynomial(f, g Poly, o Order) Poly
- func Var(n, i int) Poly
- func Vars(n int) []Poly
- func Zero(n int) Poly
- func (p Poly) Add(o Poly) Poly
- func (p Poly) Clone() Poly
- func (p Poly) Coeff(m Monomial) *big.Rat
- func (p Poly) Coefficients() []*big.Rat
- func (p Poly) ConstantTerm() *big.Rat
- func (p Poly) DegreeIn(i int) int
- func (p Poly) DependsOn(i int) bool
- func (p Poly) Derivative(i int) Poly
- func (p Poly) Equal(o Poly) bool
- func (p Poly) Eval(point []*big.Rat) *big.Rat
- func (p Poly) EvalComplex(point []complex128) complex128
- func (p Poly) EvalComplexAbs(point []complex128) float64
- func (p Poly) Format(vars []string) string
- func (p Poly) IsConstant() bool
- func (p Poly) IsOne() bool
- func (p Poly) IsZero() bool
- func (p Poly) LeadingCoeff(o Order) *big.Rat
- func (p Poly) LeadingMonomial(o Order) Monomial
- func (p Poly) LeadingTerm(o Order) Term
- func (p Poly) Len() int
- func (p Poly) Monic(o Order) Poly
- func (p Poly) Monomials() []Monomial
- func (p Poly) Mul(o Poly) Poly
- func (p Poly) MulMonomial(m Monomial) Poly
- func (p Poly) MulTerm(t Term) Poly
- func (p Poly) Multidegree(o Order) Monomial
- func (p Poly) Neg() Poly
- func (p Poly) Nvars() int
- func (p Poly) Pow(k int) Poly
- func (p Poly) ScalarMul(c *big.Rat) Poly
- func (p Poly) String() string
- func (p Poly) Sub(o Poly) Poly
- func (p Poly) Subst(i int, val *big.Rat) Poly
- func (p Poly) Terms() []Term
- func (p Poly) TotalDegree() int
- func (p Poly) UsedVars() []int
- type Ring
- func (r Ring) Constant(c *big.Rat) Poly
- func (r Ring) ConstantInt(c int64) Poly
- func (r Ring) Divide(f Poly, divisors []Poly) DivisionResult
- func (r Ring) Format(p Poly) string
- func (r Ring) GroebnerBasis(gens []Poly) []Poly
- func (r Ring) Ideal(gens ...Poly) Ideal
- func (r Ring) LeadingTerm(p Poly) Term
- func (r Ring) Names() []string
- func (r Ring) Nvars() int
- func (r Ring) One() Poly
- func (r Ring) Order() Order
- func (r Ring) Remainder(f Poly, divisors []Poly) Poly
- func (r Ring) SPolynomial(f, g Poly) Poly
- func (r Ring) Var(i int) Poly
- func (r Ring) Vars() []Poly
- func (r Ring) WithOrder(o Order) Ring
- func (r Ring) Zero() Poly
- type Term
- func (t Term) Clone() Term
- func (t Term) Degree() int
- func (t Term) Div(o Term) (Term, bool)
- func (t Term) Divides(o Term) bool
- func (t Term) Equal(o Term) bool
- func (t Term) Format(vars []string) string
- func (t Term) IsZero() bool
- func (t Term) Mul(o Term) Term
- func (t Term) Neg() Term
- func (t Term) String() string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotZeroDimensional = errors.New("groebner: system is not zero-dimensional")
ErrNotZeroDimensional is returned by the variety solver when the ideal has infinitely many solutions (positive-dimensional) and cannot be solved by finite back-substitution.
Functions ¶
func CompareGrevlex ¶
CompareGrevlex compares two monomials by the graded reverse lexicographic order: first by total degree, breaking ties by the reverse lexicographic rule (the monomial with the smaller exponent in the last variable where they differ is greater).
func CompareGrlex ¶
CompareGrlex compares two monomials by the graded lexicographic order: first by total degree, breaking ties with the lexicographic order.
func CompareLex ¶
CompareLex compares two monomials by the lexicographic order: the monomial with the larger exponent in the first variable where they differ is greater.
func Divides ¶
Divides reports whether g divides f exactly (the remainder of f divided by g is zero) with respect to the order o.
func InIdeal ¶
InIdeal reports whether f belongs to the ideal generated by gens, by checking that its normal form modulo a Gröbner basis is zero.
Example ¶
x := Var(2, 0)
y := Var(2, 1)
gens := []Poly{x.Mul(x).Sub(y), x.Mul(y).Sub(x)}
// x^2*y - y^2 = y*(x^2 - y) is in the ideal.
f := x.Mul(x).Mul(y).Sub(y.Mul(y))
fmt.Println(InIdeal(f, gens, GrevlexOrder()))
Output: true
func IsGroebnerBasis ¶
IsGroebnerBasis reports whether the set g is a Gröbner basis with respect to o, by verifying that every S-polynomial reduces to zero modulo g (Buchberger's criterion).
func IsReducible ¶
IsReducible reports whether some monomial of f is divisible by the leading monomial of one of the divisors, i.e. whether a division step is possible.
func MonomialLess ¶
MonomialLess reports whether a is strictly smaller than b under the order o.
func NewRat ¶
NewRat returns the rational number a/b as a *big.Rat. It panics only if b is zero, matching the behaviour of big.NewRat.
func RatFromString ¶
RatFromString parses a rational number from its decimal or fractional string representation (for example "3/4", "-2", or "1.5"). The boolean result is false when the string cannot be parsed.
func RatToFloat ¶
RatToFloat returns the nearest float64 to the rational r.
func RealSolutions ¶
func RealSolutions(sols [][]complex128, imagTol float64) [][]float64
RealSolutions filters a set of complex solutions, returning the real parts of those solutions whose imaginary parts are all below the tolerance imagTol.
func SolveUnivariate ¶
func SolveUnivariate(coeffs []complex128, seed int64) []complex128
SolveUnivariate returns the complex roots of a univariate polynomial given by its coefficient slice, where coeffs[k] is the coefficient of x^k. It uses the Durand–Kerner (Weierstrass) iteration seeded by the supplied random seed so results are reproducible. Trailing (high-degree) near-zero coefficients are dropped. A constant nonzero polynomial has no roots; the zero polynomial returns no roots as well.
func SolveZeroDimensional ¶
func SolveZeroDimensional(gens []Poly, seed int64, tol float64) ([][]complex128, error)
SolveZeroDimensional numerically approximates all complex solutions of the zero-dimensional system defined by gens. It computes a lexicographic Gröbner basis (which for a zero-dimensional ideal has triangular shape), solves the univariate polynomial in the last variable, and back-substitutes recursively. Candidate tuples are verified against every generator within the given tolerance. The seed makes the underlying root finder reproducible. It returns ErrNotZeroDimensional if the system has infinitely many solutions and the unit ideal (no solutions) yields an empty slice.
Types ¶
type DivisionResult ¶
DivisionResult holds the outcome of multivariate division of a dividend by an ordered list of divisors: the quotient polynomials (one per divisor) and the remainder.
func MultivariateDivide ¶
func MultivariateDivide(f Poly, divisors []Poly, o Order) DivisionResult
MultivariateDivide performs the multivariate division algorithm, dividing f by the ordered list of divisors with respect to the monomial order o. It returns quotients q_i and a remainder r such that
f = q_1*g_1 + ... + q_s*g_s + r,
where no monomial of r is divisible by the leading monomial of any divisor. The result depends on the order of the divisors. Zero divisors are skipped.
type Ideal ¶
type Ideal struct {
// contains filtered or unexported fields
}
Ideal represents a polynomial ideal by a list of generators in a fixed number of variables together with a default monomial order used by its methods.
func NewIdeal ¶
NewIdeal builds the ideal generated by gens with the given default monomial order. The number of variables is taken from the first generator; if gens is empty the ideal is the zero ideal in zero variables (callers usually supply at least one generator).
func NewIdealN ¶
NewIdealN builds the ideal generated by gens in n variables with order o, allowing an explicit variable count (needed for the zero ideal).
func (Ideal) Eliminate ¶
Eliminate returns the elimination ideal obtained by eliminating the first k variables, i.e. I ∩ Q[x_{k+1}, ..., x_n], still embedded in the original ring (the eliminated variables simply do not occur). It uses an elimination order.
func (Ideal) Equal ¶
Equal reports whether two ideals are equal, by comparing their reduced Gröbner bases under a common order (the receiver's order).
func (Ideal) Generators ¶
Generators returns a copy of the ideal's generating set.
func (Ideal) GroebnerBasis ¶
GroebnerBasis returns a (reduced) Gröbner basis of the ideal with respect to its default order.
func (Ideal) Intersect ¶
Intersect returns the ideal intersection I ∩ J. It uses the standard elimination construction: in a ring with one extra variable t it forms the ideal generated by t*f_i and (1-t)*g_j and eliminates t.
func (Ideal) IsUnit ¶
IsUnit reports whether the ideal is the whole ring, i.e. it contains the constant 1 (equivalently its reduced Gröbner basis is {1}).
func (Ideal) IsZeroDimensional ¶
IsZeroDimensional reports whether the ideal is zero-dimensional, i.e. the quotient ring is a finite-dimensional vector space over Q, equivalently the variety over the algebraic closure is finite. It checks that for every variable some leading monomial of the reduced Gröbner basis is a pure power of that variable. The unit ideal (empty variety) is considered zero-dimensional.
func (Ideal) Product ¶
Product returns the ideal product I*J, generated by all pairwise products of generators. It uses the receiver's order.
func (Ideal) Quotient ¶
Quotient returns the ideal quotient (colon ideal) I : J = { f : f*J ⊆ I }. It is computed as the intersection over the generators g of J of the single quotients I : (g).
func (Ideal) QuotientBasis ¶
QuotientBasis returns a monomial basis of the quotient ring Q[x]/I as a Q-vector space, valid when the ideal is zero-dimensional. These are exactly the standard monomials: the monomials not divisible by any leading monomial of the Gröbner basis. The boolean result is false when the ideal is not zero-dimensional.
func (Ideal) QuotientElem ¶
QuotientElem returns the ideal quotient I : (h) for a single polynomial h, using the identity h*(I:h) = I ∩ (h): it intersects I with the principal ideal (h) and divides each resulting generator by h.
func (Ideal) ReducedGroebnerBasis ¶
ReducedGroebnerBasis returns the canonical reduced Gröbner basis of the ideal.
func (Ideal) Solve ¶
func (id Ideal) Solve(seed int64, tol float64) ([][]complex128, error)
Solve numerically approximates all complex solutions of the ideal's variety, assuming the ideal is zero-dimensional. It is a convenience wrapper around SolveZeroDimensional using the ideal's generators.
func (Ideal) Sum ¶
Sum returns the ideal sum I + J, generated by the union of the two generating sets. It uses the receiver's order.
func (Ideal) VectorSpaceDimension ¶
VectorSpaceDimension returns the dimension of Q[x]/I as a Q-vector space for a zero-dimensional ideal, equal to the number of solutions counted with multiplicity over the algebraic closure. The boolean result is false when the ideal is not zero-dimensional.
type Monomial ¶
type Monomial []int
Monomial represents a power product x_1^e_1 * ... * x_n^e_n as its vector of non-negative integer exponents. The length of the slice is the number of variables in the ambient polynomial ring.
func MonomialMax ¶
MonomialMax returns whichever of a and b is larger under the order o.
func NewMonomial ¶
NewMonomial returns a copy of the given exponent vector as a Monomial. The input is not retained.
func VarMonomial ¶
VarMonomial returns the monomial x_i (the i-th variable to the first power) in a ring with n variables. It panics only if i is out of range.
func ZeroMonomial ¶
ZeroMonomial returns the constant monomial 1 in n variables, i.e. the vector of n zero exponents.
func (Monomial) Coprime ¶
Coprime reports whether two monomials have disjoint support, i.e. their GCD is 1. This is the condition used by Buchberger's first (coprime) criterion.
func (Monomial) Div ¶
Div returns the quotient o/m when m divides o. The boolean result is false (and the returned monomial nil) when the division is not exact.
func (Monomial) Divides ¶
Divides reports whether m divides o, i.e. every exponent of m is at most the corresponding exponent of o.
func (Monomial) Format ¶
Format renders the monomial using the supplied variable names. The constant monomial is rendered as "1".
func (Monomial) GCD ¶
GCD returns the greatest common divisor of two monomials, taking the componentwise minimum of the exponents.
func (Monomial) IsConstant ¶
IsConstant reports whether the monomial equals 1, i.e. every exponent is zero.
func (Monomial) LCM ¶
LCM returns the least common multiple of two monomials, taking the componentwise maximum of the exponents.
func (Monomial) Max ¶
Max returns the componentwise maximum of two monomials (identical to LCM); it is provided as a descriptive name for exponent-vector joins.
func (Monomial) Mul ¶
Mul returns the product of two monomials, obtained by adding exponents componentwise.
func (Monomial) Pow ¶
Pow returns the monomial raised to a non-negative integer power, multiplying every exponent by k.
func (Monomial) Support ¶
Support returns the sorted indices of variables that appear with a positive exponent in the monomial.
func (Monomial) TotalDegree ¶
TotalDegree is an alias for Degree, the sum of all exponents.
type Order ¶
Order is a monomial ordering: a function that compares two monomials and returns -1 if a < b, 0 if a == b, and +1 if a > b. A valid monomial order is a total order that is multiplicative and for which 1 is the smallest monomial. All monomials passed to an Order are assumed to have the same number of variables.
func BlockOrder ¶
BlockOrder returns the product (block) order that compares the first sep variables using first and, on a tie, compares the remaining variables using second. Monomials involving any of the first sep variables are larger than those that do not, so BlockOrder eliminates the first sep variables.
func EliminationOrder ¶
EliminationOrder returns a monomial order suitable for eliminating the first sep variables from an ideal. It is a block order using graded reverse lexicographic within each block. The elements of a Gröbner basis with respect to this order that do not involve the first sep variables generate the corresponding elimination ideal.
func GrevlexOrder ¶
func GrevlexOrder() Order
GrevlexOrder is the graded reverse lexicographic monomial order, generally the most efficient order for Gröbner basis computation.
func LexOrder ¶
func LexOrder() Order
LexOrder is the lexicographic monomial order. It is an elimination order: the first variables dominate.
func ReverseOrder ¶
ReverseOrder returns the order obtained by reversing the given order. Note that the reverse of a monomial order is generally not itself a monomial order; this helper is intended for sorting and diagnostics.
func WeightOrder ¶
WeightOrder returns a monomial order that first compares the dot product of the exponent vectors with the given non-negative integer weights, breaking ties with the supplied tie order. For a strictly positive weight vector any tie order yields a genuine monomial order.
type Poly ¶
type Poly struct {
// contains filtered or unexported fields
}
Poly is a sparse multivariate polynomial with rational coefficients over a fixed number of variables. Internally the terms are kept in a canonical form: combined like terms, no zero coefficients, and sorted in descending lexicographic order of their monomials. This canonical form makes structural equality a simple term-by-term comparison; the leading term with respect to a particular monomial order is computed on demand.
func Buchberger ¶
Buchberger computes a Gröbner basis of the ideal generated by gens with respect to the monomial order o, using Buchberger's algorithm with the coprime-leading-term criterion to discard trivial S-pairs. The returned basis is not necessarily reduced; use ReducedGroebnerBasis for the canonical form. Zero generators are ignored, and the empty generating set yields an empty basis.
func ConstantInt ¶
ConstantInt returns the constant polynomial equal to the integer c.
func DivideOne ¶
DivideOne divides f by a single polynomial g and returns the quotient and remainder with respect to o.
func EliminationIdeal ¶
EliminationIdeal is the free-function form of Eliminate: it returns generators of the k-th elimination ideal of the given generators.
func ExactQuotient ¶
ExactQuotient returns f/g when g divides f exactly. The boolean result is false when the division leaves a nonzero remainder.
func GroebnerBasis ¶
GroebnerBasis is a convenience wrapper that returns the reduced Gröbner basis of the given generators with respect to o.
func MinimalGroebnerBasis ¶
MinimalGroebnerBasis returns a minimal Gröbner basis obtained from g by making every element monic and discarding any element whose leading monomial is divisible by the leading monomial of another element.
func MonomialPoly ¶
Monomial returns the polynomial consisting of a single monomial m with coefficient 1.
func NewPoly ¶
NewPoly builds a polynomial in n variables from the given terms, reducing it to canonical form. Terms with mismatched arity are padded or truncated to n variables.
func NormalForm ¶
NormalForm returns the normal form (unique remainder) of f modulo the ideal with Gröbner basis g under the order o. Two polynomials are congruent modulo the ideal if and only if they have the same normal form.
func ReducedGroebnerBasis ¶
ReducedGroebnerBasis returns the unique reduced Gröbner basis of the ideal generated by gens with respect to o. Each element is monic and no monomial of any element is divisible by the leading monomial of any other. The basis is sorted in descending order of leading monomial, making it a canonical representative of the ideal.
Example ¶
// Compute the reduced Gröbner basis of <x^2 + y^2 - 1, x - y> under lex.
x := Var(2, 0)
y := Var(2, 1)
f := x.Mul(x).Add(y.Mul(y)).Sub(One(2))
g := x.Sub(y)
basis := ReducedGroebnerBasis([]Poly{f, g}, LexOrder())
for _, p := range basis {
fmt.Println(p)
}
Output: x1 - x2 x2^2 - 1/2
func Remainder ¶
Remainder returns just the remainder of dividing f by the divisors with respect to o. It is the normal form of f modulo the divisor list.
func SPolynomial ¶
SPolynomial returns the S-polynomial of f and g with respect to the order o:
S(f,g) = (L/LT(f))*f - (L/LT(g))*g,
where L is the least common multiple of the leading monomials of f and g. The S-polynomial cancels the leading terms and is the central object of Buchberger's algorithm. It returns the zero polynomial if either input is zero.
func (Poly) Coeff ¶
Coeff returns the coefficient of the monomial m in the polynomial, or 0 if it does not appear.
func (Poly) Coefficients ¶
Coefficients returns the coefficients of the polynomial in canonical order.
func (Poly) ConstantTerm ¶
ConstantTerm returns the constant coefficient of the polynomial.
func (Poly) DegreeIn ¶
DegreeIn returns the highest exponent of the i-th variable appearing in the polynomial, or 0 for the zero polynomial.
func (Poly) DependsOn ¶
DependsOn reports whether the i-th variable appears with a positive exponent in some term of the polynomial.
func (Poly) Derivative ¶
Derivative returns the formal partial derivative of the polynomial with respect to the i-th variable.
func (Poly) Eval ¶
Eval evaluates the polynomial at the rational point (one value per variable) and returns the exact rational result.
func (Poly) EvalComplex ¶
func (p Poly) EvalComplex(point []complex128) complex128
EvalComplex evaluates the polynomial at a complex point and returns the complex result. It is used by the numerical variety solver.
func (Poly) EvalComplexAbs ¶
func (p Poly) EvalComplexAbs(point []complex128) float64
EvalComplexAbs returns the magnitude |p(point)| of the complex evaluation, used to test whether a candidate solution satisfies the polynomial.
func (Poly) Format ¶
Format renders the polynomial with the supplied variable names, terms in descending lexicographic order. The zero polynomial renders as "0".
func (Poly) IsConstant ¶
IsConstant reports whether the polynomial is a constant (zero or a single term of degree 0).
func (Poly) LeadingCoeff ¶
LeadingCoeff returns the coefficient of the leading term with respect to o.
func (Poly) LeadingMonomial ¶
LeadingMonomial returns the monomial of the leading term with respect to o.
func (Poly) LeadingTerm ¶
LeadingTerm returns the term of the polynomial whose monomial is largest with respect to the order o. It returns the zero term for the zero polynomial.
func (Poly) Monic ¶
Monic returns the polynomial scaled so that its leading coefficient with respect to o is 1. The zero polynomial is returned unchanged.
func (Poly) MulMonomial ¶
MulMonomial returns the polynomial multiplied by the monomial m (coefficient 1).
func (Poly) Multidegree ¶
Multidegree returns the exponent vector of the leading monomial with respect to o.
func (Poly) Pow ¶
Pow returns the polynomial raised to the non-negative integer power k, using binary exponentiation. Pow(0) returns the constant 1.
func (Poly) Subst ¶
Subst substitutes the constant rational value val for the i-th variable and returns the resulting polynomial (still in n variables, with that variable eliminated from every term).
func (Poly) Terms ¶
Terms returns a copy of the polynomial's terms in canonical (descending lexicographic) order.
func (Poly) TotalDegree ¶
TotalDegree returns the maximum total degree among the polynomial's terms, or -1 for the zero polynomial.
type Ring ¶
type Ring struct {
// contains filtered or unexported fields
}
Ring bundles the number of variables, their display names, and a default monomial order. It offers convenient constructors and operations so that callers do not have to repeat the variable count and order everywhere.
func NewNamedRing ¶
NewNamedRing returns a ring whose variables carry the supplied names, in the given monomial order.
func NewRing ¶
NewRing returns a ring in n variables with the given monomial order and the default variable names x1, ..., xn.
func (Ring) ConstantInt ¶
ConstantInt returns the constant polynomial equal to the integer c.
func (Ring) Divide ¶
func (r Ring) Divide(f Poly, divisors []Poly) DivisionResult
Divide performs multivariate division under the ring's order.
func (Ring) GroebnerBasis ¶
GroebnerBasis returns the reduced Gröbner basis of the given generators under the ring's order.
func (Ring) LeadingTerm ¶
LeadingTerm returns the leading term of p under the ring's order.
func (Ring) Remainder ¶
Remainder returns the remainder of dividing f by the divisors under the ring's order.
func (Ring) SPolynomial ¶
SPolynomial returns the S-polynomial of f and g under the ring's order.
type Term ¶
Term is a single monomial with a rational coefficient, the building block of a polynomial.
func NewTerm ¶
NewTerm returns a term with the given coefficient and monomial. The coefficient is copied; the monomial is cloned.
func (Term) Div ¶
Div returns the quotient o/t as a term when the monomial of t divides that of o. The boolean result is false when the monomial division is not exact.
func (Term) Divides ¶
Divides reports whether term t divides term o, i.e. its monomial divides the monomial of o (coefficients are units in a field so are ignored).