integervector

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 Imports: 14 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AreEqual

func AreEqual(x *Element, y *Element) bool

AreEqual returns true iff x and y have the same parent, and x = y.

func Cmp

func Cmp(x *Element, y *Element) (int, error)

Cmp returns -1 if x < y, 0 if x == y, and +1 if x > y. This will return an error if x and y do not have the same parent.

func DotProduct

func DotProduct(x *Element, y *Element) (*integer.Element, error)

DotProduct returns the dot-product of the n-dimensional integer vectors x and y. Here there is no condition on the parents of x and y. This will return an error if the dimensions differ.

Types

type Element

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

Element describes an integer-valued vector.

func Add

func Add(x *Element, y *Element) (*Element, error)

Add returns the vector sum x + y. This will return an error if x and y do not have the same parent.

func Basis

func Basis(M *Parent) []*Element

Basis returns the n-dimensional standard basis of M.

func ChangeParent

func ChangeParent(M *Parent, x object.Element) (*Element, error)

ChangeParent returns a copy of x with the parent set to the space M of n-dimensional integer-valued vectors. If x has a ToIntegerSlice method, this will be called to allow conversion. If x cannot be cast into M -- either because the dimensions or length of the slices disagree, or because there is no known way of automatically performing the conversion -- then an error will be returned.

func ConstantVector

func ConstantVector(M *Parent, c *integer.Element) *Element

ConstantVector returns an n-dimensional vector in M all of whose entries are c.

func CopySlice

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

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

func FromInt32Slice

func FromInt32Slice(M *Parent, S []int32) (*Element, error)

FromInt32Slice returns an n-dimensional vector in M with value S. This will return an error if the length of the slice does not agree with the dimension of M.

func FromInt64Slice

func FromInt64Slice(M *Parent, S []int64) (*Element, error)

FromInt64Slice returns an n-dimensional vector in M with value S. This will return an error if the length of the slice does not agree with the dimension of M.

func FromIntSlice

func FromIntSlice(M *Parent, S []int) (*Element, error)

FromIntSlice returns an n-dimensional vector in M with value S. This will return an error if the length of the slice does not agree with the dimension of M.

func FromIntegerSlice

func FromIntegerSlice(M *Parent, S []*integer.Element) (*Element, error)

FromIntegerSlice returns an n-dimensional vector in M with value S. This will return an error if the length of the slice does not agree with the dimension of M.

func FromString

func FromString(M *Parent, s string) (*Element, error)

FromString returns the n-dimensional vector in M represented by the string s.

func FromUint64Slice

func FromUint64Slice(M *Parent, S []uint64) (*Element, error)

FromUint64Slice returns an n-dimensional vector in M with value S. This will return an error if the length of the slice does not agree with the dimension of M.

func GobDecode

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

GobDecode reads the next value from the given gob.Decoder and decodes it as an integer-valued vector. The decoded vector will lie in the default lattice of appropriate dimension.

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 integer-valued vectors. The decoded vectors will lie in the default lattice of appropriate dimension.

func NCopiesToSlice

func NCopiesToSlice(a *Element, N int) []*Element

NCopiesToSlice returns a slice of length N containing the element a.

func Negate

func Negate(x *Element) *Element

Negate returns -x.

func NthBasisElement

func NthBasisElement(M *Parent, n int) (*Element, error)

NthBasisElement returns the n-th standard basis element of M. Here the basis elements are indexed from 0 to d-1 (inclusive), where d is the dimension of M.

func ScalarMultiplyByIntegerThenAdd

func ScalarMultiplyByIntegerThenAdd(a *integer.Element, x *Element, y *Element) (*Element, error)

ScalarMultiplyByIntegerThenAdd returns a * x + y, where a is an integer, and x and y are vectors. This will return an error if x and y do not have the same parent.

func ScalarMultiplyByIntegerThenSubtract

func ScalarMultiplyByIntegerThenSubtract(a *integer.Element, x *Element, y *Element) (*Element, error)

ScalarMultiplyByIntegerThenSubtract returns a * x - y, where a is an integer, and x and y are vectors. This will return an error if x and y do not have the same parent.

func Sort

func Sort(S []*Element) ([]*Element, error)

Sort non-destructively sorts the given slice of integer-valued vectors. The sorted slice is returned. All vectors must have the same parent, otherwise an error will be returned.

func Subtract

func Subtract(x *Element, y *Element) (*Element, error)

Subtract returns the vector different x - y. This will return an error if x and y do not have the same parent.

func Sum

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

Sum returns the sum of the elements in the slice S. The sum of the empty slice is the zero element of M. This will return an error if the elements of S do not all have M as their parent.

func ToElement

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

ToElement returns the argument as an n-dimensional integer-valued vector in the given parent, if that's where it belongs. If necessary, if M is 1-dimensional then an attempt will be made to convert x to an integer, which will then be returned as an element in k.

func Zero

func Zero(M *Parent) *Element

