#8928: Infinite loop caused by Modules.ElementClass.__mul__
--------------------------+-------------------------------------------------
Reporter: mguaypaq | Owner: mguaypaq
Type: defect | Status: new
Priority: minor | Milestone: sage-4.4.2
Component: categories | Keywords: categories, coercion, infinite loop
Author: | Upstream: N/A
Reviewer: | Merged:
Work_issues: |
--------------------------+-------------------------------------------------
There is currently an infinite loop which seems to be a result of
{{{Modules.ElementClass.__mul__}}} calling
{{{get_coercion_model().bin_op(left, right, operator.mul)}}}, and
{{{bin_op}}} calling {{{operator.mul(left, right)}}}.
Note that this behavior may even mask {{{ElementClass.__mul__}}} from
other super-categories that actually implement multiplication.
Here is an illustrative example, showing a class that works
({{{MyRing1}}}) and one that breaks ({{{MyRing2}}}). The only difference
between the two classes is the very last line.
{{{
----------------------------------------------------------------------
| Sage Version 4.4, Release Date: 2010-04-24 |
| Type notebook() for the GUI, and license() for information. |
----------------------------------------------------------------------
sage: class MyRing1(CombinatorialFreeModule):
....: def __init__(self):
....: R = QQ
....: category = (ModulesWithBasis(R), Rngs())
....: CombinatorialFreeModule.__init__(self, R, Partitions(),
category = category)
....: def product(self, left, right):
....: return self.zero()
....: class Element(CombinatorialFreeModule.Element):
....: __mul__ = Rngs().element_class.__mul__
....:
sage: class MyRing2(CombinatorialFreeModule):
....: def __init__(self):
....: R = QQ
....: category = (ModulesWithBasis(R), Rngs())
....: CombinatorialFreeModule.__init__(self, R, Partitions(),
category = category)
....: def product(self, left, right):
....: return self.zero()
....: class Element(CombinatorialFreeModule.Element):
....: pass
....:
sage: x = MyRing1().basis()[Partition([2,1])]
sage: x
B[[2, 1]]
sage: x*x
0
sage: y = MyRing2().basis()[Partition([2,1])]
sage: y
B[[2, 1]]
sage: y*y
...
/opt/sage-4.4/local/lib/python2.6/site-
packages/sage/categories/modules.pyc in __mul__(left, right)
95 from sage.structure.element import get_coercion_model
96 import operator
---> 97 return get_coercion_model().bin_op(left, right,
operator.mul)
98
99 def __rmul__(right, left):
/opt/sage-4.4/local/lib/python2.6/site-packages/sage/structure/coerce.so
in sage.structure.coerce.CoercionModel_cache_maps.bin_op
(sage/structure/coerce.c:7063)()
/opt/sage-4.4/local/lib/python2.6/site-packages/sage/structure/coerce.so
in sage.structure.coerce.CoercionModel_cache_maps.bin_op
(sage/structure/coerce.c:6034)()
/opt/sage-4.4/local/lib/python2.6/site-
packages/sage/categories/modules.pyc in __mul__(left, right)
95 from sage.structure.element import get_coercion_model
96 import operator
---> 97 return get_coercion_model().bin_op(left, right,
operator.mul)
98
99 def __rmul__(right, left):
/opt/sage-4.4/local/lib/python2.6/site-packages/sage/structure/coerce.so
in sage.structure.coerce.CoercionModel_cache_maps.bin_op
(sage/structure/coerce.c:7063)()
/opt/sage-4.4/local/lib/python2.6/site-packages/sage/structure/coerce.so
in sage.structure.coerce.CoercionModel_cache_maps.bin_op
(sage/structure/coerce.c:6034)()
RuntimeError: maximum recursion depth exceeded while calling a Python
object
sage:
}}}
It seems like this could be fixed by removing
{{{Modules.ElementClass.__mul__}}}, since it doesn't seem to add any
functionality; is there any reason for it being there?
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/8928>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.