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

Commit

Permalink
Merge branch 'u/chapoton/17965' in 9.3.b0
Browse files Browse the repository at this point in the history
  • Loading branch information
fchapoton committed Nov 1, 2020
2 parents 2c87dc1 + 5e7e19a commit dc2e65f
Show file tree
Hide file tree
Showing 19 changed files with 92 additions and 88 deletions.
6 changes: 2 additions & 4 deletions src/sage/algebras/hecke_algebras/ariki_koike_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,7 @@ def inverse_T(self, i):
return self._from_dict({m: ~self._q, self.one_basis(): c})

class Element(CombinatorialFreeModule.Element):
def inverse(self):
def __invert__(self):
r"""
Return the inverse if ``self`` is a basis element.
Expand All @@ -1135,7 +1135,7 @@ def inverse(self):
sage: LT = algebras.ArikiKoike(3, 4).LT()
sage: t = LT.T(1) * LT.T(2) * LT.T(3); t
T[1,2,3]
sage: t.inverse()
sage: t.inverse() # indirect doctest
(q^-3-3*q^-2+3*q^-1-1) + (q^-3-2*q^-2+q^-1)*T[3]
+ (q^-3-2*q^-2+q^-1)*T[2] + (q^-3-q^-2)*T[3,2]
+ (q^-3-2*q^-2+q^-1)*T[1] + (q^-3-q^-2)*T[1,3]
Expand All @@ -1149,8 +1149,6 @@ def inverse(self):
H = self.parent()
return ~self[l,w] * H.prod(H.inverse_T(i) for i in reversed(w.reduced_word()))

__invert__ = inverse

class T(_Basis):
r"""
The basis of the Ariki-Koike algebra given by monomials of the
Expand Down
6 changes: 2 additions & 4 deletions src/sage/algebras/iwahori_hecke_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -1727,7 +1727,7 @@ class Element(CombinatorialFreeModule.Element):
sage: T1.parent()
Iwahori-Hecke algebra of type A2 in 1,-1 over Integer Ring in the T-basis
"""
def inverse(self):
def __invert__(self):
r"""
Return the inverse if ``self`` is a basis element.
Expand All @@ -1741,7 +1741,7 @@ def inverse(self):
sage: R.<q> = LaurentPolynomialRing(QQ)
sage: H = IwahoriHeckeAlgebra("A2", q).T()
sage: [T1,T2] = H.algebra_generators()
sage: x = (T1*T2).inverse(); x
sage: x = (T1*T2).inverse(); x # indirect doctest
(q^-2)*T[2,1] + (q^-2-q^-1)*T[1] + (q^-2-q^-1)*T[2] + (q^-2-2*q^-1+1)
sage: x*T1*T2
1
Expand All @@ -1766,8 +1766,6 @@ def inverse(self):

return H.prod(H.inverse_generator(i) for i in reversed(w.reduced_word()))

__invert__ = inverse

standard = T

class _KLHeckeBasis(_Basis):
Expand Down
7 changes: 2 additions & 5 deletions src/sage/algebras/yokonuma_hecke_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def inverse_g(self, i):
return self.g(i) + (~self._q + self._q) * self.e(i)

class Element(CombinatorialFreeModule.Element):
def inverse(self):
def __invert__(self):
r"""
Return the inverse if ``self`` is a basis element.
Expand All @@ -463,7 +463,7 @@ def inverse(self):
sage: Y = algebras.YokonumaHecke(3, 3)
sage: t = prod(Y.t()); t
t1*t2*t3
sage: ~t
sage: t.inverse() # indirect doctest
t1^2*t2^2*t3^2
sage: [3*~(t*g) for g in Y.g()]
[(q^-1+q)*t2*t3^2 + (q^-1+q)*t1*t3^2
Expand Down Expand Up @@ -494,6 +494,3 @@ def inverse(self):
c = ~self.coefficients()[0]
telt = H.monomial( (tuple((H._d - e) % H._d for e in t), H._Pn.one()) )
return c * telt * H.prod(H.inverse_g(i) for i in reversed(w.reduced_word()))

__invert__ = inverse

Original file line number Diff line number Diff line change
Expand Up @@ -1141,15 +1141,15 @@ def _mul_(self, other):
"""
return self.apply_simple_reflections(other.reduced_word())

