Skip to content

Commit 23db2d4

Browse files
author
Release Manager
committed
Trac #34620: pep cleanup for the file weyl_group.py
URL: https://trac.sagemath.org/34620 Reported by: chapoton Ticket author(s): Frédéric Chapoton Reviewer(s): David Coudert
2 parents 78b1fd0 + f83a25d commit 23db2d4

File tree

1 file changed

+58
-55
lines changed

1 file changed

+58
-55
lines changed

src/sage/combinat/root_system/weyl_group.py

Lines changed: 58 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66
- Daniel Bump (2008): initial version
77
- Mike Hansen (2008): initial version
88
- Anne Schilling (2008): initial version
9-
- Nicolas Thiery (2008): initial version
9+
- Nicolas Thiéry (2008): initial version
1010
- Volker Braun (2013): LibGAP-based matrix groups
1111
1212
EXAMPLES:
1313
14-
More examples on Weyl Groups should be added here...
15-
1614
The Cayley graph of the Weyl Group of type ['A', 3]::
1715
1816
sage: w = WeylGroup(['A',3])
@@ -26,17 +24,21 @@
2624
sage: d = w.cayley_graph(); d
2725
Digraph on 192 vertices
2826
sage: d.show3d(color_by_label=True, edge_size=0.01, vertex_size=0.03) #long time (less than one minute)
27+
28+
.. TODO::
29+
30+
More examples on Weyl Groups should be added here.
2931
"""
30-
#*****************************************************************************
32+
# ****************************************************************************
3133
# Copyright (C) 2008 Daniel Bump <bump at match.stanford.edu>,
3234
# Mike Hansen <[email protected]>
3335
# Anne Schilling <anne at math.ucdavis.edu>
3436
# Nicolas Thiery <nthiery at users.sf.net>
3537
#
3638
# Distributed under the terms of the GNU General Public License (GPL)
3739
#
38-
# http://www.gnu.org/licenses/
39-
#*****************************************************************************
40+
# https://www.gnu.org/licenses/
41+
# ****************************************************************************
4042
from sage.groups.matrix_gps.finitely_generated import FinitelyGeneratedMatrixGroup_gap
4143
from sage.groups.matrix_gps.group_element import MatrixGroupElement_gap
4244
from sage.groups.perm_gps.permgroup import PermutationGroup_generic
@@ -59,12 +61,12 @@
5961

6062
def WeylGroup(x, prefix=None, implementation='matrix'):
6163
"""
62-
Returns the Weyl group of the root system defined by the Cartan
64+
Return the Weyl group of the root system defined by the Cartan
6365
type (or matrix) ``ct``.
6466
6567
INPUT:
6668
67-
- ``x`` - a root system or a Cartan type (or matrix)
69+
- ``x`` -- a root system or a Cartan type (or matrix)
6870
6971
OPTIONAL:
7072
@@ -236,7 +238,7 @@ def __init__(self, domain, prefix):
236238
category = WeylGroups()
237239
if self.cartan_type().is_irreducible():
238240
category = category.Irreducible()
239-
self.n = domain.dimension() # Really needed?
241+
self.n = domain.dimension() # Really needed?
240242
self._prefix = prefix
241243

242244
# FinitelyGeneratedMatrixGroup_gap takes plain matrices as input
@@ -252,7 +254,7 @@ def __init__(self, domain, prefix):
252254
@cached_method
253255
def cartan_type(self):
254256
"""
255-
Returns the CartanType associated to self.
257+
Return the ``CartanType`` associated to ``self``.
256258
257259
EXAMPLES::
258260
@@ -265,7 +267,7 @@ def cartan_type(self):
265267
@cached_method
266268
def index_set(self):
267269
"""
268-
Returns the index set of self.
270+
Return the index set of ``self``.
269271
270272
EXAMPLES::
271273
@@ -289,7 +291,7 @@ def from_morphism(self, f):
289291
@cached_method
290292
def simple_reflections(self):
291293
"""
292-
Returns the simple reflections of self, as a family.
294+
Return the simple reflections of ``self``, as a family.
293295
294296
EXAMPLES:
295297
@@ -393,13 +395,13 @@ def _repr_(self):
393395
Weyl Group of type ['A', 3, 1] (as a matrix group acting on the root space)
394396
"""
395397
return "Weyl Group of type %s (as a matrix group acting on the %s)" % (self.cartan_type(),
396-
self._domain._name_string(capitalize=False,
397-
base_ring=False,
398-
type=False))
398+
self._domain._name_string(capitalize=False,
399+
base_ring=False,
400+
type=False))
399401

