@@ -74,6 +74,7 @@ class PlanePartition(ClonableArray,
74
74
75
75
sage: PP = PlanePartition([[4,3,3,1],[2,1,1],[1,1]])
76
76
sage: TestSuite(PP).run()
77
+ sage: hash(PP) # random
77
78
"""
78
79
@staticmethod
79
80
def __classcall_private__ (cls , PP , box_size = None ):
@@ -118,13 +119,14 @@ def __init__(self, parent, pp, check=True):
118
119
if isinstance (pp , PlanePartition ):
119
120
ClonableArray .__init__ (self , parent , pp , check = False )
120
121
else :
121
- pp = [list (_ ) for _ in pp ]
122
+ pp = [list (row ) for row in pp ]
122
123
if pp :
123
124
for i in reversed (range (len (pp ))):
124
125
while pp [i ] and not pp [i ][- 1 ]:
125
126
del pp [i ][- 1 ]
126
127
if not pp [i ]:
127
128
pp .pop (i )
129
+ pp = [tuple (row ) for row in pp ]
128
130
ClonableArray .__init__ (self , parent , pp , check = check )
129
131
if self .parent ()._box is None :
130
132
if pp :
@@ -232,7 +234,7 @@ def _repr_(self) -> str:
232
234
sage: PlanePartition([[4,3,3,1],[2,1,1],[1,1]])
233
235
Plane partition [[4, 3, 3, 1], [2, 1, 1], [1, 1]]
234
236
"""
235
- return "Plane partition {}" .format (list (self ) )
237
+ return "Plane partition {}" .format ([ list (row ) for row in self ] )
236
238
237
239
def to_tableau (self ) -> Tableau :
238
240
r"""
@@ -1089,7 +1091,7 @@ def maximal_boxes(self) -> list:
1089
1091
for j , entry in enumerate (row ):
1090
1092
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 ):
1091
1093
generate .append ([i , j , entry - 1 ])
1092
- return ( generate )
1094
+ return generate
1093
1095
1094
1096
def cyclically_rotate (self , preserve_parent = False ) -> PP :
1095
1097
r"""
@@ -1300,6 +1302,10 @@ def __classcall_private__(cls, *args, **kwds):
1300
1302
Plane partitions of size 3
1301
1303
sage: PlanePartitions([4,4,4], symmetry='TSSCPP')
1302
1304
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
1303
1309
"""
1304
1310
symmetry = kwds .get ('symmetry' , None )
1305
1311
box_size = kwds .get ('box_size' , None )
@@ -1310,8 +1316,10 @@ def __classcall_private__(cls, *args, **kwds):
1310
1316
if args and box_size is None :
1311
1317
# The first arg could be either a size or a box size
1312
1318
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" )
1315
1323
box_size = args [0 ]
1316
1324
1317
1325
box_size = tuple (box_size )
@@ -1445,8 +1453,10 @@ def __init__(self):
1445
1453
# super(PlanePartitions_all, self).__init__(category=InfiniteEnumeratedSets())
1446
1454
1447
1455
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 )
1450
1460
1451
1461
def _repr_ (self ) -> str :
1452
1462
"""
@@ -1632,11 +1642,16 @@ def cardinality(self) -> Integer:
1632
1642
A = self ._box [0 ]
1633
1643
B = self ._box [1 ]
1634
1644
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
1636
1650
for i in range (1 , A + 1 )
1637
1651
for j in range (1 , B + 1 )
1638
1652
for k in range (1 , C + 1 )))
1639
1653
1654
+
1640
1655
def random_element (self ) -> PP :
1641
1656
r"""
1642
1657
Return a uniformly random plane partition inside a box.
@@ -1708,6 +1723,11 @@ def __iter__(self) -> Iterator:
1708
1723
1709
1724
sage: list(PlanePartitions(2))
1710
1725
[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
1711
1731
"""
1712
1732
from sage .combinat .partition import Partitions
1713
1733
@@ -1922,6 +1942,11 @@ def __iter__(self) -> Iterator:
1922
1942
Plane partition [[1, 1], [1, 1]],
1923
1943
Plane partition [[1, 1], [1]],
1924
1944
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
1925
1950
"""
1926
1951
for acl in self .to_poset ().antichains_iterator ():
1927
1952
yield self .from_antichain (acl )
@@ -1946,11 +1971,15 @@ def cardinality(self) -> Integer:
1946
1971
"""
1947
1972
a = self ._box [0 ]
1948
1973
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 )
1954
1983
1955
1984
def random_element (self ) -> PP :
1956
1985
r"""
@@ -2143,6 +2172,11 @@ def __iter__(self) -> Iterator:
2143
2172
Plane partition [[2, 2], [2, 1]],
2144
2173
Plane partition [[2, 1], [1]],
2145
2174
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
2146
2180
"""
2147
2181
for acl in self .to_poset ().antichains_iterator ():
2148
2182
yield self .from_antichain (acl )
@@ -2321,6 +2355,11 @@ def __iter__(self) -> Iterator:
2321
2355
Plane partition [[2, 2], [2, 1]],
2322
2356
Plane partition [[2, 1], [1]],
2323
2357
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
2324
2363
"""
2325
2364
for A in self .to_poset ().antichains_iterator ():
2326
2365
yield self .from_antichain (A )
@@ -2343,8 +2382,8 @@ def cardinality(self) -> Integer:
2343
2382
66
2344
2383
"""
2345
2384
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 )))
2348
2387
2349
2388
2350
2389
# Class 5
@@ -2412,6 +2451,12 @@ def __iter__(self) -> Iterator:
2412
2451
Plane partition [[2], [2], [2]],
2413
2452
Plane partition [[2, 1], [2], [1]],
2414
2453
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
2415
2460
"""
2416
2461
b = self ._box [0 ]
2417
2462
a = self ._box [1 ]
@@ -3037,9 +3082,9 @@ def from_antichain(self, acl) -> PP:
3037
3082
height = N - 1
3038
3083
3039
3084
# generate inner triangle
3040
- # FIXME: Make this ierator more efficient
3085
+ # FIXME: Make this iterator more efficient
3041
3086
for i in range (width ):
3042
- for j in range (min ( height , i + 1 ) ):
3087
+ for j in range (i , height ):
3043
3088
for ac in acl :
3044
3089
if ac [0 ] == i and ac [1 ] == j :
3045
3090
zVal = ac [2 ]
@@ -3129,6 +3174,11 @@ def __iter__(self) -> Iterator:
3129
3174
sage: list(PlanePartitions([4,4,4], symmetry='TSSCPP'))
3130
3175
[Plane partition [[4, 4, 2, 2], [4, 4, 2, 2], [2, 2], [2, 2]],
3131
3176
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
3132
3182
"""
3133
3183
for acl in self .to_poset ().antichains_iterator ():
3134
3184
yield self .from_antichain (acl )
0 commit comments