Ticket #8154: trac_8154_affine-E-as.patch

File trac_8154_affine-E-as.patch, 163.5 KB (added by Anne Schilling, 13 years ago)
  • sage/combinat/crystals/affine.py

    # HG changeset patch
    # User Anne Schilling <anne@math.ucdavis.edu>
    # Date 1265150820 28800
    # Node ID b11d34d784d9d505d34a89c5c031c3c362a7ce03
    # Parent  3beb506d5975e568f4a9e7e2306eb8443a1db507
    trac #8154: Enhancement for crystals
    
    New features for crystals:
    
     - Started framework for general highest weight crystals in /combinat/crystals/highest_weight.py (with contributions from Nicolas M. Thiery)
     - Implementation of finite dimensional highest weight crystals for type E6 and E7
     - Added new class for direct sums of crystals in /combinat/crystals/direct_sum.py
     - Added a new crystal morphism function for acyclic crystals
     - Added the Demazure operators on crystals
     - Added Demazure characters for finite crystals in the ambient weight lattice
     - Added _test_fast_iter method to compare two different ways of creating list of classical crystals
    
    New features for Kirillov-Reshetikhin crystals:
    
     - Implementation of Kirillov-Reshetikhin crystals B^{r,s} of type E_6^{(1)} for r=1,2,6
     - Pointer to KirillovReshetikhin crystals given in /combinat/crystals/affine.py (as requested by Dan Bump)
     - Added R-matrix for tensor product of two KR crystals
    
    Bug fix:
    
     - Fixed whitespace problems in
       /combinat/crystals/crystals.py
       /combinat/crystals/kirillov_reshetikhin.py
       /combinat/crystals/affine.py
       /combinat/crystals/spins.py
       /combinat/crystals/tensor_products.py
       /combinat/crystals/fast_crystals.py
       /combinat/crystals/letters.py
    
    Depends on trac ticket #7978 (trac_7978_crystal_cleanup-as.patch)
    
    diff --git a/sage/combinat/crystals/affine.py b/sage/combinat/crystals/affine.py
    a b class AffineCrystalFromClassical(Crystal 
    3939    The zero arrows can be implemented using different methods (for example using a Dynkin diagram
    4040    automorphisms or virtual crystals).
    4141
     42    This is a helper class, mostly used to implement Kirillov-Reshetikhin crystals
     43    (see: :function:`sage.combinat.crystals.kirillov_reshetikhin.KirillovReshetikhin`).
     44
    4245    For general information about crystals see :mod:`sage.combinat.crystals`.
    4346
    4447    INPUT:
    class AffineCrystalFromClassical(Crystal 
    106109        super(AffineCrystalFromClassical, self).__init__(category = category)
    107110        self.classical_crystal = classical_crystal;
    108111        self.module_generators = map( self.retract, self.classical_crystal.module_generators )
    109         self.element_class._latex_ = lambda x: x.lift()._latex_()
     112        self.element_class._latex_ = lambda x: x.lift()._latex_()
    110113
    111114    def _repr_(self):
    112115        """
  • sage/combinat/crystals/all.py

    diff --git a/sage/combinat/crystals/all.py b/sage/combinat/crystals/all.py
    a b from fast_crystals import FastCrystal 
    99from affine import AffineCrystalFromClassical
    1010from affine import AffineCrystalFromClassicalAndPromotion
    1111from kirillov_reshetikhin import KirillovReshetikhinCrystal
     12from highest_weight_crystals import HighestWeightCrystal
     13from direct_sum import DirectSumOfCrystals
  • sage/combinat/crystals/crystals.py

    diff --git a/sage/combinat/crystals/crystals.py b/sage/combinat/crystals/crystals.py
    a b inspiration. 
    134134# library is heavily inspired from MuPAD-Combinat.
    135135#****************************************************************************
    136136
     137from sage.misc.misc_c import prod
    137138from sage.misc.latex import latex
    138139from sage.misc.cachefunc import CachedFunction
    139140from sage.structure.unique_representation import UniqueRepresentation
    from sage.graphs.all import DiGraph 
    144145from sage.combinat import ranker
    145146from sage.combinat.root_system.weyl_characters import WeylCharacter
    146147from sage.combinat.backtrack import GenericBacktracker
     148from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
     149from sage.rings.rational_field import QQ
    147150
    148151## MuPAD-Combinat's Cat::Crystal
    149152# FIXME: crystals, like most parent should have unique data representation
    class Crystal(UniqueRepresentation, Pare 
    182185            sage: C = CrystalOfLetters(['A', 5])
    183186            sage: C.weight_lattice_realization()
    184187            Ambient space of the Root system of type ['A', 5]
    185             sage: K = KirillovReshetikhinCrystal(['A',2,1], 1, 1)
    186             sage: K.weight_lattice_realization()
    187             Weight lattice of the Root system of type ['A', 2, 1]
     188            sage: K = KirillovReshetikhinCrystal(['A',2,1], 1, 1)
     189            sage: K.weight_lattice_realization()
     190            Weight lattice of the Root system of type ['A', 2, 1]
    188191        """
    189         F = self.cartan_type().root_system()
    190         if F.ambient_space() is None:
    191             return F.weight_lattice()
    192         else:
    193             return F.ambient_space()
     192        F = self.cartan_type().root_system()
     193        if F.ambient_space() is None:
     194            return F.weight_lattice()
     195        else:
     196            return F.ambient_space()
    194197
    195198    def cartan_type(self):
    196199        """
    class Crystal(UniqueRepresentation, Pare 
    274277            [1, 2, 3, 4, 5, 6]
    275278        """
    276279        # Should use transitiveIdeal
    277         # should be transformed to __iter__ instead of list
     280        # should be transformed to __iter__ instead of list
    278281        # To be moved in a super category CombinatorialModule
    279282        result = set(self.module_generators)
    280283        todo = result.copy()
    class Crystal(UniqueRepresentation, Pare 
    289292        return list(result)
    290293
    291294    def crystal_morphism(self, g, index_set = None, automorphism = lambda i : i, direction = 'down', direction_image = 'down',
    292                          similarity_factor = None, similarity_factor_domain = None, cached = False):
    293         """
    294         Constructs a morphism from the crystal self to another crystal.
    295         The input g can either be a function of a (sub)set of elements of self to
    296         element in another crystal or a dictionary between certain elements.
    297         Usually one would map highest weight elements or crystal generators to each
    298         other using g.
    299         Specifying index_set gives the opportunity to define the morphism as `I`-crystals
    300         where `I =` index_set. If index_set is not specified, the index set of self is used.
    301         It is also possible to define twisted-morphisms by specifying an automorphism on the
    302         nodes in te Dynkin diagram (or the index_set).
    303         The option direction and direction_image indicate whether to use `f_i` or `e_i` in
    304         self or the image crystal to construct the morphism, depending on whether the direction
    305         is set to 'down' or 'up'.
    306         Finally, it is possible to set a similarity_factor. This should be a dictionary between
    307         the elements in the index set and positive integers. The crystal operator `f_i` then gets
    308         mapped to `f_i^{m_i}` where `m_i =` similarity_factor[i].
    309         Setting similarity_factor_domain to a dictionary between the index set and positive integers
    310         has the effect that `f_i^{m_i}` gets mapped to `f_i` where `m_i =` similarity_factor_domain[i].
     295                         similarity_factor = None, similarity_factor_domain = None, cached = False, acyclic = True):
     296        """
     297        Constructs a morphism from the crystal self to another crystal.
     298        The input `g` can either be a function of a (sub)set of elements of self to
     299        element in another crystal or a dictionary between certain elements.
     300        Usually one would map highest weight elements or crystal generators to each
     301        other using g.
     302        Specifying index_set gives the opportunity to define the morphism as `I`-crystals
     303        where `I =` index_set. If index_set is not specified, the index set of self is used.
     304        It is also possible to define twisted-morphisms by specifying an automorphism on the
     305        nodes in te Dynkin diagram (or the index_set).
     306        The option direction and direction_image indicate whether to use `f_i` or `e_i` in
     307        self or the image crystal to construct the morphism, depending on whether the direction
     308        is set to 'down' or 'up'.
     309        It is also possible to set a similarity_factor. This should be a dictionary between
     310        the elements in the index set and positive integers. The crystal operator `f_i` then gets
     311        mapped to `f_i^{m_i}` where `m_i =` similarity_factor[i].
     312        Setting similarity_factor_domain to a dictionary between the index set and positive integers
     313        has the effect that `f_i^{m_i}` gets mapped to `f_i` where `m_i =` similarity_factor_domain[i].
     314        Finally, it is possible to set the option `acyclic = False`. This calculates an isomorphism
     315        for cyclic crystals (for example finite affine crystals). In this case the input function `g`
     316        is supposed to be given as a dictionary.
    311317
    312         EXAMPLES::
     318        EXAMPLES::
    313319
    314             sage: C2 = CrystalOfLetters(['A',2])
    315             sage: C3 = CrystalOfLetters(['A',3])
    316             sage: g = {C2.module_generators[0] : C3.module_generators[0]}
    317             sage: g_full = C2.crystal_morphism(g)
    318             sage: g_full(C2(1))
    319             1
    320             sage: g_full(C2(2))
    321             2
    322             sage: g = {C2(1) : C2(3)}
    323             sage: g_full = C2.crystal_morphism(g, automorphism = lambda i : 3-i, direction_image = 'up')
    324             sage: [g_full(b) for b in C2]
    325             [3, 2, 1]
    326             sage: T = CrystalOfTableaux(['A',2], shape = [2])
    327             sage: g = {C2(1) : T(rows=[[1,1]])}
    328             sage: g_full = C2.crystal_morphism(g, similarity_factor = {1:2, 2:2})
    329             sage: [g_full(b) for b in C2]
    330             [[[1, 1]], [[2, 2]], [[3, 3]]]
    331             sage: g = {T(rows=[[1,1]]) : C2(1)}
    332             sage: g_full = T.crystal_morphism(g, similarity_factor_domain = {1:2, 2:2})
    333             sage: g_full(T(rows=[[2,2]]))
    334             2
     320            sage: C2 = CrystalOfLetters(['A',2])
     321            sage: C3 = CrystalOfLetters(['A',3])
     322            sage: g = {C2.module_generators[0] : C3.module_generators[0]}
     323            sage: g_full = C2.crystal_morphism(g)
     324            sage: g_full(C2(1))
     325            1
     326            sage: g_full(C2(2))
     327            2
     328            sage: g = {C2(1) : C2(3)}
     329            sage: g_full = C2.crystal_morphism(g, automorphism = lambda i : 3-i, direction_image = 'up')
     330            sage: [g_full(b) for b in C2]
     331            [3, 2, 1]
     332            sage: T = CrystalOfTableaux(['A',2], shape = [2])
     333            sage: g = {C2(1) : T(rows=[[1,1]])}
     334            sage: g_full = C2.crystal_morphism(g, similarity_factor = {1:2, 2:2})
     335            sage: [g_full(b) for b in C2]
     336            [[[1, 1]], [[2, 2]], [[3, 3]]]
     337            sage: g = {T(rows=[[1,1]]) : C2(1)}
     338            sage: g_full = T.crystal_morphism(g, similarity_factor_domain = {1:2, 2:2})
     339            sage: g_full(T(rows=[[2,2]]))
     340            2
     341
     342            sage: B1=KirillovReshetikhinCrystal(['A',2,1],1,1)
     343            sage: B2=KirillovReshetikhinCrystal(['A',2,1],1,2)
     344            sage: T=TensorProductOfCrystals(B1,B2)
     345            sage: T1=TensorProductOfCrystals(B2,B1)
     346            sage: La = T.weight_lattice_realization().fundamental_weights()
     347            sage: t = [b for b in T if b.weight() == -3*La[0] + 3*La[1]][0]
     348            sage: t1 = [b for b in T1 if b.weight() == -3*La[0] + 3*La[1]][0]
     349            sage: g={t:t1}
     350            sage: f=T.crystal_morphism(g,acyclic = False)
     351            sage: [[b,f(b)] for b in T]
     352            [[[[[1]], [[1, 1]]], [[[1, 1]], [[1]]]],
     353            [[[[1]], [[1, 2]]], [[[1, 1]], [[2]]]],
     354            [[[[1]], [[2, 2]]], [[[1, 2]], [[2]]]],
     355            [[[[1]], [[1, 3]]], [[[1, 1]], [[3]]]],
     356            [[[[1]], [[2, 3]]], [[[1, 2]], [[3]]]],
     357            [[[[1]], [[3, 3]]], [[[1, 3]], [[3]]]],
     358            [[[[2]], [[1, 1]]], [[[1, 2]], [[1]]]],
     359            [[[[2]], [[1, 2]]], [[[2, 2]], [[1]]]],
     360            [[[[2]], [[2, 2]]], [[[2, 2]], [[2]]]],
     361            [[[[2]], [[1, 3]]], [[[2, 3]], [[1]]]],
     362            [[[[2]], [[2, 3]]], [[[2, 2]], [[3]]]],
     363            [[[[2]], [[3, 3]]], [[[2, 3]], [[3]]]],
     364            [[[[3]], [[1, 1]]], [[[1, 3]], [[1]]]],
     365            [[[[3]], [[1, 2]]], [[[1, 3]], [[2]]]],
     366            [[[[3]], [[2, 2]]], [[[2, 3]], [[2]]]],
     367            [[[[3]], [[1, 3]]], [[[3, 3]], [[1]]]],
     368            [[[[3]], [[2, 3]]], [[[3, 3]], [[2]]]],
     369            [[[[3]], [[3, 3]]], [[[3, 3]], [[3]]]]]
    335370        """
    336         if index_set is None:
    337             index_set = self.index_set()
    338         if similarity_factor is None:
    339             similarity_factor = dict( (i,1) for i in index_set )
    340         if similarity_factor_domain is None:
    341             similarity_factor_domain = dict( (i,1) for i in index_set )
    342         if direction == 'down':
    343             e_string = 'e_string'
    344         else:
    345             e_string = 'f_string'
    346         if direction_image == 'down':
    347             f_string = 'f_string'
    348         else:
    349             f_string = 'e_string'
    350         if type(g) == dict:
    351             g = g.__getitem__
     371        if index_set is None:
     372            index_set = self.index_set()
     373        if similarity_factor is None:
     374            similarity_factor = dict( (i,1) for i in index_set )
     375        if similarity_factor_domain is None:
     376            similarity_factor_domain = dict( (i,1) for i in index_set )
     377        if direction == 'down':
     378            e_string = 'e_string'
     379        else:
     380            e_string = 'f_string'
     381        if direction_image == 'down':
     382            f_string = 'f_string'
     383        else:
     384            f_string = 'e_string'
    352385
    353         def morphism(b):
    354             for i in index_set:
    355                 c = getattr(b, e_string)([i for k in range(similarity_factor_domain[i])])
    356                 if c is not None:
    357                     d = getattr(morphism(c),f_string)([automorphism(i) for k in range(similarity_factor[i])])
    358                     if d is not None:
    359                         return d
    360                     else:
    361                         raise ValueError, "This is not a morphism!"
    362             #now we know that b is hw
    363             return g(b)
     386        if acyclic:
     387            if type(g) == dict:
     388                g = g.__getitem__
    364389
    365         if cached:
    366             return morphism
    367         else:
    368             return CachedFunction(morphism)
     390            def morphism(b):
     391                for i in index_set:
     392                    c = getattr(b, e_string)([i for k in range(similarity_factor_domain[i])])
     393                    if c is not None:
     394                        d = getattr(morphism(c), f_string)([automorphism(i) for k in range(similarity_factor[i])])
     395                        if d is not None:
     396                            return d
     397                        else:
     398                            raise ValueError, "This is not a morphism!"
     399                        #now we know that b is hw
     400                return g(b)
    369401
     402        else:
     403            import copy
     404            morphism = copy.copy(g)
     405            known = set( g.keys() )
     406            todo = copy.copy(known)
     407            images = set( [g[x] for x in known] )
     408            # Invariants:
     409            # - images contains all known morphism(x)
     410            # - known contains all elements x for which we know morphism(x)
     411            # - todo  contains all elements x for which we haven't propagated to each child
     412            while todo <> set( [] ):
     413                x = todo.pop()
     414                for i in index_set:
     415                    eix  = getattr(x, f_string)([i for k in range(similarity_factor_domain[i])])
     416                    eigx = getattr(morphism[x], f_string)([automorphism(i) for k in range(similarity_factor[i])])
     417                    if bool(eix is None) <> bool(eigx is None):
     418                        # This is not a crystal morphism!
     419                        raise ValueError, "This is not a morphism!" #, print("x="x,"g(x)="g(x),"i="i)
     420                    if (eix is not None) and (eix not in known):
     421                        todo.add(eix)
     422                        known.add(eix)
     423                        morphism[eix] = eigx
     424                        images.add(eigx)
     425            # Check that the module generators are indeed module generators
     426            assert(len(known) == self.cardinality())
     427            # We may not want to systematically run those tests,
     428            # to allow for non bijective crystal morphism
     429            # Add an option CheckBijective?
     430            if not ( len(known) == len(images) and len(images) == images.pop().parent().cardinality() ):
     431                return(None)
     432            return morphism.__getitem__
     433
     434        if cached:
     435            return morphism
     436        else:
     437            return CachedFunction(morphism)
     438
     439    def demazure_character(self, weight, reduced_word = False):
     440        r"""
     441        Calculates the Demazure character associated to the specified weight in the
     442        ambient weight lattice.
     443
     444        INPUT:
     445            - weight in the weight lattice realization of the crystal (default input)
     446            - when the option reduced_word is set to True, a reduced word can be inputted
     447
     448        This is currently only supported for crystals whose underlying weight space is
     449        the ambient space.
     450
     451        References:
     452
     453        M. Demazure, ``Desingularisation des varietes de Schubert'',
     454        Ann. E. N. S., Vol. 6, (1974), p. 163-172
     455
     456        Sarah Mason, ``An Explicit Construction of Type A Demazure Atoms'',
     457        Journal of Algebraic Combinatorics, Vol. 29, (2009), No. 3, p.295-313
     458        (arXiv:0707.4267)
     459
     460        EXAMPLES::
     461
     462            sage: T = CrystalOfTableaux(['A',2], shape = [2,1])
     463            sage: e = T.weight_lattice_realization().basis()
     464            sage: weight = e[0] + 2*e[2]
     465            sage: weight.reduced_word()
     466            [2, 1]
     467            sage: T.demazure_character(weight)
     468            x1^2*x2 + x1^2*x3 + x1*x2^2 + x1*x2*x3 + x1*x3^2
     469
     470            sage: T = CrystalOfTableaux(['A',3],shape=[2,1])
     471            sage: T.demazure_character([1,2,3], reduced_word = True)
     472            x1^2*x2 + x1^2*x3 + x1*x2^2 + x1*x2*x3 + x2^2*x3
     473
     474            sage: T = CrystalOfTableaux(['B',2], shape = [2])
     475            sage: e = T.weight_lattice_realization().basis()
     476            sage: weight = -2*e[1]
     477            sage: T.demazure_character(weight)
     478            x1^2 + x1*x2 + x2^2 + x1 + x2 + x1/x2 + 1/x2 + 1/x2^2 + 1
     479        """
     480        if reduced_word:
     481            word = weight
     482        else:
     483            word = weight.reduced_word()
     484        n = self.weight_lattice_realization().n
     485        u = list( self.module_generators )
     486        for i in reversed(word):
     487            u = u + sum((x.demazure_operator(i, truncated = True) for x in u), [])
     488        x = ['x%s'%i for i in range(1,n+1)]
     489        P = PolynomialRing(QQ, x)
     490        u = [b.weight() for b in u]
     491        return sum((prod((x[i]**(la[i]) for i in range(n)), P.one()) for la in u), P.zero()) 
    370492
    371493    def digraph(self):
    372494        """
    class Crystal(UniqueRepresentation, Pare 
    679801                else:
    680802                    option = ""
    681803                    (source, target) = (x, child)
    682                 result += "  " + vertex_key(source) + " -> "+vertex_key(target)+ " [ "+option+"label = \" \", texlbl = \""+quoted_latex(i)+"\" ];\n"
     804                result += "  " + vertex_key(source) + " -> "+vertex_key(target)+ " [ "+option+"label = \" \", texlbl = \""+quoted_latex(i)+"\" ];\n"
    683805        result+="}"
    684806        return result
    685807   
    class CrystalElement(Element): 
    813935        return phi
    814936
    815937    def phi_minus_epsilon(self, i):
    816         """
    817         Returns `\phi_i - \epsilon_i` of self. There are sometimes
    818         better implementations using the weight for this. It is used
    819         for reflections along a string.
     938        """
     939        Returns `\phi_i - \epsilon_i` of self. There are sometimes
     940        better implementations using the weight for this. It is used
     941        for reflections along a string.
    820942
    821         EXAMPLES::
     943        EXAMPLES::
    822944
    823             sage: C = CrystalOfLetters(['A',5])
     945            sage: C = CrystalOfLetters(['A',5])
    824946            sage: C(1).phi_minus_epsilon(1)
    825947            1
    826948        """
    827         return self.phi(i) - self.epsilon(i)
     949        return self.phi(i) - self.epsilon(i)
    828950
    829951    def Epsilon(self):
    830952        """
    class CrystalElement(Element): 
    857979        return sum(self.phi(i) * Lambda[i] for i in self.index_set())
    858980
    859981    def f_string(self, list):
    860         r"""
    861         Applies `f_{i_r} ... f_{i_1}` to self for `list = [i_1, ..., i_r]`
     982        r"""
     983        Applies `f_{i_r} ... f_{i_1}` to self for `list = [i_1, ..., i_r]`
    862984
    863         EXAMPLES::
     985        EXAMPLES::
    864986
    865             sage: C = CrystalOfLetters(['A',3])
    866             sage: b = C(1)
    867             sage: b.f_string([1,2])
    868             3
    869             sage: b.f_string([2,1])
     987            sage: C = CrystalOfLetters(['A',3])
     988            sage: b = C(1)
     989            sage: b.f_string([1,2])
     990            3
     991            sage: b.f_string([2,1])
    870992
    871         """
    872         b = self
    873         for i in list:
    874             b = b.f(i)
    875             if b is None:
    876                 return None
    877         return b
     993        """
     994        b = self
     995        for i in list:
     996            b = b.f(i)
     997            if b is None:
     998                return None
     999        return b
    8781000
    8791001    def e_string(self, list):
    880         r"""
    881         Applies `e_{i_r} ... e_{i_1}` to self for `list = [i_1, ..., i_r]`
     1002        r"""
     1003        Applies `e_{i_r} ... e_{i_1}` to self for `list = [i_1, ..., i_r]`
    8821004
    883         EXAMPLES::
     1005        EXAMPLES::
    8841006
    885             sage: C = CrystalOfLetters(['A',3])
    886             sage: b = C(3)
    887             sage: b.e_string([2,1])
    888             1
    889             sage: b.e_string([1,2])
     1007            sage: C = CrystalOfLetters(['A',3])
     1008            sage: b = C(3)
     1009            sage: b.e_string([2,1])
     1010            1
     1011            sage: b.e_string([1,2])
    8901012
    891         """
    892         b = self
    893         for i in list:
    894             b = b.e(i)
    895             if b is None:
    896                 return None
    897         return b
     1013        """
     1014        b = self
     1015        for i in list:
     1016            b = b.e(i)
     1017            if b is None:
     1018                return None
     1019        return b
    8981020
    8991021    def s(self, i):
    9001022        r"""
    class CrystalElement(Element): 
    9241046                b = b.e(i)
    9251047        return b
    9261048
     1049    def demazure_operator(self, i, truncated = False):
     1050        r"""
     1051        Yields all elements one can obtain from self by application of `f_i`.
     1052        If the option "truncated" is set to True, then `self` is not included in the list.
     1053
     1054        References:
     1055       
     1056        Peter Littelmann, ``Crystal graphs and Young tableaux'',
     1057        J. Algebra 175 (1995), no. 1, 65--87.
     1058
     1059        Masaki Kashiwara, ``The crystal base and Littelmann's refined Demazure character formula'',
     1060        Duke Math. J. 71 (1993), no. 3, 839--858.
     1061
     1062        EXAMPLES::
     1063       
     1064            sage: T = CrystalOfTableaux(['A',2], shape=[2,1])
     1065            sage: t=T(rows=[[1,2],[2]])
     1066            sage: t.demazure_operator(2)
     1067            [[[1, 2], [2]], [[1, 3], [2]], [[1, 3], [3]]]
     1068            sage: t.demazure_operator(2, truncated = True)
     1069            [[[1, 3], [2]], [[1, 3], [3]]]
     1070            sage: t.demazure_operator(1, truncated = True)
     1071            []
     1072            sage: t.demazure_operator(1)
     1073            [[[1, 2], [2]]]
     1074
     1075            sage: K = KirillovReshetikhinCrystal(['A',2,1],2,1)
     1076            sage: t = K(rows=[[3],[2]])
     1077            sage: t.demazure_operator(0)
     1078            [[[2, 3]], [[1, 2]]]
     1079        """
     1080        if truncated:
     1081            l = []
     1082        else:
     1083            l = [self]
     1084        for k in range(self.phi(i)):
     1085            l.append(self.f_string([i for j in range(k+1)]))
     1086        return(l)
     1087
    9271088    def is_highest_weight(self, index_set = None):
    9281089        r"""
    9291090        Returns True if self is a highest weight.
    930         Specifying the option index_set to be a subset `I` of the index set
    931         of the underlying crystal, finds all highest weight vectors for arrows in `I`.
     1091        Specifying the option index_set to be a subset `I` of the index set
     1092        of the underlying crystal, finds all highest weight vectors for arrows in `I`.
    9321093       
    9331094        EXAMPLES::
    9341095       
    class CrystalElement(Element): 
    9371098            True
    9381099            sage: C(2).is_highest_weight()
    9391100            False
    940             sage: C(2).is_highest_weight(index_set = [2,3,4,5])
    941             True
     1101            sage: C(2).is_highest_weight(index_set = [2,3,4,5])
     1102            True
    9421103        """
    943         if index_set is None:
    944             index_set = self.index_set()
     1104        if index_set is None:
     1105            index_set = self.index_set()
    9451106        return all(self.e(i) == None for i in index_set)
    9461107
    9471108    def to_highest_weight(self, list = [], index_set = None):
    948         r"""
    949         Yields the highest weight element `u` and list `[i_1,...,i_k]`
    950         such that `self = f_{i_1} ... f_{i_k} u`, where `i_1,...,i_k` are
    951         elements in `index_set`. By default the index set is assumed to be
    952         the full index set of self.
     1109        r"""
     1110        Yields the highest weight element `u` and list `[i_1,...,i_k]`
     1111        such that `self = f_{i_1} ... f_{i_k} u`, where `i_1,...,i_k` are
     1112        elements in `index_set`. By default the index set is assumed to be
     1113        the full index set of self.
    9531114
    954         EXAMPLES::
    955            
    956             sage: T = CrystalOfTableaux(['A',3], shape = [1])
    957             sage: t = T(rows = [[3]])
    958             sage: t.to_highest_weight()
    959             [[[1]], [2, 1]]
    960             sage: t.to_highest_weight()
    961             [[[1]], [2, 1]]
    962             sage: T = CrystalOfTableaux(['A',3], shape = [2,1])
    963             sage: t = T(rows = [[1,2],[4]])
    964             sage: t.to_highest_weight()
    965             [[[1, 1], [2]], [1, 3, 2]]
    966             sage: t.to_highest_weight(index_set = [3])
    967             [[[1, 2], [3]], [3]]
    968         """
    969         #should assert that self.parent() restricted to index_set is a highest weight crystal
    970         if index_set is None:
    971             index_set = self.index_set()
    972         for i in index_set:
    973             if self.epsilon(i) <> 0:
    974                 self = self.e(i)
    975                 return self.to_highest_weight(list = list + [i], index_set = index_set)
    976         return [self, list]
     1115        EXAMPLES::
     1116           
     1117            sage: T = CrystalOfTableaux(['A',3], shape = [1])
     1118            sage: t = T(rows = [[3]])
     1119            sage: t.to_highest_weight()
     1120            [[[1]], [2, 1]]
     1121            sage: t.to_highest_weight()
     1122            [[[1]], [2, 1]]
     1123            sage: T = CrystalOfTableaux(['A',3], shape = [2,1])
     1124            sage: t = T(rows = [[1,2],[4]])
     1125            sage: t.to_highest_weight()
     1126            [[[1, 1], [2]], [1, 3, 2]]
     1127            sage: t.to_highest_weight(index_set = [3])
     1128            [[[1, 2], [3]], [3]]
     1129        """
     1130        #should assert that self.parent() restricted to index_set is a highest weight crystal
     1131        if index_set is None:
     1132            index_set = self.index_set()
     1133        for i in index_set:
     1134            if self.epsilon(i) <> 0:
     1135                self = self.e(i)
     1136                return self.to_highest_weight(list = list + [i], index_set = index_set)
     1137        return [self, list]
    9771138
    9781139
    9791140class CrystalBacktracker(GenericBacktracker):
    class ClassicalCrystal(Crystal): 
    11411302        """
    11421303        return iter(CrystalBacktracker(self))
    11431304
     1305    def _test_fast_iter(self, **options):
     1306        r"""
     1307        For classical crystals, tests whether the elements of list(self) and Crystal.list(self) are
     1308        the same (the two algorithms are different).
     1309
     1310        EXAMPLES::
     1311       
     1312            sage: C = CrystalOfLetters(['A', 5])
     1313            sage: C._test_fast_iter()
     1314
     1315        """
     1316        tester = self._tester(**options)
     1317        tester.assert_( list(self).sort() == Crystal.list(self).sort() )
    11441318
    11451319    def highest_weight_vectors(self):
    11461320        r"""
  • new file sage/combinat/crystals/direct_sum.py

    diff --git a/sage/combinat/crystals/direct_sum.py b/sage/combinat/crystals/direct_sum.py
    new file mode 100644
    - +  
     1"""
     2Direct Sum of Crystals
     3"""
     4#*****************************************************************************
     5#       Copyright (C) 2010 Anne Schilling <anne at math.ucdavis.edu>
     6#
     7#  Distributed under the terms of the GNU General Public License (GPL)
     8#
     9#    This code is distributed in the hope that it will be useful,
     10#    but WITHOUT ANY WARRANTY; without even the implied warranty of
     11#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     12#    General Public License for more details.
     13#
     14#  The full text of the GPL is available at:
     15#
     16#                  http://www.gnu.org/licenses/
     17#****************************************************************************
     18
     19from crystals import CrystalElement, Crystal
     20from sage.sets.disjoint_union_enumerated_sets import DisjointUnionEnumeratedSets
     21from sage.structure.element_wrapper import ElementWrapper
     22
     23class DirectSumOfCrystals(Crystal, DisjointUnionEnumeratedSets):
     24    r"""
     25    Direct sum of crystals.
     26
     27    Given a list of crystals `B_0, \ldots, B_k` of the same Cartan type,
     28    one can form the direct sum `B_0 \oplus \cdots \oplus B_k`.
     29
     30    INPUT:
     31
     32     - ``crystals``  -- a list of crystals of the same Cartan type
     33     - ``keepkey``   -- a boolean
     34
     35     The option keepkey is by default set to False, assuming that the crystals
     36     are all distinct. In this case the elements of the direct sum are just
     37     represented by the elements in the crystals `B_i`.
     38     If the crystals are not all distinct, one should set the keepkey option to True.
     39     In this case, the elements of the direct sum are represented as tuples
     40    `(i, b)` where `b \in B_i`.
     41
     42    EXAMPLES::
     43
     44        sage: C = CrystalOfLetters(['A',2])
     45        sage: C1 = CrystalOfTableaux(['A',2],shape=[1,1])
     46        sage: B = DirectSumOfCrystals([C,C1])
     47        sage: B.list()
     48        [1, 2, [[2], [3]], [[1], [2]], 3, [[1], [3]]]
     49        sage: [b.f(1) for b in B]
     50        [2, None, None, None, [[2], [3]], None]
     51        sage: B.module_generators
     52        [1, [[1], [2]]]
     53
     54        sage: B = DirectSumOfCrystals([C,C], keepkey=True)
     55        sage: B.list()
     56        [(0, 1), (1, 2), (1, 3), (0, 2), (0, 3), (1, 1)]
     57        sage: B.module_generators
     58        [(0, 1), (1, 1)]
     59        sage: b = B( tuple([0,C(1)]) )
     60        sage: b
     61        (0, 1)
     62        sage: b.weight()
     63        (1, 0, 0)
     64    """
     65    def __init__(self, crystals, **options):
     66        """
     67        TESTS::
     68       
     69            sage: C = CrystalOfLetters(['A',2])
     70            sage: B = DirectSumOfCrystals([C,C], keepkey=True)
     71            sage: B
     72            Direct sum of the crystals Family (The crystal of letters for type ['A', 2], The crystal of letters for type ['A', 2])
     73            sage: B.cartan_type()
     74            ['A', 2]
     75
     76            sage: isinstance(B, DirectSumOfCrystals)
     77            True
     78        """
     79        if options.has_key('keepkey'):
     80            keepkey = options['keepkey']
     81        else:
     82            keepkey = False
     83#        facade = options['facade']
     84        if keepkey:
     85            facade = False
     86        else:
     87            facade = True
     88        DisjointUnionEnumeratedSets.__init__(self, crystals, keepkey = keepkey, facade = facade)
     89        self.rename("Direct sum of the crystals %s"%(crystals,))
     90        self._keepkey = keepkey
     91        self.crystals = crystals
     92        if len(crystals) == 0:
     93            raise ValueError, "The direct sum is empty"
     94        else:
     95            assert(crystal.cartan_type() == crystals[0].cartan_type() for crystal in crystals)
     96            self._cartan_type = crystals[0].cartan_type()
     97        if keepkey:
     98            self.module_generators = [ self(tuple([i,b])) for i in range(len(crystals))
     99                                       for b in crystals[i].module_generators ]
     100        else:
     101            self.module_generators = sum( (list(B.module_generators) for B in crystals), [])
     102
     103
     104class DirectSumOfCrystalsElement(ElementWrapper, CrystalElement):
     105    r"""
     106    A class for elements of direct sums of crystals
     107    """
     108
     109    def e(self, i):
     110        r"""
     111        Returns the action of `e_i` on self.
     112       
     113        EXAMPLES::
     114
     115            sage: C = CrystalOfLetters(['A',2])
     116            sage: B = DirectSumOfCrystals([C,C], keepkey=True)
     117            sage: [[b, b.e(2)] for b in B]
     118            [[(0, 1), None], [(0, 2), None], [(0, 3), (0, 2)], [(1, 1), None], [(1, 2), None], [(1, 3), (1, 2)]]
     119        """
     120        v = self.value
     121        vn = v[1].e(i)
     122        if vn is None:
     123            return None
     124        else:
     125            return self.parent()(tuple([v[0],vn]))
     126
     127    def f(self, i):
     128        r"""
     129        Returns the action of `f_i` on self.
     130       
     131        EXAMPLES::
     132
     133            sage: C = CrystalOfLetters(['A',2])
     134            sage: B = DirectSumOfCrystals([C,C], keepkey=True)
     135            sage: [[b,b.f(1)] for b in B]
     136            [[(0, 1), (0, 2)], [(0, 2), None], [(0, 3), None], [(1, 1), (1, 2)], [(1, 2), None], [(1, 3), None]]
     137        """
     138        v = self.value
     139        vn = v[1].f(i)
     140        if vn is None:
     141            return None
     142        else:
     143            return self.parent()(tuple([v[0],vn]))
     144
     145    def weight(self):
     146        r"""
     147        Returns the weight of self.
     148
     149        EXAMPLES::
     150
     151            sage: C = CrystalOfLetters(['A',2])
     152            sage: B = DirectSumOfCrystals([C,C], keepkey=True)
     153            sage: b = B( tuple([0,C(2)]) )
     154            sage: b
     155            (0, 2)
     156            sage: b.weight()
     157            (0, 1, 0)
     158        """
     159        return self.value[1].weight()
     160
     161    def phi(self, i):
     162        r"""
     163        EXAMPLES::
     164
     165            sage: C = CrystalOfLetters(['A',2])
     166            sage: B = DirectSumOfCrystals([C,C], keepkey=True)
     167            sage: b = B( tuple([0,C(2)]) )
     168            sage: b.phi(2)
     169            1
     170        """
     171        return self.value[1].phi(i)
     172
     173    def epsilon(self, i):
     174        r"""
     175        EXAMPLES::
     176
     177            sage: C = CrystalOfLetters(['A',2])
     178            sage: B = DirectSumOfCrystals([C,C], keepkey=True)
     179            sage: b = B( tuple([0,C(2)]) )
     180            sage: b.epsilon(2)
     181            0
     182        """
     183        return self.value[1].epsilon(i)
     184
     185
     186DirectSumOfCrystals.Element = DirectSumOfCrystalsElement
  • sage/combinat/crystals/fast_crystals.py

    diff --git a/sage/combinat/crystals/fast_crystals.py b/sage/combinat/crystals/fast_crystals.py
    a b class FastCrystal(ClassicalCrystal): 
    6161        sage: C = FastCrystal(['A',2],shape=[4,1])
    6262        sage: C.cardinality()
    6363        24
    64         sage: C.cartan_type()
    65         ['A', 2]
     64        sage: C.cartan_type()
     65        ['A', 2]
    6666        sage: C.check()
    6767        True
    6868        sage: C = FastCrystal(['B',2],shape=[4,1])
  • new file sage/combinat/crystals/highest_weight_crystals.py

    diff --git a/sage/combinat/crystals/highest_weight_crystals.py b/sage/combinat/crystals/highest_weight_crystals.py
    new file mode 100644
    - +  
     1r"""
     2Highest weight crystals
     3"""
     4
     5#*****************************************************************************
     6#       Copyright (C) 2009   Anne Schilling <anne at math.ucdavis.edu>
     7#
     8#  Distributed under the terms of the GNU General Public License (GPL)
     9#
     10#    This code is distributed in the hope that it will be useful,
     11#    but WITHOUT ANY WARRANTY; without even the implied warranty of
     12#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13#    General Public License for more details.
     14#
     15#  The full text of the GPL is available at:
     16#
     17#                  http://www.gnu.org/licenses/
     18#****************************************************************************
     19
     20import operator
     21from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets
     22from sage.combinat.root_system.cartan_type import CartanType
     23from sage.combinat.crystals.crystals import Crystal, ClassicalCrystal, CrystalElement
     24from sage.combinat.crystals.letters import CrystalOfLetters
     25from sage.combinat.crystals.tensor_product import TensorProductOfCrystals, TensorProductOfCrystalsElement, CrystalOfTableaux, CrystalOfWords
     26from sage.combinat.partition import Partition, Partitions
     27
     28
     29def HighestWeightCrystal(dominant_weight):
     30    r"""
     31    Returns an implementation of the highest weight crystal of highest weight `dominant_weight`.
     32
     33    This is currently only implemented for crystals of type `E_6` and `E_7`.
     34
     35    TODO: implement highest weight crystals for classical types `A_n`, `B_n`, `C_n`, `D_n` using tableaux.
     36   
     37    TODO: implement the Littelmann path model or alcove model to obtain a realization
     38    for any highest weight crystal of given type (even affine).
     39
     40    EXAMPLES::
     41
     42        sage: C=CartanType(['E',6])
     43        sage: La=C.root_system().weight_lattice().fundamental_weights()
     44        sage: T = HighestWeightCrystal(La[1])
     45        sage: T.cardinality()
     46        27
     47        sage: T = HighestWeightCrystal(La[6])
     48        sage: T.cardinality()
     49        27
     50        sage: T = HighestWeightCrystal(La[2])
     51        sage: T.cardinality()
     52        78
     53        sage: T = HighestWeightCrystal(La[4])
     54        sage: T.cardinality()
     55        2925
     56        sage: T = HighestWeightCrystal(La[3])
     57        sage: T.cardinality()
     58        351
     59        sage: T = HighestWeightCrystal(La[5])
     60        sage: T.cardinality()
     61        351
     62
     63        sage: C=CartanType(['E',7])
     64        sage: La=C.root_system().weight_lattice().fundamental_weights()
     65        sage: T = HighestWeightCrystal(La[1])
     66        sage: T.cardinality()
     67        133
     68        sage: T = HighestWeightCrystal(La[2])
     69        sage: T.cardinality()
     70        912
     71        sage: T = HighestWeightCrystal(La[3])
     72        sage: T.cardinality()
     73        8645
     74        sage: T = HighestWeightCrystal(La[4])
     75        sage: T.cardinality()
     76        365750
     77        sage: T = HighestWeightCrystal(La[5])
     78        sage: T.cardinality()
     79        27664
     80        sage: T = HighestWeightCrystal(La[6])
     81        sage: T.cardinality()
     82        1539
     83        sage: T = HighestWeightCrystal(La[7])
     84        sage: T.cardinality()
     85        56
     86    """
     87    cartan_type = dominant_weight.parent().cartan_type()
     88    if cartan_type.is_finite() and cartan_type.type() in ['A','B','C','D']:
     89        raise NotImplementedError
     90    elif cartan_type == CartanType(['E',6]):
     91        return FiniteDimensionalHighestWeightCrystal_TypeE6(dominant_weight)
     92    elif cartan_type == CartanType(['E',7]):
     93        return FiniteDimensionalHighestWeightCrystal_TypeE7(dominant_weight)
     94    else:
     95        raise NotImplementedError
     96
     97class FiniteDimensionalHighestWeightCrystal_TypeE(CrystalOfWords, ClassicalCrystal):
     98    """
     99    Commonalities for all finite dimensional type E highest weight crystals
     100
     101    Subclasses should setup an attribute column_crystal in their
     102    __init__ method before calling the __init__ method of this class.
     103    """
     104
     105    def __init__(self, dominant_weight):
     106        """
     107        EXAMPLES::
     108
     109            sage: C=CartanType(['E',6])
     110            sage: La=C.root_system().weight_lattice().fundamental_weights()
     111            sage: T = HighestWeightCrystal(2*La[2])
     112            sage: T.cartan_type()
     113            ['E', 6]
     114            sage: T.module_generators
     115            [[[[2, -1], [1]], [[2, -1], [1]]]]
     116            sage: T.cardinality()
     117            2430
     118            sage: T = HighestWeightCrystal(La[2])
     119            sage: T.cardinality()
     120            78
     121        """
     122        self._cartan_type = dominant_weight.parent().cartan_type()
     123        self._highest_weight = dominant_weight
     124        assert dominant_weight.is_dominant()
     125        self.rename("Finite dimensional highest weight crystal of type %s and highest weight %s"%(self._cartan_type, dominant_weight))
     126        super(FiniteDimensionalHighestWeightCrystal_TypeE, self).__init__(category = FiniteEnumeratedSets())
     127        self.module_generators = [self.module_generator()]
     128
     129
     130    def module_generator(self):
     131        """
     132        This yields the module generator (or highest weight element) of the classical
     133        crystal of given dominant weight in self.
     134
     135        EXAMPLES::
     136
     137            sage: C=CartanType(['E',6])
     138            sage: La=C.root_system().weight_lattice().fundamental_weights()
     139            sage: T = HighestWeightCrystal(La[2])
     140            sage: T.module_generator()
     141            [[[2, -1], [1]]]
     142            sage: T = HighestWeightCrystal(0*La[2])
     143            sage: T.module_generator()
     144            []
     145
     146            sage: C=CartanType(['E',7])
     147            sage: La=C.root_system().weight_lattice().fundamental_weights()
     148            sage: T = HighestWeightCrystal(La[1])
     149            sage: T.module_generator()
     150            [[[-7, 1], [7]]]
     151        """
     152        dominant_weight = self._highest_weight
     153        tensor = sum(( [self.column_crystal[i]]*dominant_weight.coefficient(i) for i in dominant_weight.support()), [])
     154        return self(*[B.module_generators[0] for B in tensor])
     155
     156class FiniteDimensionalHighestWeightCrystal_TypeE6(FiniteDimensionalHighestWeightCrystal_TypeE):
     157    r"""
     158    Class of finite dimensional highest weight crystals of type `E_6`.
     159
     160    EXAMPLES::
     161
     162        sage: C=CartanType(['E',6])
     163        sage: La=C.root_system().weight_lattice().fundamental_weights()
     164        sage: T = HighestWeightCrystal(La[2]); T
     165        Finite dimensional highest weight crystal of type ['E', 6] and highest weight Lambda[2]
     166        sage: B2 = T.column_crystal[2]
     167        sage: B2
     168        The tensor product of the crystals (The crystal of letters for type ['E', 6] (dual), The crystal of letters for type ['E', 6])
     169        sage: t = T(B2([]))
     170        sage: t
     171        [[[]]]
     172        sage: TestSuite(t).run()
     173        sage: t = T(B2([[-1],[-1,3]]))
     174        sage: t
     175        [[[[-1], [-1, 3]]]]
     176        sage: TestSuite(t).run()
     177    """
     178
     179    def __init__(self, dominant_weight):
     180        """
     181        EXAMPLES::
     182
     183            sage: C=CartanType(['E',6])
     184            sage: La=C.root_system().weight_lattice().fundamental_weights()
     185            sage: p2=2*La[2]
     186            sage: p1=La[2]
     187            sage: p0=0*La[2]
     188            sage: T = HighestWeightCrystal(0*La[2])
     189            sage: T.cardinality()
     190            1
     191            sage: T = HighestWeightCrystal(La[2])
     192            sage: T.cardinality()
     193            78
     194            sage: T = HighestWeightCrystal(2*La[2])
     195            sage: T.cardinality()
     196            2430
     197        """
     198        B1 = CrystalOfLetters(['E',6])
     199        B6 = CrystalOfLetters(['E',6], dual = True)
     200        self.column_crystal = {1 : B1, 6 : B6,
     201                               4 : TensorProductOfCrystals(B1,B1,B1,generators=[[B1([-3,4]),B1([-1,3]),B1([1])]]),
     202                               3 : TensorProductOfCrystals(B1,B1,generators=[[B1([-1,3]),B1([1])]]),
     203                               5 : TensorProductOfCrystals(B6,B6,generators=[[B6([5,-6]),B6([6])]]),
     204                               2 : TensorProductOfCrystals(B6,B1,generators=[[B6([2,-1]),B1([1])]])}
     205        FiniteDimensionalHighestWeightCrystal_TypeE.__init__(self, dominant_weight)
     206
     207
     208class FiniteDimensionalHighestWeightCrystal_TypeE7(FiniteDimensionalHighestWeightCrystal_TypeE):
     209    r"""
     210    Class of finite dimensional highest weight crystals of type `E_7`.
     211
     212    EXAMPLES::
     213
     214        sage: C=CartanType(['E',7])
     215        sage: La=C.root_system().weight_lattice().fundamental_weights()
     216        sage: T = HighestWeightCrystal(La[1])
     217        sage: T.cardinality()
     218        133
     219        sage: B2 = T.column_crystal[2]
     220        sage: B2
     221        The tensor product of the crystals (The crystal of letters for type ['E', 7], The crystal of letters for type ['E', 7], The crystal of letters for type ['E', 7])
     222        sage: t = T(B2([]))
     223        sage: t
     224        [[[]]]
     225        sage: TestSuite(t).run()
     226    """
     227
     228    def __init__(self, dominant_weight):
     229        """
     230        EXAMPLES::
     231
     232            sage: C=CartanType(['E',7])
     233            sage: La=C.root_system().weight_lattice().fundamental_weights()
     234            sage: T = HighestWeightCrystal(0*La[1])
     235            sage: T.cardinality()
     236            1
     237            sage: T = HighestWeightCrystal(La[1])
     238            sage: T.cardinality()
     239            133
     240            sage: T = HighestWeightCrystal(2*La[1])
     241            sage: T.cardinality()
     242            7371
     243        """
     244        B = CrystalOfLetters(['E',7])
     245        self.column_crystal = {7 : B,
     246                               1 : TensorProductOfCrystals(B,B,generators=[[B([-7,1]),B([7])]]),
     247                               2 : TensorProductOfCrystals(B,B,B,generators=[[B([-1,2]),B([-7,1]),B([7])]]),
     248                               3 : TensorProductOfCrystals(B,B,B,B,generators=[[B([-2,3]),B([-1,2]),B([-7,1]),B([7])]]),
     249                               4 : TensorProductOfCrystals(B,B,B,B,generators=[[B([-5,4]),B([-6,5]),B([-7,6]),B([7])]]),
     250                               5 : TensorProductOfCrystals(B,B,B,generators=[[B([-6,5]),B([-7,6]),B([7])]]),
     251                               6 : TensorProductOfCrystals(B,B,generators=[[B([-7,6]),B([7])]])}
     252        FiniteDimensionalHighestWeightCrystal_TypeE.__init__(self, dominant_weight)
  • sage/combinat/crystals/kirillov_reshetikhin.py

    diff --git a/sage/combinat/crystals/kirillov_reshetikhin.py b/sage/combinat/crystals/kirillov_reshetikhin.py
    a b Affine crystals 
    2020# library is heavily inspired from MuPAD-Combinat.
    2121#****************************************************************************
    2222
     23from sage.misc.cachefunc import cached_method
    2324from sage.combinat.combinat import CombinatorialObject
    2425from sage.rings.integer import Integer
    2526from sage.misc.functional import is_even, is_odd
    26 from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets
    2727from sage.combinat.crystals.affine import AffineCrystal, AffineCrystalFromClassical, AffineCrystalFromClassicalElement
    2828from sage.combinat.crystals.affine import AffineCrystalFromClassicalAndPromotion
     29from sage.combinat.crystals.highest_weight_crystals import HighestWeightCrystal
     30from sage.combinat.crystals.direct_sum import DirectSumOfCrystals
    2931from sage.combinat.root_system.cartan_type import CartanType
    30 from sage.combinat.crystals.tensor_product import CrystalOfTableaux
     32from sage.combinat.crystals.tensor_product import CrystalOfTableaux, TensorProductOfCrystalsElement, TensorProductOfCrystals
    3133from sage.combinat.tableau import Tableau
    3234from sage.combinat.partition import Partition, Partitions
    3335from sage.combinat.integer_vector import IntegerVectors
    def KirillovReshetikhinCrystal(cartan_ty 
    5961    type `D_n(1)`, `B_n(1)`, `A_{2n-1}(2)`", J. Algebra 319 (2008) 2938-2962
    6062    (arXiv:0704.2046 [math.QA])
    6163
     64    B. Jones, A. Schilling,
     65    ""Affine structures and a tableau model for `E_6` crystals",
     66    preprint arXiv:0909.2442 [math.CO]
     67
    6268    Other Kirillov-Reshetikhin crystals are constructed using similarity methods.
    6369    See Section 4 of
    6470
    6571    G. Fourier, M. Okado, A. Schilling,
    66     "Kirillov-Reshetikhin crystals for nonexceptional types"
    67     Advances in Math., to appear (arXiv:0810.5067 [math.RT])
     72    "Kirillov-Reshetikhin crystals for nonexceptional types",
     73    Advances in Mathematics  222 Issue 3 (2009) 1080-1116
     74    (arXiv:0810.5067 [math.RT])
    6875
    6976    INPUT:
    7077
    71         - ``cartan_type`` Affine type and rank
     78        - ``cartan_type`` Affine type and rank
    7279
    73         - ``r`` Label of finite Dynkin diagram
     80        - ``r`` Label of finite Dynkin diagram
    7481
    7582        - ``s`` Positive integer
    7683
    def KirillovReshetikhinCrystal(cartan_ty 
    8087        sage: K.index_set()
    8188        [0, 1, 2, 3]
    8289        sage: K.list()
    83         [[[1], [2]], [[1], [3]], [[2], [3]], [[1], [4]], [[2], [4]], [[3], [4]]]
    84         sage: b=K(rows=[[1],[2]])
    85         sage: b.weight()
    86         -Lambda[0] + Lambda[2]
     90        [[[1], [2]], [[1], [3]], [[2], [3]], [[1], [4]], [[2], [4]], [[3], [4]]]
     91        sage: b=K(rows=[[1],[2]])
     92        sage: b.weight()
     93        -Lambda[0] + Lambda[2]
    8794
    8895        sage: K = KirillovReshetikhinCrystal(['A',3,1], 2,2)
    8996        sage: K.automorphism(K.module_generators[0])
    def KirillovReshetikhinCrystal(cartan_ty 
    105112        0
    106113        sage: K.module_generators[0].epsilon(2)
    107114        0
    108         sage: b = K(rows=[[1,2],[2,3]])
    109         sage: b
    110         [[1, 2], [2, 3]]
    111         sage: b.f(2)
    112         [[1, 2], [3, 3]]
     115        sage: b = K(rows=[[1,2],[2,3]])
     116        sage: b
     117        [[1, 2], [2, 3]]
     118        sage: b.f(2)
     119        [[1, 2], [3, 3]]
    113120
    114         sage: K = KirillovReshetikhinCrystal(['D',4,1], 2, 1)
    115         sage: K.cartan_type()
    116         ['D', 4, 1]
    117         sage: type(K.module_generators[0])
     121        sage: K = KirillovReshetikhinCrystal(['D',4,1], 2, 1)
     122        sage: K.cartan_type()
     123        ['D', 4, 1]
     124        sage: type(K.module_generators[0])
    118125        <class 'sage.combinat.crystals.affine.KR_type_vertical_with_category.element_class'>
    119126    """
    120127    ct = CartanType(cartan_type)
    121128    assert ct.is_affine()
    122129    if ct.is_untwisted_affine():
    123         if ct.type() == 'A':
    124             return KR_type_A(ct, r, s)
    125         elif ct.type() == 'D' and r<ct.rank()-2:
    126             return KR_type_vertical(ct, r, s)
    127         elif ct.type() == 'B' and r<ct.rank()-1:
    128             return KR_type_vertical(ct, r, s)
    129         elif ct.type() == 'C' and r<ct.rank()-1:
    130             return KR_type_C(ct, r, s)
    131         else:
    132             raise NotImplementedError
     130        if ct.type() == 'A':
     131            return KR_type_A(ct, r, s)
     132        elif ct.type() == 'D' and r<ct.rank()-2:
     133            return KR_type_vertical(ct, r, s)
     134        elif ct.type() == 'B' and r<ct.rank()-1:
     135            return KR_type_vertical(ct, r, s)
     136        elif ct.type() == 'C' and r<ct.rank()-1:
     137            return KR_type_C(ct, r, s)
     138        elif ct == CartanType(['E',6,1]) and r in [1,6,2]:
     139            return KR_type_E6(ct, r, s)
     140        else:
     141            raise NotImplementedError
    133142    else:
    134         if ct.dual().type() == 'B':
    135             return KR_type_vertical(ct, r, s)
    136         elif ct.type() == 'BC':
    137             return KR_type_box(ct, r, s)
    138         elif ct.dual().type() == 'C' and r<ct.rank()-1:
    139             return KR_type_box(ct, r, s)
    140         else:
    141             raise NotImplementedError
     143        if ct.dual().type() == 'B':
     144            return KR_type_vertical(ct, r, s)
     145        elif ct.type() == 'BC':
     146            return KR_type_box(ct, r, s)
     147        elif ct.dual().type() == 'C' and r<ct.rank()-1:
     148            return KR_type_box(ct, r, s)
     149        else:
     150            raise NotImplementedError
    142151
    143152
    144153class KirillovReshetikhinGenericCrystal(AffineCrystal):
    class KirillovReshetikhinGenericCrystal( 
    148157    Input is a Dynkin node `r`, a positive integer `s`, and a Cartan type `cartan_type`.
    149158    """
    150159    def __init__(self, cartan_type, r, s):
    151         r"""
    152         Initializes a generic Kirillov-Reshetikhin crystal.
     160        r"""
     161        Initializes a generic Kirillov-Reshetikhin crystal.
    153162
    154         TESTS::
     163        TESTS::
    155164
    156             sage: K = sage.combinat.crystals.kirillov_reshetikhin.KirillovReshetikhinGenericCrystal(CartanType(['A',2,1]), 1, 1)
    157             sage: K
    158             Kirillov-Reshetikhin crystal of type ['A', 2, 1] with (r,s)=(1,1)
    159             sage: K.r()
    160             1
    161             sage: K.s()
    162             1
    163         """
    164         self._cartan_type = cartan_type
    165         self._r = r
    166         self._s = s
     165            sage: K = sage.combinat.crystals.kirillov_reshetikhin.KirillovReshetikhinGenericCrystal(CartanType(['A',2,1]), 1, 1)
     166            sage: K
     167            Kirillov-Reshetikhin crystal of type ['A', 2, 1] with (r,s)=(1,1)
     168            sage: K.r()
     169            1
     170            sage: K.s()
     171            1
     172        """
     173        self._cartan_type = cartan_type
     174        self._r = r
     175        self._s = s
    167176
    168177    def _repr_(self):
    169178        """
    170179        EXAMPLES::
    171180
    172             sage: sage.combinat.crystals.kirillov_reshetikhin.KirillovReshetikhinGenericCrystal(CartanType(['A',2,1]), 1, 1) # indirect doctest
    173             Kirillov-Reshetikhin crystal of type ['A', 2, 1] with (r,s)=(1,1)
     181            sage: sage.combinat.crystals.kirillov_reshetikhin.KirillovReshetikhinGenericCrystal(CartanType(['A',2,1]), 1, 1) # indirect doctest
     182            Kirillov-Reshetikhin crystal of type ['A', 2, 1] with (r,s)=(1,1)
    174183        """
    175184        return "Kirillov-Reshetikhin crystal of type %s with (r,s)=(%d,%d)" % (self.cartan_type(), self.r(), self.s())
    176185
     186    def module_generator(self):
     187        r"""
     188        Yields the module generator of weight `s \Lambda_r` of a Kirillov-Reshetikhin crystal `B^{r,s}`
     189
     190        EXAMPLES::
     191
     192            sage: K = KirillovReshetikhinCrystal(['C',2,1],1,2)
     193            sage: K.module_generator()
     194            [[1, 1]]
     195            sage: K = KirillovReshetikhinCrystal(['E',6,1],1,1)
     196            sage: K.module_generator()
     197            [[1]]
     198
     199            sage: K = KirillovReshetikhinCrystal(['D',4,1],2,1)
     200            sage: K.module_generator()
     201            [[1], [2]]
     202        """
     203        R = self.weight_lattice_realization()
     204        Lambda = R.fundamental_weights()
     205        r = self.r()
     206        s = self.s()
     207        c = R.null_coroot()[r]
     208        return [ b for b in self.module_generators if b.weight() == s*Lambda[r] - s*c*Lambda[0] ][0]
     209
    177210    def r(self):
    178         """
    179         Returns r of the underlying Kirillov-Reshetikhin crystal `B^{r,s}`
     211        """
     212        Returns r of the underlying Kirillov-Reshetikhin crystal `B^{r,s}`
    180213
    181         EXAMPLE::
     214        EXAMPLE::
    182215
    183             sage: K = KirillovReshetikhinCrystal(['D',4,1], 2, 1)
    184             sage: K.r()
    185             2
     216            sage: K = KirillovReshetikhinCrystal(['D',4,1], 2, 1)
     217            sage: K.r()
     218            2
    186219        """
    187         return self._r
     220        return self._r
    188221   
    189222    def s(self):
    190         """
    191         Returns s of the underlying Kirillov-Reshetikhin crystal `B^{r,s}`
     223        """
     224        Returns s of the underlying Kirillov-Reshetikhin crystal `B^{r,s}`
    192225
    193         EXAMPLE::
     226        EXAMPLE::
    194227
    195             sage: K = KirillovReshetikhinCrystal(['D',4,1], 2, 1)
    196             sage: K.s()
    197             1
     228            sage: K = KirillovReshetikhinCrystal(['D',4,1], 2, 1)
     229            sage: K.s()
     230            1
    198231        """
    199         return self._s
     232        return self._s
    200233
     234    def R_matrix(self, K):
     235        r"""
     236        Returns the combinatorial `R`-matrix from `self \otimes K \to K \otimes self`,
     237        where `K` is a Kirillov-Reshetikhin crystal of the same type as `self`.
     238        The combinatorial `R`-matrix is the affine crystal isomorphism which maps
     239        `u_{self} \otimes u_K` to `u_K \otimes u_{\self}`, where `u_K` is the unique
     240        element in `K = B^{r,s}` of weight `s\Lambda_r - s c \Lambda_0` (see module_generator).
     241
     242        EXAMPLES::
     243
     244            sage: K = KirillovReshetikhinCrystal(['A',2,1],1,1)
     245            sage: L = KirillovReshetikhinCrystal(['A',2,1],1,2)
     246            sage: f = K.R_matrix(L)
     247            sage: [[b,f(b)] for b in TensorProductOfCrystals(K,L)]
     248            [[[[[1]], [[1, 1]]], [[[1, 1]], [[1]]]],
     249            [[[[1]], [[1, 2]]], [[[1, 1]], [[2]]]],
     250            [[[[1]], [[2, 2]]], [[[1, 2]], [[2]]]],
     251            [[[[1]], [[1, 3]]], [[[1, 1]], [[3]]]],
     252            [[[[1]], [[2, 3]]], [[[1, 2]], [[3]]]],
     253            [[[[1]], [[3, 3]]], [[[1, 3]], [[3]]]],
     254            [[[[2]], [[1, 1]]], [[[1, 2]], [[1]]]],
     255            [[[[2]], [[1, 2]]], [[[2, 2]], [[1]]]],
     256            [[[[2]], [[2, 2]]], [[[2, 2]], [[2]]]],
     257            [[[[2]], [[1, 3]]], [[[2, 3]], [[1]]]],
     258            [[[[2]], [[2, 3]]], [[[2, 2]], [[3]]]],
     259            [[[[2]], [[3, 3]]], [[[2, 3]], [[3]]]],
     260            [[[[3]], [[1, 1]]], [[[1, 3]], [[1]]]],
     261            [[[[3]], [[1, 2]]], [[[1, 3]], [[2]]]],
     262            [[[[3]], [[2, 2]]], [[[2, 3]], [[2]]]],
     263            [[[[3]], [[1, 3]]], [[[3, 3]], [[1]]]],
     264            [[[[3]], [[2, 3]]], [[[3, 3]], [[2]]]],
     265            [[[[3]], [[3, 3]]], [[[3, 3]], [[3]]]]]
     266
     267            sage: K = KirillovReshetikhinCrystal(['D',4,1],1,1)
     268            sage: L = KirillovReshetikhinCrystal(['D',4,1],2,1)
     269            sage: f = K.R_matrix(L)
     270            sage: T = TensorProductOfCrystals(K,L)
     271            sage: b = T( K(rows=[[1]]), L(rows=[]) )
     272            sage: f(b)
     273            [[[2], [-2]], [[1]]]
     274        """
     275        T1 = TensorProductOfCrystals(self, K)
     276        T2 = TensorProductOfCrystals(K, self)
     277        gen1 = T1( self.module_generator(), K.module_generator() )
     278        gen2 = T2( K.module_generator(), self.module_generator() )
     279        g = { gen1 : gen2 }
     280        return T1.crystal_morphism(g, acyclic = False)
    201281
    202282class KirillovReshetikhinCrystalFromPromotion(KirillovReshetikhinGenericCrystal, AffineCrystalFromClassicalAndPromotion):
    203283    r"""
    class KirillovReshetikhinCrystalFromProm 
    212292    - dynkin_diagram_automorphism
    213293    """
    214294    def __init__(self, cartan_type, r, s):
    215         r"""
    216         TESTS::
     295        r"""
     296        TESTS::
    217297
    218             sage: K = KirillovReshetikhinCrystal(['B',2,1], 1, 1)
    219             sage: K
    220             Kirillov-Reshetikhin crystal of type ['B', 2, 1] with (r,s)=(1,1)
     298            sage: K = KirillovReshetikhinCrystal(['B',2,1], 1, 1)
     299            sage: K
     300            Kirillov-Reshetikhin crystal of type ['B', 2, 1] with (r,s)=(1,1)
    221301            sage: TestSuite(K).run()
    222         """
    223         KirillovReshetikhinGenericCrystal.__init__(self, cartan_type, r ,s)
    224         AffineCrystalFromClassicalAndPromotion.__init__(self, cartan_type, self.classical_decomposition(),
    225                                                         self.promotion(), self.promotion_inverse(),
    226                                                         self.dynkin_diagram_automorphism(0))
     302        """
     303        KirillovReshetikhinGenericCrystal.__init__(self, cartan_type, r ,s)
     304        AffineCrystalFromClassicalAndPromotion.__init__(self, cartan_type, self.classical_decomposition(),
     305                                                        self.promotion(), self.promotion_inverse(),
     306                                                        self.dynkin_diagram_automorphism(0))
    227307
    228308
    229309class KR_type_A(KirillovReshetikhinCrystalFromPromotion):
    class KR_type_A(KirillovReshetikhinCryst 
    233313    EXAMPLES::
    234314
    235315        sage: K = KirillovReshetikhinCrystal(['A',3,1], 2,2)
    236         sage: b = K(rows=[[1,2],[2,4]])
    237         sage: b.f(0)
    238         [[1, 1], [2, 2]]
     316        sage: b = K(rows=[[1,2],[2,4]])
     317        sage: b.f(0)
     318        [[1, 1], [2, 2]]
    239319    """
    240320
    241321    def classical_decomposition(self):
    242         """
    243         Specifies the classical crystal underlying the KR crystal of type A.
     322        """
     323        Specifies the classical crystal underlying the KR crystal of type A.
    244324
    245         EXAMPLES::
     325        EXAMPLES::
    246326
    247             sage: K = KirillovReshetikhinCrystal(['A',3,1], 2,2)
    248             sage: K.classical_decomposition()
    249             The crystal of tableaux of type ['A', 3] and shape(s) [[2, 2]]
     327            sage: K = KirillovReshetikhinCrystal(['A',3,1], 2,2)
     328            sage: K.classical_decomposition()
     329            The crystal of tableaux of type ['A', 3] and shape(s) [[2, 2]]
    250330        """
    251         return CrystalOfTableaux(self.cartan_type().classical(), shape = [self.s() for i in range(1,self.r()+1)])
     331        return CrystalOfTableaux(self.cartan_type().classical(), shape = [self.s() for i in range(1,self.r()+1)])
    252332   
    253333    def promotion(self):
    254         """
    255         Specifies the promotion operator used to construct the affine type A crystal.
    256         For type A this corresponds to the Dynkin diagram automorphism which maps i to i+1 mod n+1,
    257         where n is the rank.
     334        """
     335        Specifies the promotion operator used to construct the affine type A crystal.
     336        For type A this corresponds to the Dynkin diagram automorphism which maps i to i+1 mod n+1,
     337        where n is the rank.
    258338
    259         EXAMPLES:
     339        EXAMPLES:
    260340
    261             sage: K = KirillovReshetikhinCrystal(['A',3,1], 2,2)
    262             sage: b = K.classical_decomposition()(rows=[[1,2],[3,4]])
    263             sage: K.promotion()(b)
    264             [[1, 3], [2, 4]]
     341            sage: K = KirillovReshetikhinCrystal(['A',3,1], 2,2)
     342            sage: b = K.classical_decomposition()(rows=[[1,2],[3,4]])
     343            sage: K.promotion()(b)
     344            [[1, 3], [2, 4]]
    265345        """
    266         return lambda x : self.classical_crystal(x.to_tableau().promotion(self._cartan_type[1]))
     346        return lambda x : self.classical_crystal(x.to_tableau().promotion(self._cartan_type[1]))
    267347   
    268348    def promotion_inverse(self):
    269         """
    270         Specifies the inverse promotion operator used to construct the affine type A crystal.
    271         For type A this corresponds to the Dynkin diagram automorphism which maps i to i-1 mod n+1,
    272         where n is the rank.
     349        """
     350        Specifies the inverse promotion operator used to construct the affine type A crystal.
     351        For type A this corresponds to the Dynkin diagram automorphism which maps i to i-1 mod n+1,
     352        where n is the rank.
    273353
    274         EXAMPLES:
     354        EXAMPLES:
    275355
    276             sage: K = KirillovReshetikhinCrystal(['A',3,1], 2,2)
    277             sage: b = K.classical_decomposition()(rows=[[1,3],[2,4]])
    278             sage: K.promotion_inverse()(b)
    279             [[1, 2], [3, 4]]
    280             sage: b = K.classical_decomposition()(rows=[[1,2],[3,3]])
    281             sage: K.promotion_inverse()(K.promotion()(b))
    282             [[1, 2], [3, 3]]
     356            sage: K = KirillovReshetikhinCrystal(['A',3,1], 2,2)
     357            sage: b = K.classical_decomposition()(rows=[[1,3],[2,4]])
     358            sage: K.promotion_inverse()(b)
     359            [[1, 2], [3, 4]]
     360            sage: b = K.classical_decomposition()(rows=[[1,2],[3,3]])
     361            sage: K.promotion_inverse()(K.promotion()(b))
     362            [[1, 2], [3, 3]]
    283363        """
    284         return lambda x : self.classical_crystal(x.to_tableau().promotion_inverse(self._cartan_type[1]))
     364        return lambda x : self.classical_crystal(x.to_tableau().promotion_inverse(self._cartan_type[1]))
    285365
    286366    def dynkin_diagram_automorphism(self, i):
    287         """
    288         Specifies the Dynkin diagram automorphism underlying the promotion action on the crystal
    289         elements. The automorphism needs to map node 0 to some other Dynkin node.
     367        """
     368        Specifies the Dynkin diagram automorphism underlying the promotion action on the crystal
     369        elements. The automorphism needs to map node 0 to some other Dynkin node.
    290370
    291         For type A we use the Dynkin diagram automorphism which maps i to i+1 mod n+1, where n is the rank.
     371        For type A we use the Dynkin diagram automorphism which maps i to i+1 mod n+1, where n is the rank.
    292372
    293         EXAMPLES::
    294        
    295             sage: K = KirillovReshetikhinCrystal(['A',3,1], 2,2)
    296             sage: K.dynkin_diagram_automorphism(0)
    297             1
    298             sage: K.dynkin_diagram_automorphism(3)
    299             0
     373        EXAMPLES::
     374       
     375            sage: K = KirillovReshetikhinCrystal(['A',3,1], 2,2)
     376            sage: K.dynkin_diagram_automorphism(0)
     377            1
     378            sage: K.dynkin_diagram_automorphism(3)
     379            0
    300380        """
    301         aut = range(1,self.cartan_type().rank())+[0]
    302         return aut[i]
     381        aut = range(1,self.cartan_type().rank())+[0]
     382        return aut[i]
    303383
    304384class KR_type_vertical(KirillovReshetikhinCrystalFromPromotion):
    305385    r"""
    class KR_type_vertical(KirillovReshetikh 
    309389    EXAMPLES::
    310390
    311391        sage: K = KirillovReshetikhinCrystal(['D',4,1], 2,2)
    312         sage: b = K(rows=[])
    313         sage: b.f(0)
    314         [[1], [2]]
    315         sage: b.f(0).f(0)
    316         [[1, 1], [2, 2]]
    317         sage: b.e(0)
    318         [[-2], [-1]]
    319         sage: b.e(0).e(0)
    320         [[-2, -2], [-1, -1]]
     392        sage: b = K(rows=[])
     393        sage: b.f(0)
     394        [[1], [2]]
     395        sage: b.f(0).f(0)
     396        [[1, 1], [2, 2]]
     397        sage: b.e(0)
     398        [[-2], [-1]]
     399        sage: b.e(0).e(0)
     400        [[-2, -2], [-1, -1]]
    321401
    322         sage: K = KirillovReshetikhinCrystal(['B',3,1], 1,1)
    323         sage: [[b,b.f(0)] for b in K]
    324         [[[[1]], None], [[[2]], None], [[[3]], None], [[[0]], None], [[[-3]], None], [[[-2]], [[1]]], [[[-1]], [[2]]]]
     402        sage: K = KirillovReshetikhinCrystal(['B',3,1], 1,1)
     403        sage: [[b,b.f(0)] for b in K]
     404        [[[[1]], None], [[[2]], None], [[[3]], None], [[[0]], None], [[[-3]], None], [[[-2]], [[1]]], [[[-1]], [[2]]]]
    325405
    326         sage: K = KirillovReshetikhinCrystal(['A',5,2], 1,1)
    327         sage: [[b,b.f(0)] for b in K]
    328         [[[[1]], None], [[[2]], None], [[[3]], None], [[[-3]], None], [[[-2]], [[1]]], [[[-1]], [[2]]]]
     406        sage: K = KirillovReshetikhinCrystal(['A',5,2], 1,1)
     407        sage: [[b,b.f(0)] for b in K]
     408        [[[[1]], None], [[[2]], None], [[[3]], None], [[[-3]], None], [[[-2]], [[1]]], [[[-1]], [[2]]]]
    329409    """
    330410 
    331411    def classical_decomposition(self):
    332         r"""
    333         Specifies the classical crystal underlying the Kirillov-Reshetikhin crystal of type `D_n^{(1)}`,
    334         `B_n^{(1)}`, and `A_{2n-1}^{(2)}`.
    335         It is given by `B^{r,s} \cong \oplus_\Lambda B(\Lambda)` where `\Lambda` are weights obtained from
    336         a rectangle of width s and height r by removing verticle dominoes. Here we identify the fundamental
    337         weight `\Lambda_i` with a column of height `i`.
     412        r"""
     413        Specifies the classical crystal underlying the Kirillov-Reshetikhin crystal of type `D_n^{(1)}`,
     414        `B_n^{(1)}`, and `A_{2n-1}^{(2)}`.
     415        It is given by `B^{r,s} \cong \oplus_\Lambda B(\Lambda)` where `\Lambda` are weights obtained from
     416        a rectangle of width s and height r by removing verticle dominoes. Here we identify the fundamental
     417        weight `\Lambda_i` with a column of height `i`.
    338418
    339         EXAMPLES::
     419        EXAMPLES::
    340420
    341             sage: K = KirillovReshetikhinCrystal(['D',4,1], 2,2)
    342             sage: K.classical_decomposition()
    343             The crystal of tableaux of type ['D', 4] and shape(s) [[], [1, 1], [2, 2]]
     421            sage: K = KirillovReshetikhinCrystal(['D',4,1], 2,2)
     422            sage: K.classical_decomposition()
     423            The crystal of tableaux of type ['D', 4] and shape(s) [[], [1, 1], [2, 2]]
    344424        """
    345         return CrystalOfTableaux(self.cartan_type().classical(),
    346                                 shapes = vertical_dominoes_removed(self.r(),self.s()))
     425        return CrystalOfTableaux(self.cartan_type().classical(),
     426                                shapes = vertical_dominoes_removed(self.r(),self.s()))
    347427   
    348428    def promotion(self):
    349         """
    350         Specifies the promotion operator used to construct the affine type `D_n^{(1)}` etc. crystal.
    351         This corresponds to the Dynkin diagram automorphism which interchanges nodes 0 and 1,
    352         and leaves all other nodes unchanged. On the level of crystals it is constructed using
    353         `\pm` diagrams.
     429        """
     430        Specifies the promotion operator used to construct the affine type `D_n^{(1)}` etc. crystal.
     431        This corresponds to the Dynkin diagram automorphism which interchanges nodes 0 and 1,
     432        and leaves all other nodes unchanged. On the level of crystals it is constructed using
     433        `\pm` diagrams.
    354434
    355         EXAMPLES:
     435        EXAMPLES:
    356436
    357             sage: K = KirillovReshetikhinCrystal(['D',4,1], 2,2)
    358             sage: promotion = K.promotion()
    359             sage: b = K.classical_decomposition()(rows=[])
    360             sage: promotion(b)
    361             [[1, 2], [-2, -1]]
    362             sage: b = K.classical_decomposition()(rows=[[1,3],[2,-1]])
    363             sage: promotion(b)
    364             [[1, 3], [2, -1]]
    365             sage: b = K.classical_decomposition()(rows=[[1],[-3]])
    366             sage: promotion(b)
    367             [[2, -3], [-2, -1]]
     437            sage: K = KirillovReshetikhinCrystal(['D',4,1], 2,2)
     438            sage: promotion = K.promotion()
     439            sage: b = K.classical_decomposition()(rows=[])
     440            sage: promotion(b)
     441            [[1, 2], [-2, -1]]
     442            sage: b = K.classical_decomposition()(rows=[[1,3],[2,-1]])
     443            sage: promotion(b)
     444            [[1, 3], [2, -1]]
     445            sage: b = K.classical_decomposition()(rows=[[1],[-3]])
     446            sage: promotion(b)
     447            [[2, -3], [-2, -1]]
    368448        """
    369         T = self.classical_decomposition()
    370         ind = T.index_set()
    371         ind.remove(1)
    372         return T.crystal_morphism( self.promotion_on_highest_weight_vectors(), index_set = ind)
     449        T = self.classical_decomposition()
     450        ind = T.index_set()
     451        ind.remove(1)
     452        return T.crystal_morphism( self.promotion_on_highest_weight_vectors(), index_set = ind)
    373453   
    374454    promotion_inverse = promotion
    375455   
    376456    def dynkin_diagram_automorphism(self, i):
    377         """
    378         Specifies the Dynkin diagram automorphism underlying the promotion action on the crystal
    379         elements. The automorphism needs to map node 0 to some other Dynkin node.
     457        """
     458        Specifies the Dynkin diagram automorphism underlying the promotion action on the crystal
     459        elements. The automorphism needs to map node 0 to some other Dynkin node.
    380460
    381         Here we use the Dynkin diagram automorphism which interchanges nodes 0 and 1 and leaves
    382         all other nodes unchanged.
     461        Here we use the Dynkin diagram automorphism which interchanges nodes 0 and 1 and leaves
     462        all other nodes unchanged.
    383463
    384         EXAMPLES::
    385        
    386             sage: K = KirillovReshetikhinCrystal(['D',4,1],1,1)
    387             sage: K.dynkin_diagram_automorphism(0)
    388             1
    389             sage: K.dynkin_diagram_automorphism(1)
    390             0
    391             sage: K.dynkin_diagram_automorphism(4)
    392             4
     464        EXAMPLES::
     465       
     466            sage: K = KirillovReshetikhinCrystal(['D',4,1],1,1)
     467            sage: K.dynkin_diagram_automorphism(0)
     468            1
     469            sage: K.dynkin_diagram_automorphism(1)
     470            0
     471            sage: K.dynkin_diagram_automorphism(4)
     472            4
    393473        """
    394         aut = [1,0]+range(2,self.cartan_type().rank())
    395         return aut[i]
     474        aut = [1,0]+range(2,self.cartan_type().rank())
     475        return aut[i]
    396476
    397477    def promotion_on_highest_weight_vectors(self):
    398         """
    399         Calculates promotion on `{2,3,...,n}` highest weight vectors.
     478        """
     479        Calculates promotion on `{2,3,...,n}` highest weight vectors.
    400480
    401         EXAMPLES::
     481        EXAMPLES::
    402482
    403             sage: K = KirillovReshetikhinCrystal(['D',4,1], 2,2)
    404             sage: T = K.classical_decomposition()
    405             sage: hw = [ b for b in T if all(b.epsilon(i)==0 for i in [2,3,4]) ]
    406             sage: [K.promotion_on_highest_weight_vectors()(b) for b in hw]
    407             [[[1, 2], [-2, -1]], [[2, 2], [-2, -1]], [[1, 2], [3, -1]], [[2], [-2]],
    408             [[1, 2], [2, -2]], [[2, 2], [-1, -1]], [[2, 2], [3, -1]], [[2, 2], [3, 3]],
    409             [], [[1], [2]], [[1, 1], [2, 2]], [[2], [-1]], [[1, 2], [2, -1]], [[2], [3]],
    410             [[1, 2], [2, 3]]]
    411         """
    412         return lambda b: self.from_pm_diagram_to_highest_weight_vector(self.from_highest_weight_vector_to_pm_diagram(b).sigma())
     483            sage: K = KirillovReshetikhinCrystal(['D',4,1], 2,2)
     484            sage: T = K.classical_decomposition()
     485            sage: hw = [ b for b in T if all(b.epsilon(i)==0 for i in [2,3,4]) ]
     486            sage: [K.promotion_on_highest_weight_vectors()(b) for b in hw]
     487            [[[1, 2], [-2, -1]], [[2, 2], [-2, -1]], [[1, 2], [3, -1]], [[2], [-2]],
     488            [[1, 2], [2, -2]], [[2, 2], [-1, -1]], [[2, 2], [3, -1]], [[2, 2], [3, 3]],
     489            [], [[1], [2]], [[1, 1], [2, 2]], [[2], [-1]], [[1, 2], [2, -1]], [[2], [3]],
     490            [[1, 2], [2, 3]]]
     491        """
     492        return lambda b: self.from_pm_diagram_to_highest_weight_vector(self.from_highest_weight_vector_to_pm_diagram(b).sigma())
    413493
    414494    def from_highest_weight_vector_to_pm_diagram(self, b):
    415         """
    416         This gives the bijection between an element b in the classical decomposition
    417         of the KR crystal that is `{2,3,..,n}`-highest weight and `\pm` diagrams.
     495        """
     496        This gives the bijection between an element b in the classical decomposition
     497        of the KR crystal that is `{2,3,..,n}`-highest weight and `\pm` diagrams.
    418498
    419         EXAMPLES::
     499        EXAMPLES::
    420500
    421             sage: K = KirillovReshetikhinCrystal(['D',4,1], 2,2)
    422             sage: T = K.classical_decomposition()
    423             sage: b = T(rows=[[2],[-2]])
    424             sage: pm = K.from_highest_weight_vector_to_pm_diagram(b); pm
    425             [[1, 1], [0, 0], [0]]
    426             sage: pm.__repr__(pretty_printing=True)
    427             +
    428             -
    429             sage: b = T(rows=[])
    430             sage: pm=K.from_highest_weight_vector_to_pm_diagram(b); pm
    431             [[0, 2], [0, 0], [0]]
    432             sage: pm.__repr__(pretty_printing=True)
     501            sage: K = KirillovReshetikhinCrystal(['D',4,1], 2,2)
     502            sage: T = K.classical_decomposition()
     503            sage: b = T(rows=[[2],[-2]])
     504            sage: pm = K.from_highest_weight_vector_to_pm_diagram(b); pm
     505            [[1, 1], [0, 0], [0]]
     506            sage: pm.__repr__(pretty_printing=True)
     507            +
     508            -
     509            sage: b = T(rows=[])
     510            sage: pm=K.from_highest_weight_vector_to_pm_diagram(b); pm
     511            [[0, 2], [0, 0], [0]]
     512            sage: pm.__repr__(pretty_printing=True)
    433513
    434             sage: hw = [ b for b in T if all(b.epsilon(i)==0 for i in [2,3,4]) ]
    435             sage: all(K.from_pm_diagram_to_highest_weight_vector(K.from_highest_weight_vector_to_pm_diagram(b)) == b for b in hw)
    436             True
    437         """
    438         n = self.cartan_type().rank()-1
    439         inner = Partition([Integer(b.weight()[i]) for i in range(1,n+1)])
    440         inter = Partition([len([i for i in r if i>0]) for r in b.to_tableau()])
    441         outer = b.to_tableau().shape()
    442         return PMDiagram([self.r(), self.s(), outer, inter, inner], from_shapes=True)
     514            sage: hw = [ b for b in T if all(b.epsilon(i)==0 for i in [2,3,4]) ]
     515            sage: all(K.from_pm_diagram_to_highest_weight_vector(K.from_highest_weight_vector_to_pm_diagram(b)) == b for b in hw)
     516            True
     517        """
     518        n = self.cartan_type().rank()-1
     519        inner = Partition([Integer(b.weight()[i]) for i in range(1,n+1)])
     520        inter = Partition([len([i for i in r if i>0]) for r in b.to_tableau()])
     521        outer = b.to_tableau().shape()
     522        return PMDiagram([self.r(), self.s(), outer, inter, inner], from_shapes=True)
    443523 
    444524    def from_pm_diagram_to_highest_weight_vector(self, pm):
    445         """
    446         This gives the bijection between a `\pm` diagram and an element b in the classical
    447         decomposition of the KR crystal that is {2,3,..,n}-highest weight.
     525        """
     526        This gives the bijection between a `\pm` diagram and an element b in the classical
     527        decomposition of the KR crystal that is {2,3,..,n}-highest weight.
    448528
    449         EXAMPLES::
     529        EXAMPLES::
    450530
    451             sage: K = KirillovReshetikhinCrystal(['D',4,1], 2,2)
    452             sage: pm = sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[1, 1], [0, 0], [0]])
    453             sage: K.from_pm_diagram_to_highest_weight_vector(pm)
    454             [[2], [-2]]
    455         """
    456         u = [b for b in self.classical_decomposition().module_generators if b.to_tableau().shape() == pm.outer_shape()][0]
    457         ct = self.cartan_type()
    458         rank = ct.rank()-1
    459         ct_type = ct.classical().type()
    460         assert ct_type in ['B', 'C', 'D']
    461         list = []
    462         for h in pm.heights_of_addable_plus():
    463             list += range(1,h+1)
    464         for h in pm.heights_of_minus():
    465             if ct_type == 'D':
    466                 list += range(1,rank+1)+[rank-2-k for k in range(rank-1-h)]
    467             elif ct_type == 'B':
    468                 list += range(1,rank+1)+[rank-k for k in range(rank+1-h)]
    469             else:
    470                 list += range(1,rank+1)+[rank-1-k for k in range(rank-h)]
    471         for i in reversed(list):
    472             u = u.f(i)
    473         return u
     531            sage: K = KirillovReshetikhinCrystal(['D',4,1], 2,2)
     532            sage: pm = sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[1, 1], [0, 0], [0]])
     533            sage: K.from_pm_diagram_to_highest_weight_vector(pm)
     534            [[2], [-2]]
     535        """
     536        u = [b for b in self.classical_decomposition().module_generators if b.to_tableau().shape() == pm.outer_shape()][0]
     537        ct = self.cartan_type()
     538        rank = ct.rank()-1
     539        ct_type = ct.classical().type()
     540        assert ct_type in ['B', 'C', 'D']
     541        list = []
     542        for h in pm.heights_of_addable_plus():
     543            list += range(1,h+1)
     544        for h in pm.heights_of_minus():
     545            if ct_type == 'D':
     546                list += range(1,rank+1)+[rank-2-k for k in range(rank-1-h)]
     547            elif ct_type == 'B':
     548                list += range(1,rank+1)+[rank-k for k in range(rank+1-h)]
     549            else:
     550                list += range(1,rank+1)+[rank-1-k for k in range(rank-h)]
     551        for i in reversed(list):
     552            u = u.f(i)
     553        return u
     554
     555class KR_type_E6(KirillovReshetikhinCrystalFromPromotion):
     556    r"""
     557    Class of Kirillov-Reshetikhin crystals of type `E_6^{(1)}` for `r=1,2,6`.
     558
     559    EXAMPLES::
     560
     561        sage: K = KirillovReshetikhinCrystal(['E',6,1],2,1)
     562        sage: K.module_generator().e(0)
     563        []
     564        sage: K.module_generator().e(0).f(0)
     565        [[[2, -1], [1]]]
     566        sage: K = KirillovReshetikhinCrystal(['E',6,1], 1,1)
     567        sage: b = K.module_generator()
     568        sage: b
     569        [[1]]
     570        sage: b.e(0)
     571        [[-2, 1]]
     572        sage: b = [t for t in K if t.epsilon(1) == 1 and t.phi(3) == 1 and t.phi(2) == 0 and t.epsilon(2) == 0][0]
     573        sage: b
     574        [[-1, 3]]
     575        sage: b.e(0)
     576        [[-1, -2, 3]]
     577
     578    The elements of the Kirillov-Reshetikhin crystals can be constructed from a classical
     579    crystal element using :meth:`rectract`.
     580
     581    EXAMPLES::
     582
     583        sage: K = KirillovReshetikhinCrystal(['E',6,1],2,1)
     584        sage: La = K.cartan_type().classical().root_system().weight_lattice().fundamental_weights()
     585        sage: H = HighestWeightCrystal(La[2])
     586        sage: t = H.module_generator()
     587        sage: t
     588        [[[2, -1], [1]]]
     589        sage: type(K.retract(t))
     590        <class 'sage.combinat.crystals.affine.KR_type_E6_with_category.element_class'>
     591        sage: K.retract(t).e(0)
     592        []
     593
     594    TESTS::
     595
     596        sage: K = KirillovReshetikhinCrystal(['E',6,1], 2,1)
     597        sage: La = K.weight_lattice_realization().fundamental_weights()
     598        sage: all(b.weight() == sum( (K.affine_weight(b.lift())[i] * La[i] for i in K.index_set()), 0*La[0]) for b in K)
     599        True
     600    """
     601
     602    def classical_decomposition(self):
     603        """
     604        Specifies the classical crystal underlying the KR crystal of type `E_6^{(1)}`.
     605
     606        EXAMPLES::
     607
     608            sage: K = KirillovReshetikhinCrystal(['E',6,1], 2,2)
     609            sage: K.classical_decomposition()
     610            Direct sum of the crystals Family (Finite dimensional highest weight crystal of type ['E', 6] and highest weight 0, Finite dimensional highest weight crystal of type ['E', 6] and highest weight Lambda[2], Finite dimensional highest weight crystal of type ['E', 6] and highest weight 2*Lambda[2])
     611            sage: K = KirillovReshetikhinCrystal(['E',6,1], 1,2)
     612            sage: K.classical_decomposition()
     613            Direct sum of the crystals Family (Finite dimensional highest weight crystal of type ['E', 6] and highest weight 2*Lambda[1],)
     614        """
     615        La = self.cartan_type().classical().root_system().weight_lattice().fundamental_weights()
     616        if self.r() in [1,6]:
     617            dw = [self.s()*La[self.r()]]
     618        elif self.r() == 2:
     619            dw = sum( ([k*La[2]] for k in range(self.s()+1)), [])
     620        else:
     621            raise ValueError
     622        return DirectSumOfCrystals([HighestWeightCrystal(dominant_weight) for dominant_weight in dw], keepkey = False)
     623
     624    def dynkin_diagram_automorphism(self, i):
     625        r"""
     626        Specifies the Dynkin diagram automorphism underlying the promotion action on the crystal
     627        elements. The automorphism needs to map node 0 to some other Dynkin node.
     628
     629        Here we use the Dynkin diagram automorphism of order 3 which maps node 0 to node 1.
     630
     631        EXAMPLES::
     632       
     633            sage: K = KirillovReshetikhinCrystal(['E',6,1],2,1)
     634            sage: [K.dynkin_diagram_automorphism(i) for i in K.index_set()]
     635            [1, 6, 3, 5, 4, 2, 0]
     636        """
     637        aut = [1,6,3,5,4,2,0]
     638        return aut[i]
     639
     640    def affine_weight(self, b):
     641        r"""
     642        Returns the affine level zero weight corresponding to the element b of the classical
     643        crystal underlying self. For the coefficients to calculate the level, see Kac pg. 48.
     644
     645        EXAMPLES::
     646
     647            sage: K = KirillovReshetikhinCrystal(['E',6,1],2,1)
     648            sage: [K.affine_weight(x.lift()) for x in K if all(x.epsilon(i) == 0 for i in [2,3,4,5])]
     649            [(0, 0, 0, 0, 0, 0, 0),
     650            (-2, 0, 1, 0, 0, 0, 0),
     651            (-1, -1, 0, 0, 0, 1, 0),
     652            (0, 0, 0, 0, 0, 0, 0),
     653            (0, 0, 0, 0, 0, 1, -2),
     654            (0, -1, 1, 0, 0, 0, -1),
     655            (-1, 0, 0, 1, 0, 0, -1),
     656            (-1, -1, 0, 0, 1, 0, -1),
     657            (0, 0, 0, 0, 0, 0, 0),
     658            (0, -2, 0, 1, 0, 0, 0)]
     659        """
     660        simple_roots = self.cartan_type().classical().root_system().ambient_space().simple_roots()
     661        index_set = b.parent().index_set()
     662        weight = [ Integer(b.weight().scalar( simple_roots[i] )) for i in index_set ]
     663        E6_coeffs = [ 1, 2, 2, 3, 2, 1 ]
     664        return tuple( [-sum([ weight[i-1] * E6_coeffs[i-1] for i in index_set ])] + weight )
     665
     666
     667    @cached_method
     668    def hw_auxiliary(self):
     669        r"""
     670        Returns the `{2,3,4,5}` highest weight elements of self.
     671
     672        EXAMPLES::
     673
     674            sage: K = KirillovReshetikhinCrystal(['E',6,1],2,1)
     675            sage: K.hw_auxiliary()
     676            [[], [[[2, -1], [1]]], [[[5, -3], [-1, 3]]], [[[6, -2], [-6, 2]]],
     677            [[[5, -2, -6], [-6, 2]]], [[[-1], [-6, 2]]], [[[3, -1, -6], [1]]],
     678            [[[4, -3, -6], [-1, 3]]], [[[1, -3], [-1, 3]]], [[[-1], [-1, 3]]]]
     679        """
     680        return [x for x in self.classical_decomposition() if all(x.epsilon(i) == 0 for i in [2,3,4,5])]
     681
     682    @cached_method
     683    def highest_weight_dict(self):
     684        r"""
     685        Returns a dictionary between `{1,2,3,4,5}` highest weight elements, and a tuple of affine weights and its classical component.
     686
     687        EXAMPLES::
     688
     689            sage: K = KirillovReshetikhinCrystal(['E',6,1],2,1)
     690            sage: K.highest_weight_dict()
     691            {[[[3, -1, -6], [1]]]: ((-1, 0, 0, 1, 0, 0, -1), 1),
     692            [[[5, -2, -6], [-6, 2]]]: ((0, 0, 0, 0, 0, 1, -2), 1),
     693            [[[2, -1], [1]]]: ((-2, 0, 1, 0, 0, 0, 0), 1),
     694            [[[6, -2], [-6, 2]]]: ((0, 0, 0, 0, 0, 0, 0), 1),
     695            []: ((0, 0, 0, 0, 0, 0, 0), 0)}
     696        """
     697        hw = [x for x in self.hw_auxiliary() if x.epsilon(1) == 0]
     698        dic = dict( ( x, tuple( [self.affine_weight(x), len(x)] ) ) for x in hw )
     699        assert len(hw) == len(dic)
     700        return dic
     701
     702    @cached_method
     703    def highest_weight_dict_inv(self):
     704        r"""
     705        Returns a dictionary between a tuple of affine weights and a classical component, and
     706        `{2,3,4,5,6}` highest weight elements.
     707
     708        EXAMPLES::
     709
     710            sage: K = KirillovReshetikhinCrystal(['E',6,1],2,1)
     711            sage: K.highest_weight_dict_inv()
     712            {((0, 0, 0, 0, 0, 0, 0), 0): [],
     713            ((-1, -1, 0, 0, 0, 1, 0), 1): [[[5, -3], [-1, 3]]],
     714            ((0, 0, 0, 0, 0, 0, 0), 1): [[[1, -3], [-1, 3]]],
     715            ((0, -2, 0, 1, 0, 0, 0), 1): [[[-1], [-1, 3]]],
     716            ((-2, 0, 1, 0, 0, 0, 0), 1): [[[2, -1], [1]]]}
     717        """
     718        hw = [x for x in self.hw_auxiliary() if x.epsilon(6) == 0]
     719        dic = dict( ( tuple( [self.affine_weight(x), len(x)] ), x ) for x in hw )
     720        assert len(hw) == len(dic)
     721        return dic
     722   
     723    def automorphism_on_affine_weight(self, weight):
     724        r"""
     725        Acts with the Dynkin diagram automorphism on affine weights as outputted by the affine_weight method.
     726
     727        EXAMPLES::
     728 
     729            sage: K = KirillovReshetikhinCrystal(['E',6,1],2,1)
     730            sage: [[x[0], K.automorphism_on_affine_weight(x[0])] for x in K.highest_weight_dict().values()]
     731            [[(-1, 0, 0, 1, 0, 0, -1), (-1, -1, 0, 0, 0, 1, 0)],
     732            [(0, 0, 0, 0, 0, 1, -2), (-2, 0, 1, 0, 0, 0, 0)],
     733            [(-2, 0, 1, 0, 0, 0, 0), (0, -2, 0, 1, 0, 0, 0)],
     734            [(0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0, 0, 0, 0)],
     735            [(0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0, 0, 0, 0)]]
     736        """
     737        f = self.dynkin_diagram_automorphism
     738        return tuple( [weight[f(f(i))] for i in self.index_set()] )
     739
     740    def promotion_on_highest_weight_vectors(self):
     741        r"""
     742        Gives a dictionary of the promotion map on `{1,2,3,4,5}` highest weight elements to
     743        `{2,3,4,5,6}` elements in self.
     744
     745        EXAMPLES::
     746
     747            sage: K = KirillovReshetikhinCrystal(['E',6,1],2,1)
     748            sage: dic = K.promotion_on_highest_weight_vectors()
     749            sage: dic
     750            {[[[2, -1], [1]]]: [[[-1], [-1, 3]]],
     751            [[[5, -2, -6], [-6, 2]]]: [[[2, -1], [1]]],
     752            [[[3, -1, -6], [1]]]: [[[5, -3], [-1, 3]]],
     753            [[[6, -2], [-6, 2]]]: [], []: [[[1, -3], [-1, 3]]]}
     754        """
     755        dic = self.highest_weight_dict()
     756        dic_inv = self.highest_weight_dict_inv()
     757        dic_weight = {}
     758        for (weight, i) in dic.values():
     759            dic_weight[weight] = dic_weight.get(weight, []) + [i]
     760        map_index = lambda (i, list) : max(list)+min(list)-i
     761        map_element = lambda x : tuple([self.automorphism_on_affine_weight(dic[x][0]), map_index((dic[x][1],dic_weight[dic[x][0]]))])
     762        return dict( (x, dic_inv[map_element(x)]) for x in dic.keys() )
     763
     764    def promotion_on_highest_weight_vectors_function(self):
     765        return lambda x : self.promotion_on_highest_weight_vectors()[x]
     766
     767    def promotion(self):
     768        """
     769        Specifies the promotion operator used to construct the affine type `E_6^{(1)}` crystal.
     770
     771        EXAMPLES:
     772
     773            sage: K = KirillovReshetikhinCrystal(['E',6,1], 2,1)
     774            sage: promotion = K.promotion()
     775            sage: all(promotion(promotion(promotion(b))) == b for b in K.classical_decomposition())
     776            True
     777            sage: K = KirillovReshetikhinCrystal(['E',6,1],1,1)
     778            sage: promotion = K.promotion()
     779            sage: all(promotion(promotion(promotion(b))) == b for b in K.classical_decomposition())
     780            True
     781        """
     782        T = self.classical_decomposition()
     783        ind = [1,2,3,4,5]
     784        return T.crystal_morphism( self.promotion_on_highest_weight_vectors_function(), automorphism = lambda i : self.dynkin_diagram_automorphism(i), index_set = ind)
     785   
     786    def promotion_inverse(self):
     787        r"""
     788        Returns the inverse promotion. Since promotion is of order 3, the inverse promotion is the same
     789        as promotion applied twice.
     790
     791        EXAMPLES::
     792       
     793            sage: K = KirillovReshetikhinCrystal(['E',6,1], 2,1)
     794            sage: p = K.promotion()
     795            sage: p_inv = K.promotion_inverse()
     796            sage: all(p_inv(p(b)) == b for b in K.classical_decomposition())
     797            True
     798        """
     799        p = self.promotion()
     800        return lambda x : p(p(x))
    474801
    475802
    476803class KR_type_C(KirillovReshetikhinGenericCrystal, AffineCrystalFromClassical):
    class KR_type_C(KirillovReshetikhinGener 
    480807    EXAMPLES::
    481808
    482809        sage: K = KirillovReshetikhinCrystal(['C',2,1], 1,2)
    483         sage: K
    484         Kirillov-Reshetikhin crystal of type ['C', 2, 1] with (r,s)=(1,2)
    485         sage: b = K(rows=[])
    486         sage: b.f(0)
    487         [[1, 1]]
    488         sage: b.e(0)
    489         [[-1, -1]]
     810        sage: K
     811        Kirillov-Reshetikhin crystal of type ['C', 2, 1] with (r,s)=(1,2)
     812        sage: b = K(rows=[])
     813        sage: b.f(0)
     814        [[1, 1]]
     815        sage: b.e(0)
     816        [[-1, -1]]
    490817    """
    491818    def __init__(self, cartan_type, r, s):
    492         r"""
    493         Initializes a Kirillov-Reshetikhin crystal of type `C_n^{(1)}`.
     819        r"""
     820        Initializes a Kirillov-Reshetikhin crystal of type `C_n^{(1)}`.
    494821
    495         TESTS::
     822        TESTS::
    496823
    497             sage: K = sage.combinat.crystals.kirillov_reshetikhin.KR_type_C(['C',2,1], 1, 1)
    498             sage: K
    499             Kirillov-Reshetikhin crystal of type ['C', 2, 1] with (r,s)=(1,1)
     824            sage: K = sage.combinat.crystals.kirillov_reshetikhin.KR_type_C(['C',2,1], 1, 1)
     825            sage: K
     826            Kirillov-Reshetikhin crystal of type ['C', 2, 1] with (r,s)=(1,1)
    500827            sage: TestSuite(K).run()
    501         """
    502         KirillovReshetikhinGenericCrystal.__init__(self, cartan_type, r ,s)
    503         AffineCrystalFromClassical.__init__(self, cartan_type, self.classical_decomposition())
     828        """
     829        KirillovReshetikhinGenericCrystal.__init__(self, cartan_type, r ,s)
     830        AffineCrystalFromClassical.__init__(self, cartan_type, self.classical_decomposition())
    504831
    505832    def classical_decomposition(self):
    506         """
    507         Specifies the classical crystal underlying the Kirillov-Reshetikhin crystal of type `C_n^{(1)}`.
    508         It is given by `B^{r,s} \cong \oplus_\Lambda B(\Lambda)` where `\Lambda` are weights obtained from
    509         a rectangle of width s and height r by removing horizontal dominoes. Here we identify the fundamental
    510         weight `\Lambda_i` with a column of height `i`.
     833        """
     834        Specifies the classical crystal underlying the Kirillov-Reshetikhin crystal of type `C_n^{(1)}`.
     835        It is given by `B^{r,s} \cong \oplus_\Lambda B(\Lambda)` where `\Lambda` are weights obtained from
     836        a rectangle of width s and height r by removing horizontal dominoes. Here we identify the fundamental
     837        weight `\Lambda_i` with a column of height `i`.
    511838
    512         EXAMPLES::
     839        EXAMPLES::
    513840
    514             sage: K = KirillovReshetikhinCrystal(['C',3,1], 2,2)
    515             sage: K.classical_decomposition()
    516             The crystal of tableaux of type ['C', 3] and shape(s) [[], [2], [2, 2]]
     841            sage: K = KirillovReshetikhinCrystal(['C',3,1], 2,2)
     842            sage: K.classical_decomposition()
     843            The crystal of tableaux of type ['C', 3] and shape(s) [[], [2], [2, 2]]
    517844        """
    518         return CrystalOfTableaux(self.cartan_type().classical(),
    519                                 shapes = horizontal_dominoes_removed(self.r(),self.s()))
     845        return CrystalOfTableaux(self.cartan_type().classical(),
     846                                shapes = horizontal_dominoes_removed(self.r(),self.s()))
    520847
    521848    def ambient_crystal(self):
    522         r"""
    523         Returns the ambient crystal `'B^{r,s}` of type `A_{2n+1}^{(2)}` associated to the Kirillov-Reshetikhin
    524         crystal of type `C_n^{(1)}`. This ambient crystal is used to construct the zero arrows.
     849        r"""
     850        Returns the ambient crystal `'B^{r,s}` of type `A_{2n+1}^{(2)}` associated to the Kirillov-Reshetikhin
     851        crystal of type `C_n^{(1)}`. This ambient crystal is used to construct the zero arrows.
    525852
    526         EXAMPLES::
     853        EXAMPLES::
    527854
    528             sage: K = KirillovReshetikhinCrystal(['C',3,1], 2,3)
    529             sage: K.ambient_crystal()
    530             Kirillov-Reshetikhin crystal of type ['B', 4, 1]^* with (r,s)=(2,3)
     855            sage: K = KirillovReshetikhinCrystal(['C',3,1], 2,3)
     856            sage: K.ambient_crystal()
     857            Kirillov-Reshetikhin crystal of type ['B', 4, 1]^* with (r,s)=(2,3)
    531858        """
    532         return KirillovReshetikhinCrystal(['A',2*self.cartan_type().classical().rank()+1,2], self.r(), self.s())
     859        return KirillovReshetikhinCrystal(['A',2*self.cartan_type().classical().rank()+1,2], self.r(), self.s())
    533860
    534861    def ambient_dict_pm_diagrams(self):
    535         r"""
    536         Gives a dictionary of all self-dual `\pm` diagrams for the ambient crystal.
    537         Their key is their inner shape.
     862        r"""
     863        Gives a dictionary of all self-dual `\pm` diagrams for the ambient crystal.
     864        Their key is their inner shape.
    538865
    539         EXAMPLES::
     866        EXAMPLES::
    540867
    541             sage: K = KirillovReshetikhinCrystal(['C',2,1], 1,2)
    542             sage: K.ambient_dict_pm_diagrams()
    543             {[]: [[1, 1], [0]], [2]: [[0, 0], [2]]}
    544             sage: K = KirillovReshetikhinCrystal(['C',3,1], 2,2)
    545             sage: K.ambient_dict_pm_diagrams()
    546             {[2, 2]: [[0, 0], [0, 0], [2]], []: [[1, 1], [0, 0], [0]], [2]: [[0, 0], [1, 1], [0]]}
    547             sage: K = KirillovReshetikhinCrystal(['C',3,1], 2,3)
    548             sage: K.ambient_dict_pm_diagrams()
    549             {[3, 3]: [[0, 0], [0, 0], [3]], [3, 1]: [[0, 0], [1, 1], [1]], [1, 1]: [[1, 1], [0, 0], [1]]}
     868            sage: K = KirillovReshetikhinCrystal(['C',2,1], 1,2)
     869            sage: K.ambient_dict_pm_diagrams()
     870            {[]: [[1, 1], [0]], [2]: [[0, 0], [2]]}
     871            sage: K = KirillovReshetikhinCrystal(['C',3,1], 2,2)
     872            sage: K.ambient_dict_pm_diagrams()
     873            {[2, 2]: [[0, 0], [0, 0], [2]], []: [[1, 1], [0, 0], [0]], [2]: [[0, 0], [1, 1], [0]]}
     874            sage: K = KirillovReshetikhinCrystal(['C',3,1], 2,3)
     875            sage: K.ambient_dict_pm_diagrams()
     876            {[3, 3]: [[0, 0], [0, 0], [3]], [3, 1]: [[0, 0], [1, 1], [1]], [1, 1]: [[1, 1], [0, 0], [1]]}
    550877        """
    551         list = []
    552         s = self.s()
    553         r = self.r()
    554         m = int(s/2)
    555         for i in range(m+1):
    556             for la in IntegerVectors(m-i, min_length=r, max_length=r):
    557                 list.append(PMDiagram([[j,j] for j in la]+[[s-2*m+2*i]]))
    558         return dict( (x.inner_shape(), x) for x in list )
     878        list = []
     879        s = self.s()
     880        r = self.r()
     881        m = int(s/2)
     882        for i in range(m+1):
     883            for la in IntegerVectors(m-i, min_length=r, max_length=r):
     884                list.append(PMDiagram([[j,j] for j in la]+[[s-2*m+2*i]]))
     885        return dict( (x.inner_shape(), x) for x in list )
    559886
    560887    def ambient_highest_weight_dict(self):
    561         r"""
    562         Gives a dictionary of all `{2,...,n+1}`-highest weight vectors in the ambient crystal.
    563         Their key is the inner shape of their corresponding `\pm` diagram, or equivalently, their
    564         `{2,...,n+1}` weight.
     888        r"""
     889        Gives a dictionary of all `{2,...,n+1}`-highest weight vectors in the ambient crystal.
     890        Their key is the inner shape of their corresponding `\pm` diagram, or equivalently, their
     891        `{2,...,n+1}` weight.
    565892
    566         EXAMPLES::
     893        EXAMPLES::
    567894
    568             sage: K = KirillovReshetikhinCrystal(['C',3,1], 2,2)
    569             sage: K.ambient_highest_weight_dict()
    570             {[]: [[2], [-2]], [2, 2]: [[2, 2], [3, 3]], [2]: [[1, 2], [2, -1]]}
     895            sage: K = KirillovReshetikhinCrystal(['C',3,1], 2,2)
     896            sage: K.ambient_highest_weight_dict()
     897            {[]: [[2], [-2]], [2, 2]: [[2, 2], [3, 3]], [2]: [[1, 2], [2, -1]]}
    571898        """
    572         A = self.ambient_dict_pm_diagrams()
    573         ambient = self.ambient_crystal()
    574         return dict( (key, ambient.retract(ambient.from_pm_diagram_to_highest_weight_vector(A[key]))) for key in A )
     899        A = self.ambient_dict_pm_diagrams()
     900        ambient = self.ambient_crystal()
     901        return dict( (key, ambient.retract(ambient.from_pm_diagram_to_highest_weight_vector(A[key]))) for key in A )
    575902
    576903    def highest_weight_dict(self):
    577         r"""
    578         Gives a dictionary of the classical highest weight vectors of self.
    579         Their key is their shape.
     904        r"""
     905        Gives a dictionary of the classical highest weight vectors of self.
     906        Their key is their shape.
    580907
    581         EXAMPLES::
     908        EXAMPLES::
    582909
    583             sage: K = KirillovReshetikhinCrystal(['C',3,1], 2,2)
    584             sage: K.highest_weight_dict()
    585             {[2, 2]: [[1, 1], [2, 2]], []: [], [2]: [[1, 1]]}
    586         """
    587         return dict( (x.lift().to_tableau().shape(),x) for x in self.module_generators )
     910            sage: K = KirillovReshetikhinCrystal(['C',3,1], 2,2)
     911            sage: K.highest_weight_dict()
     912            {[2, 2]: [[1, 1], [2, 2]], []: [], [2]: [[1, 1]]}
     913        """
     914        return dict( (x.lift().to_tableau().shape(),x) for x in self.module_generators )
    588915
    589916    def to_ambient_crystal(self):
    590         r"""
    591         Provides a map from the Kirillov-Reshetikhin crystal of type `C_n^{(1)}` to the
    592         ambient crystal of type `A_{2n+1}^{(2)}`.
     917        r"""
     918        Provides a map from the Kirillov-Reshetikhin crystal of type `C_n^{(1)}` to the
     919        ambient crystal of type `A_{2n+1}^{(2)}`.
    593920
    594         EXAMPLES::
     921        EXAMPLES::
    595922
    596             sage: K = KirillovReshetikhinCrystal(['C',3,1], 2,2)
    597             sage: b=K(rows=[[1,1]])
    598             sage: K.to_ambient_crystal()(b)
    599             [[1, 2], [2, -1]]
    600             sage: b=K(rows=[])
    601             sage: K.to_ambient_crystal()(b)
    602             [[2], [-2]]
    603             sage: K.to_ambient_crystal()(b).parent() # Anne: please check this!!!!
     923            sage: K = KirillovReshetikhinCrystal(['C',3,1], 2,2)
     924            sage: b=K(rows=[[1,1]])
     925            sage: K.to_ambient_crystal()(b)
     926            [[1, 2], [2, -1]]
     927            sage: b=K(rows=[])
     928            sage: K.to_ambient_crystal()(b)
     929            [[2], [-2]]
     930            sage: K.to_ambient_crystal()(b).parent() # Anne: please check this!!!!
    604931            Kirillov-Reshetikhin crystal of type ['B', 4, 1]^* with (r,s)=(2,2)
    605         """
    606         keys = self.highest_weight_dict().keys()
    607         pdict = dict( (self.highest_weight_dict()[key], self.ambient_highest_weight_dict()[key]) for key in keys )
    608         return self.crystal_morphism( pdict, index_set = self.cartan_type().classical().index_set(),
    609                                       automorphism = lambda i : i+1 )
     932        """
     933        keys = self.highest_weight_dict().keys()
     934        pdict = dict( (self.highest_weight_dict()[key], self.ambient_highest_weight_dict()[key]) for key in keys )
     935        return self.crystal_morphism( pdict, index_set = self.cartan_type().classical().index_set(),
     936                                      automorphism = lambda i : i+1 )
    610937
    611938    def from_ambient_crystal(self):
    612         r"""
    613         Provides a map from the ambient crystal of type `A_{2n+1}^{(2)}` to the Kirillov-Reshetikhin crystal of
    614         type `C_n^{(1)}`. Note that this map is only well-defined on elements that are in the image
    615         type `C_n^{(1)}` elements under `to_ambient_crystal`.
     939        r"""
     940        Provides a map from the ambient crystal of type `A_{2n+1}^{(2)}` to the Kirillov-Reshetikhin crystal of
     941        type `C_n^{(1)}`. Note that this map is only well-defined on elements that are in the image
     942        type `C_n^{(1)}` elements under `to_ambient_crystal`.
    616943
    617         EXAMPLES::
     944        EXAMPLES::
    618945
    619             sage: K = KirillovReshetikhinCrystal(['C',3,1], 2,2)
    620             sage: b=K.ambient_crystal()(rows=[[2,2],[3,3]])
    621             sage: K.from_ambient_crystal()(b)
    622             [[1, 1], [2, 2]]
    623         """
    624         keys = self.highest_weight_dict().keys()
    625         pdict_inv = dict( (self.ambient_highest_weight_dict()[key], self.highest_weight_dict()[key]) for key in keys )
    626         return self.crystal_morphism( pdict_inv, index_set = [j+1 for j in self.cartan_type().classical().index_set()],
    627                                       automorphism = lambda i : i-1 )
     946            sage: K = KirillovReshetikhinCrystal(['C',3,1], 2,2)
     947            sage: b=K.ambient_crystal()(rows=[[2,2],[3,3]])
     948            sage: K.from_ambient_crystal()(b)
     949            [[1, 1], [2, 2]]
     950        """
     951        keys = self.highest_weight_dict().keys()
     952        pdict_inv = dict( (self.ambient_highest_weight_dict()[key], self.highest_weight_dict()[key]) for key in keys )
     953        return self.crystal_morphism( pdict_inv, index_set = [j+1 for j in self.cartan_type().classical().index_set()],
     954                                      automorphism = lambda i : i-1 )
    628955
    629956class KR_type_CElement(AffineCrystalFromClassicalElement):
    630957    r"""
    class KR_type_CElement(AffineCrystalFrom 
    633960    EXAMPLES::
    634961
    635962        sage: K=KirillovReshetikhinCrystal(['C',3,1],1,2)
    636         sage: type(K.module_generators[0])
     963        sage: type(K.module_generators[0])
    637964        <class 'sage.combinat.crystals.kirillov_reshetikhin.KR_type_C_with_category.element_class'>
    638965    """
    639966
    640967    def e0(self):
    641         r"""
    642         Gives `e_0` on self by mapping self to the ambient crystal, calculating `e_1 e_0` there and
    643         pulling the element back.
     968        r"""
     969        Gives `e_0` on self by mapping self to the ambient crystal, calculating `e_1 e_0` there and
     970        pulling the element back.
    644971
    645         EXAMPLES::
     972        EXAMPLES::
    646973
    647             sage: K=KirillovReshetikhinCrystal(['C',3,1],1,2)
    648             sage: b = K(rows=[])
    649             sage: b.e(0)
    650             [[-1, -1]]
    651         """
    652         b = self.parent().to_ambient_crystal()(self).e(1)
    653         if b is None:
    654             return None
    655         b = b.e(0)
    656         return self.parent().from_ambient_crystal()(b)
     974            sage: K=KirillovReshetikhinCrystal(['C',3,1],1,2)
     975            sage: b = K(rows=[])
     976            sage: b.e(0)
     977            [[-1, -1]]
     978        """
     979        b = self.parent().to_ambient_crystal()(self).e(1)
     980        if b is None:
     981            return None
     982        b = b.e(0)
     983        return self.parent().from_ambient_crystal()(b)
    657984   
    658985    def f0(self):
    659         r"""
    660         Gives `f_0` on self by mapping self to the ambient crystal, calculating `f_1 f_0` there and
    661         pulling the element back.
     986        r"""
     987        Gives `f_0` on self by mapping self to the ambient crystal, calculating `f_1 f_0` there and
     988        pulling the element back.
    662989
    663         EXAMPLES::
     990        EXAMPLES::
    664991
    665             sage: K=KirillovReshetikhinCrystal(['C',3,1],1,2)
    666             sage: b = K(rows=[])
    667             sage: b.f(0)
    668             [[1, 1]]
    669         """
    670         b = self.parent().to_ambient_crystal()(self).f(1)
    671         if b is None:
    672             return None
    673         b = b.f(0)
    674         return self.parent().from_ambient_crystal()(b)
     992            sage: K=KirillovReshetikhinCrystal(['C',3,1],1,2)
     993            sage: b = K(rows=[])
     994            sage: b.f(0)
     995            [[1, 1]]
     996        """
     997        b = self.parent().to_ambient_crystal()(self).f(1)
     998        if b is None:
     999            return None
     1000        b = b.f(0)
     1001        return self.parent().from_ambient_crystal()(b)
    6751002
    6761003    def epsilon0(self):
    677         r"""
    678         Calculates `\epsilon_0` of self by mapping the element to the ambient crystal
    679         and calculating `\epsilon_1` there.
     1004        r"""
     1005        Calculates `\epsilon_0` of self by mapping the element to the ambient crystal
     1006        and calculating `\epsilon_1` there.
    6801007
    681         EXAMPLES::
     1008        EXAMPLES::
    6821009
    683             sage: K = KirillovReshetikhinCrystal(['C',2,1], 1,2)
    684             sage: b=K(rows=[[1,1]])
    685             sage: b.epsilon(0)
    686             2
     1010            sage: K = KirillovReshetikhinCrystal(['C',2,1], 1,2)
     1011            sage: b=K(rows=[[1,1]])
     1012            sage: b.epsilon(0)
     1013            2
    6871014        """
    688         b = self.parent().to_ambient_crystal()(self)
    689         return b.epsilon(1)
     1015        b = self.parent().to_ambient_crystal()(self)
     1016        return b.epsilon(1)
    6901017
    6911018    def phi0(self):
    692         r"""
    693         Calculates `\phi_0` of self by mapping the element to the ambient crystal
    694         and calculating `\phi_1` there.
     1019        r"""
     1020        Calculates `\phi_0` of self by mapping the element to the ambient crystal
     1021        and calculating `\phi_1` there.
    6951022
    696         EXAMPLES::
     1023        EXAMPLES::
    6971024
    698             sage: K = KirillovReshetikhinCrystal(['C',2,1], 1,2)
    699             sage: b=K(rows=[[-1,-1]])
    700             sage: b.phi(0)
    701             2
     1025            sage: K = KirillovReshetikhinCrystal(['C',2,1], 1,2)
     1026            sage: b=K(rows=[[-1,-1]])
     1027            sage: b.phi(0)
     1028            2
    7021029        """
    703         b = self.parent().to_ambient_crystal()(self)
    704         return b.phi(1)
     1030        b = self.parent().to_ambient_crystal()(self)
     1031        return b.phi(1)
    7051032
    7061033KR_type_C.Element = KR_type_CElement
    7071034
    class KR_type_box(KirillovReshetikhinGen 
    7141041    EXAMPLES::
    7151042
    7161043        sage: K = KirillovReshetikhinCrystal(['A',4,2], 1,1)
    717         sage: K
    718         Kirillov-Reshetikhin crystal of type ['BC', 2, 2] with (r,s)=(1,1)
    719         sage: b = K(rows=[])
    720         sage: b.f(0)
    721         [[1]]
    722         sage: b.e(0)
    723         [[-1]]
     1044        sage: K
     1045        Kirillov-Reshetikhin crystal of type ['BC', 2, 2] with (r,s)=(1,1)
     1046        sage: b = K(rows=[])
     1047        sage: b.f(0)
     1048        [[1]]
     1049        sage: b.e(0)
     1050        [[-1]]
    7241051    """
    7251052    def __init__(self, cartan_type, r, s):
    726         r"""
    727         Initializes a Kirillov-Reshetikhin crystal self.
     1053        r"""
     1054        Initializes a Kirillov-Reshetikhin crystal self.
    7281055
    729         TESTS::
     1056        TESTS::
    7301057
    731             sage: K = sage.combinat.crystals.kirillov_reshetikhin.KR_type_box(['A',4,2], 1, 1)
    732             sage: K
    733             Kirillov-Reshetikhin crystal of type ['BC', 2, 2] with (r,s)=(1,1)
    734             sage: K = sage.combinat.crystals.kirillov_reshetikhin.KR_type_box(['D',4,2], 1, 1)
    735             sage: K
    736             Kirillov-Reshetikhin crystal of type ['C', 3, 1]^* with (r,s)=(1,1)
     1058            sage: K = sage.combinat.crystals.kirillov_reshetikhin.KR_type_box(['A',4,2], 1, 1)
     1059            sage: K
     1060            Kirillov-Reshetikhin crystal of type ['BC', 2, 2] with (r,s)=(1,1)
     1061            sage: K = sage.combinat.crystals.kirillov_reshetikhin.KR_type_box(['D',4,2], 1, 1)
     1062            sage: K
     1063            Kirillov-Reshetikhin crystal of type ['C', 3, 1]^* with (r,s)=(1,1)
    7371064            sage: TestSuite(K).run()
    738         """
    739         KirillovReshetikhinGenericCrystal.__init__(self, cartan_type, r ,s)
    740         AffineCrystalFromClassical.__init__(self, cartan_type, self.classical_decomposition())
     1065        """
     1066        KirillovReshetikhinGenericCrystal.__init__(self, cartan_type, r ,s)
     1067        AffineCrystalFromClassical.__init__(self, cartan_type, self.classical_decomposition())
    7411068
    7421069    def classical_decomposition(self):
    743         r"""
    744         Specifies the classical crystal underlying the Kirillov-Reshetikhin crystal of type `A_{2n}^{(2)}`
    745         and `D_{n+1}^{(2)}`.
    746         It is given by `B^{r,s} \cong \oplus_\Lambda B(\Lambda)` where `\Lambda` are weights obtained from
    747         a rectangle of width s and height r by removing boxes. Here we identify the fundamental
    748         weight `\Lambda_i` with a column of height `i`.
     1070        r"""
     1071        Specifies the classical crystal underlying the Kirillov-Reshetikhin crystal of type `A_{2n}^{(2)}`
     1072        and `D_{n+1}^{(2)}`.
     1073        It is given by `B^{r,s} \cong \oplus_\Lambda B(\Lambda)` where `\Lambda` are weights obtained from
     1074        a rectangle of width s and height r by removing boxes. Here we identify the fundamental
     1075        weight `\Lambda_i` with a column of height `i`.
    7491076
    750         EXAMPLES::
     1077        EXAMPLES::
    7511078
    752             sage: K = KirillovReshetikhinCrystal(['A',4,2], 2,2)
    753             sage: K.classical_decomposition()
    754             The crystal of tableaux of type ['C', 2] and shape(s) [[], [1], [2], [1, 1], [2, 1], [2, 2]]
    755             sage: K = KirillovReshetikhinCrystal(['D',4,2], 2,3)
    756             sage: K.classical_decomposition()
    757             The crystal of tableaux of type ['B', 3] and shape(s) [[], [1], [2], [1, 1], [3], [2, 1], [3, 1], [2, 2], [3, 2], [3, 3]]
     1079            sage: K = KirillovReshetikhinCrystal(['A',4,2], 2,2)
     1080            sage: K.classical_decomposition()
     1081            The crystal of tableaux of type ['C', 2] and shape(s) [[], [1], [2], [1, 1], [2, 1], [2, 2]]
     1082            sage: K = KirillovReshetikhinCrystal(['D',4,2], 2,3)
     1083            sage: K.classical_decomposition()
     1084            The crystal of tableaux of type ['B', 3] and shape(s) [[], [1], [2], [1, 1], [3], [2, 1], [3, 1], [2, 2], [3, 2], [3, 3]]
    7581085        """
    759         return CrystalOfTableaux(self.cartan_type().classical(),
    760                                 shapes = partitions_in_box(self.r(),self.s()))
     1086        return CrystalOfTableaux(self.cartan_type().classical(),
     1087                                shapes = partitions_in_box(self.r(),self.s()))
    7611088
    7621089    def ambient_crystal(self):
    763         r"""
    764         Returns the ambient crystal `'B^{r,2s}` of type `C_n^{(1)}` associated to the Kirillov-Reshetikhin.
    765         This ambient crystal is used to construct the zero arrows.
     1090        r"""
     1091        Returns the ambient crystal `'B^{r,2s}` of type `C_n^{(1)}` associated to the Kirillov-Reshetikhin.
     1092        This ambient crystal is used to construct the zero arrows.
    7661093
    767         EXAMPLES::
     1094        EXAMPLES::
    7681095
    769             sage: K = KirillovReshetikhinCrystal(['A',4,2], 2,2)
    770             sage: K.ambient_crystal()
    771             Kirillov-Reshetikhin crystal of type ['C', 2, 1] with (r,s)=(2,4)
     1096            sage: K = KirillovReshetikhinCrystal(['A',4,2], 2,2)
     1097            sage: K.ambient_crystal()
     1098            Kirillov-Reshetikhin crystal of type ['C', 2, 1] with (r,s)=(2,4)
    7721099        """
    773         # calling KR_type_C instead of KirillovReshetikhin(['C',n,1],r,s) has the advantage that
    774         # that this also works for r=n for A_{2n}^{(2)}.
    775         return KR_type_C(['C', self.cartan_type().classical().rank(),1], self.r(), 2*self.s())
     1100        # calling KR_type_C instead of KirillovReshetikhin(['C',n,1],r,s) has the advantage that
     1101        # that this also works for r=n for A_{2n}^{(2)}.
     1102        return KR_type_C(['C', self.cartan_type().classical().rank(),1], self.r(), 2*self.s())
    7761103
    7771104    def highest_weight_dict(self):
    778         r"""
    779         Gives a dictionary of the classical highest weight vectors of self.
    780         Their key is 2 times their shape.
     1105        r"""
     1106        Gives a dictionary of the classical highest weight vectors of self.
     1107        Their key is 2 times their shape.
    7811108
    782         EXAMPLES::
     1109        EXAMPLES::
    7831110
    784             sage: K = KirillovReshetikhinCrystal(['A',6,2], 2,2)
    785             sage: K.highest_weight_dict()
    786             {[4, 2]: [[1, 1], [2]], [2, 2]: [[1], [2]], []: [], [4]: [[1, 1]], [4, 4]: [[1, 1], [2, 2]], [2]: [[1]]}
    787         """
    788         return dict( (Partition([2*i for i in x.lift().to_tableau().shape()]),x) for x in self.module_generators )
     1111            sage: K = KirillovReshetikhinCrystal(['A',6,2], 2,2)
     1112            sage: K.highest_weight_dict()
     1113            {[4, 2]: [[1, 1], [2]], [2, 2]: [[1], [2]], []: [], [4]: [[1, 1]], [4, 4]: [[1, 1], [2, 2]], [2]: [[1]]}
     1114        """
     1115        return dict( (Partition([2*i for i in x.lift().to_tableau().shape()]),x) for x in self.module_generators )
    7891116
    7901117    def ambient_highest_weight_dict(self):
    791         r"""
    792         Gives a dictionary of the classical highest weight vectors of the ambient crystal of self.
    793         Their key is their shape.
     1118        r"""
     1119        Gives a dictionary of the classical highest weight vectors of the ambient crystal of self.
     1120        Their key is their shape.
    7941121
    795         EXAMPLES::
     1122        EXAMPLES::
    7961123
    797             sage: K = KirillovReshetikhinCrystal(['A',6,2], 2,2)
    798             sage: K.ambient_highest_weight_dict()
    799             {[4, 2]: [[1, 1, 1, 1], [2, 2]], [2, 2]: [[1, 1], [2, 2]], []: [], [4]: [[1, 1, 1, 1]], [4, 4]: [[1, 1, 1, 1], [2, 2, 2, 2]],
    800             [2]: [[1, 1]]}
     1124            sage: K = KirillovReshetikhinCrystal(['A',6,2], 2,2)
     1125            sage: K.ambient_highest_weight_dict()
     1126            {[4, 2]: [[1, 1, 1, 1], [2, 2]], [2, 2]: [[1, 1], [2, 2]], []: [], [4]: [[1, 1, 1, 1]], [4, 4]: [[1, 1, 1, 1], [2, 2, 2, 2]],
     1127            [2]: [[1, 1]]}
    8011128        """
    802         return dict( (x.lift().to_tableau().shape(),x) for x in self.ambient_crystal().module_generators )
     1129        return dict( (x.lift().to_tableau().shape(),x) for x in self.ambient_crystal().module_generators )
    8031130
    8041131    def similarity_factor(self):
    805         r"""
    806         Sets the similarity factor used to map to the ambient crystal.
     1132        r"""
     1133        Sets the similarity factor used to map to the ambient crystal.
    8071134
    808         EXAMPLES::
     1135        EXAMPLES::
    8091136
    810             sage: K = KirillovReshetikhinCrystal(['A',6,2], 2,2)
    811             sage: K.similarity_factor()
    812             {1: 2, 2: 2, 3: 2}
    813             sage: K = KirillovReshetikhinCrystal(['D',5,2], 1,1)
    814             sage: K.similarity_factor()
    815             {1: 2, 2: 2, 3: 2, 4: 1}
    816         """   
    817         C = self.cartan_type().classical()
    818         p = dict( (i,2) for i in C.index_set() )
    819         if C.type() == 'B':
    820             p[C.rank()] = 1
    821         return p
     1137            sage: K = KirillovReshetikhinCrystal(['A',6,2], 2,2)
     1138            sage: K.similarity_factor()
     1139            {1: 2, 2: 2, 3: 2}
     1140            sage: K = KirillovReshetikhinCrystal(['D',5,2], 1,1)
     1141            sage: K.similarity_factor()
     1142            {1: 2, 2: 2, 3: 2, 4: 1}
     1143        """   
     1144        C = self.cartan_type().classical()
     1145        p = dict( (i,2) for i in C.index_set() )
     1146        if C.type() == 'B':
     1147            p[C.rank()] = 1
     1148        return p
    8221149
    8231150    def to_ambient_crystal(self):
    824         r"""
    825         Provides a map from self to the ambient crystal of type `C_n^{(1)}`.
     1151        r"""
     1152        Provides a map from self to the ambient crystal of type `C_n^{(1)}`.
    8261153
    827         EXAMPLES::
     1154        EXAMPLES::
    8281155
    829             sage: K = KirillovReshetikhinCrystal(['D',4,2], 1,1)
    830             sage: [K.to_ambient_crystal()(b) for b in K]
    831             [[], [[1, 1]], [[2, 2]], [[3, 3]], [[3, -3]], [[-3, -3]], [[-2, -2]], [[-1, -1]]]
    832             sage: K = KirillovReshetikhinCrystal(['A',4,2], 1,1)
    833             sage: [K.to_ambient_crystal()(b) for b in K]
    834             [[], [[1, 1]], [[2, 2]], [[-2, -2]], [[-1, -1]]]
    835         """
    836         keys = self.highest_weight_dict().keys()
    837         pdict = dict( (self.highest_weight_dict()[key], self.ambient_highest_weight_dict()[key]) for key in keys )
    838         return self.crystal_morphism( pdict, index_set = self.cartan_type().classical().index_set(),
    839                                       similarity_factor = self.similarity_factor() )
     1156            sage: K = KirillovReshetikhinCrystal(['D',4,2], 1,1)
     1157            sage: [K.to_ambient_crystal()(b) for b in K]
     1158            [[], [[1, 1]], [[2, 2]], [[3, 3]], [[3, -3]], [[-3, -3]], [[-2, -2]], [[-1, -1]]]
     1159            sage: K = KirillovReshetikhinCrystal(['A',4,2], 1,1)
     1160            sage: [K.to_ambient_crystal()(b) for b in K]
     1161            [[], [[1, 1]], [[2, 2]], [[-2, -2]], [[-1, -1]]]
     1162        """
     1163        keys = self.highest_weight_dict().keys()
     1164        pdict = dict( (self.highest_weight_dict()[key], self.ambient_highest_weight_dict()[key]) for key in keys )
     1165        return self.crystal_morphism( pdict, index_set = self.cartan_type().classical().index_set(),
     1166                                      similarity_factor = self.similarity_factor() )
    8401167
    8411168    def from_ambient_crystal(self):
    842         r"""
    843         Provides a map from the ambient crystal of type `C_n^{(1)}` to the Kirillov-Reshetikhin crystal self.
    844         Note that this map is only well-defined on elements that are in the image under `to_ambient_crystal`.
     1169        r"""
     1170        Provides a map from the ambient crystal of type `C_n^{(1)}` to the Kirillov-Reshetikhin crystal self.
     1171        Note that this map is only well-defined on elements that are in the image under `to_ambient_crystal`.
    8451172
    846         EXAMPLES::
     1173        EXAMPLES::
    8471174
    848             sage: K = KirillovReshetikhinCrystal(['D',4,2], 1,1)
    849             sage: b = K.ambient_crystal()(rows=[[3,-3]])
    850             sage: K.from_ambient_crystal()(b)
    851             [[0]]
    852             sage: K = KirillovReshetikhinCrystal(['A',4,2], 1,1)
    853             sage: b = K.ambient_crystal()(rows=[])
    854             sage: K.from_ambient_crystal()(b)
    855             []
    856         """
    857         keys = self.highest_weight_dict().keys()
    858         pdict_inv = dict( (self.ambient_highest_weight_dict()[key], self.highest_weight_dict()[key]) for key in keys )
    859         return self.crystal_morphism( pdict_inv, index_set = self.cartan_type().classical().index_set(),
    860                                       similarity_factor_domain = self.similarity_factor() )
     1175            sage: K = KirillovReshetikhinCrystal(['D',4,2], 1,1)
     1176            sage: b = K.ambient_crystal()(rows=[[3,-3]])
     1177            sage: K.from_ambient_crystal()(b)
     1178            [[0]]
     1179            sage: K = KirillovReshetikhinCrystal(['A',4,2], 1,1)
     1180            sage: b = K.ambient_crystal()(rows=[])
     1181            sage: K.from_ambient_crystal()(b)
     1182            []
     1183        """
     1184        keys = self.highest_weight_dict().keys()
     1185        pdict_inv = dict( (self.ambient_highest_weight_dict()[key], self.highest_weight_dict()[key]) for key in keys )
     1186        return self.crystal_morphism( pdict_inv, index_set = self.cartan_type().classical().index_set(),
     1187                                      similarity_factor_domain = self.similarity_factor() )
    8611188
    8621189
    8631190class KR_type_boxElement(AffineCrystalFromClassicalElement):
    class KR_type_boxElement(AffineCrystalFr 
    8681195    EXAMPLES::
    8691196
    8701197        sage: K=KirillovReshetikhinCrystal(['A',4,2],1,2)
    871         sage: type(K.module_generators[0])
     1198        sage: type(K.module_generators[0])
    8721199        <class 'sage.combinat.crystals.kirillov_reshetikhin.KR_type_box_with_category.element_class'>
    8731200    """
    8741201
    8751202    def e0(self):
    876         r"""
    877         Gives `e_0` on self by mapping self to the ambient crystal, calculating `e_0` there and
    878         pulling the element back.
     1203        r"""
     1204        Gives `e_0` on self by mapping self to the ambient crystal, calculating `e_0` there and
     1205        pulling the element back.
    8791206
    880         EXAMPLES::
     1207        EXAMPLES::
    8811208
    882             sage: K=KirillovReshetikhinCrystal(['A',4,2],1,1)
    883             sage: b = K(rows=[])
    884             sage: b.e(0)
    885             [[-1]]
    886         """
    887         b = self.parent().to_ambient_crystal()(self).e(0)
    888         if b is None:
    889             return None
    890         return self.parent().from_ambient_crystal()(b)
     1209            sage: K=KirillovReshetikhinCrystal(['A',4,2],1,1)
     1210            sage: b = K(rows=[])
     1211            sage: b.e(0)
     1212            [[-1]]
     1213        """
     1214        b = self.parent().to_ambient_crystal()(self).e(0)
     1215        if b is None:
     1216            return None
     1217        return self.parent().from_ambient_crystal()(b)
    8911218   
    8921219    def f0(self):
    893         r"""
    894         Gives `f_0` on self by mapping self to the ambient crystal, calculating `f_0` there and
    895         pulling the element back.
     1220        r"""
     1221        Gives `f_0` on self by mapping self to the ambient crystal, calculating `f_0` there and
     1222        pulling the element back.
    8961223
    897         EXAMPLES::
     1224        EXAMPLES::
    8981225
    899             sage: K=KirillovReshetikhinCrystal(['A',4,2],1,1)
    900             sage: b = K(rows=[])
    901             sage: b.f(0)
    902             [[1]]
    903         """
    904         b = self.parent().to_ambient_crystal()(self).f(0)
    905         if b is None:
    906             return None
    907         return self.parent().from_ambient_crystal()(b)
     1226            sage: K=KirillovReshetikhinCrystal(['A',4,2],1,1)
     1227            sage: b = K(rows=[])
     1228            sage: b.f(0)
     1229            [[1]]
     1230        """
     1231        b = self.parent().to_ambient_crystal()(self).f(0)
     1232        if b is None:
     1233            return None
     1234        return self.parent().from_ambient_crystal()(b)
    9081235
    9091236    def epsilon0(self):
    910         r"""
    911         Calculates `\epsilon_0` of self by mapping the element to the ambient crystal
    912         and calculating `\epsilon_0` there.
     1237        r"""
     1238        Calculates `\epsilon_0` of self by mapping the element to the ambient crystal
     1239        and calculating `\epsilon_0` there.
    9131240
    914         EXAMPLES::
     1241        EXAMPLES::
    9151242
    916             sage: K = KirillovReshetikhinCrystal(['A',4,2], 1,1)
    917             sage: b=K(rows=[[1]])
    918             sage: b.epsilon(0)
    919             2
     1243            sage: K = KirillovReshetikhinCrystal(['A',4,2], 1,1)
     1244            sage: b=K(rows=[[1]])
     1245            sage: b.epsilon(0)
     1246            2
    9201247        """
    921         b = self.parent().to_ambient_crystal()(self)
    922         return b.epsilon(0)
     1248        b = self.parent().to_ambient_crystal()(self)
     1249        return b.epsilon(0)
    9231250
    9241251    def phi0(self):
    925         r"""
    926         Calculates `\phi_0` of self by mapping the element to the ambient crystal
    927         and calculating `\phi_0` there.
     1252        r"""
     1253        Calculates `\phi_0` of self by mapping the element to the ambient crystal
     1254        and calculating `\phi_0` there.
    9281255
    929         EXAMPLES::
     1256        EXAMPLES::
    9301257
    931             sage: K = KirillovReshetikhinCrystal(['D',3,2], 1,1)
    932             sage: b=K(rows=[[-1]])
    933             sage: b.phi(0)
    934             2
     1258            sage: K = KirillovReshetikhinCrystal(['D',3,2], 1,1)
     1259            sage: b=K(rows=[[-1]])
     1260            sage: b.phi(0)
     1261            2
    9351262        """
    936         b = self.parent().to_ambient_crystal()(self)
    937         return b.phi(0)
     1263        b = self.parent().to_ambient_crystal()(self)
     1264        return b.phi(0)
    9381265
    9391266KR_type_box.Element = KR_type_boxElement
    9401267
    class PMDiagram(CombinatorialObject): 
    9591286    EXAMPLES::
    9601287
    9611288        sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[0,1],[1,2],[1]])
    962         sage: pm.pm_diagram
    963         [[0, 1], [1, 2], [1]]
    964         sage: pm._list
    965         [1, 1, 2, 0, 1]
    966         sage: pm.n
    967         2
    968         sage: pm.width
    969         5
    970         sage: pm.__repr__(pretty_printing=True)
    971         .  .  .  .
    972         .  +  -  -
    973         sage: sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([2,5,[4,4],[4,2],[4,1]], from_shapes=True)
    974         [[0, 1], [1, 2], [1]]
     1289        sage: pm.pm_diagram
     1290        [[0, 1], [1, 2], [1]]
     1291        sage: pm._list
     1292        [1, 1, 2, 0, 1]
     1293        sage: pm.n
     1294        2
     1295        sage: pm.width
     1296        5
     1297        sage: pm.__repr__(pretty_printing=True)
     1298        .  .  .  .
     1299        .  +  -  -
     1300        sage: sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([2,5,[4,4],[4,2],[4,1]], from_shapes=True)
     1301        [[0, 1], [1, 2], [1]]
    9751302
    9761303    TESTS::
    977        
    978         sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[1,2],[1,1],[1,1],[1,1],[1]])
    979         sage: sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([pm.n, pm.width, pm.outer_shape(), pm.intermediate_shape(), pm.inner_shape()], from_shapes=True) == pm
    980         True
    981         sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[1,2],[1,2],[1,1],[1,1],[1,1],[1]])
    982         sage: sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([pm.n, pm.width, pm.outer_shape(), pm.intermediate_shape(), pm.inner_shape()], from_shapes=True) == pm
    983         True
     1304       
     1305        sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[1,2],[1,1],[1,1],[1,1],[1]])
     1306        sage: sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([pm.n, pm.width, pm.outer_shape(), pm.intermediate_shape(), pm.inner_shape()], from_shapes=True) == pm
     1307        True
     1308        sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[1,2],[1,2],[1,1],[1,1],[1,1],[1]])
     1309        sage: sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([pm.n, pm.width, pm.outer_shape(), pm.intermediate_shape(), pm.inner_shape()], from_shapes=True) == pm
     1310        True
    9841311    """
    9851312
    9861313    def __init__(self, pm_diagram, from_shapes = None):
    987         r"""
    988         Initializes `\pm` diagrams.
     1314        r"""
     1315        Initializes `\pm` diagrams.
    9891316
    990         TESTS::
     1317        TESTS::
    9911318
    9921319           sage: sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[0,1],[1,2],[1]])
    993            [[0, 1], [1, 2], [1]]
    994            sage: sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([2,5,[4,4],[4,2],[4,1]], from_shapes=True)
    995            [[0, 1], [1, 2], [1]]
    996         """
    997         if from_shapes:
    998             n = pm_diagram[0]
    999             s = pm_diagram[1]
    1000             outer = [s]+list(pm_diagram[2])+[0 for i in range(n)]
    1001             intermediate = [s]+list(pm_diagram[3])+[0 for i in range(n)]
    1002             inner = [s]+list(pm_diagram[4])+[0 for i in range(n)]
    1003             pm = [[inner[n]]]
    1004             for i in range(int((n+1)/2)):
    1005                 pm.append([intermediate[n-2*i]-inner[n-2*i], inner[n-2*i-1]-intermediate[n-2*i]])
    1006                 pm.append([outer[n-2*i]-inner[n-2*i-1], inner[n-2*i-2]-outer[n-2*i]])
    1007             if is_odd(n):
    1008                 pm.pop(n+1)
    1009             pm_diagram = list(reversed(pm))
    1010         self.pm_diagram = pm_diagram
    1011         self.n = len(pm_diagram)-1
    1012         self._list = [i for a in reversed(pm_diagram) for i in a]
    1013         self.width = sum(i for i in self._list)
     1320           [[0, 1], [1, 2], [1]]
     1321           sage: sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([2,5,[4,4],[4,2],[4,1]], from_shapes=True)
     1322           [[0, 1], [1, 2], [1]]
     1323        """
     1324        if from_shapes:
     1325            n = pm_diagram[0]
     1326            s = pm_diagram[1]
     1327            outer = [s]+list(pm_diagram[2])+[0 for i in range(n)]
     1328            intermediate = [s]+list(pm_diagram[3])+[0 for i in range(n)]
     1329            inner = [s]+list(pm_diagram[4])+[0 for i in range(n)]
     1330            pm = [[inner[n]]]
     1331            for i in range(int((n+1)/2)):
     1332                pm.append([intermediate[n-2*i]-inner[n-2*i], inner[n-2*i-1]-intermediate[n-2*i]])
     1333                pm.append([outer[n-2*i]-inner[n-2*i-1], inner[n-2*i-2]-outer[n-2*i]])
     1334            if is_odd(n):
     1335                pm.pop(n+1)
     1336            pm_diagram = list(reversed(pm))
     1337        self.pm_diagram = pm_diagram
     1338        self.n = len(pm_diagram)-1
     1339        self._list = [i for a in reversed(pm_diagram) for i in a]
     1340        self.width = sum(i for i in self._list)
    10141341
    10151342    def __repr__(self, pretty_printing = None):
    1016         """
    1017         Turning on pretty printing allows to display the pm diagram as a
    1018         tableau with the + and - displayed
     1343        """
     1344        Turning on pretty printing allows to display the pm diagram as a
     1345        tableau with the + and - displayed
    10191346
    1020         EXAMPLES::
     1347        EXAMPLES::
    10211348
    1022             sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[1,0],[0,1],[2,0],[0,0],[0]])
    1023             sage: pm.__repr__(pretty_printing=True)
    1024             .  .  .  +
    1025             .  .  -  -
    1026             +  +
    1027             -  -
    1028             sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[0,2], [0,0], [0]])
    1029             sage: pm.__repr__(pretty_printing=True)
     1349            sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[1,0],[0,1],[2,0],[0,0],[0]])
     1350            sage: pm.__repr__(pretty_printing=True)
     1351            .  .  .  +
     1352            .  .  -  -
     1353            +  +
     1354            -  -
     1355            sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[0,2], [0,0], [0]])
     1356            sage: pm.__repr__(pretty_printing=True)
    10301357
    10311358        """
    1032         if pretty_printing is None:
    1033             return repr(self.pm_diagram)
    1034         t = []
    1035         ish = self.inner_shape() + [0]*self.n
    1036         msh = self.intermediate_shape() + [0]*self.n
    1037         osh = self.outer_shape() + [0]*self.n
    1038         for i in range(self.n):
    1039             t.append(['.']*ish[i]+['+']*(msh[i]-ish[i])+['-']*(osh[i]-msh[i]))
    1040         t=[i for i in t if i!= []]
    1041         return Tableau(t).pp()
     1359        if pretty_printing is None:
     1360            return repr(self.pm_diagram)
     1361        t = []
     1362        ish = self.inner_shape() + [0]*self.n
     1363        msh = self.intermediate_shape() + [0]*self.n
     1364        osh = self.outer_shape() + [0]*self.n
     1365        for i in range(self.n):
     1366            t.append(['.']*ish[i]+['+']*(msh[i]-ish[i])+['-']*(osh[i]-msh[i]))
     1367        t=[i for i in t if i!= []]
     1368        return Tableau(t).pp()
    10421369
    10431370    def inner_shape(self):
    1044         """
    1045         Returns the inner shape of the pm diagram
     1371        """
     1372        Returns the inner shape of the pm diagram
    10461373
    1047         EXAMPLES::
    1048             sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[0,1],[1,2],[1]])
    1049             sage: pm.inner_shape()
    1050             [4, 1]
    1051             sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[1,2],[1,1],[1,1],[1,1],[1]])
    1052             sage: pm.inner_shape()
    1053             [7, 5, 3, 1]
    1054             sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[1,2],[1,2],[1,1],[1,1],[1,1],[1]])
    1055             sage: pm.inner_shape()
    1056             [10, 7, 5, 3, 1]
     1374        EXAMPLES::
     1375            sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[0,1],[1,2],[1]])
     1376            sage: pm.inner_shape()
     1377            [4, 1]
     1378            sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[1,2],[1,1],[1,1],[1,1],[1]])
     1379            sage: pm.inner_shape()
     1380            [7, 5, 3, 1]
     1381            sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[1,2],[1,2],[1,1],[1,1],[1,1],[1]])
     1382            sage: pm.inner_shape()
     1383            [10, 7, 5, 3, 1]
    10571384        """
    1058         t = []
    1059         ll = self._list
    1060         for i in range(self.n):
    1061             t.append(sum(ll[0:2*i+1]))
    1062         return Partition(list(reversed(t)))
     1385        t = []
     1386        ll = self._list
     1387        for i in range(self.n):
     1388            t.append(sum(ll[0:2*i+1]))
     1389        return Partition(list(reversed(t)))
    10631390
    10641391    def outer_shape(self):
    1065         """
    1066         Returns the outer shape of the pm diagram
     1392        """
     1393        Returns the outer shape of the pm diagram
    10671394
    1068         EXAMPLES::
     1395        EXAMPLES::
    10691396
    1070             sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[0,1],[1,2],[1]])
    1071             sage: pm.outer_shape()
    1072             [4, 4]
    1073             sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[1,2],[1,1],[1,1],[1,1],[1]])
    1074             sage: pm.outer_shape()
    1075             [8, 8, 4, 4]
    1076             sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[1,2],[1,2],[1,1],[1,1],[1,1],[1]])
    1077             sage: pm.outer_shape()
    1078             [13, 8, 8, 4, 4]
    1079         """
    1080         t = []
    1081         ll = self._list
    1082         for i in range((self.n)/2):
    1083             t.append(sum(ll[0:4*i+4]))
    1084             t.append(sum(ll[0:4*i+4]))
    1085         if is_even(self.n+1):
    1086             t.append(sum(ll[0:2*self.n+2]))
    1087         return Partition(list(reversed(t)))
     1397            sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[0,1],[1,2],[1]])
     1398            sage: pm.outer_shape()
     1399            [4, 4]
     1400            sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[1,2],[1,1],[1,1],[1,1],[1]])
     1401            sage: pm.outer_shape()
     1402            [8, 8, 4, 4]
     1403            sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[1,2],[1,2],[1,1],[1,1],[1,1],[1]])
     1404            sage: pm.outer_shape()
     1405            [13, 8, 8, 4, 4]
     1406        """
     1407        t = []
     1408        ll = self._list
     1409        for i in range((self.n)/2):
     1410            t.append(sum(ll[0:4*i+4]))
     1411            t.append(sum(ll[0:4*i+4]))
     1412        if is_even(self.n+1):
     1413            t.append(sum(ll[0:2*self.n+2]))
     1414        return Partition(list(reversed(t)))
    10881415
    10891416    def intermediate_shape(self):
    1090         """
    1091         Returns the intermediate shape of the pm diagram (innner shape plus positions of plusses)
     1417        """
     1418        Returns the intermediate shape of the pm diagram (innner shape plus positions of plusses)
    10921419
    1093         EXAMPLES::
     1420        EXAMPLES::
    10941421
    1095             sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[0,1],[1,2],[1]])
    1096             sage: pm.intermediate_shape()
    1097             [4, 2]
    1098             sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[1,2],[1,1],[1,1],[1,1],[1]])
    1099             sage: pm.intermediate_shape()
    1100             [8, 6, 4, 2]
    1101             sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[1,2],[1,2],[1,1],[1,1],[1,1],[1]])
    1102             sage: pm.intermediate_shape()
    1103             [11, 8, 6, 4, 2]
    1104             sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[1,0],[0,1],[2,0],[0,0],[0]])
    1105             sage: pm.intermediate_shape()
    1106             [4, 2, 2]
    1107         """
    1108         p = self.inner_shape()
    1109         p = p + [0,0]
    1110         ll = list(reversed(self._list))
    1111         p = [ p[i]+ll[2*i+1] for i in range(self.n) ]
    1112         return Partition(p)
     1422            sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[0,1],[1,2],[1]])
     1423            sage: pm.intermediate_shape()
     1424            [4, 2]
     1425            sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[1,2],[1,1],[1,1],[1,1],[1]])
     1426            sage: pm.intermediate_shape()
     1427            [8, 6, 4, 2]
     1428            sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[1,2],[1,2],[1,1],[1,1],[1,1],[1]])
     1429            sage: pm.intermediate_shape()
     1430            [11, 8, 6, 4, 2]
     1431            sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[1,0],[0,1],[2,0],[0,0],[0]])
     1432            sage: pm.intermediate_shape()
     1433            [4, 2, 2]
     1434        """
     1435        p = self.inner_shape()
     1436        p = p + [0,0]
     1437        ll = list(reversed(self._list))
     1438        p = [ p[i]+ll[2*i+1] for i in range(self.n) ]
     1439        return Partition(p)
    11131440
    11141441    def heights_of_minus(self):
    1115         """
    1116         Returns a list with the heights of all minus in the `\pm` diagram.
     1442        """
     1443        Returns a list with the heights of all minus in the `\pm` diagram.
    11171444
    1118         EXAMPLES::
     1445        EXAMPLES::
    11191446
    1120             sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[1,2],[1,2],[1,1],[1,1],[1,1],[1]])
    1121             sage: pm.heights_of_minus()
    1122             [5, 5, 3, 3, 1, 1]
    1123             sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[1,2],[1,1],[1,1],[1,1],[1]])
    1124             sage: pm.heights_of_minus()
    1125             [4, 4, 2, 2]
    1126         """
    1127         n = self.n
    1128         heights = []
    1129         for i in range(int((n+1)/2)):
    1130             heights += [n-2*i]*((self.outer_shape()+[0]*n)[n-2*i-1]-(self.intermediate_shape()+[0]*n)[n-2*i-1])
    1131         return heights
     1447            sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[1,2],[1,2],[1,1],[1,1],[1,1],[1]])
     1448            sage: pm.heights_of_minus()
     1449            [5, 5, 3, 3, 1, 1]
     1450            sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[1,2],[1,1],[1,1],[1,1],[1]])
     1451            sage: pm.heights_of_minus()
     1452            [4, 4, 2, 2]
     1453        """
     1454        n = self.n
     1455        heights = []
     1456        for i in range(int((n+1)/2)):
     1457            heights += [n-2*i]*((self.outer_shape()+[0]*n)[n-2*i-1]-(self.intermediate_shape()+[0]*n)[n-2*i-1])
     1458        return heights
    11321459
    11331460    def heights_of_addable_plus(self):
    1134         """
    1135         Returns a list with the heights of all addable plus in the `\pm` diagram.
     1461        """
     1462        Returns a list with the heights of all addable plus in the `\pm` diagram.
    11361463
    1137         EXAMPLES::
     1464        EXAMPLES::
    11381465
    1139             sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[1,2],[1,2],[1,1],[1,1],[1,1],[1]])
    1140             sage: pm.heights_of_addable_plus()
    1141             [1, 1, 2, 3, 4, 5]
    1142             sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[1,2],[1,1],[1,1],[1,1],[1]])
    1143             sage: pm.heights_of_addable_plus()
    1144             [1, 2, 3, 4]
     1466            sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[1,2],[1,2],[1,1],[1,1],[1,1],[1]])
     1467            sage: pm.heights_of_addable_plus()
     1468            [1, 1, 2, 3, 4, 5]
     1469            sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[1,2],[1,1],[1,1],[1,1],[1]])
     1470            sage: pm.heights_of_addable_plus()
     1471            [1, 2, 3, 4]
    11451472        """
    1146         heights = []
    1147         for i in range(1,self.n+1):
    1148             heights += [i]*self.sigma().pm_diagram[i][0]
    1149         return heights
     1473        heights = []
     1474        for i in range(1,self.n+1):
     1475            heights += [i]*self.sigma().pm_diagram[i][0]
     1476        return heights
    11501477
    11511478    def sigma(self):
    1152         """
    1153         Returns sigma on pm diagrams as needed for the analogue of the Dynkin diagram automorphism
    1154         that interchanges nodes `0` and `1` for type `D_n(1)`, `B_n(1)`, `A_{2n-1}(2)` for
    1155         Kirillov-Reshetikhin crystals.
     1479        """
     1480        Returns sigma on pm diagrams as needed for the analogue of the Dynkin diagram automorphism
     1481        that interchanges nodes `0` and `1` for type `D_n(1)`, `B_n(1)`, `A_{2n-1}(2)` for
     1482        Kirillov-Reshetikhin crystals.
    11561483
    1157         EXAMPLES::
     1484        EXAMPLES::
    11581485
    1159             sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[0,1],[1,2],[1]])
    1160             sage: pm.sigma().pm_diagram
    1161             [[1, 0], [2, 1], [1]]
    1162         """
    1163         pm = self.pm_diagram
    1164         return PMDiagram([list(reversed(a)) for a in pm])
     1486            sage: pm=sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[0,1],[1,2],[1]])
     1487            sage: pm.sigma().pm_diagram
     1488            [[1, 0], [2, 1], [1]]
     1489        """
     1490        pm = self.pm_diagram
     1491        return PMDiagram([list(reversed(a)) for a in pm])
    11651492
    11661493
    11671494def partitions_in_box(r, s):
    def partitions_in_box(r, s): 
    11711498    EXAMPLES::
    11721499
    11731500        sage: sage.combinat.crystals.kirillov_reshetikhin.partitions_in_box(3,2)
    1174         [[], [1], [2], [1, 1], [2, 1], [1, 1, 1], [2, 2], [2, 1, 1],
    1175         [2, 2, 1], [2, 2, 2]]
     1501        [[], [1], [2], [1, 1], [2, 1], [1, 1, 1], [2, 2], [2, 1, 1],
     1502        [2, 2, 1], [2, 2, 2]]
    11761503    """
    11771504    return [x for n in range(r*s+1) for x in Partitions(n,max_part=s,max_length=r)]
    11781505
    def vertical_dominoes_removed(r, s): 
    11831510
    11841511    EXAMPLES::
    11851512
    1186         sage: sage.combinat.crystals.kirillov_reshetikhin.vertical_dominoes_removed(2,2)
    1187         [[], [1, 1], [2, 2]]
    1188         sage: sage.combinat.crystals.kirillov_reshetikhin.vertical_dominoes_removed(3,2)
    1189         [[2], [2, 1, 1], [2, 2, 2]]
    1190         sage: sage.combinat.crystals.kirillov_reshetikhin.vertical_dominoes_removed(4,2)
    1191         [[], [1, 1], [1, 1, 1, 1], [2, 2], [2, 2, 1, 1], [2, 2, 2, 2]]
     1513        sage: sage.combinat.crystals.kirillov_reshetikhin.vertical_dominoes_removed(2,2)
     1514        [[], [1, 1], [2, 2]]
     1515        sage: sage.combinat.crystals.kirillov_reshetikhin.vertical_dominoes_removed(3,2)
     1516        [[2], [2, 1, 1], [2, 2, 2]]
     1517        sage: sage.combinat.crystals.kirillov_reshetikhin.vertical_dominoes_removed(4,2)
     1518        [[], [1, 1], [1, 1, 1, 1], [2, 2], [2, 2, 1, 1], [2, 2, 2, 2]]
    11921519    """
    11931520    return [x.conjugate() for x in horizontal_dominoes_removed(s,r)]
    11941521
    def horizontal_dominoes_removed(r, s): 
    11991526
    12001527    EXAMPLES::
    12011528
    1202         sage: sage.combinat.crystals.kirillov_reshetikhin.horizontal_dominoes_removed(2,2)
    1203         [[], [2], [2, 2]]
    1204         sage: sage.combinat.crystals.kirillov_reshetikhin.horizontal_dominoes_removed(3,2)
    1205         [[], [2], [2, 2], [2, 2, 2]]
     1529        sage: sage.combinat.crystals.kirillov_reshetikhin.horizontal_dominoes_removed(2,2)
     1530        [[], [2], [2, 2]]
     1531        sage: sage.combinat.crystals.kirillov_reshetikhin.horizontal_dominoes_removed(3,2)
     1532        [[], [2], [2, 2], [2, 2, 2]]
    12061533    """
    12071534    list = [ [y for y in x] + [0 for i in range(r-x.length())] for x in partitions_in_box(r, int(s/2)) ]
    12081535    two = lambda x : 2*(x-int(s/2)) + s
    12091536    return [Partition([two(y) for y in x]) for x in list]
    1210 
  • sage/combinat/crystals/letters.py

    diff --git a/sage/combinat/crystals/letters.py b/sage/combinat/crystals/letters.py
    a b def CrystalOfLetters(cartan_type, elemen 
    5858        sage: C = CrystalOfLetters(['A',5])
    5959        sage: C.list()
    6060        [1, 2, 3, 4, 5, 6]
    61         sage: C.cartan_type()
    62         ['A', 5]
     61        sage: C.cartan_type()
     62        ['A', 5]
    6363
    6464    For type E6, one can also specify how elements are printed.
    6565    This option is usually set to None and the default representation is used.
    6666    If one chooses the option 'compact', the elements are printed in the more
    6767    compact convention with 27 letters +abcdefghijklmnopqrstuvwxyz and
    6868    the 27 letters -ABCDEFGHIJKLMNOPQRSTUVWXYZ for the dual crystal.
    69        
     69       
    7070    EXAMPLES::
    7171
    7272        sage: C = CrystalOfLetters(['E',6], element_print_style = 'compact')
    73         sage: C
    74         The crystal of letters for type ['E', 6]
    75         sage: C.list()
    76         [+, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z]
     73        sage: C
     74        The crystal of letters for type ['E', 6]
     75        sage: C.list()
     76        [+, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z]
    7777        sage: C = CrystalOfLetters(['E',6], element_print_style = 'compact', dual = True)
    78         sage: C
    79         The crystal of letters for type ['E', 6] (dual)
    80         sage: C.list()
    81         [-, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z]
     78        sage: C
     79        The crystal of letters for type ['E', 6] (dual)
     80        sage: C.list()
     81        [-, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z]
    8282    """
    8383    ct = CartanType(cartan_type)
    8484    if ct.letter == 'A':
    def CrystalOfLetters(cartan_type, elemen 
    9494        return ClassicalCrystalOfLetters(ct,
    9595                                         Crystal_of_letters_type_D_element)
    9696    elif ct.letter == 'E' and ct[1] == 6:
    97         if dual is None:
    98             return ClassicalCrystalOfLetters(ct,
    99                                              Crystal_of_letters_type_E6_element, element_print_style)
    100         else:
    101             return ClassicalCrystalOfLetters(ct,
    102                                              Crystal_of_letters_type_E6_element_dual, element_print_style, dual = True)
     97        if dual is None:
     98            return ClassicalCrystalOfLetters(ct,
     99                                             Crystal_of_letters_type_E6_element, element_print_style)
     100        else:
     101            return ClassicalCrystalOfLetters(ct,
     102                                             Crystal_of_letters_type_E6_element_dual, element_print_style, dual = True)
    103103    elif ct.letter == 'E' and ct[1] == 7:
    104104        return ClassicalCrystalOfLetters(ct,
    105105                                         Crystal_of_letters_type_E7_element)
    class ClassicalCrystalOfLetters(Classica 
    139139        self._cartan_type = CartanType(cartan_type)
    140140        self.rename("The crystal of letters for type %s"%cartan_type)
    141141        self.Element = element_class
    142         Parent.__init__(self, category = FiniteEnumeratedSets()) #, category = ClassicalCrystals()
    143         if cartan_type == CartanType(['E',6]):
     142        Parent.__init__(self, category = FiniteEnumeratedSets()) #, category = ClassicalCrystals()
     143        if cartan_type == CartanType(['E',6]):
    144144            if dual:
    145145                self.module_generators = [self([6])]
    146146                self._ambient = CrystalOfLetters(CartanType(['E',6]))
    147                 self.rename("%s (dual)"%self)
     147                self.rename("%s (dual)"%self)
    148148            else:
    149149                self.module_generators = [self([1])]
    150150        elif cartan_type == CartanType(['E',7]):
    151151            self.module_generators = [self([7])]
    152         else:
    153             self.module_generators = [self(1)]
     152        else:
     153            self.module_generators = [self(1)]
    154154        self._list = ClassicalCrystal.list(self)
    155         self._element_print_style = element_print_style
     155        self._element_print_style = element_print_style
    156156        self._digraph = ClassicalCrystal.digraph(self)
    157157        self._digraph_closure = self.digraph().transitive_closure()
    158158
    class ClassicalCrystalOfLetters(Classica 
    231231            False
    232232            sage: C.lt_elements(x,x)
    233233            False
    234             sage: C = CrystalOfLetters(['D', 4])
    235             sage: C.lt_elements(C(4),C(-4))
    236             False
    237             sage: C.lt_elements(C(-4),C(4))
    238             False
     234            sage: C = CrystalOfLetters(['D', 4])
     235            sage: C.lt_elements(C(4),C(-4))
     236            False
     237            sage: C.lt_elements(C(-4),C(4))
     238            False
    239239        """
    240240        assert x.parent() == self and y.parent() == self
    241241        if self._digraph_closure.has_edge(x,y):
    242242            return True
    243         return False
     243        return False
    244244
    245245# Utility. Note: much of this class should be factored out at some point!
    246246class Letter(ElementWrapper):
    class Letter(ElementWrapper): 
    253253    EXAMPLES::
    254254
    255255        sage: from sage.combinat.crystals.letters import Letter
    256         sage: a = Letter(ZZ, 1)
    257         sage: Letter(ZZ, 1).parent()
    258         Integer Ring
     256        sage: a = Letter(ZZ, 1)
     257        sage: Letter(ZZ, 1).parent()
     258        Integer Ring
    259259
    260         sage: Letter(ZZ, 1).__repr__()
    261         '1'
     260        sage: Letter(ZZ, 1).__repr__()
     261        '1'
    262262
    263         sage: parent1 = ZZ  # Any fake value ...
    264         sage: parent2 = QQ  # Any fake value ...
    265         sage: l11 = Letter(parent1, 1)
    266         sage: l12 = Letter(parent1, 2)
    267         sage: l21 = Letter(parent2, 1)
    268         sage: l22 = Letter(parent2, 2)
    269         sage: l11 == l11
    270         True
    271         sage: l11 == l12
    272         False
    273         sage: l11 == l21
    274         False
     263        sage: parent1 = ZZ  # Any fake value ...
     264        sage: parent2 = QQ  # Any fake value ...
     265        sage: l11 = Letter(parent1, 1)
     266        sage: l12 = Letter(parent1, 2)
     267        sage: l21 = Letter(parent2, 1)
     268        sage: l22 = Letter(parent2, 2)
     269        sage: l11 == l11
     270        True
     271        sage: l11 == l12
     272        False
     273        sage: l11 == l21
     274        False
    275275
    276         sage: C = CrystalOfLetters(['B', 3])
    277         sage: C(0) <> C(0)
    278         False
    279         sage: C(1) <> C(-1)
    280         True
     276        sage: C = CrystalOfLetters(['B', 3])
     277        sage: C(0) <> C(0)
     278        False
     279        sage: C(1) <> C(-1)
     280        True
    281281    """
    282282    def __init__(self, parent, value):
    283283        """
    class Letter(ElementWrapper): 
    293293        ElementWrapper.__init__(self, value, parent)
    294294
    295295    def __lt__(self, other):
    296         """
    297         EXAMPLES::
     296        """
     297        EXAMPLES::
    298298
    299             sage: C = CrystalOfLetters(['D', 4])
    300             sage: C(-4) < C(4)
    301             False
    302             sage: C(4) < C(-3)
    303             True
    304             sage: C(4) < C(4)
    305             False
    306             sage: C(4) < 5
    307             False
     299            sage: C = CrystalOfLetters(['D', 4])
     300            sage: C(-4) < C(4)
     301            False
     302            sage: C(4) < C(-3)
     303            True
     304            sage: C(4) < C(4)
     305            False
     306            sage: C(4) < 5
     307            False
    308308        """
    309         if parent(self) is not parent(other):
    310             return False
    311         return self.parent().lt_elements(self, other)
     309        if parent(self) is not parent(other):
     310            return False
     311        return self.parent().lt_elements(self, other)
    312312
    313313    def __gt__(self, other):
    314         """
    315         EXAMPLES::
     314        """
     315        EXAMPLES::
    316316
    317             sage: C = CrystalOfLetters(['D', 4])
    318             sage: C(-4) > C(4)
    319             False
    320             sage: C(4) > C(-3)
    321             False
    322             sage: C(4) < C(4)
    323             False
    324             sage: C(-1) > C(1)
    325             True
     317            sage: C = CrystalOfLetters(['D', 4])
     318            sage: C(-4) > C(4)
     319            False
     320            sage: C(4) > C(-3)
     321            False
     322            sage: C(4) < C(4)
     323            False
     324            sage: C(-1) > C(1)
     325            True
    326326        """
    327         return other.__lt__(self)
     327        return other.__lt__(self)
    328328
    329329    def __le__(self, other):
    330         """
    331         EXAMPLES::
    332            
    333             sage: C = CrystalOfLetters(['D', 4])
    334             sage: C(-4) <= C(4)
    335             False
    336             sage: C(4) <= C(-3)
    337             True
    338             sage: C(4) <= C(4)
    339             True
    340330        """
    341         return self.__lt__(other) or self == other
     331        EXAMPLES::
     332           
     333            sage: C = CrystalOfLetters(['D', 4])
     334            sage: C(-4) <= C(4)
     335            False
     336            sage: C(4) <= C(-3)
     337            True
     338            sage: C(4) <= C(4)
     339            True
     340        """
     341        return self.__lt__(other) or self == other
    342342
    343343    def __ge__(self, other):
    344         """
    345         EXAMPLES::
    346            
    347             sage: C = CrystalOfLetters(['D', 4])
    348             sage: C(-4) >= C(4)
    349             False
    350             sage: C(4) >= C(-3)
    351             False
    352             sage: C(4) >= C(4)
    353             True
    354344        """
    355         return other.__le__(self)
     345        EXAMPLES::
     346           
     347            sage: C = CrystalOfLetters(['D', 4])
     348            sage: C(-4) >= C(4)
     349            False
     350            sage: C(4) >= C(-3)
     351            False
     352            sage: C(4) >= C(4)
     353            True
     354        """
     355        return other.__le__(self)
    356356
    357357#    def __cmp__(self, other):
    358358#        """
    class Crystal_of_letters_type_E6_element 
    865865    TESTS::
    866866
    867867        sage: C = CrystalOfLetters(['E',6])
    868         sage: C.module_generators
    869         [[1]]
    870         sage: C.list()
    871         [[1], [-1, 3], [-3, 4], [-4, 2, 5], [-2, 5], [-5, 2, 6], [-2, -5, 4, 6],
    872         [-4, 3, 6], [-3, 1, 6], [-1, 6], [-6, 2], [-2, -6, 4], [-4, -6, 3, 5],
    873         [-3, -6, 1, 5], [-1, -6, 5], [-5, 3], [-3, -5, 1, 4], [-1, -5, 4], [-4, 1, 2],
    874         [-1, -4, 2, 3], [-3, 2], [-2, -3, 4], [-4, 5], [-5, 6], [-6], [-2, 1], [-1, -2, 3]]
     868        sage: C.module_generators
     869        [[1]]
     870        sage: C.list()
     871        [[1], [-1, 3], [-3, 4], [-4, 2, 5], [-2, 5], [-5, 2, 6], [-2, -5, 4, 6],
     872        [-4, 3, 6], [-3, 1, 6], [-1, 6], [-6, 2], [-2, -6, 4], [-4, -6, 3, 5],
     873        [-3, -6, 1, 5], [-1, -6, 5], [-5, 3], [-3, -5, 1, 4], [-1, -5, 4], [-4, 1, 2],
     874        [-1, -4, 2, 3], [-3, 2], [-2, -3, 4], [-4, 5], [-5, 6], [-6], [-2, 1], [-1, -2, 3]]
    875875        sage: C.check()
    876876        True
    877         sage: all(b.f(i).e(i) == b for i in C.index_set() for b in C if b.f(i) is not None)
    878         True
    879         sage: all(b.e(i).f(i) == b for i in C.index_set() for b in C if b.e(i) is not None)
    880         True
    881         sage: G = C.digraph()
    882         sage: G.show(edge_labels=true, figsize=12, vertex_size=1)
     877        sage: all(b.f(i).e(i) == b for i in C.index_set() for b in C if b.f(i) is not None)
     878        True
     879        sage: all(b.e(i).f(i) == b for i in C.index_set() for b in C if b.e(i) is not None)
     880        True
     881        sage: G = C.digraph()
     882        sage: G.show(edge_labels=true, figsize=12, vertex_size=1)
    883883    """
    884884
    885885    def __hash__(self):
    886         return hash(tuple(self.value))
     886        return hash(tuple(self.value))
    887887
    888888    def __repr__(self):
    889         """
    890         In their full representation, the vertices of this crystal are labeled
    891         by their weight. For example vertex [-5,2,6] indicates that a 5-arrow
    892         is coming into this vertex, and a 2-arrow and 6-arrow is leaving the vertex.
    893         Specifying element_print_style = 'compact' for a given crystal C, labels the
    894         vertices of this crystal by the 27 letters +abcdefghijklmnopqrstuvwxyz.
     889        """
     890        In their full representation, the vertices of this crystal are labeled
     891        by their weight. For example vertex [-5,2,6] indicates that a 5-arrow
     892        is coming into this vertex, and a 2-arrow and 6-arrow is leaving the vertex.
     893        Specifying element_print_style = 'compact' for a given crystal C, labels the
     894        vertices of this crystal by the 27 letters +abcdefghijklmnopqrstuvwxyz.
    895895
    896         EXAMPLES::
     896        EXAMPLES::
    897897
    898898            sage: C = CrystalOfLetters(['E',6], element_print_style = 'compact')
    899             sage: C.list()
    900             [+, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z]
     899            sage: C.list()
     900            [+, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z]
    901901        """
    902         if self.parent()._element_print_style == 'compact':
    903             l=['+','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
    904             return l[self.parent().list().index(self)]
    905         return "%s"%self.value
    906            
     902        if self.parent()._element_print_style == 'compact':
     903            l=['+','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
     904            return l[self.parent().list().index(self)]
     905        return "%s"%self.value
     906           
    907907    def weight(self):
    908908        """
    909909        Returns the weight of self.
    class Crystal_of_letters_type_E6_element 
    911911        EXAMPLES::
    912912       
    913913            sage: [v.weight() for v in CrystalOfLetters(['E',6])]
    914             [(0, 0, 0, 0, 0, -2/3, -2/3, 2/3),
    915             (-1/2, 1/2, 1/2, 1/2, 1/2, -1/6, -1/6, 1/6),
    916             (1/2, -1/2, 1/2, 1/2, 1/2, -1/6, -1/6, 1/6),
    917             (1/2, 1/2, -1/2, 1/2, 1/2, -1/6, -1/6, 1/6),
    918             (-1/2, -1/2, -1/2, 1/2, 1/2, -1/6, -1/6, 1/6),
    919             (1/2, 1/2, 1/2, -1/2, 1/2, -1/6, -1/6, 1/6),
    920             (-1/2, -1/2, 1/2, -1/2, 1/2, -1/6, -1/6, 1/6),
    921             (-1/2, 1/2, -1/2, -1/2, 1/2, -1/6, -1/6, 1/6),
    922             (1/2, -1/2, -1/2, -1/2, 1/2, -1/6, -1/6, 1/6),
    923             (0, 0, 0, 0, 1, 1/3, 1/3, -1/3),
    924             (1/2, 1/2, 1/2, 1/2, -1/2, -1/6, -1/6, 1/6),
    925             (-1/2, -1/2, 1/2, 1/2, -1/2, -1/6, -1/6, 1/6),
    926             (-1/2, 1/2, -1/2, 1/2, -1/2, -1/6, -1/6, 1/6),
    927             (1/2, -1/2, -1/2, 1/2, -1/2, -1/6, -1/6, 1/6),
    928             (0, 0, 0, 1, 0, 1/3, 1/3, -1/3),
    929             (-1/2, 1/2, 1/2, -1/2, -1/2, -1/6, -1/6, 1/6),
    930             (1/2, -1/2, 1/2, -1/2, -1/2, -1/6, -1/6, 1/6),
    931             (0, 0, 1, 0, 0, 1/3, 1/3, -1/3),
    932             (1/2, 1/2, -1/2, -1/2, -1/2, -1/6, -1/6, 1/6),
    933             (0, 1, 0, 0, 0, 1/3, 1/3, -1/3),
    934             (1, 0, 0, 0, 0, 1/3, 1/3, -1/3),
    935             (0, -1, 0, 0, 0, 1/3, 1/3, -1/3),
    936             (0, 0, -1, 0, 0, 1/3, 1/3, -1/3),
    937             (0, 0, 0, -1, 0, 1/3, 1/3, -1/3),
    938             (0, 0, 0, 0, -1, 1/3, 1/3, -1/3),
    939             (-1/2, -1/2, -1/2, -1/2, -1/2, -1/6, -1/6, 1/6),
    940             (-1, 0, 0, 0, 0, 1/3, 1/3, -1/3)]
     914            [(0, 0, 0, 0, 0, -2/3, -2/3, 2/3),
     915            (-1/2, 1/2, 1/2, 1/2, 1/2, -1/6, -1/6, 1/6),
     916            (1/2, -1/2, 1/2, 1/2, 1/2, -1/6, -1/6, 1/6),
     917            (1/2, 1/2, -1/2, 1/2, 1/2, -1/6, -1/6, 1/6),
     918            (-1/2, -1/2, -1/2, 1/2, 1/2, -1/6, -1/6, 1/6),
     919            (1/2, 1/2, 1/2, -1/2, 1/2, -1/6, -1/6, 1/6),
     920            (-1/2, -1/2, 1/2, -1/2, 1/2, -1/6, -1/6, 1/6),
     921            (-1/2, 1/2, -1/2, -1/2, 1/2, -1/6, -1/6, 1/6),
     922            (1/2, -1/2, -1/2, -1/2, 1/2, -1/6, -1/6, 1/6),
     923            (0, 0, 0, 0, 1, 1/3, 1/3, -1/3),
     924            (1/2, 1/2, 1/2, 1/2, -1/2, -1/6, -1/6, 1/6),
     925            (-1/2, -1/2, 1/2, 1/2, -1/2, -1/6, -1/6, 1/6),
     926            (-1/2, 1/2, -1/2, 1/2, -1/2, -1/6, -1/6, 1/6),
     927            (1/2, -1/2, -1/2, 1/2, -1/2, -1/6, -1/6, 1/6),
     928            (0, 0, 0, 1, 0, 1/3, 1/3, -1/3),
     929            (-1/2, 1/2, 1/2, -1/2, -1/2, -1/6, -1/6, 1/6),
     930            (1/2, -1/2, 1/2, -1/2, -1/2, -1/6, -1/6, 1/6),
     931            (0, 0, 1, 0, 0, 1/3, 1/3, -1/3),
     932            (1/2, 1/2, -1/2, -1/2, -1/2, -1/6, -1/6, 1/6),
     933            (0, 1, 0, 0, 0, 1/3, 1/3, -1/3),
     934            (1, 0, 0, 0, 0, 1/3, 1/3, -1/3),
     935            (0, -1, 0, 0, 0, 1/3, 1/3, -1/3),
     936            (0, 0, -1, 0, 0, 1/3, 1/3, -1/3),
     937            (0, 0, 0, -1, 0, 1/3, 1/3, -1/3),
     938            (0, 0, 0, 0, -1, 1/3, 1/3, -1/3),
     939            (-1/2, -1/2, -1/2, -1/2, -1/2, -1/6, -1/6, 1/6),
     940            (-1, 0, 0, 0, 0, 1/3, 1/3, -1/3)]
    941941        """
    942         R=self.parent().weight_lattice_realization().fundamental_weights()
    943         return sum(cmp(i,0)*R[abs(i)] for i in self.value)
     942        R=self.parent().weight_lattice_realization().fundamental_weights()
     943        return sum(cmp(i,0)*R[abs(i)] for i in self.value)
    944944
    945945    def e(self, i):
    946946        r"""
    947947        Returns the action of `e_i` on self.
    948948       
    949949        EXAMPLES::
    950        
    951             sage: C = CrystalOfLetters(['E',6])
    952             sage: C([-1,3]).e(1)
    953             [1]
    954             sage: C([-2,-3,4]).e(2)
    955             [-3, 2]
    956             sage: C([1]).e(1)
     950       
     951            sage: C = CrystalOfLetters(['E',6])
     952            sage: C([-1,3]).e(1)
     953            [1]
     954            sage: C([-2,-3,4]).e(2)
     955            [-3, 2]
     956            sage: C([1]).e(1)
    957957        """
    958958        assert i in self.index_set()
    959959
    class Crystal_of_letters_type_E6_element 
    10391039       
    10401040        EXAMPLES::
    10411041
    1042             sage: C = CrystalOfLetters(['E',6])
    1043             sage: C([1]).f(1)
    1044             [-1, 3]
    1045             sage: C([-6]).f(1)
     1042            sage: C = CrystalOfLetters(['E',6])
     1043            sage: C([1]).f(1)
     1044            [-1, 3]
     1045            sage: C([-6]).f(1)
    10461046        """
    10471047        assert i in self.index_set()
    10481048
    class Crystal_of_letters_type_E6_element 
    11301130    TESTS::
    11311131
    11321132        sage: C = CrystalOfLetters(['E',6], dual = True)
    1133         sage: C.module_generators
    1134         [[6]]
    1135         sage: all(b==b.retract(b.lift()) for b in C)
    1136         True
    1137         sage: C.list()
    1138         [[6], [5, -6], [4, -5], [2, 3, -4], [3, -2], [1, 2, -3], [2, -1], [1, 4, -2, -3],
    1139         [4, -1, -2], [1, 5, -4], [3, 5, -1, -4], [5, -3], [1, 6, -5], [3, 6, -1, -5], [4, 6, -3, -5],
    1140         [2, 6, -4], [6, -2], [1, -6], [3, -1, -6], [4, -3, -6], [2, 5, -4, -6], [5, -2, -6], [2, -5],
    1141         [4, -2, -5], [3, -4], [1, -3], [-1]]
     1133        sage: C.module_generators
     1134        [[6]]
     1135        sage: all(b==b.retract(b.lift()) for b in C)
     1136        True
     1137        sage: C.list()
     1138        [[6], [5, -6], [4, -5], [2, 3, -4], [3, -2], [1, 2, -3], [2, -1], [1, 4, -2, -3],
     1139        [4, -1, -2], [1, 5, -4], [3, 5, -1, -4], [5, -3], [1, 6, -5], [3, 6, -1, -5], [4, 6, -3, -5],
     1140        [2, 6, -4], [6, -2], [1, -6], [3, -1, -6], [4, -3, -6], [2, 5, -4, -6], [5, -2, -6], [2, -5],
     1141        [4, -2, -5], [3, -4], [1, -3], [-1]]
    11421142        sage: C.check()
    11431143        True
    1144         sage: all(b.f(i).e(i) == b for i in C.index_set() for b in C if b.f(i) is not None)
    1145         True
    1146         sage: all(b.e(i).f(i) == b for i in C.index_set() for b in C if b.e(i) is not None)
    1147         True
    1148         sage: G = C.digraph()
    1149         sage: G.show(edge_labels=true, figsize=12, vertex_size=1)
     1144        sage: all(b.f(i).e(i) == b for i in C.index_set() for b in C if b.f(i) is not None)
     1145        True
     1146        sage: all(b.e(i).f(i) == b for i in C.index_set() for b in C if b.e(i) is not None)
     1147        True
     1148        sage: G = C.digraph()
     1149        sage: G.show(edge_labels=true, figsize=12, vertex_size=1)
    11501150    """
    11511151
    11521152    def __repr__(self):
    1153         """
    1154         In their full representation, the vertices of this crystal are labeled
    1155         by their weight. For example vertex [-2,1] indicates that a 2-arrow
    1156         is coming into this vertex, and a 1-arrow is leaving the vertex.
    1157         Specifying the option element_print_style = 'compact' for a given crystal C,
    1158         labels the vertices of this crystal by the 27 letters -ABCDEFGHIJKLMNOPQRSTUVWXYZ
    1159        
    1160         EXAMPLES::
     1153        """
     1154        In their full representation, the vertices of this crystal are labeled
     1155        by their weight. For example vertex [-2,1] indicates that a 2-arrow
     1156        is coming into this vertex, and a 1-arrow is leaving the vertex.
     1157        Specifying the option element_print_style = 'compact' for a given crystal C,
     1158        labels the vertices of this crystal by the 27 letters -ABCDEFGHIJKLMNOPQRSTUVWXYZ
     1159       
     1160        EXAMPLES::
    11611161
    11621162            sage: C = CrystalOfLetters(['E',6], element_print_style = 'compact', dual = True)
    1163             sage: C.list()
    1164             [-, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z]
    1165             """
    1166         if self.parent()._element_print_style == 'compact':
    1167             l=['-','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
    1168             return l[self.parent().list().index(self)]
    1169         return "%s"%self.value
     1163            sage: C.list()
     1164            [-, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z]
     1165            """
     1166        if self.parent()._element_print_style == 'compact':
     1167            l=['-','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
     1168            return l[self.parent().list().index(self)]
     1169        return "%s"%self.value
    11701170
    11711171    def __hash__(self):
    1172         return hash(tuple(self.value))
     1172        return hash(tuple(self.value))
    11731173
    11741174    def lift(self):
    1175         """
    1176         Lifts an element of self to the crystal of letters CrystalOfLetters(['E',6])
    1177         by taking its inverse weight.
     1175        """
     1176        Lifts an element of self to the crystal of letters CrystalOfLetters(['E',6])
     1177        by taking its inverse weight.
    11781178
    1179         EXAMPLES::
     1179        EXAMPLES::
    11801180
    1181             sage: C = CrystalOfLetters(['E',6], dual = True)
    1182             sage: b=C.module_generators[0]
    1183             sage: b.lift()
    1184             [-6]
    1185         """
    1186         return self.parent()._ambient([-i for i in self.value])
    1187        
     1181            sage: C = CrystalOfLetters(['E',6], dual = True)
     1182            sage: b=C.module_generators[0]
     1183            sage: b.lift()
     1184            [-6]
     1185        """
     1186        return self.parent()._ambient([-i for i in self.value])
     1187       
    11881188    def retract(self, p):
    1189         """
    1190         Retracts element p, which is an element in CrystalOfLetters(['E',6]) to
    1191         an element in CrystalOfLetters(['E',6], dual = True) by taking its inverse weight.
     1189        """
     1190        Retracts element p, which is an element in CrystalOfLetters(['E',6]) to
     1191        an element in CrystalOfLetters(['E',6], dual = True) by taking its inverse weight.
    11921192
    1193         EXAMPLES::
     1193        EXAMPLES::
    11941194
    1195             sage: C = CrystalOfLetters(['E',6])
    1196             sage: Cd = CrystalOfLetters(['E',6], dual = True)
    1197             sage: b = Cd.module_generators[0]
    1198             sage: p = C([-1,3])
    1199             sage: b.retract(p)
    1200             [1, -3]
    1201             sage: b.retract(None)
    1202         """
    1203         if p is None:
    1204             return None
    1205         return self.parent()([-i for i in p.value])
     1195            sage: C = CrystalOfLetters(['E',6])
     1196            sage: Cd = CrystalOfLetters(['E',6], dual = True)
     1197            sage: b = Cd.module_generators[0]
     1198            sage: p = C([-1,3])
     1199            sage: b.retract(p)
     1200            [1, -3]
     1201            sage: b.retract(None)
     1202        """
     1203        if p is None:
     1204            return None
     1205        return self.parent()([-i for i in p.value])
    12061206   
    12071207    def e(self, i):
    12081208        r"""
    class Crystal_of_letters_type_E6_element 
    12101210       
    12111211        EXAMPLES::
    12121212
    1213             sage: C = CrystalOfLetters(['E',6], dual = True)
    1214             sage: C([-1]).e(1)
    1215             [1, -3]
     1213            sage: C = CrystalOfLetters(['E',6], dual = True)
     1214            sage: C([-1]).e(1)
     1215            [1, -3]
    12161216        """
    1217         return self.retract(self.lift().f(i))
     1217        return self.retract(self.lift().f(i))
    12181218
    12191219    def f(self, i):
    12201220        r"""
    class Crystal_of_letters_type_E6_element 
    12221222       
    12231223        EXAMPLES::
    12241224
    1225             sage: C = CrystalOfLetters(['E',6], dual = True)
    1226             sage: C([6]).f(6)
    1227             [5, -6]
    1228             sage: C([6]).f(1)
     1225            sage: C = CrystalOfLetters(['E',6], dual = True)
     1226            sage: C([6]).f(6)
     1227            [5, -6]
     1228            sage: C([6]).f(1)
    12291229        """
    1230         return self.retract(self.lift().e(i))
     1230        return self.retract(self.lift().e(i))
    12311231
    12321232    def weight(self):
    12331233        """
    class Crystal_of_letters_type_E6_element 
    12361236        EXAMPLES::
    12371237
    12381238            sage: C = CrystalOfLetters(['E',6], dual = True)
    1239             sage: b=C.module_generators[0]
    1240             sage: b.weight()
    1241             (0, 0, 0, 0, 1, -1/3, -1/3, 1/3)
     1239            sage: b=C.module_generators[0]
     1240            sage: b.weight()
     1241            (0, 0, 0, 0, 1, -1/3, -1/3, 1/3)
    12421242            sage: [v.weight() for v in C]
    1243             [(0, 0, 0, 0, 1, -1/3, -1/3, 1/3),
    1244             (0, 0, 0, 1, 0, -1/3, -1/3, 1/3),
    1245             (0, 0, 1, 0, 0, -1/3, -1/3, 1/3),
    1246             (0, 1, 0, 0, 0, -1/3, -1/3, 1/3),
    1247             (-1, 0, 0, 0, 0, -1/3, -1/3, 1/3),
    1248             (1, 0, 0, 0, 0, -1/3, -1/3, 1/3),
    1249             (1/2, 1/2, 1/2, 1/2, 1/2, 1/6, 1/6, -1/6),
    1250             (0, -1, 0, 0, 0, -1/3, -1/3, 1/3),
    1251             (-1/2, -1/2, 1/2, 1/2, 1/2, 1/6, 1/6, -1/6),
    1252             (0, 0, -1, 0, 0, -1/3, -1/3, 1/3),
    1253             (-1/2, 1/2, -1/2, 1/2, 1/2, 1/6, 1/6, -1/6),
    1254             (1/2, -1/2, -1/2, 1/2, 1/2, 1/6, 1/6, -1/6),
    1255             (0, 0, 0, -1, 0, -1/3, -1/3, 1/3),
    1256             (-1/2, 1/2, 1/2, -1/2, 1/2, 1/6, 1/6, -1/6),
    1257             (1/2, -1/2, 1/2, -1/2, 1/2, 1/6, 1/6, -1/6),
    1258             (1/2, 1/2, -1/2, -1/2, 1/2, 1/6, 1/6, -1/6),
    1259             (-1/2, -1/2, -1/2, -1/2, 1/2, 1/6, 1/6, -1/6),
    1260             (0, 0, 0, 0, -1, -1/3, -1/3, 1/3),
    1261             (-1/2, 1/2, 1/2, 1/2, -1/2, 1/6, 1/6, -1/6),
    1262             (1/2, -1/2, 1/2, 1/2, -1/2, 1/6, 1/6, -1/6),
    1263             (1/2, 1/2, -1/2, 1/2, -1/2, 1/6, 1/6, -1/6),
    1264             (-1/2, -1/2, -1/2, 1/2, -1/2, 1/6, 1/6, -1/6),
    1265             (1/2, 1/2, 1/2, -1/2, -1/2, 1/6, 1/6, -1/6),
    1266             (-1/2, -1/2, 1/2, -1/2, -1/2, 1/6, 1/6, -1/6),
    1267             (-1/2, 1/2, -1/2, -1/2, -1/2, 1/6, 1/6, -1/6),
    1268             (1/2, -1/2, -1/2, -1/2, -1/2, 1/6, 1/6, -1/6),
    1269             (0, 0, 0, 0, 0, 2/3, 2/3, -2/3)]
     1243            [(0, 0, 0, 0, 1, -1/3, -1/3, 1/3),
     1244            (0, 0, 0, 1, 0, -1/3, -1/3, 1/3),
     1245            (0, 0, 1, 0, 0, -1/3, -1/3, 1/3),
     1246            (0, 1, 0, 0, 0, -1/3, -1/3, 1/3),
     1247            (-1, 0, 0, 0, 0, -1/3, -1/3, 1/3),
     1248            (1, 0, 0, 0, 0, -1/3, -1/3, 1/3),
     1249            (1/2, 1/2, 1/2, 1/2, 1/2, 1/6, 1/6, -1/6),
     1250            (0, -1, 0, 0, 0, -1/3, -1/3, 1/3),
     1251            (-1/2, -1/2, 1/2, 1/2, 1/2, 1/6, 1/6, -1/6),
     1252            (0, 0, -1, 0, 0, -1/3, -1/3, 1/3),
     1253            (-1/2, 1/2, -1/2, 1/2, 1/2, 1/6, 1/6, -1/6),
     1254            (1/2, -1/2, -1/2, 1/2, 1/2, 1/6, 1/6, -1/6),
     1255            (0, 0, 0, -1, 0, -1/3, -1/3, 1/3),
     1256            (-1/2, 1/2, 1/2, -1/2, 1/2, 1/6, 1/6, -1/6),
     1257            (1/2, -1/2, 1/2, -1/2, 1/2, 1/6, 1/6, -1/6),
     1258            (1/2, 1/2, -1/2, -1/2, 1/2, 1/6, 1/6, -1/6),
     1259            (-1/2, -1/2, -1/2, -1/2, 1/2, 1/6, 1/6, -1/6),
     1260            (0, 0, 0, 0, -1, -1/3, -1/3, 1/3),
     1261            (-1/2, 1/2, 1/2, 1/2, -1/2, 1/6, 1/6, -1/6),
     1262            (1/2, -1/2, 1/2, 1/2, -1/2, 1/6, 1/6, -1/6),
     1263            (1/2, 1/2, -1/2, 1/2, -1/2, 1/6, 1/6, -1/6),
     1264            (-1/2, -1/2, -1/2, 1/2, -1/2, 1/6, 1/6, -1/6),
     1265            (1/2, 1/2, 1/2, -1/2, -1/2, 1/6, 1/6, -1/6),
     1266            (-1/2, -1/2, 1/2, -1/2, -1/2, 1/6, 1/6, -1/6),
     1267            (-1/2, 1/2, -1/2, -1/2, -1/2, 1/6, 1/6, -1/6),
     1268            (1/2, -1/2, -1/2, -1/2, -1/2, 1/6, 1/6, -1/6),
     1269            (0, 0, 0, 0, 0, 2/3, 2/3, -2/3)]
    12701270        """
    1271         return -self.lift().weight()
     1271        return -self.lift().weight()
    12721272
    12731273
    12741274#########################
    class Crystal_of_letters_type_E7_element 
    13071307    """
    13081308
    13091309    def __hash__(self):
    1310         return hash(tuple(self.value))
     1310        return hash(tuple(self.value))
    13111311   
    13121312    def weight(self):
    13131313        """
    class Crystal_of_letters_type_E7_element 
    13551355        Returns the action of `e_i` on self.
    13561356
    13571357        EXAMPLES::
    1358        
    1359             sage: C = CrystalOfLetters(['E',7])
    1360             sage: C([7]).e(7)
    1361             sage: C([-7,6]).e(7)
    1362             [7]
     1358       
     1359            sage: C = CrystalOfLetters(['E',7])
     1360            sage: C([7]).e(7)
     1361            sage: C([-7,6]).e(7)
     1362            [7]
    13631363        """
    13641364        assert i in self.index_set()
    13651365
    class Crystal_of_letters_type_E7_element 
    15411541       
    15421542        EXAMPLES::
    15431543
    1544             sage: C = CrystalOfLetters(['E',7])
    1545             sage: C([-7]).f(7)
    1546             sage: C([7]).f(7)
    1547             [-7, 6]
     1544            sage: C = CrystalOfLetters(['E',7])
     1545            sage: C([-7]).f(7)
     1546            sage: C([7]).f(7)
     1547            [-7, 6]
    15481548        """
    15491549        assert i in self.index_set()
    15501550
  • sage/combinat/crystals/spins.py

    diff --git a/sage/combinat/crystals/spins.py b/sage/combinat/crystals/spins.py
    a b def CrystalOfSpins(ct): 
    7575         [-1, 1, -1],
    7676         [-1, -1, 1],
    7777         [-1, -1, -1]]
    78         sage: C.cartan_type()
    79         ['B', 3]
     78        sage: C.cartan_type()
     79        ['B', 3]
    8080   
    8181    ::
    8282   
  • sage/combinat/crystals/tensor_product.py

    diff --git a/sage/combinat/crystals/tensor_product.py b/sage/combinat/crystals/tensor_product.py
    a b from sage.structure.unique_representatio 
    4242
    4343class TestParent(UniqueRepresentation, Parent):
    4444    def _repr_(self):
    45         return "A parent for tests"
     45        return "A parent for tests"
    4646
    4747class ImmutableListWithParent(CombinatorialObject, Element):
    4848    r"""
    class ImmutableListWithParent(Combinator 
    5959        sage: l._list
    6060        [1, 2, 3]
    6161        sage: l.parent()
    62         A parent for tests
     62        A parent for tests
    6363        sage: l.sibling([2,1]) == ImmutableListWithParent(TestParent(), [2,1])
    6464        True
    6565        sage: l.reversed()
    class ImmutableListWithParent(Combinator 
    7575            sage: from sage.combinat.crystals.tensor_product import ImmutableListWithParent, TestParent
    7676            sage: l = ImmutableListWithParent(TestParent(), [1,2,3])
    7777            sage: l.parent()
    78             A parent for tests
    79             sage: parent(l)
    80             A parent for tests
     78            A parent for tests
     79            sage: parent(l)
     80            A parent for tests
    8181            sage: TestSuite(l).run(skip = "_test_category")
    8282        """
    83         Element.__init__(self, parent)
     83        Element.__init__(self, parent)
    8484        CombinatorialObject.__init__(self, list)
    8585
    8686    def _repr_(self):
    class ImmutableListWithParent(Combinator 
    114114               self._list == other._list
    115115
    116116    def __ne__(self, other):
    117         return not self.__eq__(other)
     117        return not self.__eq__(other)
    118118
    119119    # Should go in Element? Sets.ElementMethods?
    120120    # How to define them conditionally, only of __lt__ is defined?
    121121    def __le__(self, other):
    122         if self == other:
    123             return True
    124         else:
    125             return self.__le__(other)
     122        if self == other:
     123            return True
     124        else:
     125            return self.__le__(other)
    126126
    127127    def __gt__(self, other):
    128         if parent(self) is not parent(other):
    129             return NotImplemented
    130         return other.__lt__(self)
     128        if parent(self) is not parent(other):
     129            return NotImplemented
     130        return other.__lt__(self)
    131131
    132132    def __ge__(self, other):
    133         if self == other:
    134             return True
    135         else:
    136             return self.__le__(other)
     133        if self == other:
     134            return True
     135        else:
     136            return self.__le__(other)
    137137
    138138    def sibling(self, l):
    139139        """
    class ImmutableListWithParent(Combinator 
    150150            sage: m = l.sibling([2,3,4]); m
    151151            [2, 3, 4]
    152152            sage: m.parent()
    153             A parent for tests
     153            A parent for tests
    154154        """
    155155        return self.__class__(self.parent(), list=l)
    156156
    class ImmutableListWithParent(Combinator 
    182182            sage: l.set_index(1,4)
    183183            [1, 4, 3]
    184184            sage: _.parent()
    185             A parent for tests
     185            A parent for tests
    186186        """
    187187        l = [i for i in self._list]
    188188        l[k] = value
    class TensorProductOfCrystalsElement(Imm 
    417417    def __lt__(self, other):
    418418        """
    419419        Non elements of the crystal are incomparable with elements of the crystal
    420         (or should it return NotImplemented?)
     420        (or should it return NotImplemented?)
    421421
    422         Comparison of two elements of this crystal:
     422        Comparison of two elements of this crystal:
    423423         - different length: incomparable
    424424         - otherwise lexicographicaly, considering self[i] and other[i]
    425425           as incomparable if self[i] < other[i] returns NotImplemented
    426426        """
    427         if parent(self) is not parent(other):
    428             return False
    429         if len(self) != len(other):
     427        if parent(self) is not parent(other):
     428            return False
     429        if len(self) != len(other):
    430430            return False
    431431        for i in range(len(self)):
    432             if (self[i] < other[i]) == True:
    433                 return True
    434             if (self[i] > other[i]) == True:
     432            if (self[i] < other[i]) == True:
     433                return True
     434            if (self[i] > other[i]) == True:
    435435                return False
    436436        return False
    437437
    class TensorProductOfCrystalsElement(Imm 
    467467            sage: T = TensorProductOfCrystals(C,C)
    468468            sage: T(C(1),C(2)).weight()
    469469            (1, 1, 0, 0)
    470             sage: T=CrystalOfTableaux(['D',4],shape=[])
    471             sage: T.list()[0].weight()
    472             (0, 0, 0, 0)
     470            sage: T=CrystalOfTableaux(['D',4],shape=[])
     471            sage: T.list()[0].weight()
     472            (0, 0, 0, 0)
    473473        """
    474474        return sum((self[j].weight() for j in range(len(self))), self.parent().weight_lattice_realization().zero())
    475475
    class TensorProductOfCrystalsElement(Imm 
    593593        return [len(self)-1-l[j] for j in range(len(l))]
    594594
    595595    def _latex_(self):
    596         """
    597         Returns latex code for self.
     596        """
     597        Returns latex code for self.
    598598
    599         EXAMPLES::
     599        EXAMPLES::
    600600
    601             sage: C = CrystalOfLetters(["A",2])
    602             sage: D = CrystalOfTableaux(["A",2], shape=[2])
    603             sage: E = TensorProductOfCrystals(C,D)
    604             sage: E.module_generators[0]._latex_()
     601            sage: C = CrystalOfLetters(["A",2])
     602            sage: D = CrystalOfTableaux(["A",2], shape=[2])
     603            sage: E = TensorProductOfCrystals(C,D)
     604            sage: E.module_generators[0]._latex_()
    605605            '1\\otimes{\\def\\lr#1{\\multicolumn{1}{|@{\\hspace{.6ex}}c@{\\hspace{.6ex}}|}{\\raisebox{-.3ex}{$#1$}}}\n\\raisebox{-.6ex}{$\\begin{array}[b]{cc}\n\\cline{1-1}\\cline{2-2}\n\\lr{1}&\\lr{1}\\\\\n\\cline{1-1}\\cline{2-2}\n\\end{array}$}\n}'
    606606        """
    607         return '\otimes'.join(latex(c) for c in self)
     607        return '\otimes'.join(latex(c) for c in self)
    608608
    609609CrystalOfWords.Element = TensorProductOfCrystalsElement
    610610
    class CrystalOfTableauxElement(TensorPro 
    888888        return repr(self.to_tableau())
    889889
    890890    def pp(self):
    891         """
    892         EXAMPLES::
     891        """
     892        EXAMPLES::
    893893
    894894            sage: T = CrystalOfTableaux(['A',3], shape = [2,2])
    895895            sage: t = T(rows=[[1,2],[3,4]])
    896             sage: t.pp()
    897             1  2
    898             3  4
    899         """
    900         return self.to_tableau().pp()
     896            sage: t.pp()
     897            1  2
     898            3  4
     899        """
     900        return self.to_tableau().pp()
    901901
    902902    def _latex_(self):
    903903        r"""