Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

various small details in combinat #38857

Merged
merged 1 commit into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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("]", "}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't it a bad idea to call a variable string ? it's also a type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, this is not a reserved keyword

sage: type(string)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[1], line 1
----> 1 type(string)

NameError: name 'string' is not defined

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
Loading