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

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

    # HG changeset patch
    # User Anne Schilling <anne@math.ucdavis.edu>
    # Date 1304964237 25200
    # Node ID f6244484025e720211068272ef69181bf92ae0bc
    # Parent  b1bdbc2b271230f6082bdee21cdd50b558bf5c09
    #11314: Enhance method from_shape_and_word in tableau to allow English reading order
    
    diff --git a/sage/combinat/tableau.py b/sage/combinat/tableau.py
    a b def from_chain(chain): 
    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, order = "French"):
     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    - ``order`` -- a string which can take values "French" or "English"; the default is "French"
     1688
     1689    OUTPUT:
     1690
     1691    A tableau, whose shape is ``shape`` and whose reading word is ``w``. 
     1692    If the order is specified to "French", the reading word is to be read starting
     1693    from the top row in French notation (= the bottom row in English notation).
     1694    If the order is specified to "English", 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
    16861700        sage: t = Tableau([[1, 3], [2], [4]])
    16871701        sage: shape = t.shape(); shape
    16881702        [2, 1, 1]
    1689         sage: word  = t.to_word(); word
     1703        sage: word = t.to_word(); 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, order = "English")
     1709        [[1, 3], [2], [4]]
    16931710    """
    16941711    res = []
    16951712    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()
     1713    if order == "French":
     1714        shape = reversed(shape)
     1715    for l in shape:
     1716        res.append( list(w[j:j+l]) )
     1717        j += l
     1718    if order == "French":
     1719        res.reverse()
    17001720    return Tableau_class(res)
    17011721
    17021722def Tableaux(n=None):