400402
def character_table(self):
401403
"""
402-
Returns the character table as a matrix
404+
Return the character table as a matrix.
403405
404406
Each row is an irreducible character. For larger tables you
405407
may preface this with a command such as
@@ -421,14 +423,14 @@ def character_table(self):
421423
X.4 3 -1 1 . -1
422424
X.5 1 1 1 1 1
423425
"""
424-
gens_str = ', '.join(str(g.gap()) for g in self.gens())
426+
gens_str = ', '.join(str(g.gap()) for g in self.gens())
425427
ctbl = gap('CharacterTable(Group({0}))'.format(gens_str))
426428
return ctbl.Display()
427429

428430
@cached_method
429431
def one(self):
430432
"""
431-
Returns the unit element of the Weyl group
433+
Return the unit element of the Weyl group.
432434
433435
EXAMPLES::
434436
@@ -441,13 +443,13 @@ def one(self):
441443
sage: type(e) == W.element_class
442444
True
443445
"""
444-
return self._element_constructor_(matrix(QQ,self.n,self.n,1))
446+
return self._element_constructor_(matrix(QQ, self.n, self.n, 1))
445447

446-
unit = one # For backward compatibility
448+
unit = one # For backward compatibility
447449

448450
def domain(self):
449451
"""
450-
Returns the domain of the element of ``self``, that is the
452+
Return the domain of the element of ``self``, that is the
451453
root lattice realization on which they act.
452454
453455
EXAMPLES::
@@ -463,7 +465,7 @@ def domain(self):
463465

464466
def simple_reflection(self, i):
465467
"""
466-
Returns the `i^{th}` simple reflection.
468+
Return the `i^{th}` simple reflection.
467469
468470
EXAMPLES::
469471
@@ -485,7 +487,7 @@ def simple_reflection(self, i):
485487

