Implementation of integer-based torsion-free Abelian Group in Go.
go get github.com/nickng/abelian
Example: creating a group
// This example shows how to create an Integer-pair abelian group.
s := set.NewIntTuple(2) // tuple size set to 2
g := abelian.New(s, s.Add)
// The following g.Op is the + operation for pairs,
// hence the output is (1,2) + (2,3) = (3,5)
//
output := g.Op(s.Tuple(1, 2), s.Tuple(2, 3))
fmt.Println("Group:", g.String())
fmt.Println(output)
// prints out (3,5)
Example: enumerating a finite subset
// This example shows how to enumerate a 2D-interval.
s := set.NewIntTuple(2)
g := abelian.New(s, s.Add)
// The given Set s implements
// - LessEqual(x, y Elem) bool
// - Interval(lo, hi Elem) Enumerable
subset := g.Set.(prop.PartialOrdered).Interval(s.Tuple(1, 1), s.Tuple(2, 2))
for i, tuple := range subset.Slice() {
fmt.Println(tuple)
}
// prints out (1,1) (1,2) (2,1) (2,2)
More examples can be found in GoDoc.
abelian is licensed under the Apache License