Zero returns the n-dimensional zero vector in M.

func (*Element) DecrementEntry

func (x *Element) DecrementEntry(i int) (*Element, error)

DecrementEntry returns a new n-dimensional vector equal to x, but with the i-th entry decremented by one. Entries are indexed from 0 up to one less than the dimension of the parent of x (inclusive). This will return an error if i is out of range.

func (*Element) DecrementEntryOrPanic

func (x *Element) DecrementEntryOrPanic(i int) *Element

DecrementEntryOrPanic returns a new n-dimensional vector equal to x, but with the i-th entry decremented by one. Entries are indexed from 0 up to one less than the dimension of the parent of x (inclusive). This will panic if i is out of range.

func (*Element) Dimension

func (x *Element) Dimension() int

Dimension returns the dimension of the parent of the vector x.

func (*Element) Entry

func (x *Element) Entry(i int) (*integer.Element, error)

Entry returns the i-th entry in the vector x, where the entries are indexed from 0 up to one less than the dimension of the parent of x (inclusive). This will return an error if i is out of range.

func (*Element) EntryOrPanic

func (x *Element) EntryOrPanic(i int) *integer.Element

EntryOrPanic returns the i-th entry in the vector x, where the entries are indexed from 0 up to one less than the dimension of the parent of x (inclusive). This will panic if i is out of range.

func (*Element) GobDecode

