Documentation ¶
Index ¶
- func ChineseRemainderTheorem(reductions []*Element) (*integer.Element, error)
- func CopySliceOfSlices(S [][]*Element) [][]*Element
- func ToInt64(a *Element) int64
- type CRTFromFiniteFieldElementsFunc
- type Element
- func Add(a *Element, b *Element) (*Element, error)
- func CopySlice(S []*Element) []*Element
- func Divide(a *Element, b *Element) (*Element, error)
- func DotProduct(k *Parent, S1 []*Element, S2 []*Element) (*Element, error)
- func FromInt(k *Parent, n int) *Element
- func FromInt32(k *Parent, n int32) *Element
- func FromInt64(k *Parent, n int64) *Element
- func FromInteger(k *Parent, n *integer.Element) *Element
- func FromRational(k *Parent, q *rational.Element) (*Element, error)
- func FromUint64(k *Parent, n uint64) *Element
- func GobDecode(dec *gob.Decoder) (*Element, error)
- func GobDecodeSlice(dec *gob.Decoder) ([]*Element, error)
- func Multiply(a *Element, b *Element) (*Element, error)
- func MultiplyMultiplyThenAdd(a *Element, b *Element, c *Element, d *Element) (*Element, error)
- func MultiplyMultiplyThenSubtract(a *Element, b *Element, c *Element, d *Element) (*Element, error)
- func MultiplyThenAdd(a *Element, b *Element, c *Element) (*Element, error)
- func MultiplyThenSubtract(a *Element, b *Element, c *Element) (*Element, error)
- func One(k *Parent) *Element
- func Power(a *Element, n *integer.Element) (*Element, error)
- func PowerInt64(a *Element, n int64) (*Element, error)
- func Product(k *Parent, S ...*Element) (*Element, error)
- func Subtract(a *Element, b *Element) (*Element, error)
- func Sum(k *Parent, S ...*Element) (*Element, error)
- func ToElement(k *Parent, x object.Element) (*Element, error)
- func Zero(k *Parent) *Element
- func (a *Element) GobDecode(buf []byte) error
- func (a *Element) GobEncode() ([]byte, error)
- func (a *Element) Hash() hash.Value
- func (a *Element) Inverse() (*Element, error)
- func (a *Element) IsEqualTo(b *Element) bool
- func (a *Element) IsOne() bool
- func (a *Element) IsZero() bool
- func (a *Element) Negate() *Element
- func (a *Element) Parent() object.Parent
- func (a *Element) Power(n *integer.Element) (*Element, error)
- func (a *Element) PowerInt64(n int64) (*Element, error)
- func (a *Element) ScalarMultiplyByInteger(n *integer.Element) *Element
- func (a *Element) String() string
- type Parent
- func (k *Parent) Add(x object.Element, y object.Element) (object.Element, error)
- func (k *Parent) AreEqual(x object.Element, y object.Element) (bool, error)
- func (k *Parent) Characteristic() *integer.Element
- func (k *Parent) CharacteristicInt64() int64
- func (k *Parent) Contains(x object.Element) bool
- func (k *Parent) Divide(x object.Element, y object.Element) (object.Element, error)
- func (k *Parent) DotProduct(S1 []object.Element, S2 []object.Element) (object.Element, error)
- func (k *Parent) FromInteger(n *integer.Element) object.Element
- func (k *Parent) FromRational(q *rational.Element) (object.Element, error)
- func (k *Parent) Inverse(n object.Element) (object.Element, error)
- func (k *Parent) IsOne(x object.Element) (bool, error)
- func (k *Parent) IsUnit(n object.Element) (bool, object.Element, error)
- func (k *Parent) IsZero(x object.Element) (bool, error)
- func (k *Parent) Multiply(x object.Element, y object.Element) (object.Element, error)
- func (k *Parent) Negate(n object.Element) (object.Element, error)
- func (k *Parent) One() object.Element
- func (k *Parent) Order() *integer.Element
- func (k *Parent) OrderInt64() int64
- func (k *Parent) Power(a object.Element, n *integer.Element) (object.Element, error)
- func (k *Parent) PowerInt64(a object.Element, n int64) (object.Element, error)
- func (k *Parent) Product(S ...object.Element) (object.Element, error)
- func (k *Parent) ScalarMultiplyByInteger(n *integer.Element, x object.Element) (object.Element, error)
- func (k *Parent) String() string
- func (k *Parent) Subtract(x object.Element, y object.Element) (object.Element, error)
- func (k *Parent) Sum(S ...object.Element) (object.Element, error)
- func (k *Parent) ToElement(x object.Element) (object.Element, error)
- func (k *Parent) Zero() object.Element
- type Slice
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChineseRemainderTheorem ¶
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 ¶
CopySliceOfSlices returns a copy of the slice S. The capacity will be preserved.
Types ¶
type CRTFromFiniteFieldElementsFunc ¶
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 ¶
Add returns the sum of a and b. It returns an error if a and b do not have the same parent.
func DotProduct ¶
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 FromInteger ¶
FromInteger returns n as an element of k.
func FromRational ¶
FromRational returns q as an element of k. It returns an error if the denominator of q is not invertible in k.
func FromUint64 ¶
FromUint64 returns n as an element of k.
func GobDecode ¶
GobDecode reads the next value from the given gob.Decoder and decodes it as a finite field elements.
func GobDecodeSlice ¶
GobDecodeSlice reads the next value from the given gob.Decoder and decodes it as a slice of finite field elements.
func Multiply ¶
Multiply returns the product of a and b. It returns an error if a and b do not have the same parent.
func MultiplyMultiplyThenAdd ¶
MultiplyMultiplyThenAdd returns the value a * b + c * d. It returns an error unless a, b, c, and d have the same parent
func MultiplyMultiplyThenSubtract ¶
MultiplyMultiplyThenSubtract returns the value a * b - c * d.
func MultiplyThenAdd ¶
MultiplyThenAdd returns the value a * b + c. It returns an error unless a, b, and c have the same parent.
func MultiplyThenSubtract ¶
MultiplyThenSubtract returns the value a * b - c.
func PowerInt64 ¶
PowerInt64 returns a^n. It returns an error if n is negative and a is not invertible.
func Product ¶
Product returns the product of the elements in the slice S. The product of the empty slice is 1.
func ToElement ¶
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 (*Element) GobDecode ¶
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) Parent ¶
Parent returns the finite field containing a as an object.Parent. This can safely be coerced to type *Parent.
func (*Element) PowerInt64 ¶
PowerInt64 returns a^n. It returns an error if n is negative and a is zero.
func (*Element) ScalarMultiplyByInteger ¶
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.
type Parent ¶
type Parent struct {
// contains filtered or unexported fields
}
Parent represents a finite field GF(p) for some prime p.
func (*Parent) Characteristic ¶
Characteristic returns the characteristic of k.
func (*Parent) CharacteristicInt64 ¶
CharacteristicInt64 returns the characteristic of k.
func (*Parent) Contains ¶
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 ¶
Divide returns the quotient x / y. Returns a errors.DivisionByZero error if y is zero.
func (*Parent) DotProduct ¶
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 ¶
FromInteger returns n as an element of k
func (*Parent) FromRational ¶
FromRational returns q as an element of k. It returns an error if the denominator of q is not invertible in k.
func (*Parent) IsUnit ¶
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) Power ¶
Power returns a^n. It returns an error if n is negative and a is not invertible.
func (*Parent) PowerInt64 ¶
PowerInt64 returns a^n. It returns an error if n is negative and a is not invertible.
func (*Parent) Product ¶
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) Sum ¶
Sum returns the sum of the elements in the slice S. The sum of the empty slice is zero.