Ticket #14464: trac-14464-cleanup_of_yang-baxter-fc.patch

File trac-14464-cleanup_of_yang-baxter-fc.patch, 21.1 KB (added by chapoton, 9 years ago)
  • doc/en/reference/combinat/index.rst

    # HG changeset patch
    # User Frederic Chapoton <chapoton at math.univ-lyon1.fr>
    # Date 1366231072 -7200
    # Node ID 5f66b9c4f0d2c6fa31de317977e18df693be924f
    # Parent  f644a39d332f0b9e6cd4a3dc892826298df9969e
    trac #14464 clean up of yang baxter graph
    
    diff --git a/doc/en/reference/combinat/index.rst b/doc/en/reference/combinat/index.rst
    a b Combinatorics 
    3030   sage/combinat/enumeration_mod_permgroup
    3131   sage/combinat/restricted_growth
    3232   sage/combinat/yamanouchi
     33   sage/combinat/yang_baxter_graph
    3334   sage/combinat/gelfand_tsetlin_patterns
    3435   sage/combinat/graph_path
    3536   sage/combinat/matrices/latin
  • sage/combinat/yang_baxter_graph.py

    diff --git a/sage/combinat/yang_baxter_graph.py b/sage/combinat/yang_baxter_graph.py
    a b def YangBaxterGraph(partition=None, root 
    3030    The user needs to provide either ``partition`` or both ``root`` and
    3131    ``operators``, where
    3232
    33     - ``partition`` - a partition of a positive integer
     33    - ``partition`` -- a partition of a positive integer
    3434
    35     - ``root`` - the root vertex
    36    
    37     - ``operator`` - a function that maps vertices u to a list of
    38       tuples of the form (v, l) where v is a successors of u and l is
    39       the label of the edge from u to v.
     35    - ``root`` -- the root vertex
     36
     37    - ``operator`` - a function that maps vertices `u` to a list of
     38      tuples of the form `(v, l)` where `v` is a successor of `u` and `l` is
     39      the label of the edge from `u` to `v`.
    4040
    4141    OUTPUT:
    4242
    4343    - Either:
    4444
    4545      - :class:`YangBaxterGraph_partition` - if partition is defined
    46       - :class:`YangBaxterGraph_generic` - if partition is None
     46      - :class:`YangBaxterGraph_generic` - if partition is ``None``
    4747
    4848    EXAMPLES:
    4949
    def YangBaxterGraph(partition=None, root 
    6363        sage: Y.vertices()
    6464        [(2, 0, 1, 0), (2, 1, 0, 0), (0, 2, 1, 0)]
    6565
    66     The ``partition`` keyword is shorthand for the above construction.
     66    The ``partition`` keyword is a shorthand for the above construction.
    6767
    6868    ::
    6969
    def YangBaxterGraph(partition=None, root 
    7575    The permutahedron can be realized as a Yang-Baxter graph.
    7676
    7777    ::
    78    
     78
    7979        sage: from sage.combinat.yang_baxter_graph import SwapIncreasingOperator
    8080        sage: swappers = [SwapIncreasingOperator(i) for i in range(3)]
    8181        sage: Y = YangBaxterGraph(root=(1,2,3,4), operators=swappers); Y
    class YangBaxterGraph_generic(SageObject 
    116116        r"""
    117117        A class to model the Yang-Baxter graph defined by ``root`` and
    118118        ``operators``.
    119        
     119
    120120        INPUT:
    121121
    122         - ``root`` - the root vertex of the graph
     122        - ``root`` -- the root vertex of the graph
    123123
    124         - ``operators`` - a list of callables that map vertices to (new)
     124        - ``operators`` -- a list of callables that map vertices to (new)
    125125          vertices.
    126        
    127        
    128         .. note::
    129        
     126
     127
     128        .. NOTE::
     129
    130130           This is a lazy implementation: the digraph is only computed
    131131           when it is needed.
    132132
    133133        EXAMPLES::
    134        
     134
    135135            sage: from sage.combinat.yang_baxter_graph import SwapIncreasingOperator
    136136            sage: ops = [SwapIncreasingOperator(i) for i in range(4)]
    137137            sage: Y = YangBaxterGraph(root=(1,0,2,1,0), operators=ops); Y
    class YangBaxterGraph_generic(SageObject 
    146146        self._root = root
    147147        self._operators = operators
    148148
    149     def _succesors(self, u):
     149    def _successors(self, u):
    150150        r"""
    151151        Return a list of tuples for the form `(op(u), op)`, where op
    152         is one of the operators defining self.
     152        is one of the operators defining ``self``.
    153153
    154154        EXAMPLES::
    155155
    156156            sage: from sage.combinat.yang_baxter_graph import SwapIncreasingOperator
    157157            sage: ops = [SwapIncreasingOperator(i) for i in range(4)]
    158158            sage: Y = YangBaxterGraph(root=(1,0,2,1,0), operators=ops)
    159             sage: Y._succesors((1,0,2,1,0))
     159            sage: Y._successors((1,0,2,1,0))
    160160            [((1, 2, 0, 1, 0), Swap-if-increasing at position 1)]
    161161        """
    162162        successors = set()
    class YangBaxterGraph_generic(SageObject 
    169169    def __repr__(self):
    170170        r"""
    171171        EXAMPLES::
    172        
     172
    173173            sage: from sage.combinat.yang_baxter_graph import SwapIncreasingOperator
    174174            sage: ops = [SwapIncreasingOperator(i) for i in range(2)]
    175175            sage: Y = YangBaxterGraph(root=(1,2,3), operators=ops)
    class YangBaxterGraph_generic(SageObject 
    185185        attribute.
    186186
    187187        EXAMPLES::
    188        
     188
    189189            sage: from sage.combinat.yang_baxter_graph import SwapIncreasingOperator
    190190            sage: ops = [SwapIncreasingOperator(i) for i in range(2)]
    191191            sage: Y = YangBaxterGraph(root=(1,2,3), operators=ops)
    class YangBaxterGraph_generic(SageObject 
    197197        queue = [self._root]
    198198        while queue:
    199199            u = queue.pop()
    200             for (v, l) in self._succesors(u):
     200            for (v, l) in self._successors(u):
    201201                if v not in digraph:
    202202                    queue.append(v)
    203203                digraph.add_edge(u, v, l)
    class YangBaxterGraph_generic(SageObject 
    206206    def __eq__(self, other):
    207207        r"""
    208208        EXAMPLES::
    209        
     209
    210210            sage: from sage.combinat.yang_baxter_graph import SwapIncreasingOperator
    211211            sage: ops = [SwapIncreasingOperator(i) for i in range(4)]
    212212            sage: Y1 = YangBaxterGraph(root=(1,0,2,1,0), operators=ops)
    class YangBaxterGraph_generic(SageObject 
    230230        Test non-equality.
    231231
    232232        EXAMPLES::
    233        
     233
    234234            sage: from sage.combinat.yang_baxter_graph import SwapIncreasingOperator
    235235            sage: ops = [SwapIncreasingOperator(i) for i in range(4)]
    236236            sage: Y1 = YangBaxterGraph(root=(1,0,2,1,0), operators=ops)
    class YangBaxterGraph_generic(SageObject 
    251251
    252252    def __iter__(self):
    253253        r"""
    254         Returns an iterator of the vertices in self.
     254        Returns an iterator of the vertices in ``self``.
    255255
    256256        EXAMPLES::
    257        
     257
    258258            sage: from sage.combinat.yang_baxter_graph import SwapIncreasingOperator
    259259            sage: ops = [SwapIncreasingOperator(i) for i in range(4)]
    260260            sage: Y = YangBaxterGraph(root=(1,0,2,1,0), operators=ops)
    class YangBaxterGraph_generic(SageObject 
    265265
    266266    def __len__(self):
    267267        r"""
    268         Returns the number of vertices in self.
     268        Returns the number of vertices in ``self``.
    269269
    270270        EXAMPLES::
    271        
     271
    272272            sage: from sage.combinat.yang_baxter_graph import SwapIncreasingOperator
    273273            sage: ops = [SwapIncreasingOperator(i) for i in range(4)]
    274274            sage: Y = YangBaxterGraph(root=(1,0,2,1,0), operators=ops)
    class YangBaxterGraph_generic(SageObject 
    283283
    284284    def __copy__(self):
    285285        r"""
    286         Returns a copy of self.  Note that :meth:`.copy` is now
    287         deprecated.
     286        Returns a copy of ``self``.
    288287
    289288        EXAMPLES::
    290        
     289
    291290            sage: from sage.combinat.yang_baxter_graph import SwapIncreasingOperator
    292291            sage: ops = [SwapIncreasingOperator(i) for i in range(3)]
    293292            sage: Y = YangBaxterGraph(root=(1,0,2,1,0), operators=ops); Y
    class YangBaxterGraph_generic(SageObject 
    304303        Y._digraph = copy(self._digraph)
    305304        return Y
    306305
    307     def copy(self):
    308         r"""
    309         Returns a copy of self.  This method is deprecated.
    310 
    311         EXAMPLES::
    312        
    313             sage: from sage.combinat.yang_baxter_graph import SwapIncreasingOperator
    314             sage: ops = [SwapIncreasingOperator(i) for i in range(3)]
    315             sage: Y = YangBaxterGraph(root=(1,0,2,1,0), operators=ops); Y
    316             Yang-Baxter graph with root vertex (1, 0, 2, 1, 0)
    317             sage: B = Y.copy(); B
    318             doctest:...: DeprecationWarning: the .copy() method is deprecated; please use the copy() function instead, for example, copy(g)
    319             See http://trac.sagemath.org/6522 for details.
    320             Yang-Baxter graph with root vertex (1, 0, 2, 1, 0)
    321         """
    322         from copy import copy
    323         from sage.misc.superseded import deprecation
    324         deprecation(6522, "the .copy() method is deprecated; please use the copy() function instead, for example, copy(g)")
    325         return copy(self)
    326 
    327 
    328306    def _edges_in_bfs(self):
    329307        r"""
    330308        Returns an iterator of the edges of the digraph traversed in a
    331309        breadth-first search of the vertices beginning at ``self.root()``.
    332310
    333311        EXAMPLES::
    334        
     312
    335313            sage: from sage.combinat.yang_baxter_graph import SwapIncreasingOperator
    336314            sage: ops = [SwapIncreasingOperator(i) for i in range(4)]
    337315            sage: Y = YangBaxterGraph(root=(1,0,2,1,0), operators=ops)
    class YangBaxterGraph_generic(SageObject 
    352330
    353331    def root(self):
    354332        r"""
    355         Returns the root vertex of ``self``. If ``self`` is the
    356         Yang-Baxter graph of the partition `[p_1,p_2,\dots,p_k]`, then
    357         this is the vertex `(p_k-1,p_k-2,\dots,0,\dots,p_1-1,p_1-2,\dots,0)`.
     333        Returns the root vertex of ``self``.
     334
     335        If ``self`` is the Yang-Baxter graph of the partition
     336        `[p_1,p_2,\dots,p_k]`, then this is the vertex
     337        `(p_k-1,p_k-2,\dots,0,\dots,p_1-1,p_1-2,\dots,0)`.
    358338
    359339        EXAMPLES::
    360        
     340
    361341            sage: from sage.combinat.yang_baxter_graph import SwapIncreasingOperator
    362342            sage: ops = [SwapIncreasingOperator(i) for i in range(4)]
    363343            sage: Y = YangBaxterGraph(root=(1,0,2,1,0), operators=ops)
    class YangBaxterGraph_generic(SageObject 
    380360        Return the successors of the vertex ``v``.
    381361
    382362        EXAMPLES::
    383        
     363
    384364            sage: from sage.combinat.yang_baxter_graph import SwapIncreasingOperator
    385365            sage: ops = [SwapIncreasingOperator(i) for i in range(4)]
    386366            sage: Y = YangBaxterGraph(root=(1,0,2,1,0), operators=ops)
    class YangBaxterGraph_generic(SageObject 
    389369            sage: Y.successors((1, 2, 0, 1, 0))
    390370            [(2, 1, 0, 1, 0), (1, 2, 1, 0, 0)]
    391371        """
    392         return [a for (a,b) in self._succesors(v)]
     372        return [a for (a,b) in self._successors(v)]
    393373
    394374    def plot(self, *args, **kwds):
    395375        r"""
    396376        Plots ``self`` as a digraph.
    397377
    398378        EXAMPLES::
    399        
     379
    400380            sage: from sage.combinat.yang_baxter_graph import SwapIncreasingOperator
    401381            sage: ops = [SwapIncreasingOperator(i) for i in range(4)]
    402382            sage: Y = YangBaxterGraph(root=(1,0,2,1,0), operators=ops)
    class YangBaxterGraph_generic(SageObject 
    414394        Returns the vertices of ``self``.
    415395
    416396        EXAMPLES::
    417        
     397
    418398            sage: from sage.combinat.yang_baxter_graph import SwapIncreasingOperator
    419399            sage: ops = [SwapIncreasingOperator(i) for i in range(3)]
    420400            sage: Y = YangBaxterGraph(root=(0,2,1,0), operators=ops)
    class YangBaxterGraph_generic(SageObject 
    428408        Returns the (labelled) edges of ``self``.
    429409
    430410        EXAMPLES::
    431        
     411
    432412            sage: from sage.combinat.yang_baxter_graph import SwapIncreasingOperator
    433413            sage: ops = [SwapIncreasingOperator(i) for i in range(3)]
    434414            sage: Y = YangBaxterGraph(root=(0,2,1,0), operators=ops)
    class YangBaxterGraph_generic(SageObject 
    443423        the object obtained from ``v`` by applying the
    444424        ``relabel_operator`` along a path from the root to ``u``. Note
    445425        that the root is paired with ``v``.
    446        
     426
    447427        INPUT:
    448428
    449         - ``v`` - an object
     429        - ``v`` -- an object
    450430
    451         - ``relabel_operator`` - function mapping a vertex and a label to
     431        - ``relabel_operator`` -- function mapping a vertex and a label to
    452432          the image of the vertex
    453433
    454434        OUTPUT:
    455435
    456436        - dictionary pairing vertices with the corresponding image of ``v``
    457        
     437
    458438        EXAMPLES::
    459        
     439
    460440            sage: from sage.combinat.yang_baxter_graph import SwapIncreasingOperator
    461441            sage: ops = [SwapIncreasingOperator(i) for i in range(3)]
    462442            sage: Y = YangBaxterGraph(root=(0,2,1,0), operators=ops)
    class YangBaxterGraph_generic(SageObject 
    466446            sage: Y.vertex_relabelling_dict((1,2,3,4), relabel_operator)
    467447            {(2, 0, 1, 0): (2, 1, 3, 4), (2, 1, 0, 0): (2, 3, 1, 4), (0, 2, 1, 0): (1, 2, 3, 4)}
    468448        """
    469         digraph = self._digraph
    470449        relabelling = {self._root:v}
    471450        for (u,w,i) in self._edges_in_bfs():
    472451            relabelling[w] = relabel_operator(i, relabelling[u])
    class YangBaxterGraph_generic(SageObject 
    476455        r"""
    477456        Relabel the vertices ``u`` of ``self`` by the object obtained
    478457        from ``u`` by applying the ``relabel_operator`` to ``v`` along
    479         a path from ``self.root()`` to ``u``. Note that the
    480         ``self.root()`` is paired with ``v``.
     458        a path from ``self.root()`` to ``u``.
     459
     460        Note that the ``self.root()`` is paired with ``v``.
    481461
    482462        INPUT:
    483463
    484         - ``v`` - tuple, Permutation, CombinatorialObject
     464        - ``v`` -- tuple, Permutation, CombinatorialObject
    485465
    486         - ``inplace`` - if True, modifies self; otherwise returns a
    487           modified copy of self.
     466        - ``inplace`` -- if ``True``, modifies ``self``; otherwise returns a
     467          modified copy of ``self``.
    488468
    489469        EXAMPLES::
    490470
    class YangBaxterGraph_generic(SageObject 
    512492
    513493    def relabel_edges(self, edge_dict, inplace=True):
    514494        r"""
    515         Relabel the edges of self.
     495        Relabel the edges of ``self``.
    516496
    517497        INPUT:
    518498
    519         - ``edge_dict`` - a dictionary keyed by the (unlabelled) edges.
    520        
     499        - ``edge_dict`` -- a dictionary keyed by the (unlabelled) edges.
     500
    521501        EXAMPLES::
    522502
    523503            sage: from sage.combinat.yang_baxter_graph import SwapIncreasingOperator
    class YangBaxterGraph_generic(SageObject 
    537517            sage: Y.edges()
    538518            [((0, 2, 1, 0), (2, 0, 1, 0), 17), ((2, 0, 1, 0), (2, 1, 0, 0), 27)]
    539519        """
    540         from copy import copy
    541520        if inplace:
    542521            Y = self
    543522        else:
     523            from copy import copy
    544524            Y = copy(self)
    545525        digraph = Y._digraph
    546526        for (u,v,i) in digraph.edges():
    class YangBaxterGraph_partition(YangBaxt 
    554534    def __init__(self, partition):
    555535        r"""
    556536        A class to model the Yang-Baxter graph of a partition.
    557        
     537
    558538        The Yang-Baxter graph defined by a partition `[p_1,\dots,p_k]`
    559539        is the labelled directed graph with vertex set obtained by
    560540        bubble-sorting `(p_k-1,p_k-2,\dots,0,\dots,p_1-1,p_1-2,\dots,0)`;
    561541        there is an arrow from `u` to `v` labelled by `i` if `v` is
    562542        obtained by swapping the `i`-th and `(i+1)`-th elements of `u`.
    563        
     543
    564544        .. note::
    565        
     545
    566546           This is a lazy implementation: the digraph is only computed
    567547           when it is needed.
    568548
    class YangBaxterGraph_partition(YangBaxt 
    586566    def __repr__(self):
    587567        r"""
    588568        EXAMPLES::
    589        
     569
    590570            sage: Y = YangBaxterGraph(partition=[3,2])
    591571            sage: Y.__repr__()
    592572            'Yang-Baxter graph of [3, 2], with top vertex (1, 0, 2, 1, 0)'
    class YangBaxterGraph_partition(YangBaxt 
    595575
    596576    def __copy__(self):
    597577        r"""
    598         Returns a copy of self.  Note that :meth:`.copy` is now
    599         deprecated.
     578        Returns a copy of ``self``.
    600579
    601580        EXAMPLES::
    602        
     581
    603582            sage: Y = YangBaxterGraph(partition=[3,2]); Y
    604583            Yang-Baxter graph of [3, 2], with top vertex (1, 0, 2, 1, 0)
    605584            sage: B = copy(Y); B
    class YangBaxterGraph_partition(YangBaxt 
    614593        Y._digraph = copy(self._digraph)
    615594        return Y
    616595
    617     def copy(self):
    618         r"""
    619         Returns a copy of self.  Note that :meth:`.copy` is now
    620         deprecated.
    621 
    622         EXAMPLES::
    623        
    624             sage: Y = YangBaxterGraph(partition=[3,2]); Y
    625             Yang-Baxter graph of [3, 2], with top vertex (1, 0, 2, 1, 0)
    626             sage: B = Y.copy(); B
    627             doctest:...: DeprecationWarning: the .copy() method is deprecated; please use the copy() function instead, for example, copy(g)
    628             See http://trac.sagemath.org/6522 for details.
    629             Yang-Baxter graph of [3, 2], with top vertex (1, 0, 2, 1, 0)
    630         """
    631         from copy import copy
    632         from sage.misc.superseded import deprecation
    633         deprecation(6522, "the .copy() method is deprecated; please use the copy() function instead, for example, copy(g)")
    634         return copy(self)
    635 
    636596    @lazy_attribute
    637597    def _digraph(self):
    638598        r"""
    class YangBaxterGraph_partition(YangBaxt 
    640600        attribute.
    641601
    642602        EXAMPLES::
    643        
     603
    644604            sage: Y = YangBaxterGraph(partition=[2,1])
    645605            sage: Y._digraph
    646606            Digraph on 2 vertices
    class YangBaxterGraph_partition(YangBaxt 
    670630        r"""
    671631        Iterate over the vertices ``self``.
    672632
    673         NOTES:
    674        
    675         The vertices are first sorted using Python's sorted command.
     633        .. NOTE::
     634
     635            The vertices are first sorted using Python's sorted command.
    676636
    677637        EXAMPLES:
    678638            sage: Y = YangBaxterGraph(partition=[3,2])
    class YangBaxterGraph_partition(YangBaxt 
    688648
    689649        INPUT:
    690650
    691         - ``i`` - positive integer between 1 and len(u)-1, inclusive
     651        - ``i`` -- positive integer between 1 and len(u)-1, inclusive
    692652
    693         - ``u`` - tuple, list, permutation, CombinatorialObject, ....
     653        - ``u`` -- tuple, list, permutation, CombinatorialObject, ....
    694654
    695655        EXAMPLES::
    696        
     656
    697657            sage: Y = YangBaxterGraph(partition=[3,1])
    698658            sage: from sage.combinat.yang_baxter_graph import SwapOperator
    699659            sage: ops = [SwapOperator(i) for i in range(3)]
    class YangBaxterGraph_partition(YangBaxt 
    708668
    709669    def vertex_relabelling_dict(self, v):
    710670        r"""
    711         Return a dictionary pairing vertices ``u`` of self with the object
     671        Return a dictionary pairing vertices ``u`` of ``self`` with the object
    712672        obtained from ``v`` by applying transpositions corresponding to the
    713         edges labels along a path from the root to ``u``. Note that the
    714         root is paired with ``v``.
    715        
     673        edges labels along a path from the root to ``u``.
     674
     675        Note that the root is paired with ``v``.
     676
    716677        INPUT:
    717678
    718         - ``v`` - an object
     679        - ``v`` -- an object
    719680
    720681        OUTPUT:
    721682
    722         - dictionary pairing vertices with the corresponding image of v
    723        
     683        - dictionary pairing vertices with the corresponding image of ``v``
     684
    724685        EXAMPLES::
    725        
     686
    726687            sage: Y = YangBaxterGraph(partition=[3,1])
    727688            sage: Y.vertex_relabelling_dict((1,2,3,4))
    728689            {(2, 0, 1, 0): (2, 1, 3, 4), (2, 1, 0, 0): (2, 3, 1, 4), (0, 2, 1, 0): (1, 2, 3, 4)}
    class YangBaxterGraph_partition(YangBaxt 
    739700
    740701        INPUT:
    741702
    742         - ``v`` - tuple, Permutation, CombinatorialObject
    743        
    744         - ``inplace`` - if True, modifies self; otherwise returns a modified
    745           copy of self.
     703        - ``v`` -- tuple, Permutation, CombinatorialObject
     704
     705        - ``inplace`` -- if ``True``, modifies ``self``; otherwise
     706          returns a modified copy of ``self``.
    746707
    747708        EXAMPLES::
    748        
     709
    749710            sage: Y = YangBaxterGraph(partition=[3,1]); Y
    750711            Yang-Baxter graph of [3, 1], with top vertex (0, 2, 1, 0)
    751712            sage: d = Y.relabel_vertices((1,2,3,4), inplace=False); d
    class SwapOperator(SageObject): 
    825786        graphs).
    826787
    827788        EXAMPLES::
    828        
     789
    829790            sage: from sage.combinat.yang_baxter_graph import SwapOperator
    830791            sage: s3 = SwapOperator(3)
    831792            sage: s3.__str__()
    class SwapOperator(SageObject): 
    836797    def __call__(self, u):
    837798        r"""
    838799        Return the object obtained from swapping the items in positions
    839         ``i`` and ``i+1`` of ``u``. 
    840        
     800        ``i`` and ``i+1`` of ``u``.
     801
    841802        EXAMPLES::
    842803
    843804            sage: from sage.combinat.yang_baxter_graph import SwapOperator
    class SwapOperator(SageObject): 
    852813
    853814    def position(self):
    854815        r"""
    855         Self is the operator that swaps positions ``i`` and ``i+1``. This
     816        ``self`` is the operator that swaps positions ``i`` and ``i+1``. This
    856817        method returns ``i``.
    857818
    858819        EXAMPLES::
    class SwapIncreasingOperator(SwapOperato 
    885846
    886847        INPUT:
    887848
    888         - ``i`` - positive integer between ``1`` and ``len(u)-1``, inclusive
    889        
    890         - ``u`` - tuple, list, permutation, CombinatorialObject, ....
    891        
     849        - ``i`` -- positive integer between ``1`` and ``len(u)-1``, inclusive
     850
     851        - ``u`` -- tuple, list, permutation, CombinatorialObject, ....
     852
    892853        EXAMPLES::
    893        
     854
    894855            sage: Y = YangBaxterGraph(partition=[2,2])
    895856            sage: from sage.combinat.yang_baxter_graph import SwapIncreasingOperator
    896857            sage: operators = [SwapIncreasingOperator(i) for i in range(3)]