next | previous | forward | backward | up | top | index | toc | Macaulay2 web site
Macaulay2Doc > The Macaulay2 language > hash tables > merge(HashTable,HashTable,Function)

merge(HashTable,HashTable,Function) -- merge hash tables

Synopsis

Description

If x and y have the same class and have the same parent, then so will z.

This function is useful for multiplying monomials or adding polynomials. We illustrate that with a simple-minded implmentation of the free abelian group on the set of strings, representing an element as a type of hash table that associates coefficients to strings.

i1 : Free = new Type of HashTable

o1 = Free

o1 : Type
i2 : p = new Free from { "x" => 2, "y" => 3, "cat" => 5 }

o2 = Free{cat => 5}
          x => 2
          y => 3

o2 : Free
i3 : q = new Free from { "x" => 100, "y" => 200, "dog" => 7 }

o3 = Free{dog => 7}
          x => 100
          y => 200

o3 : Free
i4 : Free + Free := (p,q) -> merge(p,q,plus);
i5 : p+q

o5 = Free{cat => 5}
          dog => 7
          x => 102
          y => 203

o5 : Free

See also