Skip to content

Commit 81b59fa

Browse files
committed
fix cardinality, #36119, #36118, #36116
1 parent 04232a4 commit 81b59fa

File tree

1 file changed

+67
-17
lines changed

1 file changed

+67
-17
lines changed

src/sage/combinat/plane_partition.py

Lines changed: 67 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class PlanePartition(ClonableArray,
7474
7575
sage: PP = PlanePartition([[4,3,3,1],[2,1,1],[1,1]])
7676
sage: TestSuite(PP).run()
77+
sage: hash(PP) # random
7778
"""
7879
@staticmethod
7980
def __classcall_private__(cls, PP, box_size=None):
@@ -118,13 +119,14 @@ def __init__(self, parent, pp, check=True):
118119
if isinstance(pp, PlanePartition):
119120
ClonableArray.__init__(self, parent, pp, check=False)
120121
else:
121-
pp = [list(_) for _ in pp]
122+
pp = [list(row) for row in pp]
122123
if pp:
123124
for i in reversed(range(len(pp))):
124125
while pp[i] and not pp[i][-1]:
125126
del pp[i][-1]
126127
if not pp[i]:
127128
pp.pop(i)
129+
pp = [tuple(row) for row in pp]
128130
ClonableArray.__init__(self, parent, pp, check=check)
129131
if self.parent()._box is None:
130132
if pp:
@@ -232,7 +234,7 @@ def _repr_(self) -> str:
232234
sage: PlanePartition([[4,3,3,1],[2,1,1],[1,1]])
233235
Plane partition [[4, 3, 3, 1], [2, 1, 1], [1, 1]]
234236
"""
235-
return "Plane partition {}".format(list(self))
237+
return "Plane partition {}".format([list(row) for row in self])
236238

237239
def to_tableau(self) -> Tableau:
238240
r"""
@@ -1089,7 +1091,7 @@ def maximal_boxes(self) -> list:
10891091
for j, entry in enumerate(row):
10901092
if (i == len(self)-1 or len(self[i+1])-1 < j or self[i+1][j] < entry) and (j == len(row)-1 or row[j+1] < entry):
10911093
generate.append([i, j, entry-1])
1092-
return(generate)
1094+
return generate
10931095

10941096
def cyclically_rotate(self, preserve_parent=False) -> PP:
10951097
r"""
@@ -1300,6 +1302,10 @@ def __classcall_private__(cls, *args, **kwds):
13001302
Plane partitions of size 3
13011303
sage: PlanePartitions([4,4,4], symmetry='TSSCPP')
13021304
Totally symmetric self-complementary plane partitions inside a 4 x 4 x 4 box
1305+
sage: PlanePartitions(4, symmetry='TSSCPP')
1306+
Traceback (most recent call last):
1307+
...
1308+
ValueError: the number of boxes may only be specified if no symmetry is required
13031309
"""
13041310
symmetry = kwds.get('symmetry', None)
13051311
box_size = kwds.get('box_size', None)
@@ -1310,8 +1316,10 @@ def __classcall_private__(cls, *args, **kwds):
13101316
if args and box_size is None:
13111317
# The first arg could be either a size or a box size
13121318
if isinstance(args[0], (int, Integer)):
1313-
return PlanePartitions_n(args[0])
1314-
1319+
if symmetry is None:
1320+
return PlanePartitions_n(args[0])
1321+
else:
1322+
raise ValueError("the number of boxes may only be specified if no symmetry is required")
13151323
box_size = args[0]
13161324

13171325
box_size = tuple(box_size)
@@ -1445,8 +1453,10 @@ def __init__(self):
14451453
# super(PlanePartitions_all, self).__init__(category=InfiniteEnumeratedSets())
14461454

14471455
DisjointUnionEnumeratedSets.__init__(self,
1448-
Family(NonNegativeIntegers(), PlanePartitions_n),
1449-
facade=True, keepkey=False)
1456+
Family(NonNegativeIntegers(),
1457+
PlanePartitions_n),
1458+
facade=True,
1459+
keepkey=False)
14501460

14511461
def _repr_(self) -> str:
14521462
"""
@@ -1632,11 +1642,16 @@ def cardinality(self) -> Integer:
16321642
A = self._box[0]
16331643
B = self._box[1]
16341644
C = self._box[2]
1635-
return Integer(prod(Integer(i + j + k - 1) / Integer(i + j + k - 2)
1645+
return Integer(prod(i + j + k - 1
1646+
for i in range(1, A + 1)
1647+
for j in range(1, B + 1)
1648+
for k in range(1, C + 1)) //
1649+
prod(i + j + k - 2
16361650
for i in range(1, A + 1)
16371651
for j in range(1, B + 1)
16381652
for k in range(1, C + 1)))
16391653

1654+
16401655
def random_element(self) -> PP:
16411656
r"""
16421657
Return a uniformly random plane partition inside a box.
@@ -1708,6 +1723,11 @@ def __iter__(self) -> Iterator:
17081723
17091724
sage: list(PlanePartitions(2))
17101725
[Plane partition [[2]], Plane partition [[1, 1]], Plane partition [[1], [1]]]
1726+
1727+
TESTS::
1728+
1729+
sage: all(len(set(PP)) == PP.cardinality() for n in range(1, 10) if (PP := PlanePartitions(n)))
1730+
True
17111731
"""
17121732
from sage.combinat.partition import Partitions
17131733

@@ -1922,6 +1942,11 @@ def __iter__(self) -> Iterator:
19221942
Plane partition [[1, 1], [1, 1]],
19231943
Plane partition [[1, 1], [1]],
19241944
Plane partition [[1]]]
1945+
1946+
TESTS::
1947+
1948+
sage: all(len(set(PP)) == PP.cardinality() for n in range(1, 5) if (PP := PlanePartitions([n]*3, symmetry='SPP')))
1949+
True
19251950
"""
19261951
for acl in self.to_poset().antichains_iterator():
19271952
yield self.from_antichain(acl)
@@ -1946,11 +1971,15 @@ def cardinality(self) -> Integer:
19461971
"""
19471972
a = self._box[0]
19481973
c = self._box[2]
1949-
left_prod = prod((2*i + c - 1) / (2*i - 1) for i in range(1, a+1))
1950-
right_prod = prod((i + j + c - 1) / (i + j - 1)
1951-
for j in range(1, a+1)
1952-
for i in range(1, j))
1953-
return Integer(left_prod * right_prod)
1974+
left_prod_num = prod(2*i + c - 1 for i in range(1, a+1))
1975+
left_prod_den = prod(2*i - 1 for i in range(1, a+1))
1976+
right_prod_num = prod(i + j + c - 1
1977+
for j in range(1, a+1)
1978+
for i in range(1, j))
1979+
right_prod_den = prod(i + j - 1
1980+
for j in range(1, a+1)
1981+
for i in range(1, j))
1982+
return Integer(left_prod_num * right_prod_num // left_prod_den // right_prod_den)
19541983

19551984
def random_element(self) -> PP:
19561985
r"""
@@ -2143,6 +2172,11 @@ def __iter__(self) -> Iterator:
21432172
Plane partition [[2, 2], [2, 1]],
21442173
Plane partition [[2, 1], [1]],
21452174
Plane partition [[1]]]
2175+
2176+
TESTS::
2177+
2178+
sage: all(len(set(PP)) == PP.cardinality() for n in range(1, 5) if (PP := PlanePartitions([n]*3, symmetry='CSPP')))
2179+
True
21462180
"""
21472181
for acl in self.to_poset().antichains_iterator():
21482182
yield self.from_antichain(acl)
@@ -2321,6 +2355,11 @@ def __iter__(self) -> Iterator:
23212355
Plane partition [[2, 2], [2, 1]],
23222356
Plane partition [[2, 1], [1]],
23232357
Plane partition [[1]]]
2358+
2359+
TESTS::
2360+
2361+
sage: all(len(set(PP)) == PP.cardinality() for n in range(1, 5) if (PP := PlanePartitions([n]*3, symmetry='TSPP')))
2362+
True
23242363
"""
23252364
for A in self.to_poset().antichains_iterator():
23262365
yield self.from_antichain(A)
@@ -2343,8 +2382,8 @@ def cardinality(self) -> Integer:
23432382
66
23442383
"""
23452384
a = self._box[0]
2346-
return Integer(prod((i + j + a - 1) / (i + 2*j - 2)
2347-
for j in range(1, a+1) for i in range(1, j+1)))
2385+
return Integer(prod(i + j + a - 1 for j in range(1, a+1) for i in range(1, j+1))
2386+
// prod(i + 2*j - 2 for j in range(1, a+1) for i in range(1, j+1)))
23482387

23492388

23502389
# Class 5
@@ -2412,6 +2451,12 @@ def __iter__(self) -> Iterator:
24122451
Plane partition [[2], [2], [2]],
24132452
Plane partition [[2, 1], [2], [1]],
24142453
Plane partition [[2, 2], [2]]]
2454+
2455+
TESTS::
2456+
2457+
sage: PP = PlanePartitions([3,4,5], symmetry='SCPP')
2458+
sage: len(set(PP)) == PP.cardinality()
2459+
True
24152460
"""
24162461
b = self._box[0]
24172462
a = self._box[1]
@@ -3037,9 +3082,9 @@ def from_antichain(self, acl) -> PP:
30373082
height = N - 1
30383083

30393084
# generate inner triangle
3040-
# FIXME: Make this ierator more efficient
3085+
# FIXME: Make this iterator more efficient
30413086
for i in range(width):
3042-
for j in range(min(height, i+1)):
3087+
for j in range(i, height):
30433088
for ac in acl:
30443089
if ac[0] == i and ac[1] == j:
30453090
zVal = ac[2]
@@ -3129,6 +3174,11 @@ def __iter__(self) -> Iterator:
31293174
sage: list(PlanePartitions([4,4,4], symmetry='TSSCPP'))
31303175
[Plane partition [[4, 4, 2, 2], [4, 4, 2, 2], [2, 2], [2, 2]],
31313176
Plane partition [[4, 4, 3, 2], [4, 3, 2, 1], [3, 2, 1], [2, 1]]]
3177+
3178+
TESTS::
3179+
3180+
sage: all(len(set(PP)) == PP.cardinality() for n in range(0,11,2) if (PP := PlanePartitions([n]*3, symmetry='TSSCPP')))
3181+
True
31323182
"""
31333183
for acl in self.to_poset().antichains_iterator():
31343184
yield self.from_antichain(acl)

0 commit comments

Comments
 (0)