Ticket #2853: 2853.patch

File 2853.patch, 7.0 KB (added by mhansen, 2 years ago)
  • sage/combinat/crystals/letters.py

    # 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  
    142142        """ 
    143143        return self._digraph 
    144144     
    145  
    146145    def __contains__(self, x): 
    147146        """ 
    148147        EXAMPLES: 
     
    287286 
    288287        sage: C.check() 
    289288        True 
     289 
    290290    """ 
     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 
    291302    def e(self, i): 
    292303        r""" 
    293304        Returns the action of $e_i$ on self. 
     
    331342        sage: C.check() 
    332343        True 
    333344    """ 
     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 
    334367    def e(self, i): 
    335368        r""" 
    336369        Returns the action of $e_i$ on self. 
     
    410443         [False, False, False, False, False, False]] 
    411444        sage: C.check() 
    412445        True 
    413     
    414446    """ 
     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 
    415464    def e(self, i): 
    416465        r""" 
    417466        Returns the action of $e_i$ on self. 
     
    472521        [1, 2, 3, 4, -4, -3, -2, -1] 
    473522        sage: C.check() 
    474523        True 
     524         
    475525    """ 
     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 
    476549    def e(self, i): 
    477550        r""" 
    478551        Returns the action of $e_i$ on self. 
     
    552625        sage: C.check() 
    553626        True 
    554627    """ 
     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 
    555660    def e(self, i): 
    556661        r""" 
    557662        Returns the action of $e_i$ on self. 
  • sage/combinat/crystals/tensor_product.py

    diff -r f924a49c5a06 -r 5ef43cd8ac7c sage/combinat/crystals/tensor_product.py
    a b  
    235235            else: 
    236236                self.module_generators = [ self(*x) for x in options['generators']] 
    237237 
    238  
    239238    def __call__(self, *args): 
    240239        """ 
    241240        EXAMPLES: 
     
    272271        k = position[0] 
    273272        return self.set_index(k, self[k].e(i)) 
    274273     
     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 
    275286    def f(self, i): 
    276287        """ 
    277288        Returns the action of $f_i$ on self.