Ticket #11314: trac_11314-tableau-from-shape-and-word-ht.patch

File trac_11314-tableau-from-shape-and-word-ht.patch, 2.0 KB (added by hthomas, 11 years ago)
  • sage/combinat/tableau.py

    # HG changeset patch
    # User hthomas@unb.ca
    # Date 1304882414 10800
    # Node ID 4e8c4d1ee854c0f487bff2aaefe892916baff3ab
    # Parent  00fc7e12b5f07c7d64a44d6ad4224dfa55ff3dd8
    #11314: Enhance method from_shape_and_word in tableau to allow English reading order
    
    diff -r 00fc7e12b5f0 -r 4e8c4d1ee854 sage/combinat/tableau.py
    a b  
    16761676                res[j][k] = i -1
    16771677    return Tableau_class(res)
    16781678
    1679 def from_shape_and_word(shape, w):
    1680     """
    1681     Returns a tableau from a shape and word.
     1679def from_shape_and_word(shape, w, french=True):
     1680    r"""
     1681    Returns a tableau from a shape and word. 
     1682
     1683    INPUT:
    16821684   
     1685    - ``shape`` -- a partition
     1686    - ``w`` -- a word whose length equals that of the partition
     1687    - ``french`` -- boolean
     1688
     1689    OUTPUT:
     1690
     1691    A tableau, whose shape is ``shape`` and whose reading word is ``w``. 
     1692    If ``french`` is true, the reading word is to be read starting
     1693    from the top row in French notation (= the bottom row in English notation).
     1694    If ``french`` is false, the reading word is to be read starting with the
     1695    top row in English notation. 
     1696
    16831697    EXAMPLES::
    16841698   
    16851699        sage: from sage.combinat.tableau import from_shape_and_word
     
    16901704        word: 4213
    16911705        sage: from_shape_and_word(shape, word)
    16921706        [[1, 3], [2], [4]]
     1707        sage: word = Word(flatten(t))
     1708        sage: from_shape_and_word(shape, word, False)
     1709        [[1, 3], [2], [4]]
     1710
    16931711    """
    16941712    res = []
    16951713    j = 0
    1696     for i in reversed(range(len(shape))):
    1697         res.append( list(w[j:j+shape[i]]) )
    1698         j += shape[i]
    1699     res.reverse()
     1714    if french:
     1715        for i in reversed(range(len(shape))):
     1716            res.append( list(w[j:j+shape[i]]) )
     1717            j += shape[i]
     1718        res.reverse()
     1719    else:
     1720        for i in range (len(shape)):
     1721            res.append(list(w[j:j+shape[i]]))
     1722            j += shape[i]
    17001723    return Tableau_class(res)
    17011724
    17021725def Tableaux(n=None):