11.07.2015 Views

Advanced Programming Guide

Advanced Programming Guide

Advanced Programming Guide

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

A.3 The Use of Hashing in Maple • 369against the table. Garbage collection deletes the entries in the simplificationtable that cannot be reached from a global name or from a live localvariable.The task of checking for equivalent expressions within thousands ofsubexpressions would not be feasible if it were not done with the aid ofhashing. Every expression is entered in the simplification table using itssignature as a key. The signature of an expression is a hashing functionitself, with one very important attribute: signatures of trivially equivalentexpressions are equal. For example, the signatures of the expressions a +b + c and c + a + b are identical; the signatures of a ∗ b and b ∗ a arealso identical. If two expressions’ signatures disagree then the expressionscannot be equal at the basic level of simplification.Searching for an expression in the simplification table is done by:• Simplifying recursively all of its components• Applying the basic simplification rules• Computing its signature and searching for this signature in the tableIf the signature is found, then a full comparison is performed (takinginto account that additions and multiplications are commutative) toverify that it is the same expression. If the expression is found, the onein the table is used and the searched one is discarded. A full comparisonof expressions has to be performed only when there is a collision ofsignatures.Since simplified expressions are guaranteed to have a unique occurrence,it is possible to test for equality of simplified expressions using asingle pointer comparison. Unique representation of identical expressionsis a crucial ingredient to the efficiency of tables, hence also the rememberoption. Also, since the relative order of objects is preserved during garbagecollection, this means that sequences of objects can be ordered by machineaddress. For example, sets in Maple are represented this way. Theset operations, such as union or intersection, can be done in linear timeby merging sorted sequences. Sorting by machine address is also availableto the user with the sort command.The Name TableThe simplest use of hashing in the Maple kernel is the name table. Thisis a symbol table for all global names. Each key is computed from thename’s character string and the entry is a pointer to the data structurefor the name. The name table is used to locate global names formed by

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!