-
-
Notifications
You must be signed in to change notification settings - Fork 480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make p-adic numbers unhashable #11895
Comments
comment:1
Apply 11895.patch |
Attachment: 11895.patch.gz Creates a hash function for extension elements |
comment:3
Can you clean up the formatting of the docstrings a bit? There's a general convention that long lines in docstrings (except doctests!) should be wrapped at 80 columns and trailing whitespace removed. Other than that this looks fine to me. |
Work Issues: whitespace, line wrapping in docstrings |
Author: David Roe |
Reviewer: David Loeffler |
comment:5
When trying the input:
I get the following error:
|
comment:6
Three remarks:
Properties 2 and 3 conspire to hide the problem a bit:
so the entry under f isn't found when looking up g because they end up being stored in different bins, so the difference in hash is enough to distinguish them. As soon as the dictionary gets resized in a way that lets those two hashes end up in the same bin, it'll be a toss-up which answer you get back from either To show that functions that depend on more of their arguments than just equality should not be cached:
|
comment:7
Nils, I agree that there are some horrible compromises to be had on this issue. I would like to make p-adic elements unhashable, but there are some nasty consequences of doing so. We can't add points on elliptic curves over p-adic fields. We can't print matrices. Out of curiousity I tried changing the hash methods on elements of Zp and Qp to raise a I don't know what the answer is. If we can come to a consensus on this I'm happy to fix the whitespace issues. :-) |
comment:8
I had a look into this. Except for one place (which could certainly be worked around somehow), the doctests seem to fail because caching doesn't work anymore. Would there be something wrong with adding a I gave it a try (see attached patch). The only doctests that fail seem to be a few places where |
experimental patch to disable caching for padics |
comment:9
Attachment: cache.patch.gz |
Dependencies: #15897 |
Branch: u/saraedum/ticket/11895 |
Changed branch from u/saraedum/ticket/11895 to none |
Branch: u/saraedum/ticket/11895 |
Changed reviewer from David Loeffler to none |
This comment has been minimized.
This comment has been minimized.
Changed author from David Roe to none |
Changed work issues from whitespace, line wrapping in docstrings to one pickle from the pickle jar does not unpickle correctly |
comment:41
Added Simon since we talked about this in Bad Boll a while ago. |
comment:43
The ticket description mentions a problem when comparing Just making elements not hashable is also terrible, many algorithms use sets and dicts. E.g. if the coefficient field is not hashable then you can't compute groebner bases in polynomial rings, rendering it essentially useless. |
comment:44
Replying to @vbraun:
I'm not sure I understand. Say you are in Qp with 2 digits of precision. Then 0 coerces to
I agree that disabling hashing has its drawbacks but I do not see an alternative. Judging from the doctests, not that many things break, actually. But I guess that some algorithms have to be modified to support unhashable elements if we want to use them with p-adic numbers. |
comment:45
Replying to @saraedum:
Ok, I hadn't thought about that. But IMHO thats more of an issue with having two separate and competing ways of specifying precision, one in the parent and one in the element:
I don't have a good answer right now either, but it once again shows the importance of this issue. We need to fix our failure to adhere to Python's convention about comparison and hashes. |
Stopgaps: todo |
comment:47
Replying to @vbraun:
Is it really about competing ways? I guess this happens because it is possible to specify precision in the element at all.
The problem is that sometimes you want |
Changed keywords from hash to hash, days71 |
comment:48
We are abandoning this in favor of #20246. |
Only fixed modulus p-adic numbers should be hashable, all others can not implement a reasonable hash function. Currently some of them do which can cause horrible bugs:
The problem here is that
==
has been changed so that two numbers are equal if they are equal to the least common precision. In this example, the two elements are equal to precision one and they have the same hash value (at least on my machine).The proposal of this ticket is to make p-adics unhashable (but cacheable through #16316). The modifications required for this to work are almost always related to functions which implemented manual caching through dictionaries. The long list of dependencies is mostly about rewriting constructor functions to go through
UniqueFactory
orCachedRepresentation
which gets unhashable elements right as of #16317. (I believe that these changes are valuable refactorings anyway.)I can imagine that some people will not like such a change. What are the alternatives?
==
is not used bycached_method
and friends. (Not an option, because p-adics may be wrapped inside other objects which will still use their operator==
.)==
for p-adics to say whether two numbers are "really" equal. (Bad idea. Say you are in a p-adic field. Some algorithm wants to know whetherx
is invertible and saysx==0
. Now this will be false for mostp
-adic zeros.)__hash__
return a constant. (This would work but will give horrible performance.)Depends on #11670
Depends on #15897
Depends on #15898
Depends on #15956
Depends on #16122
Depends on #16124
Depends on #16129
Depends on #16250
Depends on #16251
Depends on #16316
Depends on #16317
Depends on #16318
Depends on #16321
Depends on #16339
Depends on #16341
Depends on #16342
CC: @roed314 @simon-king-jena
Component: padics
Keywords: hash, days71
Stopgaps: todo
Work Issues: one pickle from the pickle jar does not unpickle correctly
Branch/Commit: u/saraedum/ticket/11895 @
42afa4d
Issue created by migration from https://trac.sagemath.org/ticket/11895
The text was updated successfully, but these errors were encountered: