Documentation
¶
Index ¶
- func AreEqual(x *Element, y *Element) bool
- func Cmp(x *Element, y *Element) int
- func SetBigRat(q *big.Rat, r *Element) *big.Rat
- type Element
- func Add(x *Element, y *Element) *Element
- func AddInt64(x int64, y *Element) *Element
- func AddInteger(x *integer.Element, y *Element) *Element
- func CopySlice(S []*Element) []*Element
- func Divide(x *Element, y *Element) (*Element, error)
- func DotProduct(S1 []*Element, S2 []*Element) *Element
- func FromBigInt(n *big.Int) *Element
- func FromBigIntPair(a *big.Int, b *big.Int) (*Element, error)
- func FromBigRat(q *big.Rat) *Element
- func FromInt(n int) *Element
- func FromInt32(n int32) *Element
- func FromInt32Pair(a int32, b int32) (*Element, error)
- func FromInt64(n int64) *Element
- func FromInt64Pair(a int64, b int64) (*Element, error)
- func FromIntPair(a int, b int) (*Element, error)
- func FromInteger(n *integer.Element) *Element
- func FromIntegerPair(a *integer.Element, b *integer.Element) (*Element, error)
- func FromString(s string) (*Element, error)
- func FromUint64(n uint64) *Element
- func FromUint64Pair(a uint64, b uint64) (*Element, error)
- func GobDecode(dec *gob.Decoder) (*Element, error)
- func GobDecodeSlice(dec *gob.Decoder) ([]*Element, error)
- func Inverse(q *Element) (*Element, error)
- 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 MultiplyByIntegerThenAdd(a *integer.Element, 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(q *Element) *Element
- func One() *Element
- func Power(q *Element, k *integer.Element) (*Element, error)
- func PowerInt64(q *Element, k int64) (*Element, error)
- func Product(S ...*Element) *Element
- func SliceFromIntPairs(S []int) ([]*Element, error)
- func SliceFromIntSlice(S []int) []*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 Zero() *Element
- func (q *Element) Abs() *Element
- func (q *Element) BigInt() (*big.Int, error)
- func (q *Element) BigRat() *big.Rat
- func (q *Element) Ceiling() *integer.Element
- func (q *Element) Decrement() *Element
- func (q *Element) Denominator() *integer.Element
- func (q *Element) Floor() *integer.Element
- func (q *Element) GobDecode(buf []byte) error
- func (q *Element) GobEncode() ([]byte, error)
- func (q *Element) Hash() hash.Value
- func (q *Element) Increment() *Element
- func (q *Element) Int64() (int64, error)
- func (q *Element) Inverse() (*Element, error)
- func (q *Element) IsEqualTo(r *Element) bool
- func (q *Element) IsEqualToInt64(r int64) bool
- func (q *Element) IsEqualToInteger(r *integer.Element) bool
- func (q *Element) IsEqualToUint64(r uint64) bool
- func (q *Element) IsGreaterThan(r *Element) bool
- func (q *Element) IsGreaterThanInt64(r int64) bool
- func (q *Element) IsGreaterThanInteger(r *integer.Element) bool
- func (q *Element) IsGreaterThanOrEqualTo(r *Element) bool
- func (q *Element) IsGreaterThanOrEqualToInt64(r int64) bool
- func (q *Element) IsGreaterThanOrEqualToInteger(r *integer.Element) bool
- func (q *Element) IsInt64() bool
- func (q *Element) IsIntegral() bool
- func (q *Element) IsLessThan(r *Element) bool
- func (q *Element) IsLessThanInt64(r int64) bool
- func (q *Element) IsLessThanInteger(r *integer.Element) bool
- func (q *Element) IsLessThanOrEqualTo(r *Element) bool
- func (q *Element) IsLessThanOrEqualToInt64(r int64) bool
- func (q *Element) IsLessThanOrEqualToInteger(r *integer.Element) bool
- func (q *Element) IsNegative() bool
- func (q *Element) IsOne() bool
- func (q *Element) IsPositive() bool
- func (q *Element) IsUint64() bool
- func (q *Element) IsZero() bool
- func (q *Element) Negate() *Element
- func (q *Element) Numerator() *integer.Element
- func (q *Element) Parent() object.Parent
- func (q *Element) Power(k *integer.Element) (*Element, error)
- func (q *Element) PowerInt64(k int64) (*Element, error)
- func (q *Element) ScalarMultiplyByInt64(a int64) *Element
- func (q *Element) ScalarMultiplyByInteger(a *integer.Element) *Element
- func (q *Element) ScalarMultiplyByRational(a *Element) *Element
- func (q *Element) ScalarMultiplyByUint64(a uint64) *Element
- func (q *Element) Sign() int
- func (q *Element) String() string
- func (q *Element) ToInteger() (*integer.Element, error)
- func (q *Element) Uint64() (uint64, error)
- 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) Divide(x object.Element, y object.Element) (object.Element, error)
- func (R Parent) DotProduct(S1 []object.Element, S2 []object.Element) (object.Element, error)
- func (R Parent) FromInteger(n *integer.Element) object.Element
- func (R Parent) FromRational(q *Element) (object.Element, error)
- func (R Parent) Inverse(q object.Element) (object.Element, error)
- func (R Parent) IsOne(x object.Element) (bool, error)
- func (R Parent) IsUnit(q 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(q object.Element) (object.Element, error)
- func (R Parent) One() object.Element
- func (R Parent) Power(q object.Element, k *integer.Element) (object.Element, error)
- func (R Parent) Product(S ...object.Element) (object.Element, error)
- func (R Parent) ScalarMultiplyByInteger(n *integer.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 Slice
- type SortableSlice
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Element ¶
type Element struct {
// contains filtered or unexported fields
}
Element is an element of the field of rational numbers.
func AddInteger ¶
AddInteger returns x + y.
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 FromBigIntPair ¶
FromBigIntPair returns a/b as a rational. It will return an error if b is zero.
func FromInt32Pair ¶
FromInt32Pair returns a/b as a rational. It will return an error if b is zero.
func FromInt64Pair ¶
FromInt64Pair returns a/b as a rational. It will return an error if b is zero.
func FromIntPair ¶
FromIntPair returns a/b as a rational. It will return an error if b is zero.
func FromInteger ¶
FromInteger returns n as a rational.
func FromIntegerPair ¶
FromIntegerPair returns a/b as a rational. It will return an error if b is zero.
func FromString ¶
FromString returns the rational represented by the string s.
func FromUint64Pair ¶
FromUint64Pair returns a/b as a rational. It will return an error if b is zero.
func GobDecode ¶
GobDecode reads the next value from the given gob.Decoder and decodes it as a rational.
func GobDecodeSlice ¶
GobDecodeSlice reads the next value from the given gob.Decoder and decodes it as a slice of rationals.
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 MultiplyByIntegerThenAdd ¶
MultiplyByIntegerThenAdd 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 Product ¶
Product returns the product of the elements in the slice S. The product of the empty slice is one.
func SliceFromIntPairs ¶
SliceFromIntPairs returns a slice T generated by S, where 2 * len(T) = len(S) and T[i] = S[2 * i] / S[2 * i + 1].
func SliceFromIntSlice ¶
SliceFromIntSlice returns a slice of rationals corresponding to the integers in 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 a rational number. If necessary this will be done by first attempting to convert x to an integer, and then from an integer to a rational.
func (*Element) BigInt ¶
BigInt returns the rational as a *big.Int, or an error if this is not possible.
func (*Element) Denominator ¶
Denominator returns the denominator of q as an integer.
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) Int64 ¶
Int64 returns the rational as an int64, or an error if this is not possible.
func (*Element) IsEqualToInt64 ¶
IsEqualToInt64 returns true iff q = r.
func (*Element) IsEqualToInteger ¶
IsEqualToInteger returns true iff q = r.
func (*Element) IsEqualToUint64 ¶
IsEqualToUint64 returns true iff q = r.
func (*Element) IsGreaterThan ¶
IsGreaterThan returns true iff q > r.
func (*Element) IsGreaterThanInt64 ¶
IsGreaterThanInt64 returns true iff q > r.
func (*Element) IsGreaterThanInteger ¶
IsGreaterThanInteger returns true iff q > r.
func (*Element) IsGreaterThanOrEqualTo ¶
IsGreaterThanOrEqualTo returns true iff q >= r.
func (*Element) IsGreaterThanOrEqualToInt64 ¶
IsGreaterThanOrEqualToInt64 returns true iff q >= r.
func (*Element) IsGreaterThanOrEqualToInteger ¶
IsGreaterThanOrEqualToInteger returns true iff q >= r.
func (*Element) IsIntegral ¶
IsIntegral returns true iff q can be represented by an integer.
func (*Element) IsLessThan ¶
IsLessThan returns true iff q < r.
func (*Element) IsLessThanInt64 ¶
IsLessThanInt64 returns true iff q < r.
func (*Element) IsLessThanInteger ¶
IsLessThanInteger returns true iff q < r.
func (*Element) IsLessThanOrEqualTo ¶
IsLessThanOrEqualTo returns true iff q <= r.
func (*Element) IsLessThanOrEqualToInt64 ¶
IsLessThanOrEqualToInt64 returns true iff q <= r.
func (*Element) IsLessThanOrEqualToInteger ¶
IsLessThanOrEqualToInteger returns true iff q <= r.
func (*Element) Parent ¶
Parent returns the field of rational numbers as a object.Parent. This can safely be coerced to type Parent.
func (*Element) PowerInt64 ¶
PowerInt64 returns q^k.
func (*Element) ScalarMultiplyByInt64 ¶
ScalarMultiplyByInt64 returns the product a * q.
func (*Element) ScalarMultiplyByInteger ¶
ScalarMultiplyByInteger returns the product a * q.
func (*Element) ScalarMultiplyByRational ¶
ScalarMultiplyByRational returns the product a * q.
func (*Element) ScalarMultiplyByUint64 ¶
ScalarMultiplyByUint64 returns the product a * q.
type Parent ¶
type Parent struct{}
Parent represents the (unique) field of rational numbers.
func (Parent) Contains ¶
Contains returns true iff x is a rational number, or can naturally be regarded as a rational number.
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.
func (Parent) FromInteger ¶
FromInteger returns n as rational number.
func (Parent) FromRational ¶
FromRational returns q.
func (Parent) IsUnit ¶
IsUnit returns true iff q is a multiplicative unit (i.e. q is non-zero). If true, also returns the inverse element 1/q.
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 ¶
func (R 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, 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 Slice ¶
type Slice []*Element
Slice wraps an []*Element, implementing slice.Interface.
type SortableSlice ¶
type SortableSlice []*Element
SortableSlice implements the sort.Interface interface.
func (SortableSlice) Len ¶
func (S SortableSlice) Len() int
Len is the number of elements in the 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.