Ticket #5790: partition-update-AM.patch
| File partition-update-AM.patch, 21.5 KB (added by andrew.mathas, 11 months ago) |
|---|
-
sage/combinat/ktableau.py
diff -r 5d1094576a01 sage/combinat/ktableau.py
a b 24 24 25 25 def KCore(part, k): 26 26 part = Partition(part) 27 if part != part. k_core(k):27 if part != part.core(k): 28 28 raise ValueError, "%s is not a %s-core"%(part, k) 29 29 return KCore_class(part._list, k) 30 30 … … 60 60 61 61 def KCores(n, k): 62 62 from sage.combinat.all import Partitions 63 k_cores = Partitions(n).filter(lambda x: x == x. r_core(k))63 k_cores = Partitions(n).filter(lambda x: x == x.core(k)) 64 64 k_cores = k_cores.map(lambda x: KCore(x, k)) 65 65 k_cores._name = "%s-Cores of size %s"%(k,n) 66 66 return k_cores -
sage/combinat/partition.py
diff -r 5d1094576a01 sage/combinat/partition.py
a b 186 186 sage: Partition([4,3,1]).corners() 187 187 [[0, 3], [1, 2], [2, 0]] 188 188 189 We can compute the r-core and r-quotient of a partition and build189 We can compute the core and quotient of a partition and build 190 190 the partition back up from them. 191 191 192 192 :: 193 193 194 sage: Partition([6,3,2,2]). r_core(3)194 sage: Partition([6,3,2,2]).core(3) 195 195 [2, 1, 1] 196 sage: Partition([7,7,5,3,3,3,1]). r_quotient(3)196 sage: Partition([7,7,5,3,3,3,1]).quotient(3) 197 197 [[2], [1], [2, 2, 2]] 198 198 sage: p = Partition([11,5,5,3,2,2,2]) 199 sage: p. r_core(3)199 sage: p.core(3) 200 200 [] 201 sage: p. r_quotient(3)201 sage: p.quotient(3) 202 202 [[2, 1], [4], [1, 1, 1]] 203 sage: Partition(core _and_quotient=([],[[2, 1], [4], [1, 1, 1]]))203 sage: Partition(core=[],quotient=[[2, 1], [4], [1, 1, 1]]) 204 204 [11, 5, 5, 3, 2, 2, 2] 205 205 """ 206 206 #***************************************************************************** … … 239 239 from integer_list import IntegerListsLex 240 240 from sage.combinat.root_system.weyl_group import WeylGroup 241 241 242 def Partition(l=None, exp=None, core_and_quotient=None): 243 """ 244 Returns a partition object. 245 246 Note that Sage uses the English convention for partitions and 247 tableaux. 248 249 EXAMPLES:: 250 242 def Partition(mu=None, **key_word): 243 """ 244 A partition is a weakly decreasing ordered sequence of non-negative 245 integers. This function returns a Sage partition object which can 246 be specified in one of the following ways:: 247 * a list (the default) 248 * using exponential notation 249 * by beta numbers (TODO) 250 * specifying the core and the quotient 251 * specifying the core and the canonical quotient (TODO) 252 See the examples below. 253 254 Sage follows the usual python conventions when dealing with partitions, 255 so that the first part of the partition ``mu=Partition([4,3,2,2])`` is 256 ``mu[0]``, the second part is ``mu[1]`` and so on. As is usual, Sage ignores 257 trailing zeros at the end of partitions. 258 259 EXAMPLES:: 260 261 sage: Partition([3,2,1]) 262 [3, 2, 1] 263 sage: Partition([3,2,1,0]) 264 [3, 2, 1] 251 265 sage: Partition(exp=[2,1,1]) 252 266 [3, 2, 1, 1] 253 sage: Partition(core _and_quotient=([2,1], [[2,1],[3],[1,1,1]]))267 sage: Partition(core=[2,1], quotient=[[2,1],[3],[1,1,1]]) 254 268 [11, 5, 5, 3, 2, 2, 2] 255 sage: Partition([3,2,1])256 [3, 2, 1]257 269 sage: [2,1] in Partitions() 258 270 True 259 271 sage: [2,1,0] in Partitions() 260 272 False 261 sage: Partition([2,1,0])262 [2, 1]263 273 sage: Partition([1,2,3]) 264 274 Traceback (most recent call last): 265 275 ... 266 276 ValueError: [1, 2, 3] is not a valid partition 267 277 """ 268 number_of_arguments = 0 269 for arg in ['l', 'exp', 'core_and_quotient']: 270 if locals()[arg] is not None: 271 number_of_arguments += 1 272 273 if number_of_arguments != 1: 274 raise ValueError, "you must specify exactly one argument" 275 276 if l is not None: 277 l = [i for i in l if i != 0] 278 if l in Partitions_all(): 279 return Partition_class(l) 280 else: 281 raise ValueError, "%s is not a valid partition"%l 282 elif exp is not None: 283 return from_exp(exp) 284 else: 285 return from_core_and_quotient(*core_and_quotient) 286 287 278 if mu is not None and len(key_word)==0: 279 mu = [i for i in mu if i != 0] 280 if mu in Partitions_all(): 281 return Partition_class(mu) 282 else: 283 raise ValueError, "%s is not a valid partition"%mu 284 elif 'beta_numbers' in key_word and len(key_word)==1: 285 raise NotImplementedError 286 elif 'exp' in key_word and len(key_word)==1: 287 return Partition_class([]).from_exp(key_word['exp']) 288 elif 'core' in key_word and 'quotient' in key_word and len(key_word)==2: 289 return Partition_class([]).from_core_and_quotient(key_word['core'], key_word['quotient']) 290 elif 'core' in key_word and 'canonical_quotient' in key_word and len(key_word)==2: 291 raise NotImplementedError 292 elif 'core_and_quotient' in key_word and len(key_word)==1: 293 from sage.misc.misc import deprecation 294 deprecation('"core_and_quotient=(*)" is deprecated. Use "core=[*], quotient=[*]" instead.') 295 return Partition_class([]).from_core_and_quotient(*key_word['core_and_quotient']) 296 else: 297 raise ValueError, 'incorrect syntax for Partition()' 298 288 299 def from_exp(a): 289 300 """ 301 ** This function is being deprecated - use Partition(exp=*) instead ** 302 290 303 Returns a partition from its list of multiplicities. 291 304 292 305 EXAMPLES:: 293 306 294 sage: partition.from_exp([1,2,1])307 sage: Partition(exp=[1,2,1]) 295 308 [3, 2, 2, 1] 296 309 """ 297 298 p = [] 299 for i in reversed(range(len(a))): 300 p += [i+1]*a[i] 301 302 return Partition(p) 310 from sage.misc.misc import deprecation 311 deprecation('"from_exp" is deprecated. Use "Partition(exp=[*])" instead.') 312 return Partition(exp=a) 303 313 304 314 305 315 def from_core_and_quotient(core, quotient): 306 316 """ 307 Returns a partition from its r-core and r-quotient. 317 ** This function is being deprecated - use Partition(core=*, quotient=*) instead ** 318 319 Returns a partition from its core and quotient. 308 320 309 321 Algorithm from mupad-combinat. 310 322 311 323 EXAMPLES:: 312 324 313 sage: partition.from_core_and_quotient([2,1],[[2,1],[3],[1,1,1]])325 sage: Partition(core=[2,1], quotient=[[2,1],[3],[1,1,1]]) 314 326 [11, 5, 5, 3, 2, 2, 2] 315 327 """ 316 length = len(quotient) 317 k = length*max( [ceil(len(core)/length),len(core)] + [len(q) for q in quotient] ) + length 318 v = [ core[i]-(i+1)+1 for i in range(len(core))] + [ -i + 1 for i in range(len(core)+1,k+1) ] 319 w = [ filter(lambda x: (x-i) % length == 0, v) for i in range(1, length+1) ] 320 new_w = [] 321 for i in range(length): 322 new_w += [ w[i][j] + length*quotient[i][j] for j in range(len(quotient[i]))] 323 new_w += [ w[i][j] for j in range(len(quotient[i]), len(w[i])) ] 324 new_w.sort() 325 new_w.reverse() 326 return filter(lambda x: x != 0, [new_w[i-1]+i-1 for i in range(1, len(new_w)+1)]) 327 328 from sage.misc.misc import deprecation 329 deprecation('"from_core_and_quotient" is deprecated. Use "Partition(core=[*],quotient=[*])" instead.') 330 return Partition(core=core,quotient=quotient) 328 331 329 332 class Partition_class(CombinatorialObject): 333 def from_exp(self,exp): 334 """ 335 Returns a partition from its list of multiplicities. 336 337 EXAMPLES:: 338 339 sage: Partition(exp=[1,2,1]) 340 [3, 2, 2, 1] 341 """ 342 p = [] 343 for i in reversed(range(len(exp))): 344 p += [i+1]*exp[i] 345 return Partition(p) 346 347 def from_core_and_quotient(self, core, quotient): 348 """ 349 Returns a partition from its core and quotient. 350 351 Algorithm from mupad-combinat. 352 353 EXAMPLES:: 354 355 sage: Partition(core=[2,1], quotient=[[2,1],[3],[1,1,1]]) 356 [11, 5, 5, 3, 2, 2, 2] 357 """ 358 length = len(quotient) 359 k = length*max( [ceil(len(core)/length),len(core)] + [len(q) for q in quotient] ) + length 360 v = [ core[i]-(i+1)+1 for i in range(len(core))] + [ -i + 1 for i in range(len(core)+1,k+1) ] 361 w = [ filter(lambda x: (x-i) % length == 0, v) for i in range(1, length+1) ] 362 new_w = [] 363 for i in range(length): 364 new_w += [ w[i][j] + length*quotient[i][j] for j in range(len(quotient[i]))] 365 new_w += [ w[i][j] for j in range(len(quotient[i]), len(w[i])) ] 366 new_w.sort() 367 new_w.reverse() 368 return Partition([new_w[i-1]+i-1 for i in range(1, len(new_w)+1)]) 369 330 370 def ferrers_diagram(self): 331 371 """ 332 372 Return the Ferrers diagram of pi. … … 344 384 ***** 345 385 ** 346 386 * 347 sage: pi = Partitions(10).list()[11] ## [6,1,1,1,1]348 sage: print pi.ferrers_diagram()349 ******350 *351 *352 *353 *354 sage: pi = Partitions(10).list()[8] ## [6, 3, 1]355 sage: print pi.ferrers_diagram()356 ******357 ***358 *359 387 """ 360 388 return '\n'.join(['*'*p for p in self]) 361 389 … … 507 535 508 536 def sign(self): 509 537 r""" 510 partition_sign( pi ) returns the sign of a permutation with cycle 511 structure given by the partition pi. 538 Returns the sign of a permutation with cycle type of the partition. 512 539 513 540 This function corresponds to a homomorphism from the symmetric 514 541 group `S_n` into the cyclic group of order 2, whose kernel … … 516 543 `1` are called even partitions while partitions of sign 517 544 `-1` are called odd. 518 545 519 Wraps GAP's SignPartition.520 521 546 EXAMPLES:: 522 547 523 548 sage: Partition([5,3]).sign() … … 577 602 578 603 - http://en.wikipedia.org/wiki/Zolotarev's_lemma 579 604 """ 580 ans=gap.eval("SignPartition(%s)"%(self)) 581 return sage_eval(ans) 605 return (-1)**(self.size()-self.length()) 582 606 583 607 def up(self): 584 608 r""" … … 791 815 sage: Partition([5,4,2,1,1,1]).associated().associated() 792 816 [5, 4, 2, 1, 1, 1] 793 817 """ 794 795 818 return self.conjugate() 796 819 797 820 def arm(self, i, j): … … 1461 1484 return kshape.KShape(self, k) 1462 1485 1463 1486 def r_core(self, length): 1464 """ 1465 Returns the r-core of the partition p. The construction of the 1466 r-core can be visualized by repeatedly removing border strips of 1467 size r from p until this is no longer possible. The remaining 1468 partition is the r-core. 1469 1470 EXAMPLES:: 1471 1472 sage: Partition([6,3,2,2]).r_core(3) 1487 """ *** deprecate *** """ 1488 from sage.misc.misc import deprecation 1489 deprecation('r_core is deprecated. Use core instead.') 1490 return self.core(self, length) 1491 1492 k_core = r_core 1493 1494 def core(self, length): 1495 """ 1496 Returns the core of the partition -- in the literature the core is 1497 commonly referred to as the k-core, p-core, r-core, ... . The 1498 construction of the core can be visualized by repeatedly removing 1499 border strips of size r from p until this is no longer possible. 1500 The remaining partition is the core. 1501 1502 EXAMPLES:: 1503 1504 sage: Partition([6,3,2,2]).core(3) 1473 1505 [2, 1, 1] 1474 sage: Partition([]). r_core(3)1475 [] 1476 sage: Partition([8,7,7,4,1,1,1,1,1]). r_core(3)1506 sage: Partition([]).core(3) 1507 [] 1508 sage: Partition([8,7,7,4,1,1,1,1,1]).core(3) 1477 1509 [2, 1, 1] 1478 1510 1479 1511 TESTS:: 1480 1512 1481 sage: Partition([3,3,3,2,1]). r_core(3)1482 [] 1483 sage: Partition([10,8,7,7]). r_core(4)1484 [] 1485 sage: Partition([21,15,15,9,6,6,6,3,3]). r_core(3)1513 sage: Partition([3,3,3,2,1]).core(3) 1514 [] 1515 sage: Partition([10,8,7,7]).core(4) 1516 [] 1517 sage: Partition([21,15,15,9,6,6,6,3,3]).core(3) 1486 1518 [] 1487 1519 """ 1488 1520 p = self … … 1504 1536 1505 1537 #Remove the canonical vector 1506 1538 part = [part[i-1]-len(part)+i for i in range(1, len(part)+1)] 1507 #Select the r-core 1508 return filter(lambda x: x != 0, part) 1509 1510 k_core = r_core 1539 return Partition(part) 1511 1540 1512 1541 def r_quotient(self, length): 1513 """ 1514 Returns the r-quotient of the partition p. The r-quotient is a list 1515 of r partitions, constructed in the following way. Label each cell 1516 in p with its content, modulo r. Let R_i be the set of rows ending 1517 in a box labelled i, and C_i be the set of columns ending in a box 1518 labelled i. Then the jth component of the r-quotient of p is the 1519 partition defined by intersecting R_j with C_j+1. 1520 1521 EXAMPLES:: 1522 1523 sage: Partition([7,7,5,3,3,3,1]).r_quotient(3) 1542 """ *** deprecate *** """ 1543 from sage.misc.misc import deprecation 1544 deprecation('r_quotient is deprecated. Use quotient instead.') 1545 return self.quotient(self,length) 1546 1547 k_quotient = r_quotient 1548 1549 def quotient(self, length): 1550 """ 1551 Returns the quotient of the partition -- in the literature the 1552 core is commonly referred to as the k-core, p-core, r-core, ... . The 1553 quotient is a list of r partitions, constructed in the following 1554 way. Label each cell in p with its content, modulo r. Let R_i be 1555 the set of rows ending in a box labelled i, and C_i be the set of 1556 columns ending in a box labelled i. Then the jth component of the 1557 quotient of p is the partition defined by intersecting R_j with 1558 C_j+1. 1559 1560 EXAMPLES:: 1561 1562 sage: Partition([7,7,5,3,3,3,1]).quotient(3) 1524 1563 [[2], [1], [2, 2, 2]] 1525 1564 1526 1565 TESTS:: 1527 1566 1528 sage: Partition([8,7,7,4,1,1,1,1,1]). r_quotient(3)1567 sage: Partition([8,7,7,4,1,1,1,1,1]).quotient(3) 1529 1568 [[2, 1], [2, 2], [2]] 1530 sage: Partition([10,8,7,7]). r_quotient(4)1569 sage: Partition([10,8,7,7]).quotient(4) 1531 1570 [[2], [3], [2], [1]] 1532 sage: Partition([6,3,3]). r_quotient(3)1571 sage: Partition([6,3,3]).quotient(3) 1533 1572 [[1], [1], [2]] 1534 sage: Partition([3,3,3,2,1]). r_quotient(3)1573 sage: Partition([3,3,3,2,1]).quotient(3) 1535 1574 [[1], [1, 1], [1]] 1536 sage: Partition([6,6,6,3,3,3]). r_quotient(3)1575 sage: Partition([6,6,6,3,3,3]).quotient(3) 1537 1576 [[2, 1], [2, 1], [2, 1]] 1538 sage: Partition([21,15,15,9,6,6,6,3,3]). r_quotient(3)1577 sage: Partition([21,15,15,9,6,6,6,3,3]).quotient(3) 1539 1578 [[5, 2, 1], [5, 2, 1], [7, 3, 2]] 1540 sage: Partition([21,15,15,9,6,6,3,3]). r_quotient(3)1579 sage: Partition([21,15,15,9,6,6,3,3]).quotient(3) 1541 1580 [[5, 2], [5, 2, 1], [7, 3, 1]] 1542 sage: Partition([14,12,11,10,10,10,10,9,6,4,3,3,2,1]). r_quotient(5)1581 sage: Partition([14,12,11,10,10,10,10,9,6,4,3,3,2,1]).quotient(5) 1543 1582 [[3, 3], [2, 2, 1], [], [3, 3, 3], [1]] 1544 1583 """ 1545 1584 p = self … … 1567 1606 1568 1607 return result 1569 1608 1570 k_quotient = r_quotient1571 1572 1609 def add_box(self, i, j = None): 1573 1610 r""" 1574 1611 Returns a partition corresponding to self with a box added in row … … 4073 4110 4074 4111 EXAMPLES:: 4075 4112 4076 sage: print ferrers_diagram([5,5,2,1])4113 sage: print Partition([5,5,2,1]).ferrers_diagram() 4077 4114 ***** 4078 4115 ***** 4079 4116 ** 4080 4117 * 4081 sage: pi = partitions_list(10)[30] ## [6,1,1,1,1] 4082 sage: print ferrers_diagram(pi) 4083 ****** 4084 * 4085 * 4086 * 4087 * 4088 sage: pi = partitions_list(10)[33] ## [6, 3, 1] 4089 sage: print ferrers_diagram(pi) 4090 ****** 4091 *** 4092 * 4093 """ 4094 return '\n'.join(['*'*p for p in pi]) 4118 """ 4119 from sage.misc.misc import deprecation 4120 deprecation('"ferrers_diagram deprecated. Use Partition(pi).ferrers_diagram() instead') 4121 return Partition(pi).ferrers_diagram() 4095 4122 4096 4123 4097 4124 def ordered_partitions(n,k=None): … … 4366 4393 4367 4394 def partition_sign(pi): 4368 4395 r""" 4369 partition_sign( pi ) returns the sign of a permutation with cycle 4396 ** This function is being deprecated -- use Partition(*).sign() instead. ** 4397 4398 Partition( pi ).sign() returns the sign of a permutation with cycle 4370 4399 structure given by the partition pi. 4371 4400 4372 4401 This function corresponds to a homomorphism from the symmetric … … 4374 4403 is exactly the alternating group `A_n`. Partitions of sign 4375 4404 `1` are called even partitions while partitions of sign 4376 4405 `-1` are called odd. 4377 4378 Wraps GAP's SignPartition.4379 4380 EXAMPLES:: 4381 4382 sage: partition_sign([5,3])4406 4407 This function is deprecated: use Partition( pi ).sign() instead. 4408 4409 EXAMPLES:: 4410 4411 sage: Partition([5,3]).sign() 4383 4412 1 4384 sage: partition_sign([5,2])4413 sage: Partition([5,2]).sign() 4385 4414 -1 4386 4415 4387 4416 Zolotarev's lemma states that the Legendre symbol … … 4411 4440 sage: p = PermutationGroupElement('(1, 2, 4, 8, 5, 10, 9, 7, 3, 6)') 4412 4441 sage: p.sign() 4413 4442 -1 4414 sage: partition_sign([10])4443 sage: Partition([10]).sign() 4415 4444 -1 4416 4445 sage: kronecker_symbol(11,2) 4417 4446 -1 … … 4427 4456 1 4428 4457 sage: kronecker_symbol(3,11) 4429 4458 1 4430 sage: partition_sign([5,1,1,1,1,1])4459 sage: Partition([5,1,1,1,1,1]).sign() 4431 4460 1 4432 4461 4433 4462 In both cases, Zolotarev holds. … … 4436 4465 4437 4466 - http://en.wikipedia.org/wiki/Zolotarev's_lemma 4438 4467 """ 4439 ans=gap.eval("SignPartition(%s)"%(pi)) 4440 return sage_eval(ans) 4468 from sage.misc.misc import deprecation 4469 deprecation('"partition_sign deprecated. Use Partition(pi).sign() instead') 4470 return Partition(pi).sign() 4441 4471 4442 4472 def partition_associated(pi): 4443 4473 """ 4474 ** This function is being deprecated -- use Partition(*).conjugate() instead. ** 4475 4444 4476 partition_associated( pi ) returns the "associated" (also called 4445 4477 "conjugate" in the literature) partition of the partition pi which 4446 4478 is obtained by transposing the corresponding Ferrers diagram. 4447 4479 4448 4480 EXAMPLES:: 4449 4481 4450 sage: partition_associated([2,2])4482 sage: Partition([2,2]).conjugate() 4451 4483 [2, 2] 4452 sage: partition_associated([6,3,1])4484 sage: Partition([6,3,1]).conjugate() 4453 4485 [3, 2, 2, 1, 1, 1] 4454 sage: print ferrers_diagram([6,3,1])4486 sage: print Partition([6,3,1]).ferrers_diagram() 4455 4487 ****** 4456 4488 *** 4457 4489 * 4458 sage: print ferrers_diagram([3,2,2,1,1,1])4490 sage: print Partition([6,3,1]).conjugate().ferrers_diagram() 4459 4491 *** 4460 4492 ** 4461 4493 ** … … 4463 4495 * 4464 4496 * 4465 4497 """ 4466 return list(Partition(pi).conjugate()) 4467 4498 from sage.misc.misc import deprecation 4499 deprecation('"partition_associated deprecated. Use Partition(pi).conjugte() instead') 4500 return Partition(pi).conjugate() 4501 -
sage/combinat/ribbon_tableau.py
diff -r 5d1094576a01 sage/combinat/ribbon_tableau.py
a b 143 143 """ 144 144 if shape in partition.Partitions(): 145 145 shape = partition.Partition(shape) 146 shape = skew_partition.SkewPartition([shape, shape. r_core(length)])146 shape = skew_partition.SkewPartition([shape, shape.core(length)]) 147 147 else: 148 148 shape = skew_partition.SkewPartition(shape) 149 149 … … 880 880 sage: a = SkewPartition([[8,7,6,5,1,1],[2,1,1]]) 881 881 sage: weight = [3,3,2] 882 882 sage: k = 3 883 sage: s = SemistandardMultiSkewTableaux(a. r_quotient(k),weight)883 sage: s = SemistandardMultiSkewTableaux(a.quotient(k),weight) 884 884 sage: len(s.list()) 885 885 34 886 886 sage: RibbonTableaux(a,weight,k).cardinality() -
sage/combinat/skew_partition.py
diff -r 5d1094576a01 sage/combinat/skew_partition.py
a b 451 451 return G 452 452 453 453 454 def r_quotient(self, k): 454 def r_quotient(self, length): 455 """ *** deprecate *** """ 456 from sage.misc.misc import deprecation 457 deprecation('r_quotient is deprecated. Use quotient instead.') 458 return self.quotient(self,length) 459 460 def quotient(self, k): 455 461 """ 456 462 The quotient map extended to skew partitions. 457 463 458 464 EXAMPLES:: 459 465 460 sage: SkewPartition([[3, 3, 2, 1], [2, 1]]). r_quotient(2)466 sage: SkewPartition([[3, 3, 2, 1], [2, 1]]).quotient(2) 461 467 [[[3], []], [[], []]] 462 468 """ 463 469 ## k-th element is the skew partition built using the k-th partition of the 464 470 ## k-quotient of the outer and the inner partition. 465 471 ## This bijection is only defined if the inner and the outer partition 466 472 ## have the same core 467 if self.inner(). r_core(k) == self.outer().r_core(k):468 rqinner = self.inner(). r_quotient(k)469 rqouter = self.outer(). r_quotient(k)473 if self.inner().core(k) == self.outer().core(k): 474 rqinner = self.inner().quotient(k) 475 rqouter = self.outer().quotient(k) 470 476 return [ SkewPartition_class([rqouter[i],rqinner[i]]) for i in range(k) ] 471 477 else: 472 478 raise ValueError, "quotient map is only defined for skew partitions with inner and outer partitions having the same core"
