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.7.rc1
Browse files Browse the repository at this point in the history
  • Loading branch information
fchapoton committed Sep 8, 2022
2 parents 08202bc + b6a5773 commit 9ec90c5
Show file tree
Hide file tree
Showing 21 changed files with 137 additions and 111 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 @@ -1125,7 +1125,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 @@ -1134,7 +1134,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 @@ -1148,8 +1148,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 @@ -1732,7 +1732,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 @@ -1746,7 +1746,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 @@ -1771,8 +1771,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
6 changes: 2 additions & 4 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,5 +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 @@ -1142,15 +1142,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 @@ -1166,8 +1166,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
21 changes: 0 additions & 21 deletions src/sage/categories/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,27 +640,6 @@ def order(self):
from sage.misc.misc_c import prod
return prod(c.cardinality() for c in self.cartesian_factors())

class ElementMethods:
def multiplicative_order(self):
r"""
Return the multiplicative order of this element.
EXAMPLES::
sage: G1 = SymmetricGroup(3)
sage: G2 = SL(2,3)
sage: G = cartesian_product([G1,G2])
sage: G((G1.gen(0), G2.gen(1))).multiplicative_order()
12
"""
from sage.rings.infinity import Infinity
orders = [x.multiplicative_order() for x in self.cartesian_factors()]
if any(o is Infinity for o in orders):
return Infinity
else:
from sage.arith.functions import LCM_list
return LCM_list(orders)

class Topological(TopologicalSpacesCategory):
"""
Category of topological groups.
Expand Down
4 changes: 1 addition & 3 deletions src/sage/categories/magmas.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,9 +671,7 @@ def __invert__(self):
ZeroDivisionError: rational division by zero
sage: ~C([2,2,2,2])
Traceback (most recent call last):
...
TypeError: no conversion of this rational to integer
(1/2, 1/2, 0.500000000000000, 3)
"""
# variant without coercion:
# return self.parent()._cartesian_product_of_elements(
Expand Down
80 changes: 74 additions & 6 deletions src/sage/categories/monoids.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,18 +252,18 @@ def _div_(left, right):
sage: c1._div_(c2)
(x0*x1^-1, x1*x0^-1)
With this implementation, division will fail as soon
as ``right`` is not invertible, even if ``right``
With this default implementation, division will fail as
soon as ``right`` is not invertible, even if ``right``
actually divides ``left``::
sage: x = cartesian_product([2, 1])
sage: x = cartesian_product([2, 0])
sage: y = cartesian_product([1, 1])
sage: x / y
(2, 1)
sage: x / x
(2, 0)
sage: y / x
Traceback (most recent call last):
...
TypeError: no conversion of this rational to integer
ZeroDivisionError: rational division by zero
TESTS::
Expand Down Expand Up @@ -354,6 +354,37 @@ def powers(self, n):
l.append(x)
return l

def __invert__(self):
r"""
Return the inverse of ``self``.
There is no default implementation, to avoid conflict
with the default implementation of ``_div_``.
EXAMPLES::
sage: A = Matrix([[1, 0], [1, 1]])
sage: ~A
[ 1 0]
[-1 1]
"""
raise NotImplementedError("please implement __invert__")

def inverse(self):
"""
Return the inverse of ``self``.
This is 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 Expand Up @@ -639,3 +670,40 @@ def lift(i, gen):
lambda g: (i, g))
for i, M in enumerate(F)])
return Family(gens_prod, lift, name="gen")

class ElementMethods:
def multiplicative_order(self):
r"""
Return the multiplicative order of this element.
EXAMPLES::
sage: G1 = SymmetricGroup(3)
sage: G2 = SL(2,3)
sage: G = cartesian_product([G1,G2])
sage: G((G1.gen(0), G2.gen(1))).multiplicative_order()
12
"""
from sage.rings.infinity import Infinity
orders = [x.multiplicative_order() for x in self.cartesian_factors()]
if any(o is Infinity for o in orders):
return Infinity
else:
from sage.arith.functions import LCM_list
return LCM_list(orders)

def __invert__(self):
"""
Return the inverse.
EXAMPLES::
sage: a1 = Permutation((4,2,1,3))
sage: a2 = SL(2,3)([2,1,1,1])
sage: h = cartesian_product([a1,a2])
sage: ~h
([2, 4, 1, 3], [1 2]
[2 2])
"""
build = self.parent()._cartesian_product_of_elements
return build([x.__invert__() for x in self.cartesian_factors()])
13 changes: 6 additions & 7 deletions src/sage/combinat/affine_permutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,21 +161,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 @@ -855,8 +853,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 @@ -2330,6 +2328,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 @@ -109,15 +109,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 @@ -127,8 +127,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 @@ -1030,7 +1028,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 @@ -1039,7 +1037,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 @@ -1049,8 +1047,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 @@ -324,21 +324,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
Loading

0 comments on commit 9ec90c5

Please sign in to comment.