#16316: cached_function and cached_method for unhashable elements
-------------------------------------+-------------------------------------
       Reporter:  saraedum           |        Owner:
           Type:  enhancement        |       Status:  needs_review
       Priority:  minor              |    Milestone:  sage-6.3
      Component:  misc               |   Resolution:
       Keywords:                     |    Merged in:
        Authors:  Julian Rueth       |    Reviewers:
Report Upstream:  N/A                |  Work issues:
         Branch:                     |       Commit:
  u/saraedum/ticket/16316            |  a65ac8524294fde91e021c39b9f227277ec33d23
   Dependencies:  #16251             |     Stopgaps:
-------------------------------------+-------------------------------------

Comment (by pbruin):

 It seems that the problem really has to do with key comparison in
 dictionaries, not with hashing or caching specifically.  Given (1)
 Python's use of `==` for key comparison and (2) Sage's lenient
 implementation of `==` for elements, we basically cannot use Sage elements
 as dictionary keys.

 One would like a third comparison operator, say `equal`^1^, that regards
 two objects as equal if and only if all their "mathematically relevant"
 properties (e.g. value and precision for real or ''p''-adic numbers, but
 not memory location) are the same.  Our caching problems would then
 disappear if keys were compared using `equal`.  In this hypothetical case,
 the correct property for hash functions would be `X equal Y` => `hash(X)
 == hash(Y)`.

 - Do I understand correctly that the purpose of `cache_key` can be viewed
 as emulating the "missing" `equal` by assigning to each object `X` a
 (hashable) object `cache_key(X)` satisfying the condition `cache_key(X) ==
 cache_key(Y)` <=> `X equal Y` ?

 - If so, does the implementation in this ticket satisfy this condition?
 (I am mainly worried that the parent of an element `x` does not seem to be
 encoded in `cache_key(x)`.)

 ^1^ I just looked up the different comparison functions (`=`, `eq`, `eql`,
 `equal` and `equalp`) in Lisp and `equal` seems to be the closest to what
 we would need, hence I am using that notation.  However, Lisp uses `eql`
 by default for hash tables.

--
Ticket URL: <http://trac.sagemath.org/ticket/16316#comment:8>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to