# Revision history [back]

### _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._parent.one() / self 2741