Documentation
¶
Overview ¶
Package field implements finite field arithmetic.
Example ¶
package main
import (
"fmt"
"github.com/fumin/nag/field"
)
func main() {
// This example checks the freshman's dream identity for finite fields:
//
// (x + y)^p = x^p + y^p
//
// where p is the characteristic of the field.
// Create the Galois field GF(11^3), and pick any two elements x and y.
p, n := 11, 3
irr := field.NewIrreduciblePoly(p, n)
x, y := irr.Ext(153), irr.Ext(749)
// Compute (x + y)^p.
xPlusY := irr.Ext(0).Add(x, y)
xyp := irr.Ext(1)
for range p {
xyp.Mul(xyp, xPlusY)
}
// Compute x^p + y^p.
xp, yp := irr.Ext(1), irr.Ext(1)
for range p {
xp.Mul(xp, x)
yp.Mul(yp, y)
}
xpPlusyp := irr.Ext(0).Add(xp, yp)
fmt.Println("(x + y)^p == x^p + y^p")
fmt.Println(xyp, "==", xpPlusyp)
}
Output: (x + y)^p == x^p + y^p 655 == 655
Index ¶
- type IrreduciblePoly
- type PrimeExt
- func (z *PrimeExt) Add(x, y *PrimeExt) *PrimeExt
- func (z *PrimeExt) Div(x, y *PrimeExt) *PrimeExt
- func (x *PrimeExt) Equal(y *PrimeExt) bool
- func (z *PrimeExt) Inv(x *PrimeExt) *PrimeExt
- func (z *PrimeExt) Mul(x, y *PrimeExt) *PrimeExt
- func (x *PrimeExt) NewOne() *PrimeExt
- func (x *PrimeExt) NewZero() *PrimeExt
- func (x *PrimeExt) String() string
- func (z *PrimeExt) Sub(x, y *PrimeExt) *PrimeExt
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IrreduciblePoly ¶
type IrreduciblePoly struct {
*nag.Polynomial[*prime]
}
An IrreduciblePoly is an irreducible polynomial for the construction of a prime field extension.
func NewIrreduciblePoly ¶
func NewIrreduciblePoly(p, n int) *IrreduciblePoly
NewIrreduciblePoly returns an irreducible polynomial for the finite field GF(p^n), where p is a prime number and n >= 1.
func (*IrreduciblePoly) Ext ¶
func (irr *IrreduciblePoly) Ext(i int) *PrimeExt
Ext returns the i'th element in the finite field GF(p^n).
type PrimeExt ¶
type PrimeExt struct {
// contains filtered or unexported fields
}
A PrimeExt is an element in the finite field GF(p^n), where p is a prime number and n >= 1.
Click to show internal directories.
Click to hide internal directories.