This repository was archived by the owner on Jan 30, 2023. It is now read-only.
Commit 798aaf8 1 parent fa16bc7 commit 798aaf8 Copy full SHA for 798aaf8
File tree 1 file changed +36
-2
lines changed
src/sage/rings/polynomial
1 file changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -13,8 +13,9 @@ AUTHORS:
13
13
14
14
- Simon King: Use a faster way of conversion from the base ring.
15
15
16
- - Julian Rueth (2012-05-25): Fixed is_squarefree() for imperfect fields.
17
- Fixed division without remainder over QQbar.
16
+ - Julian Rueth (2012-05-25,2014-05-09): Fixed is_squarefree() for imperfect
17
+ fields, fixed division without remainder over QQbar, added ``_cache_key``
18
+ for polynomials with unhashable coefficients
18
19
19
20
- Simon King (2013-10): Implement copying of :class:`PolynomialBaseringInjection`.
20
21
@@ -829,6 +830,39 @@ cdef class Polynomial(CommutativeAlgebraElement):
829
830
def __iter__ (self ):
830
831
return iter (self .list())
831
832
833
+ def _cache_key (self ):
834
+ """
835
+ Return a key which uniquely identifies this element among all elements
836
+ in the parent.
837
+
838
+ .. SEEALSO::
839
+
840
+ :meth:`sage.structure.sage_object.SageObject._cache_key`
841
+
842
+ EXAMPLES:
843
+
844
+ This enables caching for polynomials with unhashable coefficients such
845
+ as `p`-adics::
846
+
847
+ sage: K.<u> = Qq(4)
848
+ sage: R.<x> = K[]
849
+ sage: f = x
850
+ sage: hash(f)
851
+ Traceback (most recent call last):
852
+ ...
853
+ TypeError: unhashable type: 'sage.rings.padics.padic_ZZ_pX_CR_element.pAdicZZpXCRElement'
854
+ sage: f._cache_key()
855
+ (0, 1 + O(2^20))
856
+
857
+ sage: @cached_function
858
+ ....: def foo(t): return t
859
+ ....:
860
+ sage: foo(x)
861
+ (1 + O(2^20))*x
862
+
863
+ """
864
+ return tuple (self )
865
+
832
866
# you may have to replicate this boilerplate code in derived classes if you override
833
867
# __richcmp__. The python documentation at http://docs.python.org/api/type-structs.html
834
868
# explains how __richcmp__, __hash__, and __cmp__ are tied together.
You can’t perform that action at this time.
0 commit comments