bivariate

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2022 License: BSD-3-Clause Imports: 8 Imported by: 0

README

Go Report Card coverage-badge GoDoc

Algobra: Bivariate Polynomials

This package implements bivariate polynomials over prime fields.

Basic usage

To perform computations on bivariate polynomials, first define the finite field and the polynomial ring. Polynomials can then be constructed in several different ways.

field, _ := finitefield.Define(7)	// Ignoring errors in example
ring := bivariate.DefRing(field, bivariate.Lex(true))	// Use lex ordering with X>Y

// Define f = X^2Y + 6Y 
f := ring.PolynomialFromUnsigned(map[[2]uint]uint{
	{2,1}:	1,
	{0,3}:	6,
})

// The same polynomial can be defined from 
g := ring.PolynomialFromSigned(map[[2]uint]int{
	{2,1}:	1,
	{0,3}:	-1,
})

fmt.Println(f.Equal(g))	// Prints 'true'

In addition to the polynomial definition from maps as above, it is also possible to define polynomials from strings in a natural way by using PolynomialFromString. When doing so, each monomial can contain at most one of each variable. The order of the variables does not matter, and capitalization is ignored. Using * to indicate multiplication is optional. In addition, the parser supports Singular-style exponents, meaning that 5X2Y3 is interpreted as 5X^2Y^3.

Ideals

The package provides support for computations modulo an ideal.

// Let ring be defined as above
id, _ := ring.NewIdeal(
	ring.PolynomialFromString("X^49-X"),
	ring.PolynomialFromString("Y^7-X^8+Y"),
)
qRing, _ := ring.Quotient(id)

Once the quotient ring has been defined, polynomials are defined as before. For instance, h := qRing.PolynomialFromString("X^50") sets h to X^2 since the polynomial is automatically reduced modulo the ideal.

Internally, this is achieved by transforming the ideal such that its generators form a reduced Gröbner basis. Hence, calling Generators at a later point will not necessarily return the polynomials that were used to define the ideal.

Monomial orderings

The following monomial orderings are defined by default.

  • Lexicographical
  • Degree lexicographical
  • Degree reverse lexicographical
  • Weighted degree lexicographical
  • Weighted degree reverse lexicographical

Additional orderings can be defined by writing a function with signature func(deg1, deg2 [2]uint) int. For more information, see the documentation for the Order type.

Error handling

In order to allow method chaining for arithmetic operations – such as f.Plus(g).Mult(h.Inv()) – the methods themselves do not return errors. Instead, potential errors are tied to the resulting polynomial, and the error can be retrieved with the Err-method.

Documentation

Overview

Package bivariate implements bivariate polynomials over finite fields.

Basic usage

To perform computations on bivariate polynomials, first define the finite field and the polynomial ring. Polynomials can then be constructed in several different ways.

field, _ := finitefield.Define(7)    // Ignoring errors in example
ring := bivariate.DefRing(field, bivariate.Lex(true))   // Use lex ordering with X>Y

// Define f = X^2Y + 6Y
f := ring.PolynomialFromUnsigned(map[[2]uint]uint{
    {2,1}:  1,
    {0,3}:  6,
})

// The same polynomial can be defined from
g := ring.PolynomialFromSigned(map[[2]uint]int{
    {2,1}:  1,
    {0,3}:  -1,
})

fmt.Println(f.Equal(g)) // Prints 'true'

In addition to the polynomial definition from maps as above, it is also possible to define polynomials from strings in a natural way by using PolynomialFromString. When doing so, each monomial can contain at most one of each variable. The order of the variables does not matter, and capitalization is ignored. Using * to indicate multiplication is optional. In addition, the parser supports _Singular-style_ exponents, meaning that '5X2Y3' is interpreted as '5X^2Y^3'.

By default, the variable names 'X' and 'Y' are used, but this can be changed via the method SetVarNames. The current variable names can be obtained from the VarNames method.

Ideals

The package provides support for computations modulo an ideal.

// Let ring be defined as above
id, _ := ring.NewIdeal(
    ring.PolynomialFromString("X^49-X"),
    ring.PolynomialFromString("Y^7-X^8+Y"),
)
qRing, _ := ring.Quotient(id)

Once the quotient ring has been defined, polynomials are defined as before. For instance, h := qRing.PolynomialFromString("X^50") sets h to X^2 since the polynomial is automatically reduced modulo the ideal.

Internally, this is achieved by transforming the ideal such that its generators form a reduced Gröbner basis. Hence, calling Generators at a later point will not necessarily return the polynomials that were used to define the ideal.

Monomial orderings

The following monomial orderings are defined by default.

  • Lexicographical
  • Degree lexicographical
  • Degree reverse lexicographical
  • Weighted degree lexicographical
  • Weighted degree reverse lexicographical

Additional orderings can be defined by writing a function with signature func(deg1, deg2 [2]uint) int. For more information, see the documentation for the Order type.

Error handling

In order to allow method chaining for arithmetic operations -- such as f.Plus(g).Mult(h.Inv()) -- the methods themselves do not return errors. Instead, potential errors are tied to the resulting polynomial, and the error can be retrieved with the Err-method.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ideal

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

Ideal is the implementation of a polynomial ideal.

func (*Ideal) Copy

func (id *Ideal) Copy() *Ideal

Copy creates a copy of id.

func (*Ideal) Generators

func (id *Ideal) Generators() []*Polynomial

Generators returns a copy of the generators of id.

func (*Ideal) GroebnerBasis

func (id *Ideal) GroebnerBasis() *Ideal

GroebnerBasis computes a Gröbner basis for id. The result is returned as a new ideal object.

func (*Ideal) IsGroebner

func (id *Ideal) IsGroebner() (b bool)

IsGroebner returns a boolean describing whether the generators of id form a Gröbner basis.

func (*Ideal) IsMinimal

func (id *Ideal) IsMinimal() (b bool)

IsMinimal returns a boolean describing whether the generators of id form a minimal Gröbner basis.

Example
package main

import (
	"fmt"

	"github.com/ReneBoedker/algobra/bivariate"
	"github.com/ReneBoedker/algobra/finitefield"
	"github.com/ReneBoedker/algobra/finitefield/ff"
)

func main() {
	gf9, _ := finitefield.Define(9)
	ring := bivariate.DefRing(gf9, bivariate.WDegLex(3, 4, false))
	id, _ := ring.NewIdeal(
		ring.Polynomial(map[[2]uint]ff.Element{
			{0, 3}: gf9.One(),
			{4, 0}: gf9.One().SetNeg(),
			{0, 1}: gf9.One(),
		}),
		ring.Polynomial(map[[2]uint]ff.Element{
			{9, 0}: gf9.One(),
			{1, 0}: gf9.One().SetNeg(),
		}),
		ring.Polynomial(map[[2]uint]ff.Element{
			{0, 9}: gf9.One(),
			{0, 1}: gf9.One().SetNeg(),
		}),
	)

	fmt.Printf("%s is a Gröbner basis: %t\n", id.ShortString(), id.IsGroebner())
	fmt.Printf("%s is a minimal Gröbner basis: %t\n", id.ShortString(), id.IsMinimal())

	id.MinimizeBasis()
	fmt.Printf("%s is a minimal Gröbner basis: %t\n", id.ShortString(), id.IsMinimal())
}
Output:

<Y^3 + 2X^4 + Y, X^9 + 2X, Y^9 + 2Y> is a Gröbner basis: true
<Y^3 + 2X^4 + Y, X^9 + 2X, Y^9 + 2Y> is a minimal Gröbner basis: false
<Y^3 + 2X^4 + Y, X^9 + 2X> is a minimal Gröbner basis: true

func (*Ideal) IsReduced

func (id *Ideal) IsReduced() (b bool)

IsReduced returns a boolean describing whether the generators of id form a reduced Gröbner basis.

func (*Ideal) MinimizeBasis

