From 61c02408110bdcba546c23a0a7ca773dae1c564b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Sat, 26 Oct 2024 13:23:18 +0200 Subject: [PATCH] various small details in combinat --- src/sage/combinat/alternating_sign_matrix.py | 7 +++---- src/sage/combinat/lr_tableau.py | 11 ++++++----- .../combinat/multiset_partition_into_sets_ordered.py | 6 +++--- src/sage/combinat/output.py | 6 +++--- src/sage/combinat/shard_order.py | 2 +- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/sage/combinat/alternating_sign_matrix.py b/src/sage/combinat/alternating_sign_matrix.py index 230c9a8aae7..69a529054af 100644 --- a/src/sage/combinat/alternating_sign_matrix.py +++ b/src/sage/combinat/alternating_sign_matrix.py @@ -262,13 +262,12 @@ def to_monotone_triangle(self): True """ n = self._matrix.nrows() - triangle = [None] * n - prev = zero_vector(ZZ, n) + triangle = [0] * n + add_row = zero_vector(ZZ, n) for j, row in enumerate(self._matrix): - add_row = row + prev + add_row = row + add_row triangle[n - 1 - j] = [i + 1 for i in range(n - 1, -1, -1) if add_row[i] == 1] - prev = add_row return MonotoneTriangles(n)(triangle) @combinatorial_map(name='rotate counterclockwise') diff --git a/src/sage/combinat/lr_tableau.py b/src/sage/combinat/lr_tableau.py index 9a5e7a0ef03..5952f911a74 100644 --- a/src/sage/combinat/lr_tableau.py +++ b/src/sage/combinat/lr_tableau.py @@ -28,7 +28,7 @@ # http://www.gnu.org/licenses/ #**************************************************************************** -from itertools import zip_longest +from itertools import zip_longest, accumulate from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets from sage.combinat.tableau import SemistandardTableau, SemistandardTableaux @@ -277,14 +277,15 @@ def is_littlewood_richardson(t, heights): False """ from sage.combinat.words.word import Word - partial = [sum(heights[i] for i in range(j)) for j in range(len(heights)+1)] try: w = t.to_word() except AttributeError: # Not an instance of Tableau w = sum(reversed(t), []) + + partial = list(accumulate(heights, initial=0)) for i in range(len(heights)): subword = Word([j for j in w if partial[i]+1 <= j <= partial[i+1]], - alphabet=list(range(partial[i]+1,partial[i+1]+1))) + alphabet=list(range(partial[i]+1, partial[i+1]+1))) if not subword.is_yamanouchi(): return False return True @@ -305,5 +306,5 @@ def _tableau_join(t1, t2, shift=0): sage: _tableau_join([[1,2]],[[None,None,2],[3]],shift=5) [[1, 2, 7], [8]] """ - return [list(row1) + [e2+shift for e2 in row2 if e2 is not None] - for (row1, row2) in zip_longest(t1, t2, fillvalue=[])] + return [list(row1) + [e2 + shift for e2 in row2 if e2 is not None] + for row1, row2 in zip_longest(t1, t2, fillvalue=[])] diff --git a/src/sage/combinat/multiset_partition_into_sets_ordered.py b/src/sage/combinat/multiset_partition_into_sets_ordered.py index aae1cd569a2..211837f0b05 100755 --- a/src/sage/combinat/multiset_partition_into_sets_ordered.py +++ b/src/sage/combinat/multiset_partition_into_sets_ordered.py @@ -251,8 +251,8 @@ def _repr_normal(self): string_parts = (str(sorted(k)) for k in self) else: string_parts = (str(sorted(k, key=str)) for k in self) - string_parts = ", ".join(string_parts).replace("[","{").replace("]","}") - return "[" + string_parts + "]" + string = ", ".join(string_parts).replace("[", "{").replace("]", "}") + return "[" + string + "]" def _repr_tight(self): r""" @@ -670,7 +670,7 @@ def split_blocks(self, k=2): if not self: return {tuple([self]*k): 1} - out = {} + out: dict[tuple, int] = {} for t in product(*[_split_block(block, k) for block in self]): tt = tuple([P([l for l in c if l]) for c in zip(*t)]) out[tt] = out.get(tt, 0) + 1 diff --git a/src/sage/combinat/output.py b/src/sage/combinat/output.py index 1e2725448f9..3a369e7005d 100644 --- a/src/sage/combinat/output.py +++ b/src/sage/combinat/output.py @@ -738,7 +738,7 @@ def get_len(e): st += ' ' if E_box: st_num = str_tab[k-j][j] - ln_left = int((len(st_num) - (len(st_num) % 2))/2) + ln_left = len(st_num) // 2 st += st_num.rjust(row_height - 1 - ln_left + len(st_num), ' ').ljust(diag_length, ' ') else: st += ' ' * diag_length @@ -761,12 +761,12 @@ def get_len(e): import re mm = min(len(re.search('^ +', l)[0]) for l in str_list) - 1 str_list = [l[mm:].rstrip() for l in str_list] - while str_list[-1] == '': + while not str_list[-1]: str_list.pop() return "\n".join(str_list) -def box_exists(tab, i, j): +def box_exists(tab, i, j) -> bool: r""" Return ``True`` if ``tab[i][j]`` exists and is not ``None``; in particular this allows for `tab[i][j]` to be ``''`` or ``0``. diff --git a/src/sage/combinat/shard_order.py b/src/sage/combinat/shard_order.py index f9081ef77dc..002983ef747 100644 --- a/src/sage/combinat/shard_order.py +++ b/src/sage/combinat/shard_order.py @@ -88,7 +88,7 @@ def __init__(self, p): Digraph on 3 vertices """ self.runs = p.decreasing_runs(as_tuple=True) - self.run_indices = [None] * (len(p) + 1) + self.run_indices = [0] * (len(p) + 1) for i, bloc in enumerate(self.runs): for j in bloc: self.run_indices[j] = i