486488
def long_element_hardcoded(self):
487489
"""
488-
Returns the long Weyl group element (hardcoded data)
490+
Return the long Weyl group element (hardcoded data).
489491
490492
Do we really want to keep it? There is a generic
491493
implementation which works in all cases. The hardcoded should
@@ -497,22 +499,22 @@ def long_element_hardcoded(self):
497499
sage: types = [ ['A',5],['B',3],['C',3],['D',4],['G',2],['F',4],['E',6] ]
498500
sage: [WeylGroup(t).long_element().length() for t in types]
499501
[15, 9, 9, 12, 6, 24, 36]
500-
sage: all( WeylGroup(t).long_element() == WeylGroup(t).long_element_hardcoded() for t in types ) # long time (17s on sage.math, 2011)
502+
sage: all(WeylGroup(t).long_element() == WeylGroup(t).long_element_hardcoded() for t in types) # long time (17s on sage.math, 2011)
501503
True
502504
"""
503505
type = self.cartan_type()
504-
if type[0] == 'D' and type[1]%2 == 1:
505-
l = [-1 for i in range(self.n-1)]
506+
if type[0] == 'D' and type[1] % 2:
507+
l = [-1 for i in range(self.n - 1)]
506508
l.append(1)
507-
m = diagonal_matrix(QQ,l)
509+
m = diagonal_matrix(QQ, l)
508510
elif type[0] == 'A':
509511
l = [0 for k in range((self.n)**2)]
510-
for k in range(self.n-1, (self.n)**2-1, self.n-1):
512+
for k in range(self.n - 1, (self.n)**2 - 1, self.n - 1):
511513
l[k] = 1
512514
m = matrix(QQ, self.n, l)
513515
elif type[0] == 'E':
514516
if type[1] == 6:
515-
half = ZZ(1)/ZZ(2)
517+
half = ZZ(1) / ZZ(2)
516518
l = [[-half, -half, -half, half, 0, 0, 0, 0],
517519
[-half, -half, half, -half, 0, 0, 0, 0],
518520
[-half, half, -half, -half, 0, 0, 0, 0],
@@ -523,10 +525,10 @@ def long_element_hardcoded(self):
523525
[0, 0, 0, 0, -half, half, half, half]]
524526
m = matrix(QQ, 8, l)
525527
else:
526-
raise NotImplementedError("Not implemented yet for this type")
528+
raise NotImplementedError("not implemented yet for this type")
527529
elif type[0] == 'G':
528-
third = ZZ(1)/ZZ(3)
529-
twothirds = ZZ(2)/ZZ(3)
530+
third = ZZ(1) / ZZ(3)
531+
twothirds = ZZ(2) / ZZ(3)
530532
l = [[-third, twothirds, twothirds],
531533
[twothirds, -third, twothirds],
532534
[twothirds, twothirds, -third]]
@@ -559,6 +561,7 @@ def classical(self):
559561
raise ValueError("classical subgroup only defined for affine types")
560562
return ClassicalWeylSubgroup(self._domain, prefix=self._prefix)
561563

564+
562565
class ClassicalWeylSubgroup(WeylGroup_gens):
563566
"""
564567
A class for Classical Weyl Subgroup of an affine Weyl Group
@@ -638,9 +641,9 @@ def __repr__(self):
638641
Parabolic Subgroup of the Weyl Group of type ['C', 4, 1]^* (as a matrix group acting on the coweight lattice)
639642
"""
640643
return "Parabolic Subgroup of the Weyl Group of type %s (as a matrix group acting on the %s)" % (self.domain().cartan_type(),
641-
self._domain._name_string(capitalize=False,
642-
base_ring=False,
643-
type=False))
644+
self._domain._name_string(capitalize=False,
645+
base_ring=False,
646+
type=False))
644647

645648
def weyl_group(self, prefix="hereditary"):
646649
"""
@@ -672,6 +675,7 @@ def _test_is_finite(self, **options):
672675
tester.assertTrue(not self.weyl_group(self._prefix).is_finite())
673676
tester.assertTrue(self.is_finite())
674677

678+
675679
class WeylGroupElement(MatrixGroupElement_gap):
676680
"""
677681
Class for a Weyl Group elements
@@ -705,7 +709,7 @@ def to_matrix(self):
705709

706710
def domain(self):
707711
"""
708-
Returns the ambient lattice associated with self.
712+
Return the ambient lattice associated with ``self``.
709713
710714
EXAMPLES::
711715
@@ -789,8 +793,8 @@ def __eq__(self, other):
789793
purposes.
790794
"""
791795
return (self.__class__ == other.__class__ and
792-
self._parent == other._parent and
793-
self.matrix() == other.matrix())
796+
self._parent == other._parent and
797+
self.matrix() == other.matrix())
794798

795799
def _richcmp_(self, other, op):
796800
"""
@@ -835,15 +839,14 @@ def action(self, v):
835839
alpha[0] + alpha[1]
836840
"""
837841
if v not in self.domain():
838-
raise ValueError("{} is not in the domain".format(v))
839-
return self.domain().from_vector(self.matrix()*v.to_vector())
842+
raise ValueError(f"{v} is not in the domain")
843+
return self.domain().from_vector(self.matrix() * v.to_vector())
840844

841-
842-
##########################################################################
845+
# #######################################################################
843846
# Descents
844-
##########################################################################
847+
# #######################################################################
845848

