gfp

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: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChineseRemainderTheorem

func ChineseRemainderTheorem(reductions []*Element) (*integer.Element, error)

ChineseRemainderTheorem returns the unique non-negative integer a such that 0 <= a < N and that a reduces to reductions. Here reductions is a slice [a_1,...,a_n] of finite field elements where a_i is an element of GF(p_i) with p_i prime, and the p_i are distinct; the value N above is the product of the p_i. The return value a is congruent to a_i mod p_i, for each i.

func CopySliceOfSlices

func CopySliceOfSlices(S [][]*Element) [][]*Element

CopySliceOfSlices returns a copy of the slice S. The capacity will be preserved.

func ToInt64

func ToInt64(a *Element) int64

ToInt64 returns the int64 b that is equal to a mod p and satisfies 0 <= b < p, where a lies in ZZ/pZZ

Types

type CRTFromFiniteFieldElementsFunc

type CRTFromFiniteFieldElementsFunc func(residues ...*Element) (*integer.Element, error)

CRTFromFiniteFieldElementsFunc applies the Chinese Remainder Theorem to the given finite field elements. If the number of residues does not match the number of field elements expected, or if the characteristics of the fields do not match those expected, then an error is returned.

func PrepareChineseRemainderTheorem

func PrepareChineseRemainderTheorem(moduli ...int64) (CRTFromFiniteFieldElementsFunc, error)

PrepareChineseRemainderTheorem returns a function f that applies the Chinese Remainder Theorem to finite field elements a_1,...,a_k. More precisely, given elements a_1,...,a_k of GF(p_1),...,GF(p_k) where moduli=[p_1,...,p_k] and the primes p_1,...,p_k are distinct, f(a_1,...,a_k) returns the unique non-negative integer a such that 0 <= a < p_1*...*p_k and, for each i, n is congruent to a_i mod p_i.

type Element

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

Element is an element of a field ZZ/pZZ where p is prime

func Add

func Add(a *Element, b *Element) (*Element, error)

Add returns the sum of a and b. It returns an error if a and b do not have the same parent.

func CopySlice

func CopySlice(S []*Element) []*Element

CopySlice returns a copy of the slice S. The capacity will be preserved.

func Divide

func Divide(a *Element, b *Element) (*Element, error)

Divide returns a/b. It returns an error if a and b do not have the same parent.

func DotProduct

func DotProduct(k *Parent, S1 []*Element, S2 []*Element) (*Element, error)

DotProduct returns the dot-product of the slices S1 and S2. That is, it returns S1[0] * S2[0] + ... + S1[n] * S2[n], where n+1 is the minimum of len(S1) and len(S2). The dot-product of two empty slices is the zero element. Unless all elements of S1 and S2 lie in k, an error is returned.

func FromInt

func FromInt(k *Parent, n int) *Element

FromInt returns n as an element of k.

func FromInt32

func FromInt32(k *Parent, n int32) *Element

FromInt32 returns n as an element of k.

func FromInt64

func FromInt64(k *Parent, n int64) *Element

FromInt64 returns n as an element of k.

func FromInteger

func FromInteger(k *Parent, n *integer.Element) *Element

FromInteger returns n as an element of k.

func FromRational

func FromRational(k *Parent, q *rational.Element) (*Element, error)

FromRational returns q as an element of k. It returns an error if the denominator of q is not invertible in k.

func FromUint64

func FromUint64(k *Parent, n uint64) *Element

FromUint64 returns n as an element of k.

func GobDecode

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

GobDecode reads the next value from the given gob.Decoder and decodes it as a finite field elements.

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 finite field elements.

func Multiply

func Multiply(a *Element, b *Element) (*Element, error)

Multiply returns the product of a and b. It returns an error if a and b do not have the same parent.

func MultiplyMultiplyThenAdd

func MultiplyMultiplyThenAdd(a *Element, b *Element, c *Element, d *Element) (*Element, error)

MultiplyMultiplyThenAdd returns the value a * b + c * d. It returns an error unless a, b, c, and d have the same parent

func MultiplyMultiplyThenSubtract

