<?xml version="1.0" encoding="utf-8" ?> <!-- for emacs: -*- coding: utf-8 -*- --> <!-- Apache may like this line in the file .htaccess: AddCharset utf-8 .html --> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg-flat.dtd" > <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head><title>merge(HashTable,HashTable,Function) -- merge hash tables</title> <link rel="stylesheet" type="text/css" href="../../../../Macaulay2/Style/doc.css"/> </head> <body> <table class="buttons"> <tr> <td><div><a href="_combine.html">next</a> | <a href="_apply__Pairs.html">previous</a> | <a href="_combine.html">forward</a> | <a href="_apply__Pairs.html">backward</a> | <a href="_hash_sptables.html">up</a> | <a href="index.html">top</a> | <a href="master.html">index</a> | <a href="toc.html">toc</a> | <a href="http://www.math.uiuc.edu/Macaulay2/">Macaulay2 web site</a></div> </td> </tr> </table> <div><a href="index.html" title="">Macaulay2Doc</a> > <a href="___The_sp__Macaulay2_splanguage.html" title="">The Macaulay2 language</a> > <a href="_hash_sptables.html" title="">hash tables</a> > <a href="_merge_lp__Hash__Table_cm__Hash__Table_cm__Function_rp.html" title="merge hash tables">merge(HashTable,HashTable,Function)</a></div> <hr/> <div><h1>merge(HashTable,HashTable,Function) -- merge hash tables</h1> <div class="single"><h2>Synopsis</h2> <ul><li><div class="list"><dl class="element"><dt class="heading">Usage: </dt><dd class="value"><div><tt>z = merge(x,y,g)</tt></div> </dd></dl> </div> </li> <li><span>Function: <a href="_merge_lp__Hash__Table_cm__Hash__Table_cm__Function_rp.html" title="merge hash tables">merge</a></span></li> <li><div class="single">Inputs:<ul><li><span><tt>x</tt>, <span>a <a href="___Hash__Table.html">hash table</a></span></span></li> <li><span><tt>y</tt>, <span>a <a href="___Hash__Table.html">hash table</a></span></span></li> <li><span><tt>g</tt>, <span>a <a href="___Function.html">function</a></span>, a function of two variables to be used to combine a value of <tt>x</tt> with a value of <tt>y</tt> when the corresponding keys coincide.</span></li> </ul> </div> </li> <li><div class="single">Outputs:<ul><li><span><tt>z</tt>, <span>a <a href="___Hash__Table.html">hash table</a></span>, a new hash table whose keys are the keys occurring in <tt>x</tt> or in <tt>y</tt>; the same values are used, except that if if a key <tt>k</tt> occurs in both arguments, then <tt>g(x#k,y#k)</tt> is used instead, unless <tt>g</tt> evaluated <a href="_continue.html" title="continue with the next iteration of a loop">continue</a>, in which case the key <tt>k</tt> does not appear in the result.</span></li> </ul> </div> </li> </ul> </div> <div class="single"><h2>Description</h2> <div>If <tt>x</tt> and <tt>y</tt> have the same class and have the same parent, then so will <tt>z</tt>.<p>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.</p> <table class="examples"><tr><td><pre>i1 : Free = new Type of HashTable o1 = Free o1 : Type</pre> </td></tr> <tr><td><pre>i2 : p = new Free from { "x" => 2, "y" => 3, "cat" => 5 } o2 = Free{cat => 5} x => 2 y => 3 o2 : Free</pre> </td></tr> <tr><td><pre>i3 : q = new Free from { "x" => 100, "y" => 200, "dog" => 7 } o3 = Free{dog => 7} x => 100 y => 200 o3 : Free</pre> </td></tr> <tr><td><pre>i4 : Free + Free := (p,q) -> merge(p,q,plus);</pre> </td></tr> <tr><td><pre>i5 : p+q o5 = Free{cat => 5} dog => 7 x => 102 y => 203 o5 : Free</pre> </td></tr> </table> </div> </div> <div class="single"><h2>See also</h2> <ul><li><span><a href="_combine.html" title="combine hash tables">combine</a> -- combine hash tables</span></li> </ul> </div> </div> </body> </html>