Skip to content

Commit cff5209

Browse files
author
Release Manager
committed
gh-40104: fix some typos and other details just fixing a few typos and then other details (pep8) in the 3 modified files ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. URL: #40104 Reported by: Frédéric Chapoton Reviewer(s): Edgar Costa
2 parents 4ea41e5 + 14929ec commit cff5209

File tree

3 files changed

+51
-42
lines changed

3 files changed

+51
-42
lines changed

src/sage/combinat/SJT.py

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,28 @@ class SJT(CombinatorialElement):
3434
A representation of a list permuted using the Steinhaus-Johnson-Trotter
3535
algorithm.
3636
37-
Each element of the list has a direction (initialized at -1) that changes at
38-
each permutation and that is used to determine which elements to transpose.
39-
The directions have three possible values:
37+
Each element of the list has a direction (initialized at -1) that
38+
changes at each permutation and that is used to determine which
39+
elements to transpose. The directions have three possible values:
4040
41-
- ``-1``: element tranposes to the left
41+
- ``-1``: element transposes to the left
4242
4343
- ``1``: element transposes to the right
4444
4545
- ``0``: element does not move
4646
47-
Thus in addition to the permutation itself, the direction of each element is
48-
also stored.
47+
Thus in addition to the permutation itself, the direction of each
48+
element is also stored.
4949
5050
Note that the permutations are not generated in lexicographic order.
5151
5252
.. WARNING::
5353
54-
An ``SJT`` object should always be created with identity permutation for
55-
the algorithm to behave properly. If the identity permutation is not
56-
provided, it expects a coherent list of directions according to the
57-
provided input. This list is not checked.
54+
An ``SJT`` object should always be created with identity
55+
permutation for the algorithm to behave properly. If the
56+
identity permutation is not provided, it expects a coherent
57+
list of directions according to the provided input. This list
58+
is not checked.
5859
5960
.. TODO::
6061
@@ -101,9 +102,9 @@ def __init__(self, l, directions=None) -> None:
101102
102103
- ``l`` -- list; a list of ordered ``int``.
103104
104-
- ``directions`` -- list (default: ``None``); a list of directions for
105-
each element in the permuted list. Used when constructing permutations
106-
from a pre-defined internal state.
105+
- ``directions`` -- list (default: ``None``); a list of
106+
directions for each element in the permuted list. Used when
107+
constructing permutations from a pre-defined internal state.
107108
108109
EXAMPLES::
109110
@@ -124,8 +125,9 @@ def __init__(self, l, directions=None) -> None:
124125
sage: s = SJT([1, 3, 2, 4])
125126
Traceback (most recent call last):
126127
...
127-
ValueError: no internal state directions were given for non-identity
128-
starting permutation for Steinhaus-Johnson-Trotter algorithm
128+
ValueError: no internal state directions were given
129+
for non-identity starting permutation
130+
for Steinhaus-Johnson-Trotter algorithm
129131
sage: s = SJT([]); s
130132
[]
131133
sage: s = s.next(); s
@@ -142,8 +144,8 @@ def __init__(self, l, directions=None) -> None:
142144
if directions is None:
143145
if not all(l[i] <= l[i+1] for i in range(self._n - 1)):
144146
raise ValueError("no internal state directions were given for "
145-
"non-identity starting permutation for "
146-
"Steinhaus-Johnson-Trotter algorithm")
147+
"non-identity starting permutation for "
148+
"Steinhaus-Johnson-Trotter algorithm")
147149
self._directions = [-1] * self._n
148150

149151
# The first element has null direction.
@@ -197,8 +199,9 @@ def next(self):
197199
if self._n == 0:
198200
return False
199201

200-
# Copying lists of permutation and directions to avoid changing internal
201-
# state of the algorithm if ``next()`` is called without reassigning.
202+
# Copying lists of permutation and directions to avoid
203+
# changing internal state of the algorithm if ``next()`` is
204+
# called without reassigning.
202205
perm = self._list[:]
203206
directions = self._directions[:]
204207