func MultiplyMultiplyThenSubtract(a *Element, b *Element, c *Element, d *Element) (*Element, error)

MultiplyMultiplyThenSubtract returns the value a * b - c * d.

func MultiplyThenAdd

func MultiplyThenAdd(a *Element, b *Element, c *Element) (*Element, error)

MultiplyThenAdd returns the value a * b + c. It returns an error unless a, b, and c have the same parent.

func MultiplyThenSubtract

func MultiplyThenSubtract(a *Element, b *Element, c *Element) (*Element, error)

MultiplyThenSubtract returns the value a * b - c.

func One

func One(k *Parent) *Element

One returns the unit element of k

func Power

func Power(a *Element, n *integer.Element) (*Element, error)

Power returns a^n. It returns an error if n is negative and a is not invertible.

func PowerInt64

func PowerInt64(a *Element, n int64) (*Element, error)

PowerInt64 returns a^n. It returns an error if n is negative and a is not invertible.

func Product

func Product(k *Parent, S ...*Element) (*Element, error)

Product returns the product of the elements in the slice S. The product of the empty slice is 1.

func Subtract

func Subtract(a *Element, b *Element) (*Element, error)

Subtract returns a-b. It returns an error if a and b do not have the same parent.

func Sum

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

Sum returns the sum of the elements in the slice S. The sum of the empty slice is zero.

func ToElement

func ToElement(k *Parent, x object.Element) (*Element, error)

ToElement attempts to convert the given object.Element to an element of k. If necessary this will be done by first attempting to convert x to an integer or, if that fails, to a rational number, and then to a element of k.

func Zero

func Zero(k *Parent) *Element

Zero returns the zero of k

func (*Element) GobDecode

