Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
tentative fix, move inversion to monoids
Browse files Browse the repository at this point in the history
  • Loading branch information
fchapoton committed Aug 19, 2020
1 parent 637f8bd commit 5e7e19a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 32 deletions.
30 changes: 0 additions & 30 deletions src/sage/categories/magmas.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,36 +589,6 @@ def _div_(left, right):
"""
return left * ~right

def __invert__(self):
r"""
Return the inverse of ``self``.
The default implementation is to divide ``self.one()``.
EXAMPLES::
sage: A = Matrix([[1, 0], [1, 1]])
sage: ~A
[ 1 0]
[-1 1]
"""
return self.parent().one()._div_(self)

def inverse(self):
"""
Return the inverse of ``self``.
This an alias for inversion, defined in ``__invert__``.
Element classes should implement ``__invert__`` only.
EXAMPLES::
sage: AA(sqrt(~2)).inverse()
1.414213562373095?
"""
return self.__invert__()

class SubcategoryMethods:

@cached_method
Expand Down
30 changes: 30 additions & 0 deletions src/sage/categories/monoids.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,36 @@ def powers(self, n):
l.append(x)
return l

def __invert__(self):
r"""
Return the inverse of ``self``.
The default implementation is to divide ``self.one()``.
EXAMPLES::
sage: A = Matrix([[1, 0], [1, 1]])
sage: ~A
[ 1 0]
[-1 1]
"""
return self.parent().one()._div_(self)

def inverse(self):
"""
Return the inverse of ``self``.
This an alias for inversion, defined in ``__invert__``.
Element classes should implement ``__invert__`` only.
EXAMPLES::
sage: AA(sqrt(~2)).inverse()
1.414213562373095?
"""
return self.__invert__()

class Commutative(CategoryWithAxiom):
r"""
Category of commutative (abelian) monoids.
Expand Down
7 changes: 5 additions & 2 deletions src/sage/monoids/free_monoid_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# See the GNU General Public License for more details; the full text
# is available at:
#
# http://www.gnu.org/licenses/
# https://www.gnu.org/licenses/
#*****************************************************************************

from sage.rings.integer import Integer
Expand Down Expand Up @@ -102,7 +102,7 @@ def __hash__(self):

def __iter__(self):
"""
Returns an iterator which yields tuples of variable and exponent.
Return an iterator which yields tuples of variable and exponent.
EXAMPLES::
Expand Down Expand Up @@ -257,6 +257,9 @@ def _mul_(self, y):
z._element_list = x_elt[:k] + [ m ] + y_elt[1:]
return z

def __invert__(self):
raise NotImplementedError

def __len__(self):
"""
Return the degree of the monoid element ``self``, where each
Expand Down

0 comments on commit 5e7e19a

Please sign in to comment.