diff --git a/src/sage/combinat/root_system/cartan_matrix.py b/src/sage/combinat/root_system/cartan_matrix.py index c1560805dc7..ed56efa197c 100644 --- a/src/sage/combinat/root_system/cartan_matrix.py +++ b/src/sage/combinat/root_system/cartan_matrix.py @@ -903,6 +903,65 @@ def is_indecomposable(self): # consider the empty matrix to be indecomposable return comp_num <= 1 + @cached_method + def coxeter_matrix(self): + r""" + Return the Coxeter matrix for ``self``. + + .. SEEALSO:: :meth:`CartanType_abstract.coxeter_matrix` + + EXAMPLES:: + + sage: cm = CartanMatrix([[2,-5,0],[-2,2,-1],[0,-1,2]]) + sage: cm.coxeter_matrix() + [ 1 -1 2] + [-1 1 3] + [ 2 3 1] + sage: ct = CartanType([['A',2,2], ['B',3]]) + sage: ct.coxeter_matrix() + [ 1 -1 2 2 2] + [-1 1 2 2 2] + [ 2 2 1 3 2] + [ 2 2 3 1 4] + [ 2 2 2 4 1] + sage: ct.cartan_matrix().coxeter_matrix() == ct.coxeter_matrix() + True + """ + scalarproducts_to_order = {0: 2, 1: 3, 2: 4, 3: 6} + from sage.combinat.root_system.coxeter_matrix import CoxeterMatrix + I = self.index_set() + n = len(I) + M = matrix.identity(ZZ, n) + for i in range(n): + for j in range(i+1,n): + val = self[i,j] * self[j,i] + val = scalarproducts_to_order.get(val, -1) + M[i,j] = val + M[j,i] = val + return CoxeterMatrix(M, index_set=self.index_set(), cartan_type=self) + + @cached_method + def coxeter_diagram(self): + r""" + Construct the Coxeter diagram of ``self``. + + .. SEEALSO:: :meth:`CartanType_abstract.coxeter_diagram` + + EXAMPLES:: + + sage: cm = CartanMatrix([[2,-5,0],[-2,2,-1],[0,-1,2]]) + sage: G = cm.coxeter_diagram(); G + Graph on 3 vertices + sage: G.edges() + [(0, 1, +Infinity), (1, 2, 3)] + sage: ct = CartanType([['A',2,2], ['B',3]]) + sage: ct.coxeter_diagram() + Graph on 5 vertices + sage: ct.cartan_matrix().coxeter_diagram() == ct.coxeter_diagram() + True + """ + return self.coxeter_matrix().coxeter_graph() + def principal_submatrices(self, proper=False): """ Return a list of all principal submatrices of ``self``. diff --git a/src/sage/combinat/root_system/cartan_type.py b/src/sage/combinat/root_system/cartan_type.py index 26781f566c6..5c6c3486a84 100644 --- a/src/sage/combinat/root_system/cartan_type.py +++ b/src/sage/combinat/root_system/cartan_type.py @@ -1631,7 +1631,6 @@ def cartan_matrix(self): from sage.combinat.root_system.cartan_matrix import CartanMatrix return CartanMatrix(self.dynkin_diagram()) - @cached_method def coxeter_diagram(self): """ Return the Coxeter diagram for ``self``. @@ -1655,19 +1654,7 @@ def coxeter_diagram(self): sage: CartanType(['A',2,2]).coxeter_diagram().edges() [(0, 1, +Infinity)] """ - from sage.rings.infinity import infinity - scalarproducts_to_order = { 0: 2, 1: 3, 2: 4, 3: 6, 4: infinity } - from sage.graphs.graph import Graph - coxeter_diagram = Graph(multiedges=False) - a = self.dynkin_diagram() - I = self.index_set() - coxeter_diagram.add_vertices(I) - for i in I: - for j in a.neighbors_out(i): - # avoid adding the edge twice - if not coxeter_diagram.has_edge(i,j): - coxeter_diagram.add_edge(i,j, scalarproducts_to_order[a[i,j]*a[j,i]]) - return coxeter_diagram + return self.dynkin_diagram().coxeter_diagram() def is_crystallographic(self): """ diff --git a/src/sage/combinat/root_system/dynkin_diagram.py b/src/sage/combinat/root_system/dynkin_diagram.py index 3c889d5e0ea..32191bee515 100644 --- a/src/sage/combinat/root_system/dynkin_diagram.py +++ b/src/sage/combinat/root_system/dynkin_diagram.py @@ -805,6 +805,42 @@ def row(self, i): val = 2 if i not in self._odd_isotropic_roots else 0 return [(i,val)] + [(j,-m) for (j, i1, m) in self.incoming_edges(i)] + @cached_method + def coxeter_diagram(self): + r""" + Construct the Coxeter diagram of ``self``. + + .. SEEALSO:: :meth:`CartanType_abstract.coxeter_diagram` + + EXAMPLES:: + + sage: cm = CartanMatrix([[2,-5,0],[-2,2,-1],[0,-1,2]]) + sage: D = cm.dynkin_diagram() + sage: G = D.coxeter_diagram(); G + Graph on 3 vertices + sage: G.edges() + [(0, 1, +Infinity), (1, 2, 3)] + + sage: ct = CartanType([['A',2,2], ['B',3]]) + sage: ct.coxeter_diagram() + Graph on 5 vertices + sage: ct.dynkin_diagram().coxeter_diagram() == ct.coxeter_diagram() + True + """ + from sage.rings.infinity import infinity + scalarproducts_to_order = {0: 2, 1: 3, 2: 4, 3: 6} + from sage.graphs.graph import Graph + coxeter_diagram = Graph(multiedges=False) + I = self.index_set() + coxeter_diagram.add_vertices(I) + for i in I: + for j in self.neighbors_out(i): + # avoid adding the edge twice + if not coxeter_diagram.has_edge(i,j): + val = scalarproducts_to_order.get(self[i,j]*self[j,i], infinity) + coxeter_diagram.add_edge(i,j, val) + return coxeter_diagram.copy(immutable=True) + def precheck(t, letter=None, length=None, affine=None, n_ge=None, n=None): """ EXAMPLES:: diff --git a/src/sage/combinat/root_system/type_reducible.py b/src/sage/combinat/root_system/type_reducible.py index 2a503a7ff58..76911fb9e27 100644 --- a/src/sage/combinat/root_system/type_reducible.py +++ b/src/sage/combinat/root_system/type_reducible.py @@ -266,10 +266,12 @@ def cartan_matrix(self, subdivide=True): [-1 2 0 0] [ 0 0 2 -1] [ 0 0 -2 2] + sage: ct.index_set() == ct.cartan_matrix().index_set() + True """ from sage.combinat.root_system.cartan_matrix import CartanMatrix return CartanMatrix(block_diagonal_matrix([t.cartan_matrix() for t in self._types], subdivide=subdivide), - cartan_type=self) + cartan_type=self, index_set=self.index_set()) def dynkin_diagram(self): """