Skip to content

Commit c04cae3

Browse files
author
Release Manager
committed
gh-40078: using _an_element_ in groups instead of `an_element` ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. URL: #40078 Reported by: Frédéric Chapoton Reviewer(s): Travis Scrimshaw
2 parents 3b31e45 + dd7a86f commit c04cae3

File tree

4 files changed

+30
-23
lines changed

4 files changed

+30
-23
lines changed

src/sage/groups/additive_abelian/qmodnz.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class QmodnZ(Parent, UniqueRepresentation):
6969
"""
7070
Element = QmodnZ_Element
7171

72-
def __init__(self, n=1):
72+
def __init__(self, n=1) -> None:
7373
r"""
7474
Initialization.
7575
@@ -90,7 +90,7 @@ def __init__(self, n=1):
9090
Parent.__init__(self, base=ZZ, category=category)
9191
self._populate_coercion_lists_(coerce_list=[QQ])
9292

93-
def _repr_(self):
93+
def _repr_(self) -> str:
9494
r"""
9595
Display the group.
9696
@@ -156,7 +156,7 @@ def _element_constructor_(self, x):
156156
"""
157157
return self.element_class(self, QQ(x))
158158

159-
def an_element(self):
159+
def _an_element_(self):
160160
"""
161161
Return an element, for use in coercion system.
162162
@@ -167,7 +167,7 @@ def an_element(self):
167167
"""
168168
return self(0)
169169

170-
def some_elements(self):
170+
def some_elements(self) -> list:
171171
"""
172172
Return some elements, for use in testing.
173173

src/sage/groups/artin.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def coxeter_group_element(self, W=None):
162162
W = self.parent().coxeter_group()
163163
s = W.simple_reflections()
164164
In = W.index_set()
165-
return W.prod(s[In[abs(i)-1]] for i in self.Tietze())
165+
return W.prod(s[In[abs(i) - 1]] for i in self.Tietze())
166166

167167
def burau_matrix(self, var='t'):
168168
r"""
@@ -613,10 +613,10 @@ def __classcall_private__(cls, coxeter_data, names=None):
613613
return super().__classcall__(cls, coxeter_data, names)
614614
if coxeter_data.coxeter_type().cartan_type().type() == 'A':
615615
from sage.groups.braid import BraidGroup
616-
return BraidGroup(coxeter_data.rank()+1, names)
616+
return BraidGroup(coxeter_data.rank() + 1, names)
617617
return FiniteTypeArtinGroup(coxeter_data, names)
618618

619-
def __init__(self, coxeter_matrix, names):
619+
def __init__(self, coxeter_matrix, names) -> None:
620620
"""
621621
Initialize ``self``.
622622
@@ -635,7 +635,7 @@ def __init__(self, coxeter_matrix, names):
635635
I = coxeter_matrix.index_set()
636636
gens = free_group.gens()
637637
for ii, i in enumerate(I):
638-
for jj, j in enumerate(I[ii + 1:], start=ii+1):
638+
for jj, j in enumerate(I[ii + 1:], start=ii + 1):
639639
m = coxeter_matrix[i, j]
640640
if m == Infinity: # no relation
641641
continue
@@ -646,7 +646,7 @@ def __init__(self, coxeter_matrix, names):
646646
rels.append(elt)
647647
FinitelyPresentedGroup.__init__(self, free_group, tuple(rels))
648648

649-
def _repr_(self):
649+
def _repr_(self) -> str:
650650
"""
651651
Return a string representation of ``self``.
652652
@@ -779,7 +779,7 @@ def _element_constructor_(self, x):
779779
return self.element_class(self, x)
780780

781781
@cached_method
782-
def an_element(self):
782+
def _an_element_(self):
783783
"""
784784
Return an element of ``self``.
785785
@@ -791,7 +791,7 @@ def an_element(self):
791791
"""
792792
return self.gen(0)
793793

