Hi Kwankyu,

On 2012-05-03, Kwankyu Lee <ekwan...@gmail.com> wrote:
> In Sage 5.0rc0, I observe a weird phenomenon. See the following code 
> -----
> But the following modified code results in an error. The difference is the 
> addition of the method "_repr_".
> -----
> from sage.rings.ring import CommutativeAlgebra
>
> class NA(CommutativeAlgebra):
>     """
>     """
>
>     def __init__(self, i):
>         """
>         """
>         CommutativeAlgebra.__init__(self, i.base_ring())
>         self._ideal = i
>
>     def _repr_(self):
>         return "NA defined by %s." % self._ideal  

The reason is that in sage-5.0, all rings will (should, at least) have
proper initialisation required to make the category framework work.

That means, self._init_category is indirectly called in the line
  CommutativeAlgebra.__init__(self, i.base_ring())

However, during the category initialisation, self is used as key in
some cache. Hence, it is needed that its hash value is available. By
default in sage.rings.ring.Ring, hash(self) is the self as hash(repr(self))
(which I don't like, by the way). But that happens *before* you set self._ideal,
thus, the crash.

There are two possible solutions: Either do
    def __init__(self, i):
        self._ideal = i
        CommutativeAlgebra.__init__(self, i.base_ring())
or define a __hash__ method that does not rely on the string
representation.

The question is whether a meaningful hash is available before knowing
self._ideal. Hence, I recommend the first solution.

Cheers,
Simon

.

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to