Documentation ¶
Overview ¶
Notes for the programmer: ------------------------- The underlying value describing an *Element will be an int64 when possible; otherwise it will be a *big.Int. You should attempt to gain the performance boost of using int64 versions of your computations when possible. Typical code will branch into two cases:
if x.IsInt64() { n := x.int64() // Expose the underlying int64 ... } else { n := x.bigInt() // Expose the underlying *big.Int ... }
Take care not to modify the *big.Int returned by x.bigInt(), as this will modify the corresponding *Element (thus breaking our contract of immutability). Similarly, do not allow this *big.Int to escape into user-land.
The implementation attempts to guarantee that there is a unique 0 and 1 *Element element, returned via the functions Zero() and One(). However this isn't completely true: following good Go standard, a nil *Element behaves identically to 0. Furthermore, there's nothing stoping a user from writing:
x := &integers.Element{}
and thus creating a new, distinct 0. Care must be taken when adding new package functions: you should use the methods x.IsZero() and x.IsOne(). It's good practice to try to reuse Zero() and One(), rather than allowing additional copies of 0 or 1 to leak out of the package. The easiest way to ensure this is to use FromInt64(n) and fromBigIntAndReuse(n) to convert your working value into a *Element suitable for returning to the user.
Performance-wise, the biggest issue is big.Int.Mul(x,y), when x and y are large. Here Magma vastly outperforms big.Int. A quick search on the web shows that there exist several different algorithms for computing x * y, with different performance characteristics that depend on the size of x and y. Implementing these different algorithms, and modifying big.Int so that it uses the appropriate algorithm in each case, is a clear future task.
Index ¶
- Constants
- Variables
- func AreCoprime(a *Element, b *Element) bool
- func AreEqual(x *Element, y *Element) bool
- func Cmp(x *Element, y *Element) int
- func IsPrime(n *Element) bool
- func IsPrimeInt64(n int64) bool
- func IsPrimePowerInt64(n int64) (ok bool, p int64, k int64, err error)
- func IsProbablyPrime(n *Element, N int) bool
- func IsSliceCoprime(as []*Element) (bool, error)
- func IsSlicePairwiseCoprime(as []*Element) (bool, error)
- func NextPrimeInt64(n int64) (int64, error)
- func NthPrimeInt64(N int64) (int64, error)
- func PrimeFactorsInt64(n int64) ([]int64, error)
- func QuotientAndRemainder(x *Element, y *Element) (*Element, *Element, error)
- func SetBigInt(n *big.Int, m *Element) *big.Int
- func SliceToInt64Slice(S []*Element) ([]int64, error)
- func SliceToUint64Slice(S []*Element) ([]uint64, error)
- func XGCDOfPair(a *Element, b *Element) (gcd *Element, u *Element, v *Element)
- type CRTFunc
- type Element
- func Add(x *Element, y *Element) *Element
- func AddInt64(x int64, y *Element) *Element
- func Binomial(n *Element, k *Element) *Element
- func BinomialInt64(n int64, k int64) *Element
- func ChineseRemainderTheorem(residues []*Element, moduli []*Element) (*Element, error)
- func CommonPrimeFactors(a *Element, b *Element) []*Element
- func CopySlice(S []*Element) []*Element
- func Divisors(n *Element) ([]*Element, error)
- func DotProduct(S1 []*Element, S2 []*Element) *Element
- func Factorial(n *Element) (*Element, error)
- func FactorialInt64(n int64) (*Element, error)
- func FromBigInt(n *big.Int) *Element
- func FromInt(n int) *Element
- func FromInt32(n int32) *Element
- func FromInt64(n int64) *Element
- func FromString(s string) (*Element, error)
- func FromUint64(n uint64) *Element
- func GCD(ai ...*Element) *Element
- func GCDOfPair(a *Element, b *Element) *Element
- func GobDecode(dec *gob.Decoder) (*Element, error)
- func GobDecodeSlice(dec *gob.Decoder) ([]*Element, error)
- func IsMersenneNumber(k *Element) (bool, *Element)
- func LCM(a *Element, b *Element) *Element
- func Max(S ...*Element) (*Element, error)
- func MaxAndIndex(S []*Element) (*Element, int, error)
- func MaxOfPair(x *Element, y *Element) *Element
- func Min(S ...*Element) (*Element, error)
- func MinAndIndex(S []*Element) (*Element, int, error)
- func MinOfPair(x *Element, y *Element) *Element
- func Multiply(x *Element, y *Element) *Element
- func MultiplyByInt64ThenAdd(a int64, b *Element, c *Element) *Element
- func MultiplyMultiplyThenAdd(a *Element, b *Element, c *Element, d *Element) *Element
- func MultiplyMultiplyThenSubtract(a *Element, b *Element, c *Element, d *Element) *Element
- func MultiplyThenAdd(a *Element, b *Element, c *Element) *Element
- func MultiplyThenSubtract(a *Element, b *Element, c *Element) *Element
- func Negate(n *Element) *Element
- func NextPrime(n *Element) *Element
- func NthPrime(N int64) (*Element, error)
- func One() *Element
- func Power(n *Element, k *Element) (*Element, error)
- func PowerInt64(n *Element, k int64) (*Element, error)
- func PrimeFactors(n *Element) ([]*Element, error)
- func Product(S ...*Element) *Element
- func ProductOfRange(x1 *Element, x2 *Element) *Element
- func ProductOfRangeInt64(x1 int64, x2 int64) *Element
- func Quotient(x *Element, y *Element) (*Element, error)
- func Random(max *Element) *Element
- func ReverseSlice(S []*Element) []*Element
- func SliceFromInt32Slice(S []int32) []*Element
- func SliceFromInt64Slice(S []int64) []*Element
- func SliceFromIntSlice(S []int) []*Element
- func SliceFromString(str string) ([]*Element, error)
- func SliceFromUint64Slice(S []uint64) []*Element
- func Sort(S []*Element) []*Element
- func Subtract(x *Element, y *Element) *Element
- func Sum(S ...*Element) *Element
- func ToElement(x object.Element) (*Element, error)
- func UniqueCommonPrimeFactors(a *Element, b *Element) []*Element
- func UniquePrimeFactors(n *Element) ([]*Element, error)
- func Zero() *Element
- func ZeroSlice(n int) []*Element
- func (n *Element) Abs() *Element
- func (n *Element) BigInt() *big.Int
- func (n *Element) Decrement() *Element
- func (n *Element) Divisors() ([]*Element, error)
- func (n *Element) GobDecode(buf []byte) error
- func (n *Element) GobEncode() ([]byte, error)
- func (n *Element) Hash() uint32
- func (n *Element) Increment() *Element
- func (n *Element) Int64() (int64, error)
- func (n *Element) InverseMod(m *Element) (*Element, error)
- func (n *Element) IsDivisibleBy(m *Element) (bool, error)
- func (n *Element) IsEqualTo(m *Element) bool
- func (n *Element) IsEqualToInt(m int) bool
- func (n *Element) IsEqualToInt64(m int64) bool
- func (n *Element) IsEqualToUint64(m uint64) bool
- func (n *Element) IsEven() bool
- func (n *Element) IsGreaterThan(m *Element) bool
- func (n *Element) IsGreaterThanInt64(m int64) bool
- func (n *Element) IsGreaterThanOrEqualTo(m *Element) bool
- func (n *Element) IsGreaterThanOrEqualToInt64(m int64) bool
- func (n *Element) IsInt64() bool
- func (n *Element) IsLessThan(m *Element) bool
- func (n *Element) IsLessThanInt64(m int64) bool
- func (n *Element) IsLessThanOrEqualTo(m *Element) bool
- func (n *Element) IsLessThanOrEqualToInt64(m int64) bool
- func (n *Element) IsNegative() bool
- func (n *Element) IsOdd() bool
- func (n *Element) IsOne() bool
- func (n *Element) IsPositive() bool
- func (n *Element) IsPrime() bool
- func (n *Element) IsUint64() bool
- func (n *Element) IsZero() bool
- func (n *Element) Mod(m *Element) (*Element, error)
- func (n *Element) ModInt64(m int64) (int64, error)
- func (n *Element) Negate() *Element
- func (n *Element) Parent() object.Parent
- func (n *Element) Power(k *Element) (*Element, error)
- func (n *Element) PowerInt64(k int64) (*Element, error)
- func (n *Element) PrimeFactors() ([]*Element, error)
- func (n *Element) ScalarMultiplyByInt64(a int64) *Element
- func (n *Element) ScalarMultiplyByInteger(a *Element) *Element
- func (n *Element) ScalarMultiplyByUint64(a uint64) *Element
- func (n *Element) Sign() int
- func (n *Element) String() string
- func (n *Element) ToInteger() (*Element, error)
- func (n *Element) Uint64() (uint64, error)
- func (n *Element) UniquePrimeFactors() ([]*Element, error)
- type Int32Slice
- type Int64Slice
- type IntSlice
- type Parent
- func (R Parent) Add(x object.Element, y object.Element) (object.Element, error)
- func (R Parent) AreEqual(x object.Element, y object.Element) (bool, error)
- func (R Parent) Cmp(x object.Element, y object.Element) (int, error)
- func (R Parent) Contains(x object.Element) bool
- func (R Parent) DotProduct(S1 []object.Element, S2 []object.Element) (object.Element, error)
- func (R Parent) FromInteger(n *Element) object.Element
- func (R Parent) IsOne(x object.Element) (bool, error)
- func (R Parent) IsUnit(x object.Element) (bool, object.Element, error)
- func (R Parent) IsZero(x object.Element) (bool, error)
- func (R Parent) Max(S ...object.Element) (object.Element, error)
- func (R Parent) MaxAndIndex(S []object.Element) (object.Element, int, error)
- func (R Parent) Min(S ...object.Element) (object.Element, error)
- func (R Parent) MinAndIndex(S []object.Element) (object.Element, int, error)
- func (R Parent) Multiply(x object.Element, y object.Element) (object.Element, error)
- func (R Parent) Negate(x object.Element) (object.Element, error)
- func (R Parent) One() object.Element
- func (R Parent) Power(x object.Element, k *Element) (object.Element, error)
- func (R Parent) Product(S ...object.Element) (object.Element, error)
- func (R Parent) ScalarMultiplyByInteger(n *Element, x object.Element) (object.Element, error)
- func (R Parent) Sort(S []object.Element) ([]object.Element, error)
- func (R Parent) String() string
- func (R Parent) Subtract(x object.Element, y object.Element) (object.Element, error)
- func (R Parent) Sum(S ...object.Element) (object.Element, error)
- func (R Parent) ToElement(x object.Element) (object.Element, error)
- func (R Parent) Zero() object.Element
- type PrimeIteratorInt64
- type Slice
- type SortableSlice
- type Uint64Slice
Constants ¶
const ( ErrArgNotAnIntegerGreaterThan1 = objectError(iota) ErrArgsNotCoprime ErrArg1NotAnInteger ErrArg2NotAnInteger ErrArgNotAnInteger ErrArgOutOfRange ErrDivisionByZero ErrDecodingIntoNilObject ErrDecodingIntoExistingObject ErrEmptySlice ErrIllegalNegativeArg ErrIteratorIsClosed ErrIllegalNegativeExponent ErrIllegalZeroArg ErrOutOfRange ErrSliceNotCoprime ErrSliceLengthNotEqual ErrSliceNotPositive ErrStringNotAnInteger )
Common errors.
Variables ¶
var DefaultNumberOfMillerRabinTests = 10
DefaultNumberOfMillerRabinTests is the default number of Miller--Rabin tests when doing probabilistic primality testing in IsPrime(). This is only relevant for n such that |n| >= 2^63 - 1.
Functions ¶
func AreCoprime ¶
AreCoprime returns true iff a and b are coprime.
func IsPrime ¶
IsPrime runs primality tests on the absolute value |n| of n, returning true if they pass and false if they fail. A return value of false guarantees that n is composite. A return value of true guarantees that |n| is prime if |n| < 3,317,044,064,679,887,385,961,981. For larger |n| a return value of true indicates that |n| has a high probability of being prime.
func IsPrimeInt64 ¶
IsPrimeInt64 returns true iff the absolute value |n| is a prime.
func IsPrimePowerInt64 ¶
IsPrimePowerInt64 tests whether the integer n is equal to p^k for some prime p. If n < 2 this returns an error.
func IsProbablyPrime ¶
IsProbablyPrime returns false if n is definitely composite and returns true if the absolute value |n| of n has a high probability of being prime. It uses the ProbablyPrime() function from the Go big library, so per the documentation performs N Miller--Rabin tests.
func IsSliceCoprime ¶
IsSliceCoprime returns true iff the elements of the slice are coprime.
func IsSlicePairwiseCoprime ¶
IsSlicePairwiseCoprime returns true iff the elements of the slice are pairwise coprime.
func NextPrimeInt64 ¶
NextPrimeInt64 returns the smallest prime number > |n| if this fits in an int64, and returns an error otherwise
func NthPrimeInt64 ¶
NthPrimeInt64 returns the N-th prime p if 1 <= N <= 2^17, or an error if N is out of range. Note that primes are indexed from 1.
func PrimeFactorsInt64 ¶
PrimeFactorsInt64 returns the prime factors of |n| as a sorted slice. It returns an error if and only if n is zero.
func QuotientAndRemainder ¶
QuotientAndRemainder returns the quotient and remainder of x on division by y. This will return an error if y is zero.
func SetBigInt ¶
SetBigInt sets the given *big.Int n to the value of the given integer m. Returns the *big.Int n.
func SliceToInt64Slice ¶
SliceToInt64Slice attempts to convert the given slice of integers to a slice of int64s. Returns the new slice on success.
func SliceToUint64Slice ¶
SliceToUint64Slice attempts to convert the given slice of integers to a slice of uint64s. Returns the new slice on success.
func XGCDOfPair ¶
XGCDOfPair returns the greatest common divisor of a and b, along with integers u and v such that u a + v b = gcd. The gcd is always non-negative. The gcd of 0 and n is defined to be |n| (in particular, the gcd of 0 and 0 is 0).
Types ¶
type CRTFunc ¶
CRTFunc applies the Chinese Remainder Theorem to the given residues. If the number of residues does not match the number of moduli then an error is returned.
func PrepareChineseRemainderTheorem ¶
PrepareChineseRemainderTheorem returns a function f that applies the Chinese Remainder Theorem to residues a_1,...,a_k. More precisely, f(a_1,...,a_k) returns the unique non-negative integer a such that 0 <= a < N and, for each i, n is congruent to a_i mod n_i, where the moduli are n_1,...,n_k, and N = n_1*...*n_k. The n_i must be positive and pairwise coprime.
type Element ¶
type Element struct {
// contains filtered or unexported fields
}
Element is an element of the ring of integers.
func Binomial ¶
Binomial return the binomial coefficient of n \choose k. By convention this returns zero if either n or k are negative.
func BinomialInt64 ¶
BinomialInt64 return the binomial coefficient of n \choose k. By convention this returns zero if either n or k are negative.
func ChineseRemainderTheorem ¶
ChineseRemainderTheorem returns the unique non-negative integer a such that 0 <= a < N and, for each i, a is congruent to a_i mod n_i, where residues = [a_1,...,a_k], moduli = [n_1,...,n_k], and N = n_1*...*n_k. The n_i must be positive and pairwise coprime.
func CommonPrimeFactors ¶
CommonPrimeFactors returns the common prime factors of a and b as a sorted slice of *Elements.
func Divisors ¶
Divisors returns the divisors of a non-zero integer n as a sorted slice of *Elements.
func 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.
func Factorial ¶
Factorial returns the value n!, for a non-negative value of n. By convention 0! is 1.
func FactorialInt64 ¶
FactorialInt64 returns the value n!, for a non-negative value of n. By convention 0! is 1.
func FromString ¶
FromString returns the integer represented by the string s.
func GCD ¶
GCD returns the greatest common divisor of a1, a2, ..., ak. The gcd is always non-negative. The gcd of 0 and n is defined to be |n| (in particular, the gcd of 0 is 0, and the gcd of the empty sequence is 0).
func GCDOfPair ¶
GCDOfPair returns the greatest common divisor of a and b. The gcd is always non-negative. The gcd of 0 and n is defined to be |n| (in particular, the gcd of 0 is 0). If you also require integers u and v such that u a + v y = gcd, then use XGCDOfPair.
func GobDecode ¶
GobDecode reads the next value from the given gob.Decoder and decodes it as an integer.
func GobDecodeSlice ¶
GobDecodeSlice reads the next value from the given gob.Decoder and decodes it as a slice of integers.
func IsMersenneNumber ¶
IsMersenneNumber returns true iff k = 2^n - 1 for some non-negative integer n. If true, also returns n.
func MaxAndIndex ¶
MaxAndIndex returns the maximum element in the slice S, along with the index of the first occurrence of that element in S. If S is empty then an error is returned.
func MinAndIndex ¶
MinAndIndex returns the minimum element in the slice S, along with the index of the first occurrence of that element in S. If S is empty then an error is returned.
func MultiplyByInt64ThenAdd ¶
MultiplyByInt64ThenAdd returns the value a * b + c.
func MultiplyMultiplyThenAdd ¶
MultiplyMultiplyThenAdd returns the value a * b + c * d.
func MultiplyMultiplyThenSubtract ¶
MultiplyMultiplyThenSubtract returns the value a * b - c * d.
func MultiplyThenAdd ¶
MultiplyThenAdd returns the value a * b + c.
func MultiplyThenSubtract ¶
MultiplyThenSubtract returns the value a * b - c.
func NextPrime ¶
NextPrime returns the smallest prime number > |n|. Primality testing is done by IsPrime, which in particular is probabilistic for large values.
func NthPrime ¶
NthPrime returns the N-th prime p if 1 <= N <= 2^17, or an error if N is out of range. Note that primes are indexed from 1.
func PrimeFactors ¶
PrimeFactors returns the prime factors of |n| as a sorted slice. It returns an error if and only if n is zero. Primality testing is done by the IsPrime function, which in particular is probabilistic for large arguments.
func Product ¶
Product returns the product of the elements in the slice S. The product of the empty slice is one.
func ProductOfRange ¶
ProductOfRange returns the product of the elements x1 * (x1 + 1) * ... * x2. If x1 > x2 then ProductOfRange returns one.
func ProductOfRangeInt64 ¶
ProductOfRangeInt64 returns the product of the elements x1 * (x1 + 1) * ... * x2. If x1 > x2 then ProductOfRange returns one.
func Quotient ¶
Quotient returns the quotient of x on division by y. This will return an error if y is zero.
func Random ¶
Random returns a random integer in the range [0,max]. It will panic if max is negative. This wraps crypto/rand.
func ReverseSlice ¶
ReverseSlice returns a new slice whose entries are equal to the entries of S, but in the reverse order.
func SliceFromInt32Slice ¶
SliceFromInt32Slice returns a slice of integers given by the slice S.
func SliceFromInt64Slice ¶
SliceFromInt64Slice returns a slice of integers given by the slice S.
func SliceFromIntSlice ¶
SliceFromIntSlice returns a slice of integers given by the slice S.
func SliceFromString ¶
SliceFromString converts a string into a slice of integers.
func SliceFromUint64Slice ¶
SliceFromUint64Slice returns a slice of integers given by the slice S.
func Sum ¶
Sum returns the sum of the elements in the slice S. The sum of the empty slice is the zero element.
func ToElement ¶
ToElement attempts to convert the given object.Element to an integer. If x satisfies either of the interfaces:
type ToIntegerer interface { ToInteger() (*Element, error) // ToInteger attempts to convert the object.Element to an integer. } type ToIntegererNoError interface { ToInteger() *Element // ToInteger converts the object.Element to an integer. }
then x's ToInteger method will be called.
func UniqueCommonPrimeFactors ¶
UniqueCommonPrimeFactors returns the common prime factors of a and b as a sorted slice of *Elements, without repeats.
func UniquePrimeFactors ¶
UniquePrimeFactors returns the prime factors of a non-zero integer n as a sorted slice of *Elements, without repeats, or an error if n is zero.
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) InverseMod ¶
InverseMod returns an inverse of n modulo m if n and m are coprime, and an error otherwise. The returned inverse modulo m is in the range 0 < n^{-1} < m if m is positive, and m < n^{-1} < 0 if m is negative.
func (*Element) IsDivisibleBy ¶
IsDivisibleBy returns true iff n is divisible by m and m is non-zero. If m is zero then an error is returned.
func (*Element) IsEqualToInt ¶
IsEqualToInt returns true iff n = m.
func (*Element) IsEqualToInt64 ¶
IsEqualToInt64 returns true iff n = m.
func (*Element) IsEqualToUint64 ¶
IsEqualToUint64 returns true iff n = m.
func (*Element) IsGreaterThan ¶
IsGreaterThan returns true iff n > m.
func (*Element) IsGreaterThanInt64 ¶
IsGreaterThanInt64 returns true iff n > m.
func (*Element) IsGreaterThanOrEqualTo ¶
IsGreaterThanOrEqualTo returns true iff n >= m.
func (*Element) IsGreaterThanOrEqualToInt64 ¶
IsGreaterThanOrEqualToInt64 returns true iff n >= m.
func (*Element) IsLessThan ¶
IsLessThan returns true iff n < m.
func (*Element) IsLessThanInt64 ¶
IsLessThanInt64 returns true iff n < m.
func (*Element) IsLessThanOrEqualTo ¶
IsLessThanOrEqualTo returns true iff n <= m.
func (*Element) IsLessThanOrEqualToInt64 ¶
IsLessThanOrEqualToInt64 returns true iff n <= m.
func (*Element) IsPrime ¶
IsPrime runs primality tests on the absolute value |n| of n, returning true if they pass and false if they fail. A return value of false guarantees that n is composite. A return value of true guarantees that |n| is prime if |n| < 3,317,044,064,679,887,385,961,981. For larger |n| a return value of true indicates that |n| has a high probability of being prime.
func (*Element) Mod ¶
Mod returns n modulo m if m is non-zero, and an error otherwise. The returned modulus k is in the range 0 <= k < m if m is positive, and m < k <= 0 if m is negative.
func (*Element) ModInt64 ¶
ModInt64 returns n modulo m if m is non-zero, and an error otherwise. The returned modulus k is in the range 0 <= k < m if m is positive, and m < k <= 0 if m is negative.
func (*Element) Parent ¶
Parent returns the ring of integers as a object.Parent. This can safely be coerced to type Parent.
func (*Element) PowerInt64 ¶
PowerInt64 returns n^k.
func (*Element) PrimeFactors ¶
PrimeFactors returns the prime factors of n as a sorted slice of *Elements.
func (*Element) ScalarMultiplyByInt64 ¶
ScalarMultiplyByInt64 returns the product a * n.
func (*Element) ScalarMultiplyByInteger ¶
ScalarMultiplyByInteger returns the product a * n.
func (*Element) ScalarMultiplyByUint64 ¶
ScalarMultiplyByUint64 returns the product a * n.
func (*Element) UniquePrimeFactors ¶
UniquePrimeFactors returns the prime factors of n as a sorted slice of *Elements, without repeats.
type Int32Slice ¶
type Int32Slice []int32
Int32Slice wraps an []int32, implementing slice.Interface and returning the entries as *Elements.
func (Int32Slice) Entry ¶
func (S Int32Slice) Entry(i int) object.Element
Entry returns the i-th element in the slice. This will panic if i is out of range.
func (Int32Slice) Hash ¶
func (S Int32Slice) Hash() uint32
Hash returns a hash value for this slice.
type Int64Slice ¶
type Int64Slice []int64
Int64Slice wraps an []int64, implementing slice.Interface and returning the entries as *Elements.
func (Int64Slice) Entry ¶
func (S Int64Slice) Entry(i int) object.Element
Entry returns the i-th element in the slice. This will panic if i is out of range.
func (Int64Slice) Hash ¶
func (S Int64Slice) Hash() uint32
Hash returns a hash value for this slice.
type IntSlice ¶
type IntSlice []int
IntSlice wraps an []int, implementing slice.Interface and returning the entries as *Elements.
type Parent ¶
type Parent struct{}
Parent represents the (unique) ring of integers.
func (Parent) Contains ¶
Contains returns true iff x is an integer, or can naturally be regarded as an integer.
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.
func (Parent) FromInteger ¶
FromInteger returns n.
func (Parent) IsUnit ¶
IsUnit returns true iff x is a multiplicative unit in the ring of integers (i.e. x = 1 or -1). If true, also returns the inverse element y such that x * y = 1.
func (Parent) Max ¶
Max returns the maximum element in the slice S. If S is empty then an error is returned.
func (Parent) MaxAndIndex ¶
MaxAndIndex returns the maximum element in the slice S, along with the index of the first occurrence of that element in S. If S is empty then an error is returned.
func (Parent) Min ¶
Min returns the maximum element in the slice S. If S is empty then an error is returned.
func (Parent) MinAndIndex ¶
MinAndIndex returns the minimum element in the slice S, along with the index of the first occurrence of that element in S. If S is empty then an error is returned.
func (Parent) Product ¶
Product returns the product of the elements in the slice S. The product of the empty slice is one.
func (Parent) ScalarMultiplyByInteger ¶
ScalarMultiplyByInteger returns nx, where this is defined to be x + ... + x (n times) if n is positive, and -x - ... - x (|n| times) if n is negative.
func (Parent) Sort ¶
Sort non-destructively sorts the given slice of integers. The sorted slice is returned.
func (Parent) Sum ¶
Sum returns the sum of the elements in the slice S. The sum of the empty slice is the zero element.
type PrimeIteratorInt64 ¶
type PrimeIteratorInt64 struct {
// contains filtered or unexported fields
}
PrimeIteratorInt64 provides an efficient way to iterate over the primes that fit in an int64.
func NewPrimeIteratorInt64 ¶
func NewPrimeIteratorInt64(n int64) *PrimeIteratorInt64
NewPrimeIteratorInt64 returns a new prime iterator starting at the smallest prime number > |n|.
func (*PrimeIteratorInt64) Close ¶
func (np *PrimeIteratorInt64) Close() error
Close stops the iterator.
func (*PrimeIteratorInt64) Next ¶
func (np *PrimeIteratorInt64) Next() (int64, error)
Next returns the next prime from the iterator, or an error.
type Slice ¶
type Slice []*Element
Slice wraps an []*Element, implementing slice.Interface.
type SortableSlice ¶
type SortableSlice []*Element
SortableSlice implements slice.Interface and sort.Interface.
func (SortableSlice) Entry ¶
func (S SortableSlice) Entry(i int) object.Element
Entry returns the i-th element in the slice. This will panic if i is out of range.
func (SortableSlice) Hash ¶
func (S SortableSlice) Hash() uint32
Hash returns a hash value for this slice.
func (SortableSlice) Less ¶
func (S SortableSlice) Less(i int, j int) bool
Less reports whether the element with index i should sort before the element with index j.
func (SortableSlice) Swap ¶
func (S SortableSlice) Swap(i int, j int)
Swap swaps the elements with indexes i and j.
type Uint64Slice ¶
type Uint64Slice []uint64
Uint64Slice wraps an []uint64, implementing slice.Interface and returning the entries as *Elements.
func (Uint64Slice) Entry ¶
func (S Uint64Slice) Entry(i int) object.Element
Entry returns the i-th element in the slice. This will panic if i is out of range.
func (Uint64Slice) Hash ¶
func (S Uint64Slice) Hash() uint32
Hash returns a hash value for this slice.
Source Files ¶
- chineseremainder.go
- conversion.go
- creation.go
- element.go
- encoding.go
- errors.go
- factorial.go
- hash.go
- mersenne.go
- minmax.go
- naivefactorisation.go
- nextprime.go
- parent.go
- primalitytesting.go
- primepower.go
- primes.go
- primescache.go
- random.go
- slice.go
- smallintegercache.go
- smallprimestable.go
- sort.go
- sumproduct.go