Skip to content

Commit

Permalink
gh-38857: various small details in combinat
Browse files Browse the repository at this point in the history
    
some of them are made to please the type-checker `mypy`

### 📝 Checklist

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.
    
URL: #38857
Reported by: Frédéric Chapoton
Reviewer(s): David Coudert, Frédéric Chapoton
  • Loading branch information
Release Manager committed Nov 2, 2024
2 parents ac72d64 + 61c0240 commit 59a5a5f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
7 changes: 3 additions & 4 deletions src/sage/combinat/alternating_sign_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
11 changes: 6 additions & 5 deletions src/sage/combinat/lr_tableau.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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=[])]
6 changes: 3 additions & 3 deletions src/sage/combinat/multiset_partition_into_sets_ordered.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/sage/combinat/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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``.
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/shard_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 59a5a5f

Please sign in to comment.