Ticket #13077: trac_13077_tamari_posets-fc.patch

File trac_13077_tamari_posets-fc.patch, 8.5 KB (added by chapoton, 9 years ago)
  • doc/en/reference/combinat/index.rst

    # HG changeset patch
    # User "sage-combinat script"
    # Date 1352839101 -3600
    # Node ID 2cb39e38f7113c89faab19ff5d191376c61c0f91
    # Parent  15bb8b362364e04fb0ce9a754cfec237f458a045
    #13077 : A general familly of lattices, including the classical Tamari lattices and their recent generalised versions by Bergeron et al.
    
    Include the generalised version as GeneralisedTamariLattice
    
    and the classical version as TamariLattice
    * * *
    trac 13077 review
    
    diff --git a/doc/en/reference/combinat/index.rst b/doc/en/reference/combinat/index.rst
    a b Combinatorics 
    1919   ../sage/combinat/dlx
    2020   ../sage/combinat/matrices/dlxcpp
    2121   ../sage/combinat/dyck_word
     22   ../sage/combinat/tamari_lattices
    2223   ../sage/combinat/e_one_star
    2324   ../sage/combinat/finite_class
    2425   ../sage/combinat/integer_list
  • new file sage/combinat/tamari_lattices.py

    diff --git a/sage/combinat/tamari_lattices.py b/sage/combinat/tamari_lattices.py
    new file mode 100644
    - +  
     1r"""
     2The family of generalized Tamari lattices
     3
     4These lattices depend on three parameters `a`, `b` and `m`, where `a` and `b` are
     5coprime positive integers and `m` is a nonnegative integer.
     6
     7The elements are :func:`Dyck paths<sage.combinat.dyck_word.DyckWord>` in the `(a \times b)`-rectangle. The order relation
     8depends on `m`.
     9
     10To use the provided functionality, you should import Tamari lattices by typing
     11
     12``from sage.combinat.tamari_lattices import TamariLattice``
     13
     14or
     15
     16``from sage.combinat.tamari_lattices import GeneralizedTamariLattice``.
     17
     18EXAMPLES::
     19
     20    sage: from sage.combinat.tamari_lattices import TamariLattice
     21    sage: TamariLattice(3)
     22    Finite lattice containing 5 elements
     23
     24    sage: from sage.combinat.tamari_lattices import GeneralizedTamariLattice
     25    sage: GeneralizedTamariLattice(3,2)
     26    Finite lattice containing 2 elements
     27    sage: GeneralizedTamariLattice(4,3)
     28    Finite lattice containing 5 elements
     29
     30.. seealso::
     31
     32    For more detailed information see :meth:`TamariLattice`, :meth:`GeneralizedTamariLattice`.
     33"""
     34
     35#*****************************************************************************
     36#       Copyright (C) 2012 Frederic Chapoton <chapoton@math.univ-lyon1.fr>
     37#
     38#  Distributed under the terms of the GNU General Public License (GPL)
     39#
     40#    This code is distributed in the hope that it will be useful,
     41#    but WITHOUT ANY WARRANTY; without even the implied warranty of
     42#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     43#    General Public License for more details.
     44#
     45#  The full text of the GPL is available at:
     46#
     47#                  http://www.gnu.org/licenses/
     48#*****************************************************************************
     49
     50from sage.combinat.posets.lattices import LatticePoset
     51from sage.rings.arith import gcd
     52
     53def paths_in_triangle(i,j,a,b):
     54    r"""
     55    Returns all Dyck paths from `(0,0)` to `(i,j)` in the `(a \times b)`-rectangle.
     56
     57    This means that at each step of the path, one has `a y \geq b x`.
     58
     59    A path is represented by a sequence of `0` and `1`, where `0` is an
     60    horizontal step `(1,0)` and `1` is a vertical step `(0,1)`.
     61
     62    INPUT:
     63
     64    - `a` and `b` coprime integers with `a \geq b`
     65
     66    - `i` and `j` nonnegative integers with `1 \geq \frac{j}{b} \geq \frac{bi}{a} \geq 0`
     67
     68    OUTPUT:
     69
     70    - a list of paths
     71
     72    EXAMPLES::
     73
     74        sage: from sage.combinat.tamari_lattices import paths_in_triangle
     75        sage: paths_in_triangle(2,2,2,2)
     76        [(1, 0, 1, 0), (1, 1, 0, 0)]
     77        sage: paths_in_triangle(2,3,4,4)
     78        [(1, 0, 1, 0, 1), (1, 1, 0, 0, 1), (1, 0, 1, 1, 0), (1, 1, 0, 1, 0), (1, 1, 1, 0, 0)]
     79        sage: paths_in_triangle(2,1,4,4)
     80        Traceback (most recent call last):
     81        ...
     82        ValueError: The endpoint is not valid.
     83        sage: paths_in_triangle(3,2,5,3)
     84        [(1, 0, 1, 0, 0), (1, 1, 0, 0, 0)]
     85    """
     86    if not(b>=j and j*a>=i*b and i>=0):
     87        raise ValueError("The endpoint is not valid.")
     88    if i==0:
     89        return [tuple([1 for k in range(j)])]
     90    else:
     91        if (j-1)*a>=(i)*b:
     92            return [u+tuple([1]) for u in paths_in_triangle(i,j-1,a,b)]+[u+tuple([0]) for u in paths_in_triangle(i-1,j,a,b)]
     93        else:
     94            return [u+tuple([0]) for u in paths_in_triangle(i-1,j,a,b)]
     95
     96def swap(p,i,m=1):
     97    r"""
     98    Performs a covering move in the `(a,b)`-Tamari lattice of parameter `m`.
     99
     100    The letter at position `i` in `p` must be a `0`, followed by at
     101    least one `1`.
     102
     103    INPUT:
     104
     105    - `p` a Dyck path in the `(a \times b)`-rectangle
     106
     107    - `i` an integer between `0` and `a+b-1`
     108
     109    OUTPUT:
     110
     111    - a Dyck path in the `(a \times b)`-rectangle
     112
     113    EXAMPLES::
     114
     115        sage: from sage.combinat.tamari_lattices import swap
     116        sage: swap((1,0,1,0),1)
     117        (1, 1, 0, 0)
     118        sage: swap((1,0,1,0),6)
     119        Traceback (most recent call last):
     120        ...
     121        ValueError: The index is greater than the length of the path.
     122        sage: swap((1,1,0,0,1,1,0,0),3)
     123        (1, 1, 0, 1, 1, 0, 0, 0)
     124        sage: swap((1,1,0,0,1,1,0,0),2)
     125        Traceback (most recent call last):
     126        ...
     127        ValueError: There is no such covering move.
     128
     129    """
     130    if i>=len(p):
     131        raise ValueError("The index is greater than the length of the path.")
     132    if i==len(p)-1 or p[i+1]==0:
     133        raise ValueError("There is no such covering move.")
     134    else:
     135        found=False
     136        height=0
     137        j=i
     138        while not found and j<=len(p)-2:
     139            j+=1
     140            if p[j]==1:
     141                height+=m
     142            else:
     143                height=height-1
     144            if height==0:
     145                found=True
     146        q=[k for k in p]
     147        for k in range(i,j):
     148            q[k]=p[k+1]
     149        q[j]=0
     150        return tuple(q)
     151
     152def GeneralizedTamariLattice(a,b,m=1):
     153    r"""
     154    Returns the `(a,b)`-Tamari lattice of parameter `m`.
     155
     156    INPUT:
     157
     158    - `a` and `b` coprime integers with `a \geq b`
     159
     160    - `m` a nonnegative integer such that `a \geq b \times m`
     161
     162    OUTPUT:
     163
     164    - a finite lattice (the lattice property is only conjectural in general)
     165
     166    The elements of the lattice are :func:`Dyck paths<sage.combinat.dyck_word.DyckWord>` in the `(a \times b)`-rectangle.
     167
     168    The parameter `m` (slope) is used only to define the covering relations.
     169    When the slope `m` is `0`, two paths are comparable if and only if
     170    one is always above the other.
     171
     172    The usual :wikipedia:`Tamari lattice<Tamari lattice>` of index `b` is the special
     173    case `a=b+1` and `m=1`.
     174
     175    Other special cases give the `m`-Tamari lattices studied in [BMFPR]_.
     176
     177    EXAMPLES::
     178
     179        sage: from sage.combinat.tamari_lattices import GeneralizedTamariLattice
     180        sage: GeneralizedTamariLattice(3,2)
     181        Finite lattice containing 2 elements
     182        sage: GeneralizedTamariLattice(4,3)
     183        Finite lattice containing 5 elements
     184        sage: GeneralizedTamariLattice(4,4)
     185        Traceback (most recent call last):
     186        ...
     187        ValueError: The numbers a and b must be coprime with a>=b.
     188        sage: GeneralizedTamariLattice(7,5,2)
     189        Traceback (most recent call last):
     190        ...
     191        ValueError: The condition a>=b*m does not hold.
     192        sage: P = GeneralizedTamariLattice(5,3);P
     193        Finite lattice containing 7 elements
     194
     195    TESTS::
     196
     197        sage: P.coxeter_transformation()**18 == 1
     198        True
     199
     200    REFERENCES:
     201
     202    .. [BMFPR] M. Bousquet-Melou, E. Fusy, L.-F. Preville Ratelle. "The number of intervals in the m-Tamari lattices". arXiv:1106.1498
     203
     204    """
     205    if not(gcd(a,b)==1 and a>=b):
     206        raise ValueError("The numbers a and b must be coprime with a>=b.")
     207    if not(a>=b*m):
     208        raise ValueError("The condition a>=b*m does not hold.")
     209    def covers(p):
     210        return [swap(p,i,m) for i in range(len(p)-1) if p[i]==0 and p[i+1]==1]
     211    return LatticePoset(dict([[p,covers(p)]
     212                    for p in paths_in_triangle(a,b,a,b)]))
     213
     214def TamariLattice(n):
     215    r"""
     216    Returns the `n`-th Tamari lattice.
     217
     218    INPUT:
     219
     220    - `n` a nonnegative integer
     221
     222    OUTPUT:
     223
     224    - a finite lattice
     225
     226    The elements of the lattice are :func:`Dyck paths<sage.combinat.dyck_word.DyckWord>` in the `(n+1 \times n)`-rectangle.
     227
     228    See :wikipedia:`Tamari lattice<Tamari lattice>` for mathematical background.
     229
     230    EXAMPLES::
     231
     232        sage: from sage.combinat.tamari_lattices import TamariLattice
     233        sage: TamariLattice(3)
     234        Finite lattice containing 5 elements
     235    """
     236    return GeneralizedTamariLattice(n+1,n,1)