Skip to content

Commit 06ef9fe

Browse files
author
Release Manager
committed
sagemathgh-39477: typing and details in tableaux files add `-> bool` typing to some methods in three files related to tableaux also very minor code details ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. URL: sagemath#39477 Reported by: Frédéric Chapoton Reviewer(s): Travis Scrimshaw
2 parents 3b8531d + 033c93b commit 06ef9fe

File tree

4 files changed

+42
-38
lines changed

4 files changed

+42
-38
lines changed

src/sage/combinat/ribbon_tableau.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
from sage.rings.integer import Integer
2727
from sage.combinat.combinat import CombinatorialElement
2828
from sage.combinat.skew_partition import SkewPartition, SkewPartitions
29-
from sage.combinat.skew_tableau import SkewTableau, SkewTableaux, SemistandardSkewTableaux
29+
from sage.combinat.skew_tableau import (SkewTableau, SkewTableaux,
30+
SemistandardSkewTableaux)
3031
from sage.combinat.tableau import Tableaux
3132
from sage.combinat.partition import Partition, _Partitions
3233
from sage.combinat.permutation import to_standard
@@ -94,7 +95,8 @@ def __classcall_private__(cls, rt=None, expr=None):
9495
try:
9596
rt = [tuple(row) for row in rt]
9697
except TypeError:
97-
raise TypeError("each element of the ribbon tableau must be an iterable")
98+
raise TypeError("each element of the ribbon tableau "
99+
"must be an iterable")
98100
if not all(row for row in rt):
99101
raise TypeError("a ribbon tableau cannot have empty rows")
100102
# calls the inherited __init__ method (of SkewTableau )
@@ -195,9 +197,10 @@ class RibbonTableaux(UniqueRepresentation, Parent):
195197
196198
REFERENCES:
197199
198-
.. [vanLeeuwen91] Marc. A. A. van Leeuwen, *Edge sequences, ribbon tableaux,
199-
and an action of affine permutations*. Europe J. Combinatorics. **20**
200-
(1999). http://wwwmathlabo.univ-poitiers.fr/~maavl/pdf/edgeseqs.pdf
200+
.. [vanLeeuwen91] Marc. A. A. van Leeuwen, *Edge sequences,
201+
ribbon tableaux, and an action of affine permutations*.
202+
Europe J. Combinatorics. **20** (1999).
203+
http://wwwmathlabo.univ-poitiers.fr/~maavl/pdf/edgeseqs.pdf
201204
"""
202205
@staticmethod
203206
def __classcall_private__(cls, shape=None, weight=None, length=None):
@@ -318,10 +321,11 @@ def __iter__(self):
318321
sage: RibbonTableaux([[2,2],[]],[1,1],2).list()
319322
[[[0, 0], [1, 2]], [[1, 0], [2, 0]]]
320323
"""
321-
for x in graph_implementation_rec(self._shape, self._weight, self._length, list_rec):
324+
for x in graph_implementation_rec(self._shape, self._weight,
325+
self._length, list_rec):
322326
yield self.from_expr(x)
323327

324-
def _repr_(self):
328+
def _repr_(self) -> str:
325329
"""
326330
Return a string representation of ``self``.
327331
@@ -332,7 +336,7 @@ def _repr_(self):
332336
"""
333337
return "Ribbon tableaux of shape %s and weight %s with %s-ribbons" % (repr(self._shape), list(self._weight), self._length)
334338

335-
def __contains__(self, x):
339+
def __contains__(self, x) -> bool:
336340
"""
337341
Note that this just checks to see if ``x`` appears in ``self``.
338342
@@ -855,7 +859,7 @@ def weight(self):
855859
[5, 3, 1]
856860
"""
857861
weights = [x.weight() for x in self]
858-
m = max([len(x) for x in weights])
862+
m = max(len(x) for x in weights)
859863
weight = [0] * m
860864
for w in weights:
861865
for i in range(len(w)):

src/sage/combinat/skew_tableau.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ def weight(self):
620620

621621
evaluation = weight
622622

623-
def is_standard(self):
623+
def is_standard(self) -> bool:
624624
"""
625625
Return ``True`` if ``self`` is a standard skew tableau and ``False``
626626
otherwise.
@@ -640,7 +640,7 @@ def is_standard(self):
640640
w = [i for row in self for i in row if i is not None]
641641
return sorted(w) == list(range(1, len(w) + 1)) and self.is_semistandard()
642642

643-
def is_semistandard(self):
643+
def is_semistandard(self) -> bool:
644644
"""
645645
Return ``True`` if ``self`` is a semistandard skew tableau and
646646
``False`` otherwise.
@@ -1324,7 +1324,7 @@ def shuffle(self, t2):
13241324
corner = self.cells_containing(i)[0]
13251325

