# HG changeset patch
# User Mike Hansen <mhansen@gmail.com>
# Date 1207646570 25200
# Node ID 5ef43cd8ac7cf16cde4fca794c7b41124d8ce1b7
# Parent f924a49c5a06dade7892b922174644abc15d2bc0
The following patch was originally intended to correct a problem with
the weights for type A. The reason for the patch, and the plan of the
patch are described here.
http://groups.google.com/group/sage-combinat-devel/browse_thread/thread/7cdfe075257ba963?hl=en
As it turns out, the patch produces a substantial speedup for
computing the weights for crystals of moderate size. For example,
consider this crystal.
sage: C = CrystalOfTableaux(['A',4],shape=[4,2,2])
sage: C.count()
560
BEFORE THE PATCH:
sage: time [v.weight() for v in C]
CPU times: user 2.66 s, sys: 0.04 s, total: 2.69 s
Wall time: 2.71
AFTER THE PATCH:
sage: CPU times: user 0.79 s, sys: 0.00 s, total: 0.79 s
Wall time: 0.79
Similar speedups are found for the other Cartan types B,C,D and G2.
Note that the original weight code is still in place and will
be called for Crystals that are not Crystals of Tableaux or of
Letters.
diff -r f924a49c5a06 -r 5ef43cd8ac7c sage/combinat/crystals/letters.py
|
a
|
b
|
|
| 142 | 142 | """ |
| 143 | 143 | return self._digraph |
| 144 | 144 | |
| 145 | | |
| 146 | 145 | def __contains__(self, x): |
| 147 | 146 | """ |
| 148 | 147 | EXAMPLES: |
| … |
… |
|
| 287 | 286 | |
| 288 | 287 | sage: C.check() |
| 289 | 288 | True |
| | 289 | |
| 290 | 290 | """ |
| | 291 | |
| | 292 | def weight(self): |
| | 293 | """ |
| | 294 | Returns the weight of self. |
| | 295 | |
| | 296 | EXAMPLES: |
| | 297 | sage: [v.weight() for v in CrystalOfLetters(['A',3])] |
| | 298 | [(1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1)] |
| | 299 | """ |
| | 300 | return self._parent.weight_lattice_realization()._term(self.value-1) |
| | 301 | |
| 291 | 302 | def e(self, i): |
| 292 | 303 | r""" |
| 293 | 304 | Returns the action of $e_i$ on self. |
| … |
… |
|
| 331 | 342 | sage: C.check() |
| 332 | 343 | True |
| 333 | 344 | """ |
| | 345 | |
| | 346 | def weight(self): |
| | 347 | """ |
| | 348 | Returns the weight of self. |
| | 349 | |
| | 350 | EXAMPLES: |
| | 351 | sage: [v.weight() for v in CrystalOfLetters(['B',3])] |
| | 352 | [(1, 0, 0), |
| | 353 | (0, 1, 0), |
| | 354 | (0, 0, 1), |
| | 355 | (0, 0, 0), |
| | 356 | (0, 0, -1), |
| | 357 | (0, -1, 0), |
| | 358 | (-1, 0, 0)] |
| | 359 | """ |
| | 360 | if self.value > 0: |
| | 361 | return self._parent.weight_lattice_realization()._term(self.value-1) |
| | 362 | elif self.value < 0: |
| | 363 | return -self._parent.weight_lattice_realization()._term(-self.value-1) |
| | 364 | else: |
| | 365 | return self._parent.weight_lattice_realization()._free_module(0) |
| | 366 | |
| 334 | 367 | def e(self, i): |
| 335 | 368 | r""" |
| 336 | 369 | Returns the action of $e_i$ on self. |
| … |
… |
|
| 410 | 443 | [False, False, False, False, False, False]] |
| 411 | 444 | sage: C.check() |
| 412 | 445 | True |
| 413 | | |
| 414 | 446 | """ |
| | 447 | |
| | 448 | def weight(self): |
| | 449 | """ |
| | 450 | Returns the weight of self. |
| | 451 | |
| | 452 | EXAMPLES: |
| | 453 | sage: [v.weight() for v in CrystalOfLetters(['C',3])] |
| | 454 | [(1, 0, 0), (0, 1, 0), (0, 0, 1), (0, 0, -1), (0, -1, 0), (-1, 0, 0)] |
| | 455 | |
| | 456 | """ |
| | 457 | if self.value > 0: |
| | 458 | return self._parent.weight_lattice_realization()._term(self.value-1) |
| | 459 | elif self.value < 0: |
| | 460 | return -self._parent.weight_lattice_realization()._term(-self.value-1) |
| | 461 | else: |
| | 462 | return self._parent.weight_lattice_realization()._free_module(0) |
| | 463 | |
| 415 | 464 | def e(self, i): |
| 416 | 465 | r""" |
| 417 | 466 | Returns the action of $e_i$ on self. |
| … |
… |
|
| 472 | 521 | [1, 2, 3, 4, -4, -3, -2, -1] |
| 473 | 522 | sage: C.check() |
| 474 | 523 | True |
| | 524 | |
| 475 | 525 | """ |
| | 526 | |
| | 527 | def weight(self): |
| | 528 | """ |
| | 529 | Returns the weight of self. |
| | 530 | |
| | 531 | EXAMPLES: |
| | 532 | sage: [v.weight() for v in CrystalOfLetters(['D',4])] |
| | 533 | [(1, 0, 0, 0), |
| | 534 | (0, 1, 0, 0), |
| | 535 | (0, 0, 1, 0), |
| | 536 | (0, 0, 0, 1), |
| | 537 | (0, 0, 0, -1), |
| | 538 | (0, 0, -1, 0), |
| | 539 | (0, -1, 0, 0), |
| | 540 | (-1, 0, 0, 0)] |
| | 541 | """ |
| | 542 | if self.value > 0: |
| | 543 | return self._parent.weight_lattice_realization()._term(self.value-1) |
| | 544 | elif self.value < 0: |
| | 545 | return -self._parent.weight_lattice_realization()._term(-self.value-1) |
| | 546 | else: |
| | 547 | return self._parent.weight_lattice_realization()._free_module(0) |
| | 548 | |
| 476 | 549 | def e(self, i): |
| 477 | 550 | r""" |
| 478 | 551 | Returns the action of $e_i$ on self. |
| … |
… |
|
| 552 | 625 | sage: C.check() |
| 553 | 626 | True |
| 554 | 627 | """ |
| | 628 | |
| | 629 | def weight(self): |
| | 630 | """ |
| | 631 | Returns the weight of self. |
| | 632 | |
| | 633 | EXAMPLES: |
| | 634 | sage: [v.weight() for v in CrystalOfLetters(['G',2])] |
| | 635 | [(-1, 0, 1), |
| | 636 | (-1, 1, 0), |
| | 637 | (0, -1, 1), |
| | 638 | (0, 0, 0), |
| | 639 | (0, 1, -1), |
| | 640 | (1, -1, 0), |
| | 641 | (1, 0, -1)] |
| | 642 | """ |
| | 643 | if self.value == 1: |
| | 644 | return self._parent.weight_lattice_realization()._free_module((-1, 0, 1)) |
| | 645 | elif self.value == 2: |
| | 646 | return self._parent.weight_lattice_realization()._free_module((-1, 1, 0)) |
| | 647 | elif self.value == 3: |
| | 648 | return self._parent.weight_lattice_realization()._free_module((0, -1, 1)) |
| | 649 | elif self.value == 0: |
| | 650 | return self._parent.weight_lattice_realization()._free_module((0, 0, 0)) |
| | 651 | elif self.value == -3: |
| | 652 | return self._parent.weight_lattice_realization()._free_module((0, 1, -1)) |
| | 653 | elif self.value == -2: |
| | 654 | return self._parent.weight_lattice_realization()._free_module((1, -1, 0)) |
| | 655 | elif self.value == -1: |
| | 656 | return self._parent.weight_lattice_realization()._free_module((1, 0, -1)) |
| | 657 | else: |
| | 658 | raise RuntimeError, "G2 crystal of letters element %d not valid"%self.value |
| | 659 | |
| 555 | 660 | def e(self, i): |
| 556 | 661 | r""" |
| 557 | 662 | Returns the action of $e_i$ on self. |
diff -r f924a49c5a06 -r 5ef43cd8ac7c sage/combinat/crystals/tensor_product.py
|
a
|
b
|
|
| 235 | 235 | else: |
| 236 | 236 | self.module_generators = [ self(*x) for x in options['generators']] |
| 237 | 237 | |
| 238 | | |
| 239 | 238 | def __call__(self, *args): |
| 240 | 239 | """ |
| 241 | 240 | EXAMPLES: |
| … |
… |
|
| 272 | 271 | k = position[0] |
| 273 | 272 | return self.set_index(k, self[k].e(i)) |
| 274 | 273 | |
| | 274 | def weight(self): |
| | 275 | """ |
| | 276 | Returns the weight of self. |
| | 277 | |
| | 278 | EXAMPLES: |
| | 279 | sage: C = CrystalOfLetters(['A',3]) |
| | 280 | sage: T = TensorProductOfCrystals(C,C) |
| | 281 | sage: T(C(1),C(2)).weight() |
| | 282 | (1, 1, 0, 0) |
| | 283 | """ |
| | 284 | return sum(self[j].weight() for j in range(len(self))) |
| | 285 | |
| 275 | 286 | def f(self, i): |
| 276 | 287 | """ |
| 277 | 288 | Returns the action of $f_i$ on self. |