[Maxima] [Maxima-commits] CVS: maxima/share/contrib/graphs graph_core.lisp, 1.15, 1.16
elzacho at gmail.com
Tue May 6 12:31:57 CDT 2008
I am guessing that the gurus are going to correct me here, but this is my
understanding (which seems to fit observed behavior). Please excuse my
Common Lisp, and hence Maxima (using CL hash tables) can hash on arbitrary
objects/values. However, the way an object is hashed depends on the test
function. The test function that CL uses to determine the equivalence of
two keys can only be set to the functions #'eq, #'eql, #'equal, and
#'equalp. It looks like Stavros' and Raymond's comments show good reasons
Upon creation, the hash table must determine what hashing function will be
useful for the test you asked for. For example:
(let ((lst '(1 2 3)))
(eql lst (copy-list lst)) )
(let ((lst '(1 2 3)))
(equal lst (copy-list lst)) )
If a hash table's test is #'equal, the hashing function must hash the actual
contents of the list. While if it is just #'eql, the hash function doesn't
need to do that much work. In fact it would be erroneous for the #'eql hash
table to examine all the list since that is not what we asked of it.
This seems pretty good, does Perl have better capabilities? I cannot think
of situations that require other tests off the top of my head (but there
must be some or CMU wouldn't have bothered with extending their hash
tables). In Maxima, I think all objects are trees with symbols or numbers
for leaves. Using #'equal should recursively search the tree for
differences. Thus the hash table knows it must hash on the entire tree.
This seems right and it explains we you see no problems with get_hash and
set_hash. I suppose that the expression must be is the same form though,
not just equivalent in a mathematical sense.
On Mon, May 5, 2008 at 5:34 PM, Oliver Kullmann <O.Kullmann at swansea.ac.uk>
> Even Perl hashes arbitrary values.
> In Maxima it should be simple:
> Isn't every object a term? So just evaluate this term,
> take it as a string, use a standard hash function for
> strings, and use bucket hashing.
> So do you say that in Maxima you don't have general hash-table
> But the hash-table from the graphs-package works normally!
> It is just that under certain circumstances, which I still
> don't understand, it does this annotation business.
> For example:
> h : hash_table();
> set_hash(,h, 20);
> Looks all perfectly reasonable to me.
> Only under certain circumstances, as this example in my
> reply in the original thread shows, Maxima or CLisp (perhaps
> the latter) starts distinguishing identical terms.
> What is the effect of your change below (I don't know that alike1)?
> Will it disable the mostly correct working of that graphs-hash-table
> (and I have quite extensive tests running)??
> On Mon, May 05, 2008 at 04:48:11PM -0400, Raymond Toy (RT/EUS) wrote:
> > Andrej Vodopivec wrote:
> > > Update of /cvsroot/maxima/maxima/share/contrib/graphs
> > > In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv13769
> > >
> > > Modified Files:
> > > graph_core.lisp
> > > Log Message:
> > > Use alike1 instead of equal in user defined hash tables.
> > >
> > >
> > > Index: graph_core.lisp
> > > ===================================================================
> > > RCS file:
> > > retrieving revision 1.15
> > > retrieving revision 1.16
> > > diff -u -d -r1.15 -r1.16
> > > --- graph_core.lisp 25 Apr 2008 13:54:22 -0000 1.15
> > > +++ graph_core.lisp 5 May 2008 20:38:42 -0000 1.16
> > > @@ -2008,7 +2008,7 @@
> > > ;;;;;;
> > >
> > > (defun $hash_table ()
> > > - (make-hash-table :test #'equal))
> > > + (make-hash-table :test #'alike1))
> > You can't use an arbitrary test in a Common Lisp hash table. Some lisps
> > will allow you to define your own, but that's not portable.
> > Ray
> > _______________________________________________
> > Maxima mailing list
> > Maxima at math.utexas.edu
> > http://www.math.utexas.edu/mailman/listinfo/maxima
> Maxima mailing list
> Maxima at math.utexas.edu
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Maxima