13261326
# slide t2_new backwards, record i in the vacated square
1327-
(t2_new, (x, y)) = t2_new.slide(corner, True)
1327+
t2_new, (x, y) = t2_new.slide(corner, True)
13281328
t1_new[x][y] = i
13291329

13301330
t1_new = SkewTableau(t1_new)
@@ -1582,10 +1582,12 @@ def to_expr(self):
15821582
rows.reverse()
15831583
return [self.inner_shape(), rows]
15841584

1585-
def is_ribbon(self):
1585+
def is_ribbon(self) -> bool:
15861586
r"""
15871587
Return ``True`` if and only if the shape of ``self`` is a
1588-
ribbon, that is, if it has exactly one cell in each of `q`
1588+
ribbon.
1589+
1590+
This means that it has exactly one cell in each of `q`
15891591
consecutive diagonals for some nonnegative integer `q`.
15901592
15911593
EXAMPLES::
@@ -1824,7 +1826,7 @@ def cells_containing(self, i):
18241826
cell_list.append((r, c))
18251827
return cell_list
18261828

1827-
def is_k_tableau(self, k):
1829+
def is_k_tableau(self, k) -> bool:
18281830
r"""
18291831
Check whether ``self`` is a valid skew weak `k`-tableau.
18301832
@@ -1857,11 +1859,9 @@ def _label_skew(list_of_cells, sk):
18571859
sage: skew_tableau._label_skew(l, empty)
18581860
[[1, 4], [3, 2]]
18591861
"""
1860-
i = 1
18611862
skew = [list(row) for row in sk]
1862-
for row, column in list_of_cells:
1863+
for i, (row, column) in enumerate(list_of_cells, start=1):
18631864
skew[row][column] = i
1864-
i += 1
18651865
return skew
18661866

18671867

src/sage/combinat/tableau.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,7 @@ def to_sign_matrix(self, max_entry=None):
12981298
raise ValueError("the entries must be nonnegative integers")
12991299
from sage.matrix.matrix_space import MatrixSpace
13001300
if max_entry is None:
1301-
max_entry = max([max(c) for c in self])
1301+
max_entry = max(max(c) for c in self)
13021302
MS = MatrixSpace(ZZ, len(self[0]), max_entry)
13031303
Tconj = self.conjugate()
13041304
conj_len = len(Tconj)
@@ -1694,7 +1694,7 @@ def weight(self):
16941694

16951695
evaluation = weight
16961696

1697-
def is_row_strict(self):
1697+
def is_row_strict(self) -> bool:
16981698
"""
16991699
Return ``True`` if ``self`` is a row strict tableau and ``False``
17001700
otherwise.
@@ -1715,7 +1715,7 @@ def is_row_strict(self):
17151715
"""
17161716
return all(row[i] < row[i+1] for row in self for i in range(len(row)-1))
17171717

1718-
def is_row_increasing(self, weak=False):
1718+
def is_row_increasing(self, weak=False) -> bool:
17191719
r"""
17201720
Return ``True`` if the entries in each row are in increasing order,
17211721
and ``False`` otherwise.
@@ -1741,7 +1741,7 @@ def test(a, b):
17411741
return a < b
17421742
return all(test(a, b) for row in self for (a, b) in zip(row, row[1:]))
17431743

1744-
def is_column_increasing(self, weak=False):
1744+
def is_column_increasing(self, weak=False) -> bool:
17451745
r"""
17461746
Return ``True`` if the entries in each column are in increasing order,
17471747
and ``False`` otherwise.
@@ -1770,7 +1770,7 @@ def tworow(a, b):
17701770
return all(test(a[i], b_i) for i, b_i in enumerate(b))
17711771
return all(tworow(self[r], self[r + 1]) for r in range(len(self) - 1))
17721772

1773-
def is_column_strict(self):
1773+
def is_column_strict(self) -> bool:
17741774
"""
17751775
Return ``True`` if ``self`` is a column strict tableau and ``False``
17761776
otherwise.
@@ -1801,7 +1801,7 @@ def tworow(a, b):
18011801
return all(a[i] < b_i for i, b_i in enumerate(b))
18021802
return all(tworow(self[r], self[r+1]) for r in range(len(self)-1))
18031803

1804-
def is_semistandard(self):
1804+
def is_semistandard(self) -> bool:
18051805
r"""
18061806
Return ``True`` if ``self`` is a semistandard tableau, and ``False``
18071807
otherwise.
@@ -1824,7 +1824,7 @@ def is_semistandard(self):
18241824
"""
18251825
return self.is_row_increasing(weak=True) and self.is_column_increasing()
18261826

