Ticket #11763: trac_11763_fix_associahedron.patch

File trac_11763_fix_associahedron.patch, 10.0 KB (added by vbraun, 7 years ago)

Updated patch

  • sage/combinat/root_system/associahedron.py

    # HG changeset patch
    # User Volker Braun <vbraun.name@gmail.com>
    # Date 1351028446 -3600
    # Node ID 0eedc1f54b84d76e401f1edd27da8e5eb014c9e8
    # Parent  038528374fe2ff63665d221bbedcc6f6238bb90f
    Trac #11763: fix the associahedron
    
    The Associahedron class derives from Polyhedron_QQ_ppl. It must
    be converted to the parent/element framework as well.
    
    diff --git a/sage/combinat/root_system/associahedron.py b/sage/combinat/root_system/associahedron.py
    a b  
    2020#                  http://www.gnu.org/licenses/
    2121#*****************************************************************************
    2222from sage.geometry.polyhedron.backend_ppl import Polyhedron_QQ_ppl
     23from sage.geometry.polyhedron.parent import Polyhedra_QQ_ppl
    2324from sage.combinat.root_system.cartan_type import CartanType
    2425from sage.modules.free_module_element import vector
     26from sage.rings.all import QQ
    2527
    26 class Associahedron(Polyhedron_QQ_ppl):
     28
     29def Associahedron(cartan_type):
    2730    r"""
    28     The generalized associahedron is a polytopal complex with vertices in one-to-one correspondence
    29     with clusters in the cluster complex, and with edges between two vertices if and only if the associated two
    30     clusters intersect in codimension 1.
     31    Construct an associahedron
    3132
    32     The associahedron of type `A_n` is one way to realize the classical associahedron as defined in
     33    An Associahedron
     34
     35    The generalized associahedron is a polytopal complex with vertices
     36    in one-to-one correspondence with clusters in the cluster complex,
     37    and with edges between two vertices if and only if the associated
     38    two clusters intersect in codimension 1.
     39
     40    The associahedron of type `A_n` is one way to realize the
     41    classical associahedron as defined in
    3342
    3443    http://en.wikipedia.org/wiki/Associahedron.
    3544
     
    4150        sage: Asso = Associahedron(['A',2]); Asso
    4251        Generalized associahedron of type ['A', 2] with 5 vertices
    4352        sage: sorted(Asso.Hrepresentation(), key=repr)
    44         [An inequality (-1, 0) x + 1 >= 0, An inequality (0, -1) x + 1 >= 0, An inequality (0, 1) x + 1 >= 0, An inequality (1, 0) x + 1 >= 0, An inequality (1, 1) x + 1 >= 0]
     53        [An inequality (-1, 0) x + 1 >= 0,
     54         An inequality (0, -1) x + 1 >= 0,
     55         An inequality (0, 1) x + 1 >= 0,
     56         An inequality (1, 0) x + 1 >= 0,
     57         An inequality (1, 1) x + 1 >= 0]
    4558        sage: Asso.Vrepresentation()
    46         (A vertex at (1, -1), A vertex at (1, 1), A vertex at (-1, 1), A vertex at (-1, 0), A vertex at (0, -1))
     59        (A vertex at (1, -1), A vertex at (1, 1), A vertex at (-1, 1),
     60         A vertex at (-1, 0), A vertex at (0, -1))
    4761
    4862        sage: Associahedron(['B',2])
    4963        Generalized associahedron of type ['B', 2] with 6 vertices
     
    6175    TESTS::
    6276
    6377        sage: sorted(Associahedron(['A',3]).vertices())
    64         [[-3/2, 0, -1/2], [-3/2, 0, 3/2], [-3/2, 1, -3/2], [-3/2, 2, -3/2], [-3/2, 2, 3/2], [-1/2, -1, -1/2], [-1/2, 0, -3/2], [1/2, -2, 1/2], [1/2, -2, 3/2], [3/2, -2, 1/2], [3/2, -2, 3/2], [3/2, 0, -3/2], [3/2, 2, -3/2], [3/2, 2, 3/2]]
     78        [A vertex at (-3/2, 0, -1/2), A vertex at (-3/2, 0, 3/2),
     79         A vertex at (-3/2, 1, -3/2), A vertex at (-3/2, 2, -3/2),
     80         A vertex at (-3/2, 2, 3/2), A vertex at (-1/2, -1, -1/2),
     81         A vertex at (-1/2, 0, -3/2), A vertex at (1/2, -2, 1/2),
     82         A vertex at (1/2, -2, 3/2), A vertex at (3/2, -2, 1/2),
     83         A vertex at (3/2, -2, 3/2), A vertex at (3/2, 0, -3/2),
     84         A vertex at (3/2, 2, -3/2), A vertex at (3/2, 2, 3/2)]
     85
    6586        sage: sorted(Associahedron(['B',3]).vertices())
    66         [[-3, 0, 0], [-3, 0, 3], [-3, 2, -2], [-3, 4, -3], [-3, 5, -3], [-3, 5, 3], [-2, 1, -2], [-2, 3, -3], [-1, -2, 0], [-1, -1, -1], [1, -4, 1], [1, -3, 0], [2, -5, 2], [2, -5, 3], [3, -5, 2], [3, -5, 3], [3, -3, 0], [3, 3, -3], [3, 5, -3], [3, 5, 3]]
     87        [A vertex at (-3, 0, 0), A vertex at (-3, 0, 3),
     88         A vertex at (-3, 2, -2), A vertex at (-3, 4, -3),
     89         A vertex at (-3, 5, -3), A vertex at (-3, 5, 3),
     90         A vertex at (-2, 1, -2), A vertex at (-2, 3, -3),
     91         A vertex at (-1, -2, 0), A vertex at (-1, -1, -1),
     92         A vertex at (1, -4, 1), A vertex at (1, -3, 0),
     93         A vertex at (2, -5, 2), A vertex at (2, -5, 3),
     94         A vertex at (3, -5, 2), A vertex at (3, -5, 3),
     95         A vertex at (3, -3, 0), A vertex at (3, 3, -3),
     96         A vertex at (3, 5, -3), A vertex at (3, 5, 3)]
    6797
    6898        sage: Associahedron(['A',4]).f_vector()
    6999        (1, 42, 84, 56, 14, 1)
     
    72102
    73103    REFERENCES:
    74104
    75     - [CFZ] Chapoton, Fomin, Zelevinsky - Polytopal realizations of generalized associahedra, arXiv:0202004.
     105    - [CFZ] Chapoton, Fomin, Zelevinsky - Polytopal realizations of
     106      generalized associahedra, arXiv:0202004.
    76107    """
    77     def __init__(self, cartan_type):
    78         """
    79         TESTS::
     108    cartan_type = CartanType( cartan_type )
     109    parent = Associahedra(QQ, cartan_type.rank())
     110    return parent(cartan_type)
    80111
    81             sage: Asso = Associahedron(['A',2]); Asso
    82             Generalized associahedron of type ['A', 2] with 5 vertices
    83             sage: TestSuite(Asso).run()
    84112
    85         """
    86         self._cartan_type = CartanType( cartan_type )
    87         assert self._cartan_type.is_finite()
    88         root_space = self._cartan_type.root_system().root_space()
    89         # TODO: generalize this as a method of root lattice realization
    90         rhocheck = sum( beta.associated_coroot() for beta in root_space.positive_roots() )/2
    91         I = root_space.index_set()
    92         inequalities = []
    93         for orbit in root_space.almost_positive_roots_decomposition():
    94             c = rhocheck.coefficient(orbit[0].leading_support())
    95             for beta in orbit:
    96                 inequalities.append( [c] + [ beta.coefficient(i) for i in I ] )
    97         Polyhedron_QQ_ppl.__init__(self, len(I), None, [inequalities,[]])
    98         # check that there are non non trivial facets
    99         assert self.n_facets() == len(inequalities)
     113
     114
     115
     116class Associahedron_class(Polyhedron_QQ_ppl):
     117    r"""
     118    The Python class of an associahedron
     119
     120    You should use the :func:`Associahedron` convenience function to
     121    construct associahedra from the cartan type.
     122
     123    TESTS::
     124
     125        sage: Asso = Associahedron(['A',2]); Asso
     126        Generalized associahedron of type ['A', 2] with 5 vertices
     127        sage: TestSuite(Asso).run()
     128    """
    100129
    101130    def _repr_(self):
    102131        r"""
     
    107136            sage: Associahedron(['A',3])._repr_()
    108137            "Generalized associahedron of type ['A', 3] with 14 vertices"
    109138        """
    110         return 'Generalized associahedron of type %s with %s vertices'%(self._cartan_type,self.n_vertices())
     139        return 'Generalized associahedron of type %s with %s vertices'\
     140            %(self._cartan_type,self.n_vertices())
    111141
    112142    def cartan_type(self):
    113143        r"""
    114         Returns the Cartan type of self.
     144        Returns the Cartan type
    115145
    116146        EXAMPLES::
    117147
     
    128158
    129159            sage: Asso = Associahedron(['A',2])
    130160            sage: Asso.vertices()
    131             [[1, -1], [1, 1], [-1, 1], [-1, 0], [0, -1]]
     161            (A vertex at (1, -1), A vertex at (1, 1),
     162             A vertex at (-1, 1), A vertex at (-1, 0),
     163             A vertex at (0, -1))
    132164
    133165            sage: Asso.vertices_in_root_space()
    134166            (alpha[1] - alpha[2], alpha[1] + alpha[2], -alpha[1] + alpha[2], -alpha[1], -alpha[2])
    135167        """
    136168        root_space = self._cartan_type.root_system().root_space()
    137169        return tuple( root_space.from_vector(vector(V)) for V in self.vertex_generator() )
     170
     171
     172
     173
     174
     175
     176class Associahedra(Polyhedra_QQ_ppl):
     177    """
     178    Parent of Associahedra of specified dimension
     179
     180    EXAMPLES::
     181
     182        sage: from sage.combinat.root_system.associahedron import Associahedra
     183        sage: parent = Associahedra(QQ,2);  parent
     184        Polyhedra in QQ^2
     185        sage: type(parent)
     186        <class 'sage.combinat.root_system.associahedron.Associahedra_with_category'>
     187        sage: parent(['A',2])
     188        Generalized associahedron of type ['A', 2] with 5 vertices
     189
     190    Importantly, the parent knows the dimension of the ambient
     191    space. If you try to construct an associahedron of a different
     192    dimension, a ``ValueError`` is raised::
     193
     194        sage: parent(['A',3])
     195        Traceback (most recent call last):
     196        ...
     197        ValueError: V-representation data requires a list of length ambient_dim
     198    """
     199    Element = Associahedron_class
     200
     201    def _element_constructor_(self, cartan_type, **kwds):
     202        """
     203        The element constructor.
     204
     205        This method is called internally when we try to convert
     206        something into an element. In this case, the only thing that
     207        can be converted into an associahedron is the Cartan type.
     208
     209        EXAMPLES::
     210
     211            sage: from sage.combinat.root_system.associahedron import Associahedra
     212            sage: parent = Associahedra(QQ,2)
     213            sage: parent(['A',2])
     214            Generalized associahedron of type ['A', 2] with 5 vertices
     215            sage: parent._element_constructor_(['A',2])
     216            Generalized associahedron of type ['A', 2] with 5 vertices
     217        """
     218        cartan_type = CartanType( cartan_type )
     219        assert cartan_type.is_finite()
     220        root_space = cartan_type.root_system().root_space()
     221        # TODO: generalize this as a method of root lattice realization
     222        rhocheck = sum( beta.associated_coroot() for beta in root_space.positive_roots() )/2
     223        I = root_space.index_set()
     224        inequalities = []
     225        for orbit in root_space.almost_positive_roots_decomposition():
     226            c = rhocheck.coefficient(orbit[0].leading_support())
     227            for beta in orbit:
     228                inequalities.append( [c] + [ beta.coefficient(i) for i in I ] )
     229        associahedron = super(Associahedra, self)._element_constructor_(None, [inequalities,[]])
     230        associahedron._cartan_type = cartan_type
     231        return associahedron
     232
     233