def inverse(self):
def __invert__(self):
"""
Return the inverse of ``self``.
EXAMPLES::
sage: W = WeylGroup(['B',7])
sage: w = W.an_element()
sage: u = w.inverse()
sage: u = w.inverse() # indirect doctest
sage: u == ~w
True
sage: u * w == w * u
Expand All @@ -1165,8 +1165,6 @@ def inverse(self):
"""
return self.parent().one().apply_simple_reflections(self.reduced_word_reverse_iterator())

__invert__ = inverse

def apply_conjugation_by_simple_reflection(self, i):
r"""
Conjugate ``self`` by the ``i``-th simple reflection.
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
13 changes: 6 additions & 7 deletions src/sage/combinat/affine_permutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,21 +159,19 @@ def __mul__(self, q):
return self.__rmul__(q)

@cached_method
def inverse(self):
def __invert__(self):
r"""
Return the inverse affine permutation.
EXAMPLES::
sage: p = AffinePermutationGroup(['A',7,1])([3, -1, 0, 6, 5, 4, 10, 9])
sage: p.inverse()
sage: p.inverse() # indirect doctest
Type A affine permutation with window [0, -1, 1, 6, 5, 4, 10, 11]
"""
inv = [self.position(i) for i in range(1,len(self)+1)]
inv = [self.position(i) for i in range(1, len(self) + 1)]
return type(self)(self.parent(), inv, check=False)

__invert__=inverse

def apply_simple_reflection(self, i, side='right'):
r"""
Apply a simple reflection.
Expand Down Expand Up @@ -853,8 +851,8 @@ def to_lehmer_code(self, typ='decreasing', side='right'):
a=self(i)
for j in range(i-self.k, i):
b=self(j)
#A small rotation is necessary for the reduced word from
#the lehmer code to match the element.
# A small rotation is necessary for the reduced word from
# the Lehmer code to match the element.
if a < b:
code[i-1]+=((b-a)//(self.k+1)+1)
elif typ[0] == 'i' and side[0] == 'l':
Expand Down Expand Up @@ -2348,6 +2346,7 @@ def from_lehmer_code(self, C, typ='decreasing', side='right'):

Element = AffinePermutationTypeA


class AffinePermutationGroupTypeC(AffinePermutationGroupGeneric):
#------------------------
#Type-specific methods.
Expand Down
12 changes: 4 additions & 8 deletions src/sage/combinat/colored_permutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ def _mul_(self, other):
p = self._perm._left_to_right_multiply_on_right(other._perm)
return self.__class__(self.parent(), colors, p)

def inverse(self):
def __invert__(self):
"""
Return the inverse of ``self``.
EXAMPLES::
sage: C = ColoredPermutations(4, 3)
sage: s1,s2,t = C.gens()
sage: ~t
sage: ~t # indirect doctest
[[0, 0, 3], [1, 2, 3]]
sage: all(x * ~x == C.one() for x in C.gens())
True
Expand All @@ -114,8 +114,6 @@ def inverse(self):
tuple([-self._colors[i - 1] for i in ip]), # -1 for indexing
ip)

__invert__ = inverse

def __eq__(self, other):
"""
Check equality.
Expand Down Expand Up @@ -981,7 +979,7 @@ def _mul_(self, other):
p = self._perm._left_to_right_multiply_on_right(other._perm)
return self.__class__(self.parent(), colors, p)

def inverse(self):
def __invert__(self):
"""
Return the inverse of ``self``.
Expand All @@ -990,7 +988,7 @@ def inverse(self):
sage: S = SignedPermutations(4)
sage: s1,s2,s3,s4 = S.gens()
sage: x = s4*s1*s2*s3*s4
sage: ~x
sage: ~x # indirect doctest
[2, 3, -4, -1]
sage: x * ~x == S.one()
True
Expand All @@ -1000,8 +998,6 @@ def inverse(self):
tuple([self._colors[i - 1] for i in ip]), # -1 for indexing
ip)

__invert__ = inverse

def __iter__(self):
"""
Iterate over ``self``.
Expand Down
6 changes: 2 additions & 4 deletions src/sage/combinat/root_system/fundamental_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,15 @@ def _repr_(self):
"""
return self.parent()._prefix + "[" + repr(self.value()) + "]"

def inverse(self):
def __invert__(self):
r"""
Return the inverse element of ``self``.
EXAMPLES::
sage: from sage.combinat.root_system.fundamental_group import FundamentalGroupOfExtendedAffineWeylGroup
sage: F = FundamentalGroupOfExtendedAffineWeylGroup(['A',3,1])
sage: F(1).inverse()
sage: F(1).inverse() # indirect doctest
pi[3]
sage: F = FundamentalGroupOfExtendedAffineWeylGroup(['E',6,1], prefix="f")
sage: F(1).inverse()
Expand All @@ -266,8 +266,6 @@ def inverse(self):
par = self.parent()
return self.__class__(par, par.dual_node(self.value()))

__invert__ = inverse

def _richcmp_(self, x, op):
r"""
Compare ``self`` with `x`.
Expand Down
8 changes: 3 additions & 5 deletions src/sage/geometry/hyperbolic_space/hyperbolic_isometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,21 +323,19 @@ def matrix(self):
"""
return self._matrix

def inverse(self):
def __invert__(self):
r"""
Return the inverse of the isometry ``self``.
EXAMPLES::
sage: UHP = HyperbolicPlane().UHP()
sage: A = UHP.get_isometry(matrix(2,[4,1,3,2]))
sage: B = A.inverse()
sage: B = A.inverse() # indirect doctest
sage: A*B == UHP.get_isometry(identity_matrix(2))
True
"""
return self.__class__(self.domain(), self.matrix().inverse())

__invert__ = inverse
return self.__class__(self.domain(), self.matrix().__invert__())

def is_identity(self):
"""
Expand Down
14 changes: 6 additions & 8 deletions src/sage/groups/abelian_gps/element_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# Copyright (C) 2012 Volker Braun <vbraun.name@gmail.com>
#
# Distributed under the terms of the GNU General Public License (GPL)
# http://www.gnu.org/licenses/
# https://www.gnu.org/licenses/
###########################################################################

from sage.structure.element import MultiplicativeGroupElement
Expand Down Expand Up @@ -298,14 +298,14 @@ def __pow__(self, n):
for e,order in zip(self._exponents, G.gens_orders()) ]
return G.element_class(G, exponents)

def inverse(self):
def __invert__(self):
"""
Returns the inverse element.
Return the inverse element.
EXAMPLES::
sage: G.<a,b> = AbelianGroup([0,5])
sage: a.inverse()
sage: a.inverse() # indirect doctest
a^-1
sage: a.__invert__()
a^-1
Expand All @@ -319,12 +319,10 @@ def inverse(self):
(-1, 4)
"""
G = self.parent()
exponents = [ (-e)%order if order!=0 else -e
for e,order in zip(self._exponents, G.gens_orders()) ]
exponents = [(-e) % order if order != 0 else -e
for e, order in zip(self._exponents, G.gens_orders())]
return G.element_class(G, exponents)

__invert__ = inverse

def is_trivial(self):
"""
Test whether ``self`` is the trivial group element ``1``.
Expand Down
9 changes: 3 additions & 6 deletions src/sage/groups/abelian_gps/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,14 +330,14 @@ def __pow__(self, n):
pow_self._value = pow(self.value(), m)
return pow_self

def inverse(self):
def __invert__(self):
"""
Return the inverse element.
EXAMPLES::
sage: G.<a,b> = AbelianGroupWithValues([2,-1], [0,4])
sage: a.inverse()
sage: a.inverse() # indirect doctest
a^-1
sage: a.inverse().value()
1/2
Expand All @@ -350,13 +350,10 @@ def inverse(self):
sage: (a*b).inverse().value()
-1/2
"""
m = AbelianGroupElement.inverse(self)
m = AbelianGroupElement.__invert__(self)
m._value = ~self.value()
return m

__invert__ = inverse



class AbelianGroupWithValues_class(AbelianGroup_class):
"""
Expand Down
10 changes: 4 additions & 6 deletions src/sage/groups/affine_gps/group_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ def _act_on_(self, x, self_on_left):
if self_on_left:
return self(x)

def inverse(self):
def __invert__(self):
"""
Return the inverse group element.
Expand All @@ -422,19 +422,17 @@ def inverse(self):
sage: ~g
[1 1] [1]
x |-> [0 1] x + [0]
sage: g * g.inverse()
sage: g * g.inverse() # indirect doctest
[1 0] [0]
x |-> [0 1] x + [0]
sage: g * g.inverse() == g.inverse() * g == G(1)
True
"""
parent = self.parent()
A = parent.matrix_space()(self._A.inverse())
b = -A*self.b()
A = parent.matrix_space()(~self._A)
b = -A * self.b()
return parent.element_class(parent, A, b, check=False)

__invert__ = inverse

def _richcmp_(self, other, op):
"""
Compare ``self`` with ``other``.
Expand Down
Loading

0 comments on commit dc2e65f

Please sign in to comment.