Ticket #9265: trac_9265_tableaux_categories_am.patch

File trac_9265_tableaux_categories_am.patch, 124.3 KB (added by Andrew Mathas, 10 years ago)

Removing assert statements

  • sage/combinat/all.py

    # HG changeset patch
    # User Andrew Mathas <andrew dot mathas at sydney dot edu dot au>
    # Date 1305910311 14400
    # Node ID 7341ea68d40af495b12c67ae60abd274ddb430f5
    # Parent  fcd2ddf558a65a6c0c0e747e90df011d6f118ad0
    #9265: Remove 'CombinatorialClass' from tableau.py
    
    diff --git a/sage/combinat/all.py b/sage/combinat/all.py
    a b from partition_algebra import SetPartiti 
    5454from core import Core, Cores
    5555
    5656#Tableaux
    57 from tableau import Tableau, StandardTableau, Tableaux, StandardTableaux, SemistandardTableaux
     57from tableau import Tableau, SemistandardTableau, StandardTableau, \
     58        Tableaux, StandardTableaux, SemistandardTableaux
    5859from skew_tableau import SkewTableau, StandardSkewTableaux, SemistandardSkewTableaux
    5960from ribbon import Ribbon, StandardRibbons
    6061from ribbon_tableau import RibbonTableaux, RibbonTableau, MultiSkewTableau, SemistandardMultiSkewTableaux
  • sage/combinat/crystals/tensor_product.py

    diff --git a/sage/combinat/crystals/tensor_product.py b/sage/combinat/crystals/tensor_product.py
    a b from sage.combinat.cartesian_product imp 
    3535from sage.combinat.combinat import CombinatorialObject
    3636from sage.combinat.partition import Partition
    3737from sage.combinat.tableau import Tableau
    38 from sage.combinat.tableau import Tableau_class
    3938from letters import CrystalOfLetters
    4039from spins import CrystalOfSpins, CrystalOfSpinsMinus, CrystalOfSpinsPlus
    4140from sage.misc.flatten import flatten
    class CrystalOfTableauxElement(TensorPro 
    11141113            [0]
    11151114        """
    11161115        if len(args) == 1:
    1117             if isinstance(args[0], Tableau_class):
     1116            if isinstance(args[0], Tableau):
    11181117                options['rows'] = args[0]
    11191118        if options.has_key('list'):
    11201119            list = options['list']
    class CrystalOfTableauxElement(TensorPro 
    11901189            sage: t = T(rows=[[1,2],[3,4]]).to_tableau(); t
    11911190            [[1, 2], [3, 4]]
    11921191            sage: type(t)
    1193             <class 'sage.combinat.tableau.Tableau_class'>
     1192            <class 'sage.combinat.tableau.Tableaux_all_with_category.element_class'>
    11941193            sage: type(t[0][0])
    11951194            <type 'sage.rings.integer.Integer'>
    11961195            sage: T = CrystalOfTableaux(['D',3], shape = [1,1])
  • sage/combinat/partition.py

    diff --git a/sage/combinat/partition.py b/sage/combinat/partition.py
    a b class Partition_class(CombinatorialObjec 
    23522352            [[[1, 2, 3, 6], [4, 5]], [[1, 2, 3], [4, 5], [6]]]
    23532353        """
    23542354        res = []
    2355         for tab in tableau.StandardTableaux_n(self.size()):
     2355        for tab in tableau.StandardTableaux_size(self.size()):
    23562356            if tab.atom() == self:
    23572357                res.append(tab)
    23582358        return res
    class Partition_class(CombinatorialObjec 
    23812381            sage: Partition([]).k_atom(1)
    23822382            [[]]
    23832383        """
    2384         res = [ tableau.Tableau_class([]) ]
     2384        res = [ tableau.Tableau([]) ]
    23852385        for i in range(len(self)):
    23862386            res = [ x.promotion_operator( self[-i-1] ) for x in res]
    23872387            res = sum(res, [])
  • sage/combinat/permutation.py

    diff --git a/sage/combinat/permutation.py b/sage/combinat/permutation.py
    a b def Permutation(l): 
    249249
    250250    #if l is a pair of tableaux or a pair of lists
    251251    elif isinstance(l, (tuple, list)) and len(l) == 2 and \
    252         all(map(lambda x: isinstance(x, tableau.Tableau_class), l)):
     252        all(map(lambda x: isinstance(x, tableau.Tableau), l)):
    253253        return robinson_schensted_inverse(*l)
    254254    elif isinstance(l, (tuple, list)) and len(l) == 2 and \
    255255        all(map(lambda x: isinstance(x, list), l)):
  • sage/combinat/skew_tableau.py

    diff --git a/sage/combinat/skew_tableau.py b/sage/combinat/skew_tableau.py
    a b def StandardSkewTableaux(skp=None): 
    684684    if skp is None:
    685685        return StandardSkewTableaux_all()
    686686    elif isinstance(skp, (int, Integer)):
    687         return StandardSkewTableaux_n(skp)
     687        return StandardSkewTableaux_size(skp)
    688688    elif skp in skew_partition.SkewPartitions():
    689689        return StandardSkewTableaux_skewpartition(skew_partition.SkewPartition(skp))
    690690    else:
    class StandardSkewTableaux_all(InfiniteA 
    735735            sage: [it.next() for i in range(10)]
    736736            [[], [[1]], [[1, 2]], [[1], [2]], [[None, 1], [2]], [[None, 2], [1]], [[1, 2, 3]], [[1, 2], [3]], [[1, 3], [2]], [[None, 1, 2], [3]]]
    737737        """
    738         return StandardSkewTableaux_n(n)
     738        return StandardSkewTableaux_size(n)
    739739
    740740
    741 class StandardSkewTableaux_n(CombinatorialClass):
     741class StandardSkewTableaux_size(CombinatorialClass):
    742742    def __init__(self, n):
    743743        """
    744744        EXAMPLES::
    def SemistandardSkewTableaux(p=None, mu= 
    912912
    913913    if isinstance(p, (int, Integer)):
    914914        if mu is None:
    915             return SemistandardSkewTableaux_n(p)
     915            return SemistandardSkewTableaux_size(p)
    916916        else:
    917             return SemistandardSkewTableaux_nmu(p, mu)
     917            return SemistandardSkewTableaux_size_weight(p, mu)
    918918
    919919    if p in skew_partition.SkewPartitions():
    920920        p = skew_partition.SkewPartition(p)
    921921        if mu is None:
    922             return SemistandardSkewTableaux_p(p)
     922            return SemistandardSkewTableaux_shape(p)
    923923        else:
    924             return SemistandardSkewTableaux_pmu(p, mu)
     924            return SemistandardSkewTableaux_shape_weight(p, mu)
    925925
    926926   
    927927
    class SemistandardSkewTableaux_all(Combi 
    935935        """
    936936        return "Semistandard skew tableaux"
    937937   
    938 class SemistandardSkewTableaux_n(CombinatorialClass):
     938class SemistandardSkewTableaux_size(CombinatorialClass):
    939939    def __init__(self, n):
    940940        """
    941941        EXAMPLES::
    class SemistandardSkewTableaux_n(Combina 
    964964        """
    965965        count = 0
    966966        for p in skew_partition.SkewPartitions(self.n):
    967             count += SemistandardSkewTableaux_p(p).cardinality()
     967            count += SemistandardSkewTableaux_shape(p).cardinality()
    968968        return count
    969969
    970970    def __iter__(self):
    class SemistandardSkewTableaux_n(Combina 
    982982             [[None, 2], [2]]]
    983983        """
    984984        for p in skew_partition.SkewPartitions(self.n):
    985             for ssst in SemistandardSkewTableaux_p(p):
     985            for ssst in SemistandardSkewTableaux_shape(p):
    986986                yield ssst
    987987
    988 class SemistandardSkewTableaux_nmu(CombinatorialClass):
     988class SemistandardSkewTableaux_size_weight(CombinatorialClass):
    989989    def __init__(self, n, mu):
    990990        """
    991991        EXAMPLES::
    class SemistandardSkewTableaux_nmu(Combi 
    10151015        """
    10161016        count = 0
    10171017        for p in skew_partition.SkewPartitions(self.n):
    1018             count += SemistandardSkewTableaux_pmu(p, self.mu).cardinality()
     1018            count += SemistandardSkewTableaux_shape_weight(p, self.mu).cardinality()
    10191019        return count
    10201020
    10211021    def __iter__(self):
    class SemistandardSkewTableaux_nmu(Combi 
    10261026            [[[1, 2]], [[1], [2]], [[None, 2], [1]], [[None, 1], [2]]]
    10271027        """       
    10281028        for p in skew_partition.SkewPartitions(self.n):
    1029             for ssst in SemistandardSkewTableaux_pmu(p, self.mu):
     1029            for ssst in SemistandardSkewTableaux_shape_weight(p, self.mu):
    10301030                yield ssst
    10311031
    1032 class SemistandardSkewTableaux_p(CombinatorialClass):
     1032class SemistandardSkewTableaux_shape(CombinatorialClass):
    10331033    def __init__(self, p):
    10341034        """
    10351035        EXAMPLES::
    class SemistandardSkewTableaux_p(Combina 
    10581058        """
    10591059        count = 0
    10601060        for mu in IntegerVectors(self.p.size(), self.p.size()):
    1061             count += SemistandardSkewTableaux_pmu(self.p, mu).cardinality()
     1061            count += SemistandardSkewTableaux_shape_weight(self.p, mu).cardinality()
    10621062        return count
    10631063
    10641064    def __iter__(self):
    class SemistandardSkewTableaux_p(Combina 
    10761076             [[2, 3], [3]]]
    10771077        """
    10781078        for mu in IntegerVectors(self.p.size(), self.p.size()):
    1079             for ssst in SemistandardSkewTableaux_pmu(self.p, mu):
     1079            for ssst in SemistandardSkewTableaux_shape_weight(self.p, mu):
    10801080                yield ssst
    10811081               
    1082 class SemistandardSkewTableaux_pmu(CombinatorialClass):
     1082class SemistandardSkewTableaux_shape_weight(CombinatorialClass):
    10831083    def __init__(self, p, mu):
    10841084        """
    10851085        EXAMPLES::
    def from_shape_and_word(shape, word): 
    11611161                st[i][j] = word[w_count]
    11621162                w_count += 1
    11631163    return SkewTableau(st)
    1164    
     1164
     1165
     1166# Deprecation of internal classes seems to be unnecessarily painful...
     1167from sage.misc.superseded import deprecation
     1168
     1169def SemistandardSkewTableaux_n(*args, **kargs):
     1170    """
     1171    EXAMPLES::
     1172
     1173        sage: sage.combinat.skew_tableau.SemistandardSkewTableaux_n(3)
     1174        doctest:1: DeprecationWarning: this class is deprecated. Use SemistandardSkewTableaux_size instead
     1175        See http://trac.sagemath.org/9265 for details.
     1176        Semistandard skew tableaux of size 3
     1177    """
     1178    deprecation(9265,'this class is deprecated. Use SemistandardSkewTableaux_size instead')
     1179    return SemistandardSkewTableaux(*args, **kargs)
     1180
     1181def SemistandardSkewTableaux_nmu(*args, **kargs):
     1182    """
     1183    EXAMPLES::
     1184
     1185        sage: sage.combinat.skew_tableau.SemistandardSkewTableaux_nmu(3,[2,1])
     1186        doctest:1: DeprecationWarning: this class is deprecated. Use SemistandardSkewTableaux_size_weight instead
     1187        See http://trac.sagemath.org/9265 for details.
     1188        Semistandard skew tableaux of size 3 and weight [2, 1]
     1189    """
     1190    deprecation(9265,'this class is deprecated. Use SemistandardSkewTableaux_size_weight instead')
     1191    return SemistandardSkewTableaux(*args, **kargs)
     1192
     1193def SemistandardSkewTableaux_p(*args, **kargs):
     1194    """
     1195    EXAMPLES::
     1196
     1197        sage: sage.combinat.skew_tableau.SemistandardSkewTableaux_p([[2,1],[]])
     1198        doctest:1: DeprecationWarning: this class is deprecated. Use SemistandardSkewTableaux_shape instead
     1199        See http://trac.sagemath.org/9265 for details.
     1200        Semistandard skew tableaux of shape [[2, 1], []]
     1201    """
     1202    deprecation(9265,'this class is deprecated. Use SemistandardSkewTableaux_shape instead')
     1203    return SemistandardSkewTableaux_shape(*args, **kargs)
     1204
     1205def SemistandardSkewTableaux_pmu(*args, **kargs):
     1206    """
     1207    EXAMPLES::
     1208
     1209        sage: sage.combinat.skew_tableau.SemistandardSkewTableaux_pmu([[2,1],[]],[2,1])
     1210        doctest:1: DeprecationWarning: this class is deprecated. Use SemistandardSkewTableaux_shape_weight instead
     1211        See http://trac.sagemath.org/9265 for details.
     1212        Semistandard skew tableaux of shape [[2, 1], []] and weight [2, 1]
     1213    """
     1214    deprecation(9265,'this class is deprecated. Use SemistandardSkewTableaux_shape_weight instead')
     1215    return SemistandardSkewTableaux_shape_weight(*args, **kargs)
     1216
     1217def StandardSkewTableaux_n(*args, **kargs):
     1218    """
     1219    EXAMPLES::
     1220
     1221        sage: sage.combinat.skew_tableau.StandardSkewTableaux_n(2)
     1222        doctest:1: DeprecationWarning: this class is deprecated. Use StandardSkewTableaux_size instead
     1223        See http://trac.sagemath.org/9265 for details.
     1224        Standard skew tableaux of size 2
     1225    """
     1226    deprecation(9265,'this class is deprecated. Use StandardSkewTableaux_size instead')
     1227    return StandardSkewTableaux(*args, **kargs)
     1228
     1229
     1230
  • sage/combinat/symmetric_group_algebra.py

    diff --git a/sage/combinat/symmetric_group_algebra.py b/sage/combinat/symmetric_group_algebra.py
    a b from free_module import CombinatorialFre 
    1313from sage.categories.all import FiniteDimensionalAlgebrasWithBasis
    1414import permutation
    1515import partition
    16 from tableau import Tableau, StandardTableaux_n, StandardTableaux_partition, StandardTableaux
     16from tableau import Tableau, StandardTableaux_size, StandardTableaux_shape, StandardTableaux
    1717from sage.interfaces.all import gap
    1818from sage.rings.all import factorial, QQ, PolynomialRing
    1919from sage.matrix.all import matrix
    class SymmetricGroupAlgebra_n(Combinator 
    320320        """
    321321        basis = []
    322322        for part in partition.Partitions_n(self.n):
    323             stp = StandardTableaux_partition(part)
     323            stp = StandardTableaux_shape(part)
    324324            for t1 in stp:
    325325                for t2 in stp:
    326326                    basis.append(self.epsilon_ik(t1,t2))
    class SymmetricGroupAlgebra_n(Combinator 
    386386        it = Tableau(itab)
    387387        kt = Tableau(ktab)
    388388
    389         stn = StandardTableaux_n(self.n)
     389        stn = StandardTableaux_size(self.n)
    390390
    391391        if it not in stn:
    392392            raise TypeError, "it must be a standard tableaux of size %s"%self.n
  • sage/combinat/tableau.py

    diff --git a/sage/combinat/tableau.py b/sage/combinat/tableau.py
    a b  
    11"""
    22Tableaux
     3
     4AUTHORS:
     5
     6    - Mike Hansen (2007): initial version
     7
     8    - Jason Bandlow (2011): updated to use Parent/Element model, and many
     9      minor fixes
     10
     11This file consists of the following major classes:
     12
     13    Element classes:
     14
     15        * Tableau
     16        * SemistandardTableau
     17        * StandardTableau
     18
     19    Factory classes:
     20
     21        * Tableaux
     22        * SemistandardTableaux
     23        * StandardTableaux
     24
     25    Parent classes:
     26
     27        * Tableaux_all
     28        * Tableaux_size
     29        * SemistandardTableaux_all (facade class)
     30        * SemistandardTableaux_size
     31        * SemistandardTableaux_size_inf
     32        * SemistandardTableaux_size_weight
     33        * SemistandardTableaux_shape
     34        * SemistandardTableaux_shape_inf
     35        * SemistandardTableaux_shape_weight
     36        * StandardTableaux_all (facade class)
     37        * StandardTableaux_size
     38        * StandardTableaux_shape
     39
     40TODO:
     41
     42    - Move methods that only apply to semistandard tableaux from tableau to
     43      semistandard tableau
     44
     45    - Add a class for tableaux of a given shape (eg Tableaux_shape)
    346"""
    447#*****************************************************************************
    548#       Copyright (C) 2007 Mike Hansen <mhansen@gmail.com>,
     49#                     2011 Jason Bandlow <jbandlow@gmail.com>
    650#
    751#  Distributed under the terms of the GNU General Public License (GPL)
    852#
    Tableaux 
    1559#
    1660#                  http://www.gnu.org/licenses/
    1761#*****************************************************************************
     62from sage.sets.disjoint_union_enumerated_sets import DisjointUnionEnumeratedSets
     63from sage.sets.family import Family
     64from sage.sets.non_negative_integers import NonNegativeIntegers
     65from sage.structure.element import Element
     66from sage.structure.unique_representation import UniqueRepresentation
     67from sage.structure.parent import Parent
     68from sage.misc.classcall_metaclass import ClasscallMetaclass
    1869from sage.rings.infinity import PlusInfinity
    1970from sage.rings.arith import factorial
    2071from sage.rings.integer import Integer
     72from sage.combinat.combinat import CombinatorialObject
    2173import sage.combinat.skew_tableau
    22 import partition
    2374from integer_vector import IntegerVectors
    2475import sage.libs.symmetrica.all as symmetrica
    2576import sage.misc.prandom as random
    2677import copy
    2778import permutation
     79from sage.misc.flatten import flatten
    2880from sage.groups.perm_gps.permgroup import PermutationGroup
    2981from sage.misc.misc import uniq
    30 from combinat import CombinatorialClass, CombinatorialObject, InfiniteAbstractCombinatorialClass
     82from sage.misc.sage_unittest import TestSuite
     83from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets
     84from sage.categories.infinite_enumerated_sets import InfiniteEnumeratedSets
     85from sage.categories.sets_cat import Sets
    3186import __builtin__
    3287
    33 def Tableau(t):
     88class Tableau(CombinatorialObject, Element):
    3489    """
    35     Returns the tableau object corresponding to t.  A tableau in sage is a
    36     finite list of lists, whose lengths are weakly decreasing, or an empty
    37     list, representing the empty tableau.  The entries of a tableau can be
    38     any sage object.
     90    A class to model a tableau.
     91
     92    INPUT:
     93
     94    - ``t`` -- a Tableau, a list of lists, or an empty list
     95
     96    OUTPUT:
     97
     98    - A Tableau object constructed from ``t``.
     99
     100    A tableau in Sage is a finite list of lists, whose lengths are weakly
     101    decreasing, or an empty list, representing the empty tableau.  The entries
     102    of a tableau can be any sage object.
    39103
    40104    Note that Sage uses the English convention for partitions and
    41     tableaux.
     105    tableaux; the longer rows are displayed on top.
    42106
    43107    EXAMPLES::
    44108
    def Tableau(t): 
    52116        sage: t.is_standard()
    53117        True
    54118
    55         sage: t = Tableau([['a','c','b'],[[],(2,1)]]); t
     119        sage: Tableau([['a','c','b'],[[],(2,1)]])
    56120        [['a', 'c', 'b'], [[], (2, 1)]]
    57121       
    58         sage: t = Tableau([]); t
     122        sage: Tableau([]) # The empty tableau
    59123        []
    60        
    61         sage: t = Tableau([[1],[2,3]])
     124
     125    When using code that will generate a lot of tableaux, it is slightly more
     126    efficient to construct a Tableau from the appropriate Parent object::
     127
     128        sage: T = Tableaux()
     129        sage: T([[1, 2, 3], [4, 5]])
     130        [[1, 2, 3], [4, 5]]
     131
     132    SEE ALSO:
     133
     134        - :class:`Tableaux`
     135        - :class:`SemistandardTableaux`
     136        - :class:`SemistandardTableau`
     137        - :class:`StandardTableaux`
     138        - :class:`StandardTableau`
     139
     140    TESTS::
     141
     142        sage: Tableau([[1],[2,3]])
    62143        Traceback (most recent call last):
    63144        ...
    64         ValueError: invalid tableau
     145        ValueError: A tableau must be a list of lists of weakly decreasing length.
     146        sage: Tableau([1,2,3])
     147        Traceback (most recent call last):
     148        ...
     149        ValueError: A tableau must be a list of lists.
     150
    65151    """
    66     if isinstance(t, Tableau_class):
    67         return t
    68     elif t in Tableaux_all():
    69         return Tableau_class(t)
    70     raise ValueError, "invalid tableau"
    71 
    72 class Tableau_class(CombinatorialObject):
    73     def __init__(self, t):
    74         """
     152    __metaclass__ = ClasscallMetaclass
     153
     154    @staticmethod
     155    def __classcall_private__(self, t):
     156        r"""
     157        This ensures that a Tableau is only ever constructed as an
     158        element_class call of an appropriate parent.
     159
    75160        TESTS::
    76161
    77             sage: t = Tableau([[1,2],[3,4]])
    78             sage: t == loads(dumps(t))
     162            sage: t = Tableau([[1,1],[1]])
     163            sage: TestSuite(t).run()
     164
     165            sage: t.parent()
     166            Tableaux
     167            sage: t.category()
     168            Category of elements of Tableaux
     169            sage: type(t)
     170            <class 'sage.combinat.tableau.Tableaux_all_with_category.element_class'>
     171        """
     172        if isinstance(t, Tableau):
     173            return t
     174
     175        return Tableaux_all().element_class(Tableaux_all(), t)
     176
     177    def __init__(self, parent, t):
     178        r"""
     179        Initializes a tableau.
     180
     181        TESTS::
     182
     183            sage: t = Tableaux()([[1,1],[1]])
     184            sage: s = Tableaux(3)([[1,1],[1]])
     185            sage: s==t
    79186            True
    80         """
    81         CombinatorialObject.__init__(self,t)
     187            sage: t.parent()
     188            Tableaux
     189            sage: s.parent()
     190            Tableaux of size 3
     191            sage: r = Tableaux()(s); r.parent()
     192            Tableaux
     193            sage: s is t # identical tableaux are distinct objects
     194            False
     195        """
     196        Element.__init__(self, parent)
     197        CombinatorialObject.__init__(self, t)
     198
     199        if isinstance(t, Tableau):
     200            return None
     201
     202        # CombinatorialObject verifies that t is a list
     203        # We must verify t is a list of lists
     204        if not all(isinstance(row, __builtin__.list) for row in t):
     205            raise ValueError, "A tableau must be a list of lists."
     206
     207        if not map(len,t) in sage.combinat.partition.Partitions_all():
     208            raise ValueError, "A tableau must be a list of lists of weakly decreasing length."
     209
    82210
    83211    def _latex_(self):
    84212        r"""
    class Tableau_class(CombinatorialObject) 
    86214
    87215        EXAMPLES::
    88216
    89             sage: latex(Tableau([[1,1,2],[2,3],[3]]))
     217            sage: latex(Tableau([[1,1,2],[2,3],[3]]))    # indirect doctest
    90218            {\def\lr#1{\multicolumn{1}{|@{\hspace{.6ex}}c@{\hspace{.6ex}}|}{\raisebox{-.3ex}{$#1$}}}
    91219            \raisebox{-.6ex}{$\begin{array}[b]{ccc}
    92220            \cline{1-1}\cline{2-2}\cline{3-3}
    class Tableau_class(CombinatorialObject) 
    137265
    138266        #if t is a list, convert to to a partition first
    139267        if isinstance(t, list):
    140             t = partition.Partition(t)
     268            t = sage.combinat.partition.Partition(t)
    141269
    142270        #Check to make sure that
    143271        if not self.shape().dominates(t):
    144272            raise ValueError, "the partition must dominate t"
    145273
    146 
    147274        st = copy.deepcopy(self._list)
    148275
    149276        for i in range(len(t)):
    class Tableau_class(CombinatorialObject) 
    152279
    153280        return sage.combinat.skew_tableau.SkewTableau(st)
    154281
     282    def __call__(self, *cell):
     283        r"""
     284
     285        INPUT:
     286
     287        - ``self`` -- a tableau
     288        - ``cell`` -- a pair of integers, tuple, or list specifying a cell in
     289          the tableau
     290
     291        OUTPUT:
     292
     293        - The value in the corresponding cell.
     294
     295        EXAMPLES::
     296
     297            sage: t = Tableau([[1,2,3],[4,5]])
     298            sage: t(1,0)
     299            4
     300            sage: t((1,0))
     301            4
     302            sage: t(3,3)
     303            Traceback (most recent call last):
     304            ...
     305            IndexError: The cell (3,3) is not contained in [[1, 2, 3], [4, 5]]
     306        """
     307        if isinstance(cell[0], (int, Integer)):
     308            i,j = cell[0], cell[1]
     309        else:
     310            i,j = cell[0]
     311        try:
     312            return self[i][j]
     313        except IndexError:
     314            raise IndexError, \
     315                  "The cell (%d,%d) is not contained in %s"%(i,j,self)
     316
    155317
    156318    def shape(self):
    157319        r"""
    class Tableau_class(CombinatorialObject) 
    163325            [3, 2, 1]
    164326        """
    165327
    166         return partition.Partition([len(row) for row in self])
     328        return sage.combinat.partition.Partition([len(row) for row in self])
    167329
    168330    def size(self):
    169331        """
    class Tableau_class(CombinatorialObject) 
    468630        i,j = cell
    469631        return self[i][j]
    470632   
    471     def evaluation(self):
    472         """
    473         Returns the evaluation of the word from tableau t.
     633    def weight(self):
     634        """
     635        Returns the weight of the word corresponding to the tableau ``self``.
    474636       
    475637        EXAMPLES::
    476638       
    477             sage: Tableau([[1,2],[3,4]]).evaluation()
     639            sage: Tableau([[1,2],[3,4]]).weight()
    478640            [1, 1, 1, 1]
    479641        """
    480642        ed = self.to_word().evaluation_dict()
    class Tableau_class(CombinatorialObject) 
    482644        m = max(entries) + 1 if entries else -1
    483645        return [ed.get(k,0) for k in range(1,m)]
    484646
    485     weight = evaluation
     647    evaluation = weight
    486648
    487649    def is_standard(self):
    488650        """
    class Tableau_class(CombinatorialObject) 
    508670        if fillings != range(1, t.size()+1):
    509671            return False
    510672
    511 
    512 
    513673        #Check to make sure it is increasing along the rows
    514674        for row in t:
    515675            for i in range(1, len(row)):
    516676                if row[i] <= row[i-1]:
    517677                    return False
    518678
    519 
    520679        #Check to make sure it is increasing along the columns
    521680        conj = t.conjugate()
    522681        for row in conj:
    class Tableau_class(CombinatorialObject) 
    667826            [[1, 1]]
    668827        """
    669828        res = [ [y for y in row if y <=n] for row in self]
    670         return Tableau_class([row for row in res if row != []])
     829        return Tableau([row for row in res if row != []])
    671830
    672831    def to_chain(self):
    673832        """
    class Tableau_class(CombinatorialObject) 
    8821041        """
    8831042        h = self.height()
    8841043        if h == 0:
    885             return Tableau_class([[letter]])
     1044            return Tableau([[letter]])
    8861045        h += 1
    8871046        rep = self.to_list() + [[]]
    8881047
    class Tableau_class(CombinatorialObject) 
    8981057                rep[i][j+1] = letter
    8991058                letter = new_letter
    9001059
    901         return Tableau_class([ row for row in rep if row != []])
     1060        return Tableau([ row for row in rep if row != []])
    9021061
    9031062    def _left_schensted_insert(self, letter):
    9041063        """
    class Tableau_class(CombinatorialObject) 
    9141073        """
    9151074        h = len(self)
    9161075        if h == 0:
    917             return Tableau_class([[letter]])
     1076            return Tableau([[letter]])
    9181077        h1 = h + 1
    9191078        rep = self.to_list()
    9201079        rep.reverse()
    class Tableau_class(CombinatorialObject) 
    9461105                letter = new_letter
    9471106
    9481107        rep.reverse()
    949         return Tableau_class(rep)
     1108        return Tableau(rep)
    9501109                   
    9511110                   
    9521111    def insert_word(self, w, left=False):
    class Tableau_class(CombinatorialObject) 
    9881147            sage: t.bump_multiply(t2)
    9891148            [[1, 1, 2, 2, 3], [2, 2, 3, 5], [3, 4, 5], [4, 6, 6], [5]]
    9901149        """
    991         if not isinstance(right, Tableau_class):
     1150        if not isinstance(right, Tableau):
    9921151            raise TypeError, "right must be a Tableau"
    9931152
    9941153        row = len(right)
    class Tableau_class(CombinatorialObject) 
    12591418            [0 0 0 0 1]
    12601419        """
    12611420        n = self.size()
    1262         if not isinstance(tab2, Tableau_class):
     1421        if not isinstance(tab2, Tableau):
    12631422            try:
    1264                 tab2 = Tableau_class(tab2)
     1423                tab2 = Tableau(tab2)
    12651424            except StandardError:
    12661425                raise TypeError, "tab2 must be a standard tableau"
    12671426
    class Tableau_class(CombinatorialObject) 
    13601519            return self
    13611520        else:
    13621521            #Remove the top row and insert it back in
    1363             return Tableau_class(self[1:]).insert_word(self[0],left=True)
     1522            return Tableau(self[1:]).insert_word(self[0],left=True)
    13641523
    13651524    def katabolism_sequence(self):
    13661525        """
    class Tableau_class(CombinatorialObject) 
    13811540        return res
    13821541
    13831542    def lambda_katabolism(self, part):
    1384         """
     1543        r"""
     1544        For a partition ``lambda`` and a tableau ``T``, the
     1545        ``lambda``-katabolism of ``T`` is defined by performing the following
     1546        steps.
     1547
     1548        1. Truncate the parts of ``lambda`` so that ``lambda`` is contained
     1549        in the shape of ``T``.  Let ``m`` be the length of this partition.
     1550
     1551        2. Let ``T_a`` be the first ``m`` rows of ``T``, and ``T_b`` be the
     1552        remaining rows.
     1553
     1554        3. Let ``S_a`` be the skew tableau ``T_a / lambda``.
     1555
     1556        4. Concatenate the reading words of ``S_a`` and ``T_b``, and insert
     1557        into a tableau.
     1558
    13851559        EXAMPLES::
    13861560       
     1561            sage: Tableau([[1,1,3],[2,4,5]]).lambda_katabolism([2,1])
     1562            [[3, 5], [4]]
    13871563            sage: t = Tableau([[1,1,3,3],[2,3],[3]])
    13881564            sage: t.lambda_katabolism([])
    13891565            [[1, 1, 3, 3], [2, 3], [3]]
    class Tableau_class(CombinatorialObject) 
    14031579        #Reduce the partition if it is too big for the tableau
    14041580        part  = [ min(part[i],len(self[i])) for i in range(min(len(self), len(part))) ]
    14051581        if self.shape() == part:
    1406             return Tableau_class([])
    1407 
    1408         w1 = Tableau_class( self[len(part):] ).to_word()
    1409 
    1410         if len(self)-len(part)+11 > 0:
    1411             t2 = Tableau_class(self[:len(part)])
    1412         else:
    1413             t2 = self
    1414 
    1415         if t2.shape() == part:
    1416             t2 = Tableau_class([])
    1417         else:
    1418             part += [0]*(len(t2)-len(part))
    1419             t2 = [[t2[i][j] for j in range(part[i], len(t2[i]))]  for i in range(len(t2)) ]
    1420             t2 = Tableau_class([ row for row in t2 if row != [] ])
    1421 
    1422         w2 = t2.to_word()
    1423         return Tableau_class([]).insert_word(w2+w1)
     1582            return Tableau([])
     1583
     1584        m = len(part)
     1585
     1586        w1 = flatten([row for row in reversed(self[m:])])
     1587
     1588        w2 = []
     1589        for i,row in enumerate(reversed(self[:m])):
     1590            w2 += row[ part[-1-i] : ]
     1591
     1592        return Tableau([]).insert_word(w2+w1)
    14241593           
    14251594
    14261595    def reduced_lambda_katabolism(self, part):
    class Tableau_class(CombinatorialObject) 
    14591628        a = self[0][0]
    14601629
    14611630        part = [ min(part1[i], len(self[i])) for i in range(min(len(part1),len(self)))]
    1462         tt_part = Tableau_class([ [a+i]*part[i] for i in range(len(part)) ])
    1463         t_part = Tableau_class([[self[i][j] for j in range(part[i])] for i in range(len(part))])
     1631        tt_part = Tableau([ [a+i]*part[i] for i in range(len(part)) ])
     1632        t_part = Tableau([[self[i][j] for j in range(part[i])] for i in range(len(part))])
    14641633
    14651634        if t_part == tt_part:
    14661635            return res
    class Tableau_class(CombinatorialObject) 
    14901659        if res == []:
    14911660            return self
    14921661        else:
    1493             return Tableau_class([])
     1662            return Tableau([])
    14941663
    14951664       
    14961665    def promotion_operator(self, i):
    class Tableau_class(CombinatorialObject) 
    16031772            lres[i] = ll[i] - ll[i-1]
    16041773        return lres
    16051774
    1606 def StandardTableau(t):
     1775class SemistandardTableau(Tableau):
    16071776    """
    1608     Returns the standard tableau object corresponding to t.
     1777    A class to model a semistandard tableau.
     1778
     1779    INPUT:
     1780
     1781    - ``t`` -- a Tableau, a list of lists, or an empty list
     1782
     1783    OUTPUT:
     1784
     1785    - A SemistandardTableau object constructed from ``t``.
     1786
     1787    A semistandard tableau is a tableau whose entries are positive integers,
     1788    which are weakly increasing in rows and strictly increasing down columns.
    16091789   
    16101790    Note that Sage uses the English convention for partitions and
    1611     tableaux.
     1791    tableaux; the longer rows are displayed on top.
     1792
     1793    EXAMPLES::
     1794
     1795        sage: t = SemistandardTableau([[1,2,3],[2,3]]); t
     1796        [[1, 2, 3], [2, 3]]
     1797        sage: t.shape()
     1798        [3, 2]
     1799        sage: t.pp() # pretty print
     1800        1 2 3
     1801        2 3
     1802        sage: t = Tableau([[1,2],[2]])
     1803        sage: s = SemistandardTableau(t); s
     1804        [[1, 2], [2]]
     1805        sage: SemistandardTableau([]) # The empty tableau
     1806        []
     1807
     1808    When using code that will generate a lot of tableaux, it is slightly more
     1809    efficient to construct a SemistandardTableau from the appropriate Parent object::
     1810
     1811        sage: SST = SemistandardTableaux()
     1812        sage: SST([[1, 2, 3], [4, 5]])
     1813        [[1, 2, 3], [4, 5]]
     1814
     1815    SEE ALSO:
     1816
     1817        - :class:`Tableaux`
     1818        - :class:`Tableau`
     1819        - :class:`SemistandardTableaux`
     1820        - :class:`StandardTableaux`
     1821        - :class:`StandardTableau`
     1822
     1823    TESTS::
     1824
     1825        sage: SemistandardTableau([[1,2,3],[1]])
     1826        Traceback (most recent call last):
     1827        ...
     1828        ValueError: Columns are not strictly increasing.
     1829
     1830        sage: SemistandardTableau([[1,2,1]])
     1831        Traceback (most recent call last):
     1832        ...
     1833        ValueError: Rows are not weakly increasing.
     1834
     1835        sage: SemistandardTableau([[0,1]])
     1836        Traceback (most recent call last):
     1837        ...
     1838        ValueError: Entries must be non-negative integers
     1839    """
     1840    __metaclass__ = ClasscallMetaclass
     1841
     1842    @staticmethod
     1843    def __classcall_private__(self, t):
     1844        r"""
     1845        This ensures that a SemistandardTableau is only ever constructed as an
     1846        element_class call of an appropriate parent.
     1847
     1848        TESTS::
     1849
     1850            sage: t = SemistandardTableau([[1,1],[2]])
     1851            sage: TestSuite(t).run()
     1852
     1853            sage: t.parent()
     1854            Semistandard tableaux
     1855            sage: t.category()
     1856            Category of elements of Semistandard tableaux
     1857            sage: type(t)
     1858            <class 'sage.combinat.tableau.SemistandardTableaux_all_with_category.element_class'>
     1859        """
     1860        if isinstance(t, SemistandardTableau):
     1861            return t
     1862
     1863        return SemistandardTableaux_all().element_class(SemistandardTableaux_all(), t)
     1864
     1865
     1866    def __init__(self, parent, t):
     1867        r"""
     1868        Initializes a semistandard tableau.
     1869
     1870        TESTS::
     1871
     1872            sage: t = Tableaux()([[1,1],[2]])
     1873            sage: s = SemistandardTableaux(3)([[1,1],[2]])
     1874            sage: s==t
     1875            True
     1876            sage: s.parent()
     1877            Semistandard tableaux of size 3 and maximum entry 3
     1878            sage: r = SemistandardTableaux(3)(t); r.parent()
     1879            Semistandard tableaux of size 3 and maximum entry 3
     1880            sage: isinstance(r, Tableau)
     1881            True
     1882        """
     1883        Tableau.__init__(self, parent, t)
     1884
     1885        # Verify row-weak condition and integer entries
     1886        for row in t:
     1887            if not isinstance(row[0], (int, Integer)) or row[0]<=0:
     1888                raise ValueError, "Entries must be non-negative integers"
     1889            for i in range(1, len(row)):
     1890                if not isinstance(row[i], (int, Integer)):
     1891                    raise ValueError, "Entries must be integers"
     1892                if row[i-1] > row[i]:
     1893                    raise ValueError, "Rows are not weakly increasing."
     1894
     1895
     1896        # Verify col-strict condition
     1897        for i in range(len(t) - 1):
     1898            M = len(t[i+1])
     1899            for j,x in enumerate(t[i]):
     1900                if (j < M and x >= t[i+1][j]):
     1901                    raise ValueError, "Columns are not strictly increasing."
     1902
     1903class StandardTableau(SemistandardTableau):
     1904    """
     1905    A class to model a standard tableau.
     1906
     1907    INPUT:
     1908
     1909    - ``t`` -- a Tableau, a list of lists, or an empty list
     1910
     1911    OUTPUT:
     1912
     1913    - A StandardTableau object constructed from ``t``.
     1914
     1915    A standard tableau is a semistandard tableau whose entries are exactly the
     1916    positive integers from 1 to ``n``, where ``n`` is the size of the tableau.
    16121917   
    16131918    EXAMPLES::
    16141919   
    def StandardTableau(t): 
    16161921        [[1, 2, 3], [4, 5]]
    16171922        sage: t.shape()
    16181923        [3, 2]
     1924        sage: t.pp() # pretty print
     1925        1 2 3
     1926        4 5
    16191927        sage: t.is_standard()
    16201928        True
    1621 
    1622         sage: t = StandardTableau([[1,2,3],[4,4]])
     1929        sage: StandardTableau([]) # The empty tableau
     1930        []
     1931
     1932    When using code that will generate a lot of tableaux, it is slightly more
     1933    efficient to construct a StandardTableau from the appropriate Parent object::
     1934
     1935        sage: ST = StandardTableaux()
     1936        sage: ST([[1, 2, 3], [4, 5]])
     1937        [[1, 2, 3], [4, 5]]
     1938
     1939    SEE ALSO:
     1940
     1941        - :class:`Tableaux`
     1942        - :class:`Tableau`
     1943        - :class:`SemistandardTableaux`
     1944        - :class:`SemistandardTableau`
     1945        - :class:`StandardTableaux`
     1946
     1947        sage: StandardTableau([[1,2,3],[4,4]])
    16231948        Traceback (most recent call last):
    16241949        ...
    1625         ValueError: not a standard tableau
     1950        ValueError: The entries must consist of exactly the numbers 1..n
     1951        sage: StandardTableau([[1,3,2]])
     1952        Traceback (most recent call last):
     1953        ...
     1954        ValueError: Rows are not weakly increasing.
    16261955    """
    1627     if isinstance(t, StandardTableau_class):
    1628         return t
    1629     elif t in StandardTableaux_all():
    1630         return StandardTableau_class(t)
    1631     raise ValueError, "not a standard tableau"
    1632 
    1633 class StandardTableau_class(Tableau_class):
    1634    
     1956    __metaclass__ = ClasscallMetaclass
     1957
     1958    @staticmethod
     1959    def __classcall_private__(self, t):
     1960        r"""
     1961        This ensures that a StandardTableau is only ever constructed as an
     1962        element_class call of an appropriate parent.
     1963
     1964        TESTS::
     1965
     1966            sage: t = StandardTableau([[1,2],[3]])
     1967            sage: TestSuite(t).run()
     1968
     1969            sage: t.parent()
     1970            Standard tableaux
     1971            sage: type(t)
     1972            <class 'sage.combinat.tableau.StandardTableaux_all_with_category.element_class'>
     1973        """
     1974        if isinstance(t, StandardTableau):
     1975            return t
     1976
     1977        return StandardTableaux_all().element_class(StandardTableaux_all(), t)
     1978
     1979    def __init__(self, parent, t):
     1980        r"""
     1981        Initializes a standard tableau.
     1982
     1983        TESTS::
     1984
     1985            sage: t = Tableaux()([[1,2],[3]])
     1986            sage: s = StandardTableaux(3)([[1,2],[3]])
     1987            sage: s==t
     1988            True
     1989            sage: s.parent()
     1990            Standard tableaux of size 3
     1991            sage: r = StandardTableaux(3)(t); r.parent()
     1992            Standard tableaux of size 3
     1993            sage: isinstance(r, Tableau)
     1994            True
     1995        """
     1996        SemistandardTableau.__init__(self, parent, t)
     1997
     1998        # Verify that the entries are exactly the numbers 1..n
     1999        entries = []
     2000        for row in self:
     2001            entries += row
     2002        entries.sort()
     2003        if len(entries)>0 and entries != range(1, max(entries)+1):
     2004            raise ValueError, "The entries must consist of exactly the numbers 1..n"
     2005
    16352006    def content(self, k):
    16362007        """
    16372008        Returns the content of ``k`` in a standard tableau. That is, if
    class StandardTableau_class(Tableau_clas 
    16552026            return c-r
    16562027          except ValueError:
    16572028            pass
    1658         raise ValueError, '%d does not appear in tableau'%k
     2029        raise ValueError, "%d does not appear in tableau"%k
    16592030
    16602031def from_chain(chain):
    16612032    """
    def from_chain(chain): 
    16722043        for j in range(len(chain[i-1])):
    16732044            for k in range(chain[i-1][j]):
    16742045                res[j][k] = i -1
    1675     return Tableau_class(res)
     2046    return Tableau(res)
    16762047
    16772048def from_shape_and_word(shape, w, order = "French"):
    16782049    r"""
    def from_shape_and_word(shape, w, order  
    17152086        j += l
    17162087    if order == "French":
    17172088        res.reverse()
    1718     return Tableau_class(res)
    1719 
    1720 def Tableaux(n=None):
     2089    return Tableau(res)
     2090
     2091class Tableaux(UniqueRepresentation, Parent):
    17212092    """
    1722     Returns the combinatorial class of tableaux. If n is specified,
    1723     then it returns the combinatorial class of all tableaux of size n.  A
    1724     tableau in sage is a finite list of lists, whose lengths are weakly
    1725     decreasing.  The entries can be anything at all.
    1726    
     2093    A factory class for the various classes of tableaux.
     2094
     2095    INPUT:
     2096
     2097    - ``n`` (optional) -- a non-negative integer
     2098
     2099    OUTPUT:
     2100
     2101    - If ``n`` is specified, the class of tableaux of size ``n``. Otherwise,
     2102      the class of all tableaux.
     2103
     2104    A tableau in Sage is a finite list of lists, whose lengths are weakly
     2105    decreasing, or an empty list, representing the empty tableau.  The entries
     2106    of a tableau can be any sage object. Because of this, no enumeration
     2107    through the set of Tableaux is possible.
     2108
    17272109    EXAMPLES::
    1728    
     2110
    17292111        sage: T = Tableaux(); T
    17302112        Tableaux
    1731         sage: [[1,2],[3,4]] in T
     2113        sage: T3 = Tableaux(3); T3
     2114        Tableaux of size 3
     2115        sage: [['a','b']] in T
    17322116        True
    1733         sage: [[1,2],[3]] in T
     2117        sage: [['a','b']] in T3
     2118        False
     2119        sage: t = T3([[1,1,1]]); t
     2120        [[1, 1, 1]]
     2121        sage: t in T
    17342122        True
    1735         sage: [1,2,3] in T
     2123        sage: t.parent()
     2124        Tableaux of size 3
     2125        sage: T([]) # the empty tableau
     2126        []
     2127        sage: T.category()
     2128        Category of sets
     2129
     2130    SEE ALSO:
     2131
     2132        - :class:`Tableau`
     2133        - :class:`SemistandardTableaux`
     2134        - :class:`SemistandardTableau`
     2135        - :class:`StandardTableaux`
     2136        - :class:`StandardTableau`
     2137
     2138    TESTS::
     2139
     2140        sage: t = Tableaux(3)([[1,2],[3]])
     2141        sage: t.parent()
     2142        Tableaux of size 3
     2143        sage: Tableaux(t)
     2144        Traceback (most recent call last):
     2145        ...
     2146        ValueError: The argument to Tableaux() must be a non-negative integer.
     2147        sage: Tableaux(3)([[1, 1]])
     2148        Traceback (most recent call last):
     2149        ...
     2150        ValueError: [[1, 1]] is not an element of Tableaux of size 3.
     2151
     2152        sage: t0 = Tableau([[1]])
     2153        sage: t1 = Tableaux()([[1]])
     2154        sage: t2 = Tableaux()(t1)
     2155        sage: t0 == t1 == t2
     2156        True
     2157        sage: t1 in Tableaux()
     2158        True
     2159        sage: t1 in Tableaux(1)
     2160        True
     2161        sage: t1 in Tableaux(2)
    17362162        False
    1737         sage: [[42, -1, 3.1], ['parrot', []]] in T
     2163
     2164        sage: [[1]] in Tableaux()
    17382165        True
     2166        sage: [] in Tableaux(0)
     2167        True
     2168    """
     2169    @staticmethod
     2170    def __classcall_private__(cls, *args, **kwargs):
     2171        r"""
     2172        This is a factory class which returns the appropriate parent based on
     2173        arguments.  See the documentation for :class:`Tableaux` for more
     2174        information.
     2175
     2176        TESTS::
     2177
     2178            sage: Tableaux()
     2179            Tableaux
     2180            sage: Tableaux(3)
     2181            Tableaux of size 3
     2182        """
     2183        if args:
     2184            n = args[0]
     2185        elif 'n' in kwargs:
     2186            n = kwargs[n]
     2187        else:
     2188            n = None
     2189
     2190        if n == None:
     2191            return Tableaux_all()
     2192        else:
     2193            if not isinstance(n,(int, Integer)) or n < 0:
     2194                raise ValueError, "The argument to Tableaux() must be a non-negative integer."
     2195            return Tableaux_size(n)
     2196
     2197    Element = Tableau
     2198
     2199    def _element_constructor_(self, t):
     2200        r"""
     2201        Constructs an object from t as an element of self, if possible. This
     2202        is inherited by all Tableaux, SemistandardTableaux, and
     2203        StandardTableaux classes.
     2204
     2205        INPUT:
     2206
     2207        - ``t`` -- Data which can be interpreted as a tableau
     2208
     2209        OUTPUT:
     2210
     2211        - The corresponding tableau object
     2212
     2213        TESTS::
     2214
     2215            sage: T = Tableaux(3)
     2216            sage: T([[1,2,1]]).parent() is T     # indirect doctest
     2217            True
     2218            sage: T( StandardTableaux(3)([[1, 2, 3]])).parent() is T
     2219            True
     2220            sage: T([[1,2]])
     2221            Traceback (most recent call last):
     2222            ...
     2223            ValueError: [[1, 2]] is not an element of Tableaux of size 3.
     2224        """
     2225        if not t in self:
     2226            raise ValueError, "%s is not an element of %s."%(t, self)
     2227
     2228        return self.element_class(self, t)
     2229
     2230class Tableaux_all(Tableaux):
     2231
     2232    def __init__(self):
     2233        r"""
     2234        Initializes the class of all tableaux
     2235
     2236        TESTS::
     2237
     2238            sage: T = sage.combinat.tableau.Tableaux_all()
     2239            sage: TestSuite(T).run()
     2240
     2241        """
     2242        super(Tableaux_all, self).__init__(category=Sets())
    17392243   
    1740     ::
    1741    
    1742         sage: T = Tableaux(4); T
    1743         Tableaux of size 4
    1744         sage: [[1,2],[3,4]] in T
    1745         True
    1746         sage: [[1,2],[3]] in T
    1747         False
    1748     """
    1749     if n == None:
    1750         return Tableaux_all()
    1751     else:
    1752         return Tableaux_n(n)
    1753 
    1754 class Tableaux_all(CombinatorialClass):
    1755     def __init__(self):
     2244    def __contains__(self, x):
    17562245        """
    17572246        TESTS::
    17582247       
    1759             sage: T = Tableaux()
    1760             sage: T == loads(dumps(T))
    1761             True
    1762         """
    1763         pass
    1764    
    1765     def __contains__(self, x):
    1766         """
    1767         TESTS::
    1768        
    1769             sage: T = Tableaux()   
     2248            sage: T = sage.combinat.tableau.Tableaux_all()
    17702249            sage: [[1,2],[3,4]] in T
    17712250            True
    17722251            sage: [[1,2],[3]] in T
    17732252            True
     2253            sage: [] in T
     2254            True
     2255            sage: [['a','b']] in T
     2256            True
     2257            sage: Tableau([['a']]) in T
     2258            True
     2259
    17742260            sage: [1,2,3] in T
    17752261            False
    1776         """
    1777         if isinstance(x, Tableau_class):
     2262            sage: [[1],[1,2]] in T
     2263            False
     2264        """
     2265        if isinstance(x, self.element_class):
    17782266            return True
    1779        
    1780         if not isinstance(x, __builtin__.list):
     2267        try:
     2268            x = Tableau(x)
     2269        except ValueError:
    17812270            return False
    1782        
    1783         for row in x:
    1784             if not isinstance(row, __builtin__.list):
    1785                 return False
    1786 
    1787         if map(len, x) not in partition.Partitions_all():
    1788             return False
    1789            
    17902271        return True
    17912272
    17922273    def _repr_(self):
    17932274        """
    17942275        TESTS::
    17952276       
    1796             sage: repr(Tableaux())
     2277            sage: repr(Tableaux())    # indirect doctest
    17972278            'Tableaux'
    17982279        """
    17992280        return "Tableaux"
    18002281
     2282    def an_element(self):
     2283        r"""
     2284        Returns a particular element of the class.
     2285
     2286        TESTS::
     2287
     2288            sage: T = Tableaux()
     2289            sage: T.an_element()
     2290            [[1, 1], [1]]
     2291        """
     2292        return self.element_class(self, [[1, 1], [1]])
     2293
     2294
    18012295    def list(self):
    18022296        """
    18032297        TESTS::
    class Tableaux_all(CombinatorialClass): 
    18192313            NotImplementedError
    18202314        """
    18212315        raise NotImplementedError
     2316
     2317
     2318
     2319class Tableaux_size(Tableaux):
     2320    def __init__(self, n):
     2321        r"""
     2322        Initializes the class of tableaux of size n
     2323
     2324        TESTS::
     2325
     2326            sage: T = sage.combinat.tableau.Tableaux_size(3)
     2327            sage: TestSuite(T).run()
     2328
     2329            sage: T = sage.combinat.tableau.Tableaux_size(0)
     2330            sage: TestSuite(T).run()
     2331        """
     2332        super(Tableaux_size, self).__init__(category=Sets())
     2333        self.size = n
    18222334   
    1823 
    1824 class Tableaux_n(CombinatorialClass):
    1825     def __init__(self, n):
     2335    def __contains__(self,x):
     2336        """
     2337        TESTS::
     2338
     2339            sage: T = sage.combinat.tableau.Tableaux_size(3)
     2340            sage: [[2,4], [1]] in T
     2341            True
     2342
     2343            sage: [[2,4],[1,3]] in T
     2344            False
     2345        """
     2346        if isinstance(x, self.element_class) and sum(map(len,x))==self.size:
     2347            return True
     2348        try:
     2349            x = Tableau(x)
     2350        except ValueError:
     2351            return False
     2352        return sum(map(len,x))==self.size
     2353
     2354    def _repr_(self):
    18262355        """
    18272356        TESTS::
    18282357       
    1829             sage: T = Tableaux(3)
    1830             sage: T == loads(dumps(T))
    1831             True
    1832         """
    1833         self.n = n
    1834 
    1835 
    1836     def _repr_(self):
    1837         """
     2358            sage: repr(Tableaux(4))    # indirect doctest
     2359            'Tableaux of size 4'
     2360        """
     2361        return "Tableaux of size %s"%self.size
     2362
     2363    def an_element(self):
     2364        r"""
     2365        Returns a particular element of the class.
     2366
    18382367        TESTS::
    1839        
    1840             sage: repr(Tableaux(4))
    1841             'Tableaux of size 4'
    1842         """
    1843         return "Tableaux of size %s"%self.n
    1844    
    1845     def __contains__(self,x):
    1846         """
    1847         EXAMPLES::
    1848        
    1849             sage: [[2,4],[1,3]] in Tableaux(3)
    1850             False
    1851             sage: [[2,4], [1]] in Tableaux(3)
    1852             True
    1853         """
    1854         return x in Tableaux() and sum(map(len, x)) == self.n
    1855    
     2368
     2369            sage: T = sage.combinat.tableau.Tableaux_size(3)
     2370            sage: T.an_element()
     2371            [[1, 1], [1]]
     2372            sage: T = sage.combinat.tableau.Tableaux_size(0)
     2373            sage: T.an_element()
     2374            []
     2375        """
     2376        if self.size==0:
     2377            return self.element_class(self, [])
     2378
     2379        if self.size==1:
     2380            return self.element_class(self, [[1]])
     2381
     2382        return self.element_class(self, [[1]*(self.size-1),[1]])
     2383
    18562384    def list(self):
    18572385        """
    18582386        TESTS::
    class Tableaux_n(CombinatorialClass): 
    18752403        """
    18762404        raise NotImplementedError
    18772405
    1878 def StandardTableaux(n=None):
     2406
     2407
     2408##########################
     2409# Semi-standard tableaux #
     2410##########################
     2411class SemistandardTableaux(Tableaux):
    18792412    """
    1880     Returns the combinatorial class of standard tableaux. If n is
    1881     specified and is an integer, then it returns the combinatorial
    1882     class of all standard tableaux of size n. If n is a partition, then
    1883     it returns the class of all standard tableaux of shape n.
     2413    A factory class for the various classes of semistandard tableaux.
     2414
     2415    INPUT:
     2416
     2417    Keyword arguments:
     2418
     2419    - ``size`` -- The size of the tableaux
     2420    - ``shape`` -- The shape of the tableaux
     2421    - ``eval`` -- The weight (also called content or weight) of the tableaux
     2422    - `max_entry` -- A maximum entry for the tableaux.  This can be a positive
     2423      integer or infinity (oo). If ``size`` or ``shape`` are specified, `max_entry`
     2424      defaults to be ``size`` or the size of ``shape``.
     2425
     2426    Positional arguments:
     2427
     2428    - The first argument is interpreted as either ``size`` or ``shape`` according to
     2429      whether it is an integer or a partition
     2430    - The second keyword argument will always be interpreted as ``eval``
     2431
     2432    OUTPUT:
     2433
     2434    - The appropriate class, after checking basic consistency tests. (For
     2435      example, specifying ``eval`` implies a value for `max_entry`).
     2436
     2437    A semistandard tableau is a tableau whose entries are positive integers,
     2438    which are weakly increasing in rows and strictly increasing down columns.
     2439    Note that Sage uses the English convention for partitions and tableaux;
     2440    the longer rows are displayed on top.
     2441
     2442    Classes of semistandard tableaux can be iterated over if and only if there is some
     2443    restriction.
     2444
     2445    EXAMPLES::
     2446
     2447        sage: SST = SemistandardTableaux([2,1]); SST
     2448        Semistandard tableaux of shape [2, 1] and maximum entry 3
     2449        sage: SST.list()
     2450        [[[1, 1], [2]],
     2451         [[1, 1], [3]],
     2452         [[1, 2], [2]],
     2453         [[1, 2], [3]],
     2454         [[1, 3], [2]],
     2455         [[1, 3], [3]],
     2456         [[2, 2], [3]],
     2457         [[2, 3], [3]]]
     2458
     2459        sage: SST = SemistandardTableaux(3); SST
     2460        Semistandard tableaux of size 3 and maximum entry 3
     2461        sage: SST.list()
     2462        [[[1, 1, 1]],
     2463         [[1, 1, 2]],
     2464         [[1, 1, 3]],
     2465         [[1, 2, 2]],
     2466         [[1, 2, 3]],
     2467         [[1, 3, 3]],
     2468         [[2, 2, 2]],
     2469         [[2, 2, 3]],
     2470         [[2, 3, 3]],
     2471         [[3, 3, 3]],
     2472         [[1, 1], [2]],
     2473         [[1, 1], [3]],
     2474         [[1, 2], [2]],
     2475         [[1, 2], [3]],
     2476         [[1, 3], [2]],
     2477         [[1, 3], [3]],
     2478         [[2, 2], [3]],
     2479         [[2, 3], [3]],
     2480         [[1], [2], [3]]]
     2481
     2482        sage: SST = SemistandardTableaux(3, max_entry=2); SST
     2483        Semistandard tableaux of size 3 and maximum entry 2
     2484        sage: SST.list()
     2485        [[[1, 1, 1]],
     2486         [[1, 1, 2]],
     2487         [[1, 2, 2]],
     2488         [[2, 2, 2]],
     2489         [[1, 1], [2]],
     2490         [[1, 2], [2]]]
     2491
     2492        sage: SST = SemistandardTableaux(3, max_entry=oo); SST
     2493        Semistandard tableaux of size 3
     2494        sage: SST[123]
     2495        [[3, 4], [6]]
     2496
     2497        sage: SemistandardTableaux(max_entry=2)[11]
     2498        [[1, 1], [2]]
     2499
     2500        sage: SemistandardTableaux()[0]
     2501        []
     2502
     2503    SEE ALSO:
     2504
     2505        - :class:`Tableaux`
     2506        - :class:`Tableau`
     2507        - :class:`SemistandardTableau`
     2508        - :class:`StandardTableaux`
     2509        - :class:`StandardTableau`
     2510    """
     2511    @staticmethod
     2512    def __classcall_private__(cls, *args, **kwargs):
     2513        r"""
     2514        This is a factory class which returns the appropriate parent based on
     2515        arguments.  See the documentation for :class:`SemistandardTableaux` for more
     2516        information.
     2517
     2518        TESTS::
     2519
     2520            sage: SemistandardTableaux()
     2521            Semistandard tableaux
     2522            sage: SemistandardTableaux(3)
     2523            Semistandard tableaux of size 3 and maximum entry 3
     2524            sage: SemistandardTableaux(size=3)
     2525            Semistandard tableaux of size 3 and maximum entry 3
     2526            sage: SemistandardTableaux(0)
     2527            Semistandard tableaux of size 0 and maximum entry 0
     2528            sage: SemistandardTableaux([2,1])
     2529            Semistandard tableaux of shape [2, 1] and maximum entry 3
     2530            sage: SemistandardTableaux(shape=[2,1])
     2531            Semistandard tableaux of shape [2, 1] and maximum entry 3
     2532            sage: SemistandardTableaux([])
     2533            Semistandard tableaux of shape [] and maximum entry 0
     2534            sage: SemistandardTableaux(eval=[2,1])
     2535            Semistandard tableaux of size 3 and weight [2, 1]
     2536            sage: SemistandardTableaux(max_entry=3)
     2537            Semistandard tableaux with maximum entry 3
     2538            sage: SemistandardTableaux(3, [2,1])
     2539            Semistandard tableaux of size 3 and weight [2, 1]
     2540            sage: SemistandardTableaux(3, shape=[2,1])
     2541            Semistandard tableaux of shape [2, 1] and maximum entry 3
     2542            sage: SemistandardTableaux(3, [2,1], shape=[2,1])
     2543            Semistandard tableaux of shape [2, 1] and weight [2, 1]
     2544            sage: SemistandardTableaux(3, max_entry=4)
     2545            Semistandard tableaux of size 3 and maximum entry 4
     2546            sage: SemistandardTableaux(3, max_entry=oo)
     2547            Semistandard tableaux of size 3
     2548            sage: SemistandardTableaux([2, 1], max_entry=oo)
     2549            Semistandard tableaux of shape [2, 1]
     2550            sage: SemistandardTableaux([2, 1], [2, 1])
     2551            Semistandard tableaux of shape [2, 1] and weight [2, 1]
     2552            sage: mu = Partition([2,1]); SemistandardTableaux(mu, mu)
     2553            Semistandard tableaux of shape [2, 1] and weight [2, 1]
     2554            sage: SemistandardTableaux(3, [2, 1], max_entry=2)
     2555            Semistandard tableaux of size 3 and weight [2, 1]
     2556
     2557            sage: SemistandardTableaux(3, shape=[2])
     2558            Traceback (most recent call last):
     2559            ...
     2560            ValueError: size and shape are different sizes
     2561
     2562            sage: SemistandardTableaux(3, [2])
     2563            Traceback (most recent call last):
     2564            ...
     2565            ValueError: size and eval are different sizes
     2566
     2567            sage: SemistandardTableaux([2],[3])
     2568            Traceback (most recent call last):
     2569            ...
     2570            ValueError: shape and eval are different sizes
     2571
     2572            sage: SemistandardTableaux(2,[2], max_entry=4)
     2573            Traceback (most recent call last):
     2574            ...
     2575            ValueError: the maximum entry must match the weight
     2576
     2577            sage: SemistandardTableaux(eval=[2], max_entry=oo)
     2578            Traceback (most recent call last):
     2579            ...
     2580            ValueError: the maximum entry must match the weight
     2581
     2582            sage: SemistandardTableaux([[1]])
     2583            Traceback (most recent call last):
     2584            ...
     2585            ValueError: shape must be a partition
     2586        """
     2587        # Process the keyword arguments -- allow for original syntax where
     2588        #   n == size,  p== shape and mu == eval
     2589        n = kwargs.get('n', None)
     2590        size = kwargs.get('size', n)
     2591
     2592        p = kwargs.get('p', None)
     2593        shape = kwargs.get('shape', p)
     2594
     2595        mu = kwargs.get('eval', None)
     2596        mu = kwargs.get("mu", mu)
     2597
     2598        max_entry = kwargs.get('max_entry', None)
     2599
     2600        # Process the positional arguments
     2601        if args:
     2602            # The first arg could be either a size or a shape
     2603            if isinstance(args[0], (int, Integer)):
     2604                if size is not None:
     2605                    raise ValueError, "size was specified more than once"
     2606                else:
     2607                    size = args[0]
     2608            else:
     2609                if shape is not None:
     2610                    raise ValueError, "the shape was specified more than once"
     2611                shape = args[0] # we check it's a partition later
     2612
     2613        if len(args) == 2:
     2614            # The second non-keyword argument is the weight
     2615            if mu is not None:
     2616                raise ValueError, "the weight was specified more than once"
     2617            else:
     2618                mu = args[1]
     2619
     2620
     2621        # Consistency checks
     2622        if size is not None:
     2623            if not isinstance(size, (int, Integer)):
     2624                raise ValueError, "size must be an integer"
     2625            elif size < 0:
     2626                raise ValueError, "size must be non-negative"
     2627
     2628        if shape is not None:
     2629            # use in (and not isinstance) below so that lists can be used as
     2630            # shorthand
     2631            if not shape in sage.combinat.partition.Partitions():
     2632                raise ValueError, "shape must be a partition"
     2633            shape = sage.combinat.partition.Partition(shape)
     2634
     2635        if mu is not None:
     2636            if (not mu in sage.combinat.composition.Compositions()) and\
     2637                    (not mu in sage.combinat.partition.Partitions()):
     2638                raise ValueError, "mu must be a composition"
     2639            mu = sage.combinat.composition.Composition(mu)
     2640
     2641        is_inf = max_entry is PlusInfinity()
     2642
     2643        if max_entry is not None:
     2644            if not is_inf and not isinstance(max_entry, (int, Integer)):
     2645                raise ValueError, "max_entry must be an integer or PlusInfinity"
     2646            elif max_entry <= 0:
     2647                raise ValueError, "max_entry must be positive"
     2648
     2649        if (mu is not None) and (max_entry is not None):
     2650            if max_entry != len(mu):
     2651                raise ValueError, "the maximum entry must match the weight"
     2652
     2653        if (size is not None) and (shape is not None):
     2654            if sum(shape) != size:
     2655                # This could return an empty class instead of an error
     2656                raise ValueError, "size and shape are different sizes"
     2657
     2658        if (size is not None) and (mu is not None):
     2659            if sum(mu) != size:
     2660                # This could return an empty class instead of an error
     2661                raise ValueError, "size and eval are different sizes"
     2662
     2663        # Dispatch appropriately
     2664        if (shape is not None) and (mu is not None):
     2665            if sum(shape) != sum(mu):
     2666                # This could return an empty class instead of an error
     2667                raise ValueError, "shape and eval are different sizes"
     2668            else:
     2669                return SemistandardTableaux_shape_weight(shape, mu)
     2670
     2671        if (shape is not None):
     2672            if is_inf:
     2673                return SemistandardTableaux_shape_inf(shape)
     2674            return SemistandardTableaux_shape(shape, max_entry)
     2675
     2676        if (mu is not None):
     2677            return SemistandardTableaux_size_weight(sum(mu), mu)
     2678
     2679        if (size is not None):
     2680            if is_inf:
     2681                return SemistandardTableaux_size_inf(size)
     2682            return SemistandardTableaux_size(size, max_entry)
     2683
     2684        return SemistandardTableaux_all(max_entry)
     2685
     2686    Element = SemistandardTableau
     2687
     2688
     2689    def __getitem__(self, r):
     2690        r"""
     2691        The default implementation of __getitem__ for enumerated sets does not
     2692        allow slices so we override it.
     2693
     2694        EXAMPLES::
     2695
     2696            sage: StandardTableaux([4,3,3,2])[10:20]     # indirect doctest
     2697            [[[1, 3, 9, 12], [2, 5, 10], [4, 6, 11], [7, 8]],
     2698             [[1, 2, 9, 12], [3, 5, 10], [4, 6, 11], [7, 8]],
     2699             [[1, 3, 9, 12], [2, 4, 10], [5, 6, 11], [7, 8]],
     2700             [[1, 2, 9, 12], [3, 4, 10], [5, 6, 11], [7, 8]],
     2701             [[1, 5, 8, 12], [2, 6, 10], [3, 7, 11], [4, 9]],
     2702             [[1, 4, 8, 12], [2, 6, 10], [3, 7, 11], [5, 9]],
     2703             [[1, 3, 8, 12], [2, 6, 10], [4, 7, 11], [5, 9]],
     2704             [[1, 2, 8, 12], [3, 6, 10], [4, 7, 11], [5, 9]],
     2705             [[1, 4, 8, 12], [2, 5, 10], [3, 7, 11], [6, 9]],
     2706             [[1, 3, 8, 12], [2, 5, 10], [4, 7, 11], [6, 9]]]
     2707
     2708            sage: SemistandardTableaux(size=2, max_entry=oo)[5]
     2709            [[2, 3]]
     2710
     2711            sage: SemistandardTableaux([2,1], max_entry=oo)[3]
     2712            [[1, 2], [3]]
     2713
     2714            sage: SemistandardTableaux(3, max_entry=2)[0:5]    # indirect doctest
     2715            [[[1, 1, 1]],
     2716            [[1, 1, 2]],
     2717            [[1, 2, 2]],
     2718            [[2, 2, 2]],
     2719            [[1, 1], [2]]]
     2720
     2721            sage: SemistandardTableaux([2,2], [2, 1, 1])[0]    # indirect doctest
     2722            [[1, 1], [2, 3]]
     2723
     2724            sage: SemistandardTableaux([1,1,1], max_entry=4)[0:4]
     2725            [[[1], [2], [3]],
     2726             [[1], [2], [4]],
     2727             [[1], [3], [4]],
     2728             [[2], [3], [4]]]
     2729
     2730            sage: SemistandardTableaux(3, [2,1])[1]    # indirect doctest
     2731            [[1, 1], [2]]
     2732
     2733            sage: StandardTableaux(3)[:]  # indirect doctest
     2734            [[[1, 2, 3]], [[1, 3], [2]], [[1, 2], [3]], [[1], [2], [3]]]
     2735
     2736            sage: StandardTableaux([2,2])[1]   # indirect doctest
     2737            [[1, 2], [3, 4]]
     2738
     2739        TESTS:
     2740
     2741            sage: SemistandardTableaux()[5]
     2742            [[1], [2]]
     2743
     2744            sage: SemistandardTableaux(max_entry=2)[5]
     2745            [[2, 2]]
     2746
     2747            sage: SemistandardTableaux()[:]
     2748            Traceback (most recent call last):
     2749            ...
     2750            ValueError: infinite set
     2751
     2752            sage: SemistandardTableaux(size=2, max_entry=oo)[:]
     2753            Traceback (most recent call last):
     2754            ...
     2755            ValueError: infinite set
     2756        """
     2757        if isinstance(r,(int,Integer)):
     2758            return self.unrank(r)
     2759        elif isinstance(r,slice):
     2760            start=0 if r.start is None else r.start
     2761            stop=r.stop
     2762            if stop is None and not self.is_finite():
     2763                raise ValueError, 'infinite set'
     2764        else:
     2765            raise ValueError, 'r must be an integer or a slice'
     2766        count=0
     2767        tabs=[]
     2768        for t in self:
     2769            if count==stop:
     2770                break
     2771            if count>=start:
     2772                tabs.append(t)
     2773            count+=1
     2774
     2775        # this is to cope with empty slices endpoints like [:6] or [:}
     2776        if count==stop or stop is None:
     2777            return tabs
     2778        raise IndexError, 'value out of range'
     2779
     2780
     2781class SemistandardTableaux_all(DisjointUnionEnumeratedSets, SemistandardTableaux):
     2782    def __init__(self, max_entry=None):
     2783        r"""
     2784        Initializes the class of all semistandard tableaux. Input is not
     2785        checked; please use :class:`SemistandardTableaux` to ensure the
     2786        options are properly parsed.
     2787
     2788        TESTS::
     2789
     2790            sage: T = sage.combinat.tableau.SemistandardTableaux_all()
     2791            sage: TestSuite(T).run()
     2792
     2793            sage: T=sage.combinat.tableau.SemistandardTableaux_all(max_entry=3)
     2794            sage: TestSuite(T).run()
     2795        """
     2796        if max_entry is not PlusInfinity():
     2797            self.max_entry = max_entry
     2798            SST_n = lambda n: SemistandardTableaux_size(n, max_entry)
     2799            DisjointUnionEnumeratedSets.__init__( self,
     2800                    Family(NonNegativeIntegers(), SST_n),
     2801                    facade=True, keepkey = False)
     2802
     2803        else:
     2804            self.max_entry = None
     2805
     2806
     2807    def __contains__(self, t):
     2808        """
     2809        Returns true if ``t`` can be interpreted as a SemistandardTableau
     2810
     2811        TESTS::
     2812
     2813            sage: T = sage.combinat.tableau.SemistandardTableaux_all()
     2814            sage: [[1,2],[2]] in T
     2815            True
     2816            sage: [] in T
     2817            True
     2818            sage: Tableau([[1]]) in T
     2819            True
     2820            sage: StandardTableau([[1]]) in T
     2821            True
     2822
     2823            sage: [[1,2],[1]] in T
     2824            False
     2825            sage: [[1,1],[5]] in T
     2826            True
     2827        """
     2828        if isinstance(t, self.element_class):
     2829            return self.max_entry is None or \
     2830                    t == [] or \
     2831                    max(flatten(t)) <= self.max_entry
     2832
     2833        try:
     2834            t = SemistandardTableau(t)
     2835        except ValueError:
     2836            return False
     2837
     2838        return self.max_entry is None or \
     2839                t == [] or \
     2840                max(flatten(t)) <= self.max_entry
     2841
     2842
     2843    def _repr_(self):
     2844        """
     2845        TESTS::
     2846
     2847            sage: SemistandardTableaux()    # indirect doctest
     2848            Semistandard tableaux
     2849
     2850            sage: SemistandardTableaux(max_entry=3)
     2851            Semistandard tableaux with maximum entry 3
     2852        """
     2853        if self.max_entry is not None:
     2854            return "Semistandard tableaux with maximum entry %s"%str(self.max_entry)
     2855        return "Semistandard tableaux"
     2856
     2857
     2858    def list(self):
     2859        """
     2860        TESTS::
     2861
     2862            sage: SemistandardTableaux().list()
     2863            Traceback (most recent call last):
     2864            ...
     2865            NotImplementedError
     2866        """
     2867        raise NotImplementedError
     2868
     2869
     2870class SemistandardTableaux_size_inf(SemistandardTableaux):
     2871    def __init__(self, n):
     2872        r"""
     2873        Initializes the class of semistandard tableaux of size ``n`` with no
     2874        maximum entry. Input is not checked; please use
     2875        :class:`SemistandardTableaux` to ensure the options are properly
     2876        parsed.
     2877
     2878        TESTS::
     2879
     2880            sage: T = sage.combinat.tableau.SemistandardTableaux_size_inf(3)
     2881            sage: TestSuite(T).run()
     2882        """
     2883        super(SemistandardTableaux_size_inf, self).__init__(
     2884              category = InfiniteEnumeratedSets())
     2885        self.size = n
     2886
     2887
     2888    def _repr_(self):
     2889        """
     2890        TESTS::
     2891
     2892            sage: repr(SemistandardTableaux(3, max_entry=oo))    # indirect doctest
     2893            'Semistandard tableaux of size 3'
     2894        """
     2895        return "Semistandard tableaux of size %s"%str(self.size)
     2896
     2897    def __contains__(self, t):
     2898        """
     2899        Returns true if ``t`` can be interpreted as an element of the class.
     2900
     2901        TESTS::
     2902
     2903            sage: T = SemistandardTableaux(3, max_entry=oo)
     2904            sage: [[1,2],[5]] in T
     2905            True
     2906            sage: StandardTableau([[1, 2], [3]]) in T
     2907            True
     2908
     2909            sage: [] in T
     2910            False
     2911            sage: Tableau([[1]]) in T
     2912            False
     2913        """
     2914        if isinstance(t, self.element_class):
     2915            return sum(map(len, t)) == self.size
     2916
     2917        try:
     2918            t = SemistandardTableau(t)
     2919        except ValueError:
     2920            return False
     2921
     2922        return sum(map(len, t)) == self.size
     2923
     2924    def __iter__(self):
     2925        """
     2926        EXAMPLES::
     2927
     2928            sage: sst = SemistandardTableaux(3, max_entry=oo)
     2929            sage: [sst[t] for t in range(0,5)]
     2930            [[[1, 1, 1]],
     2931             [[1, 1, 2]],
     2932             [[1, 2, 2]],
     2933             [[2, 2, 2]],
     2934             [[1, 1], [2]]]
     2935            sage: sst[1000]
     2936            [[2, 12], [7]]
     2937            sage: sst[0].parent() is sst
     2938            True
     2939        """
     2940        # Iterates through with maximum entry as order
     2941        i = 1
     2942        while(True):
     2943            for part in sage.combinat.partition.Partitions(self.size):
     2944                if i != 1:
     2945                    for k in range(1, self.size+1):
     2946                        for c in IntegerVectors(self.size - k, i-1):
     2947                            c.append(k)
     2948                            for sst in SemistandardTableaux_shape_weight(part,
     2949                                    sage.combinat.composition.Composition(c)):
     2950                                yield self.element_class(self, sst)
     2951                else:
     2952                    for sst in SemistandardTableaux_shape_weight(part,
     2953                            sage.combinat.composition.Composition([self.size])):
     2954                        yield self.element_class(self, sst)
     2955            i += 1
     2956
     2957
     2958    def list(self):
     2959        """
     2960        TESTS::
     2961
     2962            sage: SemistandardTableaux(3, max_entry=oo).list()
     2963            Traceback (most recent call last):
     2964            ...
     2965            NotImplementedError
     2966        """
     2967        raise NotImplementedError
     2968
     2969
     2970class SemistandardTableaux_shape_inf(SemistandardTableaux):
     2971    def __init__(self, p):
     2972        r"""
     2973        Initializes the class of semistandard tableaux of shape ``p`` and no
     2974        maximum entry. Input is not checked; please use
     2975        :class:`SemistandardTableaux` to ensure the options are properly
     2976        parsed.
     2977
     2978        TESTS::
     2979
     2980            sage: SST = SemistandardTableaux([2,1], max_entry=oo)
     2981            sage: type(SST)
     2982            <class 'sage.combinat.tableau.SemistandardTableaux_shape_inf_with_category'>
     2983            sage: TestSuite(SST).run()
     2984        """
     2985        super(SemistandardTableaux_shape_inf, self).__init__(
     2986              category = InfiniteEnumeratedSets())
     2987
     2988        self.shape = p
     2989
     2990
     2991    def __contains__(self, x):
     2992        """
     2993        EXAMPLES::
     2994
     2995            sage: SST = SemistandardTableaux([2,1], max_entry=oo)
     2996            sage: [[13, 67], [1467]] in SST
     2997            True
     2998            sage: SST = SemistandardTableaux([3,1], max_entry=oo)
     2999            sage: [[13, 67], [1467]] in SST
     3000            False
     3001        """
     3002        if isinstance(x, self.element_class) and map(len,x)==self.shape:
     3003            return True
     3004        try:
     3005            x = SemistandardTableau(x)
     3006        except ValueError:
     3007            return False
     3008        return map(len,x)==self.shape
     3009
     3010    def _repr_(self):
     3011        """
     3012        TESTS::
     3013
     3014            sage: repr(SemistandardTableaux([2,1], max_entry=oo))    # indirect doctest
     3015            'Semistandard tableaux of shape [2, 1]'
     3016        """
     3017        return "Semistandard tableaux of shape %s" %str(self.shape)
     3018
     3019
     3020    def __iter__(self):
     3021        """
     3022        An iterator for the semistandard partitions of shape p and no maximum entry.
     3023        Iterates through with maximum entry as order.
     3024
     3025        EXAMPLES::
     3026
     3027            sage: SST = SemistandardTableaux([3, 1], max_entry=oo)
     3028            sage: SST[1000]
     3029            [[1, 1, 10], [6]]
     3030            sage: [ SST[t] for t in range(0, 5) ]
     3031            [[[1, 1, 1], [2]],
     3032             [[1, 1, 2], [2]],
     3033             [[1, 2, 2], [2]],
     3034             [[1, 1, 1], [3]],
     3035             [[1, 1, 2], [3]]]
     3036            sage: SST[0].parent() is SST
     3037            True
     3038        """
     3039        # Iterates through with maximum entry as order
     3040        i = 1
     3041        n = sum(self.shape)
     3042        while(True):
     3043            if i != 1:
     3044                for k in range(1, n+1):
     3045                    for c in IntegerVectors(n - k, i-1):
     3046                        c.append(k)
     3047                        for sst in SemistandardTableaux_shape_weight(self.shape,
     3048                                sage.combinat.composition.Composition(c)):
     3049                            yield self.element_class(self, sst)
     3050            else:
     3051                for sst in SemistandardTableaux_shape_weight(self.shape,
     3052                                sage.combinat.composition.Composition([n])):
     3053                    yield self.element_class(self, sst)
     3054            i += 1
     3055
     3056
     3057class SemistandardTableaux_size(SemistandardTableaux):
     3058    def __init__(self, n, max_entry=None):
     3059        r"""
     3060        Initializes the class of semistandard tableaux of size ``n``. Input is
     3061        not checked; please use :class:`SemistandardTableaux` to ensure the
     3062        options are properly parsed.
     3063
     3064        TESTS::
     3065
     3066            sage: SST = SemistandardTableaux(3); SST
     3067            Semistandard tableaux of size 3 and maximum entry 3
     3068            sage: type(SST)
     3069            <class 'sage.combinat.tableau.SemistandardTableaux_size_with_category'>
     3070            sage: TestSuite(SST).run()
     3071
     3072            sage: SST = SemistandardTableaux(3, max_entry=6)
     3073            sage: type(SST)
     3074            <class 'sage.combinat.tableau.SemistandardTableaux_size_with_category'>
     3075            sage: TestSuite(SST).run()
     3076        """
     3077        super(SemistandardTableaux_size, self).__init__(
     3078                  category = FiniteEnumeratedSets())
     3079
     3080        self.size = n
     3081
     3082        if max_entry is None:
     3083            self.max_entry = n
     3084        else:
     3085            self.max_entry = max_entry
     3086
     3087
     3088    def _repr_(self):
     3089        """
     3090        TESTS::
     3091
     3092            sage: repr(SemistandardTableaux(3))    # indirect doctest
     3093            'Semistandard tableaux of size 3 and maximum entry 3'
     3094
     3095            sage: repr(SemistandardTableaux(3, max_entry=6))
     3096            'Semistandard tableaux of size 3 and maximum entry 6'
     3097        """
     3098        return "Semistandard tableaux of size %s and maximum entry %s"%(str(self.size), str(self.max_entry))
     3099
     3100    def __contains__(self, x):
     3101        """
     3102        EXAMPLES::
     3103
     3104            sage: [[1,2],[3,3]] in SemistandardTableaux(3)
     3105            False
     3106            sage: [[1,2],[3,3]] in SemistandardTableaux(4)
     3107            True
     3108            sage: [[1,2],[3,3]] in SemistandardTableaux(4, max_entry=2)
     3109            False
     3110            sage: SST = SemistandardTableaux(4)
     3111            sage: all([sst in SST for sst in SST])
     3112            True
     3113        """
     3114        if self.size==0:
     3115            return x == []
     3116
     3117        if isinstance(x, self.element_class) and \
     3118                sum(map(len,x)) == self.size and \
     3119                max(flatten(x)) <= self.max_entry:
     3120            return True
     3121        try:
     3122            x = SemistandardTableau(x)
     3123        except ValueError:
     3124            return False
     3125        return sum(map(len,x)) == self.size and \
     3126                max(flatten(x)) <= self.max_entry
     3127
     3128    def cardinality(self):
     3129        """
     3130        EXAMPLES::
     3131
     3132            sage: SemistandardTableaux(3).cardinality()
     3133            19
     3134            sage: SemistandardTableaux(4).cardinality()
     3135            116
     3136            sage: SemistandardTableaux(4, max_entry=2).cardinality()
     3137            9
     3138            sage: SemistandardTableaux(4, max_entry=10).cardinality()
     3139            4225
     3140            sage: ns = range(1, 6)
     3141            sage: ssts = [ SemistandardTableaux(n) for n in ns ]
     3142            sage: all([sst.cardinality() == len(sst.list()) for sst in ssts])
     3143            True
     3144        """
     3145        c = 0
     3146        for part in sage.combinat.partition.Partitions(self.size):
     3147            c += SemistandardTableaux_shape(part, self.max_entry).cardinality()
     3148        return c
     3149
     3150
     3151    def __iter__(self):
     3152        """
     3153        EXAMPLES::
     3154
     3155            sage: [ t for t in SemistandardTableaux(2) ]
     3156            [[[1, 1]], [[1, 2]], [[2, 2]], [[1], [2]]]
     3157            sage: [ t for t in SemistandardTableaux(3) ]
     3158            [[[1, 1, 1]],
     3159             [[1, 1, 2]],
     3160             [[1, 1, 3]],
     3161             [[1, 2, 2]],
     3162             [[1, 2, 3]],
     3163             [[1, 3, 3]],
     3164             [[2, 2, 2]],
     3165             [[2, 2, 3]],
     3166             [[2, 3, 3]],
     3167             [[3, 3, 3]],
     3168             [[1, 1], [2]],
     3169             [[1, 1], [3]],
     3170             [[1, 2], [2]],
     3171             [[1, 2], [3]],
     3172             [[1, 3], [2]],
     3173             [[1, 3], [3]],
     3174             [[2, 2], [3]],
     3175             [[2, 3], [3]],
     3176             [[1], [2], [3]]]
     3177
     3178            sage: [ t for t in SemistandardTableaux(3, max_entry=2) ]
     3179            [[[1, 1, 1]],
     3180             [[1, 1, 2]],
     3181             [[1, 2, 2]],
     3182             [[2, 2, 2]],
     3183             [[1, 1], [2]],
     3184             [[1, 2], [2]]]
     3185
     3186            sage: sst = SemistandardTableaux(3)
     3187            sage: sst[0].parent() is sst
     3188            True
     3189        """
     3190        for part in sage.combinat.partition.Partitions(self.size):
     3191            for sst in SemistandardTableaux_shape(part, self.max_entry):
     3192                yield self.element_class(self, sst)
     3193
     3194
     3195class SemistandardTableaux_shape_weight(SemistandardTableaux):
     3196    def __init__(self, p, mu):
     3197        r"""
     3198        Initializes the class of all semistandard tableaux of shape ``p`` and
     3199        weight ``mu``. Input is not checked; please use
     3200        :class:`SemistandardTableaux` to ensure the options are properly
     3201        parsed.
     3202
     3203        TESTS::
     3204
     3205            sage: SST = SemistandardTableaux([2,1], [2,1])
     3206            sage: TestSuite(SST).run()
     3207        """
     3208        super(SemistandardTableaux_shape_weight, self).__init__(
     3209              category = FiniteEnumeratedSets())
     3210        self.shape = p
     3211        self.weight = mu
     3212        self.max_entry = len(mu)
     3213
     3214
     3215    def _repr_(self):
     3216        """
     3217        TESTS::
     3218
     3219            sage: repr(SemistandardTableaux([2,1],[2,1]))    # indirect doctest
     3220            'Semistandard tableaux of shape [2, 1] and weight [2, 1]'
     3221        """
     3222        return "Semistandard tableaux of shape %s and weight %s"%(self.shape, self.weight)
     3223
     3224    def __contains__(self, x):
     3225        """
     3226        EXAMPLES::
     3227
     3228            sage: SST = SemistandardTableaux([2,1], [2,1])
     3229            sage: all([sst in SST for sst in SST])
     3230            True
     3231            sage: len(filter(lambda x: x in SST, SemistandardTableaux(3)))
     3232            1
     3233            sage: SST.cardinality()
     3234            1
     3235        """
     3236        if x not in SemistandardTableaux_shape(self.shape, self.max_entry):
     3237            return False
     3238        n = sum(self.shape)
     3239
     3240        if n == 0 and len(x) == 0:
     3241            return True
     3242
     3243        content = {}
     3244        for row in x:
     3245            for i in row:
     3246                content[i] = content.get(i, 0) + 1
     3247        content_list = [0]*int(max(content))
     3248
     3249        for key in content:
     3250            content_list[key-1] = content[key]
     3251
     3252        if content_list != self.weight:
     3253            return False
     3254
     3255        return True
     3256
     3257
     3258    def cardinality(self):
     3259        """
     3260        Returns the number of semistandard tableaux of the given shape and
     3261        weight, as computed by kostka_number function of symmetrica.
     3262
     3263        EXAMPLES::
     3264
     3265            sage: SemistandardTableaux([2,2], [2, 1, 1]).cardinality()
     3266            1
     3267            sage: SemistandardTableaux([2,2,2], [2, 2, 1,1]).cardinality()
     3268            1
     3269            sage: SemistandardTableaux([2,2,2], [2, 2, 2]).cardinality()
     3270            1
     3271            sage: SemistandardTableaux([3,2,1], [2, 2, 2]).cardinality()
     3272            2
     3273        """
     3274        return symmetrica.kostka_number(self.shape,self.weight)
     3275
     3276    def __iter__(self):
     3277        """
     3278        TESTS::
     3279
     3280            sage: sst = SemistandardTableaux([3,1],[2,1,1])
     3281            sage: [sst[i] for i in range(2)]
     3282            [[[1, 1, 2], [3]], [[1, 1, 3], [2]]]
     3283            sage: sst[0].parent() is sst
     3284            True
     3285        """
     3286        for t in symmetrica.kostka_tab(self.shape, self.weight):
     3287            yield self.element_class(self, t)
     3288
     3289
     3290    def list(self):
     3291        """
     3292        EXAMPLES::
     3293
     3294            sage: SemistandardTableaux([2,2], [2, 1, 1]).list()
     3295            [[[1, 1], [2, 3]]]
     3296            sage: SemistandardTableaux([2,2,2], [2, 2, 1,1]).list()
     3297            [[[1, 1], [2, 2], [3, 4]]]
     3298            sage: SemistandardTableaux([2,2,2], [2, 2, 2]).list()
     3299            [[[1, 1], [2, 2], [3, 3]]]
     3300            sage: SemistandardTableaux([3,2,1], [2, 2, 2]).list()
     3301            [[[1, 1, 2], [2, 3], [3]], [[1, 1, 3], [2, 2], [3]]]
     3302        """
     3303        return symmetrica.kostka_tab(self.shape, self.weight)
     3304
     3305
     3306class SemistandardTableaux_shape(SemistandardTableaux):
     3307    def __init__(self, p, max_entry=None):
     3308        r"""
     3309        Initializes the class of semistandard tableaux of shape ``p``, with a
     3310        given max_entry. max_entry defaults to the size of ``p``. Input is not
     3311        checked; please use :class:`SemistandardTableaux` to ensure the
     3312        options are properly parsed.
     3313
     3314        TESTS::
     3315
     3316            sage: SST = SemistandardTableaux([2,1])
     3317            sage: TestSuite(SST).run()
     3318
     3319            sage: SST = SemistandardTableaux([2,1], max_entry=5)
     3320            sage: TestSuite(SST).run()
     3321        """
     3322        super(SemistandardTableaux_shape, self).__init__(
     3323              category = FiniteEnumeratedSets())
     3324
     3325        self.shape = p
     3326
     3327        if max_entry is None:
     3328            self.max_entry = sum(p)
     3329        else:
     3330            self.max_entry = max_entry
     3331
     3332
     3333    def __iter__(self):
     3334        """
     3335        An iterator for the semistandard partitions of the specified shape.
     3336
     3337        EXAMPLES::
     3338
     3339            sage: [ t for t in SemistandardTableaux([3]) ]
     3340            [[[1, 1, 1]],
     3341             [[1, 1, 2]],
     3342             [[1, 1, 3]],
     3343             [[1, 2, 2]],
     3344             [[1, 2, 3]],
     3345             [[1, 3, 3]],
     3346             [[2, 2, 2]],
     3347             [[2, 2, 3]],
     3348             [[2, 3, 3]],
     3349             [[3, 3, 3]]]
     3350            sage: [ t for t in SemistandardTableaux([2,1]) ]
     3351            [[[1, 1], [2]],
     3352             [[1, 1], [3]],
     3353             [[1, 2], [2]],
     3354             [[1, 2], [3]],
     3355             [[1, 3], [2]],
     3356             [[1, 3], [3]],
     3357             [[2, 2], [3]],
     3358             [[2, 3], [3]]]
     3359            sage: [ t for t in SemistandardTableaux([1,1,1]) ]
     3360            [[[1], [2], [3]]]
     3361
     3362            sage: [ t for t in SemistandardTableaux([1,1,1], max_entry=4) ]
     3363            [[[1], [2], [3]],
     3364             [[1], [2], [4]],
     3365             [[1], [3], [4]],
     3366             [[2], [3], [4]]]
     3367
     3368            sage: sst = SemistandardTableaux([3])
     3369            sage: sst[0].parent() is sst
     3370            True
     3371        """
     3372        for c in IntegerVectors(sum(self.shape), self.max_entry):
     3373            for sst in SemistandardTableaux_shape_weight(self.shape,
     3374                    sage.combinat.composition.Composition(c)):
     3375                yield self.element_class(self, sst)
     3376
     3377
     3378    def __contains__(self, x):
     3379        """
     3380        EXAMPLES::
     3381
     3382            sage: SST = SemistandardTableaux([2,1])
     3383            sage: all([sst in SST for sst in SST])
     3384            True
     3385            sage: len(filter(lambda x: x in SST, SemistandardTableaux(3)))
     3386            8
     3387            sage: SST.cardinality()
     3388            8
     3389
     3390            sage: SST = SemistandardTableaux([2,1], max_entry=4)
     3391            sage: all([sst in SST for sst in SST])
     3392            True
     3393            sage: SST.cardinality()
     3394            20
     3395        """
     3396        return x in SemistandardTableaux_all(max_entry=self.max_entry)\
     3397                and map(len, x) == self.shape
     3398
     3399    def _repr_(self):
     3400        """
     3401        TESTS::
     3402
     3403            sage: repr(SemistandardTableaux([2,1]))    # indirect doctest
     3404            'Semistandard tableaux of shape [2, 1] and maximum entry 3'
     3405
     3406            sage: repr(SemistandardTableaux([2,1], max_entry=5))
     3407            'Semistandard tableaux of shape [2, 1] and maximum entry 5'
     3408        """
     3409        return "Semistandard tableaux of shape %s and maximum entry %s" %(str(self.shape), str(self.max_entry))
     3410
     3411    def cardinality(self):
     3412        """
     3413        EXAMPLES::
     3414
     3415            sage: SemistandardTableaux([2,1]).cardinality()
     3416            8
     3417            sage: SemistandardTableaux([2,2,1]).cardinality()
     3418            75
     3419            sage: SymmetricFunctions(QQ).schur()([2,2,1]).expand(5)(1,1,1,1,1) # cross check
     3420            75
     3421            sage: SemistandardTableaux([5]).cardinality()
     3422            126
     3423            sage: SemistandardTableaux([3,2,1]).cardinality()
     3424            896
     3425
     3426            sage: SemistandardTableaux([3,2,1], max_entry=7).cardinality()
     3427            2352
     3428        """
     3429        c = 0
     3430        for comp in IntegerVectors(sum(self.shape), self.max_entry):
     3431            c += SemistandardTableaux_shape_weight(self.shape,
     3432                    sage.combinat.composition.Composition(comp)).cardinality()
     3433        return c
     3434
     3435class SemistandardTableaux_size_weight(SemistandardTableaux):
     3436    def __init__(self, n, mu):
     3437        r"""
     3438        Initializes the class of semistandard tableaux of size ``n`` and
     3439        weight ``mu``. Input is not checked; please use
     3440        :class:`SemistandardTableaux` to ensure the options are properly
     3441        parsed.
     3442
     3443        TESTS::
     3444
     3445            sage: SST = SemistandardTableaux(3, [2,1])
     3446            sage: TestSuite(SST).run()
     3447        """
     3448        super(SemistandardTableaux_size_weight, self).__init__(
     3449              category = FiniteEnumeratedSets())
     3450        self.size = n
     3451        self.weight = mu
     3452        self.max_entry = len(mu)
     3453
     3454
     3455    def _repr_(self):
     3456        """
     3457        TESTS::
     3458
     3459            sage: repr(SemistandardTableaux(3, [2,1]))    # indirect doctest
     3460            'Semistandard tableaux of size 3 and weight [2, 1]'
     3461        """
     3462        return "Semistandard tableaux of size %s and weight %s"%(self.size, self.weight)
     3463
     3464    def __iter__(self):
     3465        """
     3466        EXAMPLES::
     3467
     3468            sage: [ t for t in SemistandardTableaux(3, [2,1]) ]
     3469            [[[1, 1, 2]], [[1, 1], [2]]]
     3470            sage: [ t for t in SemistandardTableaux(4, [2,2]) ]
     3471            [[[1, 1, 2, 2]], [[1, 1, 2], [2]], [[1, 1], [2, 2]]]
     3472            sage: sst = SemistandardTableaux(4, [2,2])
     3473            sage: sst[0].parent() is sst
     3474            True
     3475        """
     3476        for p in sage.combinat.partition.Partitions(self.size):
     3477            for sst in SemistandardTableaux_shape_weight(p, self.weight):
     3478                yield self.element_class(self, sst)
     3479
     3480
     3481    def cardinality(self):
     3482        """
     3483        EXAMPLES::
     3484
     3485            sage: SemistandardTableaux(3, [2,1]).cardinality()
     3486            2
     3487            sage: SemistandardTableaux(4, [2,2]).cardinality()
     3488            3
     3489        """
     3490        c = 0
     3491        for p in sage.combinat.partition.Partitions(self.size):
     3492            c += SemistandardTableaux_shape_weight(p, self.weight).cardinality()
     3493        return c
     3494
     3495    def __contains__(self, x):
     3496        """
     3497        TESTS::
     3498
     3499            sage: SST = SemistandardTableaux(6, [2,2,2])
     3500            sage: all([sst in SST for sst in SST])
     3501            True
     3502            sage: all([sst in SST for sst in SemistandardTableaux([3,2,1],[2,2,2])])
     3503            True
     3504        """
     3505        return x in SemistandardTableaux_shape_weight(sage.combinat.partition.Partition(map(len,
     3506            x)), self.weight)
     3507
     3508########################
     3509# Standard Tableaux    #
     3510########################
     3511
     3512class StandardTableaux(SemistandardTableaux):
     3513    """
     3514    A factory for the various classes of standard tableaux.
     3515
     3516    INPUT:
     3517
     3518    - Either a non-negative integer (possibly specified with the keyword ``n``)
     3519      or a partition.
     3520
     3521    OUTPUT:
     3522
     3523    - With no argument, the class of all standard tableaux
     3524
     3525    - With a non-negative integer argument, ``n``, the class of all standard
     3526      tableaux of size ``n``
     3527
     3528    - With a partition argument, the class of all standard tableaux of that
     3529      shape.
     3530
     3531    A standard tableau is a semistandard tableaux which contains each of the
     3532    entries from 1 to ``n`` exactly once.
     3533
     3534    All classes of standard tableaux are iterable.
    18843535   
    18853536    EXAMPLES::
    18863537   
    def StandardTableaux(n=None): 
    18943545        4
    18953546        sage: ST.list()
    18963547        [[[1, 2, 3]], [[1, 3], [2]], [[1, 2], [3]], [[1], [2], [3]]]
    1897    
    1898     ::
    1899    
     3548
     3549    SEE ALSO:
     3550
     3551        - :class:`Tableaux`
     3552        - :class:`Tableau`
     3553        - :class:`SemistandardTableaux`
     3554        - :class:`SemistandardTableau`
     3555        - :class:`StandardTableau`
     3556
     3557    TESTS::
     3558
     3559        sage: StandardTableaux()([])
     3560        []
    19003561        sage: ST = StandardTableaux([2,2]); ST
    19013562        Standard tableaux of shape [2, 2]
    19023563        sage: ST.first()
    def StandardTableaux(n=None): 
    19083569        sage: ST.list()
    19093570        [[[1, 3], [2, 4]], [[1, 2], [3, 4]]]
    19103571    """
    1911     if n == None:
    1912         return StandardTableaux_all()
    1913     elif n in partition.Partitions():
    1914         return StandardTableaux_partition(n)
    1915     else:
    1916         return StandardTableaux_n(n)
    1917 
    1918 class StandardTableaux_all(InfiniteAbstractCombinatorialClass):
     3572    @staticmethod
     3573    def __classcall_private__(cls, *args, **kwargs):
     3574        r"""
     3575        This is a factory class which returns the appropriate parent based on
     3576        arguments.  See the documentation for :class:`StandardTableaux` for more
     3577        information.
     3578
     3579        TESTS::
     3580
     3581            sage: StandardTableaux()
     3582            Standard tableaux
     3583            sage: StandardTableaux(3)
     3584            Standard tableaux of size 3
     3585            sage: StandardTableaux([2,1])
     3586            Standard tableaux of shape [2, 1]
     3587            sage: StandardTableaux(0)
     3588            Standard tableaux of size 0
     3589
     3590            sage: StandardTableaux(-1)
     3591            Traceback (most recent call last):
     3592            ...
     3593            ValueError: The argument must be a non-negative integer or a partition.
     3594            sage: StandardTableaux([[1]])
     3595            Traceback (most recent call last):
     3596            ...
     3597            ValueError: The argument must be a non-negative integer or a partition.
     3598        """
     3599        if args:
     3600            n = args[0]
     3601        elif 'n' in kwargs:
     3602            n = kwargs[n]
     3603        else:
     3604            n = None
     3605
     3606        if n is None:
     3607            return StandardTableaux_all()
     3608
     3609        elif n in sage.combinat.partition.Partitions():
     3610            return StandardTableaux_shape(sage.combinat.partition.Partition(n))
     3611
     3612        if not isinstance(n,(int, Integer)) or n < 0:
     3613            raise ValueError, "The argument must be a non-negative integer or a partition."
     3614
     3615        return StandardTableaux_size(n)
     3616
     3617    Element = StandardTableau
     3618
     3619class StandardTableaux_all(DisjointUnionEnumeratedSets, StandardTableaux):
    19193620    def __init__(self):
    1920         """
     3621        r"""
     3622        Initializes the class of all standard tableaux.
     3623
    19213624        TESTS::
    19223625       
    19233626            sage: ST = StandardTableaux()
    1924             sage: ST == loads(dumps(ST))
    1925             True
    1926         """
    1927         pass
    1928    
     3627            sage: TestSuite(ST).run()
     3628        """
     3629        DisjointUnionEnumeratedSets.__init__( self,
     3630                Family(NonNegativeIntegers(), StandardTableaux_size),
     3631                facade=True, keepkey = False)
     3632
    19293633    def __contains__(self, x):
    19303634        """
    19313635        EXAMPLES::
    class StandardTableaux_all(InfiniteAbstr 
    19393643            sage: [] in StandardTableaux()
    19403644            True
    19413645        """
    1942         if x not in Tableaux():
     3646        if isinstance(x, self.element_class):
     3647            return True
     3648
     3649        try:
     3650            x = StandardTableau(x)
     3651        except ValueError:
    19433652            return False
    1944         else:
    1945             t = Tableau(x)
    1946 
    1947         if len(t) == 0:
    1948             return True
    1949         #Check to make sure the first position is 1
    1950         fillings = []
    1951         for row in t:
    1952             fillings += row
    1953         fillings.sort()
    1954         if fillings != range(1, max(fillings)+1):
    1955             return False
    1956 
    1957         #Check to make sure it is increasing along the rows
    1958         for row in t:
    1959             for i in range(1, len(row)):
    1960                 if row[i] <= row[i-1]:
    1961                     return False
    1962 
    1963         #Check to make sure it is increasing along the columns
    1964         conj = t.conjugate()
    1965         for row in conj:
    1966             for i in range(1, len(row)):
    1967                 if row[i] <= row[i-1]:
    1968                     return False   
    19693653
    19703654        return True
    1971    
     3655
    19723656    def _repr_(self):
    19733657        """
    19743658        TESTS::
    19753659       
    1976             sage: repr(StandardTableaux())
     3660            sage: repr(StandardTableaux())    # indirect doctest
    19773661            'Standard tableaux'
    19783662        """
    19793663        return "Standard tableaux"
    19803664
    1981     def _infinite_cclass_slice(self, n):
    1982         """
    1983         Needed by InfiniteAbstractCombinatorialClass to build __iter__.
    1984 
    1985         TESTS::
    1986        
    1987             sage: StandardTableaux()._infinite_cclass_slice(4) == StandardTableaux(4)
    1988             True
    1989             sage: it = iter(StandardTableaux())    # indirect doctest
    1990             sage: [it.next() for i in range(10)]
    1991             [[], [[1]], [[1, 2]], [[1], [2]], [[1, 2, 3]], [[1, 3], [2]], [[1, 2], [3]], [[1], [2], [3]], [[1, 2, 3, 4]], [[1, 3, 4], [2]]]
    1992         """
    1993         return StandardTableaux_n(n)
    1994 
    1995 
    1996 class StandardTableaux_n(CombinatorialClass):
     3665
     3666class StandardTableaux_size(StandardTableaux):
    19973667    def __init__(self, n):
    1998         """
     3668        r"""
     3669        Initializes the class of all standard tableaux of size ``n``. Input is
     3670        not checked; please use :class:`StandardTableaux` to ensure the
     3671        options are properly parsed.
     3672
    19993673        TESTS::
    20003674       
    20013675            sage: ST = StandardTableaux(3)
    2002             sage: ST == loads(dumps(ST))
    2003             True
    2004         """
    2005         self.n = n
    2006 
    2007     Element = Tableau_class
     3676            sage: TestSuite(ST).run()
     3677            sage: ST = StandardTableaux(0)
     3678            sage: TestSuite(ST).run()
     3679        """
     3680        super(StandardTableaux_size, self).__init__(
     3681              category = FiniteEnumeratedSets())
     3682        self.size = n
     3683
    20083684
    20093685    def _repr_(self):
    20103686        """
    20113687        TESTS::
    20123688       
    2013             sage: repr(StandardTableaux(3))
     3689            sage: repr(StandardTableaux(3))    # indirect doctest
    20143690            'Standard tableaux of size 3'
    20153691        """
    2016         return "Standard tableaux of size %s"%self.n
     3692        return "Standard tableaux of size %s"%self.size
    20173693       
    20183694    def __contains__(self, x):
    20193695        """
    class StandardTableaux_n(CombinatorialCl 
    20263702            sage: filter(lambda x: x in ST3, ST4)
    20273703            []
    20283704        """
    2029         return x in StandardTableaux() and sum(map(len, x)) == self.n
     3705        if isinstance(x, self.element_class) and sum(map(len, x)) == self.size:
     3706            return True
     3707
     3708        try:
     3709            x = StandardTableau(x)
     3710        except ValueError:
     3711            return False
     3712
     3713        return sum(map(len, x)) == self.size
     3714
    20303715
    20313716    def __iter__(self):
    20323717        """
    class StandardTableaux_n(CombinatorialCl 
    20493734             [[1, 3], [2], [4]],
    20503735             [[1, 2], [3], [4]],
    20513736             [[1], [2], [3], [4]]]
    2052         """
    2053         for p in partition.Partitions(self.n):
     3737            sage: ST4 = StandardTableaux(4)
     3738            sage: ST4[0].parent() is ST4
     3739            True
     3740        """
     3741        for p in sage.combinat.partition.Partitions(self.size):
    20543742            for st in StandardTableaux(p):
    2055                 yield st
     3743                yield self.element_class(self, st)
     3744
    20563745
    20573746    def cardinality(self):
    20583747        """
    class StandardTableaux_n(CombinatorialCl 
    20613750            sage: StandardTableaux(3).cardinality()
    20623751            4
    20633752            sage: ns = [1,2,3,4,5,6]
    2064             sage: sts = [StandardTableaux(n) for n in ns]
     3753            sage: sts = [StandardTableaux(n) for n in ns]    # indirect doctest
    20653754            sage: all([st.cardinality() == len(st.list()) for st in sts])
    20663755            True
    20673756        """
    20683757        c = 0
    2069         for p in partition.Partitions(self.n):
     3758        for p in sage.combinat.partition.Partitions(self.size):
    20703759            c += StandardTableaux(p).cardinality()
    20713760        return c
    20723761
    20733762   
    2074 class StandardTableaux_partition(CombinatorialClass):
     3763class StandardTableaux_shape(StandardTableaux):
    20753764    def __init__(self, p):
    2076         """
     3765        r"""
     3766        Initializes the class of all semistandard tableaux of a given shape.
     3767        Input is not checked; please use :class:`SemistandardTableaux` to
     3768        ensure the options are properly parsed.
     3769
    20773770        TESTS::
    20783771       
    20793772            sage: ST = StandardTableaux([2,1,1])
    2080             sage: ST == loads(dumps(ST))
    2081             True
    2082         """
    2083         self.p = partition.Partition(p)
     3773            sage: TestSuite(ST).run()
     3774        """
     3775
     3776        super(StandardTableaux_shape, self).__init__(
     3777              category = FiniteEnumeratedSets())
     3778        self.shape = sage.combinat.partition.Partition(p)
     3779
    20843780   
     3781
    20853782    def __contains__(self, x):
    20863783        """
    20873784        EXAMPLES::
    class StandardTableaux_partition(Combina 
    20943791            sage: ST.cardinality()
    20953792            3
    20963793        """
    2097         return x in StandardTableaux() and map(len,x) == self.p
     3794        if isinstance(x, self.element_class) and map(len,x) == self.shape:
     3795            return True
     3796
     3797        try:
     3798            x = StandardTableau(x)
     3799        except ValueError:
     3800            return False
     3801
     3802        return map(len,x) == self.shape
     3803
    20983804
    20993805    def _repr_(self):
    21003806        """
    21013807        TESTS::
    21023808       
    2103             sage: repr(StandardTableaux([2,1,1]))
     3809            sage: repr(StandardTableaux([2,1,1]))    # indirect doctest
    21043810            'Standard tableaux of shape [2, 1, 1]'
    21053811        """
    2106         return "Standard tableaux of shape %s"%str(self.p)
     3812        return "Standard tableaux of shape %s"%str(self.shape)
    21073813   
    21083814    def cardinality(self):
    21093815        r"""
    class StandardTableaux_partition(Combina 
    21473853
    21483854        - http://mathworld.wolfram.com/HookLengthFormula.html
    21493855        """
    2150         pi = self.p
     3856        pi = self.shape
    21513857
    21523858        number = factorial(sum(pi))
    21533859        hook = pi.hook_lengths()
    class StandardTableaux_partition(Combina 
    21573863                #Divide the hook length by the entry
    21583864                number /= hook[row][col]
    21593865
    2160         return number
     3866        return Integer(number)
    21613867
    21623868    def __iter__(self):
    21633869        r"""
    class StandardTableaux_partition(Combina 
    21743880             [[1, 3, 4], [2, 5]],
    21753881             [[1, 2, 4], [3, 5]],
    21763882             [[1, 2, 3], [4, 5]]]
    2177         """
    2178 
    2179         pi = self.p
     3883            sage: st = StandardTableaux([2,1])
     3884            sage: st[0].parent() is st
     3885            True
     3886        """
     3887
     3888        pi = self.shape
    21803889        #Set the initial tableaux by filling it in going down the columns
    21813890        tableau = [[None]*n for n in pi]
    21823891        size = sum(pi)
    class StandardTableaux_partition(Combina 
    21933902                row = 0
    21943903                col += 1
    21953904
    2196         yield Tableau(tableau)
     3905        yield self.element_class(self, tableau)
    21973906
    21983907        if self.cardinality() == 1:
    21993908            last_tableau = True
    class StandardTableaux_partition(Combina 
    22583967                tableau[tableau_vector[i]][row_count[tableau_vector[i]]] = i+1
    22593968                row_count[tableau_vector[i]] += 1
    22603969
    2261             yield Tableau(tableau)
     3970            yield self.element_class(self, tableau)
    22623971
    22633972            #Check to see if we are at the last tableau
    22643973            #The last tableau if given by filling in the
    class StandardTableaux_partition(Combina 
    22803989
    22813990    def list(self):
    22823991        r"""
    2283         Returns a list of the standard Young tableau associated with a
    2284         partition p.
     3992        Returns a list of the standard Young tableaux of the specified shape.
    22853993       
    22863994        EXAMPLES::
    22873995       
    class StandardTableaux_partition(Combina 
    23124020
    23134021    def random_element(self):
    23144022        """
    2315         Returns a random standard tableau of shape p using the
     4023        Returns a random standard tableau of the given shape using the
    23164024        Green-Nijenhuis-Wilf Algorithm.
    23174025
    23184026        EXAMPLES::
    class StandardTableaux_partition(Combina 
    23214029            [[1, 2], [3, 4]]
    23224030        """
    23234031
    2324         p = self.p
     4032        p = self.shape
    23254033
    23264034        t = [[None]*n for n in p]
    23274035
    class StandardTableaux_partition(Combina 
    23614069
    23624070            m -= 1
    23634071
    2364         return Tableau(t)
    2365 
    2366 
    2367 
    2368 ##########################
    2369 # Semi-standard tableaux #
    2370 ##########################
    2371 
    2372 def SemistandardTableaux(p=None, mu=None, max_entry=None):
    2373     """
    2374     Returns the combinatorial class of semistandard tableaux.
    2375    
    2376     If p is specified and is a partition, then it returns the class of
    2377     semistandard tableaux of shape p.
    2378    
    2379     If p is specified and is an integer, it returns the class of
    2380     semistandard tableaux of size p.
    2381    
    2382     If mu is specified, then it returns the class of semistandard
    2383     tableaux with evaluation/content mu.
    2384 
    2385     If max_entry is specified and is a positive integer, then it
    2386     returns semistandard tableaux with entries less than or equal to
    2387     max_entry. A max_entry of oo (+Infinity) returns semistandard tableaux
    2388     with no limit on the entries. By default, if p is specified as an integer
    2389     then max_entry is equal to p, if p is a partition then max_entry is equal
    2390     to sum(p), if p and mu are None then max_entry is infinite.
    2391    
    2392     EXAMPLES::
    2393    
    2394         sage: SST = SemistandardTableaux([2,1]); SST
    2395         Semistandard tableaux of shape [2, 1] and maximum entry 3
    2396         sage: SST.list()
    2397         [[[1, 1], [2]],
    2398          [[1, 1], [3]],
    2399          [[1, 2], [2]],
    2400          [[1, 2], [3]],
    2401          [[1, 3], [2]],
    2402          [[1, 3], [3]],
    2403          [[2, 2], [3]],
    2404          [[2, 3], [3]]]
    2405 
    2406         sage: SST = SemistandardTableaux(3); SST
    2407         Semistandard tableaux of size 3 and maximum entry 3
    2408         sage: SST.list()
    2409         [[[1, 1, 1]],
    2410          [[1, 1, 2]],
    2411          [[1, 1, 3]],
    2412          [[1, 2, 2]],
    2413          [[1, 2, 3]],
    2414          [[1, 3, 3]],
    2415          [[2, 2, 2]],
    2416          [[2, 2, 3]],
    2417          [[2, 3, 3]],
    2418          [[3, 3, 3]],
    2419          [[1, 1], [2]],
    2420          [[1, 1], [3]],
    2421          [[1, 2], [2]],
    2422          [[1, 2], [3]],
    2423          [[1, 3], [2]],
    2424          [[1, 3], [3]],
    2425          [[2, 2], [3]],
    2426          [[2, 3], [3]],
    2427          [[1], [2], [3]]]
    2428 
    2429         sage: SST = SemistandardTableaux(3, max_entry=2); SST
    2430         Semistandard tableaux of size 3 and maximum entry 2
    2431         sage: SST.list()
    2432         [[[1, 1, 1]],
    2433          [[1, 1, 2]],
    2434          [[1, 2, 2]],
    2435          [[2, 2, 2]],
    2436          [[1, 1], [2]],
    2437          [[1, 2], [2]]]
    2438 
    2439         sage: SST = SemistandardTableaux(3, max_entry=oo); SST
    2440         Semistandard tableaux of size 3
    2441         sage: SST[123]
    2442         [[3, 4], [6]]
    2443     """
    2444     is_inf = max_entry is PlusInfinity()
    2445 
    2446     if max_entry is not None and not is_inf:
    2447         if not isinstance(max_entry, (int, Integer)):
    2448             raise ValueError, "max_entry must be an integer"
    2449         elif max_entry < 0:
    2450             raise ValueError, "max_entry must be non-negative"
    2451 
    2452     if p is None:
    2453         if mu is None:
    2454             return SemistandardTableaux_all(max_entry)
    2455         else:
    2456             return SemistandardTableaux_nmu(sum(mu), mu)
    2457     elif p in partition.Partitions():
    2458         if mu is None:
    2459             if is_inf:
    2460                 if sum(p) != 0:
    2461                     return SemistandardTableaux_p_inf(p)
    2462                 else:
    2463                     return SemistandardTableaux_p(p)
    2464             else:
    2465                 return SemistandardTableaux_p(p, max_entry)
    2466         else:
    2467             if sum(p) != sum(mu):
    2468                 #Error size mismatch
    2469                 raise TypeError, "p and mu must be of the same size"
    2470             else:
    2471                 return SemistandardTableaux_pmu(p, mu)
    2472     elif isinstance(p, (int, Integer)):
    2473         if p >= 0:
    2474             if mu is None:
    2475                 if is_inf:
    2476                     if p != 0:
    2477                         return SemistandardTableaux_n_inf(p)
    2478                     else:
    2479                         return SemistandardTableaux_n(p)
    2480                 else:
    2481                     return SemistandardTableaux_n(p, max_entry)
    2482             else:
    2483                 if p != sum(mu):
    2484                     #Error size mismatch
    2485                     raise ValueError, "mu must be of size p (= %s)"%p
    2486                 else:
    2487                     return SemistandardTableaux_nmu(p, mu)
    2488         else:
    2489             raise ValueError, "p must be non-negative"
    2490     else:
    2491         raise ValueError
    2492 
    2493 class SemistandardTableaux_all(CombinatorialClass):
    2494     def __init__(self, max_entry=None):
    2495         """
    2496         TESTS::
    2497        
    2498             sage: SST = SemistandardTableaux()
    2499             sage: SST == loads(dumps(SST))
    2500             True
    2501 
    2502             sage: SST = SemistandardTableaux(max_entry=5)
    2503             sage: SST == loads(dumps(SST))
    2504             True
    2505 
    2506         """
    2507         self.max_entry = None
    2508        
    2509         if max_entry is not PlusInfinity():
    2510             self.max_entry = max_entry
    2511 
    2512     def _repr_(self):
    2513         """
    2514         TESTS::
    2515             sage: SST = SemistandardTableaux()
    2516             sage: SST
    2517             Semistandard tableaux
    2518 
    2519             sage: SemistandardTableaux(max_entry=3)
    2520             Semistandard tableaux with maximum entry 3
    2521         """   
    2522         if self.max_entry is not None:
    2523             return "Semistandard tableaux with maximum entry %s"%str(self.max_entry)
    2524         return "Semistandard tableaux"
    2525      
    2526     def __contains__(self, x):
    2527         """
    2528         TESTS::
    2529        
    2530             sage: [[1,2],[1]] in SemistandardTableaux()
    2531             False
    2532             sage: SST = SemistandardTableaux()
    2533             sage: all([st in SST for st in StandardTableaux(4)])
    2534             True
    2535             sage: [[1,1],[5]] in SemistandardTableaux(max_entry=4)
    2536             False
    2537         """
    2538         # Check that x is either a Tableau, or a list of lists whose lengths
    2539         # form a partition.
    2540         if x not in Tableaux():
    2541             return False
    2542         else:
    2543             t = Tableau(x)
    2544            
    2545         #Check to make sure it is non-decreasing along the rows
    2546         for i, row in enumerate(t):
    2547             for j, entry in enumerate(row):
    2548                 # Verify that the entries are integers
    2549                 if not isinstance(entry, (int, Integer)):
    2550                     return False
    2551                
    2552                 # Verify that the rows are weakly increasing
    2553                 if j > 0 and entry < row[j-1]:
    2554                     return False
    2555                
    2556                 # Verify that the columns are strictly increasing
    2557                 if i > 0 and entry <= t[i-1][j]:
    2558                     return False
    2559            
    2560             # Verify that the last entry in each row (and hence all entries)
    2561             # are less than or equal to max_entry
    2562             if self.max_entry is not None and row[-1] > self.max_entry:
    2563                 return False
    2564 
    2565         return True
    2566 
    2567     def list(self):
    2568         """
    2569         TESTS::
    2570        
    2571             sage: SemistandardTableaux().list()
    2572             Traceback (most recent call last):
    2573             ...
    2574             NotImplementedError
    2575         """
    2576         raise NotImplementedError
    2577 
    2578 
    2579 class SemistandardTableaux_n_inf(CombinatorialClass):
    2580     def __init__(self, n):
    2581         """
    2582         TESTS::
    2583        
    2584             sage: SST = SemistandardTableaux(3, max_entry=oo)
    2585             sage: SST == loads(dumps(SST))
    2586             True
    2587         """
    2588         self.n = n
    2589 
    2590     def _repr_(self):
    2591         """
    2592         TESTS::
    2593        
    2594             sage: repr(SemistandardTableaux(3, max_entry=oo))
    2595             'Semistandard tableaux of size 3'
    2596         """
    2597         return "Semistandard tableaux of size %s"%str(self.n)
    2598 
    2599     def __contains__(self, x):
    2600         """
    2601         EXAMPLES::
    2602        
    2603             sage: [[1,2],[17,1938]] in SemistandardTableaux(3, max_entry=oo)
    2604             False
    2605             sage: [[1,2],[17,1938]] in SemistandardTableaux(4, max_entry=oo)
    2606             True
    2607         """
    2608         return x in SemistandardTableaux_all() and sum(map(len, x)) == self.n
    2609 
    2610     Element = Tableau_class
    2611 
    2612     def __iter__(self):
    2613         """
    2614         EXAMPLES::
    2615        
    2616             sage: sst = SemistandardTableaux(3, max_entry=oo)
    2617             sage: [sst[t] for t in range(0,5)]
    2618             [[[1, 1, 1]],
    2619              [[1, 1, 2]],
    2620              [[1, 2, 2]],
    2621              [[2, 2, 2]],
    2622              [[1, 1], [2]]]
    2623             sage: sst[1000]
    2624             [[2, 12], [7]]
    2625         """
    2626         # Iterates through with maximum entry as order
    2627         i = 1
    2628         while(True):
    2629             for part in partition.Partitions(self.n):
    2630                 if i != 1:
    2631                     for k in range(1, self.n+1):
    2632                         for c in IntegerVectors(self.n - k, i-1):
    2633                             c.append(k)
    2634                             for sst in SemistandardTableaux_pmu(part, c):
    2635                                 yield sst
    2636                 else:
    2637                     for sst in SemistandardTableaux_pmu(part, [self.n]):
    2638                         yield sst
    2639             i += 1
    2640 
    2641     def list(self):
    2642         """
    2643         TESTS::
    2644        
    2645             sage: SemistandardTableaux(3, max_entry=oo).list()
    2646             Traceback (most recent call last):
    2647             ...
    2648             NotImplementedError
    2649         """
    2650         raise NotImplementedError
    2651 
    2652 
    2653 class SemistandardTableaux_p_inf(CombinatorialClass):
    2654     def __init__(self, p):
    2655         """
    2656         TESTS::
    2657        
    2658             sage: SST = SemistandardTableaux([2,1], max_entry=oo)
    2659             sage: SST == loads(dumps(SST))
    2660             True
    2661         """
    2662         self.p = p
    2663 
    2664     Element = Tableau_class
    2665 
    2666     def __contains__(self, x):
    2667         """
    2668         EXAMPLES::
    2669        
    2670             sage: SST = SemistandardTableaux([2,1], max_entry=oo)
    2671             sage: [[13, 67], [1467]] in SST
    2672             True
    2673             sage: SST = SemistandardTableaux([3,1], max_entry=oo)
    2674             sage: [[13, 67], [1467]] in SST
    2675             False
    2676         """
    2677         return x in SemistandardTableaux_all() and map(len, x) == self.p
    2678    
    2679     def _repr_(self):
    2680         """
    2681         TESTS::
    2682        
    2683             sage: repr(SemistandardTableaux([2,1], max_entry=oo))
    2684             'Semistandard tableaux of shape [2, 1]'
    2685         """
    2686         return "Semistandard tableaux of shape %s" %str(self.p)
    2687 
    2688    
    2689     def __iter__(self):
    2690         """
    2691         An iterator for the semistandard partitions of shape p and no maximum entry.
    2692         Iterates through with maximum entry as order.
    2693        
    2694         EXAMPLES::
    2695        
    2696             sage: SST = SemistandardTableaux([3, 1], max_entry=oo)
    2697             sage: SST[1000]
    2698             [[1, 1, 10], [6]]
    2699             sage: [ SST[t] for t in range(0, 5) ]
    2700             [[[1, 1, 1], [2]],
    2701              [[1, 1, 2], [2]],
    2702              [[1, 2, 2], [2]],
    2703              [[1, 1, 1], [3]],
    2704              [[1, 1, 2], [3]]]       
    2705         """
    2706         # Iterates through with maximum entry as order
    2707         i = 1
    2708         n = sum(self.p)
    2709         while(True):
    2710             if i != 1:
    2711                 for k in range(1, n+1):
    2712                     for c in IntegerVectors(n - k, i-1):
    2713                         c.append(k)
    2714                         for sst in SemistandardTableaux_pmu(self.p, c):
    2715                             yield sst
    2716             else:
    2717                 for sst in SemistandardTableaux_pmu(self.p, [n]):
    2718                     yield sst
    2719             i += 1
    2720 
    2721 
    2722 class SemistandardTableaux_n(CombinatorialClass):
    2723     def __init__(self, n, max_entry=None):
    2724         """
    2725         TESTS::
    2726        
    2727             sage: SST = SemistandardTableaux(3)
    2728             sage: SST == loads(dumps(SST))
    2729             True
    2730 
    2731             sage: SST = SemistandardTableaux(3, max_entry=6)
    2732             sage: SST == loads(dumps(SST))
    2733             True
    2734         """
    2735         self.n = n
    2736 
    2737         self.max_entry = None
    2738 
    2739         if max_entry is None:
    2740             self.max_entry = n
    2741         else:
    2742             self.max_entry = max_entry
    2743 
    2744     def _repr_(self):
    2745         """
    2746         TESTS::
    2747        
    2748             sage: repr(SemistandardTableaux(3))
    2749             'Semistandard tableaux of size 3 and maximum entry 3'
    2750 
    2751             sage: repr(SemistandardTableaux(3, max_entry=6))
    2752             'Semistandard tableaux of size 3 and maximum entry 6'
    2753         """       
    2754         return "Semistandard tableaux of size %s and maximum entry %s"%(str(self.n), str(self.max_entry))
    2755 
    2756     def __contains__(self, x):
    2757         """
    2758         EXAMPLES::
    2759        
    2760             sage: [[1,2],[3,3]] in SemistandardTableaux(3)
    2761             False
    2762             sage: [[1,2],[3,3]] in SemistandardTableaux(4)
    2763             True
    2764             sage: [[1,2],[3,3]] in SemistandardTableaux(4, max_entry=2)
    2765             False
    2766             sage: SST = SemistandardTableaux(4)
    2767             sage: all([sst in SST for sst in SST])
    2768             True
    2769         """
    2770         return x in SemistandardTableaux_all(self.max_entry) and sum(map(len, x)) == self.n
    2771 
    2772     Element = Tableau_class
    2773        
    2774     def cardinality(self):
    2775         """
    2776         EXAMPLES::
    2777        
    2778             sage: SemistandardTableaux(3).cardinality()
    2779             19
    2780             sage: SemistandardTableaux(4).cardinality()
    2781             116
    2782             sage: SemistandardTableaux(4, max_entry=2).cardinality()
    2783             9
    2784             sage: SemistandardTableaux(4, max_entry=10).cardinality()
    2785             4225
    2786             sage: ns = range(1, 6)
    2787             sage: ssts = [ SemistandardTableaux(n) for n in ns ]
    2788             sage: all([sst.cardinality() == len(sst.list()) for sst in ssts])
    2789             True
    2790         """
    2791         c = 0
    2792         for part in partition.Partitions(self.n):
    2793             c += SemistandardTableaux_p(part, self.max_entry).cardinality()
    2794         return c
    2795 
    2796 
    2797     def __iter__(self):
    2798         """
    2799         EXAMPLES::
    2800        
    2801             sage: [ t for t in SemistandardTableaux(2) ]
    2802             [[[1, 1]], [[1, 2]], [[2, 2]], [[1], [2]]]
    2803             sage: [ t for t in SemistandardTableaux(3) ]
    2804             [[[1, 1, 1]],
    2805              [[1, 1, 2]],
    2806              [[1, 1, 3]],
    2807              [[1, 2, 2]],
    2808              [[1, 2, 3]],
    2809              [[1, 3, 3]],
    2810              [[2, 2, 2]],
    2811              [[2, 2, 3]],
    2812              [[2, 3, 3]],
    2813              [[3, 3, 3]],
    2814              [[1, 1], [2]],
    2815              [[1, 1], [3]],
    2816              [[1, 2], [2]],
    2817              [[1, 2], [3]],
    2818              [[1, 3], [2]],
    2819              [[1, 3], [3]],
    2820              [[2, 2], [3]],
    2821              [[2, 3], [3]],
    2822              [[1], [2], [3]]]
    2823 
    2824             sage: [ t for t in SemistandardTableaux(3, max_entry=2) ]
    2825             [[[1, 1, 1]],
    2826              [[1, 1, 2]],
    2827              [[1, 2, 2]],
    2828              [[2, 2, 2]],
    2829              [[1, 1], [2]],
    2830              [[1, 2], [2]]]
    2831         """
    2832         for part in partition.Partitions(self.n):
    2833             for sst in SemistandardTableaux_p(part, self.max_entry):
    2834                 yield sst
    2835 
    2836 
    2837 class SemistandardTableaux_pmu(CombinatorialClass):
    2838     def __init__(self, p, mu):
    2839         """
    2840         TESTS::
    2841        
    2842             sage: SST = SemistandardTableaux([2,1], [2,1])
    2843             sage: SST == loads(dumps(SST))
    2844             True
    2845         """
    2846         self.p = p
    2847         self.mu = mu
    2848         self.max_entry = len(mu)
    2849 
    2850     Element = Tableau_class
    2851 
    2852     def _repr_(self):
    2853         """
    2854         TESTS::
    2855        
    2856             sage: repr(SemistandardTableaux([2,1],[2,1]))
    2857             'Semistandard tableaux of shape [2, 1] and evaluation [2, 1]'
    2858         """
    2859         return "Semistandard tableaux of shape %s and evaluation %s"%(self.p, self.mu)
    2860 
    2861     def __contains__(self, x):
    2862         """
    2863         EXAMPLES::
    2864        
    2865             sage: SST = SemistandardTableaux([2,1], [2,1])
    2866             sage: all([sst in SST for sst in SST])
    2867             True
    2868             sage: len(filter(lambda x: x in SST, SemistandardTableaux(3)))
    2869             1
    2870             sage: SST.cardinality()
    2871             1
    2872         """
    2873         if x not in SemistandardTableaux_p(self.p, self.max_entry):
    2874             return False
    2875         n = sum(self.p)
    2876 
    2877         if n == 0 and len(x) == 0:
    2878             return True
    2879 
    2880         content = {}
    2881         for row in x:
    2882             for i in row:
    2883                 content[i] = content.get(i, 0) + 1
    2884         content_list = [0]*int(max(content))
    2885 
    2886         for key in content:
    2887             content_list[key-1] = content[key]
    2888 
    2889         if content_list != self.mu:
    2890             return False
    2891 
    2892         return True
    2893        
    2894 
    2895     def cardinality(self):
    2896         """
    2897         EXAMPLES::
    2898        
    2899             sage: SemistandardTableaux([2,2], [2, 1, 1]).cardinality()
    2900             1
    2901             sage: SemistandardTableaux([2,2,2], [2, 2, 1,1]).cardinality()
    2902             1
    2903             sage: SemistandardTableaux([2,2,2], [2, 2, 2]).cardinality()
    2904             1
    2905             sage: SemistandardTableaux([3,2,1], [2, 2, 2]).cardinality()
    2906             2
    2907         """
    2908         return symmetrica.kostka_number(self.p,self.mu)
    2909 
    2910 
    2911     def list(self):
    2912         """
    2913         EXAMPLES::
    2914        
    2915             sage: SemistandardTableaux([2,2], [2, 1, 1]).list()
    2916             [[[1, 1], [2, 3]]]
    2917             sage: SemistandardTableaux([2,2,2], [2, 2, 1,1]).list()
    2918             [[[1, 1], [2, 2], [3, 4]]]
    2919             sage: SemistandardTableaux([2,2,2], [2, 2, 2]).list()
    2920             [[[1, 1], [2, 2], [3, 3]]]
    2921             sage: SemistandardTableaux([3,2,1], [2, 2, 2]).list()
    2922             [[[1, 1, 2], [2, 3], [3]], [[1, 1, 3], [2, 2], [3]]]
    2923         """
    2924         return symmetrica.kostka_tab(self.p, self.mu)
    2925        
    2926    
    2927 class SemistandardTableaux_p(CombinatorialClass):
    2928     def __init__(self, p, max_entry=None):
    2929         """
    2930         TESTS::
    2931        
    2932             sage: SST = SemistandardTableaux([2,1])
    2933             sage: SST == loads(dumps(SST))
    2934             True
    2935 
    2936             sage: SST = SemistandardTableaux([2,1], max_entry=5)
    2937             sage: SST == loads(dumps(SST))
    2938             True
    2939         """
    2940         self.p = p
    2941 
    2942         self.max_entry = None
    2943 
    2944         if max_entry is None:
    2945             self.max_entry = sum(p)
    2946         else:
    2947             self.max_entry = max_entry
    2948 
    2949 
    2950     Element = Tableau_class
    2951 
    2952     def __contains__(self, x):
    2953         """
    2954         EXAMPLES::
    2955        
    2956             sage: SST = SemistandardTableaux([2,1])
    2957             sage: all([sst in SST for sst in SST])
    2958             True
    2959             sage: len(filter(lambda x: x in SST, SemistandardTableaux(3)))
    2960             8
    2961             sage: SST.cardinality()
    2962             8
    2963 
    2964             sage: SST = SemistandardTableaux([2,1], max_entry=4)
    2965             sage: all([sst in SST for sst in SST])
    2966             True
    2967             sage: SST.cardinality()
    2968             20
    2969         """
    2970         return x in SemistandardTableaux_all(self.max_entry) and map(len, x) == self.p
    2971    
    2972     def _repr_(self):
    2973         """
    2974         TESTS::
    2975        
    2976             sage: repr(SemistandardTableaux([2,1]))
    2977             'Semistandard tableaux of shape [2, 1] and maximum entry 3'
    2978 
    2979             sage: repr(SemistandardTableaux([2,1], max_entry=5))
    2980             'Semistandard tableaux of shape [2, 1] and maximum entry 5'
    2981         """
    2982         return "Semistandard tableaux of shape %s and maximum entry %s" %(str(self.p), str(self.max_entry))
    2983 
    2984     def cardinality(self):
    2985         """
    2986         EXAMPLES::
    2987        
    2988             sage: SemistandardTableaux([2,1]).cardinality()
    2989             8
    2990             sage: SemistandardTableaux([2,2,1]).cardinality()
    2991             75
    2992             sage: s = SymmetricFunctions(QQ).schur()
    2993             sage: s([2,2,1]).expand(5)(1,1,1,1,1)
    2994             75
    2995             sage: SemistandardTableaux([5]).cardinality()
    2996             126
    2997             sage: SemistandardTableaux([3,2,1]).cardinality()
    2998             896
    2999 
    3000             sage: SemistandardTableaux([3,2,1], max_entry=7).cardinality()
    3001             2352
    3002         """
    3003         c = 0
    3004         for comp in IntegerVectors(sum(self.p), self.max_entry):
    3005             c += SemistandardTableaux_pmu(self.p, comp).cardinality()
    3006         return c
    3007    
    3008     def __iter__(self):
    3009         """
    3010         An iterator for the semistandard partitions of shape p.
    3011        
    3012         EXAMPLES::
    3013        
    3014             sage: [ t for t in SemistandardTableaux([3]) ]
    3015             [[[1, 1, 1]],
    3016              [[1, 1, 2]],
    3017              [[1, 1, 3]],
    3018              [[1, 2, 2]],
    3019              [[1, 2, 3]],
    3020              [[1, 3, 3]],
    3021              [[2, 2, 2]],
    3022              [[2, 2, 3]],
    3023              [[2, 3, 3]],
    3024              [[3, 3, 3]]]
    3025             sage: [ t for t in SemistandardTableaux([2,1]) ]
    3026             [[[1, 1], [2]],
    3027              [[1, 1], [3]],
    3028              [[1, 2], [2]],
    3029              [[1, 2], [3]],
    3030              [[1, 3], [2]],
    3031              [[1, 3], [3]],
    3032              [[2, 2], [3]],
    3033              [[2, 3], [3]]]
    3034             sage: [ t for t in SemistandardTableaux([1,1,1]) ]
    3035             [[[1], [2], [3]]]
    3036 
    3037             sage: [ t for t in SemistandardTableaux([1,1,1], max_entry=4) ]
    3038             [[[1], [2], [3]],
    3039              [[1], [2], [4]],
    3040              [[1], [3], [4]],
    3041              [[2], [3], [4]]]
    3042         """
    3043         for c in IntegerVectors(sum(self.p), self.max_entry):
    3044             for sst in SemistandardTableaux_pmu(self.p, c):
    3045                 yield sst
    3046 
    3047 
    3048 class SemistandardTableaux_nmu(CombinatorialClass):
    3049     def __init__(self, n, mu):
    3050         """
    3051         TESTS::
    3052        
    3053             sage: SST = SemistandardTableaux(3, [2,1])
    3054             sage: SST == loads(dumps(SST))
    3055             True
    3056         """
    3057         self.n = n
    3058         self.mu = mu
    3059         self.max_entry = len(mu)
    3060 
    3061     def _repr_(self):
    3062         """
    3063         TESTS::
    3064        
    3065             sage: repr(SemistandardTableaux(3, [2,1]))
    3066             'Semistandard tableaux of size 3 and evaluation [2, 1]'
    3067         """
    3068         return "Semistandard tableaux of size %s and evaluation %s"%(self.n, self.mu)
    3069 
    3070     def __iter__(self):
    3071         """
    3072         EXAMPLES::
    3073        
    3074             sage: [ t for t in SemistandardTableaux(3, [2,1]) ]
    3075             [[[1, 1, 2]], [[1, 1], [2]]]
    3076             sage: [ t for t in SemistandardTableaux(4, [2,2]) ]
    3077             [[[1, 1, 2, 2]], [[1, 1, 2], [2]], [[1, 1], [2, 2]]]
    3078         """
    3079         for p in partition.Partitions(self.n):
    3080             for sst in SemistandardTableaux_pmu(p, self.mu):
    3081                 yield sst
    3082 
    3083     def cardinality(self):
    3084         """
    3085         EXAMPLES::
    3086        
    3087             sage: SemistandardTableaux(3, [2,1]).cardinality()
    3088             2
    3089             sage: SemistandardTableaux(4, [2,2]).cardinality()
    3090             3
    3091         """
    3092         c = 0
    3093         for p in partition.Partitions(self.n):
    3094             c += SemistandardTableaux_pmu(p, self.mu).cardinality()
    3095         return c
    3096 
    3097     def __contains__(self, x):
    3098         """
    3099         TESTS::
    3100        
    3101             sage: SST = SemistandardTableaux(6, [2,2,2])
    3102             sage: all([sst in SST for sst in SST])
    3103             True
    3104             sage: all([sst in SST for sst in SemistandardTableaux([3,2,1],[2,2,2])])
    3105             True
    3106         """
    3107         return x in SemistandardTableaux_pmu(map(len, x), self.mu)
     4072        return self.element_class(self, t)
     4073
    31084074
    31094075##########################
    31104076# Symmetric group action #
    def symmetric_group_action_on_values(wor 
    31854151            for i in range(nbr-dif,ma):
    31864152                w[places_r[i]] = l
    31874153    return w
    3188        
     4154
     4155
     4156# August 2012: Deprecation of internal classes seems to be unnecessarily painful...
     4157from sage.misc.superseded import deprecation
     4158
     4159def Tableau_class(*args, **kargs):
     4160    """
     4161    EXAMPLES::
     4162
     4163        sage: sage.combinat.tableau.Tableau_class([[3,2]])
     4164        doctest:1: DeprecationWarning: this class is deprecated. Use Tableau_class instead
     4165        See http://trac.sagemath.org/9265 for details.
     4166        [[3, 2]]
     4167    """
     4168    deprecation(9265,'this class is deprecated. Use Tableau_class instead')
     4169    return Tableau(*args, **kargs)
     4170
     4171def Tableaux_n(*args, **kargs):
     4172    """
     4173    EXAMPLES::
     4174
     4175        sage: sage.combinat.tableau.Tableaux_n(3)
     4176        doctest:1: DeprecationWarning: this class is deprecated. Use Tableaux_size instead
     4177        See http://trac.sagemath.org/9265 for details.
     4178        Tableaux of size 3
     4179    """
     4180    deprecation(9265,'this class is deprecated. Use Tableaux_size instead')
     4181    return Tableaux(*args, **kargs)
     4182
     4183def SemistandardTableaux_n(*args, **kargs):
     4184    """
     4185    EXAMPLES::
     4186
     4187        sage: sage.combinat.tableau.SemistandardTableaux_n(3)
     4188        doctest:1: DeprecationWarning: this class is deprecated. Use SemistandardTableaux_size instead
     4189        See http://trac.sagemath.org/9265 for details.
     4190        Semistandard tableaux of size 3 and maximum entry 3
     4191    """
     4192    deprecation(9265,'this class is deprecated. Use SemistandardTableaux_size instead')
     4193    return SemistandardTableaux(*args, **kargs)
     4194
     4195def SemistandardTableaux_nmu(*args, **kargs):
     4196    """
     4197    EXAMPLES::
     4198
     4199        sage: sage.combinat.tableau.SemistandardTableaux_nmu(3,[2,1])
     4200        doctest:1: DeprecationWarning: this class is deprecated. Use SemistandardTableaux_size_weight instead
     4201        See http://trac.sagemath.org/9265 for details.
     4202        Semistandard tableaux of size 3 and weight [2, 1]
     4203    """
     4204    deprecation(9265,'this class is deprecated. Use SemistandardTableaux_size_weight instead')
     4205    return SemistandardTableaux(*args, **kargs)
     4206
     4207def SemistandardTableaux_p(*args, **kargs):
     4208    """
     4209    EXAMPLES::
     4210
     4211        sage: sage.combinat.tableau.SemistandardTableaux_p([2,1])
     4212        doctest:1: DeprecationWarning: this class is deprecated. Use SemistandardTableaux_shape instead
     4213        See http://trac.sagemath.org/9265 for details.
     4214        Semistandard tableaux of shape [2, 1] and maximum entry 3
     4215    """
     4216    deprecation(9265,'this class is deprecated. Use SemistandardTableaux_shape instead')
     4217    return SemistandardTableaux(*args, **kargs)
     4218
     4219def SemistandardTableaux_pmu(*args, **kargs):
     4220    """
     4221    EXAMPLES::
     4222
     4223        sage: sage.combinat.tableau.SemistandardTableaux_pmu([2,1],[2,1])
     4224        doctest:1: DeprecationWarning: this class is deprecated. Use SemistandardTableaux_shape_weight instead
     4225        See http://trac.sagemath.org/9265 for details.
     4226        Semistandard tableaux of shape [2, 1] and weight [2, 1]
     4227    """
     4228    deprecation(9265,'this class is deprecated. Use SemistandardTableaux_shape_weight instead')
     4229    return SemistandardTableaux(*args, **kargs)
     4230
     4231def StandardTableaux_n(*args, **kargs):
     4232    """
     4233    EXAMPLES::
     4234
     4235        sage: sage.combinat.tableau.StandardTableaux_n(2)
     4236        doctest:1: DeprecationWarning: this class is deprecated. Use StandardTableaux_size instead
     4237        See http://trac.sagemath.org/9265 for details.
     4238        Standard tableaux of size 2
     4239    """
     4240    deprecation(9265,'this class is deprecated. Use StandardTableaux_size instead')
     4241    return StandardTableaux(*args, **kargs)
     4242
     4243def StandardTableaux_partition(*args, **kargs):
     4244    """
     4245    EXAMPLES::
     4246
     4247        sage: sage.combinat.tableau.StandardTableaux_partition([2,1])
     4248        doctest:1: DeprecationWarning: this class is deprecated. Use StandardTableaux_shape instead
     4249        See http://trac.sagemath.org/9265 for details.
     4250        Standard tableaux of shape [2, 1]
     4251    """
     4252    deprecation(9265,'this class is deprecated. Use StandardTableaux_shape instead')
     4253    return StandardTableaux(*args, **kargs)
     4254
     4255
  • sage/libs/symmetrica/symmetrica.pxi

    diff --git a/sage/libs/symmetrica/symmetrica.pxi b/sage/libs/symmetrica/symmetrica.pxi
    a b cdef extern from 'symmetrica/def.h': 
    366366##########################################
    367367cdef object matrix_constructor
    368368cdef object Integer
    369 cdef object Tableau, Tableau_class, SkewTableau, SkewTableau_class
     369cdef object Tableau, SkewTableau, SkewTableau_class
    370370cdef object SkewPartition, SkewPartition_class
    371371cdef object Partition, Partition_class
    372372cdef object Permutation_class, Permutations
    cdef void late_import(): 
    386386    global matrix_constructor, \
    387387           Integer, \
    388388           Tableau, \
    389            Tableau_class, \
    390389           SkewTableau, \
    391390           SkewTableau_class, \
    392391           SkewPartition, \
    cdef void late_import(): 
    417416
    418417    import sage.combinat.tableau
    419418    Tableau = sage.combinat.tableau.Tableau
    420     Tableau_class = sage.combinat.tableau.Tableau_class
    421419
    422420    import sage.combinat.skew_tableau
    423421    SkewTableau = sage.combinat.skew_tableau.SkewTableau
    cdef object _py_tableau(OP t): 
    11711169    if is_skew:
    11721170        return SkewTableau_class(res)
    11731171    else:
    1174         return Tableau_class(res)
     1172        return Tableau(res)
    11751173
    11761174
    11771175