# HG changeset patch
# User Franco Saliola <saliola@gmail.com>
# Date 1245612237 -7200
# Node ID eed995d18b83b53bb8a3910c65d00d41bf38ad0d
# Parent 3ead28f72457a47a670c07c207b330e1c72b2359
[mq]: trac_5790-review.patch
diff -r 3ead28f72457 -r eed995d18b83 sage/combinat/partition.py
|
a
|
b
|
|
| 284 | 284 | elif 'beta_numbers' in key_word and len(key_word)==1: |
| 285 | 285 | raise NotImplementedError |
| 286 | 286 | elif 'exp' in key_word and len(key_word)==1: |
| 287 | | return Partition_class([]).from_exp(key_word['exp']) |
| | 287 | return from_exp(key_word['exp']) |
| 288 | 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']) |
| | 289 | return from_core_and_quotient(key_word['core'], key_word['quotient']) |
| 290 | 290 | elif 'core' in key_word and 'canonical_quotient' in key_word and len(key_word)==2: |
| 291 | 291 | raise NotImplementedError |
| 292 | 292 | elif 'core_and_quotient' in key_word and len(key_word)==1: |
| 293 | 293 | from sage.misc.misc import deprecation |
| 294 | 294 | deprecation('"core_and_quotient=(*)" is deprecated. Use "core=[*], quotient=[*]" instead.') |
| 295 | | return Partition_class([]).from_core_and_quotient(*key_word['core_and_quotient']) |
| | 295 | return from_core_and_quotient(*key_word['core_and_quotient']) |
| 296 | 296 | else: |
| 297 | 297 | raise ValueError, 'incorrect syntax for Partition()' |
| 298 | 298 | |
| 299 | | def from_exp(a): |
| 300 | | """ |
| 301 | | ** This function is being deprecated - use Partition(exp=*) instead ** |
| | 299 | def from_exp(exp): |
| | 300 | """ |
| 302 | 301 | Returns a partition from its list of multiplicities. |
| | 302 | |
| | 303 | .. note:: |
| | 304 | |
| | 305 | This function is for internal use only; |
| | 306 | use Partition(exp=*) instead. |
| 303 | 307 | |
| 304 | 308 | EXAMPLES:: |
| 305 | 309 | |
| 306 | 310 | sage: Partition(exp=[1,2,1]) |
| 307 | 311 | [3, 2, 2, 1] |
| 308 | 312 | """ |
| 309 | | from sage.misc.misc import deprecation |
| 310 | | deprecation('"from_exp" is deprecated. Use "Partition(exp=[*])" instead.') |
| 311 | | return Partition(exp=a) |
| | 313 | p = [] |
| | 314 | for i in reversed(range(len(exp))): |
| | 315 | p += [i+1]*exp[i] |
| | 316 | return Partition(p) |
| 312 | 317 | |
| 313 | 318 | def from_core_and_quotient(core, quotient): |
| 314 | 319 | """ |
| … |
… |
|
| 318 | 323 | |
| 319 | 324 | Algorithm from mupad-combinat. |
| 320 | 325 | |
| | 326 | .. note:: |
| | 327 | |
| | 328 | This function is for internal use only; |
| | 329 | use Partition(core=*, quotient=*) instead. |
| | 330 | |
| 321 | 331 | EXAMPLES:: |
| 322 | 332 | |
| 323 | 333 | sage: Partition(core=[2,1], quotient=[[2,1],[3],[1,1,1]]) |
| 324 | 334 | [11, 5, 5, 3, 2, 2, 2] |
| 325 | 335 | """ |
| 326 | | from sage.misc.misc import deprecation |
| 327 | | deprecation('"from_core_and_quotient" is deprecated. Use "Partition(core=[*],quotient=[*])" instead.') |
| 328 | | return Partition(core=core,quotient=quotient) |
| 329 | | |
| | 336 | length = len(quotient) |
| | 337 | k = length*max( [ceil(len(core)/length),len(core)] + [len(q) for q in quotient] ) + length |
| | 338 | v = [ core[i]-(i+1)+1 for i in range(len(core))] + [ -i + 1 for i in range(len(core)+1,k+1) ] |
| | 339 | w = [ filter(lambda x: (x-i) % length == 0, v) for i in range(1, length+1) ] |
| | 340 | new_w = [] |
| | 341 | for i in range(length): |
| | 342 | new_w += [ w[i][j] + length*quotient[i][j] for j in range(len(quotient[i]))] |
| | 343 | new_w += [ w[i][j] for j in range(len(quotient[i]), len(w[i])) ] |
| | 344 | new_w.sort() |
| | 345 | new_w.reverse() |
| | 346 | return Partition([new_w[i-1]+i-1 for i in range(1, len(new_w)+1)]) |
| | 347 | |
| 330 | 348 | class Partition_class(CombinatorialObject): |
| 331 | | def from_exp(self,exp): |
| 332 | | """ |
| 333 | | Returns a partition from its list of multiplicities. |
| 334 | | |
| 335 | | EXAMPLES:: |
| 336 | | |
| 337 | | sage: Partition(exp=[1,2,1]) |
| 338 | | [3, 2, 2, 1] |
| 339 | | """ |
| 340 | | p = [] |
| 341 | | for i in reversed(range(len(exp))): |
| 342 | | p += [i+1]*exp[i] |
| 343 | | return Partition(p) |
| 344 | | |
| 345 | | def from_core_and_quotient(self, core, quotient): |
| 346 | | """ |
| 347 | | Returns a partition from its core and quotient. |
| 348 | | |
| 349 | | Algorithm from mupad-combinat. |
| 350 | | |
| 351 | | EXAMPLES:: |
| 352 | | |
| 353 | | sage: Partition(core=[2,1], quotient=[[2,1],[3],[1,1,1]]) |
| 354 | | [11, 5, 5, 3, 2, 2, 2] |
| 355 | | """ |
| 356 | | length = len(quotient) |
| 357 | | k = length*max( [ceil(len(core)/length),len(core)] + [len(q) for q in quotient] ) + length |
| 358 | | v = [ core[i]-(i+1)+1 for i in range(len(core))] + [ -i + 1 for i in range(len(core)+1,k+1) ] |
| 359 | | w = [ filter(lambda x: (x-i) % length == 0, v) for i in range(1, length+1) ] |
| 360 | | new_w = [] |
| 361 | | for i in range(length): |
| 362 | | new_w += [ w[i][j] + length*quotient[i][j] for j in range(len(quotient[i]))] |
| 363 | | new_w += [ w[i][j] for j in range(len(quotient[i]), len(w[i])) ] |
| 364 | | new_w.sort() |
| 365 | | new_w.reverse() |
| 366 | | return Partition([new_w[i-1]+i-1 for i in range(1, len(new_w)+1)]) |
| 367 | | |
| 368 | | |
| 369 | 349 | def ferrers_diagram(self): |
| 370 | 350 | """ |
| 371 | 351 | Return the Ferrers diagram of pi. |