Skip to content

Convert partitions into skew partitions automatically #40580

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

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
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
61 changes: 55 additions & 6 deletions src/sage/combinat/skew_partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@
sage: SkewPartition([[4,3,1],[2]]).outer_corners()
[(0, 3), (1, 2), (2, 0)]

Any partition `p` can be viewed as a skew partition
`p / ()`. This is implemented as a default conversion::

sage: SkewPartition([2,2,1])
[2, 2, 1] / []
sage: SkewPartition(Partition([2]))
[2] / []

AUTHORS:

- Mike Hansen: Initial version
Expand Down Expand Up @@ -154,7 +162,7 @@
from sage.misc.lazy_import import lazy_import

from sage.combinat.combinat import CombinatorialElement
from sage.combinat.partition import Partitions, _Partitions
from sage.combinat.partition import Partitions, _Partitions, Partition
from sage.combinat.tableau import Tableaux
from sage.combinat.composition import Compositions

Expand Down Expand Up @@ -183,18 +191,36 @@
[2, 1]
sage: skp.outer()
[3, 2, 1]

Partitions can be converted into skew partitions::

sage: skp = SkewPartition([3,3,2]); skp
[3, 3, 2] / []
sage: skp = SkewPartition(Partition([3,3,2])); skp
[3, 3, 2] / []
sage: skp = SkewPartition([]); skp
[] / []
"""
skp = [_Partitions(p) for p in skp]
if skp not in SkewPartitions():
try:
skp_list = [_Partitions(p) for p in skp]
except ValueError:
if skp in _Partitions:
return SkewPartitions()([_Partitions(skp), _Partitions([])])
raise ValueError("invalid skew partition: %s" % p)
if skp_list not in SkewPartitions():
if not skp_list:
return SkewPartitions()([_Partitions([]), _Partitions([])])
raise ValueError("invalid skew partition: %s" % skp)
return SkewPartitions()(skp)
return SkewPartitions()(skp_list)

def __init__(self, parent, skp):
"""
TESTS::

sage: skp = SkewPartition([[3,2,1],[2,1]])
sage: TestSuite(skp).run()
sage: skp = SkewPartition([3,2,1])
sage: TestSuite(skp).run()
"""
CombinatorialElement.__init__(self, parent,
[_Partitions(skp[0]), _Partitions(skp[1])])
Expand Down Expand Up @@ -1490,7 +1516,15 @@
sage: S = SkewPartitions()
sage: S([[3,1], [1]])
[3, 1] / [1]

TESTS::

sage: S = SkewPartitions()
sage: S(Partition([3,2]))
[3, 2] / []
"""
if skp in _Partitions:
skp = SkewPartition(skp)
Comment on lines +1526 to +1527
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if skp in _Partitions:
skp = SkewPartition(skp)
if skp in _Partitions:
skp = [_Partitions(skp), _Partitions([])]

Less indirection (so faster) and will result in the correct parent. Please add an analogous test with a different parent (such as SkewPartitions(4)) and make sure it has the correct output.

return self.element_class(self, skp)

def __contains__(self, x):
Expand Down Expand Up @@ -1535,9 +1569,13 @@
False
sage: [[1,1,1,0],[1,1,0,0]] in SkewPartitions()
True
sage: Partition([3,2]) in SkewPartitions()
True
"""
if isinstance(x, SkewPartition):
return True
if isinstance(x, Partition):
return True

try:
if len(x) != 2:
Expand Down Expand Up @@ -1798,9 +1836,15 @@
False
sage: [[7, 4, 3, 2], [5, 2, 1]] in SkewPartitions(8, overlap=-2)
True
sage: Partition([2, 1]) in SkewPartitions(3)
True
sage: Partition([2, 1]) in SkewPartitions(4)
False
"""
return x in SkewPartitions() \
and sum(x[0])-sum(x[1]) == self.n \
if not x in SkewPartitions():

Check failure on line 1844 in src/sage/combinat/skew_partition.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (E713)

src/sage/combinat/skew_partition.py:1844:16: E713 Test for membership should be `not in`
return False
x = SkewPartition(x)
return sum(x[0])-sum(x[1]) == self.n \
and self.overlap <= SkewPartition(x).overlap()
Comment on lines +1844 to 1848
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if not x in SkewPartitions():
return False
x = SkewPartition(x)
return sum(x[0])-sum(x[1]) == self.n \
and self.overlap <= SkewPartition(x).overlap()
SP = SkewPartitions()
if not x in SP:
return False
x = SP(x)
return (sum(x[0]) - sum(x[1]) == self.n
and self.overlap <= x.overlap())


def _repr_(self):
Expand Down Expand Up @@ -1972,8 +2016,13 @@
False
sage: [[5,4,3,1],[3,3,1]] in SkewPartitions(row_lengths=[2,1,2,1])
True
sage: Partition([2, 1]) in SkewPartitions(row_lengths=[2,1])
True
sage: Partition([2, 1]) in SkewPartitions(row_lengths=[2,2])
False
"""
if x in SkewPartitions():
x = SkewPartition(x)
Comment on lines 2024 to +2025
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if x in SkewPartitions():
x = SkewPartition(x)
SP = SkewPartitions()
if x in SP:
x = SP(x)

o = x[0]
i = x[1]+[0]*(len(x[0])-len(x[1]))
return [u[0]-u[1] for u in zip(o,i)] == self.co
Expand Down
Loading