From 5e7e19afded220ad7e88b6362e7f98448a46df04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Wed, 19 Aug 2020 10:08:36 +0200 Subject: [PATCH] tentative fix, move inversion to monoids --- src/sage/categories/magmas.py | 30 ------------------------- src/sage/categories/monoids.py | 30 +++++++++++++++++++++++++ src/sage/monoids/free_monoid_element.py | 7 ++++-- 3 files changed, 35 insertions(+), 32 deletions(-) diff --git a/src/sage/categories/magmas.py b/src/sage/categories/magmas.py index ba6a5b7135f..89af2269084 100644 --- a/src/sage/categories/magmas.py +++ b/src/sage/categories/magmas.py @@ -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 diff --git a/src/sage/categories/monoids.py b/src/sage/categories/monoids.py index 42b55b8dda4..d598a6cecb3 100644 --- a/src/sage/categories/monoids.py +++ b/src/sage/categories/monoids.py @@ -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. diff --git a/src/sage/monoids/free_monoid_element.py b/src/sage/monoids/free_monoid_element.py index 549f9381e94..0da37bb9adf 100644 --- a/src/sage/monoids/free_monoid_element.py +++ b/src/sage/monoids/free_monoid_element.py @@ -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 @@ -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:: @@ -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