Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

_invert_ for ring which is not integral

Suppose I have implemented my own ring MyRing which derives (among others) from CommutativeRing. MyRing is not an integral domain, so MyRing.is_integral_domain() will return False. The element class is called MyRingElement and is derived from CommutativeRingElement. All arithmetic operations on MyRingElement, like _add_, _mult_, etc., work well. Some of the elements are invertible and for those, _invert_ will return the inverse (or raise an error if no inverse exists). What is the Sage-way to call _invert_?

R = MyRing()
el = R.an_element()
~el # or 1/el or el.inverse_of_unit()

yields an error as MyRing is not an integral domain:

~/sage-9.2/local/lib/python3.8/site-packages/sage/structure/element.pyx in sage.structure.element.RingElement.__invert__ (build/cythonized/sage/structure/element.c:19405)() 2738 2739 def __invert__(self): -> 2740 return / self 2741
2742 def additive_order(self):

~/sage-9.2/local/lib/python3.8/site-packages/sage/structure/element.pyx in sage.structure.element.Element.__truediv__ (build/cythonized/sage/structure/element.c:13147)() 1733 cdef int cl = classify_elements(left, right) 1734 if HAVE_SAME_PARENT(cl): -> 1735 return (<element>left)._div_(right) 1736
if BOTH_ARE_ELEMENT(cl): 1737
return coercion_model.bin_op(left, right, truediv)

~/sage-9.2/local/lib/python3.8/site-packages/sage/structure/element.pyx in sage.structure.element.RingElement._div_ (build/cythonized/sage/structure/element.c:19149)() 2732 """ 2733 try: -> 2734 frac = self._parent.fraction_field() 2735 except AttributeError: 2736
raise bin_op_exception('/', self, other)

~/sage-9.2/local/lib/python3.8/site-packages/sage/rings/ring.pyx in sage.rings.ring.CommutativeRing.fraction_field (build/cythonized/sage/rings/ring.c:12126)() 1328 1329 if not self.is_integral_domain(): -> 1330 raise TypeError("self must be an integral domain.") 1331 1332 if self.__fraction_field is not None:

TypeError: self must be an integral domain.