func (id *Ideal) MinimizeBasis() error

MinimizeBasis transforms the generators of id into a minimal Gröbner basis.

If the generators of id do not form a Gröbner basis, the function returns an InputValue-error.

func (*Ideal) Reduce

func (id *Ideal) Reduce(f *Polynomial) error

Reduce sets f to f modulo id.

Note that when the generators of id do not form a Gröbner basis, such a basis will be computed. This alters the representation of id.

func (*Ideal) ReduceBasis

func (id *Ideal) ReduceBasis() error

ReduceBasis transforms the generators of id into a reduced Gröbner basis.

If the generators of id do not form a Gröbner basis, the function returns an InputValue-error.

func (*Ideal) ShortString

func (id *Ideal) ShortString() string

ShortString returns a short string description of id. More precisely, it returns the string representation of the generators.

Example
package main

import (
	"fmt"

	"github.com/ReneBoedker/algobra/bivariate"
	"github.com/ReneBoedker/algobra/finitefield"
	"github.com/ReneBoedker/algobra/finitefield/ff"
)

func main() {
	field, _ := finitefield.Define(7)
	ring := bivariate.DefRing(field, bivariate.Lex(true))

	id, _ := ring.NewIdeal(
		ring.Polynomial(map[[2]uint]ff.Element{
			{2, 0}: field.One(),
			{0, 1}: field.One(),
		}),
		ring.Polynomial(map[[2]uint]ff.Element{
			{2, 1}: field.One(),
			{0, 0}: field.One(),
		}),
	)

	fmt.Println(id.ShortString())
}
Output:

<X^2 + Y, X^2Y + 1>

func (*Ideal) String

func (id *Ideal) String() string

String returns the string representation of id. See also ShortString.

type Order

type Order func(deg1, deg2 [2]uint) int

Order denotes an order function.

Return value is meant to be interpreted in the following way:

-1: deg1 < deg2
 0: deg1 == deg2
 1: deg1 > deg2

By defining functions of type Order, additional monomial orders can be used.

func DegLex

func DegLex(xGtY bool) Order

DegLex returns the total degree lexicographical ordering.

The resulting order will first compare the total degree and then break any ties using the lexicographical ordering. The boolean xGtY indicates whether X is greater than Y.

func DegRevLex

func DegRevLex(xGtY bool) Order

DegRevLex returns the total degree reverse lexicographical ordering.

The resulting order will first compare the total degree and then break any ties using the lexicographical ordering. However, the smaller degree with respect to the lexicographical ordering is considered as the larger degree with respect to the reverse ordering. In addition, the order of the variables is reversed when performing the lexicographical comparison.

The boolean xGtY indicates whether X is greater than Y.

func Lex

func Lex(xGtY bool) Order

Lex returns the lexicographical ordering.

The boolean xGtY indicates whether X is greater than Y.

func WDegLex

func WDegLex(xWeight, yWeight uint, xGtY bool) Order

WDegLex returns the weighted degree lexicographical ordering.

The resulting order will first compare the weighted degree using the given weights. Then it will break any ties using the lexicographical ordering. The boolean xGtY indicates whether X is greater than Y.

func WDegRevLex

func WDegRevLex(xWeight, yWeight uint, xGtY bool) Order

WDegRevLex returns the weighted degree reverse lexicographical ordering.

The resulting order will first compare the weighted degree using the given weights. Then it will break any ties using the lexicographical ordering. However, the smaller degree with respect to the lexicographical ordering is considered as the larger degree with respect to the reverse ordering. In addition, the order of the variables is reversed when performing the lexicographical comparison.

The boolean xGtY indicates whether X is greater than Y.

type Polynomial

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

Polynomial implements bivariate polynomials.

func SPolynomial

func SPolynomial(f, g *Polynomial) (*Polynomial, error)

SPolynomial computes the S-polynomial of f and g.

It returns an ArithmeticIncompat-error if f and g are defined over different rings.

func (*Polynomial) Add