func (x *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. The decoded vector will lie in the default lattice of appropriate dimension.

func (*Element) GobEncode

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

GobEncode implements the gob.GobEncoder interface.

func (*Element) Hash

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

Hash returns a hash value for this vector.

func (*Element) IncrementEntry

func (x *Element) IncrementEntry(i int) (*Element, error)

IncrementEntry returns a new n-dimensional vector equal to x, but with the i-th entry incremented by one. Entries are indexed from 0 up to one less than the dimension of the parent of x (inclusive). This will return an error if i is out of range.

func (*Element) IncrementEntryOrPanic

func (x *Element) IncrementEntryOrPanic(i int) *Element

IncrementEntryOrPanic returns a new n-dimensional vector equal to x, but with the i-th entry incremented by one. Entries are indexed from 0 up to one less than the dimension of the parent of x (inclusive). This will panic if i is out of range.

func (*Element) IsEqualTo

func (x *Element) IsEqualTo(y *Element) bool

IsEqualTo returns true iff x and y have the same parent, and x = y.

func (*Element) IsGreaterThan

func (x *Element) IsGreaterThan(y *Element) bool

IsGreaterThan returns true iff x and y have the same parent, and x > y.

func (*Element) IsGreaterThanOrEqualTo

func (x *Element) IsGreaterThanOrEqualTo(y *Element) bool

IsGreaterThanOrEqualTo returns true iff x and y have the same parent, and x >= y.

func (*Element) IsLessThan

func (x *Element) IsLessThan(y *Element) bool

IsLessThan returns true iff x and y have the same parent, and x < y.

func (*Element) IsLessThanOrEqualTo

func (x *Element) IsLessThanOrEqualTo(y *Element) bool

IsLessThanOrEqualTo returns true iff x and y have the same parent, and x <= y.

func (*Element) IsNegative

func (x *Element) IsNegative() bool

IsNegative returns true iff x < 0.

func (*Element) IsPositive

func (x *Element) IsPositive() bool

IsPositive returns true iff x > 0.

func (*Element) IsZero

func (x *Element) IsZero() bool

IsZero returns true iff x is the zero vector (0,0,...,0).

func (*Element) Negate

func (x *Element) Negate() *Element

Negate returns the negation -x.

func (*Element) Parent

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

Parent returns the parent of this vector.

func (*Element) ScalarMultiplyByInt64

func (x *Element) ScalarMultiplyByInt64(a int64) *Element

ScalarMultiplyByInt64 returns the scalar product a * x, where a is an integer.

func (*Element) ScalarMultiplyByInteger

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

ScalarMultiplyByInteger returns the scalar product a * x, where a is an integer.

func (*Element) ScalarMultiplyByUint64

func (x *Element) ScalarMultiplyByUint64(a uint64) *Element

ScalarMultiplyByUint64 returns the scalar product a * x, where a is an integer.

func (*Element) Sign

func (x *Element) Sign() int

Sign returns -1 if x < 0, 0 if x == 0, and +1 if x > 0.

func (*Element) String

func (x *Element) String() string

String returns a string representation of the vector.

func (*Element) ToInt64Slice

func (x *Element) ToInt64Slice() ([]int64, error)

ToInt64Slice returns the vector as a slice of int64s. It returns an error if any of the entries is too large to fit in an int64.

func (*Element) ToIntegerSlice

func (x *Element) ToIntegerSlice() []*integer.Element

ToIntegerSlice returns the vector as a slice of integers. Note that you can modify the returned slice without affecting the vector.

func (*Element) TotalDegree

func (x *Element) TotalDegree() *integer.Element

TotalDegree returns the total degree of the vector x. That is, it returns the sum of the entries in x.

type Parent

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

Parent is an n-dimensional ZZ-module.

func DefaultLattice

func DefaultLattice(n int) (*Parent, error)

DefaultLattice returns the default space of n-dimensional integer-valued vectors with lex ordering. This is provided for use when the particular space the vector lives in is either currently undetermined, or doesn't matter. Calls to DefaultLattice (with the same value of n) always return the same n-dimensional space. This will return an error if n is negative.

func DefaultLatticeWithOrder

func DefaultLatticeWithOrder(n int, c monomialorder.Type) (*Parent, error)

DefaultLatticeWithOrder returns the default space of n-dimensional integer-valued vectors with given ordering. This is provided for use when the particular space the vector lives in is either currently undetermined, or doesn't matter. Calls to DefaultLattice (with the same value of n) always return the same n-dimensional space. This will return an error if n is negative.

func NewLattice

func NewLattice(n int) (*Parent, error)

NewLattice returns a new space of n-dimensional integer-valued vectors with lex ordering. That is, it returns a copy of ZZ^n. Note that two different copies of ZZ^n will be regarded as being distinct. This will return an error if n is negative.

func NewLatticeWithOrder

func NewLatticeWithOrder(n int, c monomialorder.Type) (M *Parent, err error)

NewLatticeWithOrder returns a new space of n-dimensional integer-valued vectors with given ordering. That is, it returns a copy of ZZ^n. Note that two different copies of ZZ^n will be regarded as being distinct. This will return an error if n is negative.

func (*Parent) Add

Add returns the sum x + y of the n-dimensional vectors x and y in M.

func (*Parent) AreEqual

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

AreEqual returns true iff x and y are both contained in M, and x = y.

func (*Parent) AssignName

func (M *Parent) AssignName(name string)

AssignName assigns a name to M to be used by String.

func (*Parent) Basis

func (M *Parent) Basis() []object.Element

Basis returns the standard basis of M.

func (*Parent) Cmp

func (M *Parent) Cmp(x object.Element, y object.Element) (int, error)

Cmp returns -1 if x < y, 0 if x == y, and +1 if x > y.

func (*Parent) Contains

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

Contains returns true iff x is an n-dimension vector in M. Note that we do not allow a natural isomorphism between two different parent ZZ-modules, hence it is not sufficient that the dimensions agree.

func (*Parent) Dimension

func (M *Parent) Dimension() int

Dimension returns the dimension of M.

func (*Parent) InclusionMap

func (M *Parent) InclusionMap(i int) (objectmap.Interface, error)

InclusionMap returns the inclusion ZZ -> M into the (i+1)-th factor of the of M. This is, the inclusion maps are indexed from 0.

func (*Parent) IsZero

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

IsZero returns true iff x is the n-dimensional zero vector in M.

func (*Parent) MonomialOrder

func (M *Parent) MonomialOrder() monomialorder.Type

MonomialOrder returns the monomial order being used to order the elements of M.

func (*Parent) Negate

func (M *Parent) Negate(x object.Element) (object.Element, error)

Negate returns the negation -x of the n-dimensional vector x in M.

func (*Parent) NthBasisElement

func (M *Parent) NthBasisElement(n int) (object.Element, error)

NthBasisElement returns the n-th standard basis element of M. Here the basis elements are indexed from 0 to d-1 (inclusive), where d is the dimension of M.

func (*Parent) ProjectionMap

func (M *Parent) ProjectionMap(i int) (objectmap.Interface, error)

ProjectionMap returns the projection M -> ZZ onto the (i+1)-th factor of M. That is, projection maps are indexed from 0.

func (*Parent) Rank

func (M *Parent) Rank() int

Rank returns the dimension of M.

func (*Parent) ScalarMultiplyByInteger

func (M *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

func (M *Parent) Sort(S []object.Element) ([]object.Element, error)

Sort non-destructively sorts the given slice of integer-valued vectors. The sorted slice is returned.

func (*Parent) String

func (M *Parent) String() string

String returns a string representation of M.

func (*Parent) Subtract

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

Subtract returns the difference x - y of the n-dimensional vectors x and y in M.

func (*Parent) Sum

func (M *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 the zero element of M.

func (*Parent) ToElement

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

ToElement returns x as an element of this parent, or an error if x cannot naturally be regarded as an element of this parent.

func (*Parent) Zero

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

Zero returns the n-dimensional zero vector in M.

type Slice

type Slice []*Element

Slice implements the slice.Interface for a slice of Elements.

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) Hash

func (S Slice) Hash() hash.Value

Hash returns a hash value for this slice.

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.

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) Sort

func (S SortableSlice) Sort()

Sort sorts the slice in place.

func (SortableSlice) Swap

func (S SortableSlice) Swap(i int, j int)

Swap swaps the elements with indexes i and j.

Jump to

Keyboard shortcuts

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