Ticket #2854: crystal_weights.patch

File crystal_weights.patch, 6.1 KB (added by bump, 13 years ago)
  • sage/combinat/crystals/letters.py

    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 80b506b8e07c sage/combinat/crystals/letters.py
    a b class ClassicalCrystalOfLetters(Classica 
    142142        """
    143143        return self._digraph
    144144   
    145 
    146145    def __contains__(self, x):
    147146        """
    148147        EXAMPLES:
    class Crystal_of_letters_type_A_element( 
    287286
    288287        sage: C.check()
    289288        True
    290     """
     289
     290        sage: [v.weight() for v in CrystalOfLetters(['A',3])]
     291        [(1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1)]
     292    """
     293    def weight(self):
     294        return self._parent.weight_lattice_realization()._term(self.value-1)
     295
    291296    def e(self, i):
    292297        r"""
    293298        Returns the action of $e_i$ on self.
    class Crystal_of_letters_type_B_element( 
    330335        sage: C = CrystalOfLetters (['B',3])
    331336        sage: C.check()
    332337        True
    333     """
     338        sage: [v.weight() for v in CrystalOfLetters(['B',3])]
     339        [(1, 0, 0),
     340         (0, 1, 0),
     341         (0, 0, 1),
     342         (0, 0, 0),
     343         (0, 0, -1),
     344         (0, -1, 0),
     345         (-1, 0, 0)]
     346    """
     347    def weight(self):
     348        if self.value > 0:
     349            return self._parent.weight_lattice_realization()._term(self.value-1)
     350        elif self.value < 0:
     351            return -self._parent.weight_lattice_realization()._term(-self.value-1)
     352        else:
     353            return self._parent.weight_lattice_realization()._free_module(0)
     354
    334355    def e(self, i):
    335356        r"""
    336357        Returns the action of $e_i$ on self.
    class Crystal_of_letters_type_C_element( 
    410431         [False, False, False, False, False, False]]
    411432        sage: C.check()
    412433        True
    413    
    414     """
     434        sage: [v.weight() for v in CrystalOfLetters(['C',3])]
     435        [(1, 0, 0), (0, 1, 0), (0, 0, 1), (0, 0, -1), (0, -1, 0), (-1, 0, 0)]
     436    """
     437    def weight(self):
     438        if self.value > 0:
     439            return self._parent.weight_lattice_realization()._term(self.value-1)
     440        elif self.value < 0:
     441            return -self._parent.weight_lattice_realization()._term(-self.value-1)
     442        else:
     443            return self._parent.weight_lattice_realization()._free_module(0)
     444
    415445    def e(self, i):
    416446        r"""
    417447        Returns the action of $e_i$ on self.
    class Crystal_of_letters_type_D_element( 
    472502        [1, 2, 3, 4, -4, -3, -2, -1]
    473503        sage: C.check()
    474504        True
    475     """
     505
     506        sage: [v.weight() for v in CrystalOfLetters(['D',4])]
     507        [(1, 0, 0, 0),
     508         (0, 1, 0, 0),
     509         (0, 0, 1, 0),
     510         (0, 0, 0, 1),
     511         (0, 0, 0, -1),
     512         (0, 0, -1, 0),
     513         (0, -1, 0, 0),
     514         (-1, 0, 0, 0)]
     515    """
     516    def weight(self):
     517        if self.value > 0:
     518            return self._parent.weight_lattice_realization()._term(self.value-1)
     519        elif self.value < 0:
     520            return -self._parent.weight_lattice_realization()._term(-self.value-1)
     521        else:
     522            return self._parent.weight_lattice_realization()._free_module(0)
     523
    476524    def e(self, i):
    477525        r"""
    478526        Returns the action of $e_i$ on self.
    class Crystal_of_letters_type_G_element( 
    551599        [1, 2, 3, 0, -3, -2, -1]
    552600        sage: C.check()
    553601        True
    554     """
     602        sage: [v.weight() for v in CrystalOfLetters(['G',2])]
     603        [(-1, 0, 1),
     604         (-1, 1, 0),
     605         (0, -1, 1),
     606         (0, 0, 0),
     607         (0, 1, -1),
     608         (1, -1, 0),
     609         (1, 0, -1)]
     610    """
     611    def weight(self):
     612        if self.value ==1:
     613            return self._parent.weight_lattice_realization()._free_module((-1, 0, 1))
     614        elif self.value ==2:
     615            return self._parent.weight_lattice_realization()._free_module((-1, 1, 0))
     616        elif self.value ==3:
     617            return self._parent.weight_lattice_realization()._free_module((0, -1, 1))
     618        elif self.value ==0:
     619            return self._parent.weight_lattice_realization()._free_module((0, 0, 0))
     620        elif self.value ==-3:
     621            return self._parent.weight_lattice_realization()._free_module((0, 1, -1))
     622        elif self.value ==-2:
     623            return self._parent.weight_lattice_realization()._free_module((1, -1, 0))
     624        elif self.value ==-1:
     625            return self._parent.weight_lattice_realization()._free_module((1, 0, -1))
     626        else:
     627            raise RuntimeError, "G2 crystal of letters element %d not valid"%self.value
     628
    555629    def e(self, i):
    556630        r"""
    557631        Returns the action of $e_i$ on self.
  • sage/combinat/crystals/tensor_product.py

    diff -r 80b506b8e07c sage/combinat/crystals/tensor_product.py
    a b class TensorProductOfCrystals(ClassicalC 
    234234            else:
    235235                self.module_generators = [ self(*x) for x in options['generators']]
    236236
    237 
    238237    def __call__(self, *args):
    239238        """
    240239        EXAMPLES:
    class TensorProductOfCrystalsElement(Imm 
    271270        k = position[0]
    272271        return self.set_index(k, self[k].e(i))
    273272   
     273    def weight(self):
     274        return sum(self[j].weight() for j in range(len(self)))
     275
    274276    def f(self, i):
    275277        """
    276278        Returns the action of $f_i$ on self.