func (f *Polynomial) Add(g *Polynomial) *Polynomial

Add sets f to the sum of the two polynomials f and g and returns f.

If f and g are defined over different rings, a new polynomial is returned with an ArithmeticIncompat-error as error status.

When f or g has a non-nil error status, its error is wrapped and the same polynomial is returned.

func (*Polynomial) BaseField

func (f *Polynomial) BaseField() ff.Field

BaseField returns the field over which the coefficients of f are defined.

func (*Polynomial) Coef

func (f *Polynomial) Coef(deg [2]uint) ff.Element

Coef returns the coefficient of the monomial with degree specified by the input. The return value is a finite field element.

func (*Polynomial) Copy

func (f *Polynomial) Copy() *Polynomial

Copy returns a new polynomial object over the same ring and with the same coefficients as f.

func (*Polynomial) DecrementCoef

func (f *Polynomial) DecrementCoef(deg [2]uint, val ff.Element)

DecrementCoef decrements the coefficient of the monomial with degree deg in f by val.

func (*Polynomial) EmbedIn

func (f *Polynomial) EmbedIn(r *QuotientRing, reduce bool) error

EmbedIn embeds f in the ring r if possible. The input reduce determines if f is reduced in the new ring.

An InputIncompatible-error is returned if r and the polynomial ring of f are not compatible.

func (*Polynomial) Equal

func (f *Polynomial) Equal(g *Polynomial) bool

Equal determines whether two polynomials are equal. That is, whether they are defined over the same ring, and have the same coefficients.

func (*Polynomial) Err

func (f *Polynomial) Err() error

Err returns the error status of f.

func (*Polynomial) Eval

func (f *Polynomial) Eval(point [2]ff.Element) ff.Element

Eval evaluates f at the given point.

func (*Polynomial) IncrementCoef

func (f *Polynomial) IncrementCoef(deg [2]uint, val ff.Element)

IncrementCoef increments the coefficient of the monomial with degree deg in f by val.

func (*Polynomial) IsMonomial

func (f *Polynomial) IsMonomial() bool

IsMonomial returns a bool describing whether f consists of a single monomial.

func (*Polynomial) IsNonzero

func (f *Polynomial) IsNonzero() bool

IsNonzero determines whether f contains some monomial with nonzero coefficient.

func (*Polynomial) IsZero

func (f *Polynomial) IsZero() bool

IsZero determines whether f is the zero polynomial.

func (*Polynomial) Lc

func (f *Polynomial) Lc() ff.Element

Lc returns the leading coefficient of f.

Example
package main

import (
	"fmt"

	"github.com/ReneBoedker/algobra/bivariate"
	"github.com/ReneBoedker/algobra/finitefield"
)

func main() {
	gf9, _ := finitefield.Define(9)
	ring := bivariate.DefRing(gf9, bivariate.DegLex(true))
	f, _ := ring.PolynomialFromString("(a+2)X^4Y + aX^2Y^3 + Y^4 - 1")

	fmt.Println(f.Lc())
}
Output:

a + 2

func (*Polynomial) Ld

func (f *Polynomial) Ld() [2]uint

Ld returns the leading degree of f.

Example
package main

import (
	"fmt"

	"github.com/ReneBoedker/algobra/bivariate"
	"github.com/ReneBoedker/algobra/finitefield"
)

func main() {
	gf9, _ := finitefield.Define(9)
	ring := bivariate.DefRing(gf9, bivariate.DegLex(true))
	f, _ := ring.PolynomialFromString("(a+2)X^4Y + aX^2Y^3 + Y^4 - 1")

	fmt.Println(f.Ld())
}
Output:

[4 1]

func (*Polynomial) Lt

func (f *Polynomial) Lt() *Polynomial

Lt returns the leading term of f.

Example
package main

import (
	"fmt"

	"github.com/ReneBoedker/algobra/bivariate"
	"github.com/ReneBoedker/algobra/finitefield"
)

