Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Optimization of add_*_border_strip() and doctest update.
Browse files Browse the repository at this point in the history
  • Loading branch information
tscrim committed Aug 11, 2022
1 parent 12be2d9 commit 6ccd9e4
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 79 deletions.
118 changes: 76 additions & 42 deletions src/sage/combinat/partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@
from . import permutation
from . import composition
from sage.combinat.partitions import ZS1_iterator, ZS1_iterator_nk
from sage.combinat.integer_vector import IntegerVectors
from sage.combinat.integer_lists import IntegerListsLex
from sage.combinat.integer_lists.invlex import IntegerListsBackend_invlex
from sage.combinat.integer_vector_weighted import iterator_fast as weighted_iterator_fast
from sage.combinat.combinat_cython import conjugate
from sage.combinat.root_system.weyl_group import WeylGroup
Expand Down Expand Up @@ -4655,67 +4655,101 @@ def add_vertical_border_strip(self, k):
sage: Partition([]).add_vertical_border_strip(0)
[[]]
sage: Partition([3,2,1]).add_vertical_border_strip(0)
[[3, 2, 1]]
sage: Partition([]).add_vertical_border_strip(2)
[[1, 1]]
sage: Partition([2,2]).add_vertical_border_strip(2)
[[3, 3], [3, 2, 1], [2, 2, 1, 1]]
sage: Partition([3,2,2]).add_vertical_border_strip(2)
[[4, 3, 2], [4, 2, 2, 1], [3, 3, 3], [3, 3, 2, 1], [3, 2, 2, 1, 1]]
"""
return [p.conjugate() for p in self.conjugate().add_horizontal_border_strip(k)]
if k == 0:
return [self]

def add_horizontal_border_strip(self, k):
"""
Return a list of all the partitions that can be obtained by adding
a horizontal border strip of length ``k`` to ``self``.
EXAMPLES::
sage: Partition([]).add_horizontal_border_strip(0)
[[]]
sage: Partition([]).add_horizontal_border_strip(2)
[[2]]
sage: Partition([2,2]).add_horizontal_border_strip(2)
[[2, 2, 2], [3, 2, 1], [4, 2]]
sage: Partition([3,2,2]).add_horizontal_border_strip(2)
[[3, 2, 2, 2], [3, 3, 2, 1], [4, 2, 2, 1], [4, 3, 2], [5, 2, 2]]
.. TODO::
Reimplement like ``remove_horizontal_border_strip`` using
:class:`IntegerListsLex`
"""
conj = self.conjugate().to_list()
shelf = []
res = []
i = 0
while i < len(conj):
ell = len(self._list)
while i < ell:
tmp = 1
while i+1 < len(conj) and conj[i] == conj[i+1]:
while i+1 < ell and self._list[i] == self._list[i+1]:
tmp += 1
i += 1
if i == len(conj)-1 and i > 0 and conj[i] != conj[i-1]:
if i == ell-1 and i > 0 and self._list[i] != self._list[i-1]:
tmp = 1
shelf.append(tmp)
i += 1

#added the last shelf on the right side of
#the first line
# added the last shelf on the right side of
# the first line
shelf.append(k)

#list all of the positions for cells
#filling each self from the left to the right
for iv in IntegerVectors(k, len(shelf), outer=shelf):
iv = list(iv) # Make a mutable list
tmp = conj + [0]*k
# list all of the positions for cells
# filling each self from the left to the right
for iv in IntegerListsBackend_invlex(k, length=len(shelf), ceiling=shelf, check=False)._iter():
tmp = self._list + [0]*k
j = 0
for t in range(len(iv)):
while iv[t] > 0:
for _ in range(iv[t]):
tmp[j] += 1
iv[t] -= 1
j += 1
j = sum(shelf[:t+1])
res.append(Partition([u for u in tmp if u != 0]).conjugate())
# This should never return the empty partition.
# So tmp should never be [0, ..., 0].
while not tmp[-1]:
tmp.pop()
res.append(_Partitions(tmp))
return res

def add_horizontal_border_strip(self, k):
"""
Return a list of all the partitions that can be obtained by adding
a horizontal border strip of length ``k`` to ``self``.
EXAMPLES::
sage: Partition([]).add_horizontal_border_strip(0)
[[]]
sage: Partition([3,2,1]).add_horizontal_border_strip(0)
[[3, 2, 1]]
sage: Partition([]).add_horizontal_border_strip(2)
[[2]]
sage: Partition([2,2]).add_horizontal_border_strip(2)
[[4, 2], [3, 2, 1], [2, 2, 2]]
sage: Partition([3,2,2]).add_horizontal_border_strip(2)
[[5, 2, 2], [4, 3, 2], [4, 2, 2, 1], [3, 3, 2, 1], [3, 2, 2, 2]]
"""
if k == 0:
return [self]

L = self._list
res = []
mapping = [0]
shelf = [k]
for i in range(len(L)-1):
val = L[i] - L[i+1]
if not val:
continue
mapping.append(i+1)
shelf.append(val)

# add the last shelf
if L:
mapping.append(len(L))
shelf.append(L[-1])

# list all of the positions for cells
# filling each self from the top to bottom
for iv in IntegerListsBackend_invlex(k, length=len(shelf), ceiling=shelf, check=False)._iter():
tmp = self._list + [0]
for i, val in enumerate(iv):
if val:
tmp[mapping[i]] += val
# Only the last row is possibly empty
if not tmp[-1]:
tmp.pop()
res.append(_Partitions(tmp))
return res

def remove_horizontal_border_strip(self, k):
Expand Down Expand Up @@ -4839,7 +4873,7 @@ def atom(self):
return res

def k_atom(self, k):
"""
r"""
Return a list of the standard tableaux of size ``self.size()`` whose
``k``-atom is equal to ``self``.
Expand All @@ -4849,12 +4883,12 @@ def k_atom(self, k):
sage: p.k_atom(1)
[]
sage: p.k_atom(3)
[[[1, 1, 1], [2, 2], [3]],
[[1, 1, 1, 2], [2], [3]],
[[[1, 1, 1, 2, 3], [2]],
[[1, 1, 1, 3], [2, 2]],
[[1, 1, 1, 2, 3], [2]]]
[[1, 1, 1, 2], [2], [3]],
[[1, 1, 1], [2, 2], [3]]]
sage: Partition([3,2,1]).k_atom(4)
[[[1, 1, 1], [2, 2], [3]], [[1, 1, 1, 3], [2, 2]]]
[[[1, 1, 1, 3], [2, 2]], [[1, 1, 1], [2, 2], [3]]]
TESTS::
Expand Down
54 changes: 27 additions & 27 deletions src/sage/combinat/superpartition.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,19 +678,19 @@ def add_horizontal_border_strip_star(self, h) -> list:
EXAMPLES::
sage: SuperPartition([[4,1],[3]]).add_horizontal_border_strip_star(3)
[[4, 1; 3, 3],
[4, 1; 4, 2],
[3, 1; 5, 2],
[4, 1; 5, 1],
[[3, 1; 7],
[4, 1; 6],
[3, 0; 6, 2],
[3, 1; 6, 1],
[4, 0; 4, 3],
[3, 0; 5, 3],
[4, 0; 5, 2],
[3, 0; 6, 2],
[4, 1; 6],
[3, 1; 7]]
[4, 1; 5, 1],
[3, 0; 5, 3],
[3, 1; 5, 2],
[4, 0; 4, 3],
[4, 1; 4, 2],
[4, 1; 3, 3]]
sage: SuperPartition([[2,1],[3]]).add_horizontal_border_strip_star(2)
[[2, 1; 3, 2], [2, 1; 4, 1], [2, 0; 3, 3], [2, 0; 4, 2], [2, 1; 5]]
[[2, 1; 5], [2, 0; 4, 2], [2, 1; 4, 1], [2, 0; 3, 3], [2, 1; 3, 2]]
"""
sp1, circ_list = self.to_circled_diagram()
nsp = [list(la) + [0] for la in sp1.add_horizontal_border_strip(h)]
Expand Down Expand Up @@ -726,29 +726,29 @@ def add_horizontal_border_strip_star_bar(self, h) -> list:
EXAMPLES::
sage: SuperPartition([[4,1],[5,4]]).add_horizontal_border_strip_star_bar(3)
[[4, 3; 5, 4, 1],
[4, 1; 5, 4, 3],
[4, 2; 5, 5, 1],
[4, 1; 5, 5, 2],
[[4, 1; 8, 4],
[4, 1; 7, 5],
[4, 2; 7, 4],
[4, 1; 7, 4, 1],
[4, 2; 6, 5],
[4, 1; 6, 5, 1],
[4, 3; 6, 4],
[4, 2; 6, 4, 1],
[4, 1; 6, 4, 2],
[4, 1; 6, 5, 1],
[4, 1; 7, 4, 1],
[4, 3; 5, 5],
[4, 3; 6, 4],
[4, 2; 6, 5],
[4, 2; 7, 4],
[4, 1; 7, 5],
[4, 1; 8, 4]]
[4, 2; 5, 5, 1],
[4, 1; 5, 5, 2],
[4, 3; 5, 4, 1],
[4, 1; 5, 4, 3]]
sage: SuperPartition([[3,1],[5]]).add_horizontal_border_strip_star_bar(2)
[[3, 2; 5, 1],
[3, 1; 5, 2],
[4, 1; 5, 1],
[[3, 1; 7],
[4, 1; 6],
[3, 2; 6],
[3, 1; 6, 1],
[4, 2; 5],
[3, 2; 6],
[4, 1; 6],
[3, 1; 7]]
[4, 1; 5, 1],
[3, 2; 5, 1],
[3, 1; 5, 2]]
"""
sp1, circ_list = self.to_circled_diagram()
nsp = [list(la) + [0] for la in sp1.add_horizontal_border_strip(h)]
Expand Down
20 changes: 10 additions & 10 deletions src/sage/combinat/tableau.py
Original file line number Diff line number Diff line change
Expand Up @@ -3239,26 +3239,26 @@ def promotion_operator(self, i):
sage: t = Tableau([[1,2],[3]])
sage: t.promotion_operator(1)
[[[1, 2], [3], [4]], [[1, 2], [3, 4]], [[1, 2, 4], [3]]]
[[[1, 2, 4], [3]], [[1, 2], [3, 4]], [[1, 2], [3], [4]]]
sage: t.promotion_operator(2)
[[[1, 1], [2, 3], [4]],
[[1, 1, 2], [3], [4]],
[[[1, 1, 2, 4], [3]],
[[1, 1, 4], [2, 3]],
[[1, 1, 2, 4], [3]]]
[[1, 1, 2], [3], [4]],
[[1, 1], [2, 3], [4]]]
sage: Tableau([[1]]).promotion_operator(2)
[[[1, 1], [2]], [[1, 1, 2]]]
[[[1, 1, 2]], [[1, 1], [2]]]
sage: Tableau([[1,1],[2]]).promotion_operator(3)
[[[1, 1, 1], [2, 2], [3]],
[[1, 1, 1, 2], [2], [3]],
[[[1, 1, 1, 2, 3], [2]],
[[1, 1, 1, 3], [2, 2]],
[[1, 1, 1, 2, 3], [2]]]
[[1, 1, 1, 2], [2], [3]],
[[1, 1, 1], [2, 2], [3]]]
The example from [LLM2003]_ p. 12::
sage: Tableau([[1,1],[2,2]]).promotion_operator(3)
[[[1, 1, 1], [2, 2], [3, 3]],
[[[1, 1, 1, 3, 3], [2, 2]],
[[1, 1, 1, 3], [2, 2], [3]],
[[1, 1, 1, 3, 3], [2, 2]]]
[[1, 1, 1], [2, 2], [3, 3]]]
TESTS::
Expand Down

0 comments on commit 6ccd9e4

Please sign in to comment.