794-
def some_elements(self):
794+
def some_elements(self) -> list:
795795
"""
796796
Return a list of some elements of ``self``.
797797
@@ -959,7 +959,8 @@ def val(x):
959959
elif x == 1:
960960
return 1 + q**2
961961
else:
962-
return q * (E(2*x) + ~E(2*x))
962+
E2x = E(2 * x)
963+
return q * (E2x + ~E2x)
963964
elif isinstance(base_ring, sage.rings.abc.NumberField_quadratic):
964965
from sage.rings.universal_cyclotomic_field import UniversalCyclotomicField
965966
E = UniversalCyclotomicField().gen

src/sage/groups/braid.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2616,7 +2616,7 @@ class BraidGroup_class(FiniteTypeArtinGroup):
26162616
sage: B1
26172617
Braid group on 5 strands
26182618
sage: B2 = BraidGroup(3)
2619-
sage: B1==B2
2619+
sage: B1 == B2
26202620
False
26212621
sage: B2 is BraidGroup(3)
26222622
True
@@ -2788,7 +2788,7 @@ def _element_constructor_(self, x):
27882788
x = self._standard_lift_Tietze(x)
27892789
return self.element_class(self, x)
27902790

2791-
def an_element(self):
2791+
def _an_element_(self):
27922792
"""
27932793
Return an element of the braid group.
27942794
@@ -3565,10 +3565,13 @@ def epimorphisms(self, H) -> list:
35653565
for u in self.gens()])
35663566
g0quotients = [hom1g * h for h in gquotients]
35673567
res = []
3568+
35683569
# the following closure is needed to attach a specific value of quo to
35693570
# each function in the different morphisms
3570-
fmap = lambda tup: (lambda a: H(prod(tup[abs(i)-1]**sign(i)
3571-
for i in a.Tietze())))
3571+
def fmap(tup):
3572+
return (lambda a: H(prod(tup[abs(i) - 1]**sign(i)
3573+
for i in a.Tietze())))
3574+
35723575
for quo in g0quotients:
35733576
tup = tuple(H(quo.ImageElm(i.gap()).sage()) for i in self.gens())
35743577
fhom = GroupMorphismWithGensImages(HomSpace, fmap(tup))

src/sage/groups/group_exp.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
66
- Mark Shimozono (2013): initial version
77
"""
8-
#*****************************************************************************
8+
# ***************************************************************************
99
# Copyright (C) 2013 <mshimo at math.vt.edu>
1010
#
1111
# This program is free software: you can redistribute it and/or modify
1212
# it under the terms of the GNU General Public License as published by
1313
# the Free Software Foundation, either version 2 of the License, or
1414
# (at your option) any later version.
15-
# http://www.gnu.org/licenses/
16-
#*****************************************************************************
15+
# https://www.gnu.org/licenses/
16+
# ***************************************************************************
1717

1818
from sage.categories.commutative_additive_groups import CommutativeAdditiveGroups
1919
from sage.categories.functor import Functor
@@ -168,7 +168,10 @@ def _apply_functor_to_morphism(self, f):
168168
"""
169169
new_domain = self._apply_functor(f.domain())
170170
new_codomain = self._apply_functor(f.codomain())
171-
new_f = lambda a: new_codomain(f(a.value))
171+
172+
def new_f(a):
173+
return new_codomain(f(a.value))
174+
172175
return SetMorphism(Hom(new_domain, new_codomain, Groups()), new_f)
173176

174177

@@ -254,7 +257,7 @@ class GroupExp_Class(UniqueRepresentation, Parent):
254257
sage: GroupExp()(QQ)
255258
Multiplicative form of Rational Field
256259
"""
257-
def __init__(self, G):
260+
def __init__(self, G) -> None:
258261
r"""
259262
260263
EXAMPLES::
@@ -267,7 +270,7 @@ def __init__(self, G):
267270
self._G = G
268271
Parent.__init__(self, category=Groups())
269272

270-
def _repr_(self):
273+
def _repr_(self) -> str:
271274
r"""
272275
Return a string describing the multiplicative form of a commutative additive group.
273276
@@ -307,7 +310,7 @@ def one(self):
307310
"""
308311
return GroupExpElement(self, self._G.zero())
309312

310-
def an_element(self):
313+
def _an_element_(self):
311314
r"""
312315
Return an element of the multiplicative group.
313316

0 commit comments

Comments
 (0)