@@ -210,7 +213,8 @@ def next(self):
210213
# If this element has null direction, find the largest whose is
211214
# non-null.
212215
if direction == 0:
213-
xi = self.__idx_largest_element_non_zero_direction(perm, directions)
216+
xi = self.__idx_largest_element_non_zero_direction(perm,
217+
directions)
214218
if xi is None:
215219
# We have created every permutation. Detected when all elements
216220
# have null direction.
@@ -228,14 +232,15 @@ def next(self):
228232
# If the transposition results in the largest element being on one edge
229233
# or if the following element in its direction is greater than it, then
230234
# then set its direction to 0
231-
if new_pos == 0 or new_pos == self._n - 1 or \
232-
perm[new_pos + direction] > selected_elt:
235+
if (new_pos == 0 or new_pos == self._n - 1 or
236+
perm[new_pos + direction] > selected_elt):
233237
directions[new_pos] = 0
234238

235-
# After each permutation, update each element's direction. If one
236-
# element is greater than selected element, change its direction towards
237-
# the selected element. This loops has no reason to be if selected
238-
# element is n and this will be the case most of the time.
239+
# After each permutation, update each element's direction. If
240+
# one element is greater than selected element, change its
241+
# direction towards the selected element. This loops has no
242+
# reason to be if selected element is n and this will be the
243+
# case most of the time.
239244
if selected_elt != self._n:
240245
for i in range(self._n):
241246
if perm[i] > selected_elt:

src/sage/graphs/generators/distance_regular.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ def HermitianFormsGraph(const int n, const int r):
853853
sage: G.is_distance_regular(True)
854854
([5, 4, None], [None, 1, 2])
855855
sage: G = graphs.HermitianFormsGraph(3, 3) # not tested (2 min)
856-
sage: G.order() # not tested (bacuase of the above)
856+
sage: G.order() # not tested (because of the above)
857857
19683
858858
859859
REFERENCES:

src/sage/modules/diamond_cutting.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
# ****************************************************************************
1717

1818
from sage.geometry.polyhedron.constructor import Polyhedron
19-
from sage.matrix.constructor import matrix, identity_matrix
19+
from sage.matrix.constructor import matrix
2020
from sage.modules.free_module_element import vector
2121

2222
from math import sqrt, floor, ceil
2323

2424

25-
def plane_inequality(v):
25+
def plane_inequality(v) -> list:
2626
"""
2727
Return the inequality for points on the same side as the origin
2828
with respect to the plane through ``v`` normal to ``v``.
@@ -124,7 +124,7 @@ def jacobi(M):
124124
return matrix(q)
125125

126126

127-
def diamond_cut(V, GM, C, verbose=False):
127+
def diamond_cut(V, GM, C, verbose=False) -> Polyhedron:
128128
r"""
129129
Perform diamond cutting on polyhedron ``V`` with basis matrix ``GM``
130130
and squared radius ``C``.
@@ -137,7 +137,8 @@ def diamond_cut(V, GM, C, verbose=False):
137137
138138
- ``C`` -- square of the radius to use in cutting algorithm
139139
140-
- ``verbose`` -- boolean (default: ``False``); whether to print debug information
140+
- ``verbose`` -- boolean (default: ``False``); whether to print
141+
debug information
141142
142143
OUTPUT: a :class:`Polyhedron` instance
143144
@@ -199,7 +200,7 @@ def diamond_cut(V, GM, C, verbose=False):
199200
inequalities = []
200201
while True:
201202
if verbose:
202-
print("Dimension: {}".format(i))
203+
print(f"Dimension: {i}")
203204
if new_dimension:
204205
Z = sqrt(T[i] / q[i][i])
205206
if verbose:
@@ -212,7 +213,7 @@ def diamond_cut(V, GM, C, verbose=False):
212213

213214
x[i] += 1
214215
if verbose:
215-
print("x: {}".format(x))
216+
print(f"x: {x}")
216217
if x[i] > L[i]:
217218
i += 1
218219
elif i > 0:
@@ -249,7 +250,7 @@ def diamond_cut(V, GM, C, verbose=False):
249250
return V
250251

251252

