From b95f344a698d26faae50de392c773fe53d70f777 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Fri, 7 Feb 2025 20:53:56 +0100 Subject: [PATCH 1/3] typing and details in tableaux files --- src/sage/combinat/skew_tableau.py | 18 +++++++++--------- src/sage/combinat/tableau.py | 26 +++++++++++++------------- src/sage/combinat/tableau_tuple.py | 12 ++++++------ 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/sage/combinat/skew_tableau.py b/src/sage/combinat/skew_tableau.py index 44189013d5c..469a84e9ee9 100644 --- a/src/sage/combinat/skew_tableau.py +++ b/src/sage/combinat/skew_tableau.py @@ -620,7 +620,7 @@ def weight(self): evaluation = weight - def is_standard(self): + def is_standard(self) -> bool: """ Return ``True`` if ``self`` is a standard skew tableau and ``False`` otherwise. @@ -640,7 +640,7 @@ def is_standard(self): w = [i for row in self for i in row if i is not None] return sorted(w) == list(range(1, len(w) + 1)) and self.is_semistandard() - def is_semistandard(self): + def is_semistandard(self) -> bool: """ Return ``True`` if ``self`` is a semistandard skew tableau and ``False`` otherwise. @@ -1324,7 +1324,7 @@ def shuffle(self, t2): corner = self.cells_containing(i)[0] # slide t2_new backwards, record i in the vacated square - (t2_new, (x, y)) = t2_new.slide(corner, True) + t2_new, (x, y) = t2_new.slide(corner, True) t1_new[x][y] = i t1_new = SkewTableau(t1_new) @@ -1582,10 +1582,12 @@ def to_expr(self): rows.reverse() return [self.inner_shape(), rows] - def is_ribbon(self): + def is_ribbon(self) -> bool: r""" Return ``True`` if and only if the shape of ``self`` is a - ribbon, that is, if it has exactly one cell in each of `q` + ribbon. + + This means that it has exactly one cell in each of `q` consecutive diagonals for some nonnegative integer `q`. EXAMPLES:: @@ -1824,7 +1826,7 @@ def cells_containing(self, i): cell_list.append((r, c)) return cell_list - def is_k_tableau(self, k): + def is_k_tableau(self, k) -> bool: r""" Check whether ``self`` is a valid skew weak `k`-tableau. @@ -1857,11 +1859,9 @@ def _label_skew(list_of_cells, sk): sage: skew_tableau._label_skew(l, empty) [[1, 4], [3, 2]] """ - i = 1 skew = [list(row) for row in sk] - for row, column in list_of_cells: + for i, (row, column) in enumerate(list_of_cells, start=1): skew[row][column] = i - i += 1 return skew diff --git a/src/sage/combinat/tableau.py b/src/sage/combinat/tableau.py index eef2536beba..8b33b1cbd66 100644 --- a/src/sage/combinat/tableau.py +++ b/src/sage/combinat/tableau.py @@ -1694,7 +1694,7 @@ def weight(self): evaluation = weight - def is_row_strict(self): + def is_row_strict(self) -> bool: """ Return ``True`` if ``self`` is a row strict tableau and ``False`` otherwise. @@ -1715,7 +1715,7 @@ def is_row_strict(self): """ return all(row[i] < row[i+1] for row in self for i in range(len(row)-1)) - def is_row_increasing(self, weak=False): + def is_row_increasing(self, weak=False) -> bool: r""" Return ``True`` if the entries in each row are in increasing order, and ``False`` otherwise. @@ -1741,7 +1741,7 @@ def test(a, b): return a < b return all(test(a, b) for row in self for (a, b) in zip(row, row[1:])) - def is_column_increasing(self, weak=False): + def is_column_increasing(self, weak=False) -> bool: r""" Return ``True`` if the entries in each column are in increasing order, and ``False`` otherwise. @@ -1770,7 +1770,7 @@ def tworow(a, b): return all(test(a[i], b_i) for i, b_i in enumerate(b)) return all(tworow(self[r], self[r + 1]) for r in range(len(self) - 1)) - def is_column_strict(self): + def is_column_strict(self) -> bool: """ Return ``True`` if ``self`` is a column strict tableau and ``False`` otherwise. @@ -1801,7 +1801,7 @@ def tworow(a, b): return all(a[i] < b_i for i, b_i in enumerate(b)) return all(tworow(self[r], self[r+1]) for r in range(len(self)-1)) - def is_semistandard(self): + def is_semistandard(self) -> bool: r""" Return ``True`` if ``self`` is a semistandard tableau, and ``False`` otherwise. @@ -1824,7 +1824,7 @@ def is_semistandard(self): """ return self.is_row_increasing(weak=True) and self.is_column_increasing() - def is_standard(self): + def is_standard(self) -> bool: """ Return ``True`` if ``self`` is a standard tableau and ``False`` otherwise. @@ -1843,7 +1843,7 @@ def is_standard(self): entries = sorted(self.entries()) return entries == list(range(1, self.size() + 1)) and self.is_row_strict() and self.is_column_strict() - def is_increasing(self): + def is_increasing(self) -> bool: """ Return ``True`` if ``self`` is an increasing tableau and ``False`` otherwise. @@ -1865,7 +1865,7 @@ def is_increasing(self): """ return self.is_row_strict() and self.is_column_strict() - def is_rectangular(self): + def is_rectangular(self) -> bool: """ Return ``True`` if the tableau ``self`` is rectangular and ``False`` otherwise. @@ -2067,7 +2067,7 @@ def k_weight(self, k): return res - def is_k_tableau(self, k): + def is_k_tableau(self, k) -> bool: r""" Check whether ``self`` is a valid weak `k`-tableau. @@ -2518,7 +2518,7 @@ def reverse_bump(self, loc): if not (self.is_semistandard()): raise ValueError("reverse bumping is only defined for semistandard tableaux") try: - (r, c) = loc + r, c = loc if (r, c) not in self.corners(): raise ValueError("invalid corner") except TypeError: @@ -3177,7 +3177,7 @@ def add_entry(self, cell, m): IndexError: (2, 2) is not an addable cell of the tableau """ tab = self.to_list() - (r, c) = cell + r, c = cell try: tab[r][c] = m # will work if we are replacing an entry except IndexError: @@ -3616,7 +3616,7 @@ def symmetric_group_action_on_entries(self, w): except Exception: return Tableau([[w[entry-1] for entry in row] for row in self]) - def is_key_tableau(self): + def is_key_tableau(self) -> bool: r""" Return ``True`` if ``self`` is a key tableau or ``False`` otherwise. @@ -4788,7 +4788,7 @@ def dominates(self, t): return all(self.restrict(m).shape().dominates(t.restrict(m).shape()) for m in range(1, 1 + self.size())) - def is_standard(self): + def is_standard(self) -> bool: """ Return ``True`` since ``self`` is a standard tableau. diff --git a/src/sage/combinat/tableau_tuple.py b/src/sage/combinat/tableau_tuple.py index 6c75106154b..863b47dc6a6 100644 --- a/src/sage/combinat/tableau_tuple.py +++ b/src/sage/combinat/tableau_tuple.py @@ -823,7 +823,7 @@ def entry(self, l, r, c): """ return self[l][r][c] - def is_row_strict(self): + def is_row_strict(self) -> bool: """ Return ``True`` if the tableau ``self`` is row strict and ``False`` otherwise. @@ -874,7 +874,7 @@ def first_row_descent(self): return (k, cell[0], cell[1]) return None - def is_column_strict(self): + def is_column_strict(self) -> bool: """ Return ``True`` if the tableau ``self`` is column strict and ``False`` otherwise. @@ -925,7 +925,7 @@ def first_column_descent(self): return (k, cell[0], cell[1]) return None - def is_standard(self): + def is_standard(self) -> bool: r""" Return ``True`` if the tableau ``self`` is a standard tableau and ``False`` otherwise. @@ -1173,7 +1173,7 @@ def add_entry(self, cell, m): ... IndexError: (2, 1, 2) is not an addable cell of the tableau """ - (k, r, c) = cell + k, r, c = cell tab = self.to_list() try: @@ -5017,7 +5017,7 @@ def random_element(self): while m < mu.size(): m += 1 i = randint(0, len(addables) - 1) # index for a random addable cell - (k, r, c) = addables[i] # the actual cell + k, r, c = addables[i] # the actual cell # remove the cell we just added from the list addable nodes addables.pop(i) # add m into the tableau @@ -5336,7 +5336,7 @@ def _add_entry_fast(T, cell, m): 6 8 12 14 2 11 10 """ - (k, r, c) = cell + k, r, c = cell tab = T.to_list() try: From 400bd424232aa508c34388a17249b311073a4f7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Fri, 7 Feb 2025 21:06:17 +0100 Subject: [PATCH 2/3] two more details in tableaux --- src/sage/combinat/ribbon_tableau.py | 4 ++-- src/sage/combinat/tableau.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sage/combinat/ribbon_tableau.py b/src/sage/combinat/ribbon_tableau.py index 6a1643a46c7..66e6348e58b 100644 --- a/src/sage/combinat/ribbon_tableau.py +++ b/src/sage/combinat/ribbon_tableau.py @@ -854,8 +854,8 @@ def weight(self): sage: a.weight() [5, 3, 1] """ - weights = [x.weight() for x in self] - m = max([len(x) for x in weights]) + weights = (x.weight() for x in self) + m = max(len(x) for x in weights) weight = [0] * m for w in weights: for i in range(len(w)): diff --git a/src/sage/combinat/tableau.py b/src/sage/combinat/tableau.py index 8b33b1cbd66..c9d1164d0a5 100644 --- a/src/sage/combinat/tableau.py +++ b/src/sage/combinat/tableau.py @@ -1298,7 +1298,7 @@ def to_sign_matrix(self, max_entry=None): raise ValueError("the entries must be nonnegative integers") from sage.matrix.matrix_space import MatrixSpace if max_entry is None: - max_entry = max([max(c) for c in self]) + max_entry = max(max(c) for c in self) MS = MatrixSpace(ZZ, len(self[0]), max_entry) Tconj = self.conjugate() conj_len = len(Tconj) From 033c93b2b263cc61f00528658038023c6c762eb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Fri, 7 Feb 2025 21:59:21 +0100 Subject: [PATCH 3/3] fix mistake --- src/sage/combinat/ribbon_tableau.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/sage/combinat/ribbon_tableau.py b/src/sage/combinat/ribbon_tableau.py index 66e6348e58b..a849c6ac88f 100644 --- a/src/sage/combinat/ribbon_tableau.py +++ b/src/sage/combinat/ribbon_tableau.py @@ -26,7 +26,8 @@ from sage.rings.integer import Integer from sage.combinat.combinat import CombinatorialElement from sage.combinat.skew_partition import SkewPartition, SkewPartitions -from sage.combinat.skew_tableau import SkewTableau, SkewTableaux, SemistandardSkewTableaux +from sage.combinat.skew_tableau import (SkewTableau, SkewTableaux, + SemistandardSkewTableaux) from sage.combinat.tableau import Tableaux from sage.combinat.partition import Partition, _Partitions from sage.combinat.permutation import to_standard @@ -94,7 +95,8 @@ def __classcall_private__(cls, rt=None, expr=None): try: rt = [tuple(row) for row in rt] except TypeError: - raise TypeError("each element of the ribbon tableau must be an iterable") + raise TypeError("each element of the ribbon tableau " + "must be an iterable") if not all(row for row in rt): raise TypeError("a ribbon tableau cannot have empty rows") # calls the inherited __init__ method (of SkewTableau ) @@ -195,9 +197,10 @@ class RibbonTableaux(UniqueRepresentation, Parent): REFERENCES: - .. [vanLeeuwen91] Marc. A. A. van Leeuwen, *Edge sequences, ribbon tableaux, - and an action of affine permutations*. Europe J. Combinatorics. **20** - (1999). http://wwwmathlabo.univ-poitiers.fr/~maavl/pdf/edgeseqs.pdf + .. [vanLeeuwen91] Marc. A. A. van Leeuwen, *Edge sequences, + ribbon tableaux, and an action of affine permutations*. + Europe J. Combinatorics. **20** (1999). + http://wwwmathlabo.univ-poitiers.fr/~maavl/pdf/edgeseqs.pdf """ @staticmethod def __classcall_private__(cls, shape=None, weight=None, length=None): @@ -318,10 +321,11 @@ def __iter__(self): sage: RibbonTableaux([[2,2],[]],[1,1],2).list() [[[0, 0], [1, 2]], [[1, 0], [2, 0]]] """ - for x in graph_implementation_rec(self._shape, self._weight, self._length, list_rec): + for x in graph_implementation_rec(self._shape, self._weight, + self._length, list_rec): yield self.from_expr(x) - def _repr_(self): + def _repr_(self) -> str: """ Return a string representation of ``self``. @@ -332,7 +336,7 @@ def _repr_(self): """ return "Ribbon tableaux of shape %s and weight %s with %s-ribbons" % (repr(self._shape), list(self._weight), self._length) - def __contains__(self, x): + def __contains__(self, x) -> bool: """ Note that this just checks to see if ``x`` appears in ``self``. @@ -854,7 +858,7 @@ def weight(self): sage: a.weight() [5, 3, 1] """ - weights = (x.weight() for x in self) + weights = [x.weight() for x in self] m = max(len(x) for x in weights) weight = [0] * m for w in weights: