#15822: Tropical semiring cannot exponentiate infinity
-----------------------+--------------------------------------------------
Reporter: darij | Owner:
Type: defect | Status: new
Priority: trivial | Milestone: sage-6.2
Component: algebra | Keywords: tropical semiring, border case
Merged in: | Authors: Darij Grinberg
Reviewers: | Report Upstream: N/A
Work issues: | Branch:
Commit: | Dependencies:
Stopgaps: |
-----------------------+--------------------------------------------------
Just found this while experimenting with my own semirings:
{{{
sage: T = TropicalSemiring(QQ)
sage: T.infinity() ** 2
---------------------------------------------------------------------------
TypeError Traceback (most recent call
last)
<ipython-input-28-b94a4a077331> in <module>()
----> 1 T.infinity() ** Integer(2)
/scratch/sage-6.1.1/local/lib/python2.7/site-
packages/sage/rings/semirings/tropical_semiring.so in
sage.rings.semirings.tropical_semiring.TropicalSemiringElement.__pow__
(sage/rings/semirings/tropical_semiring.c:4218)()
/scratch/sage-6.1.1/local/lib/python2.7/site-
packages/sage/structure/element.so in
sage.structure.element.RingElement.__mul__
(sage/structure/element.c:14520)()
/scratch/sage-6.1.1/local/lib/python2.7/site-
packages/sage/structure/coerce.so in
sage.structure.coerce.CoercionModel_cache_maps.bin_op
(sage/structure/coerce.c:8150)()
TypeError: unsupported operand parent(s) for '*': 'Integer Ring' and
'<type 'NoneType'>'
}}}
Here is a way to solve this (sage/rings/semirings/tropical_semiring.pyx):
{{{
def __pow__(base, exp, dummy):
"""
Return ``self`` to ``exp``.
EXAMPLES::
sage: T = TropicalSemiring(QQ)
sage: elt = T(2)
sage: elt**3
6
sage: elt**-2
-4
sage: elt**(3/7)
6/7
sage: elt**0
0
sage: elt = T.infinity()
sage: elt**0
0
sage: elt**(1/2)
+infinity
sage: elt*33
+infinity
"""
cdef TropicalSemiringElement self, x
self = base
if self._val is None:
if exp > 0:
return self
elif exp == 0:
return self.parent().one()
raise ZeroDivisionError("Tropical division by infinity")
x = self._new()
x._val = exp*self._val
return x
}}}
Is this good? (I cannot upload branches from here -- git fails
authorization?)
--
Ticket URL: <http://trac.sagemath.org/ticket/15822>
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/groups/opt_out.