func main() {
	gf9, _ := finitefield.Define(9)
	ring := bivariate.DefRing(gf9, bivariate.DegLex(true))
	f, _ := ring.PolynomialFromString("(a+2)X^4Y + aX^2Y^3 + Y^4 - 1")

	fmt.Println(f.Lt())
}
Output:

(a + 2)X^4Y

func (*Polynomial) Minus

func (f *Polynomial) Minus(g *Polynomial) *Polynomial

Minus returns polynomial difference f-g.

If f and g are defined over different rings, a new polynomial is returned with an ArithmeticIncompat-error as error status.

When f or g has a non-nil error status, its error is wrapped and the same polynomial is returned.

func (*Polynomial) Mult

func (f *Polynomial) Mult(g *Polynomial) *Polynomial

Mult sets f to the product of the polynomials f and g and returns f.

If f and g are defined over different rings, a new polynomial is returned with an ArithmeticIncompat-error as error status.

When f or g has a non-nil error status, its error is wrapped and the same polynomial is returned.

func (*Polynomial) Neg

func (f *Polynomial) Neg() *Polynomial

Neg returns the polynomial obtained by scaling f by -1 (modulo the characteristic).

func (*Polynomial) Normalize

func (f *Polynomial) Normalize() *Polynomial

Normalize creates a new polynomial obtained by normalizing f. That is, f.Normalize() multiplied by f.Lc() is f.

If f is the zero polynomial, a copy of f is returned.

func (*Polynomial) Plus

func (f *Polynomial) Plus(g *Polynomial) *Polynomial

Plus returns the sum of the two polynomials f and g.

If f and g are defined over different rings, a new polynomial is returned with an ArithmeticIncompat-error as error status.

When f or g has a non-nil error status, its error is wrapped and the same polynomial is returned.

func (*Polynomial) Pow

func (f *Polynomial) Pow(n uint) *Polynomial

Pow raises f to the power of n.

If the computation causes the degree of f to overflow, the returned polynomial has an Overflow-error as error status.

func (*Polynomial) QuoRem

func (f *Polynomial) QuoRem(list ...*Polynomial) (q []*Polynomial, r *Polynomial, err error)

QuoRem returns the polynomial quotient and remainder under division by the given list of polynomials.

func (*Polynomial) Rem

func (f *Polynomial) Rem(list ...*Polynomial) (r *Polynomial, err error)

Rem returns the polynomial remainder under division by the given list of polynomials.

func (*Polynomial) Scale

func (f *Polynomial) Scale(c ff.Element) *Polynomial

Scale scales all coefficients of f by the field element c and returns the result as a new polynomial. See also SetScale.

func (*Polynomial) SetCoef

func (f *Polynomial) SetCoef(deg [2]uint, val ff.Element)

SetCoef sets the coefficient of the monomial with degree deg in f to val by copying. See also SetCoefPtr.

Example
package main

import (
	"fmt"

	"github.com/ReneBoedker/algobra/bivariate"
	"github.com/ReneBoedker/algobra/finitefield"
)

func main() {
	gf5, _ := finitefield.Define(5)
	ring := bivariate.DefRing(gf5, bivariate.WDegLex(2, 1, false))
	f := ring.PolynomialFromUnsigned(map[[2]uint]uint{
		{3, 1}: 3,
		{1, 4}: 1,
		{0, 0}: 3,
	})
	fmt.Println(f)

	f.SetCoef([2]uint{1, 4}, gf5.ElementFromUnsigned(4))
	f.SetCoef([2]uint{1, 1}, gf5.One())
	fmt.Println(f)
}
Output:

3X^3Y + XY^4 + 3
3X^3Y + 4XY^4 + XY + 3

func (*Polynomial) SetCoefPtr

func (f *Polynomial) SetCoefPtr(deg [2]uint, ptr ff.Element)

SetCoefPtr sets the coefficient of the monomial with degree deg in f to ptr as a pointer. To set coefficient as a value, use SetCoef instead.

func (*Polynomial) SetScale

