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 1 1 from sage.combinat.free_module import CombinatorialFreeModule, CombinatorialFreeModuleElement 2 2 from root_lattice_realization import RootLatticeRealizationElement 3 3 from weight_lattice_realization import WeightLatticeRealization 4 from sage.modules.free_module import FreeModule5 4 from sage.rings.all import ZZ, QQ 6 from sage.modules.free_module_element import vector7 5 8 6 class AmbientSpace(CombinatorialFreeModule, WeightLatticeRealization): 9 7 r""" … … 15 13 as attribute. There is no safe default implementation for the later, 16 14 so none is provided. 17 15 """ 18 19 # FIXME: attribute or method?20 def dimension(self):21 """22 Returns the dimension of this ambient space23 """24 raise NotImplementedError25 26 @classmethod27 def smallest_base_ring(cls):28 """29 Returns the smallest ground ring over which the ambient space can be realized30 """31 return QQ;32 33 16 def __init__(self, root_system, base_ring): 34 17 """ 35 18 EXAMPLES: … … 38 21 True 39 22 """ 40 23 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, 46 27 prefix='e') 47 28 48 29 # FIXME: here for backward compatibility; 49 30 # Should we use dimension everywhere? 50 31 self.n = self.dimension() 51 32 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 52 63 def __repr__(self): 53 64 """ 54 TEST:65 EXAMPLES: 55 66 sage: RootSystem(['A',4]).ambient_lattice() 56 Ambient lattice forthe Root system of type ['A', 4]67 Ambient lattice of the Root system of type ['A', 4] 57 68 sage: RootSystem(['B',4]).ambient_space() 58 Ambient space forthe Root system of type ['B', 4]69 Ambient space of the Root system of type ['B', 4] 59 70 60 71 """ 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) 66 82 67 83 def __call__(self, v): 68 84 """ … … 72 88 (1, 2, 3, 4, 5) 73 89 """ 74 90 # This adds coercion from a list 75 if isinstance(v, list) or isinstance(v, tuple):91 if isinstance(v, (list, tuple)): 76 92 K = self.base_ring() 77 93 return self._from_dict(dict([(i,K(v[i])) for i in range(len(v))])) 78 94 else: 79 95 return CombinatorialFreeModule.__call__(self, v) 80 81 # For backward compatibility82 def _term(self, i):83 self.term(i)84 96 85 97 def __getitem__(self,i): 86 98 """ … … 94 106 return self.term(i-1) 95 107 96 108 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 """ 97 115 return self 98 116 99 117 def simple_coroot(self, i): 100 118 r""" 101 119 Returns the i-th simple coroot, as an element of this space 102 120 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) 112 130 """ 113 131 return self.simple_root(i).associated_coroot() 114 132 115 133 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 """ 116 146 # TODO: get rid of this as one can use the generic implementation 117 147 # (i.e. scalar and associated coroot are implemented) 118 148 return lambda v: v-2*root.inner_product(v)/root.inner_product(root)*root … … 145 175 return 0 146 176 147 177 class AmbientSpaceElement(CombinatorialFreeModuleElement, RootLatticeRealizationElement): 148 149 178 # For backward compatibility 150 179 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 """ 151 186 return str(self.to_vector()) 152 187 153 188 def inner_product(self, lambdacheck): 154 189 """ 155 190 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 157 199 """ 158 200 assert(lambdacheck.parent() == self.parent()) 159 201 return sum((c*self[t] for (t,c) in lambdacheck), … … 163 205 dot_product = inner_product 164 206 165 207 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 """ 166 217 # FIXME: make it work over ZZ! 167 218 return self * (2/self.inner_product(self)) 168 219 -
a/sage/combinat/root_system/cartan_type.py
old new 15 15 # 16 16 # http://www.gnu.org/licenses/ 17 17 #***************************************************************************** 18 #import sage.combinat.root_system.root_system as root_system19 18 from sage.combinat import root_system 20 from cartan_matrix import cartan_matrix21 19 from sage.rings.all import ZZ 20 from sage.structure.sage_object import SageObject 22 21 23 22 # TODO: 24 23 # Get rid of almost all runtype type checking by extending the class hierarchy with: … … 35 34 # Implement coxeter diagrams for non crystalographic 36 35 # Implement dual ambient space 37 36 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? 45 class CartanTypeFactory(SageObject): 46 def __call__(self, *args): 47 """ 48 Returns an object corresponding to the Cartan type t. 38 49 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 48 57 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 59 82 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:])]) 84 88 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]]]) 88 133 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) 137 135 138 136 CartanType = CartanTypeFactory() 139 137 140 class CartanType_abstract :138 class CartanType_abstract(SageObject): 141 139 r""" 142 140 Abstract class for cartan types 143 141 144 142 Subclasses should implement: 145 143 146 144 type() 145 type_string() 147 146 dynkin_diagram() 148 147 cartan_matrix() 149 148 is_finite() 150 149 is_affine() 151 150 is_irreducible() 152 151 """ 153 154 152 def type(self): 155 153 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 157 162 """ 158 163 return None 159 164 160 165 def rank(self): 161 166 """ 162 167 Returns the rank of self. 168 163 169 EXAMPLES: 164 170 sage: CartanType(['A', 4]).rank() 165 171 4 … … 168 174 sage: CartanType(['I', 8]).rank() 169 175 2 170 176 """ 171 raise notImplementedError177 raise NotImplementedError 172 178 173 179 def dual(self): 174 180 """ 175 Returns the dual cartan type, possibly just as a formal dual 181 Returns the dual cartan type, possibly just as a formal dual. 176 182 177 183 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 188 187 """ 189 188 return root_system.type_dual.CartanType(self) 190 189 191 def type_string(self):192 r"""193 Returns a string suitable for type-specific code dispatch194 195 EXAMPLES: (TODO!)196 """197 return "type_None"198 199 190 def is_reducible(self): 200 191 """ 201 192 Report whether the root system is reducible (i.e. not simple), … … 203 194 systems. 204 195 205 196 EXAMPLES: 206 sage: CartanType("A2xB3").is_reducible()207 True208 sage: CartanType(['A',2]).is_reducible()209 False197 sage: CartanType("A2xB3").is_reducible() 198 True 199 sage: CartanType(['A',2]).is_reducible() 200 False 210 201 """ 211 202 return not self.is_irreducible() 212 203 213 204 def is_irreducible(self): 214 205 """ 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 216 216 217 217 """ 218 218 raise NotImplementedError 219 219 220 220 def is_finite(self): 221 221 """ 222 Returns whether this Cartan type is finite. 222 Returns whether this Cartan type is finite. This should be overridden in 223 any subclass. 223 224 224 225 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 225 233 sage: CartanType(['A',4]).is_finite() 226 234 True 227 sage: CartanType(['A',4, 1]).is_finite()235 sage: CartanType(['A',4, 1]).is_finite() 228 236 False 229 237 """ 230 238 raise NotImplementedError … … 306 314 # Maybe we want a separate class for affine 307 315 308 316 class CartanType_simple(CartanType_abstract): 309 """ 310 TESTS: 317 def __cmp__(self, other): 318 """ 319 TESTS: 311 320 sage: ct1 = CartanType(['A',4]) 312 321 sage: ct2 = CartanType(['A',4]) 313 322 sage: ct3 = CartanType(['A',5]) … … 316 325 sage: ct1 != ct3 317 326 True 318 327 """ 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) 319 333 320 334 def __hash__(self): 321 335 """ … … 344 358 return self.t[x] 345 359 346 360 def is_irreducible(self): 361 """ 362 EXAMPLES: 363 sage: CartanType(['A', 3]).is_irreducible() 364 True 365 """ 347 366 return True 348 367 349 368 def dynkin_diagram(self): … … 382 401 """ 383 402 return self.letter 384 403 385 def type_string(self):404 def dual(self): 386 405 """ 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] 388 411 389 EXAMPLES:390 sage: CartanType(['A', 4]).type_string()391 'type_A'392 sage: CartanType(['A', 4, 1]).type_string()393 'type_A_affine'394 412 """ 395 if self.is_affine():396 return "type_%s_affine"%self.letter397 else:398 return "type_%s"%self.letter399 400 def dual(self):401 413 if self.type() in ["A", "D", "E"]: 402 414 return self 403 415 else: 404 416 return CartanType_abstract.dual(self) 405 417 406 def is_irreducible(self):407 """408 Report that this Cartan type is irreducible.409 """410 return True411 418 412 419 class CartanType_simple_finite(CartanType_simple): 413 420 r""" … … 441 448 self.letter = t[0] 442 449 self.n = t[1] 443 450 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 444 457 445 458 def __repr__(self): 446 459 """ … … 459 472 """ 460 473 return 2 461 474 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 469 475 def rank(self): 476 """ 477 EXAMPLES: 478 sage: CartanType(["A", 3]).rank() 479 3 480 """ 470 481 if self.letter == "I": 471 482 return 2 472 483 else: 473 484 return self.n 485 474 486 def is_finite(self): 487 """ 488 EXAMPLES: 489 sage: CartanType(["A", 3]).is_finite() 490 True 491 """ 475 492 return True 476 493 477 494 def is_affine(self): 495 """ 496 EXAMPLES: 497 sage: CartanType(["A", 3]).is_affine() 498 False 499 """ 478 500 return False 479 501 480 502 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 """ 481 510 return self.letter in ["A", "B", "C", "D", "E", "F", "G"] 482 511 483 512 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 """ 484 520 return self.letter in ["A", "D", "E"] 485 521 486 522 def affine(self): … … 494 530 return CartanType([self.letter, self.n, 1]) 495 531 496 532 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 """ 497 546 if self.type() == "B": 498 547 return CartanType(["C",self.n]) 499 548 elif self.type() == "C": … … 506 555 r""" 507 556 A class for affine simple Cartan types 508 557 """ 509 510 558 def __init__(self, t): 511 559 """ 512 560 EXAMPLES: … … 541 589 self.n = t[1] 542 590 self.affine = t[2] 543 591 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 544 598 def __repr__(self): 545 599 """ 546 600 TESTS: … … 551 605 return "['%s', %s, %s]"%(self.letter, self.n, self.affine) 552 606 553 607 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) 555 621 if c != 0: 556 622 return c 557 623 else: … … 566 632 return 3 567 633 568 634 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 """ 569 642 if self.affine == 3 and self.letter == 'D': 570 643 return self.n-1 571 644 elif self.affine == 2 and self.letter == 'A': … … 576 649 return self.n 577 650 578 651 def is_finite(self): 652 """ 653 EXAMPLES: 654 sage: CartanType(['A', 3, 1]).is_finite() 655 False 656 """ 579 657 return False 580 658 581 659 def is_affine(self): 660 """ 661 EXAMPLES: 662 sage: CartanType(['A', 3, 1]).is_affine() 663 True 664 """ 582 665 return True 583 666 584 667 def is_crystalographic(self): 668 """ 669 EXAMPLES: 670 sage: CartanType(['A', 3, 1]).is_crystalographic() 671 True 672 """ 585 673 return True 586 674 587 675 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 """ 588 687 if self.affine != 1: 589 688 return False 590 689 if self.letter == "A": -
a/sage/combinat/root_system/dynkin_diagram.py
old new 18 18 from sage.graphs.all import DiGraph 19 19 from cartan_type import CartanType, CartanType_abstract 20 20 from cartan_matrix import cartan_matrix 21 import cartan_type22 21 from root_system import RootSystem 23 22 24 23 def DynkinDiagram(*args): … … 54 53 ct = t.cartan_type() 55 54 else: 56 55 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 59 59 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 66 62 try: 67 63 return function(ct) 68 64 except KeyError: … … 70 66 71 67 def dynkin_diagram(t): 72 68 """ 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 74 78 """ 79 import warnings 80 warnings.warn("dynkin_diagram is deprecated, use DynkinDiagram instead!", DeprecationWarning, stacklevel=2) 75 81 return DynkinDiagram(t) 76 82 77 83 78 84 class DynkinDiagram_class(DiGraph, CartanType_abstract): 79 85 def __init__(self, t): 86 """ 87 EXAMPLES: 88 sage: d = DynkinDiagram(["A", 3]) 89 sage: d == loads(dumps(d)) 90 True 91 """ 80 92 DiGraph.__init__(self) 81 93 self._cartan_type = t 82 94 83 95 def __repr__(self): 84 96 """ 85 97 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] 88 100 """ 89 101 if self._cartan_type is None: 90 102 return "Dynkin diagram of rank %s"%self.rank() … … 92 104 return "Dynkin diagram of type %s"%self._cartan_type 93 105 94 106 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 """ 95 118 DiGraph.add_edge(self, i, j, label) 96 119 if not self.has_edge(j,i): 97 120 self.add_edge(j,i,1) … … 99 122 def index_set(self): 100 123 """ 101 124 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] 106 129 """ 107 130 return self.vertices() 108 131 109 132 def cartan_type(self): 110 133 """ 111 134 EXAMPLES: 112 sage: DynkinDiagram("A2","B2","F4").cartan_type()113 A2xB2xF4135 sage: DynkinDiagram("A2","B2","F4").cartan_type() 136 A2xB2xF4 114 137 """ 115 138 return self._cartan_type 116 139 117 140 def rank(self): 118 141 r""" 119 returns the index set for this Dynkin diagram142 Returns the index set for this Dynkin diagram 120 143 121 144 EXAMPLES: 145 sage: DynkinDiagram(['C',3]).rank() 146 3 147 sage: DynkinDiagram("A2","B2","F4").rank() 148 8 122 149 """ 123 150 return self.num_verts() 124 151 125 152 def dynkin_diagram(self): 153 """ 154 EXAMPLES: 155 sage: DynkinDiagram(['C',3]).dynkin_diagram() 156 Dynkin diagram of type ['C', 3] 157 """ 126 158 return self 127 159 128 160 def cartan_matrix(self): … … 218 250 sage: [ (i,a) for (i,a) in g.column(3) ] 219 251 [(3, 2), (2, -1), (4, -2)] 220 252 221 Caveat: broken in sage < 3.0.3222 253 """ 223 254 return [(j,2)] + [(i,-m) for (j1, i, m) in self.outgoing_edges(j)] 224 255 … … 284 315 if n is not None: 285 316 if t[1] != n: 286 317 raise ValueError, "t[1] must be = %s"%n 287 288 ##############################################################################289 # Everything below is type by type hardcoded data. It probably should be moved290 # into the type_... files291 ##############################################################################292 293 294 def type_a(t):295 """296 Returns the graph corresponding to the Dynkin diagram297 of type A.298 299 EXAMPLES:300 sage: from sage.combinat.root_system.dynkin_diagram import type_a301 sage: ct = CartanType(['A',3])302 &n