846-
def has_descent(self, i, positive=False, side = "right"):
849+
def has_descent(self, i, positive=False, side="right"):
847850
"""
848851
Test if ``self`` has a descent at position ``i``.
849852
@@ -934,7 +937,7 @@ def has_left_descent(self, i):
934937
sage: [(s[3]*s[2]).has_left_descent(i) for i in W.domain().index_set()]
935938
[False, False, True]
936939
"""
937-
return self.has_descent(i, side = "left")
940+
return self.has_descent(i, side="left")
938941

939942
def has_right_descent(self, i):
940943
"""
@@ -957,13 +960,14 @@ def has_right_descent(self, i):
957960
"""
958961
return self.has_descent(i, side="right")
959962

960-
def apply_simple_reflection(self, i, side = "right"):
963+
def apply_simple_reflection(self, i, side="right"):
961964
s = self.parent().simple_reflections()
962965
if side == "right":
963966
return self * s[i]
964967
else:
965968
return s[i] * self
966969

970+
# TODO
967971
# The methods first_descent, descents, reduced_word appear almost verbatim in
968972
# root_lattice_realizations and need to be factored out!
969973

@@ -978,9 +982,8 @@ def to_permutation(self):
978982
"""
979983
W = self.parent()
980984
e = W.domain().basis()
981-
return tuple( c*(j+1)
982-
for i in e.keys()
983-
for (j,c) in self.action(e[i]) )
985+
return tuple(c * (j + 1) for i in e.keys()
986+
for (j, c) in self.action(e[i]))
984987

985988
def to_permutation_string(self):
986989
"""
@@ -993,6 +996,7 @@ def to_permutation_string(self):
993996
"""
994997
return "".join(str(i) for i in self.to_permutation())
995998

999+
9961000
WeylGroup_gens.Element = WeylGroupElement
9971001

9981002

@@ -1025,13 +1029,12 @@ def __init__(self, cartan_type, prefix):
10251029
"""
10261030
self._cartan_type = cartan_type
10271031
self._index_set = cartan_type.index_set()
1028-
self._index_set_inverse = {ii: i for i,ii in enumerate(cartan_type.index_set())}
1032+
self._index_set_inverse = {ii: i for i, ii in enumerate(cartan_type.index_set())}
10291033
self._reflection_representation = None
10301034
self._prefix = prefix
1031-
#from sage.libs.gap.libgap import libgap
10321035
Q = cartan_type.root_system().root_lattice()
10331036
Phi = list(Q.positive_roots()) + [-x for x in Q.positive_roots()]
1034-
p = [[Phi.index(x.weyl_action([i]))+1 for x in Phi]
1037+
p = [[Phi.index(x.weyl_action([i])) + 1 for x in Phi]
10351038
for i in self._cartan_type.index_set()]
10361039
cat = FiniteWeylGroups()
10371040
if self._cartan_type.is_irreducible():
@@ -1207,7 +1210,7 @@ def reflection_index_set(self):
12071210
sage: W.reflection_index_set()
12081211
(1, 2, 3, 4, 5, 6)
12091212
"""
1210-
return tuple(range(1, self.number_of_reflections()+1))
1213+
return tuple(range(1, self.number_of_reflections() + 1))
12111214

12121215
def cartan_type(self):
12131216
"""
@@ -1301,9 +1304,9 @@ def distinguished_reflections(self):
13011304

13021305
def build_elt(index):
13031306
r = pos_roots[index]
1304-
perm = [Phi.index(x.reflection(r))+1 for x in Phi]
1307+
perm = [Phi.index(x.reflection(r)) + 1 for x in Phi]
13051308
return self.element_class(perm, self, check=False)
1306-
return Family(self.reflection_index_set(), lambda i: build_elt(i-1))
1309+
return Family(self.reflection_index_set(), lambda i: build_elt(i - 1))
13071310

13081311
reflections = distinguished_reflections
13091312

0 commit comments

Comments
 (0)