func (f *Polynomial) SetScale(c ff.Element) *Polynomial

SetScale scales all coefficients of f by the field element c and returns f. See also Scale.

func (*Polynomial) SortedDegrees

func (f *Polynomial) SortedDegrees() [][2]uint

SortedDegrees returns a list containing the degrees is the support of f.

The list is sorted according to the ring order with higher orders preceding lower orders in the list.

Example
package main

import (
	"fmt"

	"github.com/ReneBoedker/algobra/bivariate"
	"github.com/ReneBoedker/algobra/finitefield"
)

func main() {
	gf9, _ := finitefield.Define(9)
	ring := bivariate.DefRing(gf9, bivariate.DegLex(true))
	f, _ := ring.PolynomialFromString("(a+2)X^4Y + aX^2Y^3 + Y^4 - 1")

	fmt.Println(f.SortedDegrees())
}
Output:

[[4 1] [2 3] [0 4] [0 0]]

func (*Polynomial) String

func (f *Polynomial) String() string

String returns the string representation of f. Variables are 'X' and 'Y' by default. To change this, see the SetVarNames method.

func (*Polynomial) Sub

func (f *Polynomial) Sub(g *Polynomial) *Polynomial

Sub sets f to the difference of the two polynomials f and g and returns f.

If f and g are defined over different rings, a new polynomial is returned with an ArithmeticIncompat-error as error status.

When f or g has a non-nil error status, its error is wrapped and the same polynomial is returned.

func (*Polynomial) Times

func (f *Polynomial) Times(g *Polynomial) *Polynomial

Times returns the product of the polynomials f and g

If f and g are defined over different rings, a new polynomial is returned with an ArithmeticIncompat-error as error status.

When f or g has a non-nil error status, its error is wrapped and the same polynomial is returned.

type QuotientRing

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

QuotientRing denotes a polynomial quotient ring. The quotient may be trivial, in which case, the object acts as a ring.

func DefRing

func DefRing(field ff.Field, ord Order) *QuotientRing

DefRing defines a new polynomial ring over the given field, using the order function ord. It returns a new ring-object.

func (*QuotientRing) Interpolate

func (r *QuotientRing) Interpolate(
	points [][2]ff.Element,
	values []ff.Element,
) (*Polynomial, error)

Interpolate computes an interpolation polynomial evaluating to values in the specified points. The resulting polynomial has degree at most 2*len(points)

It returns an InputValue-error if the number of points and values differ, or if points are not distinct.

func (*QuotientRing) NewIdeal

func (r *QuotientRing) NewIdeal(generators ...*Polynomial) (*Ideal, error)

NewIdeal returns a new polynomial ideal over the given ring. If the generators are not defined over the given ring, the function returns an InputIncompatible-error.

Example
package main

import (
	"fmt"

	"github.com/ReneBoedker/algobra/bivariate"
	"github.com/ReneBoedker/algobra/finitefield"
	"github.com/ReneBoedker/algobra/finitefield/ff"
)

func main() {
	gf9, _ := finitefield.Define(9)
	ring := bivariate.DefRing(gf9, bivariate.WDegLex(3, 4, false))
	id, _ := ring.NewIdeal(
		ring.Polynomial(map[[2]uint]ff.Element{
			{0, 3}: gf9.One(),
			{4, 0}: gf9.One().SetNeg(),
			{0, 1}: gf9.One(),
		}),
		ring.Polynomial(map[[2]uint]ff.Element{
			{9, 0}: gf9.One(),
			{1, 0}: gf9.One().SetNeg(),
		}),
	)

	fmt.Println(id)
}
Output:

Ideal <Y^3 + 2X^4 + Y, X^9 + 2X> of Bivariate polynomial ring over Finite field of 9 elements

func (*QuotientRing) Polynomial

func (r *QuotientRing) Polynomial(coefs map[[2]uint]ff.Element) *Polynomial

Polynomial defines a new polynomial with the given coefficients.

func (*QuotientRing) PolynomialFromSigned