252-
def calculate_voronoi_cell(basis, radius=None, verbose=False):
253+
def calculate_voronoi_cell(basis, radius=None, verbose=False) -> Polyhedron:
253254
"""
254255
Calculate the Voronoi cell of the lattice defined by basis.
255256
@@ -289,7 +290,8 @@ def calculate_voronoi_cell(basis, radius=None, verbose=False):
289290
sage: L = IntegerLattice([v])
290291
sage: C = L.voronoi_cell()
291292
sage: C.Hrepresentation()
292-
(An inequality (-2, -2, 2) x + 3 >= 0, An inequality (2, 2, -2) x + 3 >= 0)
293+
(An inequality (-2, -2, 2) x + 3 >= 0,
294+
An inequality (2, 2, -2) x + 3 >= 0)
293295
sage: C.Vrepresentation()
294296
(A line in the direction (0, 1, 1),
295297
A line in the direction (1, 0, 1),
@@ -299,7 +301,8 @@ def calculate_voronoi_cell(basis, radius=None, verbose=False):
299301
Verify that :issue:`37086` is fixed::
300302
301303
sage: from sage.modules.free_module_integer import IntegerLattice
302-
sage: l = [7, 0, -1, -2, -1, -2, 7, -2, 0, 0, -2, 0, 7, -2, 0, -1, -2, -1, 7, 0 , -1, -1, 0, -2, 7]
304+
sage: l = [7, 0, -1, -2, -1, -2, 7, -2, 0, 0, -2,
305+
....: 0, 7, -2, 0, -1, -2, -1, 7, 0 , -1, -1, 0, -2, 7]
303306
sage: M = matrix(5, 5, l)
304307
sage: C = IntegerLattice(M).voronoi_cell()
305308
sage: C
@@ -313,15 +316,15 @@ def calculate_voronoi_cell(basis, radius=None, verbose=False):
313316
# Convert the basis matrix to use RDF numbers for efficiency when we
314317
# calculate the triangular matrix of the QR decomposition.
315318
from sage.rings.real_double import RDF
316-
tranposed_RDF_matrix = (basis.transpose()).change_ring(RDF)
317-
R = tranposed_RDF_matrix.QR()[1]
319+
transposed_RDF_matrix = (basis.transpose()).change_ring(RDF)
320+
R = transposed_RDF_matrix.QR()[1]
318321
# The length of the vector formed by the diagonal entries of R is an
319322
# upper bound for twice the covering radius, so it is an upper bound
320323
# on the length of the lattice vectors that need to be considered for
321324
# diamond cutting. However, the value of the `radius` keyword is
322325
# actually a squared length, so there is no square root in the
323326
# following formula.
324-
radius = sum(R[i,i]**2 for i in range(dim[0]))
327+
radius = sum(R[i, i]**2 for i in range(dim[0]))
325328
# We then divide by 4 as we will divide the basis by 2 later on.
326329
radius = ceil(radius / 4)
327330
artificial_length = None
@@ -336,13 +339,14 @@ def calculate_voronoi_cell(basis, radius=None, verbose=False):
336339
from sage.rings.real_double import RDF
337340
# Convert the basis matrix to use RDF numbers for efficiency when we
338341
# perform the QR decomposition.
339-
tranposed_RDF_matrix = (additional_vectors.transpose()).change_ring(RDF)
340-
R = tranposed_RDF_matrix.QR()[1]
342+
transposed_RDF_matrix = additional_vectors.transpose().change_ring(RDF)
343+
R = transposed_RDF_matrix.QR()[1]
341344
# Since R is triangular, its smallest diagonal entry provides a
342345
# lower bound on the length of the shortest nonzero vector in the
343346
# lattice spanned by the artificial points. We square it because
344347
# value of `radius` is a squared length.
345-
shortest_vector_lower_bound = min(R[i,i]**2 for i in range(dim[1] - dim[0]))
348+
shortest_vector_lower_bound = min(R[i, i]**2
349+
for i in range(dim[1] - dim[0]))
346350
# We will multiply our artificial points by the following scalar in
347351
# order to make sure the squared length of the shortest
348352
# nonzero vector is greater than radius, even after the vectors

0 commit comments

Comments
 (0)