next | previous | forward | backward | up | top | index | toc | Macaulay2 website
Macaulay2Doc > The Macaulay2 language > hash tables > combine

combine -- combine hash tables

Synopsis

Description

The function f is applied to every pair (p,q) where p is a key of x and q is a key of y. The number of times f is evaluated is thus the product of the number of keys in x and the number of keys in y.

The function h should be an associative function, for otherwise the result may depend on internal details about the implementation of hash tables that affect the order in which entries are encountered. If f, g, and h are commutative functions as well, then the result z is a commutative function of x and y.

The result is mutable if and only if x or y is.

This function can be used for multiplying polynomials, where it can be used in code something like this:

     combine(x, y, monomialTimes, coeffTimes, coeffPlus)
We illustrate that with a simple-minded implmentation of the free ring on the English alphabet, representing words as string and polynomials as hash tables that associate coefficients to words.
i1 : Poly = new Type of HashTable

o1 = Poly

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

o2 = Poly{ => 1   }
          cat => 5
          x => 2
          y => 3

o2 : Poly
i3 : Poly * Poly := (p,q) -> combine(p,q,concatenate,times,plus);
i4 : p*p

o4 = Poly{ => 1       }
          cat => 10
          catcat => 25
          catx => 10
          caty => 15
          x => 4
          xcat => 10
          xx => 4
          xy => 6
          y => 6
          ycat => 15
          yx => 6
          yy => 9

o4 : Poly

See also

For the programmer

The object combine is a compiled function.