func (r *QuotientRing) PolynomialFromSigned(coefs map[[2]uint]int) *Polynomial

PolynomialFromSigned defines a new polynomial with the given coefficients.

func (*QuotientRing) PolynomialFromString

func (r *QuotientRing) PolynomialFromString(s string) (*Polynomial, error)

PolynomialFromString defines a polynomial by parsing s.

The string s must use the variable names specified by r, but capitalization is ignored. Multiplication symbol '*' is allowed, but not necessary. Additionally, Singular-style exponents are allowed, meaning that "X2Y3" is interpreted as "X^2Y^3".

If the string cannot be parsed, the function returns the zero polynomial and a Parsing-error.

func (*QuotientRing) PolynomialFromUnsigned

func (r *QuotientRing) PolynomialFromUnsigned(coefs map[[2]uint]uint) *Polynomial

PolynomialFromUnsigned defines a new polynomial with the given coefficients.

func (*QuotientRing) Quotient

func (r *QuotientRing) Quotient(id *Ideal) (*QuotientRing, error)

Quotient defines the quotient of the given ring modulo the input ideal.

The return type is a new QuotientRing-object

Example
package main

import (
	"fmt"

	"github.com/ReneBoedker/algobra/bivariate"
	"github.com/ReneBoedker/algobra/finitefield"
	"github.com/ReneBoedker/algobra/finitefield/ff"
)

func main() {
	gf9, _ := finitefield.Define(9)
	ring := bivariate.DefRing(gf9, bivariate.WDegLex(3, 4, false))
	id, _ := ring.NewIdeal(
		ring.Polynomial(map[[2]uint]ff.Element{
			{0, 3}: gf9.One(),
			{4, 0}: gf9.One().SetNeg(),
			{0, 1}: gf9.One(),
		}),
		ring.Polynomial(map[[2]uint]ff.Element{
			{9, 0}: gf9.One(),
			{1, 0}: gf9.One().SetNeg(),
		}),
	)

	ring, _ = ring.Quotient(id)

	fmt.Println(ring)
}
Output:

Quotient ring of bivariate polynomials over Finite field of 9 elements modulo <Y^3 + 2X^4 + Y, X^9 + 2X>

func (*QuotientRing) SetVarNames

func (r *QuotientRing) SetVarNames(varNames [2]string) error

SetVarNames sets the variable names to be used in the given quotient ring.

Leading and trailing whitespace characters are removed before setting the variable name. If the one of the strings consists solely of whitespace characters, an InputValue-error is returned.

If the two variable names are identical when ignoring leading and trailing whitespace and capitalization, an InputValue-error is returned.

Example
package main

import (
	"fmt"

	"github.com/ReneBoedker/algobra/bivariate"
	"github.com/ReneBoedker/algobra/finitefield"
)

func main() {
	gf4, _ := finitefield.Define(4)
	ring := bivariate.DefRing(gf4, bivariate.Lex(false))

	f, _ := ring.PolynomialFromString("Y^4 + (a+1)Y^2X^3 + a")

	// Change the variable names
	err := ring.SetVarNames([2]string{"S", "T"})
	if err != nil {
		fmt.Printf("Could not set variable names: %q", err)
	}

	g, _ := ring.PolynomialFromString("ST^3 + T^2 + S")

	// Both f and g are affected by the change
	fmt.Printf("f(S, T) = %v\ng(S, T) = %v", f, g)
}
Output:

f(S, T) = T^4 + (a + 1)S^3T^2 + a
g(S, T) = ST^3 + T^2 + S

func (*QuotientRing) String

func (r *QuotientRing) String() string

String returns the string representation of r.

func (*QuotientRing) VarNames

func (r *QuotientRing) VarNames() [2]string

VarNames returns the strings used to represent the variables of r.

func (*QuotientRing) Zero

func (r *QuotientRing) Zero() *Polynomial

Zero returns a zero polynomial over the specified ring.

Jump to

Keyboard shortcuts

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