[Maxima-commits] CVS: maxima/share/contrib/graphs graph_core.lisp, 1.15, 1.16



Oliver,

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
nonsensical dribble.

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
why.

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)) )
==> NIL

(let ((lst '(1 2 3)))
   (equal lst (copy-list lst)) )
==> T

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.

Zach


On Mon, May 5, 2008 at 5:34 PM, Oliver Kullmann <O.Kullmann at swansea.ac.uk>
wrote:

> 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
> functionality??
>
> 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:
> load(graphs);
> h : hash_table();
> set_hash([1.1],h,5);
> set_hash({1},h,10);
> set_hash([1],h, 20);
> set_hash(7,h,30);
>
> get_hash([1.1],h);
> get_hash({1},h);
> get_hash([1],h);
> get_hash(7,h);
>
> print(h);
>
> 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)??
>
> Oliver
>
>
> 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:
> /cvsroot/maxima/maxima/share/contrib/graphs/graph_core.lisp,v
> > > 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
> http://www.math.utexas.edu/mailman/listinfo/maxima
>