Ticket #3664: trac_3664-2.patch

File trac_3664-2.patch, 145.2 kB (added by mhansen, 4 months ago)
  • a/sage/combinat/root_system/ambient_space.py

    old new  
    11from sage.combinat.free_module import CombinatorialFreeModule, CombinatorialFreeModuleElement 
    22from root_lattice_realization import RootLatticeRealizationElement 
    33from weight_lattice_realization import WeightLatticeRealization 
    4 from sage.modules.free_module import FreeModule 
    54from sage.rings.all import ZZ, QQ 
    6 from sage.modules.free_module_element import vector 
    75 
    86class AmbientSpace(CombinatorialFreeModule, WeightLatticeRealization): 
    97    r""" 
     
    1513    as attribute. There is no safe default implementation for the later, 
    1614    so none is provided. 
    1715    """ 
    18  
    19     # FIXME: attribute or method? 
    20     def dimension(self): 
    21         """ 
    22         Returns the dimension of this ambient space 
    23         """ 
    24         raise NotImplementedError 
    25      
    26     @classmethod 
    27     def smallest_base_ring(cls): 
    28         """ 
    29         Returns the smallest ground ring over which the ambient space can be realized 
    30         """ 
    31         return QQ; 
    32  
    3316    def __init__(self, root_system, base_ring): 
    3417        """ 
    3518        EXAMPLES: 
     
    3821            True 
    3922        """ 
    4023        self.root_system = root_system 
    41         basis_name = "alphacheck" if root_system.dualSide else "alpha" 
    42         CombinatorialFreeModule.__init__(self, base_ring,\ 
    43                                          #range(1,self.dimension()+1),\ 
    44                                          range(0,self.dimension()),\ 
    45                                          element_class = AmbientSpaceElement,\ 
     24        CombinatorialFreeModule.__init__(self, base_ring, 
     25                                         range(0,self.dimension()), 
     26                                         element_class = AmbientSpaceElement, 
    4627                                         prefix='e') 
    4728 
    4829        # FIXME: here for backward compatibility; 
    4930        # Should we use dimension everywhere? 
    5031        self.n = self.dimension() 
    5132 
     33 
     34 
     35    # FIXME: attribute or method? 
     36    def dimension(self): 
     37        """ 
     38        Returns the dimension of this ambient space. 
     39 
     40        EXAMPLES: 
     41            sage: from sage.combinat.root_system.ambient_space import AmbientSpace 
     42            sage: e = RootSystem(['F',4]).ambient_space() 
     43            sage: AmbientSpace.dimension(e) 
     44            Traceback (most recent call last): 
     45            ... 
     46            NotImplementedError 
     47 
     48        """ 
     49        raise NotImplementedError 
     50     
     51    @classmethod 
     52    def smallest_base_ring(cls): 
     53        """ 
     54        Returns the smallest ground ring over which the ambient space can be realized. 
     55 
     56        EXAMPLES: 
     57            sage: e = RootSystem(['F',4]).ambient_space() 
     58            sage: e.smallest_base_ring() 
     59            Rational Field 
     60        """ 
     61        return QQ 
     62 
    5263    def __repr__(self): 
    5364        """ 
    54         TEST
     65        EXAMPLES
    5566            sage: RootSystem(['A',4]).ambient_lattice() 
    56             Ambient lattice for the Root system of type ['A', 4] 
     67            Ambient lattice of the Root system of type ['A', 4] 
    5768            sage: RootSystem(['B',4]).ambient_space() 
    58             Ambient space for the Root system of type ['B', 4] 
     69            Ambient space of the Root system of type ['B', 4] 
    5970 
    6071        """ 
    61         if self.base_ring() == ZZ: 
    62             space = "lattice" 
    63         else: 
    64             space = "space" 
    65         return "Ambient "+space+" for the %s"%self.root_system 
     72        return self._name_string() 
     73     
     74    def _name_string(self, capitalize=True, base_ring=False, type=True): 
     75        """ 
     76        EXAMPLES: 
     77            sage: RootSystem(['A',4]).ambient_lattice()._name_string() 
     78            "Ambient lattice of the Root system of type ['A', 4]" 
     79 
     80        """ 
     81        return self._name_string_helper("ambient", capitalize=capitalize, base_ring=base_ring, type=type) 
    6682 
    6783    def __call__(self, v): 
    6884        """ 
     
    7288            (1, 2, 3, 4, 5) 
    7389        """ 
    7490        # This adds coercion from a list 
    75         if isinstance(v, list) or isinstance(v, tuple): 
     91        if isinstance(v, (list, tuple)): 
    7692            K = self.base_ring() 
    7793            return self._from_dict(dict([(i,K(v[i])) for i in range(len(v))])) 
    7894        else: 
    7995            return CombinatorialFreeModule.__call__(self, v) 
    80  
    81     # For backward compatibility 
    82     def _term(self, i): 
    83         self.term(i) 
    8496 
    8597    def __getitem__(self,i): 
    8698        """ 
     
    94106        return self.term(i-1) 
    95107 
    96108    def coroot_lattice(self): 
     109        """ 
     110        EXAMPLES: 
     111            sage: e = RootSystem(["A", 3]).ambient_lattice() 
     112            sage: e.coroot_lattice() 
     113            Ambient lattice of the Root system of type ['A', 3] 
     114        """ 
    97115        return self 
    98116 
    99117    def simple_coroot(self, i): 
    100118        r""" 
    101119        Returns the i-th simple coroot, as an element of this space 
    102120 
    103         EXAMPLE
    104         sage: R = RootSystem(["A",3]) 
    105         sage: L = R.ambient_lattice () 
    106         sage: L.simple_coroot(1) 
    107         (1, -1, 0, 0) 
    108         sage: L.simple_coroot(2) 
    109         (0, 1, -1, 0) 
    110         sage: L.simple_coroot(3) 
    111         (0, 0, 1, -1) 
     121        EXAMPLES
     122            sage: R = RootSystem(["A",3]) 
     123            sage: L = R.ambient_lattice() 
     124            sage: L.simple_coroot(1) 
     125            (1, -1, 0, 0) 
     126            sage: L.simple_coroot(2) 
     127            (0, 1, -1, 0) 
     128            sage: L.simple_coroot(3) 
     129            (0, 0, 1, -1) 
    112130        """         
    113131        return self.simple_root(i).associated_coroot() 
    114132 
    115133    def reflection(self, root, coroot=None): 
     134        """ 
     135        EXAMPLES: 
     136            sage: e = RootSystem(["A", 3]).ambient_lattice() 
     137            sage: a = e.simple_root(0); a 
     138            (-1, 0, 0, 0) 
     139            sage: b = e.simple_root(1); b 
     140            (1, -1, 0, 0) 
     141            sage: s_a = e.reflection(a) 
     142            sage: s_a(b) 
     143            (0, -1, 0, 0) 
     144 
     145        """ 
    116146        # TODO: get rid of this as one can use the generic implementation 
    117147        # (i.e. scalar and associated coroot are implemented) 
    118148        return lambda v: v-2*root.inner_product(v)/root.inner_product(root)*root 
     
    145175        return 0 
    146176 
    147177class AmbientSpaceElement(CombinatorialFreeModuleElement, RootLatticeRealizationElement): 
    148  
    149178    # For backward compatibility 
    150179    def __repr__(self): 
     180        """ 
     181        EXAMPLES: 
     182            sage: e = RootSystem(['A',2]).ambient_space() 
     183            sage: e.simple_root(0) 
     184            (-1, 0, 0) 
     185        """ 
    151186        return str(self.to_vector()) 
    152187     
    153188    def inner_product(self, lambdacheck): 
    154189        """ 
    155190        The scalar product with elements of the coroot lattice 
    156         embedded in the ambient space 
     191        embedded in the ambient space. 
     192 
     193        EXAMPLES: 
     194            sage: e = RootSystem(['A',2]).ambient_space() 
     195            sage: a = e.simple_root(0); a 
     196            (-1, 0, 0) 
     197            sage: a.inner_product(a) 
     198            2 
    157199        """ 
    158200        assert(lambdacheck.parent() == self.parent()) 
    159201        return sum((c*self[t] for (t,c) in lambdacheck), 
     
    163205    dot_product = inner_product 
    164206 
    165207    def associated_coroot(self): 
     208        """ 
     209        EXAMPLES: 
     210            sage: e = RootSystem(['F',4]).ambient_space() 
     211            sage: a = e.simple_root(0); a 
     212            (1/2, -1/2, -1/2, -1/2) 
     213            sage: a.associated_coroot() 
     214            (1, -1, -1, -1) 
     215 
     216        """ 
    166217        # FIXME: make it work over ZZ! 
    167218        return self * (2/self.inner_product(self)) 
    168219 
  • a/sage/combinat/root_system/cartan_type.py

    old new  
    1515# 
    1616#                  http://www.gnu.org/licenses/ 
    1717#***************************************************************************** 
    18 #import sage.combinat.root_system.root_system as root_system 
    1918from sage.combinat import root_system 
    20 from cartan_matrix import cartan_matrix 
    2119from sage.rings.all import ZZ 
     20from sage.structure.sage_object import SageObject 
    2221 
    2322# TODO: 
    2423# Get rid of almost all runtype type checking by extending the class hierarchy with: 
     
    3534# Implement coxeter diagrams for non crystalographic 
    3635# Implement dual ambient space 
    3736 
     37# Intention: we want simultaneously CartanType to be a factory for 
     38# the various subtypes of CartanType_abstract, as in: 
     39#     CartanType(["A",4,1]) 
     40# and to behaves as a "module" for some extra utilities: 
     41#     CartanType.samples() 
     42# 
     43# Implementation: CartanType is the unique instance of this class 
     44# CartanTypeFactory. Is there a better/more standard way to do it? 
     45class CartanTypeFactory(SageObject): 
     46    def __call__(self, *args): 
     47        """ 
     48        Returns an object corresponding to the Cartan type t. 
    3849 
    39 class CartanTypeFactory: 
    40     # Intention: we want simultaneously CartanType to be a factory for 
    41     # the various subtypes of CartanType_abstract, as in: 
    42     #     CartanType(["A",4,1]) 
    43     # and to behaves as a "module" for some extra utilities: 
    44     #     CartanType.samples() 
    45     # 
    46     # Implementation: CartanType is the unique instance of this class 
    47     # CartanTypeFactory. Is there a better/more standard way to do it? 
     50        INPUT: 
     51        [letter, rank] 
     52        where letter is one of 'A','B','C','D','E','F','G' and rank 
     53        is the rank. An alternative string notation is allowed. 
     54        A third optional parameter is permitted for affine 
     55        types. Reducible types may be entered by giving a list of 
     56        irreducible types or by a single string  
    4857 
    49   def __call__(self, *args): 
    50     """ 
    51     Returns an object corresponding to the Cartan type t. 
    52     INPUT: 
    53        [letter, rank] 
    54     where letter is one of 'A','B','C','D','E','F','G' and rank 
    55     is the rank. An alternative string notation is allowed. 
    56     A third optional parameter is permitted for affine 
    57     types. Reducible types may be entered by giving a list of 
    58     irreducible types or by a single string  
     58        EXAMPLES: 
     59            sage: CartanType(['A',4]) 
     60            ['A', 4] 
     61            sage: CartanType("A4") 
     62            ['A', 4] 
     63            sage: CartanType(['A',2],['B',2]) 
     64            A2xB2 
     65            sage: CartanType(['A',2],['B',2]).is_reducible() 
     66            True 
     67            sage: CartanType("A2xB2") 
     68            A2xB2 
     69            sage: CartanType("A2","B2") == CartanType("A2xB2") 
     70            True 
     71            sage: CartanType(['A',4,1]) 
     72            ['A', 4, 1] 
     73            sage: CartanType(['A',4,1]).is_affine() 
     74            True 
     75        """ 
     76        if len(args) == 1: 
     77            t = args[0] 
     78        else: 
     79            t = args 
     80        if isinstance(t, CartanType_abstract): 
     81            return t 
    5982 
    60     EXAMPLES: 
    61         sage: CartanType(['A',4]) 
    62         ['A', 4] 
    63         sage: CartanType("A4") 
    64         ['A', 4] 
    65         sage: CartanType(['A',2],['B',2]) 
    66         A2xB2 
    67         sage: CartanType(['A',2],['B',2]).is_reducible() 
    68         True 
    69         sage: CartanType("A2xB2") 
    70         A2xB2 
    71         sage: CartanType("A2","B2") == CartanType("A2xB2") 
    72         True 
    73         sage: CartanType(['A',4,1]) 
    74         ['A', 4, 1] 
    75         sage: CartanType(['A',4,1]).is_affine() 
    76         True 
    77     """ 
    78     if len(args) == 1: 
    79         t = args[0] 
    80     else: 
    81         t = args 
    82     if isinstance(t, CartanType_abstract): 
    83         return t 
     83        if type(t)==str: 
     84            if "x" in t: 
     85                return root_system.type_reducible.CartanType([CartanType(u) for u in t.split("x")]) 
     86            else: 
     87                return CartanType([t[0], eval(t[1:])]) 
    8488 
    85     if type(t)==str: 
    86         if "x" in t: 
    87             return root_system.type_reducible.CartanType([CartanType(u) for u in t.split("x")]) 
     89        t = list(t) 
     90             
     91        if type(t[0]) == str and t[1] in ZZ: 
     92            if len(t) == 2: 
     93                return CartanType_simple_finite(t) 
     94            elif len(t) == 3: 
     95                return CartanType_simple_affine(t) 
     96 
     97        return root_system.type_reducible.CartanType([ CartanType(subt) for subt in t ]) 
     98 
     99    def samples(self, finite=False, affine=False, crystalographic=False): 
     100        """ 
     101        Returns a sample of the implemented cartan types 
     102         
     103        With finite=True resp. affine=True, one can restrict to finite 
     104        resp. affine only cartan types 
     105 
     106        EXAMPLES: 
     107            sage: CartanType.samples(finite=True) 
     108            [['A', 1], ['A', 5], ['B', 5], ['C', 5], ['D', 5], ['E', 6], ['E', 7], ['E', 8], ['F', 4], ['G', 2], ['I', 5], ['H', 3], ['H', 4]] 
     109             
     110            sage: CartanType.samples(affine=True) 
     111            [['A', 1, 1], ['A', 5, 1], ['B', 5, 1], ['C', 5, 1], ['D', 5, 1], ['E', 6, 1], ['E', 7, 1], ['E', 8, 1], ['F', 4, 1], ['G', 2, 1], ['A', 2, 2], ['A', 10, 2], ['A', 9, 2], ['D', 5, 2], ['D', 4, 3], ['E', 6, 2]] 
     112             
     113            sage: CartanType.samples() 
     114            [['A', 1], ['A', 5], ['B', 5], ['C', 5], ['D', 5], ['E', 6], ['E', 7], ['E', 8], ['F', 4], ['G', 2], ['I', 5], ['H', 3], ['H', 4], ['A', 1, 1], ['A', 5, 1], ['B', 5, 1], ['C', 5, 1], ['D', 5, 1], ['E', 6, 1], ['E', 7, 1], ['E', 8, 1], ['F', 4, 1], ['G', 2, 1], ['A', 2, 2], ['A', 10, 2], ['A', 9, 2], ['D', 5, 2], ['D', 4, 3], ['E', 6, 2]] 
     115            sage: CartanType.samples(crystalographic=True) 
     116            [['A', 1], ['A', 5], ['B', 5], ['C', 5], ['D', 5], ['E', 6], ['E', 7], ['E', 8], ['F', 4], ['G', 2], ['A', 1, 1], ['A', 5, 1], ['B', 5, 1], ['C', 5, 1], ['D', 5, 1], ['E', 6, 1], ['E', 7, 1], ['E', 8, 1], ['F', 4, 1], ['G', 2, 1], ['A', 2, 2], ['A', 10, 2], ['A', 9, 2], ['D', 5, 2], ['D', 4, 3], ['E', 6, 2]] 
     117        """ 
     118        if crystalographic: 
     119            return [ t for t in CartanType.samples(finite=finite, affine=affine) if t.is_crystalographic() ] 
     120        if finite: 
     121            return([CartanType(t) for t in [["A", 1], ["A", 5], ["B", 5], ["C", 5], ["D", 5], 
     122                                            ["E", 6], ["E", 7], ["E", 8], 
     123                                            ["F", 4], 
     124                                            ["G", 2], 
     125                                            ["I", 5], 
     126                                            ["H", 3], ["H", 4]]]) 
     127        elif affine: 
     128            return([t.affine() for t in CartanType.samples(finite=True, crystalographic=True)] + 
     129                   [CartanType(t) for t in [["A", 2, 2], ["A", 10, 2], ["A", 9, 2], 
     130                                            ["D", 5, 2], 
     131                                            ["D", 4, 3], 
     132                                            ["E", 6, 2]]]) 
    88133        else: 
    89             return CartanType([t[0], eval(t[1:])]) 
    90  
    91     t = list(t) 
    92          
    93     if type(t[0]) == str and t[1] in ZZ: 
    94         if len(t) == 2: 
    95             return CartanType_simple_finite(t) 
    96         elif len(t) == 3: 
    97             return CartanType_simple_affine(t) 
    98  
    99     return root_system.type_reducible.CartanType([ CartanType(subt) for subt in t ]) 
    100  
    101   def samples(self, finite=False, affine=False, crystalographic=False): 
    102       """ 
    103       Returns a sample of the implemented cartan types 
    104  
    105       With finite=True resp. affine=True, one can restrict to finite 
    106       resp. affine only cartan types 
    107  
    108       EXAMPLES: 
    109           sage: CartanType.samples(finite=True) 
    110           [['A', 1], ['A', 5], ['B', 5], ['C', 5], ['D', 5], ['E', 6], ['E', 7], ['E', 8], ['F', 4], ['G', 2], ['I', 5], ['H', 3], ['H', 4]] 
    111  
    112           sage: CartanType.samples(affine=True) 
    113           [['A', 1, 1], ['A', 5, 1], ['B', 5, 1], ['C', 5, 1], ['D', 5, 1], ['E', 6, 1], ['E', 7, 1], ['E', 8, 1], ['F', 4, 1], ['G', 2, 1], ['A', 2, 2], ['A', 10, 2], ['A', 9, 2], ['D', 5, 2], ['D', 4, 3], ['E', 6, 2]] 
    114  
    115           sage: CartanType.samples() 
    116           [['A', 1], ['A', 5], ['B', 5], ['C', 5], ['D', 5], ['E', 6], ['E', 7], ['E', 8], ['F', 4], ['G', 2], ['I', 5], ['H', 3], ['H', 4], ['A', 1, 1], ['A', 5, 1], ['B', 5, 1], ['C', 5, 1], ['D', 5, 1], ['E', 6, 1], ['E', 7, 1], ['E', 8, 1], ['F', 4, 1], ['G', 2, 1], ['A', 2, 2], ['A', 10, 2], ['A', 9, 2], ['D', 5, 2], ['D', 4, 3], ['E', 6, 2]] 
    117           sage: CartanType.samples(crystalographic=True) 
    118           [['A', 1], ['A', 5], ['B', 5], ['C', 5], ['D', 5], ['E', 6], ['E', 7], ['E', 8], ['F', 4], ['G', 2], ['A', 1, 1], ['A', 5, 1], ['B', 5, 1], ['C', 5, 1], ['D', 5, 1], ['E', 6, 1], ['E', 7, 1], ['E', 8, 1], ['F', 4, 1], ['G', 2, 1], ['A', 2, 2], ['A', 10, 2], ['A', 9, 2], ['D', 5, 2], ['D', 4, 3], ['E', 6, 2]] 
    119       """ 
    120       if crystalographic: 
    121           return [ t for t in CartanType.samples(finite=finite, affine=affine) if t.is_crystalographic() ] 
    122       if finite: 
    123           return([CartanType(t) for t in [["A", 1], ["A", 5], ["B", 5], ["C", 5], ["D", 5], 
    124                                           ["E", 6], ["E", 7], ["E", 8], 
    125                                           ["F", 4], 
    126                                           ["G", 2], 
    127                                           ["I", 5], 
    128                                           ["H", 3], ["H", 4]]]) 
    129       elif affine: 
    130           return([t.affine() for t in CartanType.samples(finite=True, crystalographic=True)] + 
    131                  [CartanType(t) for t in [["A", 2, 2], ["A", 10, 2], ["A", 9, 2], 
    132                                           ["D", 5, 2], 
    133                                           ["D", 4, 3], 
    134                                           ["E", 6, 2]]]); 
    135       else: 
    136           return CartanType.samples(finite=True) + CartanType.samples(affine=True) 
     134            return CartanType.samples(finite=True) + CartanType.samples(affine=True) 
    137135 
    138136CartanType = CartanTypeFactory() 
    139137 
    140 class CartanType_abstract
     138class CartanType_abstract(SageObject)
    141139    r""" 
    142140    Abstract class for cartan types 
    143141 
    144142    Subclasses should implement: 
    145143 
    146144    type() 
     145    type_string() 
    147146    dynkin_diagram() 
    148147    cartan_matrix() 
    149148    is_finite() 
    150149    is_affine() 
    151150    is_irreducible() 
    152151    """ 
    153  
    154152    def type(self): 
    155153        r""" 
    156         Returns the type of self, or None if unknown 
     154        Returns the type of self, or None if unknown. This method should be overridden in  
     155        any subclass. 
     156 
     157        EXAMPLES: 
     158            sage: from sage.combinat.root_system.cartan_type import CartanType_abstract 
     159            sage: C = CartanType_abstract() 
     160            sage: C.type() is None 
     161            True 
    157162        """ 
    158163        return None 
    159164 
    160165    def rank(self): 
    161166        """ 
    162167        Returns the rank of self. 
     168 
    163169        EXAMPLES: 
    164170            sage: CartanType(['A', 4]).rank() 
    165171            4 
     
    168174            sage: CartanType(['I', 8]).rank() 
    169175            2 
    170176        """ 
    171         raise notImplementedError 
     177        raise NotImplementedError 
    172178 
    173179    def dual(self): 
    174180        """ 
    175         Returns the dual cartan type, possibly just as a formal dual 
     181        Returns the dual cartan type, possibly just as a formal dual. 
    176182 
    177183        EXAMPLES: 
    178             sage: CartanType(['A',3]).dual() 
    179             ['A', 3] 
    180             sage: CartanType(['D',4]).dual() 
    181             ['D', 4] 
    182             sage: CartanType(['E',8]).dual() 
    183             ['E', 8] 
    184             sage: CartanType(['B',3]).dual() 
    185             ['C', 3] 
    186             sage: CartanType(['C',2]).dual() 
    187             ['B', 2] 
     184            sage: CartanType(['F',4]).dual() 
     185            ['F', 4]^* 
     186 
    188187        """ 
    189188        return root_system.type_dual.CartanType(self) 
    190189     
    191     def type_string(self): 
    192         r""" 
    193         Returns a string suitable for type-specific code dispatch 
    194  
    195         EXAMPLES: (TODO!) 
    196         """ 
    197         return "type_None" 
    198  
    199190    def is_reducible(self): 
    200191        """ 
    201192        Report whether the root system is reducible (i.e. not simple), 
     
    203194        systems. 
    204195         
    205196        EXAMPLES: 
    206           sage: CartanType("A2xB3").is_reducible() 
    207           True 
    208           sage: CartanType(['A',2]).is_reducible() 
    209           False 
     197            sage: CartanType("A2xB3").is_reducible() 
     198            True 
     199            sage: CartanType(['A',2]).is_reducible() 
     200            False 
    210201        """ 
    211202        return not self.is_irreducible() 
    212203 
    213204    def is_irreducible(self): 
    214205        """ 
    215         Report whether this Cartan type is irreducible (i.e. simple) 
     206        Report whether this Cartan type is irreducible (i.e. simple).  This 
     207        should be overridden in any subclass. 
     208 
     209        EXAMPLES: 
     210            sage: from sage.combinat.root_system.cartan_type import CartanType_abstract 
     211            sage: C = CartanType_abstract() 
     212            sage: C.is_irreducible() 
     213            Traceback (most recent call last): 
     214            ... 
     215            NotImplementedError 
    216216         
    217217        """ 
    218218        raise NotImplementedError 
    219219 
    220220    def is_finite(self): 
    221221        """ 
    222         Returns whether this Cartan type is finite. 
     222        Returns whether this Cartan type is finite.  This should be overridden in 
     223        any subclass. 
    223224 
    224225        EXAMPLES: 
     226            sage: from sage.combinat.root_system.cartan_type import CartanType_abstract 
     227            sage: C = CartanType_abstract() 
     228            sage: C.is_irreducible() 
     229            Traceback (most recent call last): 
     230            ... 
     231            NotImplementedError 
     232 
    225233            sage: CartanType(['A',4]).is_finite() 
    226234            True 
    227             sage: CartanType(['A',4,1]).is_finite() 
     235            sage: CartanType(['A',4, 1]).is_finite() 
    228236            False 
    229237        """ 
    230238        raise NotImplementedError 
     
    306314# Maybe we want a separate class for affine 
    307315 
    308316class CartanType_simple(CartanType_abstract): 
    309     """ 
    310     TESTS: 
     317    def __cmp__(self, other): 
     318        """ 
     319        TESTS: 
    311320            sage: ct1 = CartanType(['A',4]) 
    312321            sage: ct2 = CartanType(['A',4]) 
    313322            sage: ct3 = CartanType(['A',5]) 
     
    316325            sage: ct1 != ct3 
    317326            True 
    318327        """ 
     328        if other.__class__ != self.__class__: 
     329            return cmp(self.__class__, other.__class__) 
     330        if other.letter != self.letter: 
     331            return cmp(self.letter, other.letter) 
     332        return cmp(self.n, other.n) 
    319333 
    320334    def __hash__(self): 
    321335        """ 
     
    344358        return self.t[x] 
    345359 
    346360    def is_irreducible(self): 
     361        """ 
     362        EXAMPLES: 
     363            sage: CartanType(['A', 3]).is_irreducible() 
     364            True 
     365        """ 
    347366        return True 
    348367 
    349368    def dynkin_diagram(self): 
     
    382401        """ 
    383402        return self.letter 
    384403 
    385     def type_string(self): 
     404    def dual(self): 
    386405        """ 
    387         Returns a string suitable for type-specific code dispatch 
     406        EXAMPLES: 
     407            sage: CartanType(["A", 3]).dual() 
     408            ['A', 3] 
     409            sage: CartanType(["B", 3]).dual() 
     410            ['C', 3] 
    388411 
    389         EXAMPLES: 
    390             sage: CartanType(['A', 4]).type_string() 
    391             'type_A' 
    392             sage: CartanType(['A', 4, 1]).type_string() 
    393             'type_A_affine' 
    394412        """ 
    395         if self.is_affine(): 
    396             return "type_%s_affine"%self.letter 
    397         else: 
    398             return "type_%s"%self.letter 
    399  
    400     def dual(self): 
    401413        if self.type() in ["A", "D", "E"]: 
    402414            return self 
    403415        else: 
    404416            return CartanType_abstract.dual(self) 
    405417 
    406     def is_irreducible(self): 
    407         """ 
    408         Report that this Cartan type is irreducible. 
    409         """ 
    410         return True 
    411418 
    412419class CartanType_simple_finite(CartanType_simple): 
    413420    r""" 
     
    441448        self.letter = t[0] 
    442449        self.n = t[1] 
    443450 
     451        # Get the python module containing type-specific information, 
     452        # if it exists 
     453        self.tools = getattr(root_system, 
     454                             "type_"+self.type(), 
     455                             root_system.type_None) 
     456 
    444457 
    445458    def __repr__(self): 
    446459        """ 
     
    459472        """ 
    460473        return 2 
    461474 
    462     def __cmp__(self, other): 
    463         if other.__class__ != self.__class__: 
    464             return cmp(self.__class__, other.__class__) 
    465         if other.letter != self.letter: 
    466             return cmp(self.letter, other.letter) 
    467         return cmp(self.n, other.n) 
    468  
    469475    def rank(self): 
     476        """ 
     477        EXAMPLES: 
     478            sage: CartanType(["A", 3]).rank() 
     479            3 
     480        """ 
    470481        if self.letter == "I": 
    471482            return 2 
    472483        else: 
    473484            return self.n 
     485 
    474486    def is_finite(self): 
     487        """         
     488        EXAMPLES: 
     489            sage: CartanType(["A", 3]).is_finite() 
     490            True 
     491        """ 
    475492        return True 
    476493 
    477494    def is_affine(self): 
     495        """ 
     496        EXAMPLES: 
     497            sage: CartanType(["A", 3]).is_affine() 
     498            False 
     499        """ 
    478500        return False 
    479501 
    480502    def is_crystalographic(self): 
     503        """ 
     504        EXAMPLES: 
     505            sage: CartanType(["A", 3]).is_crystalographic() 
     506            True 
     507            sage: CartanType(["I", 2]).is_crystalographic() 
     508            False 
     509        """ 
    481510        return self.letter in ["A", "B", "C", "D", "E", "F", "G"] 
    482511 
    483512    def is_simply_laced(self): 
     513        """ 
     514        EXAMPLES: 
     515            sage: CartanType(['A',3]).is_simply_laced() 
     516            True 
     517            sage: CartanType(['B',3]).is_simply_laced() 
     518            False 
     519        """ 
    484520        return self.letter in  ["A", "D", "E"] 
    485521 
    486522    def affine(self): 
     
    494530        return CartanType([self.letter, self.n, 1]) 
    495531 
    496532    def dual(self): 
     533        """ 
     534        EXAMPLES: 
     535            sage: CartanType(['A',3]).dual() 
     536            ['A', 3] 
     537            sage: CartanType(['D',4]).dual() 
     538            ['D', 4] 
     539            sage: CartanType(['E',8]).dual() 
     540            ['E', 8] 
     541            sage: CartanType(['B',3]).dual() 
     542            ['C', 3] 
     543            sage: CartanType(['C',2]).dual() 
     544            ['B', 2] 
     545        """ 
    497546        if self.type() == "B": 
    498547            return CartanType(["C",self.n]) 
    499548        elif self.type() == "C": 
     
    506555    r""" 
    507556    A class for affine simple Cartan types 
    508557    """ 
    509  
    510558    def __init__(self, t): 
    511559        """ 
    512560        EXAMPLES: 
     
    541589        self.n = t[1] 
    542590        self.affine = t[2] 
    543591 
     592        # Get the python module containing type-specific information, 
     593        # if it exists 
     594        self.tools = getattr(root_system, 
     595                             'type_'+self.type(), 
     596                             root_system.type_None); 
     597 
    544598    def __repr__(self): 
    545599        """ 
    546600        TESTS: 
     
    551605        return "['%s', %s, %s]"%(self.letter, self.n, self.affine) 
    552606 
    553607    def __cmp__(self, other): 
    554         c = CartanType_simple_finite.cmp(self, other) 
     608        """ 
     609        EXAMPLES: 
     610            sage: ct1 = CartanType(['A',3, 1]) 
     611            sage: ct2 = CartanType(['B',3, 1]) 
     612            sage: ct3 = CartanType(['A',3]) 
     613            sage: ct1 == ct1 
     614            True 
     615            sage: ct1 == ct2 
     616            False 
     617            sage: ct1 == ct3 
     618            False 
     619        """ 
     620        c = CartanType_simple.__cmp__(self, other) 
    555621        if c != 0: 
    556622            return c 
    557623        else: 
     
    566632        return 3 
    567633 
    568634    def rank(self): 
     635        """ 
     636        EXAMPLES: 
     637            sage: CartanType(['D', 4, 3]).rank() 
     638            3 
     639            sage: CartanType(['B', 4, 1]).rank() 
     640            4 
     641        """ 
    569642        if self.affine == 3 and self.letter == 'D': 
    570643            return self.n-1 
    571644        elif self.affine == 2 and self.letter == 'A': 
     
    576649            return self.n 
    577650 
    578651    def is_finite(self): 
     652        """ 
     653        EXAMPLES: 
     654            sage: CartanType(['A', 3, 1]).is_finite() 
     655            False 
     656        """ 
    579657        return False 
    580658 
    581659    def is_affine(self): 
     660        """ 
     661        EXAMPLES: 
     662            sage: CartanType(['A', 3, 1]).is_affine() 
     663            True 
     664        """ 
    582665        return True 
    583666 
    584667    def is_crystalographic(self): 
     668        """ 
     669        EXAMPLES: 
     670            sage: CartanType(['A', 3, 1]).is_crystalographic() 
     671            True 
     672        """ 
    585673        return True 
    586674 
    587675    def is_simply_laced(self): 
     676        """ 
     677        EXAMPLES: 
     678            sage: CartanType(['A', 3, 1]).is_simply_laced() 
     679            True 
     680            sage: CartanType(['D', 4, 3]).is_simply_laced() 
     681            False 
     682            sage: CartanType(['D', 4, 1]).is_simply_laced() 
     683            True 
     684            sage: CartanType(['B', 4, 1]).is_simply_laced() 
     685            False 
     686        """ 
    588687        if self.affine != 1: 
    589688            return False 
    590689        if self.letter == "A": 
  • a/sage/combinat/root_system/dynkin_diagram.py

    old new  
    1818from sage.graphs.all import DiGraph 
    1919from cartan_type import CartanType, CartanType_abstract 
    2020from cartan_matrix import cartan_matrix 
    21 import cartan_type 
    2221from root_system import RootSystem 
    2322 
    2423def DynkinDiagram(*args): 
     
    5453        ct = t.cartan_type() 
    5554    else: 
    5655        ct = CartanType(t) 
    57     if ct.is_reducible(): 
    58         function = globals()["type_reducible"] 
     56 
     57    if ct.is_affine(): 
     58        function = ct.tools.affine_dynkin_diagram 
    5959    else: 
    60         letter = ct[0].lower() 
    61         affine = "" 
    62         ct = CartanType(ct) 
    63         if ct.is_affine(): 
    64             affine = "_affine" 
    65         function = globals()["type_"+letter+affine] 
     60        function = ct.tools.dynkin_diagram 
     61   
    6662    try: 
    6763        return function(ct) 
    6864    except KeyError: 
     
    7066 
    7167def dynkin_diagram(t): 
    7268    """ 
    73     Deprecated; please use DynkinDiagram 
     69    Returns the Dynkin diagram of type t.   
     70 
     71    Note that this function is deprecated, and that you should use DynkinDiagram  
     72    instead as this will be disappearing in the near future. 
     73 
     74    EXAMPLES: 
     75        sage: dynkin_diagram(["A", 3]) 
     76        Dynkin diagram of type ['A', 3] 
     77 
    7478    """ 
     79    import warnings 
     80    warnings.warn("dynkin_diagram is deprecated, use DynkinDiagram instead!", DeprecationWarning, stacklevel=2) 
    7581    return DynkinDiagram(t) 
    7682 
    7783 
    7884class DynkinDiagram_class(DiGraph, CartanType_abstract): 
    7985    def __init__(self, t): 
     86        """ 
     87        EXAMPLES: 
     88            sage: d = DynkinDiagram(["A", 3]) 
     89            sage: d == loads(dumps(d)) 
     90            True 
     91        """ 
    8092        DiGraph.__init__(self) 
    8193        self._cartan_type = t 
    8294 
    8395    def __repr__(self): 
    8496        """ 
    8597        EXAMPLES: 
    86           sage: DynkinDiagram(['A',3]) 
    87           Dynkin diagram of type ['A', 3] 
     98            sage: DynkinDiagram(['A',3]) 
     99            Dynkin diagram of type ['A', 3] 
    88100        """ 
    89101        if self._cartan_type is None: 
    90102            return "Dynkin diagram of rank %s"%self.rank() 
     
    92104            return "Dynkin diagram of type %s"%self._cartan_type 
    93105 
    94106    def add_edge(self, i, j, label=1): 
     107        """ 
     108        EXAMPLES: 
     109            sage: from sage.combinat.root_system.dynkin_diagram import DynkinDiagram_class 
     110            sage: d = DynkinDiagram_class(CartanType(['A',3])) 
     111            sage: list(sorted(d.edges())) 
     112            [] 
     113            sage: d.add_edge(2, 3) 
     114            sage: list(sorted(d.edges())) 
     115            [(2, 3, 1), (3, 2, 1)] 
     116 
     117        """ 
    95118        DiGraph.add_edge(self, i, j, label) 
    96119        if not self.has_edge(j,i): 
    97120            self.add_edge(j,i,1) 
     
    99122    def index_set(self): 
    100123        """ 
    101124        EXAMPLES: 
    102           sage: DynkinDiagram(['C',3]).index_set() 
    103           [1, 2, 3] 
    104           sage: DynkinDiagram("A2","B2","F4").index_set() 
    105           [1, 2, 3, 4, 5, 6, 7, 8] 
     125             sage: DynkinDiagram(['C',3]).index_set() 
     126             [1, 2, 3] 
     127             sage: DynkinDiagram("A2","B2","F4").index_set() 
     128             [1, 2, 3, 4, 5, 6, 7, 8] 
    106129        """ 
    107130        return self.vertices() 
    108131         
    109132    def cartan_type(self): 
    110133        """ 
    111134        EXAMPLES: 
    112           sage: DynkinDiagram("A2","B2","F4").cartan_type() 
    113           A2xB2xF4 
     135            sage: DynkinDiagram("A2","B2","F4").cartan_type() 
     136            A2xB2xF4 
    114137        """ 
    115138        return self._cartan_type 
    116139 
    117140    def rank(self): 
    118141        r""" 
    119         returns the index set for this Dynkin diagram 
     142        Returns the index set for this Dynkin diagram 
    120143 
    121144        EXAMPLES: 
     145            sage: DynkinDiagram(['C',3]).rank() 
     146            3 
     147            sage: DynkinDiagram("A2","B2","F4").rank() 
     148            8 
    122149        """ 
    123150        return self.num_verts() 
    124151 
    125152    def dynkin_diagram(self): 
     153        """ 
     154        EXAMPLES: 
     155            sage: DynkinDiagram(['C',3]).dynkin_diagram() 
     156            Dynkin diagram of type ['C', 3] 
     157        """ 
    126158        return self 
    127159 
    128160    def cartan_matrix(self): 
     
    218250            sage: [ (i,a) for (i,a) in g.column(3) ] 
    219251            [(3, 2), (2, -1), (4, -2)] 
    220252 
    221         Caveat: broken in sage < 3.0.3 
    222253        """ 
    223254        return [(j,2)] + [(i,-m) for (j1, i, m) in self.outgoing_edges(j)] 
    224255 
     
    284315    if n is not None: 
    285316        if t[1] != n: 
    286317            raise ValueError, "t[1] must be = %s"%n 
    287  
    288 ############################################################################## 
    289 # Everything below is type by type hardcoded data. It probably should be moved 
    290 # into the type_... files 
    291 ############################################################################## 
    292  
    293  
    294 def type_a(t): 
    295     """ 
    296     Returns the graph corresponding to the Dynkin diagram 
    297     of type A. 
    298  
    299     EXAMPLES: 
    300         sage: from sage.combinat.root_system.dynkin_diagram import type_a 
    301         sage: ct = CartanType(['A',3]) 
    302&n