Ticket #3601: tensor_product-3601-review.patch

File tensor_product-3601-review.patch, 5.5 KB (added by mhansen, 13 years ago)
  • sage/combinat/crystals/tensor_product.py

    # HG changeset patch
    # User Mike Hansen <mhansen@gmail.com>
    # Date 1215636097 18000
    # Node ID 5264d43d46adb88ec78de470a3a51a71c0162803
    # Parent  aadde55709efb9226c112b55edd79893b57bc4d5
    imported patch tensor_product-3601-review.patch
    
    diff -r aadde55709ef -r 5264d43d46ad sage/combinat/crystals/tensor_product.py
    a b  
    216216        [[2, 1, 1], [1, 2, 1]]
    217217    """
    218218    if options.has_key('generators'):
    219         if all(isinstance(crystal,ClassicalCrystal) for crystal in crystals):
    220             return TensorProductOfClassicalCrystalsWithGenerators(generators=options['generators'], *crystals)
    221         else:
    222             return TensorProductOfCrystalsWithGenerators(generators=options['generators'], *crystals)
     219        if all(isinstance(crystal,ClassicalCrystal) for crystal in crystals):
     220            return TensorProductOfClassicalCrystalsWithGenerators(generators=options['generators'], *crystals)
     221        else:
     222            return TensorProductOfCrystalsWithGenerators(generators=options['generators'], *crystals)
    223223    else:
    224         if all(isinstance(crystal,ClassicalCrystal) for crystal in crystals):
    225             return FullTensorProductOfClassicalCrystals(*crystals)
    226         else:
    227             return FullTensorProductOfCrystals(*crystals)
     224        if all(isinstance(crystal,ClassicalCrystal) for crystal in crystals):
     225            return FullTensorProductOfClassicalCrystals(*crystals)
     226        else:
     227            return FullTensorProductOfCrystals(*crystals)
    228228
    229229class TensorProductOfCrystalsWithGenerators(Crystal):
    230 
    231230    def __init__(self, *crystals, **options):
    232231        """
    233232        EXAMPLES:
     
    247246            else:
    248247                self.cartan_type = crystals[0].cartan_type
    249248        self.index_set = self.cartan_type.index_set()
    250 #        if options.has_key('generators'):
    251 #            if options['generators'] == "all":
    252 #                self.module_generators = []
    253 #                for c in list(xmrange_iter([D.list() for D in crystals])):
    254 #                    candidate = self(*c)
    255 #                    if all(candidate.e(k) == None for k in self.index_set):
    256 #                        self.module_generators.append(candidate)
    257 #            else:
    258 #                self.module_generators = [ self(*x) for x in options['generators']]
    259         self.module_generators = [ self(*x) for x in options['generators']]
     249        self.module_generators = [ self(*x) for x in options['generators']]
    260250
    261251    def __call__(self, *args):
    262252        """
     
    273263    pass
    274264
    275265class FullTensorProductOfCrystals(Crystal):
    276  
    277266    def __init__(self, *crystals, **options):
    278         crystals = [ crystal for crystal in crystals]
     267        """
     268        TESTS:
     269            sage: from sage.combinat.crystals.tensor_product import FullTensorProductOfCrystals
     270            sage: C = CrystalOfLetters(['A',2])
     271            sage: T = TensorProductOfCrystals(C,C)
     272            sage: isinstance(T, FullTensorProductOfCrystals)
     273            True
     274            sage: T == loads(dumps(T))
     275            True
     276        """
     277        crystals = list(crystals)
    279278        self._name = "Full tensor product of the crystals %s"%crystals
    280279        self.crystals = crystals
    281280        if options.has_key('cartan_type'):
     
    285284                raise ValueError, "you need to specify the Cartan type if the tensor product list is empty"
    286285            else:
    287286                self.cartan_type = crystals[0].cartan_type
    288             self.index_set = self.cartan_type.index_set()
    289         self.cartesian_product = CartesianProduct(*self.crystals)
    290         self.module_generators = self
     287            self.index_set = self.cartan_type.index_set()
     288        self.cartesian_product = CartesianProduct(*self.crystals)
     289        self.module_generators = self
    291290
    292291    def iterator(self):
    293         for x in self.cartesian_product:
    294             yield self(*x)
     292        """
     293        EXAMPLES:
     294            sage: C = CrystalOfLetters(['A',2])
     295            sage: T = TensorProductOfCrystals(C,C)
     296            sage: list(T.iterator())
     297            [[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3]]
     298            sage: _[0].parent()
     299            Full tensor product of the crystals [The crystal of letters for type ['A', 2], The crystal of letters for type ['A', 2]]
     300        """
     301        for x in self.cartesian_product:
     302            yield self(*x)
    295303
    296304    __iter__ = iterator
    297305
    298306    list = CombinatorialClass._CombinatorialClass__list_from_iterator
    299307   
    300308    def count(self):
    301         return self.cartesian_product.count()
     309        """
     310        EXAMPLES:
     311            sage: C = CrystalOfLetters(['A',2])
     312            sage: T = TensorProductOfCrystals(C,C)
     313            sage: T.count()
     314            9
     315        """
     316        return self.cartesian_product.count()
    302317
    303     def __call__(self, *args):
    304         return TensorProductOfCrystalsElement(self,
    305                                               [crystalElement for crystalElement in args])
     318    def __call__(self, *crystalElements):
     319        """
     320        EXAMPLES:
     321            sage: C = CrystalOfLetters(['A',2])
     322            sage: T = TensorProductOfCrystals(C,C)
     323            sage: T(1,1)
     324            [1, 1]
     325            sage: _.parent()
     326            Full tensor product of the crystals [The crystal of letters for type ['A', 2], The crystal of letters for type ['A', 2]]
     327        """
     328        return TensorProductOfCrystalsElement(self, list(crystalElements))
     329
    306330
    307331class FullTensorProductOfClassicalCrystals(FullTensorProductOfCrystals, ClassicalCrystal):
    308332    pass