# 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): |
1676 | 1676 | res[j][k] = i -1 |
1677 | 1677 | return Tableau_class(res) |
1678 | 1678 | |
1679 | | def from_shape_and_word(shape, w): |
1680 | | """ |
1681 | | Returns a tableau from a shape and word. |
| 1679 | def from_shape_and_word(shape, w, order = "French"): |
| 1680 | r""" |
| 1681 | Returns a tableau from a shape and word. |
| 1682 | |
| 1683 | INPUT: |
1682 | 1684 | |
| 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 | |
1683 | 1697 | EXAMPLES:: |
1684 | 1698 | |
1685 | 1699 | sage: from sage.combinat.tableau import from_shape_and_word |
1686 | 1700 | sage: t = Tableau([[1, 3], [2], [4]]) |
1687 | 1701 | sage: shape = t.shape(); shape |
1688 | 1702 | [2, 1, 1] |
1689 | | sage: word = t.to_word(); word |
| 1703 | sage: word = t.to_word(); word |
1690 | 1704 | word: 4213 |
1691 | 1705 | sage: from_shape_and_word(shape, word) |
1692 | 1706 | [[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]] |
1693 | 1710 | """ |
1694 | 1711 | res = [] |
1695 | 1712 | 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() |
1700 | 1720 | return Tableau_class(res) |
1701 | 1721 | |
1702 | 1722 | def Tableaux(n=None): |