1827-
def is_standard(self):
1827+
def is_standard(self) -> bool:
18281828
"""
18291829
Return ``True`` if ``self`` is a standard tableau and ``False``
18301830
otherwise.
@@ -1843,7 +1843,7 @@ def is_standard(self):
18431843
entries = sorted(self.entries())
18441844
return entries == list(range(1, self.size() + 1)) and self.is_row_strict() and self.is_column_strict()
18451845

1846-
def is_increasing(self):
1846+
def is_increasing(self) -> bool:
18471847
"""
18481848
Return ``True`` if ``self`` is an increasing tableau and
18491849
``False`` otherwise.
@@ -1865,7 +1865,7 @@ def is_increasing(self):
18651865
"""
18661866
return self.is_row_strict() and self.is_column_strict()
18671867

1868-
def is_rectangular(self):
1868+
def is_rectangular(self) -> bool:
18691869
"""
18701870
Return ``True`` if the tableau ``self`` is rectangular and
18711871
``False`` otherwise.
@@ -2067,7 +2067,7 @@ def k_weight(self, k):
20672067

20682068
return res
20692069

2070-
def is_k_tableau(self, k):
2070+
def is_k_tableau(self, k) -> bool:
20712071
r"""
20722072
Check whether ``self`` is a valid weak `k`-tableau.
20732073
@@ -2518,7 +2518,7 @@ def reverse_bump(self, loc):
25182518
if not (self.is_semistandard()):
25192519
raise ValueError("reverse bumping is only defined for semistandard tableaux")
25202520
try:
2521-
(r, c) = loc
2521+
r, c = loc
25222522
if (r, c) not in self.corners():
25232523
raise ValueError("invalid corner")
25242524
except TypeError:
@@ -3177,7 +3177,7 @@ def add_entry(self, cell, m):
31773177
IndexError: (2, 2) is not an addable cell of the tableau
31783178
"""
31793179
tab = self.to_list()
3180-
(r, c) = cell
3180+
r, c = cell
31813181
try:
31823182
tab[r][c] = m # will work if we are replacing an entry
31833183
except IndexError:
@@ -3616,7 +3616,7 @@ def symmetric_group_action_on_entries(self, w):
36163616
except Exception:
36173617
return Tableau([[w[entry-1] for entry in row] for row in self])
36183618

3619-
def is_key_tableau(self):
3619+
def is_key_tableau(self) -> bool:
36203620
r"""
36213621
Return ``True`` if ``self`` is a key tableau or ``False`` otherwise.
36223622
@@ -4788,7 +4788,7 @@ def dominates(self, t):
47884788
return all(self.restrict(m).shape().dominates(t.restrict(m).shape())
47894789
for m in range(1, 1 + self.size()))
47904790

4791-
def is_standard(self):
4791+
def is_standard(self) -> bool:
47924792
"""
47934793
Return ``True`` since ``self`` is a standard tableau.
47944794

src/sage/combinat/tableau_tuple.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ def entry(self, l, r, c):
823823
"""
824824
return self[l][r][c]
825825

826-
def is_row_strict(self):
826+
def is_row_strict(self) -> bool:
827827
"""
828828
Return ``True`` if the tableau ``self`` is row strict and ``False``
829829
otherwise.
@@ -874,7 +874,7 @@ def first_row_descent(self):
874874
return (k, cell[0], cell[1])
875875
return None
876876

877-
def is_column_strict(self):
877+
def is_column_strict(self) -> bool:
878878
"""
879879
Return ``True`` if the tableau ``self`` is column strict and ``False``
880880
otherwise.
@@ -925,7 +925,7 @@ def first_column_descent(self):
925925
return (k, cell[0], cell[1])
926926
return None
927927

928-
def is_standard(self):
928+
def is_standard(self) -> bool:
929929
r"""
930930
Return ``True`` if the tableau ``self`` is a standard tableau and
931931
``False`` otherwise.
@@ -1173,7 +1173,7 @@ def add_entry(self, cell, m):
11731173
...
11741174
IndexError: (2, 1, 2) is not an addable cell of the tableau
11751175
"""
1176-
(k, r, c) = cell
1176+
k, r, c = cell
11771177
tab = self.to_list()
11781178

11791179
try:
@@ -5017,7 +5017,7 @@ def random_element(self):
50175017
while m < mu.size():
50185018
m += 1
50195019
i = randint(0, len(addables) - 1) # index for a random addable cell
5020-
(k, r, c) = addables[i] # the actual cell
5020+
k, r, c = addables[i] # the actual cell
50215021
# remove the cell we just added from the list addable nodes
50225022
addables.pop(i)
50235023
# add m into the tableau
@@ -5336,7 +5336,7 @@ def _add_entry_fast(T, cell, m):
53365336
6 8 12 14 2 11
53375337
10
53385338
"""
5339-
(k, r, c) = cell
5339+
k, r, c = cell
53405340
tab = T.to_list()
53415341

53425342
try:

0 commit comments

Comments
 (0)