func (a *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.

func (*Element) GobEncode

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

GobEncode implements the gob.GobEncoder interface.

func (*Element) Hash

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

Hash returns a hash value for a

func (*Element) Inverse

func (a *Element) Inverse() (*Element, error)

Inverse returns 1/a. It will return an error if a is zero.

func (*Element) IsEqualTo

func (a *Element) IsEqualTo(b *Element) bool

IsEqualTo returns true iff a = b.

func (*Element) IsOne

func (a *Element) IsOne() bool

IsOne returns true iff a is one.

func (*Element) IsZero

func (a *Element) IsZero() bool

IsZero returns true iff a is zero.

func (*Element) Negate

func (a *Element) Negate() *Element

Negate return -a.

func (*Element) Parent

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

Parent returns the finite field containing a as an object.Parent. This can safely be coerced to type *Parent.

func (*Element) Power

func (a *Element) Power(n *integer.Element) (*Element, error)

Power returns a^n. It returns an error if n is negative and a is zero.

func (*Element) PowerInt64

func (a *Element) PowerInt64(n int64) (*Element, error)

PowerInt64 returns a^n. It returns an error if n is negative and a is zero.

func (*Element) ScalarMultiplyByInteger

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

ScalarMultiplyByInteger returns na, where this is defined to be a + ... + a (n times) if n is positive, -a - ... - a (|n| times) if n is negative, and the zero element if n is zero.

func (*Element) String

func (a *Element) String() string

String returns a string representation of the finite field element a

type Parent

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

Parent represents a finite field GF(p) for some prime p.

func GF

func GF(p int64) (*Parent, error)

GF returns the finite field with p elements. p must be prime or 1.

func (*Parent) Add

Add returns x + y.

func (*Parent) AreEqual

func (k *Parent) AreEqual(x object.Element, y object.Element) (bool, error)

AreEqual returns true iff x equals y.

func (*Parent) Characteristic

func (k *Parent) Characteristic() *integer.Element

Characteristic returns the characteristic of k.

func (*Parent) CharacteristicInt64

func (k *Parent) CharacteristicInt64() int64

CharacteristicInt64 returns the characteristic of k.

func (*Parent) Contains

func (k *Parent) Contains(x object.Element) bool

Contains returns true iff x is an element of the field, or can naturally be regarded as an element of the field

func (*Parent) Divide

func (k *Parent) Divide(x object.Element, y object.Element) (object.Element, error)

Divide returns the quotient x / y. Returns a errors.DivisionByZero error if y is zero.

func (*Parent) DotProduct

func (k *Parent) DotProduct(S1 []object.Element, S2 []object.Element) (object.Element, error)

DotProduct returns the dot-product of the slices S1 and S2. That is, it returns S1[0] * S2[0] + ... + S1[k] * S2[k], where k+1 is the minimum of len(S1) and len(S2). The dot-product of two empty slices is the zero element of k.

func (*Parent) FromInteger

func (k *Parent) FromInteger(n *integer.Element) object.Element

FromInteger returns n as an element of k

func (*Parent) FromRational

func (k *Parent) FromRational(q *rational.Element) (object.Element, error)

FromRational returns q as an element of k. It returns an error if the denominator of q is not invertible in k.

func (*Parent) Inverse

func (k *Parent) Inverse(n object.Element) (object.Element, error)

Inverse returns 1/n. Returns an errors.DivisionByZero error if n is zero.

func (*Parent) IsOne

func (k *Parent) IsOne(x object.Element) (bool, error)

IsOne returns true iff x is the unit element in this field.

func (*Parent) IsUnit

func (k *Parent) IsUnit(n object.Element) (bool, object.Element, error)

IsUnit returns true iff n is a multiplicative unit (i.e. n is non-zero). If true, also returns the inverse element 1/n.

func (*Parent) IsZero

func (k *Parent) IsZero(x object.Element) (bool, error)

IsZero returns true iff x is the zero element in this field

func (*Parent) Multiply

func (k *Parent) Multiply(x object.Element, y object.Element) (object.Element, error)

Multiply returns the product x * y.

func (*Parent) Negate

func (k *Parent) Negate(n object.Element) (object.Element, error)

Negate returns -n.

func (*Parent) One

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

One returns 1.

func (*Parent) Order

func (k *Parent) Order() *integer.Element

Order returns the order of k.

func (*Parent) OrderInt64

func (k *Parent) OrderInt64() int64

OrderInt64 returns the order of k.

func (*Parent) Power

func (k *Parent) Power(a object.Element, n *integer.Element) (object.Element, error)

Power returns a^n. It returns an error if n is negative and a is not invertible.

func (*Parent) PowerInt64

func (k *Parent) PowerInt64(a object.Element, n int64) (object.Element, error)

PowerInt64 returns a^n. It returns an error if n is negative and a is not invertible.

func (*Parent) Product

func (k *Parent) Product(S ...object.Element) (object.Element, error)

Product returns the product of the elements in the slice S. The product of the empty slice is 1.

func (*Parent) ScalarMultiplyByInteger

func (k *Parent) ScalarMultiplyByInteger(n *integer.Element, x object.Element) (object.Element, error)

ScalarMultiplyByInteger returns nx, where this is defined to be x + ... + x (n times) if n is positive, -x - ... - x (|n| times) if n is negative, and the zero element if n is zero.

func (*Parent) String

func (k *Parent) String() string

String returns a string representation of the field

func (*Parent) Subtract

func (k *Parent) Subtract(x object.Element, y object.Element) (object.Element, error)

Subtract returns x - y.

func (*Parent) Sum

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

Sum returns the sum of the elements in the slice S. The sum of the empty slice is zero.

func (*Parent) ToElement

func (k *Parent) ToElement(x object.Element) (object.Element, error)

ToElement attempts to convert the given object.Element to an element of k. If necessary this will be done by first attempting to convert x to an integer or, if that fails, to a rational number.

func (*Parent) Zero

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

Zero returns 0.

type Slice

type Slice []*Element

Slice wraps an []*Element implementing slice.Interface.

func (Slice) Entry

func (s Slice) Entry(i int) object.Element

Entry returns the i-th element in the slice. This will panic if i is out of range.

func (Slice) Len

func (s Slice) Len() int

Len returns the length of the slice.

func (Slice) Slice

func (s Slice) Slice(k int, m int) slice.Interface

Slice returns a subslice starting at index k and of length m - k. The returned subslice will be of the same underlying type. This will panic if the arguments are out of range.

Jump to

Keyboard shortcuts

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