Ticket #13072: trac_13072-tuples-of-partitions_am.patch

File trac_13072-tuples-of-partitions_am.patch, 241.9 KB (added by andrew.mathas, 7 years ago)

Adding proper commit message

  • doc/de/tutorial/tour_numtheory.rst

    # HG changeset patch
    # User Andrew Mathas <andrew.mathas at sydney.edu.au>
    # Date 1341585162 -28800
    # Node ID e01a2b546f1d3b6f6d105263b65b16082201f0dd
    # Parent  8c7785b0f522cedaea430b967b8f673c4b483e21
    #13072 Implementing partition tuples + general partition clean up
    
    diff --git a/doc/de/tutorial/tour_numtheory.rst b/doc/de/tutorial/tour_numtheory.rst
    a b Schließlich illustrieren wir den chines 
    106106    [1, -1, 1, 1, -1, -1, -1, -1, 1, 1, -1, 1]
    107107    sage: n = 10000; sum([moebius(m) for m in range(1,n)])
    108108    -23
    109     sage: list(partitions(4))
    110     [(1, 1, 1, 1), (1, 1, 2), (2, 2), (1, 3), (4,)]
     109    sage: Partitions(4).list()
     110    [[4], [3, 1], [2, 2], [2, 1, 1], [1, 1, 1, 1]]
    111111
    112112:math:`p`-adische Zahlen
    113113------------------------
  • doc/en/reference/combinat/index.rst

    diff --git a/doc/en/reference/combinat/index.rst b/doc/en/reference/combinat/index.rst
    a b Combinatorics 
    3535   ../sage/combinat/necklace
    3636   ../sage/combinat/non_decreasing_parking_function
    3737   ../sage/combinat/partition
     38   ../sage/combinat/partition_tuple
    3839   ../sage/combinat/permutation
    3940   ../sage/combinat/perfect_matching
    4041   ../sage/combinat/q_analogues
  • doc/en/tutorial/tour_numtheory.rst

    diff --git a/doc/en/tutorial/tour_numtheory.rst b/doc/en/tutorial/tour_numtheory.rst
    a b Finally we illustrate the Chinese remain 
    105105    [1, -1, 1, 1, -1, -1, -1, -1, 1, 1, -1, 1]
    106106    sage: n = 10000; sum([moebius(m) for m in range(1,n)])
    107107    -23
    108     sage: list(partitions(4))
    109     [(1, 1, 1, 1), (1, 1, 2), (2, 2), (1, 3), (4,)]
     108    sage: Partitions(4).list()
     109    [[4], [3, 1], [2, 2], [2, 1, 1], [1, 1, 1, 1]]
    110110
    111111:math:`p`-adic Numbers
    112112------------------------
  • doc/fr/tutorial/tour_numtheory.rst

    diff --git a/doc/fr/tutorial/tour_numtheory.rst b/doc/fr/tutorial/tour_numtheory.rst
    a b Et finalement un exemple d'utilisation d 
    107107    [1, -1, 1, 1, -1, -1, -1, -1, 1, 1, -1, 1]
    108108    sage: n = 10000; sum([moebius(m) for m in range(1,n)])
    109109    -23
    110     sage: list(partitions(4))
    111     [(1, 1, 1, 1), (1, 1, 2), (2, 2), (1, 3), (4,)]
     110    sage: Partitions(4).list()
     111    [[4], [3, 1], [2, 2], [2, 1, 1], [1, 1, 1, 1]]
    112112
    113113Nombres :math:`p`-adiques
    114114-------------------------
  • doc/ru/tutorial/tour_numtheory.rst

    diff --git a/doc/ru/tutorial/tour_numtheory.rst b/doc/ru/tutorial/tour_numtheory.rst
    a b Sage содержит стандартн 
    104104    [1, -1, 1, 1, -1, -1, -1, -1, 1, 1, -1, 1]
    105105    sage: n = 10000; sum([moebius(m) for m in range(1,n)])
    106106    -23
    107     sage: list(partitions(4))
    108     [(1, 1, 1, 1), (1, 1, 2), (2, 2), (1, 3), (4,)]
     107    sage: Partitions(4).list()
     108    [[4], [3, 1], [2, 2], [2, 1, 1], [1, 1, 1, 1]]
    109109
    110110
    111111:math:`p`--адические числа
  • sage/combinat/all.py

    diff --git a/sage/combinat/all.py b/sage/combinat/all.py
    a b from expnums import expnums 
    44from sage.combinat.crystals.all import *
    55from rigged_configurations.all import *
    66
    7 from sage.combinat.dlx import DLXMatrix, AllExactCovers, OneExactCover 
     7from sage.combinat.dlx import DLXMatrix, AllExactCovers, OneExactCover
    88
    99# block designs, etc
    1010from sage.combinat.designs.all import *
    from composition import Composition, Com 
    3535from composition_signed import SignedCompositions
    3636
    3737#Partitions
    38 import partition
    3938from partition import Partition, Partitions, PartitionsInBox,\
    40     OrderedPartitions, RestrictedPartitions, PartitionTuples,\
    41     PartitionsGreatestLE, PartitionsGreatestEQ, partitions_set,\
    42     number_of_partitions_set, number_of_partitions_list, \
    43     ordered_partitions, number_of_ordered_partitions, number_of_partitions,\
    44     partitions, cyclic_permutations_of_partition,\
    45     cyclic_permutations_of_partition_iterator, ferrers_diagram, \
    46     partitions_greatest, partitions_greatest_eq, partitions_restricted,\
    47     number_of_partitions_restricted, partitions_tuples, \
    48     number_of_partitions_tuples, partition_power, partition_sign, \
    49     partition_associated, partitions_list
     39     OrderedPartitions, PartitionsGreatestLE, PartitionsGreatestEQ,\
     40     PartitionsGreatestLE, PartitionsGreatestEQ, number_of_partitions
     41#Functions being deprecated from partition
     42from partition import partitions_set, RestrictedPartitions, number_of_partitions_set,\
     43    ordered_partitions, number_of_ordered_partitions, partitions,\
     44     cyclic_permutations_of_partition, cyclic_permutations_of_partition_iterator,\
     45     ferrers_diagram, partitions_greatest, partitions_greatest_eq,\
     46     partitions_tuples, number_of_partitions_tuples, partition_power
     47
     48from partition_tuple import PartitionTuple, PartitionTuples
    5049from skew_partition import SkewPartition, SkewPartitions
     50
     51#Partition algebra
    5152from partition_algebra import SetPartitionsAk, SetPartitionsPk, SetPartitionsTk, SetPartitionsIk, SetPartitionsBk, SetPartitionsSk, SetPartitionsRk, SetPartitionsRk, SetPartitionsPRk
    5253
    5354#Cores
  • sage/combinat/combinat.py

    diff --git a/sage/combinat/combinat.py b/sage/combinat/combinat.py
    a b  
    11r"""
    22Combinatorial Functions
    3  
     3
    44AUTHORS:
    55
    66- David Joyner (2006-07): initial implementation.
    Partitions: 
    8888   of set S is a set of pairwise disjoint nonempty sets with union S
    8989   and is represented by a sorted list of such sets.
    9090
    91 -  Partitions of an integer, ``partitions_list``,
    92    ``number_of_partitions_list``. An unordered
    93    partition of n is an unordered sum
     91-  Partitions of an integer, ``Partitions``.
     92   An unordered partition of n is an unordered sum
    9493   `n = p_1+p_2 +\ldots+ p_k` of positive integers and is
    9594   represented by the list `p = [p_1,p_2,\ldots,p_k]`, in
    9695   nonincreasing order, i.e., `p1\geq p_2 ...\geq p_k`.
    Partitions: 
    103102   represented by the list `p = [p_1,p_2,\ldots,p_k]`, in
    104103   nonincreasing order, i.e., `p1\geq p_2 ...\geq p_k`.
    105104
    106 -  Restricted partitions of an integer,
    107    ``partitions_restricted``,
    108    ``number_of_partitions_restricted``. An unordered
    109    restricted partition of n is an unordered sum
    110    `n = p_1+p_2 +\ldots+ p_k` of positive integers
    111    `p_i` belonging to a given set `S`, and is
    112    represented by the list `p = [p_1,p_2,\ldots,p_k]`, in
    113    nonincreasing order, i.e., `p1\geq p_2 ...\geq p_k`.
    114 
    115105-  ``partitions_greatest`` implements a special type
    116106   of restricted partition.
    117107
    118108-  ``partitions_greatest_eq`` is another type of
    119109   restricted partition.
    120110
    121 -  Tuples of partitions, ``partition_tuples``,
    122    ``number_of_partition_tuples``. A `k`-tuple
     111-  Tuples of partitions, ``PartitionTuples``. A `k`-tuple
    123112   of partitions is represented by a list of all `k`-tuples of
    124113   partitions which together form a partition of `n`.
    125114
    Partitions: 
    127116   The power of a partition corresponds to the `k`-th power of
    128117   a permutation with cycle structure `\pi`.
    129118
    130 -  Sign of a partition, ``partition_sign( pi )`` This
    131    means the sign of a permutation with cycle structure given by the
    132    partition pi.
    133 
    134 -  Associated partition, ``partition_associated( pi
    135    )`` The "associated" (also called "conjugate" in the
    136    literature) partition of the partition pi which is obtained by
    137    transposing the corresponding Ferrers diagram.
    138 
    139 -  Ferrers diagram, ``ferrers_diagram``. Analogous to
    140    the Young diagram of an irreducible representation of
    141    `S_n`.
    142 
    143119
    144120Related functions:
    145121
    combinatorial functions: 
    174150   `\frac {\Gamma(x+a)} {\Gamma(x)}`.
    175151
    176152-  gaussian_binomial the gaussian binomial
    177    
     153
    178154.. math::
    179155
    180              \binom{n}{k}_q = \frac{(1-q^m)(1-q^{m-1})\cdots (1-q^{m-r+1})}                              {(1-q)(1-q^2)\cdots (1-q^r)}.     
     156             \binom{n}{k}_q = \frac{(1-q^m)(1-q^{m-1})\cdots (1-q^{m-r+1})}                              {(1-q)(1-q^2)\cdots (1-q^r)}.
    181157
    182158
    183159
    def bell_number(n): 
    240216    r"""
    241217    Returns the n-th Bell number (the number of ways to partition a set
    242218    of n elements into pairwise disjoint nonempty subsets).
    243    
     219
    244220    If `n \leq 0`, returns `1`.
    245    
     221
    246222    Wraps GAP's Bell.
    247    
     223
    248224    EXAMPLES::
    249    
     225
    250226        sage: bell_number(10)
    251227        115975
    252228        sage: bell_number(2)
    def bell_number(n): 
    265241
    266242## def bernoulli_number(n):
    267243##     r"""
    268 ##     Returns the n-th Bernoulli number $B_n$; $B_n/n!$ is the 
     244##     Returns the n-th Bernoulli number $B_n$; $B_n/n!$ is the
    269245##     coefficient of $x^n$ in the power series of $x/(e^x-1)$.
    270246##     Wraps GAP's Bernoulli.
    271247##     EXAMPLES:
    def bell_number(n): 
    278254def catalan_number(n):
    279255    r"""
    280256    Returns the n-th Catalan number
    281    
     257
    282258    Catalan numbers: The `n`-th Catalan number is given
    283259    directly in terms of binomial coefficients by
    284    
     260
    285261    .. math::
    286    
    287                C_n = \frac{1}{n+1}{2n\choose n} = \frac{(2n)!}{(n+1)!\,n!}              \qquad\mbox{ for }\quad n\ge 0.       
    288    
    289    
    290    
     262
     263               C_n = \frac{1}{n+1}{2n\choose n} = \frac{(2n)!}{(n+1)!\,n!}              \qquad\mbox{ for }\quad n\ge 0.
     264
     265
     266
    291267    Consider the set `S = \{ 1, ..., n \}`. A noncrossing
    292268    partition of `S` is a partition in which no two blocks
    293269    "cross" each other, i.e., if a and b belong to one block and x and
    def catalan_number(n): 
    295271    `C_n` is the number of noncrossing partitions of the set
    296272    `S`. There are many other interpretations (see
    297273    REFERENCES).
    298    
     274
    299275    When `n=-1`, this function raises a ZeroDivisionError; for
    300276    other `n<0` it returns `0`.
    301277
    def catalan_number(n): 
    304280    - ``n`` - integer
    305281
    306282    OUTPUT: integer
    307  
    308 
    309    
     283
     284
     285
    310286    EXAMPLES::
    311    
     287
    312288        sage: [catalan_number(i) for i in range(7)]
    313289        [1, 1, 2, 5, 14, 42, 132]
    314290        sage: taylor((-1/2)*sqrt(1 - 4*x^2), x, 0, 15)
    def catalan_number(n): 
    318294        sage: catalan_number(-1)
    319295        Traceback (most recent call last):
    320296        ...
    321         ZeroDivisionError       
     297        ZeroDivisionError
    322298        sage: [catalan_number(n).mod(2) for n in range(16)]
    323299        [1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1]
    324    
     300
    325301    REFERENCES:
    326        
     302
    327303    -  http://en.wikipedia.org/wiki/Catalan_number
    328    
     304
    329305    -  http://www-history.mcs.st-andrews.ac.uk/~history/Miscellaneous/CatalanNumbers/catalan.html
    330306    """
    331307    from sage.rings.arith import binomial
    def catalan_number(n): 
    335311def euler_number(n):
    336312    """
    337313    Returns the n-th Euler number
    338    
     314
    339315    IMPLEMENTATION: Wraps Maxima's euler.
    340    
     316
    341317    EXAMPLES::
    342    
     318
    343319        sage: [euler_number(i) for i in range(10)]
    344320        [1, 0, -1, 0, 5, 0, -61, 0, 1385, 0]
    345321        sage: maxima.eval("taylor (2/(exp(x)+exp(-x)), x, 0, 10)")
    def euler_number(n): 
    349325        sage: euler_number(-1)
    350326        Traceback (most recent call last):
    351327        ...
    352         ValueError: n (=-1) must be a nonnegative integer       
    353    
     328        ValueError: n (=-1) must be a nonnegative integer
     329
    354330    REFERENCES:
    355331
    356332    - http://en.wikipedia.org/wiki/Euler_number
    def fibonacci(n, algorithm="pari"): 
    368344    `F_{n+2} = F_{n+1} + F_n`. For negative `n` we
    369345    define `F_n = (-1)^{n+1}F_{-n}`, which is consistent with
    370346    the recurrence relation.
    371    
     347
    372348    INPUT:
    373    
    374    
     349
     350
    375351    -  ``algorithm`` - string:
    376    
     352
    377353    -  ``"pari"`` - (default) - use the PARI C library's
    378354       fibo function.
    379    
     355
    380356    -  ``"gap"`` - use GAP's Fibonacci function
    381    
    382    
     357
     358
    383359    .. note::
    384360
    385361       PARI is tens to hundreds of times faster than GAP here;
    386362       moreover, PARI works for every large input whereas GAP doesn't.
    387    
     363
    388364    EXAMPLES::
    389    
     365
    390366        sage: fibonacci(10)
    391367        55
    392368        sage: fibonacci(10, algorithm='gap')
    393369        55
    394    
     370
    395371    ::
    396    
     372
    397373        sage: fibonacci(-100)
    398374        -354224848179261915075
    399375        sage: fibonacci(100)
    400376        354224848179261915075
    401    
     377
    402378    ::
    403    
     379
    404380        sage: fibonacci(0)
    405381        0
    406382        sage: fibonacci(1/2)
    def lucas_number1(n,P,Q): 
    423399    defined by the initial conditions `L^{(1)}_1=0`,
    424400    `L^{(1)}_2=1` and the recurrence relation
    425401    `L^{(1)}_{n+2} = P*L^{(1)}_{n+1} - Q*L^{(1)}_n`.
    426    
     402
    427403    Wraps GAP's Lucas(...)[1].
    428    
     404
    429405    P=1, Q=-1 gives the Fibonacci sequence.
    430    
     406
    431407    INPUT:
    432    
    433    
     408
     409
    434410    -  ``n`` - integer
    435    
     411
    436412    -  ``P, Q`` - integer or rational numbers
    437    
    438    
     413
     414
    439415    OUTPUT: integer or rational number
    440    
     416
    441417    EXAMPLES::
    442    
     418
    443419        sage: lucas_number1(5,1,-1)
    444420        5
    445421        sage: lucas_number1(6,1,-1)
    def lucas_number1(n,P,Q): 
    448424        13
    449425        sage: lucas_number1(7,1,-2)
    450426        43
    451    
     427
    452428    ::
    453    
     429
    454430        sage: lucas_number1(5,2,3/5)
    455431        229/25
    456432        sage: lucas_number1(5,2,1.5)
    457433        Traceback (most recent call last):
    458434        ...
    459435        TypeError: no canonical coercion from Real Field with 53 bits of precision to Rational Field
    460    
     436
    461437    There was a conjecture that the sequence `L_n` defined by
    462438    `L_{n+2} = L_{n+1} + L_n`, `L_1=1`,
    463439    `L_2=3`, has the property that `n` prime implies
    464440    that `L_n` is prime.
    465    
     441
    466442    ::
    467    
     443
    468444        sage: lucas = lambda n : Integer((5/2)*lucas_number1(n,1,-1)+(1/2)*lucas_number2(n,1,-1))
    469445        sage: [[lucas(n),is_prime(lucas(n)),n+1,is_prime(n+1)] for n in range(15)]
    470446        [[1, False, 1, False],
    def lucas_number1(n,P,Q): 
    482458         [521, True, 13, True],
    483459         [843, False, 14, False],
    484460         [1364, False, 15, False]]
    485    
     461
    486462    Can you use Sage to find a counterexample to the conjecture?
    487463    """
    488464    ans=gap.eval("Lucas(%s,%s,%s)[1]"%(QQ._coerce_(P),QQ._coerce_(Q),ZZ(n)))
    def lucas_number2(n,P,Q): 
    495471    defined by the initial conditions `L^{(2)}_1=2`,
    496472    `L^{(2)}_2=P` and the recurrence relation
    497473    `L^{(2)}_{n+2} = P*L^{(2)}_{n+1} - Q*L^{(2)}_n`.
    498    
     474
    499475    Wraps GAP's Lucas(...)[2].
    500    
     476
    501477    INPUT:
    502    
    503    
     478
     479
    504480    -  ``n`` - integer
    505    
     481
    506482    -  ``P, Q`` - integer or rational numbers
    507    
    508    
     483
     484
    509485    OUTPUT: integer or rational number
    510    
     486
    511487    EXAMPLES::
    512    
     488
    513489        sage: [lucas_number2(i,1,-1) for i in range(10)]
    514490        [2, 1, 3, 4, 7, 11, 18, 29, 47, 76]
    515491        sage: [fibonacci(i-1)+fibonacci(i+1) for i in range(10)]
    516492        [2, 1, 3, 4, 7, 11, 18, 29, 47, 76]
    517    
     493
    518494    ::
    519    
     495
    520496        sage: n = lucas_number2(5,2,3); n
    521497        2
    522498        sage: type(n)
    def lucas_number2(n,P,Q): 
    525501        418/9
    526502        sage: type(n)
    527503        <type 'sage.rings.rational.Rational'>
    528    
     504
    529505    The case P=1, Q=-1 is the Lucas sequence in Brualdi's Introductory
    530506    Combinatorics, 4th ed., Prentice-Hall, 2004::
    531    
     507
    532508        sage: [lucas_number2(n,1,-1) for n in range(10)]
    533509        [2, 1, 3, 4, 7, 11, 18, 29, 47, 76]
    534510    """
    def stirling_number1(n,k): 
    540516    Returns the n-th Stilling number `S_1(n,k)` of the first
    541517    kind (the number of permutations of n points with k cycles). Wraps
    542518    GAP's Stirling1.
    543    
     519
    544520    EXAMPLES::
    545    
     521
    546522        sage: stirling_number1(3,2)
    547523        3
    548524        sage: stirling_number1(5,2)
    def stirling_number1(n,k): 
    551527        269325
    552528        sage: stirling_number1(10,5)
    553529        269325
    554    
     530
    555531    Indeed, `S_1(n,k) = S_1(n-1,k-1) + (n-1)S_1(n-1,k)`.
    556532    """
    557533    return ZZ(gap.eval("Stirling1(%s,%s)"%(ZZ(n),ZZ(k))))
    class CombinatorialObject(SageObject): 
    691667        differences are that __setitem__ is disabled so that
    692668        CombinatorialObjects are shallowly immutable, and the intention is
    693669        that they are semantically immutable.
    694        
     670
    695671        Because of this, CombinatorialObjects provide a __hash__
    696672        function which computes the hash of the string representation of a
    697673        list and the hash of its parent's class. Thus, each
    698674        CombinatorialObject should have a unique string representation.
    699        
     675
    700676        INPUT:
    701        
    702         -  ``l`` - a list or any object that can be convert to a list by 
     677
     678        -  ``l`` - a list or any object that can be convert to a list by
    703679                   ``list``
    704                
     680
    705681        EXAMPLES::
    706        
     682
    707683            sage: c = CombinatorialObject([1,2,3])
    708684            sage: c == loads(dumps(c))
    709685            True
    class CombinatorialObject(SageObject): 
    721697    def __str__(self):
    722698        """
    723699        EXAMPLES::
    724        
     700
    725701            sage: c = CombinatorialObject([1,2,3])
    726702            sage: str(c)
    727703            '[1, 2, 3]'
    class CombinatorialObject(SageObject): 
    731707    def _repr_(self):
    732708        """
    733709        EXAMPLES::
    734        
     710
    735711            sage: c = CombinatorialObject([1,2,3])
    736712            sage: c.__repr__()
    737713            '[1, 2, 3]'
    738714        """
    739715        return self._list.__repr__()
    740    
     716
    741717    def __eq__(self, other):
    742718        """
    743719        EXAMPLES::
    744        
     720
    745721            sage: c = CombinatorialObject([1,2,3])
    746722            sage: d = CombinatorialObject([2,3,4])
    747723            sage: c == [1,2,3]
    class CombinatorialObject(SageObject): 
    751727            sage: c == d
    752728            False
    753729        """
    754        
     730
    755731        if isinstance(other, CombinatorialObject):
    756732            return self._list.__eq__(other._list)
    757733        else:
    class CombinatorialObject(SageObject): 
    760736    def __lt__(self, other):
    761737        """
    762738        EXAMPLES::
    763        
     739
    764740            sage: c = CombinatorialObject([1,2,3])
    765741            sage: d = CombinatorialObject([2,3,4])
    766742            sage: c < d
    class CombinatorialObject(SageObject): 
    768744            sage: c < [2,3,4]
    769745            True
    770746        """
    771        
     747
    772748        if isinstance(other, CombinatorialObject):
    773749            return self._list.__lt__(other._list)
    774750        else:
    class CombinatorialObject(SageObject): 
    777753    def __le__(self, other):
    778754        """
    779755        EXAMPLES::
    780        
     756
    781757            sage: c = CombinatorialObject([1,2,3])
    782758            sage: d = CombinatorialObject([2,3,4])
    783759            sage: c <= c
    class CombinatorialObject(SageObject): 
    795771    def __gt__(self, other):
    796772        """
    797773        EXAMPLES::
    798        
     774
    799775            sage: c = CombinatorialObject([1,2,3])
    800776            sage: d = CombinatorialObject([2,3,4])
    801777            sage: c > c
    class CombinatorialObject(SageObject): 
    813789    def __ge__(self, other):
    814790        """
    815791        EXAMPLES::
    816        
     792
    817793            sage: c = CombinatorialObject([1,2,3])
    818794            sage: d = CombinatorialObject([2,3,4])
    819795            sage: c >= c
    class CombinatorialObject(SageObject): 
    831807    def __ne__(self, other):
    832808        """
    833809        EXAMPLES::
    834        
     810
    835811            sage: c = CombinatorialObject([1,2,3])
    836812            sage: d = CombinatorialObject([2,3,4])
    837813            sage: c != c
    class CombinatorialObject(SageObject): 
    849825    def __add__(self, other):
    850826        """
    851827        EXAMPLES::
    852        
     828
    853829            sage: c = CombinatorialObject([1,2,3])
    854830            sage: c + [4]
    855831            [1, 2, 3, 4]
    class CombinatorialObject(SageObject): 
    863839        Computes the hash of self by computing the hash of the string
    864840        representation of self._list. The hash is cached and stored in
    865841        self._hash.
    866        
     842
    867843        EXAMPLES::
    868        
     844
    869845            sage: c = CombinatorialObject([1,2,3])
    870846            sage: c._hash is None
    871847            True
    class CombinatorialObject(SageObject): 
    881857    def __len__(self):
    882858        """
    883859        EXAMPLES::
    884        
     860
    885861            sage: c = CombinatorialObject([1,2,3])
    886862            sage: len(c)
    887863            3
    class CombinatorialObject(SageObject): 
    893869    def __getitem__(self, key):
    894870        """
    895871        EXAMPLES::
    896        
     872
    897873            sage: c = CombinatorialObject([1,2,3])
    898874            sage: c[0]
    899875            1
    class CombinatorialObject(SageObject): 
    907883    def __iter__(self):
    908884        """
    909885        EXAMPLES::
    910        
     886
    911887            sage: c = CombinatorialObject([1,2,3])
    912888            sage: list(iter(c))
    913889            [1, 2, 3]
    class CombinatorialObject(SageObject): 
    917893    def __contains__(self, item):
    918894        """
    919895        EXAMPLES::
    920        
     896
    921897            sage: c = CombinatorialObject([1,2,3])
    922898            sage: 1 in c
    923899            True
    class CombinatorialObject(SageObject): 
    930906    def index(self, key):
    931907        """
    932908        EXAMPLES::
    933        
     909
    934910            sage: c = CombinatorialObject([1,2,3])
    935911            sage: c.index(1)
    936912            0
    class CombinatorialClass(Parent): 
    981957        """
    982958        __len__ has been removed ! to get the number of element in a
    983959        combinatorial class, use .cardinality instead.
    984        
     960
    985961
    986962        TEST::
    987        
     963
    988964            sage: len(Partitions(5))
    989965            Traceback (most recent call last):
    990966            ...
    class CombinatorialClass(Parent): 
    995971    def count(self):
    996972        """
    997973        Deprecated ! Please use ``.cardinality`` instead.
    998        
     974
    999975
    1000976        TEST::
    1001        
     977
    1002978            sage: class C(CombinatorialClass):
    1003979            ...     def __iter__(self):
    1004980            ...          return iter([1,2,3])
    class CombinatorialClass(Parent): 
    1014990    def is_finite(self):
    1015991        """
    1016992        Returns whether self is finite or not.
    1017        
     993
    1018994        EXAMPLES::
    1019        
     995
    1020996            sage: Partitions(5).is_finite()
    1021997            True
    1022998            sage: Permutations().is_finite()
    class CombinatorialClass(Parent): 
    10241000        """
    10251001        from sage.rings.all import infinity
    10261002        return self.cardinality() != infinity
    1027    
     1003
    10281004    def __getitem__(self, i):
    10291005        """
    10301006        Returns the combinatorial object of rank i.
    1031        
     1007
    10321008        EXAMPLES::
    1033        
     1009
    10341010            sage: p5 = Partitions(5)
    10351011            sage: p5[0]
    10361012            [5]
    class CombinatorialClass(Parent): 
    10461022    def __str__(self):
    10471023        """
    10481024        Returns a string representation of self.
    1049        
     1025
    10501026        EXAMPLES::
    1051        
     1027
    10521028            sage: str(Partitions(5))
    10531029            'Partitions of the integer 5'
    10541030        """
    10551031        return self.__repr__()
    1056    
     1032
    10571033    def _repr_(self):
    10581034        """
    10591035        EXAMPLES::
    1060        
     1036
    10611037            sage: repr(Partitions(5))   # indirect doctest
    10621038            'Partitions of the integer 5'
    10631039        """
    class CombinatorialClass(Parent): 
    10711047        Tests whether or not the combinatorial class contains the object x.
    10721048        This raises a NotImplementedError as a default since _all_
    10731049        subclasses of CombinatorialClass should override this.
    1074        
     1050
    10751051        Note that we could replace this with a default implementation that
    10761052        just iterates through the elements of the combinatorial class and
    10771053        checks for equality. However, since we use __contains__ for
    10781054        type checking, this operation should be cheap and should be
    10791055        implemented manually for each combinatorial class.
    1080        
     1056
    10811057        EXAMPLES::
    1082        
     1058
    10831059            sage: C = CombinatorialClass()
    10841060            sage: x in C
    10851061            Traceback (most recent call last):
    class CombinatorialClass(Parent): 
    10921068        """
    10931069        Compares two different combinatorial classes. For now, the
    10941070        comparison is done just on their repr's.
    1095        
     1071
    10961072        EXAMPLES::
    1097        
     1073
    10981074            sage: p5 = Partitions(5)
    10991075            sage: p6 = Partitions(6)
    11001076            sage: repr(p5) == repr(p6)
    class CombinatorialClass(Parent): 
    11031079            False
    11041080        """
    11051081        return cmp(repr(self), repr(x))
    1106    
     1082
    11071083    def __cardinality_from_iterator(self):
    11081084        """
    11091085        Default implementation of cardinality which just goes through the iterator
    11101086        of the combinatorial class to count the number of objects.
    1111        
     1087
    11121088        EXAMPLES::
    1113        
     1089
    11141090            sage: class C(CombinatorialClass):
    11151091            ...     def __iter__(self):
    11161092            ...          return iter([1,2,3])
    class CombinatorialClass(Parent): 
    11331109    def __call__(self, x):
    11341110        """
    11351111        Returns x as an element of the combinatorial class's object class.
    1136        
     1112
    11371113        EXAMPLES::
    1138        
     1114
    11391115            sage: p5 = Partitions(5)
    11401116            sage: a = [2,2,1]
    11411117            sage: type(a)
    class CombinatorialClass(Parent): 
    11961172        """
    11971173        The default implementation of list which builds the list from the
    11981174        iterator.
    1199        
     1175
    12001176        EXAMPLES::
    1201        
     1177
    12021178            sage: class C(CombinatorialClass):
    12031179            ...     def __iter__(self):
    12041180            ...          return iter([1,2,3])
    class CombinatorialClass(Parent): 
    12171193    def __iterator_from_next(self):
    12181194        """
    12191195        An iterator to use when .first() and .next() are provided.
    1220        
     1196
    12211197        EXAMPLES::
    1222        
     1198
    12231199            sage: C = CombinatorialClass()
    12241200            sage: C.first = lambda: 0
    12251201            sage: C.next  = lambda c: c+1
    class CombinatorialClass(Parent): 
    12341210                f = self.next(f)
    12351211            except (TypeError, ValueError ):
    12361212                break
    1237            
     1213
    12381214            if f is None or f is False :
    12391215                break
    12401216            else:
    12411217                yield f
    1242                
     1218
    12431219    def __iterator_from_previous(self):
    12441220        """
    12451221        An iterator to use when .last() and .previous() are provided. Note
    12461222        that this requires the combinatorial class to be finite. It is not
    12471223        recommended to implement combinatorial classes using last and
    12481224        previous.
    1249        
     1225
    12501226        EXAMPLES::
    1251        
     1227
    12521228            sage: C = CombinatorialClass()
    12531229            sage: C.last = lambda: 4
    12541230            sage: def prev(c):
    class CombinatorialClass(Parent): 
    12691245                l = self.previous(l)
    12701246            except (TypeError, ValueError):
    12711247                break
    1272            
     1248
    12731249            if l == None:
    12741250                break
    12751251            else:
    12761252                li.append(l)
    12771253        return reversed(li)
    1278                
     1254
    12791255    def __iterator_from_unrank(self):
    12801256        """
    12811257        An iterator to use when .unrank() is provided.
    1282        
     1258
    12831259        EXAMPLES::
    1284        
     1260
    12851261            sage: C = CombinatorialClass()
    12861262            sage: l = [1,2,3]
    12871263            sage: C.unrank = lambda c: l[c]
    class CombinatorialClass(Parent): 
    12971273                u = self.unrank(r)
    12981274            except (TypeError, ValueError, IndexError):
    12991275                break
    1300            
     1276
    13011277            if u == None:
    13021278                break
    13031279            else:
    class CombinatorialClass(Parent): 
    13061282    def __iterator_from_list(self):
    13071283        """
    13081284        An iterator to use when .list() is provided()
    1309        
     1285
    13101286        EXAMPLES::
    1311        
     1287
    13121288            sage: C = CombinatorialClass()
    13131289            sage: C.list = lambda: [1, 2, 3]
    13141290            sage: list(C) # indirect doctest
    class CombinatorialClass(Parent): 
    13201296    def iterator(self):
    13211297        """
    13221298        Iterator is deprecated for combinatorial classes.
    1323        
     1299
    13241300        EXAMPLES::
    1325        
     1301
    13261302            sage: p5 = Partitions(3)
    13271303            sage: it = p5.iterator()
    13281304            doctest:...: DeprecationWarning: The usage of iterator for combinatorial classes is deprecated. Please use the class itself
    13291305            See http://trac.sagemath.org/5308 for details.
    13301306            sage: [i for i in it]
    1331             [[3], [2, 1], [1, 1, 1]]       
     1307            [[3], [2, 1], [1, 1, 1]]
    13321308            sage: [i for i in p5]
    1333             [[3], [2, 1], [1, 1, 1]]       
     1309            [[3], [2, 1], [1, 1, 1]]
    13341310        """
    13351311        from sage.misc.superseded import deprecation
    13361312        deprecation(5308, "The usage of iterator for combinatorial classes is deprecated. Please use the class itself")
    13371313        return self.__iter__()
    1338    
     1314
    13391315    def __iter__(self):
    13401316        """
    13411317        Allows the combinatorial class to be treated as an iterator. Default
    13421318        implementation.
    1343        
     1319
    13441320        EXAMPLES::
    1345        
     1321
    13461322            sage: p5 = Partitions(5)
    13471323            sage: [i for i in p5]
    13481324            [[5], [4, 1], [3, 2], [3, 1, 1], [2, 2, 1], [2, 1, 1, 1], [1, 1, 1, 1, 1]]
    class CombinatorialClass(Parent): 
    13721348    def __unrank_from_iterator(self, r):
    13731349        """
    13741350        Default implementation of unrank which goes through the iterator.
    1375        
     1351
    13761352        EXAMPLES::
    1377        
     1353
    13781354            sage: C = CombinatorialClass()
    13791355            sage: C.list = lambda: [1,2,3]
    13801356            sage: C.unrank(1) # indirect doctest
    class CombinatorialClass(Parent): 
    13901366    #Set the default implementation of unrank
    13911367    unrank = __unrank_from_iterator
    13921368
    1393    
     1369
    13941370    def __random_element_from_unrank(self):
    13951371        """
    13961372        Default implementation of random which uses unrank.
    1397        
     1373
    13981374        EXAMPLES::
    1399        
     1375
    14001376            sage: C = CombinatorialClass()
    14011377            sage: C.list = lambda: [1,2,3]
    14021378            sage: C.random_element()       # indirect doctest
    class CombinatorialClass(Parent): 
    14131389    def random(self):
    14141390        """
    14151391        Deprecated. Use self.random_element() instead.
    1416        
     1392
    14171393        EXAMPLES::
    1418        
     1394
    14191395            sage: C = CombinatorialClass()
    14201396            sage: C.random()
    14211397            Traceback (most recent call last):
    14221398            ...
    14231399            NotImplementedError: Deprecated: use random_element() instead
    14241400        """
    1425         raise NotImplementedError, "Deprecated: use random_element() instead" 
     1401        raise NotImplementedError, "Deprecated: use random_element() instead"
    14261402
    14271403    def __rank_from_iterator(self, obj):
    14281404        """
    14291405        Default implementation of rank which uses iterator.
    1430        
     1406
    14311407        EXAMPLES::
    1432        
     1408
    14331409            sage: C = CombinatorialClass()
    14341410            sage: C.list = lambda: [1,2,3]
    14351411            sage: C.rank(3) # indirect doctest
    class CombinatorialClass(Parent): 
    14411417                return r
    14421418            r += 1
    14431419        raise ValueError
    1444            
     1420
    14451421    rank =  __rank_from_iterator
    14461422
    14471423    def __first_from_iterator(self):
    14481424        """
    14491425        Default implementation for first which uses iterator.
    1450        
     1426
    14511427        EXAMPLES::
    1452        
     1428
    14531429            sage: C = CombinatorialClass()
    14541430            sage: C.list = lambda: [1,2,3]
    14551431            sage: C.first() # indirect doctest
    class CombinatorialClass(Parent): 
    14631439    def __last_from_iterator(self):
    14641440        """
    14651441        Default implementation for first which uses iterator.
    1466        
     1442
    14671443        EXAMPLES::
    1468        
     1444
    14691445            sage: C = CombinatorialClass()
    14701446            sage: C.list = lambda: [1,2,3]
    14711447            sage: C.last() # indirect doctest
    class CombinatorialClass(Parent): 
    14801456    def __next_from_iterator(self, obj):
    14811457        """
    14821458        Default implementation for next which uses iterator.
    1483        
     1459
    14841460        EXAMPLES::
    1485        
     1461
    14861462            sage: C = CombinatorialClass()
    14871463            sage: C.list = lambda: [1,2,3]
    14881464            sage: C.next(2) # indirect doctest
    class CombinatorialClass(Parent): 
    15011477    def __previous_from_iterator(self, obj):
    15021478        """
    15031479        Default implementation for next which uses iterator.
    1504        
     1480
    15051481        EXAMPLES::
    1506        
     1482
    15071483            sage: C = CombinatorialClass()
    15081484            sage: C.list = lambda: [1,2,3]
    15091485            sage: C.previous(2) # indirect doctest
    class CombinatorialClass(Parent): 
    15221498        """
    15231499        Returns the combinatorial subclass of f which consists of the
    15241500        elements x of self such that f(x) is True.
    1525        
     1501
    15261502        EXAMPLES::
    1527        
     1503
    15281504            sage: P = Permutations(3).filter(lambda x: x.avoids([1,2]))
    15291505            sage: P.list()
    15301506            [[3, 2, 1]]
    class CombinatorialClass(Parent): 
    15351511        """
    15361512        Returns the combinatorial class representing the union of self and
    15371513        right_cc.
    1538        
     1514
    15391515        EXAMPLES::
    1540        
     1516
    15411517            sage: P = Permutations(2).union(Permutations(1))
    15421518            sage: P.list()
    15431519            [[1, 2], [2, 1], [1]]
    class FilteredCombinatorialClass(Combina 
    15851561        A filtered combinatorial class F is a subset of another
    15861562        combinatorial class C specified by a function f that takes in an
    15871563        element c of C and returns True if and only if c is in F.
    1588        
     1564
    15891565        TESTS::
    1590        
     1566
    15911567            sage: Permutations(3).filter(lambda x: x.avoids([1,2]))
    15921568            Filtered sublass of Standard permutations of 3
    15931569        """
    class FilteredCombinatorialClass(Combina 
    15981574    def __repr__(self):
    15991575        """
    16001576        EXAMPLES::
    1601        
     1577
    16021578            sage: P = Permutations(3).filter(lambda x: x.avoids([1,2]))
    16031579            sage: P.__repr__()
    16041580            'Filtered sublass of Standard permutations of 3'
    class FilteredCombinatorialClass(Combina 
    16141590    def __contains__(self, x):
    16151591        """
    16161592        EXAMPLES::
    1617        
     1593
    16181594            sage: P = Permutations(3).filter(lambda x: x.avoids([1,2]))
    16191595            sage: 'cat' in P
    16201596            False
    class FilteredCombinatorialClass(Combina 
    16301606    def cardinality(self):
    16311607        """
    16321608        EXAMPLES::
    1633        
     1609
    16341610            sage: P = Permutations(3).filter(lambda x: x.avoids([1,2]))
    16351611            sage: P.cardinality()
    16361612            1
    class FilteredCombinatorialClass(Combina 
    16431619    def __iter__(self):
    16441620        """
    16451621        EXAMPLES::
    1646        
     1622
    16471623            sage: P = Permutations(3).filter(lambda x: x.avoids([1,2]))
    16481624            sage: list(P)
    16491625            [[3, 2, 1]]
    class UnionCombinatorialClass(Combinator 
    16571633        """
    16581634        A UnionCombinatorialClass is a union of two other combinatorial
    16591635        classes.
    1660        
     1636
    16611637        TESTS::
    1662        
     1638
    16631639            sage: P = Permutations(3).union(Permutations(2))
    16641640            sage: P == loads(dumps(P))
    16651641            True
    class UnionCombinatorialClass(Combinator 
    16711647    def __repr__(self):
    16721648        """
    16731649        TESTS::
    1674        
     1650
    16751651            sage: print repr(Permutations(3).union(Permutations(2)))
    1676             Union combinatorial class of 
     1652            Union combinatorial class of
    16771653                Standard permutations of 3
    16781654            and
    16791655                Standard permutations of 2
    class UnionCombinatorialClass(Combinator 
    16861662    def __contains__(self, x):
    16871663        """
    16881664        EXAMPLES::
    1689        
     1665
    16901666            sage: P = Permutations(3).union(Permutations(2))
    16911667            sage: [1,2] in P
    16921668            True
    class UnionCombinatorialClass(Combinator 
    17001676    def cardinality(self):
    17011677        """
    17021678        EXAMPLES::
    1703        
     1679
    17041680            sage: P = Permutations(3).union(Permutations(2))
    17051681            sage: P.cardinality()
    17061682            8
    class UnionCombinatorialClass(Combinator 
    17101686    def list(self):
    17111687        """
    17121688        EXAMPLES::
    1713        
     1689
    17141690            sage: P = Permutations(3).union(Permutations(2))
    17151691            sage: P.list()
    17161692            [[1, 2, 3],
    class UnionCombinatorialClass(Combinator 
    17281704    def __iter__(self):
    17291705        """
    17301706        EXAMPLES::
    1731        
     1707
    17321708            sage: P = Permutations(3).union(Permutations(2))
    17331709            sage: list(P)
    17341710            [[1, 2, 3],
    class UnionCombinatorialClass(Combinator 
    17481724    def first(self):
    17491725        """
    17501726        EXAMPLES::
    1751        
     1727
    17521728            sage: P = Permutations(3).union(Permutations(2))
    17531729            sage: P.first()
    17541730            [1, 2, 3]
    class UnionCombinatorialClass(Combinator 
    17581734    def last(self):
    17591735        """
    17601736        EXAMPLES::
    1761        
     1737
    17621738            sage: P = Permutations(3).union(Permutations(2))
    17631739            sage: P.last()
    17641740            [2, 1]
    class UnionCombinatorialClass(Combinator 
    17681744    def rank(self, x):
    17691745        """
    17701746        EXAMPLES::
    1771        
     1747
    17721748            sage: P = Permutations(3).union(Permutations(2))
    17731749            sage: P.rank(Permutation([2,1]))
    17741750            7
    class UnionCombinatorialClass(Combinator 
    17831759    def unrank(self, x):
    17841760        """
    17851761        EXAMPLES::
    1786        
     1762
    17871763            sage: P = Permutations(3).union(Permutations(2))
    17881764            sage: P.unrank(7)
    17891765            [2, 1]
    class MapCombinatorialClass(Combinatoria 
    18071783    def __init__(self, cc, f, name=None):
    18081784        """
    18091785        TESTS::
    1810        
     1786
    18111787            sage: Partitions(3).map(attrcall('conjugate'))
    18121788            Image of Partitions of the integer 3 by *.conjugate()
    18131789        """
    class MapCombinatorialClass(Combinatoria 
    18691845##############################################################################
    18701846from sage.rings.all import infinity
    18711847class InfiniteAbstractCombinatorialClass(CombinatorialClass):
    1872     r"""   
     1848    r"""
    18731849    This is an internal class that should not be used directly.  A class which
    18741850    inherits from InfiniteAbstractCombinatorialClass inherits the standard
    18751851    methods list and count.
    class InfiniteAbstractCombinatorialClass 
    18931869    def list(self):
    18941870        """
    18951871        Returns an error since self is an infinite combinatorial class.
    1896        
     1872
    18971873        EXAMPLES:
    18981874            sage: R = InfiniteAbstractCombinatorialClass()
    18991875            sage: R.list()
    class InfiniteAbstractCombinatorialClass 
    19141890            Traceback (most recent call last):
    19151891            ...
    19161892            NotImplementedError
    1917            
     1893
    19181894            sage: c = iter(Compositions()) # indirect doctest
    19191895            sage: c.next(), c.next(), c.next(), c.next(), c.next(), c.next()
    19201896            ([], [1], [1, 1], [2], [1, 1, 1], [1, 2])
    class InfiniteAbstractCombinatorialClass 
    19291905        while True:
    19301906            for c in finite(i):
    19311907                yield c
    1932             i+=1   
    1933      
    1934        
    1935            
     1908            i+=1
     1909
     1910
     1911
    19361912def hurwitz_zeta(s,x,N):
    19371913    """
    19381914    Returns the value of the `\zeta(s,x)` to `N`
    19391915    decimals, where s and x are real.
    1940    
     1916
    19411917    The Hurwitz zeta function is one of the many zeta functions. It
    19421918    defined as
    1943    
     1919
    19441920    .. math::
    1945    
    1946              \zeta(s,x) = \sum_{k=0}^\infty (k+x)^{-s}.     
    1947    
    1948    
     1921
     1922             \zeta(s,x) = \sum_{k=0}^\infty (k+x)^{-s}.
     1923
     1924
    19491925    When `x = 1`, this coincides with Riemann's zeta function.
    19501926    The Dirichlet L-functions may be expressed as a linear combination
    19511927    of Hurwitz zeta functions.
    1952    
     1928
    19531929    Note that if you use floating point inputs, then the results may be
    19541930    slightly off.
    1955    
     1931
    19561932    EXAMPLES::
    1957    
     1933
    19581934        sage: hurwitz_zeta(3,1/2,6)
    19591935        8.41439000000000
    19601936        sage: hurwitz_zeta(11/10,1/2,6)
    19611937        12.1041000000000
    19621938        sage: hurwitz_zeta(11/10,1/2,50)
    19631939        12.10381349568375510570907741296668061903364861809
    1964    
     1940
    19651941    REFERENCES:
    19661942
    19671943    - http://en.wikipedia.org/wiki/Hurwitz_zeta_function
    def hurwitz_zeta(s,x,N): 
    19801956            return sage_eval(s[:i])
    19811957        else:
    19821958            return sage_eval(s[:i])*10**sage_eval(s[i+1:])
    1983    
     1959
    19841960    return s  ## returns an odd string
    19851961
    19861962
    def combinations(mset,k): 
    19941970    without repetitions and is represented by a sorted sublist of mset.
    19951971    Returns the set of all combinations of the multiset mset with k
    19961972    elements.
    1997    
     1973
    19981974    .. warning::
    19991975
    20001976       Wraps GAP's Combinations. Hence mset must be a list of objects
    def combinations(mset,k): 
    20021978       GAP interpreter. If mset consists of at all complicated Sage
    20031979       objects, this function does *not* do what you expect. A proper
    20041980       function should be written! (TODO!)
    2005    
     1981
    20061982    EXAMPLES::
    2007    
     1983
    20081984        sage: mset = [1,1,2,3,4,4,5]
    20091985        sage: combinations(mset,2)
    20101986        [[1, 1],
    def combinations(mset,k): 
    20221998         sage: mset = ["d","a","v","i","d"]
    20231999         sage: combinations(mset,3)
    20242000         ['add', 'adi', 'adv', 'aiv', 'ddi', 'ddv', 'div']
    2025    
     2001
    20262002    .. note::
    20272003
    20282004       For large lists, this raises a string error.
    def combinations_iterator(mset,n=None): 
    20342010    """
    20352011    Posted by Raymond Hettinger, 2006/03/23, to the Python Cookbook:
    20362012    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/474124
    2037    
     2013
    20382014    Much faster than combinations.
    2039    
     2015
    20402016    EXAMPLES::
    2041    
     2017
    20422018        sage: X = combinations_iterator([1,2,3,4,5],3)
    20432019        sage: [x for x in X]
    20442020        [[1, 2, 3],
    def combinations_iterator(mset,n=None): 
    20542030    """
    20552031    items = mset
    20562032    if n is None:
    2057         n = len(items)   
     2033        n = len(items)
    20582034    for i in range(len(items)):
    20592035        v = items[i:i+1]
    20602036        if n == 1:
    def number_of_combinations(mset,k): 
    20692045    """
    20702046    Returns the size of combinations(mset,k). IMPLEMENTATION: Wraps
    20712047    GAP's NrCombinations.
    2072    
     2048
    20732049    .. note::
    20742050
    20752051       ``mset`` must be a list of integers or strings (i.e., this is
    20762052       very restricted).
    2077    
     2053
    20782054    EXAMPLES::
    2079    
     2055
    20802056        sage: mset = [1,1,2,3,4,4,5]
    20812057        sage: number_of_combinations(mset,2)
    20822058        12
    def arrangements(mset,k): 
    20882064    An arrangement of mset is an ordered selection without repetitions
    20892065    and is represented by a list that contains only elements from mset,
    20902066    but maybe in a different order.
    2091    
     2067
    20922068    ``arrangements`` returns the set of arrangements of the
    20932069    multiset mset that contain k elements.
    2094    
     2070
    20952071    IMPLEMENTATION: Wraps GAP's Arrangements.
    2096    
     2072
    20972073    .. warning::
    20982074
    20992075       Wraps GAP - hence mset must be a list of objects that have
    def arrangements(mset,k): 
    21012077       interpreter. If mset consists of at all complicated Sage
    21022078       objects, this function does *not* do what you expect. A proper
    21032079       function should be written! (TODO!)
    2104    
     2080
    21052081    EXAMPLES::
    2106    
     2082
    21072083        sage: mset = [1,1,2,3,4,4,5]
    21082084        sage: arrangements(mset,2)
    21092085        [[1, 1],
    def arrangements(mset,k): 
    21252101         [4, 4],
    21262102         [4, 5],
    21272103         [5, 1],
    2128          [5, 2], 
     2104         [5, 2],
    21292105         [5, 3],
    21302106         [5, 4]]
    21312107         sage: arrangements( ["c","a","t"], 2 )
    def number_of_arrangements(mset,k): 
    21402116    """
    21412117    Returns the size of arrangements(mset,k). Wraps GAP's
    21422118    NrArrangements.
    2143    
     2119
    21442120    EXAMPLES::
    2145    
     2121
    21462122        sage: mset = [1,1,2,3,4,4,5]
    21472123        sage: number_of_arrangements(mset,2)
    21482124        22
    def derangements(mset): 
    21552131    represented by a list that contains exactly the same elements as
    21562132    mset, but possibly in different order. Derangements returns the set
    21572133    of all derangements of a multiset.
    2158    
     2134
    21592135    Wraps GAP's Derangements.
    2160    
     2136
    21612137    .. warning::
    21622138
    21632139       Wraps GAP - hence mset must be a list of objects that have
    def derangements(mset): 
    21652141       interpreter. If mset consists of at all complicated Sage
    21662142       objects, this function does *not* do what you expect. A proper
    21672143       function should be written! (TODO!)
    2168    
     2144
    21692145    EXAMPLES::
    2170    
     2146
    21712147        sage: mset = [1,2,3,4]
    21722148        sage: derangements(mset)
    21732149        [[2, 1, 4, 3],
    def number_of_derangements(mset): 
    21892165    """
    21902166    Returns the size of derangements(mset). Wraps GAP's
    21912167    NrDerangements.
    2192    
     2168
    21932169    EXAMPLES::
    2194    
     2170
    21952171        sage: mset = [1,2,3,4]
    21962172        sage: number_of_derangements(mset)
    21972173        9
    def tuples(S,k): 
    22052181    repetition and is represented by a list of length k containing
    22062182    elements of set. tuples returns the set of all ordered tuples of
    22072183    length k of the set.
    2208    
     2184
    22092185    EXAMPLES::
    2210    
     2186
    22112187        sage: S = [1,2]
    22122188        sage: tuples(S,3)
    22132189        [[1, 1, 1], [2, 1, 1], [1, 2, 1], [2, 2, 1], [1, 1, 2], [2, 1, 2], [1, 2, 2], [2, 2, 2]]
    def tuples(S,k): 
    22172193         ['e', 't'], ['i', 't'], ['n', 't'], ['s', 'e'], ['t', 'e'], ['e', 'e'], ['i', 'e'],
    22182194         ['n', 'e'], ['s', 'i'], ['t', 'i'], ['e', 'i'], ['i', 'i'], ['n', 'i'], ['s', 'n'],
    22192195         ['t', 'n'], ['e', 'n'], ['i', 'n'], ['n', 'n']]
    2220    
     2196
    22212197    The Set(...) comparisons are necessary because finite fields are
    22222198    not enumerated in a standard order.
    2223    
     2199
    22242200    ::
    2225    
     2201
    22262202        sage: K.<a> = GF(4, 'a')
    22272203        sage: mset = [x for x in K if x!=0]
    22282204        sage: tuples(mset,2)
    22292205        [[a, a], [a + 1, a], [1, a], [a, a + 1], [a + 1, a + 1], [1, a + 1], [a, 1], [a + 1, 1], [1, 1]]
    2230                
     2206
    22312207    AUTHORS:
    22322208
    22332209    - Jon Hanke (2006-08)
    def tuples(S,k): 
    22522228def number_of_tuples(S,k):
    22532229    """
    22542230    Returns the size of tuples(S,k). Wraps GAP's NrTuples.
    2255    
     2231
    22562232    EXAMPLES::
    2257    
     2233
    22582234        sage: S = [1,2,3,4,5]
    22592235        sage: number_of_tuples(S,2)
    22602236        25
    def unordered_tuples(S,k): 
    22702246    An unordered tuple of length k of set is a unordered selection with
    22712247    repetitions of set and is represented by a sorted list of length k
    22722248    containing elements from set.
    2273    
     2249
    22742250    unordered_tuples returns the set of all unordered tuples of length
    22752251    k of the set. Wraps GAP's UnorderedTuples.
    2276    
     2252
    22772253    .. warning::
    22782254
    22792255       Wraps GAP - hence mset must be a list of objects that have
    def unordered_tuples(S,k): 
    22812257       interpreter. If mset consists of at all complicated Sage
    22822258       objects, this function does *not* do what you expect. A proper
    22832259       function should be written! (TODO!)
    2284    
     2260
    22852261    EXAMPLES::
    2286    
     2262
    22872263        sage: S = [1,2]
    22882264        sage: unordered_tuples(S,3)
    22892265        [[1, 1, 1], [1, 1, 2], [1, 2, 2], [2, 2, 2]]
    def number_of_unordered_tuples(S,k): 
    22972273    """
    22982274    Returns the size of unordered_tuples(S,k). Wraps GAP's
    22992275    NrUnorderedTuples.
    2300    
     2276
    23012277    EXAMPLES::
    2302    
     2278
    23032279        sage: S = [1,2,3,4,5]
    23042280        sage: number_of_unordered_tuples(S,2)
    23052281        15
    def permutations(mset): 
    23162292    second element appears `k_2` times and so on, the number
    23172293    of permutations is `|mset|! / (k_1! k_2! \ldots)`, which
    23182294    is sometimes called a multinomial coefficient.
    2319    
     2295
    23202296    permutations returns the set of all permutations of a multiset.
    23212297    Calls a function written by Mike Hansen, not GAP.
    2322    
     2298
    23232299    EXAMPLES::
    2324    
     2300
    23252301        sage: mset = [1,1,2,2,2]
    23262302        sage: permutations(mset)
    23272303        [[1, 1, 2, 2, 2],
    def permutations_iterator(mset,n=None): 
    23482324    Do not use this function. It will be deprecated in future version
    23492325    of Sage and eventually removed. Use Permutations instead; instead
    23502326    of
    2351    
     2327
    23522328    for p in permutations_iterator(range(1, m+1), n)
    2353    
     2329
    23542330    use
    2355    
     2331
    23562332    for p in Permutations(m, n).
    2357    
     2333
    23582334    Note that Permutations, unlike this function, treats repeated
    23592335    elements as identical.
    2360    
     2336
    23612337    If you insist on using this now:
    2362    
     2338
    23632339    Returns an iterator (http://docs.python.org/lib/typeiter.html)
    23642340    which can be used in place of permutations(mset) if all you need it
    23652341    for is a 'for' loop.
    2366    
     2342
    23672343    Posted by Raymond Hettinger, 2006/03/23, to the Python Cookbook:
    23682344    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/474124
    2369    
     2345
    23702346    Note- This function considers repeated elements as different
    23712347    entries, so for example::
    2372    
     2348
    23732349        sage: from sage.combinat.combinat import permutations, permutations_iterator
    23742350        sage: mset = [1,2,2]
    23752351        sage: permutations(mset)
    def permutations_iterator(mset,n=None): 
    23812357        [2, 2, 1]
    23822358        [2, 1, 2]
    23832359        [2, 2, 1]
    2384    
     2360
    23852361    EXAMPLES::
    2386    
     2362
    23872363        sage: X = permutations_iterator(range(3),2)
    23882364        sage: [x for x in X]
    23892365        [[0, 1], [0, 2], [1, 0], [1, 2], [2, 0], [2, 1]]
    def number_of_permutations(mset): 
    24052381    Do not use this function. It will be deprecated in future version
    24062382    of Sage and eventually removed. Use Permutations instead; instead
    24072383    of
    2408    
     2384
    24092385    number_of_permutations(mset)
    2410    
     2386
    24112387    use
    2412    
     2388
    24132389    Permutations(mset).cardinality().
    2414    
     2390
    24152391    If you insist on using this now:
    2416    
     2392
    24172393    Returns the size of permutations(mset).
    2418    
     2394
    24192395    AUTHORS:
    24202396
    24212397    - Robert L. Miller
    2422    
     2398
    24232399    EXAMPLES::
    2424    
     2400
    24252401        sage: mset = [1,1,2,2,2]
    24262402        sage: number_of_permutations(mset)
    24272403        10
    def cyclic_permutations(mset): 
    24422418    """
    24432419    Returns a list of all cyclic permutations of mset. Treats mset as a
    24442420    list, not a set, i.e. entries with the same value are distinct.
    2445    
     2421
    24462422    AUTHORS:
    24472423
    24482424    - Emily Kirkman
    2449    
     2425
    24502426    EXAMPLES::
    2451    
     2427
    24522428        sage: from sage.combinat.combinat import cyclic_permutations, cyclic_permutations_iterator
    24532429        sage: cyclic_permutations(range(4))
    24542430        [[0, 1, 2, 3], [0, 1, 3, 2], [0, 2, 1, 3], [0, 2, 3, 1], [0, 3, 1, 2], [0, 3, 2, 1]]
    def cyclic_permutations(mset): 
    24562432        ...       print cycle
    24572433        ['a', 'b', 'c']
    24582434        ['a', 'c', 'b']
    2459    
     2435
    24602436    Note that lists with repeats are not handled intuitively::
    2461    
     2437
    24622438        sage: cyclic_permutations([1,1,1])
    24632439        [[1, 1, 1], [1, 1, 1]]
    24642440    """
    def cyclic_permutations_iterator(mset): 
    24692445    Iterates over all cyclic permutations of mset in cycle notation.
    24702446    Treats mset as a list, not a set, i.e. entries with the same value
    24712447    are distinct.
    2472    
     2448
    24732449    AUTHORS:
    24742450
    24752451    - Emily Kirkman
    2476    
     2452
    24772453    EXAMPLES::
    2478    
     2454
    24792455        sage: from sage.combinat.combinat import cyclic_permutations, cyclic_permutations_iterator
    24802456        sage: cyclic_permutations(range(4))
    24812457        [[0, 1, 2, 3], [0, 1, 3, 2], [0, 2, 1, 3], [0, 2, 3, 1], [0, 3, 1, 2], [0, 3, 2, 1]]
    def cyclic_permutations_iterator(mset): 
    24832459        ...       print cycle
    24842460        ['a', 'b', 'c']
    24852461        ['a', 'c', 'b']
    2486    
     2462
    24872463    Note that lists with repeats are not handled intuitively::
    2488    
     2464
    24892465        sage: cyclic_permutations([1,1,1])
    24902466        [[1, 1, 1], [1, 1, 1]]
    24912467    """
    def bell_polynomial(n, k): 
    25042480       B_{n,k}(x_1, x_2, \ldots, x_{n-k+1}) = \sum_{\sum{j_i}=k, \sum{i j_i}
    25052481       =n} \frac{n!}{j_1!j_2!\ldots} \frac{x_1}{1!}^j_1 \frac{x_2}{2!}^j_2
    25062482       \ldots
    2507    
     2483
    25082484    INPUT:
    25092485
    25102486    - ``n`` - integer
    def bell_polynomial(n, k): 
    25142490    OUTPUT:
    25152491
    25162492    - polynomial expression (SymbolicArithmetic)
    2517  
     2493
    25182494    EXAMPLES::
    2519    
     2495
    25202496        sage: bell_polynomial(6,2)
    25212497        10*x_3^2 + 15*x_2*x_4 + 6*x_1*x_5
    25222498        sage: bell_polynomial(6,3)
    def bell_polynomial(n, k): 
    25252501    REFERENCES:
    25262502
    25272503    - E.T. Bell, "Partition Polynomials"
    2528            
     2504
    25292505    AUTHORS:
    25302506
    25312507    - Blair Sutton (2009-01-26)
    def bell_polynomial(n, k): 
    25412517            factorial_product *= factorial(count)
    25422518            power_factorial_product *= factorial(part)**count
    25432519
    2544         coefficient = factorial(n) / (factorial_product * power_factorial_product)   
     2520        coefficient = factorial(n) / (factorial_product * power_factorial_product)
    25452521        result += coefficient *  prod([vars[i-1] for i in p])
    2546    
    2547     return result 
     2522
     2523    return result
    25482524
    25492525def fibonacci_sequence(start, stop=None, algorithm=None):
    25502526    r"""
    25512527    Returns an iterator over the Fibonacci sequence, for all fibonacci
    25522528    numbers `f_n` from ``n = start`` up to (but
    25532529    not including) ``n = stop``
    2554    
     2530
    25552531    INPUT:
    2556    
    2557    
     2532
     2533
    25582534    -  ``start`` - starting value
    2559    
     2535
    25602536    -  ``stop`` - stopping value
    2561    
     2537
    25622538    -  ``algorithm`` - default (None) - passed on to
    25632539       fibonacci function (or not passed on if None, i.e., use the
    25642540       default).
    2565    
    2566    
     2541
     2542
    25672543    EXAMPLES::
    2568    
     2544
    25692545        sage: fibs = [i for i in fibonacci_sequence(10, 20)]
    25702546        sage: fibs
    25712547        [55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181]
    2572    
     2548
    25732549    ::
    2574    
     2550
    25752551        sage: sum([i for i in fibonacci_sequence(100, 110)])
    25762552        69919376923075308730013
    2577    
     2553
    25782554    .. seealso::
    25792555
    25802556       :func:`fibonacci_xrange`
    2581    
     2557
    25822558    AUTHORS:
    25832559
    25842560    - Bobby Moretti
    def fibonacci_xrange(start, stop=None, a 
    26022578    Returns an iterator over all of the Fibonacci numbers in the given
    26032579    range, including ``f_n = start`` up to, but not
    26042580    including, ``f_n = stop``.
    2605    
     2581
    26062582    EXAMPLES::
    2607    
     2583
    26082584        sage: fibs_in_some_range =  [i for i in fibonacci_xrange(10^7, 10^8)]
    26092585        sage: len(fibs_in_some_range)
    26102586        4
    26112587        sage: fibs_in_some_range
    26122588        [14930352, 24157817, 39088169, 63245986]
    2613    
     2589
    26142590    ::
    2615    
     2591
    26162592        sage: fibs = [i for i in fibonacci_xrange(10, 100)]
    26172593        sage: fibs
    26182594        [13, 21, 34, 55, 89]
    2619    
     2595
    26202596    ::
    2621    
     2597
    26222598        sage: list(fibonacci_xrange(13, 34))
    26232599        [13, 21]
    2624    
     2600
    26252601    A solution to the second Project Euler problem::
    2626    
     2602
    26272603        sage: sum([i for i in fibonacci_xrange(10^6) if is_even(i)])
    26282604        1089154
    2629    
     2605
    26302606    .. seealso::
    26312607
    26322608       :func:`fibonacci_sequence`
    2633    
     2609
    26342610    AUTHORS:
    26352611
    26362612    - Bobby Moretti
    def fibonacci_xrange(start, stop=None, a 
    26602636def bernoulli_polynomial(x, n):
    26612637    r"""
    26622638    Return the nth Bernoulli polynomial evaluated at x.
    2663    
     2639
    26642640    The generating function for the Bernoulli polynomials is
    2665    
     2641
    26662642    .. math::
    2667    
    2668        \frac{t e^{xt}}{e^t-1}= \sum_{n=0}^\infty B_n(x) \frac{t^n}{n!}, 
    2669    
     2643
     2644       \frac{t e^{xt}}{e^t-1}= \sum_{n=0}^\infty B_n(x) \frac{t^n}{n!},
     2645
    26702646    and they are given directly by
    2671    
     2647
    26722648    .. math::
    2673    
     2649
    26742650       B_n(x) = \sum_{i=0}^n \binom{n}{i}B_{n-i}x^i.
    2675        
     2651
    26762652    One has `B_n(x) = - n\zeta(1 - n,x)`, where
    26772653    `\zeta(s,x)` is the Hurwitz zeta function. Thus, in a
    2678     certain sense, the Hurwitz zeta function generalizes the 
     2654    certain sense, the Hurwitz zeta function generalizes the
    26792655    Bernoulli polynomials to non-integer values of n.
    2680    
     2656
    26812657    EXAMPLES::
    2682    
     2658
    26832659        sage: y = QQ['y'].0
    26842660        sage: bernoulli_polynomial(y, 5)
    26852661        y^5 - 5/2*y^4 + 5/3*y^3 - 1/6*y
    def bernoulli_polynomial(x, n): 
    27012677        sage: 5*power_sum == bernoulli_polynomial(10, 5) - bernoulli(5)
    27022678        True
    27032679
    2704    
     2680
    27052681    REFERENCES:
    2706        
     2682
    27072683    - http://en.wikipedia.org/wiki/Bernoulli_polynomials
    27082684    """
    27092685    try:
    def bernoulli_polynomial(x, n): 
    27182694
    27192695    if n == 1:
    27202696        return x - ZZ(1)/2
    2721    
     2697
    27222698    k = n.mod(2)
    2723     coeffs = [0]*k + sum(([binomial(n, i)*bernoulli(n-i), 0] 
     2699    coeffs = [0]*k + sum(([binomial(n, i)*bernoulli(n-i), 0]
    27242700                          for i in range(k, n+1, 2)), [])
    27252701    coeffs[-3] = -n/2
    27262702
    def bernoulli_polynomial(x, n): 
    27292705            return x.parent()(coeffs)(x)
    27302706        except TypeError:
    27312707            pass
    2732    
     2708
    27332709    x2 = x*x
    27342710    xi = x**k
    27352711    s = 0
  • sage/combinat/partition.py

    diff --git a/sage/combinat/partition.py b/sage/combinat/partition.py
    a b AUTHORS: 
    1919
    2020- Dan Drake (2009-03-28): deprecate RestrictedPartitions and implement
    2121  Partitions_parts_in
    22  
     22
    2323- Travis Scrimshaw (2012-01-12): Implemented latex function to Partition_class
     24
    2425- Travis Scrimshaw (2012-05-09): Fixed Partitions(-1).list() infinite recursion
    2526  loop by saying Partitions_n is the empty set.
    2627
    2728- Travis Scrimshaw (2012-05-11): Fixed bug in inner where if the length was
    2829  longer than the length of the inner partition, it would include 0's.
    2930
     31- Andrew Mathas (2012-06-01): Removed depreciated functions and added
     32  compatibility with the PartitionTuple classes.  See :trac:`13072`
     33
    3034EXAMPLES:
    3135
    3236There are 5 partitions of the integer 4::
    the partition back up from them:: 
    205209    sage: Partition(core=[],quotient=([2, 1], [4], [1, 1, 1]))
    206210    [11, 5, 5, 3, 2, 2, 2]
    207211
    208 We can compute the Frobenius coordinates (or beta numbers), and go back
     212We can compute the Frobenius coordinates and go back
    209213and forth::
    210214
    211215    sage: Partition([7,3,1]).frobenius_coordinates()
    import sage.combinat.skew_partition 
    233237from sage.rings.integer import Integer
    234238import __builtin__
    235239from combinat import CombinatorialClass, CombinatorialObject, cyclic_permutations_iterator, InfiniteAbstractCombinatorialClass
    236 import partitions as partitions_ext
     240from sage.combinat.partitions import number_of_partitions as bober_number_of_partitions
    237241from sage.libs.all import pari
    238242import tableau
    239243import permutation
    import composition 
    241245from integer_vector import IntegerVectors
    242246from cartesian_product import CartesianProduct
    243247from integer_list import IntegerListsLex
    244 from sage.misc.superseded import deprecation, deprecated_function_alias
    245248from sage.misc.prandom import randrange
    246249from sage.rings.infinity import infinity
     250from sage.groups.perm_gps.permgroup import PermutationGroup
    247251
    248252def Partition(mu=None, **keyword):
    249253    """
    def Partition(mu=None, **keyword): 
    253257
    254258      * a list (the default)
    255259      * using exponential notation
    256       * by Frobenius coordinates (also called beta numbers)
     260      * by Frobenius coordinates
    257261      * specifying the core and the quotient
    258       * specifying the core and the canonical quotient (TODO)
    259262
    260263    See the examples below.
    261264
    def Partition(mu=None, **keyword): 
    291294            return Partition_class(mu)
    292295        else:
    293296            raise ValueError, "%s is not a valid partition"%mu
     297    elif 'beta_numbers' in keyword and len(keyword)==1:
     298        return from_beta_numbers(keyword['beta_numbers'])
     299    elif 'core' in keyword and 'quotient' in keyword and len(keyword)==2:
     300        return from_core_and_quotient(keyword['core'], keyword['quotient'])
     301    elif 'exp' in keyword and len(keyword)==1:
     302        return from_exp(keyword['exp'])
    294303    elif 'frobenius_coordinates' in keyword and len(keyword)==1:
    295304        return from_frobenius_coordinates(keyword['frobenius_coordinates'])
    296     elif 'exp' in keyword and len(keyword)==1:
    297         return from_exp(keyword['exp'])
    298     elif 'core' in keyword and 'quotient' in keyword and len(keyword)==2:
    299         return from_core_and_quotient(keyword['core'], keyword['quotient'])
    300     elif 'core' in keyword and 'canonical_quotient' in keyword and len(keyword)==2:
    301         raise NotImplementedError
    302     elif 'core_and_quotient' in keyword and len(keyword)==1:
    303         deprecation(5790, '"core_and_quotient=(*)" is deprecated. Use "core=[*], quotient=[*]" instead.')
    304         return from_core_and_quotient(*keyword['core_and_quotient'])
    305305    else:
    306306        raise ValueError, 'incorrect syntax for Partition()'
    307307
    def from_frobenius_coordinates(frobenius 
    316316
    317317    EXAMPLES::
    318318
    319         sage: Partition(frobenius_coordinates=([],[]))
     319        sage: Partition(frobenius_coordinates=([],[])) # indirect doctest
    320320        []
    321321        sage: Partition(frobenius_coordinates=([0],[0]))
    322322        [1]
    def from_frobenius_coordinates(frobenius 
    351351            raise ValueError, '%s is not a partition, the coordinates need to be strictly decreasing'%str(frobenius_coordinates)
    352352    return Partition(tmp)
    353353
     354def from_beta_numbers(beta):
     355    r"""
     356    Return the partition corresponding to a sequence of beta numbers.
     357
     358    A sequence of beta numbers is a strictly increasing sequence
     359    `0 \leq b_1 < \cdots < b_k` of non-negative integers. The corresponding
     360    partition `\mu = (\mu_k, \ldots, \mu_1)` is
     361    given by `\mu_i = [1,i) \setminus \{ b_1, \ldots, b_i \}`. This gives a
     362    bijection from the set of partitions with at most `k` non-zero parts to
     363    the set of strictly increasing sequences of non-negative integers of
     364    length `k`.
     365
     366    .. NOTE::
     367
     368       This function is for internal use only;
     369       use Partition(beta_numbers=*) instead.
     370
     371    EXAMPLES::
     372
     373        sage: Partition(beta_numbers=[0,1,2,4,5,8]) # indirect doctest
     374        [3, 1, 1]
     375        sage: Partition(beta_numbers=[0,2,3,6])
     376        [3, 1, 1]
     377    """
     378    beta.sort()  # put them into increasing order just in case
     379    offset=0
     380    while offset<len(beta)-1 and beta[offset]==offset:
     381        offset+=1
     382    beta=beta[offset:]
     383    mu=[beta[i]-offset-i for i in range(len(beta))]
     384    return Partition(reversed(mu))  # partition removes trailing zeros
     385
    354386def from_exp(exp):
    355387    """
    356388    Returns a partition from its list of multiplicities.
    def from_exp(exp): 
    362394
    363395    EXAMPLES::
    364396
    365         sage: Partition(exp=[1,2,1])
     397        sage: Partition(exp=[1,2,1])  # indirect doctest
    366398        [3, 2, 2, 1]
    367399    """
    368400    p = []
    def from_exp(exp): 
    372404
    373405def from_core_and_quotient(core, quotient):
    374406    """
    375     ** This function is being deprecated - use Partition(core=*, quotient=*) instead **
    376 
    377407    Returns a partition from its core and quotient.
    378408
    379409    Algorithm from mupad-combinat.
    def from_core_and_quotient(core, quotien 
    385415
    386416    EXAMPLES::
    387417
    388         sage: Partition(core=[2,1], quotient=[[2,1],[3],[1,1,1]])
     418        sage: Partition(core=[2,1], quotient=[[2,1],[3],[1,1,1]])   # indirect doctest
    389419        [11, 5, 5, 3, 2, 2, 2]
    390420
    391421    TESTS:
    def from_core_and_quotient(core, quotien 
    398428        ...       for n in range(10) for mu in Partitions(n))
    399429        True
    400430        sage: test2 = lambda core, mus: (
    401         ...       Partition(core=core, quotient=mus).core(len(mus)) == core
     431        ...       Partition(core=core, quotient=mus).core(mus.level()) == core
    402432        ...       and
    403         ...       Partition(core=core, quotient=mus).quotient(len(mus)) == mus)
    404         sage: all(test2(core,tuple(mus))  # long time (5s on sage.math, 2011)
     433        ...       Partition(core=core, quotient=mus).quotient(mus.level()) == mus)
     434        sage: all(test2(core,mus)  # long time (5s on sage.math, 2011)
    405435        ...       for k in range(1,10)
    406436        ...       for n_core in range(10-k)
    407437        ...       for core in Partitions(n_core)
    408438        ...       if core.core(k) == core
    409439        ...       for n_mus in range(10-k)
    410         ...       for mus in PartitionTuples(n_mus,k))
     440        ...       for mus in PartitionTuples(k,n_mus))
    411441        True
    412442    """
    413     length = len(quotient)
    414     k = length*max(len(q) for q in quotient) + len(core)
     443    from partition_tuple import PartitionTuple
     444    components=PartitionTuple(quotient).components()
     445    length = len(components)
     446    k = length*max(len(q) for q in components) + len(core)
    415447    # k needs to be large enough. this seems to me like the smallest it can be
    416448    v = [core[i]-i for i in range(len(core))] + [ -i for i in range(len(core),k) ]
    417449    w = [ filter(lambda x: (x-i) % length == 0, v) for i in range(1, length+1) ]
    418450    new_w = []
    419451    for i in range(length):
    420452        lw = len(w[i])
    421         lq = len(quotient[i])
     453        lq = len(components[i])
    422454        # k needs to be chosen so lw >= lq
    423         new_w += [ w[i][j] + length*quotient[i][j] for j in range(lq)]
     455        new_w += [ w[i][j] + length*components[i][j] for j in range(lq)]
    424456        new_w += [ w[i][j] for j in range(lq,lw)]
    425457    new_w.sort(reverse=True)
    426458    return Partition([new_w[i]+i for i in range(len(new_w))])
    427459
    428460class Partition_class(CombinatorialObject):
     461    r"""
     462    A partition `p` of a nonnegative integer `n` is a
     463    non-increasing list of positive integers (the *parts* of the
     464    partition) with total sum `n`.
     465
     466    A partition can be depicted by a diagram made of rows of cells,
     467    where the number of cells in the `i^{th}` row starting from
     468    the top is the `i^{th}` part of the partition.
     469
     470    The coordinate system related to a partition applies from the top
     471    to the bottom and from left to right. So, the corners of the
     472    partition `[5, 3, 1]` are `[[0,4], [1,2], [2,0]]`.
     473
     474    EXAMPLES::
     475
     476        sage: mu=Partition([3,2,1,1,1] ); mu
     477        [3, 2, 1, 1, 1]
     478        sage: nu=Partition([3,2,1,1,1] ); mu
     479        [3, 2, 1, 1, 1]
     480        sage: mu == nu
     481        True
     482        sage: mu is nu
     483        False
     484        sage: mu in Partitions()
     485        True
     486        sage: mu.parent()
     487        Partitions of the integer 8
     488        sage: mu.size()
     489        8
     490        sage: mu.category()
     491        Category of objects
     492        sage: mu.parent()
     493        Partitions of the integer 8
     494        sage: mu[0]
     495        3
     496        sage: mu[1]
     497        2
     498        sage: mu[2]
     499        1
     500        sage: mu.pp()
     501        ***
     502        **
     503        *
     504        *
     505        *
     506        sage: mu.removable_cells()
     507        [(0, 2), (1, 1), (4, 0)]
     508        sage: mu.down_list()
     509        [[2, 2, 1, 1, 1], [3, 1, 1, 1, 1], [3, 2, 1, 1]]
     510        sage: mu.addable_cells()
     511        [(0, 3), (1, 2), (2, 1), (5, 0)]
     512        sage: mu.up_list()
     513        [[4, 2, 1, 1, 1], [3, 3, 1, 1, 1], [3, 2, 2, 1, 1], [3, 2, 1, 1, 1, 1]]
     514        sage: mu.conjugate()
     515        [5, 2, 1]
     516        sage: mu.dominates(nu)
     517        True
     518        sage: nu.dominates(mu)
     519        True
     520
     521    """
     522
     523
     524    def _repr_(self, compact=False):
     525        r"""
     526        Partitions are represented as the underlying list. There is an optional
     527        ``compact`` argument which gives a more compact representation.
     528
     529        EXAMPLE::
     530
     531            sage: mu=Partition([7,7,7,3,3,2,1,1,1,1,1,1,1]); mu
     532            [7, 7, 7, 3, 3, 2, 1, 1, 1, 1, 1, 1, 1]
     533            sage: mu._repr_(compact=True)
     534            '7^3,3^2,2,1^7'
     535        """
     536        if compact:
     537            exp=self.to_exp()[::-1]  # reversed list of exponents
     538            M=max(self)
     539            return '%s' % ','.join('%s%s' % (M-m, '' if e==1 else '^%s'%e)
     540                                     for (m,e) in enumerate(exp) if e>0)
     541        else:
     542            return '[%s]' % ', '.join('%s'%m for m in self)
     543
     544
     545    def level(self):
     546        """
     547        Returns the level of ``self``, which is always 1.
     548
     549        This method exists only for compatibility with
     550        :class:`PartitionTuples`.
     551
     552        EXAMPLE::
     553
     554            sage: Partition([4,3,2]).level()
     555            1
     556        """
     557        return 1
     558
     559
     560    def components(self):
     561        """
     562        Return a list containing the shape of ``self``.
     563
     564        This method exists only for compatibility with
     565        :class:`PartitionTuples`.
     566
     567        EXAMPLE::
     568
     569            sage: Partition([3,2]).components()
     570            [[3, 2]]
     571        """
     572        return [ self ]
     573
     574
     575    def Young_subgroup(self):
     576        """
     577        Return the corresponding Young, or parabolic, subgroup of the symmetric
     578        group.
     579
     580        EXAMPLE::
     581
     582            sage: Partition([4,2]).Young_subgroup()
     583            Permutation Group with generators [(), (5,6), (3,4), (2,3), (1,2)]
     584        """
     585        gens=[]
     586        m=0
     587        for row in self:
     588            gens.extend([ (c,c+1) for c in range(m+1,m+row)])
     589            m+=row
     590        gens.append( range(1,self.size()+1) )  # to ensure we get a subgroup of Sym_n
     591        return PermutationGroup( gens )
     592
     593
     594    def Young_subgroup_generators(self):
     595        """
     596        Return an indexing set for the generators of the corresponding Young
     597        subgroup.
     598
     599        EXAMPLE::
     600
     601            sage: Partition([4,2]).Young_subgroup_generators()
     602            [1, 2, 3, 5]
     603        """
     604        gens=[]
     605        m=0
     606        for row in self:
     607            gens.extend([c for c in range(m+1,m+row)])
     608            m+=row
     609        return gens
     610
    429611
    430612    def _latex_(self):
    431613        r"""
    432         Returns a LaTeX version of self.
     614        Returns a LaTeX version of ``self``.
    433615
    434616        EXAMPLES::
    435617
    436             sage: latex(Partition([2, 1]))
     618            sage: latex(Partition([2, 1]))       # indirect doctest
    437619            {\def\lr#1{\multicolumn{1}{|@{\hspace{.6ex}}c@{\hspace{.6ex}}|}{\raisebox{-.3ex}{$#1$}}}
    438620            \raisebox{-.6ex}{$\begin{array}[b]{cc}
    439621            \cline{1-1}\cline{2-2}
    class Partition_class(CombinatorialObjec 
    446628        """
    447629        if len(self._list) == 0:
    448630            return "{\\emptyset}"
    449        
     631
    450632        from sage.combinat.output import tex_from_array
    451633        return tex_from_array([ ["\\phantom{x}"]*row_size for row_size in self._list ])
    452    
     634
    453635    def ferrers_diagram(self):
    454         """
    455         Return the Ferrers diagram of pi.
    456 
    457         INPUT:
    458 
    459         -  ``pi`` - a partition, given as a list of integers.
    460 
     636        r"""
     637        Return the Ferrers diagram of ``self``.
    461638
    462639        EXAMPLES::
    463640
    class Partition_class(CombinatorialObjec 
    506683        return sage.combinat.skew_partition.SkewPartition([self[:], p])
    507684
    508685    def power(self, k):
    509         """
     686        r"""
    510687        Returns the cycle type of the `k`-th power of any permutation
    511688        with cycle type ``self`` (thus describes the powermap of
    512689        symmetric groups).
    513        
     690
    514691        Wraps GAP's PowerPartition.
    515        
     692
    516693        EXAMPLES::
    517        
     694
    518695            sage: p = Partition([5,3])
    519696            sage: p.power(1)
    520697            [5, 3]
    class Partition_class(CombinatorialObjec 
    526703            [5, 3]
    527704            sage: Partition([3,2,1]).power(3)
    528705            [2, 1, 1, 1, 1]
    529        
     706
    530707        Now let us compare this to the power map on `S_8`::
    531        
     708
    532709            sage: G = SymmetricGroup(8)
    533710            sage: g = G([(1,2,3,4,5),(6,7,8)])
    534711            sage: g
    class Partition_class(CombinatorialObjec 
    546723            res.extend( [ZZ(i//g)]*int(g) )
    547724        res.sort(reverse=True)
    548725        return Partition_class( res )
    549        
     726
    550727    def next(self):
    551728        """
    552729        Returns the partition that lexicographically follows the partition
    553730        p. If p is the last partition, then it returns False.
    554        
     731
    555732        EXAMPLES::
    556        
     733
    557734            sage: Partition([4]).next()
    558735            [3, 1]
    559736            sage: Partition([1,1,1,1]).next()
    class Partition_class(CombinatorialObjec 
    565742        for i in p:
    566743            n += i
    567744            m += 1
    568        
     745
    569746        next_p = p[:] + [1]*(n - len(p))
    570747
    571748        #Check to see if we are at the last (all ones) partition
    class Partition_class(CombinatorialObjec 
    578755
    579756        #Let h be the number of non-one  entries in the
    580757        #partition
    581         h = 0 
     758        h = 0
    582759        for i in next_p:
    583760            if i != 1:
    584761                h += 1
    class Partition_class(CombinatorialObjec 
    606783                    next_p[h-1] = t
    607784
    608785        return Partition_class(next_p[:m])
    609      
     786
    610787    def size(self):
    611788        """
    612789        Returns the size of partition p.
    613        
     790
    614791        EXAMPLES::
    615        
     792
    616793            sage: Partition([2,2]).size()
    617794            4
    618795            sage: Partition([3,2,1]).size()
    class Partition_class(CombinatorialObjec 
    623800    def sign(self):
    624801        r"""
    625802        Returns the sign of any permutation with cycle type ``self``.
    626        
     803
    627804        This function corresponds to a homomorphism from the symmetric
    628805        group `S_n` into the cyclic group of order 2, whose kernel
    629806        is exactly the alternating group `A_n`. Partitions of sign
    630807        `1` are called even partitions while partitions of sign
    631808        `-1` are called odd.
    632        
     809
    633810        EXAMPLES::
    634        
     811
    635812            sage: Partition([5,3]).sign()
    636813            1
    637814            sage: Partition([5,2]).sign()
    638815            -1
    639        
     816
    640817        Zolotarev's lemma states that the Legendre symbol
    641818        `\left(\frac{a}{p}\right)` for an integer
    642819        `a \pmod p` (`p` a prime number), can be computed
    class Partition_class(CombinatorialObjec 
    644821        p_a the permutation of the residue classes `\pmod p`
    645822        induced by modular multiplication by `a`, provided
    646823        `p` does not divide `a`.
    647        
     824
    648825        We verify this in some examples.
    649        
     826
    650827        ::
    651        
     828
    652829            sage: F = GF(11)
    653830            sage: a = F.multiplicative_generator();a
    654831            2
    655832            sage: plist = [int(a*F(x)) for x in range(1,11)]; plist
    656833            [2, 4, 6, 8, 10, 1, 3, 5, 7, 9]
    657        
     834
    658835        This corresponds to the permutation (1, 2, 4, 8, 5, 10, 9, 7, 3, 6)
    659836        (acting the set `\{1,2,...,10\}`) and to the partition
    660837        [10].
    661        
     838
    662839        ::
    663        
     840
    664841            sage: p = PermutationGroupElement('(1, 2, 4, 8, 5, 10, 9, 7, 3, 6)')
    665842            sage: p.sign()
    666843            -1
    class Partition_class(CombinatorialObjec 
    668845            -1
    669846            sage: kronecker_symbol(11,2)
    670847            -1
    671        
     848
    672849        Now replace `2` by `3`::
    673        
     850
    674851            sage: plist = [int(F(3*x)) for x in range(1,11)]; plist
    675852            [3, 6, 9, 1, 4, 7, 10, 2, 5, 8]
    676853            sage: range(1,11)
    class Partition_class(CombinatorialObjec 
    682859            1
    683860            sage: Partition([5,1,1,1,1,1]).sign()
    684861            1
    685        
     862
    686863        In both cases, Zolotarev holds.
    687        
     864
    688865        REFERENCES:
    689866
    690867        - http://en.wikipedia.org/wiki/Zolotarev's_lemma
    class Partition_class(CombinatorialObjec 
    695872        r"""
    696873        Returns a generator for partitions that can be obtained from pi by
    697874        adding a cell.
    698        
     875
    699876        EXAMPLES::
    700        
     877
    701878            sage: [p for p in Partition([2,1,1]).up()]
    702879            [[3, 1, 1], [2, 2, 1], [2, 1, 1, 1]]
    703880            sage: [p for p in Partition([3,2]).up()]
    class Partition_class(CombinatorialObjec 
    718895        """
    719896        Returns a list of the partitions that can be formed from the
    720897        partition `p` by adding a cell.
    721        
     898
    722899        EXAMPLES::
    723        
     900
    724901            sage: Partition([2,1,1]).up_list()
    725902            [[3, 1, 1], [2, 2, 1], [2, 1, 1, 1]]
    726903            sage: Partition([3,2]).up_list()
    class Partition_class(CombinatorialObjec 
    734911        r"""
    735912        Returns a generator for partitions that can be obtained from p by
    736913        removing a cell.
    737        
     914
    738915        EXAMPLES::
    739        
     916
    740917            sage: [p for p in Partition([2,1,1]).down()]
    741918            [[1, 1, 1], [2, 1]]
    742919            sage: [p for p in Partition([3,2]).down()]
    743920            [[2, 2], [3, 1]]
    744921            sage: [p for p in Partition([3,2,1]).down()]
    745922            [[2, 2, 1], [3, 1, 1], [3, 2]]
    746            
     923
    747924        TESTS: We check that #11435 is actually fixed::
    748            
     925
    749926            sage: Partition([]).down_list() #indirect doctest
    750927            []
    751928        """
    class Partition_class(CombinatorialObjec 
    766943        """
    767944        Returns a list of the partitions that can be obtained from the
    768945        partition p by removing a cell.
    769        
     946
    770947        EXAMPLES::
    771        
     948
    772949            sage: Partition([2,1,1]).down_list()
    773950            [[1, 1, 1], [2, 1]]
    774951            sage: Partition([3,2]).down_list()
    775952            [[2, 2], [3, 1]]
    776953            sage: Partition([3,2,1]).down_list()
    777954            [[2, 2, 1], [3, 1, 1], [3, 2]]
    778             sage: Partition([]).down_list()  #checks trac #11435
     955            sage: Partition([]).down_list()  #checks :trac:`11435`
    779956            []
    780957        """
    781958        return [p for p in self.down()]
    782959
    783960    def frobenius_coordinates(self):
    784         """ Returns a couple of sequences of beta numbers aka Frobenius coordinates of the partition.
    785         These are two striclty decreasing sequences of nonnegative integers, of the same length.
     961        """
     962        Returns a pair of sequences of Frobenius coordinates aka beta numbers
     963        of the partition.
     964
     965        These are two strictly decreasing sequences of nonnegative integers
     966        of the same length.
    786967
    787968        EXAMPLES::
     969
    788970            sage: Partition([]).frobenius_coordinates()
    789971            ([], [])
    790972            sage: Partition([1]).frobenius_coordinates()
    class Partition_class(CombinatorialObjec 
    805987            a = filter(lambda x: x>=0, [mu[i]-i-1 for i in range(len(b))])
    806988        return (a,b)
    807989
    808     beta_numbers = frobenius_coordinates
    809 
    810990    def frobenius_rank(self):
    811991        """ Returns the Frobenius rank of the partition, which is the number of cells on the main diagonal.
    812992
    813993        EXAMPLES::
     994
    814995            sage: Partition([]).frobenius_rank()
    815996            0
    816997            sage: Partition([1]).frobenius_rank()
    class Partition_class(CombinatorialObjec 
    8341015            return len(filter(lambda x: x>=0, [val-i-1 for i, val in enumerate(muconj)]))
    8351016
    8361017
     1018    def beta_numbers(self, length=None):
     1019        """
     1020        Return the set of beta numbers corresponding to ``self``.
     1021
     1022        The optional argument ``length`` specifies the length of the beta set
     1023        (which must be at least the length of ``self``).
     1024
     1025        For more on beta numbers, see :meth:`frobenius_coordinates`.
     1026
     1027        EXAMPLES::
     1028
     1029            sage: Partition([4,3,2]).beta_numbers()
     1030            [6, 4, 2]
     1031            sage: Partition([4,3,2]).beta_numbers(5)
     1032            [8, 6, 4, 1, 0]
     1033
     1034        """
     1035        if length==None: length=self.length()
     1036        elif length<self.length():
     1037            raise ValueError, "length must at least the length of the partition"
     1038        beta=[self.hook_lengths()[row][0]+length-self.length() for row in range(self.length())]
     1039        if length>self.length(): beta.extend( range(length-self.length()-1,-1,-1) )
     1040        return beta
     1041
     1042
    8371043    def dominates(self, p2):
    8381044        r"""
    8391045        Returns True if partition p1 dominates partitions p2. Otherwise, it
    8401046        returns False.
    841        
     1047
    8421048        EXAMPLES::
    843        
     1049
    8441050            sage: p = Partition([3,2])
    8451051            sage: p.dominates([3,1])
    8461052            True
    class Partition_class(CombinatorialObjec 
    8671073        min_length = min(len(p1), len(p2))
    8681074        if min_length == 0:
    8691075            return len(p1) >= len(p2)
    870        
     1076
    8711077        for i in range(min_length):
    8721078            sum1 += p1[i]
    8731079            sum2 += p2[i]
    class Partition_class(CombinatorialObjec 
    8791085        """
    8801086        Return the coordinates of the cells of self. Coordinates are given
    8811087        as (row-index, column-index) and are 0 based.
    882        
     1088
    8831089        EXAMPLES::
    884        
     1090
    8851091            sage: Partition([2,2]).cells()
    8861092            [(0, 0), (0, 1), (1, 0), (1, 1)]
    8871093            sage: Partition([3,2]).cells()
    class Partition_class(CombinatorialObjec 
    8931099                res.append( (i,j) )
    8941100        return res
    8951101
    896 
    897     boxes = deprecated_function_alias(7515, cells)
    898 
    8991102    def generalized_pochhammer_symbol(self, a, alpha):
    9001103        r"""
    9011104        Returns the generalized Pochhammer symbol
    9021105        `(a)_{self}^{(\alpha)}`. This is the product over all
    9031106        cells (i,j) in p of `a - (i-1) / \alpha + j - 1`.
    904        
     1107
    9051108        EXAMPLES::
    906        
     1109
    9071110            sage: Partition([2,2]).generalized_pochhammer_symbol(2,1)
    9081111            12
    9091112        """
    class Partition_class(CombinatorialObjec 
    9811184        perm = permutation.Permutation(word)
    9821185        return perm.robinson_schensted()[1]
    9831186
    984     associated = deprecated_function_alias(6655, conjugate)
    985 
    9861187    def arm_length(self, i, j):
    987         """
     1188        r"""
    9881189        Returns the length of the arm of cell (i,j) in partition p.
    9891190
    9901191        INPUT: ``i`` and ``j``: two integers
    9911192
    992         OUPUT: an integer or a ValueError
     1193        OUTPUT: An integer or a ValueError
    9931194
    9941195        The arm of cell (i,j) is the cells that appear to the right of cell
    9951196        (i,j). Note that i and j are 0-based indices. If your coordinates are
    class Partition_class(CombinatorialObjec 
    10131214        if i < len(p) and j < p[i]:
    10141215            return p[i]-(j+1)
    10151216        else:
    1016             raise ValueError, "The cells is not in the diagram"
    1017 
    1018     arm = deprecated_function_alias(6655, arm_length)
     1217            raise ValueError, "The cell is not in the diagram"
    10191218
    10201219    def arm_lengths(self, flat=False):
    10211220        """
    class Partition_class(CombinatorialObjec 
    10531252        (i,j). Note that i and j are 0-based indices. If your coordinates are
    10541253        in the form (i,j), use Python's \*-operator.
    10551254
    1056         Examples::
     1255        EXAMPLES::
    10571256
    10581257            sage: Partition([4,4,3,1]).arm_cells(1,1)
    10591258            [(1, 2), (1, 3)]
    class Partition_class(CombinatorialObjec 
    10611260            sage: Partition([]).arm_cells(0,0)
    10621261            Traceback (most recent call last):
    10631262            ...
    1064             ValueError: The cells is not in the diagram
     1263            ValueError: The cell is not in the diagram
    10651264
    10661265        """
    10671266        p = self
    10681267        if i < len(p) and j < p[i]:
    10691268            return [ (i, x) for x in range(j+1, p[i]) ]
    10701269        else:
    1071             raise ValueError, "The cells is not in the diagram"
     1270            raise ValueError, "The cell is not in the diagram"
    10721271
    10731272    def leg_length(self, i, j):
    10741273        """
    class Partition_class(CombinatorialObjec 
    10761275
    10771276        INPUT: ``i`` and ``j``: two integers
    10781277
    1079         OUPUT: an integer or a ValueError
     1278        OUTPUT: an integer or a ValueError
    10801279
    10811280        The leg of cell (i,j) is defined to be the cells below it in partition
    10821281        p (in English convention). Note that i and j are 0-based. If your
    class Partition_class(CombinatorialObjec 
    11011300        if j < len(conj) and i < conj[j]:
    11021301            return conj[j]-(i+1)
    11031302        else:
    1104             raise ValueError, "The cells is not in the diagram"
    1105 
    1106     leg = deprecated_function_alias(6655, leg_length)
     1303            raise ValueError, "The cell is not in the diagram"
    11071304
    11081305    def leg_lengths(self, flat=False):
    11091306        """
    class Partition_class(CombinatorialObjec 
    11421339        p (in English convention). Note that i and j are 0-based. If your
    11431340        coordinates are in the form (i,j), use Python's \*-operator.
    11441341
    1145         Examples::
     1342        EXAMPLES::
    11461343
    11471344            sage: Partition([4,4,3,1]).leg_cells(1,1)
    11481345            [(2, 1)]
    class Partition_class(CombinatorialObjec 
    11521349            sage: Partition([]).leg_cells(0,0)
    11531350            Traceback (most recent call last):
    11541351            ...
    1155             ValueError: The cells is not in the diagram
     1352            ValueError: The cell is not in the diagram
    11561353        """
    11571354        l = self.leg_length(i, j)
    11581355        return [(x, j) for x in range(i+1, i+l+1)]
    class Partition_class(CombinatorialObjec 
    11611358        """
    11621359        Returns a list of the partitions dominated by n. If n is specified,
    11631360        then it only returns the ones with = rows rows.
    1164        
     1361
    11651362        EXAMPLES::
    1166        
     1363
    11671364            sage: Partition([3,2,1]).dominate()
    11681365            [[3, 2, 1], [3, 1, 1, 1], [2, 2, 2], [2, 2, 1, 1], [2, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1]]
    11691366            sage: Partition([3,2,1]).dominate(rows=3)
    class Partition_class(CombinatorialObjec 
    11801377        """
    11811378        Returns True if p2 is a partition whose Ferrers diagram is
    11821379        contained in the Ferrers diagram of self
    1183        
     1380
    11841381        EXAMPLES::
    1185        
     1382
    11861383            sage: p = Partition([3,2,1])
    11871384            sage: p.contains([2,1])
    11881385            True
    class Partition_class(CombinatorialObjec 
    11921389            False
    11931390        """
    11941391        return len(self) >= len(x) and all(self[i] >= x[i] for i in range(len(x)))
    1195        
     1392
    11961393    def hook_product(self, a):
    11971394        """
    11981395        Returns the Jack hook-product.
    1199        
     1396
    12001397        EXAMPLES::
    1201        
     1398
    12021399            sage: Partition([3,2,1]).hook_product(x)
    12031400            (x + 2)^2*(2*x + 3)
    12041401            sage: Partition([2,2]).hook_product(x)
    12051402            2*(x + 1)*(x + 2)
    12061403        """
    1207        
     1404
    12081405        nu = self.conjugate()
    12091406        res = 1
    12101407        for i in range(len(self)):
    class Partition_class(CombinatorialObjec 
    12151412    def hook_polynomial(self, q, t):
    12161413        """
    12171414        Returns the two-variable hook polynomial.
    1218        
     1415
    12191416        EXAMPLES::
    1220        
     1417
    12211418            sage: R.<q,t> = PolynomialRing(QQ)
    12221419            sage: a = Partition([2,2]).hook_polynomial(q,t)
    12231420            sage: a == (1 - t)*(1 - q*t)*(1 - t^2)*(1 - q*t^2)
    class Partition_class(CombinatorialObjec 
    12401437        hook of cell (i,j) is defined as the cells to the right or below (in
    12411438        the English convention). Note that i and j are 0-based. If your
    12421439        coordinates are in the form (i,j), use Python's \*-operator.
    1243        
     1440
    12441441        EXAMPLES::
    1245        
     1442
    12461443            sage: p = Partition([2,2,1])
    12471444            sage: p.hook_length(0, 0)
    12481445            4
    12491446            sage: p.hook_length(0, 1)
    12501447            2
    12511448            sage: p.hook_length(2, 0)
    1252             1       
     1449            1
    12531450            sage: Partition([3,3]).hook_length(0, 0)
    1254             4       
     1451            4
    12551452            sage: cell = [0,0]; Partition([3,3]).hook_length(*cell)
    12561453            4
    12571454        """
    12581455        return self.leg_length(i,j)+self.arm_length(i,j)+1
    12591456
    1260     hook = deprecated_function_alias(7515, hook_length)
    1261 
    12621457    def hooks(self):
    12631458        """
    12641459        Returns a sorted list of the hook lengths in self.
    class Partition_class(CombinatorialObjec 
    12731468            res += row
    12741469        res.sort(reverse=True)
    12751470        return res
    1276        
     1471
     1472
    12771473    def hook_lengths(self):
    12781474        r"""
    12791475        Returns a tableau of shape p with the cells filled in with the
    12801476        hook lengths.
    1281        
     1477
    12821478        In each cell, put the sum of one plus the number of cells
    12831479        horizontally to the right and vertically below the cell (the
    12841480        hook length).
    1285        
     1481
    12861482        For example, consider the partition [3,2,1] of 6 with Ferrers
    12871483        Diagram::
    12881484
    class Partition_class(CombinatorialObjec 
    12951491            5 3 1
    12961492            3 1
    12971493            1
    1298        
     1494
    12991495        EXAMPLES::
    1300        
     1496
    13011497            sage: Partition([2,2,1]).hook_lengths()
    13021498            [[4, 2], [3, 1], [1]]
    13031499            sage: Partition([3,3]).hook_lengths()
    class Partition_class(CombinatorialObjec 
    13081504            [[3, 2], [2, 1]]
    13091505            sage: Partition([5]).hook_lengths()
    13101506            [[5, 4, 3, 2, 1]]
    1311        
     1507
    13121508        REFERENCES:
    13131509
    13141510        - http://mathworld.wolfram.com/HookLengthFormula.html
    class Partition_class(CombinatorialObjec 
    13221518        Returns the upper hook length of the cell (i,j) in self. When alpha
    13231519        == 1, this is just the normal hook length. As usual, indices are 0
    13241520        based.
    1325        
     1521
    13261522        The upper hook length of a cell (i,j) in a partition
    13271523        `\kappa` is defined by
    1328        
     1524
    13291525        .. math::
    1330        
     1526
    13311527             h_*^\kappa(i,j) = \kappa_j^\prime-i+\alpha(\kappa_i - j+1).
    1332        
    1333        
    1334        
     1528
     1529
     1530
    13351531        EXAMPLES::
    1336        
     1532
    13371533            sage: p = Partition([2,1])
    13381534            sage: p.upper_hook(0,0,1)
    13391535            3
    class Partition_class(CombinatorialObjec 
    13501546        r"""
    13511547        Returns the upper hook lengths of the partition. When alpha == 1,
    13521548        these are just the normal hook lengths.
    1353        
     1549
    13541550        The upper hook length of a cell (i,j) in a partition
    13551551        `\kappa` is defined by
    1356        
     1552
    13571553        .. math::
    1358        
     1554
    13591555             h_*^\kappa(i,j) = \kappa_j^\prime-i+1+\alpha(\kappa_i - j).
    1360        
    1361        
    1362        
     1556
     1557
     1558
    13631559        EXAMPLES::
    1364        
     1560
    13651561            sage: Partition([3,2,1]).upper_hook_lengths(x)
    13661562            [[3*x + 2, 2*x + 1, x], [2*x + 1, x], [x]]
    13671563            sage: Partition([3,2,1]).upper_hook_lengths(1)
    class Partition_class(CombinatorialObjec 
    13771573        r"""
    13781574        Returns the lower hook length of the cell (i,j) in self. When alpha
    13791575        == 1, this is just the normal hook length. Indices are 0-based.
    1380        
     1576
    13811577        The lower hook length of a cell (i,j) in a partition
    13821578        `\kappa` is defined by
    1383        
     1579
    13841580        .. math::
    1385        
     1581
    13861582             h_*^\kappa(i,j) = \kappa_j^\prime-i+1+\alpha(\kappa_i - j).
    1387        
    1388        
    1389        
     1583
     1584
     1585
    13901586        EXAMPLES::
    1391        
     1587
    13921588            sage: p = Partition([2,1])
    13931589            sage: p.lower_hook(0,0,1)
    13941590            3
    class Partition_class(CombinatorialObjec 
    14061602        r"""
    14071603        Returns the lower hook lengths of the partition. When alpha == 1,
    14081604        these are just the normal hook lengths.
    1409        
     1605
    14101606        The lower hook length of a cell (i,j) in a partition
    14111607        `\kappa` is defined by
    1412        
     1608
    14131609        .. math::
    1414        
     1610
    14151611             h_\kappa^*(i,j) = \kappa_j^\prime-i+\alpha(\kappa_i - j + 1).
    1416        
    1417        
    1418        
     1612
     1613
     1614
    14191615        EXAMPLES::
    1420        
     1616
    14211617            sage: Partition([3,2,1]).lower_hook_lengths(x)
    14221618            [[2*x + 3, x + 2, 1], [x + 2, 1], [1]]
    14231619            sage: Partition([3,2,1]).lower_hook_lengths(1)
    class Partition_class(CombinatorialObjec 
    14351631        Returns sum([i\*p[i] for i in range(len(p))]). It is also the
    14361632        sum of the leg length of every cell in b, or the sum of
    14371633        binomial(s[i],2) for s the conjugate partition of p.
    1438        
     1634
    14391635        EXAMPLES::
    1440        
     1636
    14411637            sage: Partition([2,2]).weighted_size()
    14421638            2
    14431639            sage: Partition([3,3,3]).weighted_size()
    class Partition_class(CombinatorialObjec 
    14521648    def length(self):
    14531649        """
    14541650        Returns the number of parts in self.
    1455        
     1651
    14561652        EXAMPLES::
    1457        
     1653
    14581654            sage: Partition([3,2]).length()
    14591655            2
    14601656            sage: Partition([2,2,1]).length()
    class Partition_class(CombinatorialObjec 
    14691665        Return a list of the multiplicities of the parts of a partition.
    14701666        Use the optional parameter k to get a return list of length at
    14711667        least k.
    1472        
     1668
    14731669        EXAMPLES::
    1474        
     1670
    14751671            sage: Partition([3,2,2,1]).to_exp()
    14761672            [1, 2, 1]
    14771673            sage: Partition([3,2,2,1]).to_exp(5)
    class Partition_class(CombinatorialObjec 
    14881684    def evaluation(self):
    14891685        """
    14901686        Returns the evaluation of the partition.
    1491        
     1687
    14921688        EXAMPLES::
    1493        
     1689
    14941690            sage: Partition([4,3,1,1]).evaluation()
    14951691            [2, 0, 1, 1]
    14961692        """
    class Partition_class(CombinatorialObjec 
    15311727
    15321728        Including the optional
    15331729        parameters `t` and `q` gives the `q`-`t` analog which is the former product
    1534         times 
     1730        times
    15351731
    15361732        .. math::
    15371733
    15381734           \prod_{i=1}^{\mathrm{length}(p)} \frac{1 - q^{p_i}}{1 - t^{p_i}}.
    1539        
     1735
    15401736        EXAMPLES::
    1541        
     1737
    15421738            sage: Partition([2,2,1]).centralizer_size()
    15431739            8
    15441740            sage: Partition([2,2,2]).centralizer_size()
    1545             48 
    1546        
     1741            48
     1742
    15471743        REFERENCES:
    15481744
    15491745        - Kerber, A. 'Algebraic Combinatorics via Finite Group Action',
    class Partition_class(CombinatorialObjec 
    15611757        Returns a factor for the number of permutations with cycle type
    15621758        ``self``. self.aut() returns
    15631759        `1^{j_1}j_1! \cdots n^{j_n}j_n!` where `j_k`
    1564         is the number of parts in self equal to k.
    1565        
     1760        is the number of parts in self equal to `k`.
     1761
    15661762        The number of permutations having `p` as a cycle type is
    15671763        given by
    1568        
     1764
    15691765        .. math::
    1570        
     1766
    15711767             \frac{n!}{1^{j_1}j_1! \cdots n^{j_n}j_n!} .
    1572        
     1768
    15731769        EXAMPLES::
    1574        
     1770
    15751771            sage: Partition([2,1]).aut()
    15761772            2
    15771773        """
    15781774        m = self.to_exp()
    15791775        return prod([(i+1)**m[i]*factorial(m[i]) for i in range(len(m)) if m[i] > 0])
    15801776
    1581     def content(self, i, j):
     1777    def content(self, r, c, multicharge=[0]):
    15821778        r"""
    1583         Returns the content statistic of the given cell, which is simply
    1584         defined by j - i. This doesn't technically depend on the partition,
    1585         but is included here because it is often useful in the context of
    1586         partitions.
    1587        
     1779        Returns the content of the cell at row `r` and column `c`.
     1780
     1781        The content of a cell is `c - r`.
     1782
     1783        For consistency with partition tuples there is also an optional
     1784        ``multicharge`` argument which is an offset to the usual content. By
     1785        setting the ``multicharge`` equal to the 0-element the ring `\ZZ/e\ZZ`
     1786        the corresponding `e`-residue will be returned. This is the content
     1787        modulo `e`.
     1788
     1789        The content (and residue) do not strictly depend on the partition,
     1790        however, this method is included because it is often useful in the
     1791        context of partitions.
     1792
    15881793        EXAMPLES::
    1589        
    1590             sage: Partition([2,1]).content(0,1)
    1591             1
     1794
     1795            sage: Partition([2,1]).content(1,0)
     1796            -1
    15921797            sage: p = Partition([3,2])
    15931798            sage: sum([p.content(*c) for c in p.cells()])
    15941799            2
    1595         """
    1596 
    1597         return j - i
     1800
     1801        and now we return the 3-residue of a cell::
     1802
     1803            sage: Partition([2,1]).content(1,0, multicharge=[IntegerModRing(3)(0)])
     1804            2
     1805        """
     1806        return c - r + multicharge[0]
    15981807
    15991808    def conjugacy_class_size(self):
    16001809        """
    16011810        Returns the size of the conjugacy class of the symmetric group
    16021811        indexed by the partition p.
    1603        
     1812
    16041813        EXAMPLES::
    1605        
     1814
    16061815            sage: Partition([2,2,2]).conjugacy_class_size()
    16071816            15
    16081817            sage: Partition([2,2,1]).conjugacy_class_size()
    16091818            15
    1610             sage: Partition([2,1,1]).conjugacy_class_size() 
     1819            sage: Partition([2,1,1]).conjugacy_class_size()
    16111820            6
    1612        
     1821
    16131822        REFERENCES:
    16141823
    1615         - Kerber, A. 'Algebraic Combinatorics via Finite Group Action'
    1616           1.3 p24
    1617         """
    1618        
     1824        .. [Ker]  Kerber, A. 'Algebraic Combinatorics via Finite Group Action' 1.3 p24
     1825        """
     1826
    16191827        return factorial(sum(self))/self.centralizer_size()
    16201828
    1621 
    16221829    def corners(self):
    16231830        """
    16241831        Returns a list of the corners of the partitions. These are the
    1625         positions where we can remove a cell. Indices are of the form (i,j)
    1626         where i is the row-index and j is the column-index, and are
     1832        positions where we can remove a cell. Indices are of the form `(i,j)`
     1833        where `i` is the row-index and `j` is the column-index, and are
    16271834        0-based.
    16281835
    16291836        EXAMPLES::
    class Partition_class(CombinatorialObjec 
    16521859
    16531860        return map(tuple, lcors)
    16541861
     1862    removable_cells = corners            # for compatibility with partition tuples
    16551863
    16561864    def outside_corners(self):
    16571865        """
    16581866        Returns a list of the positions where we can add a cell so that the
    1659         shape is still a partition. Indices are of the form (i,j) where i
    1660         is the row-index and j is the column-index, and are 0-based.
     1867        shape is still a partition. Indices are of the form `(i,j)` where `i`
     1868        is the row-index and `j` is the column-index, and are 0-based.
    16611869
    16621870        EXAMPLES::
    16631871
    class Partition_class(CombinatorialObjec 
    16811889
    16821890        return res
    16831891
     1892    addable_cells=outside_corners        # for compatibility with partition tuples
     1893
     1894
    16841895    def rim(self):
    16851896        r"""
    16861897        Returns the rim of ``self``.
    class Partition_class(CombinatorialObjec 
    18052016        #Select the r-core
    18062017        return Partition_class(filter(lambda x: x != 0, part))
    18072018
    1808     r_core = deprecated_function_alias(11165, core)
    1809 
    18102019    def quotient(self, length):
    18112020        """
    18122021        Returns the quotient of the partition  -- in the literature the
    class Partition_class(CombinatorialObjec 
    18702079            a.reverse()
    18712080            result[e] = a
    18722081
    1873         return tuple(map(Partition_class, result))
    1874 
    1875     r_quotient = deprecated_function_alias(7515, quotient)
     2082        from partition_tuple import PartitionTuple
     2083        return PartitionTuple(result)  #tuple(map(Partition_class, result))
    18762084
    18772085    def is_core(self, k):
    18782086        r"""
    class Partition_class(CombinatorialObjec 
    19682176
    19692177        raise ValueError, "[%s, %s] is not an addable cell"%(i,j)
    19702178
    1971     add_box = deprecated_function_alias(7515, add_cell)
    19722179
    19732180    def remove_cell(self, i, j = None):
    19742181        """
    class Partition_class(CombinatorialObjec 
    20042211        else:
    20052212            return Partition(self[:i] + [ self[i:i+1][0] - 1 ] + self[i+1:])
    20062213
    2007     remove_box = deprecated_function_alias(7515, remove_cell)
    2008 
    20092214    def k_skew(self, k):
    20102215        r"""
    20112216        Returns the `k`-skew partition.
    2012        
     2217
    20132218        The `k`-skew diagram of a `k`-bounded partition is the skew diagram
    2014         denoted `\lambda/^k` satisfying the conditions: 
    2015 
    2016         1. row i of `\lambda/^k` has length `\lambda_i` 
    2017 
    2018         2. no cell in `\lambda/^k` has hook-length exceeding k 
     2219        denoted `\lambda/^k` satisfying the conditions:
     2220
     2221        1. row i of `\lambda/^k` has length `\lambda_i`
     2222
     2223        2. no cell in `\lambda/^k` has hook-length exceeding k
    20192224
    20202225        3. every square above the diagram of `\lambda/^k` has hook
    20212226           length exceeding k.
    2022        
     2227
    20232228        REFERENCES:
    20242229
    20252230        - Lapointe, L. and Morse, J. 'Order Ideals in Weak Subposets
    20262231          of Young's Lattice and Associated Unimodality Conjectures'
    2027        
     2232
    20282233        EXAMPLES::
    2029        
     2234
    20302235            sage: p = Partition([4,3,2,2,1,1])
    20312236            sage: p.k_skew(4)
    20322237            [[9, 5, 3, 2, 1, 1], [5, 2, 1]]
    class Partition_class(CombinatorialObjec 
    20412246        #Find the k-skew diagram of the partition formed
    20422247        #by removing the first row
    20432248        s = Partition(self[1:]).k_skew(k)
    2044        
     2249
    20452250        s_inner = s.inner()
    20462251        s_outer = s.outer()
    20472252        s_conj_rl = s.conjugate().row_lengths()
    2048        
     2253
    20492254        #Find the leftmost column with less than
    20502255        # or equal to kdiff cells
    20512256        kdiff = k - self[0]
    2052        
     2257
    20532258        if s_outer == []:
    20542259            spot = 0
    20552260        else:
    class Partition_class(CombinatorialObjec 
    20712276    def to_core(self, k):
    20722277        r"""
    20732278        Maps the `k`-bounded partition ``self`` to its corresponding `k+1`-core.
    2074        
     2279
    20752280        See also :meth:`k_skew`.
    20762281
    20772282        EXAMPLES::
    2078        
     2283
    20792284            sage: p = Partition([4,3,2,2,1,1])
    20802285            sage: c = p.to_core(4); c
    20812286            [9, 5, 3, 2, 1, 1]
    class Partition_class(CombinatorialObjec 
    21562361    def to_list(self):
    21572362        r"""
    21582363        Return self as a list.
    2159        
     2364
    21602365        EXAMPLES::
    2161        
     2366
    21622367            sage: p = Partition([2,1]).to_list(); p
    21632368            [2, 1]
    21642369            sage: type(p)
    21652370            <type 'list'>
    2166        
     2371
    21672372        TESTS::
    2168        
     2373
    21692374            sage: p = Partition([2,1])
    21702375            sage: pl = p.to_list()
    21712376            sage: pl[0] = 0; p
    class Partition_class(CombinatorialObjec 
    21772382        """
    21782383        Returns a list of all the partitions that can be obtained by adding
    21792384        a vertical border strip of length k to self.
    2180        
     2385
    21812386        EXAMPLES::
    2182        
     2387
    21832388            sage: Partition([]).add_vertical_border_strip(0)
    21842389            [[]]
    21852390            sage: Partition([]).add_vertical_border_strip(2)
    class Partition_class(CombinatorialObjec 
    21952400        """
    21962401        Returns a list of all the partitions that can be obtained by adding
    21972402        a horizontal border strip of length k to self.
    2198        
     2403
    21992404        EXAMPLES::
    2200        
     2405
    22012406            sage: Partition([]).add_horizontal_border_strip(0)
    22022407            [[]]
    22032408            sage: Partition([]).add_horizontal_border_strip(2)
    class Partition_class(CombinatorialObjec 
    22072412            sage: Partition([3,2,2]).add_horizontal_border_strip(2)
    22082413            [[3, 2, 2, 2], [3, 3, 2, 1], [4, 2, 2, 1], [4, 3, 2], [5, 2, 2]]
    22092414
    2210         TODO: reimplement like remove_horizontal_border_strip using IntegerListsLex
     2415        .. TODO::
     2416
     2417            reimplement like remove_horizontal_border_strip using IntegerListsLex
    22112418        """
    22122419        conj = self.conjugate().to_list()
    22132420        shelf = []
    class Partition_class(CombinatorialObjec 
    22482455        horizontal border strip of length k
    22492456
    22502457        EXAMPLES::
    2251        
     2458
    22522459            sage: Partition([5,3,1]).remove_horizontal_border_strip(0).list()
    2253             [[5, 3, 1]] 
     2460            [[5, 3, 1]]
    22542461            sage: Partition([5,3,1]).remove_horizontal_border_strip(1).list()
    22552462            [[5, 3], [5, 2, 1], [4, 3, 1]]
    22562463            sage: Partition([5,3,1]).remove_horizontal_border_strip(2).list()
    class Partition_class(CombinatorialObjec 
    22652472            []
    22662473
    22672474        The result is returned as a combinatorial class::
    2268        
     2475
    22692476            sage: Partition([5,3,1]).remove_horizontal_border_strip(5)
    22702477            The subpartitions of [5, 3, 1] obtained by removing an horizontal border strip of length 5
    2271            
     2478
    22722479        TESTS::
    2273        
     2480
    22742481            sage: Partition([3,2,2]).remove_horizontal_border_strip(2).list()
    22752482            [[3, 2], [2, 2, 1]]
    22762483            sage: Partition([3,2,2]).remove_horizontal_border_strip(2).first().parent()
    class Partition_class(CombinatorialObjec 
    22922499    def k_conjugate(self, k):
    22932500        """
    22942501        Returns the k-conjugate of the partition.
    2295        
     2502
    22962503        The k-conjugate is the partition that is given by the columns of
    22972504        the k-skew diagram of the partition.
    2298        
     2505
    22992506        EXAMPLES::
    2300        
     2507
    23012508            sage: p = Partition([4,3,2,2,1,1])
    23022509            sage: p.k_conjugate(4)
    23032510            [3, 2, 2, 1, 1, 1, 1, 1, 1]
    23042511        """
    23052512        return Partition(self.k_skew(k).conjugate().row_lengths())
    2306        
     2513
    23072514    def parent(self):
    23082515        """
    23092516        Returns the combinatorial class of partitions of sum(self).
    2310        
     2517
    23112518        EXAMPLES::
    2312        
     2519
    23132520            sage: Partition([3,2,1]).parent()
    23142521            Partitions of the integer 6
    23152522        """
    class Partition_class(CombinatorialObjec 
    23192526        """
    23202527        This is a statistic on a cell c=(i,j) in the diagram of partition p
    23212528        given by
    2322        
     2529
    23232530        .. math::
    2324        
    2325              [ (1 - q^{arm_length(c)} * t^{leg_length(c) + 1}) ] /            [ (1 - q^{arm_length(c) + 1} * t^{leg_length(c)}) ] 
    2326        
    2327        
    2328        
     2531
     2532             [ (1 - q^{arm_length(c)} * t^{leg_length(c) + 1}) ] /            [ (1 - q^{arm_length(c) + 1} * t^{leg_length(c)}) ]
     2533
     2534
     2535
    23292536        EXAMPLES::
    2330        
     2537
    23312538            sage: Partition([3,2,1]).arms_legs_coeff(1,1)
    23322539            (-t + 1)/(-q + 1)
    23332540            sage: Partition([3,2,1]).arms_legs_coeff(0,0)
    class Partition_class(CombinatorialObjec 
    23482555        """
    23492556        Returns a list of the standard tableaux of size self.size() whose
    23502557        atom is equal to self.
    2351        
     2558
    23522559        EXAMPLES::
    2353        
     2560
    23542561            sage: Partition([2,1]).atom()
    23552562            [[[1, 2], [3]]]
    23562563            sage: Partition([3,2,1]).atom()
    class Partition_class(CombinatorialObjec 
    23652572    def k_atom(self, k):
    23662573        """
    23672574        EXAMPLES::
    2368        
     2575
    23692576            sage: p = Partition([3,2,1])
    23702577            sage: p.k_atom(1)
    23712578            []
    class Partition_class(CombinatorialObjec 
    23762583             [[1, 1, 1, 2, 3], [2]]]
    23772584            sage: Partition([3,2,1]).k_atom(4)
    23782585            [[[1, 1, 1], [2, 2], [3]], [[1, 1, 1, 3], [2, 2]]]
    2379        
     2586
    23802587        TESTS::
    2381        
     2588
    23822589            sage: Partition([1]).k_atom(1)
    23832590            [[[1]]]
    23842591            sage: Partition([1]).k_atom(2)
    class Partition_class(CombinatorialObjec 
    23972604    def k_split(self, k):
    23982605        """
    23992606        Returns the k-split of self.
    2400        
     2607
    24012608        EXAMPLES::
    2402        
     2609
    24032610            sage: Partition([4,3,2,1]).k_split(3)
    24042611            []
    24052612            sage: Partition([4,3,2,1]).k_split(4)
    class Partition_class(CombinatorialObjec 
    24272634            if part != []:
    24282635                res.append(part)
    24292636        return res
    2430        
     2637
    24312638    def jacobi_trudi(self):
    24322639        """
    24332640        EXAMPLES::
    2434        
     2641
    24352642            sage: part = Partition([3,2,1])
    24362643            sage: jt = part.jacobi_trudi(); jt
    24372644            [h[3] h[1]    0]
    class Partition_class(CombinatorialObjec 
    24492656
    24502657    def character_polynomial(self):
    24512658        r"""
    2452         Returns the character polynomial associated to the partition self.
     2659        Returns the character polynomial associated to the partition ``self``.
    24532660        The character polynomial `q_\mu` is defined by
    2454        
    2455        
     2661
     2662
    24562663        .. math::
    2457        
    2458            q_\mu(x_1, x_2, \ldots, x_k) = \downarrow \sum_{\alpha \vdash k}\frac{ \chi^\mu_\alpha }{1^{a_1}2^{a_2}\cdots k^{a_k}a_1!a_2!\cdots a_k!} \prod_{i=1}^{k} (ix_i-1)^{a_i}         
    2459        
    2460        
     2664
     2665           q_\mu(x_1, x_2, \ldots, x_k) = \downarrow \sum_{\alpha \vdash k}\frac{ \chi^\mu_\alpha }{1^{a_1}2^{a_2}\cdots k^{a_k}a_1!a_2!\cdots a_k!} \prod_{i=1}^{k} (ix_i-1)^{a_i}
     2666
     2667
    24612668        where `a_i` is the multiplicity of `i` in
    24622669        `\alpha`.
    2463        
     2670
    24642671        It is computed in the following manner.
    2465        
     2672
    24662673        1. Expand the Schur function `s_\mu` in the power-sum
    2467            basis. 
    2468 
    2469         2. Replace each `p_i` with `ix_i-1` 
     2674           basis.
     2675
     2676        2. Replace each `p_i` with `ix_i-1`
    24702677
    24712678        3. Apply the umbral operator `\downarrow` to the resulting
    24722679           polynomial.
    2473        
     2680
    24742681        EXAMPLES::
    2475        
     2682
    24762683            sage: Partition([1]).character_polynomial()
    24772684            x - 1
    24782685            sage: Partition([1,1]).character_polynomial()
    class Partition_class(CombinatorialObjec 
    24802687            sage: Partition([2,1]).character_polynomial()
    24812688            1/3*x0^3 - 2*x0^2 + 8/3*x0 - x2
    24822689        """
    2483        
     2690
    24842691        #Create the polynomial ring we will use
    24852692        k = self.size()
    24862693        P = PolynomialRing(QQ, k, 'x')
    class Partition_class(CombinatorialObjec 
    26952902
    26962903
    26972904
    2698 ##################################################
    2699 
    2700 def number_of_partitions_list(n,k=None):
    2701     r"""
    2702     This function will be deprecated in a future version of Sage and
    2703     eventually removed. Use Partitions(n).cardinality() or Partitions(n,
    2704     length=k).cardinality() instead.
    2705    
    2706     Original docstring follows.
    2707    
    2708     Returns the size of partitions_list(n,k).
    2709    
    2710     Wraps GAP's NrPartitions.
    2711    
    2712     It is possible to associate with every partition of the integer n a
    2713     conjugacy class of permutations in the symmetric group on n points
    2714     and vice versa. Therefore p(n) = NrPartitions(n) is the number of
    2715     conjugacy classes of the symmetric group on n points.
    2716    
    2717     ``number_of_partitions(n)`` is also available in
    2718     PARI, however the speed seems the same until `n` is in the
    2719     thousands (in which case PARI is faster).
    2720    
    2721     EXAMPLES::
    2722    
    2723         sage: partition.number_of_partitions_list(10,2)
    2724         5
    2725         sage: partition.number_of_partitions_list(10)
    2726         42
    2727    
    2728     A generating function for p(n) is given by the reciprocal of
    2729     Euler's function:
    2730    
    2731     .. math::
    2732    
    2733              \sum_{n=0}^\infty p(n)x^n = \prod_{k=1}^\infty \left(\frac {1}{1-x^k} \right).     
    2734    
    2735    
    2736     Sage verifies that the first several coefficients do instead
    2737     agree::
    2738    
    2739         sage: q = PowerSeriesRing(QQ, 'q', default_prec=9).gen()
    2740         sage: prod([(1-q^k)^(-1) for k in range(1,9)])  ## partial product of
    2741         1 + q + 2*q^2 + 3*q^3 + 5*q^4 + 7*q^5 + 11*q^6 + 15*q^7 + 22*q^8 + O(q^9)
    2742         sage: [partition.number_of_partitions_list(k) for k in range(2,10)]
    2743         [2, 3, 5, 7, 11, 15, 22, 30]
    2744    
    2745     REFERENCES:
    2746 
    2747     - http://en.wikipedia.org/wiki/Partition\_(number\_theory)
    2748     """
    2749     if k is None:
    2750         ans=gap.eval("NrPartitions(%s)"%(ZZ(n)))
    2751     else:
    2752         ans=gap.eval("NrPartitions(%s,%s)"%(ZZ(n),ZZ(k)))
    2753     return ZZ(ans)
    2754 
    2755 
    27562905######################
    27572906# Ordered Partitions #
    27582907######################
    def OrderedPartitions(n, k=None): 
    27612910    Returns the combinatorial class of ordered partitions of n. If k is
    27622911    specified, then only the ordered partitions of length k are
    27632912    returned.
    2764    
     2913
    27652914    .. note::
    27662915
    27672916       It is recommended that you use Compositions instead as
    27682917       OrderedPartitions wraps GAP. See also ordered_partitions.
    2769    
     2918
    27702919    EXAMPLES::
    2771    
     2920
    27722921        sage: OrderedPartitions(3)
    27732922        Ordered partitions of 3
    27742923        sage: OrderedPartitions(3).list()
    class OrderedPartitions_nk(Combinatorial 
    27842933    def __init__(self, n, k=None):
    27852934        """
    27862935        EXAMPLES::
    2787        
     2936
    27882937            sage: o = OrderedPartitions(4,2)
    27892938            sage: o == loads(dumps(o))
    27902939            True
    class OrderedPartitions_nk(Combinatorial 
    27952944    def __contains__(self, x):
    27962945        """
    27972946        EXAMPLES::
    2798        
     2947
    27992948            sage: o = OrderedPartitions(4,2)
    28002949            sage: [2,1] in o
    28012950            False
    class OrderedPartitions_nk(Combinatorial 
    28092958    def __repr__(self):
    28102959        """
    28112960        EXAMPLES::
    2812        
     2961
    28132962            sage: OrderedPartitions(3).__repr__()
    28142963            'Ordered partitions of 3'
    28152964            sage: OrderedPartitions(3,2).__repr__()
    class OrderedPartitions_nk(Combinatorial 
    28192968        if self.k is not None:
    28202969            string += " of length %s"%self.k
    28212970        return string
    2822        
     2971
    28232972    def list(self):
    28242973        """
    28252974        EXAMPLES::
    2826        
     2975
    28272976            sage: OrderedPartitions(3).list()
    28282977            [[3], [2, 1], [1, 2], [1, 1, 1]]
    28292978            sage: OrderedPartitions(3,2).list()
    class OrderedPartitions_nk(Combinatorial 
    28412990
    28422991    def cardinality(self):
    28432992        """
     2993        Return the cardinality of ``self``.
     2994
    28442995        EXAMPLES::
    2845        
     2996
    28462997            sage: OrderedPartitions(3).cardinality()
    28472998            4
    28482999            sage: OrderedPartitions(3,2).cardinality()
    class PartitionsGreatestLE(IntegerListsL 
    28643015    Returns the combinatorial class of all (unordered) "restricted"
    28653016    partitions of the integer n having parts less than or equal to the
    28663017    integer k.
    2867    
     3018
    28683019    EXAMPLES::
    2869    
     3020
    28703021        sage: PartitionsGreatestLE(10,2)
    28713022        Partitions of 10 having parts less than or equal to 2
    28723023        sage: PartitionsGreatestLE(10,2).list()
    class PartitionsGreatestLE(IntegerListsL 
    28973048        """
    28983049        IntegerListsLex.__init__(self, n, max_slope = 0, min_part=1, max_part = k)
    28993050        self.k = k
    2900        
     3051
    29013052    def _repr_(self):
    29023053        """
    29033054        TESTS::
    2904        
     3055
    29053056            sage: PartitionsGreatestLE(10, 2).__repr__()
    29063057            'Partitions of 10 having parts less than or equal to 2'
    29073058        """
    class PartitionsGreatestLE_nk(Partitions 
    29143065    def __setstate__(self, data):
    29153066        r"""
    29163067        TESTS::
    2917        
     3068
    29183069            sage: p = loads('x\x9c\x85\x8e\xbd\xaa\xc2@\x10\x85\x89\xff.>\xc4\x94\xda\x04\x15|\x04\xb1\xb1\x90\x0b[\x87I\x18\x935\xc9\xae\xb33\xda\t\xd7\xc2\xf76"biw\x0e\x9c\x9f\xef\xbfW\x08\x96\x94\x16\xa1\xcd\x9dGM\xcf\x18\xd5\xa9\x0b\xde\x1c>Jv\x91PIt\xbf\xcd|m8Y\xdc\xb9w\xe3\xfe\xdc&\xf5\xbb\x1d\x9d/%u^\xa9\xa4hZ\xac)\xfb\x18\x1e\xd8d\xfd\xf8\xe3\xa1\x1df\x1e[\xe2\x91\xdd|\x97!\x1ca\xb5\x84\n\xaf\xdd\x02\xbc\xbe\x05\x1a\x12\x01\xad\xd0C\x88@|\xc1\x064\xc0\x9a\xc7v\x16\xf2\x13\x15\x9a\x15\r\x8a\xf0\xe47\xf9;ixj\x13_u \xd8\x81\x98K\x9e>\x01\x13iVH')
    29193070            sage: p == PartitionsGreatestLE(10,2)
    29203071            True
    class PartitionsGreatestEQ(IntegerListsL 
    29303081    Returns combinatorial class of all (unordered) "restricted"
    29313082    partitions of the integer n having its greatest part equal to the
    29323083    integer k.
    2933    
     3084
    29343085    EXAMPLES::
    2935    
     3086
    29363087        sage: PartitionsGreatestEQ(10,2)
    29373088        Partitions of 10 having greatest part equal to 2
    29383089        sage: PartitionsGreatestEQ(10,2).list()
    class PartitionsGreatestEQ(IntegerListsL 
    29523103        sage: PartitionsGreatestEQ(10,2).first().parent()
    29533104        Partitions...
    29543105
    2955     """   
     3106    """
    29563107
    29573108    def __init__(self, n, k):
    29583109        """
    class PartitionsGreatestEQ(IntegerListsL 
    29673118        IntegerListsLex.__init__(self, n, max_slope = 0, max_part=k, floor = [k])
    29683119        self.k = k
    29693120
    2970     def _repr_(self):
     3121    def __repr__(self):
    29713122        """
    29723123        TESTS::
    2973        
     3124
    29743125            sage: PartitionsGreatestEQ(10,2).__repr__()
    29753126            'Partitions of 10 having greatest part equal to 2'
    29763127        """
    class PartitionsGreatestEQ_nk(Partitions 
    29913142        self.__class__ = PartitionsGreatestEQ
    29923143        self.__init__(data['n'], data['k'])
    29933144
     3145
    29943146#########################
    29953147# Restricted Partitions #
    29963148#########################
    29973149def RestrictedPartitions(n, S, k=None):
    29983150    r"""
    29993151    This function has been deprecated and will be removed in a
    3000     future version of Sage; use Partitions() with the ``parts_in``
    3001     keyword.
     3152    future version of Sage; use :meth:`Partitions` with the ``parts_in``
     3153    keyword. Note, however, that the current implementation of
     3154    :meth:`Partitions` does not allow the ``parts_in`` keyword to be combined
     3155    with keywords such as ``max_length``; see :trac:`13072` and :trac:`12278`
     3156    for more details. This class should not be removed until this problem
     3157    has been fixed.
    30023158
    30033159    Original docstring follows.
    30043160
    def RestrictedPartitions(n, S, k=None): 
    30083164    nonincreasing order. The difference is that here the `p_i`
    30093165    must be elements from the set `S`, while for ordinary
    30103166    partitions they may be elements from `[1..n]`.
    3011    
     3167
    30123168    Returns the list of all restricted partitions of the positive
    3013     integer n into sums with k summands with the summands of the
    3014     partition coming from the set S. If k is not given all restricted
    3015     partitions for all k are returned.
     3169    integer n into sums with `k` summands with the summands of the
     3170    partition coming from the set `S`. If `k` is not given all restricted
     3171    partitions for all `k` are returned.
    30163172
    30173173    Wraps GAP's RestrictedPartitions.
    30183174
    30193175    EXAMPLES::
    30203176
    30213177        sage: RestrictedPartitions(5,[3,2,1])
    3022         doctest:...: DeprecationWarning: RestrictedPartitions is deprecated; use Partitions with the parts_in keyword instead.
    3023         See http://trac.sagemath.org/5478 for details.
     3178        doctest:1: DeprecationWarning: RestrictedPartitions is deprecated; use Partitions with the parts_in keyword instead.
     3179        See http://trac.sagemath.org/13072 for details.
     3180        doctest:...: DeprecationWarning: RestrictedPartitions_nsk is deprecated; use Partitions with the parts_in keyword instead.
     3181        See http://trac.sagemath.org/13072 for details.
    30243182        Partitions of 5 restricted to the values [1, 2, 3]
    30253183        sage: RestrictedPartitions(5,[3,2,1]).list()
    30263184        [[3, 2], [3, 1, 1], [2, 2, 1], [2, 1, 1, 1], [1, 1, 1, 1, 1]]
    def RestrictedPartitions(n, S, k=None): 
    30303188        [[2, 1, 1, 1]]
    30313189    """
    30323190    from sage.misc.superseded import deprecation
    3033     deprecation(5478, 'RestrictedPartitions is deprecated; use Partitions with the parts_in keyword instead.')
     3191    deprecation(13072, 'RestrictedPartitions is deprecated; use Partitions with the parts_in keyword instead.')
    30343192    return RestrictedPartitions_nsk(n, S, k)
    30353193
     3194
    30363195class RestrictedPartitions_nsk(CombinatorialClass):
    30373196    r"""
    30383197    We are deprecating RestrictedPartitions, so this class should
    3039     be deprecated too.
     3198    be deprecated too. See :trac:`13072`.
    30403199
    30413200    """
    30423201    def __init__(self, n, S, k=None):
    30433202        """
    30443203        TESTS::
    3045        
     3204
    30463205            sage: r = RestrictedPartitions(5,[3,2,1])
    3047             doctest:...: DeprecationWarning: RestrictedPartitions is deprecated; use Partitions with the parts_in keyword instead.
    3048             See http://trac.sagemath.org/5478 for details.
     3206            doctest:1: DeprecationWarning: RestrictedPartitions is deprecated; use Partitions with the parts_in keyword instead.
     3207            See http://trac.sagemath.org/13072 for details.
    30493208            sage: r == loads(dumps(r))
    30503209            True
    30513210        """
    30523211        from sage.misc.superseded import deprecation
    3053         deprecation(5478, 'RestrictedPartitions_nsk is deprecated; use Partitions with the parts_in keyword instead.')
     3212        deprecation(13072, 'RestrictedPartitions_nsk is deprecated; use Partitions with the parts_in keyword instead.')
    30543213        self.n = n
    30553214        self.S = S
    30563215        self.S.sort()
    30573216        self.k = k
    30583217
    30593218    Element = Partition_class
    3060        
     3219
    30613220    def __contains__(self, x):
    30623221        """
    30633222        EXAMPLES::
    3064        
     3223
    30653224            sage: [4,1] in RestrictedPartitions(5,[3,2,1])
    30663225            doctest:...: DeprecationWarning: RestrictedPartitions is deprecated; use Partitions with the parts_in keyword instead.
    3067             See http://trac.sagemath.org/5478 for details.
     3226            See http://trac.sagemath.org/13072 for details.
    30683227            False
    30693228            sage: [3,2] in RestrictedPartitions(5,[3,2,1])
    30703229            True
    class RestrictedPartitions_nsk(Combinato 
    30813240        EXAMPLES::
    30823241
    30833242            sage: RestrictedPartitions(5,[3,2,1]).__repr__()
    3084             doctest:...: DeprecationWarning: RestrictedPartitions is deprecated; use Partitions with the parts_in keyword instead.
    3085             See http://trac.sagemath.org/5478 for details.
    3086             doctest:...: DeprecationWarning: RestrictedPartitions_nsk is deprecated; use Partitions with the parts_in keyword instead.
    3087             See http://trac.sagemath.org/5478 for details.
     3243            doctest:1: DeprecationWarning: RestrictedPartitions is deprecated; use Partitions with the parts_in keyword instead.
     3244            See http://trac.sagemath.org/13072 for details.
    30883245            'Partitions of 5 restricted to the values [1, 2, 3]'
    3089             sage: RestrictedPartitions(5,[3,2,1],4).__repr__()
    3090             'Partitions of 5 restricted to the values [1, 2, 3] of length 4'
    30913246        """
    30923247        string = "Partitions of %s restricted to the values %s"%(self.n, self.S)
    30933248        if self.k is not None:
    class RestrictedPartitions_nsk(Combinato 
    31073262
    31083263            sage: RestrictedPartitions(8,[1,3,5,7]).list()
    31093264            doctest:...: DeprecationWarning: RestrictedPartitions is deprecated; use Partitions with the parts_in keyword instead.
    3110             See http://trac.sagemath.org/5478 for details.
     3265            See http://trac.sagemath.org/13072 for details.
    31113266            [[7, 1], [5, 3], [5, 1, 1, 1], [3, 3, 1, 1], [3, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1]]
    31123267            sage: RestrictedPartitions(8,[1,3,5,7],2).list()
    31133268            [[7, 1], [5, 3]]
    class RestrictedPartitions_nsk(Combinato 
    31273282        """
    31283283        Returns the size of RestrictedPartitions(n,S,k). Wraps GAP's
    31293284        NrRestrictedPartitions.
    3130        
     3285
    31313286        EXAMPLES::
    3132        
     3287
    31333288            sage: RestrictedPartitions(8,[1,3,5,7]).cardinality()
    31343289            doctest:...: DeprecationWarning: RestrictedPartitions is deprecated; use Partitions with the parts_in keyword instead.
    3135             See http://trac.sagemath.org/5478 for details.
     3290            See http://trac.sagemath.org/13072 for details.
    31363291            6
    31373292            sage: RestrictedPartitions(8,[1,3,5,7],2).cardinality()
    31383293            2
    class RestrictedPartitions_nsk(Combinato 
    31453300        else:
    31463301            ans=gap.eval("NrRestrictedPartitions(%s,%s,%s)"%(ZZ(n),S,ZZ(k)))
    31473302        return ZZ(ans)
    3148        
    3149 ####################
    3150 # Partition Tuples #
    3151 ####################
    3152 def PartitionTuples(n,k):
    3153     """
    3154     Returns the combinatorial class of k-tuples of partitions of n.
    3155     These are are ordered list of k partitions whose sizes add up to
    3156 
    3157     TODO: reimplement in term of species.ProductSpecies and Partitions
    3158 
    3159     These describe the classes and the characters of wreath products of
    3160     groups with k conjugacy classes with the symmetric group
    3161     `S_n`.
    3162    
    3163     EXAMPLES::
    3164    
    3165         sage: PartitionTuples(4,2)
    3166         2-tuples of partitions of 4
    3167         sage: PartitionTuples(3,2).list()
    3168         [[[3], []],
    3169          [[2, 1], []],
    3170          [[1, 1, 1], []],
    3171          [[2], [1]],
    3172          [[1, 1], [1]],
    3173          [[1], [2]],
    3174          [[1], [1, 1]],
    3175          [[], [3]],
    3176          [[], [2, 1]],
    3177          [[], [1, 1, 1]]]
    3178     """   
    3179     return PartitionTuples_nk(n,k)
    3180 
    3181 class PartitionTuples_nk(CombinatorialClass):
    3182     def __init__(self, n, k):
    3183         """
    3184         TESTS::
    3185        
    3186             sage: p = PartitionTuples(4,2)
    3187             sage: p == loads(dumps(p))
    3188             True
    3189         """
    3190         self.n = n
    3191         self.k = k
    3192 
    3193     Element = Partition_class
    3194 
    3195 
    3196     def __contains__(self, x):
    3197         """
    3198         EXAMPLES::
    3199        
    3200             sage: [[], [1, 1, 1]] in PartitionTuples(3,2)
    3201             True
    3202             sage: [[1], [1, 1, 1]] in PartitionTuples(3,2)
    3203             False
    3204         """
    3205         p = Partitions_all()
    3206         return len(x) == self.k and all(i in p for i in x)\
    3207                and sum(sum(i) for i in x) == self.n
    3208        
    3209     def __repr__(self):
    3210         """
    3211         EXAMPLES::
    3212        
    3213             sage: PartitionTuples(4,2).__repr__()
    3214             '2-tuples of partitions of 4'
    3215         """
    3216         return "%s-tuples of partitions of %s"%(self.k, self.n)
    3217 
    3218     def __iter__(self):
    3219         r"""
    3220         Returns an iterator for all k-tuples of partitions which together
    3221         form a partition of n.
    3222        
    3223         EXAMPLES::
    3224        
    3225             sage: PartitionTuples(2,0).list() #indirect doctest
    3226             []           
    3227             sage: PartitionTuples(2,1).list() #indirect doctest
    3228             [[[2]], [[1, 1]]]
    3229             sage: PartitionTuples(2,2).list() #indirect doctest
    3230             [[[2], []], [[1, 1], []], [[1], [1]], [[], [2]], [[], [1, 1]]]
    3231             sage: PartitionTuples(3,2).list() #indirect doctest
    3232             [[[3], []], [[2, 1], []], [[1, 1, 1], []], [[2], [1]], [[1, 1], [1]], [[1], [2]], [[1], [1, 1]], [[], [3]], [[], [2, 1]], [[], [1, 1, 1]]]
    3233         """
    3234         p = [Partitions(i) for i in range(self.n+1)]
    3235         for iv in IntegerVectors(self.n,self.k):
    3236             for cp in CartesianProduct(*[p[i] for i in iv]):
    3237                 yield cp
    3238                                    
    3239    
    3240     def cardinality(self):
    3241         r"""
    3242         Returns the number of k-tuples of partitions which together form a
    3243         partition of n.
    3244        
    3245         Wraps GAP's NrPartitionTuples.
    3246        
    3247         EXAMPLES::
    3248        
    3249             sage: PartitionTuples(3,2).cardinality()
    3250             10
    3251             sage: PartitionTuples(8,2).cardinality()
    3252             185
    3253        
    3254         Now we compare that with the result of the following GAP
    3255         computation::
    3256        
    3257             gap> S8:=Group((1,2,3,4,5,6,7,8),(1,2));
    3258             Group([ (1,2,3,4,5,6,7,8), (1,2) ])
    3259             gap> C2:=Group((1,2));
    3260             Group([ (1,2) ])
    3261             gap> W:=WreathProduct(C2,S8);
    3262             <permutation group of size 10321920 with 10 generators>
    3263             gap> Size(W);
    3264             10321920     ## = 2^8*Factorial(8), which is good:-)
    3265             gap> Size(ConjugacyClasses(W));
    3266             185
    3267         """
    3268         return ZZ(gp.eval('polcoeff(1/eta(x)^%s, %s, x)'%(self.k, self.n)))
    3269 
    32703303
    32713304##############
    32723305# Partitions #
    def Partitions(n=None, **kwargs): 
    32773310    Partitions(n, \*\*kwargs) returns the combinatorial class of
    32783311    integer partitions of `n`, subject to the constraints given by the
    32793312    keywords.
    3280    
     3313
    32813314    Valid keywords are: ``starting``, ``ending``, ``min_part``,
    32823315    ``max_part``, ``max_length``, ``min_length``, ``length``,
    32833316    ``max_slope``, ``min_slope``, ``inner``, ``outer``, and
    32843317    ``parts_in``. They have the following meanings:
    3285    
     3318
    32863319    - ``starting=p`` specifies that the partitions should all be greater
    32873320      than or equal to `p` in reverse lex order.
    32883321
    def Partitions(n=None, **kwargs): 
    33033336
    33043337    - ``parts_in=S`` specifies that the partitions have parts in the set
    33053338      `S`, which can be any sequence of positive integers.
    3306    
     3339
    33073340    The ``max_*`` versions, along with ``inner`` and ``ending``, work
    33083341    analogously.
    33093342
    def Partitions(n=None, **kwargs): 
    33123345    keyword arguments. If you specify, say, ``parts_in``, all other
    33133346    keyword arguments will be ignored; ``starting`` and ``ending`` work
    33143347    the same way.
    3315    
    3316     EXAMPLES: If no arguments are passed, then the combinatorial class
     3348
     3349    EXAMPLES:
     3350
     3351    If no arguments are passed, then the combinatorial class
    33173352    of all integer partitions is returned.
    3318    
     3353
    33193354    ::
    3320    
     3355
    33213356        sage: Partitions()
    33223357        Partitions
    33233358        sage: [2,1] in Partitions()
    33243359        True
    3325    
     3360
    33263361    If an integer `n` is passed, then the combinatorial class of integer
    33273362    partitions of `n` is returned.
    3328    
     3363
    33293364    ::
    3330    
     3365
    33313366        sage: Partitions(3)
    33323367        Partitions of the integer 3
    33333368        sage: Partitions(3).list()
    33343369        [[3], [2, 1], [1, 1, 1]]
    3335    
     3370
    33363371    If ``starting=p`` is passed, then the combinatorial class of partitions
    33373372    greater than or equal to `p` in lexicographic order is returned.
    3338    
     3373
    33393374    ::
    3340    
     3375
    33413376        sage: Partitions(3, starting=[2,1])
    33423377        Partitions of the integer 3 starting with [2, 1]
    33433378        sage: Partitions(3, starting=[2,1]).list()
    33443379        [[2, 1], [1, 1, 1]]
    3345    
     3380
    33463381    If ``ending=p`` is passed, then the combinatorial class of
    33473382    partitions at most `p` in lexicographic order is returned.
    3348    
     3383
    33493384    ::
    3350    
     3385
    33513386        sage: Partitions(3, ending=[2,1])
    33523387        Partitions of the integer 3 ending with [2, 1]
    33533388        sage: Partitions(3, ending=[2,1]).list()
    33543389        [[3], [2, 1]]
    3355    
     3390
    33563391    Using ``max_slope=-1`` yields partitions into distinct parts -- each
    33573392    part differs from the next by at least 1. Use a different
    33583393    ``max_slope`` to get parts that differ by, say, 2.
    def Partitions(n=None, **kwargs): 
    33873422    and ``length``.
    33883423
    33893424    ::
    3390    
     3425
    33913426        sage: Partitions(5,min_part=2)
    33923427        Partitions of the integer 5 satisfying constraints min_part=2
    33933428        sage: Partitions(5,min_part=2).list()
    33943429        [[5], [3, 2]]
    3395    
     3430
    33963431    ::
    3397    
     3432
    33983433        sage: Partitions(3,max_length=2).list()
    33993434        [[3], [2, 1]]
    3400    
     3435
    34013436    ::
    3402    
     3437
    34033438        sage: Partitions(10, min_part=2, length=3).list()
    34043439        [[6, 2, 2], [5, 3, 2], [4, 4, 2], [4, 3, 3]]
    34053440
    34063441
    34073442    Here are some further examples using various constraints::
    3408    
     3443
    34093444        sage: [x for x in Partitions(4)]
    34103445        [[4], [3, 1], [2, 2], [2, 1, 1], [1, 1, 1, 1]]
    34113446        sage: [x for x in Partitions(4, length=2)]
    def Partitions(n=None, **kwargs): 
    34403475    Partition class makes.
    34413476
    34423477    ::
    3443      
     3478
    34443479        sage: [x for x in Partitions(4, length=3, min_part=0)]
    34453480        doctest:... RuntimeWarning: Currently, setting min_part=0 produces Partition objects which violate internal assumptions.  Calling methods on these objects may produce errors or WRONG results!
    34463481        [[4, 0, 0], [3, 1, 0], [2, 2, 0], [2, 1, 1]]
    def Partitions(n=None, **kwargs): 
    34563491        [[1000]]
    34573492
    34583493    In particular, getting the first element is also constant time::
    3459      
     3494
    34603495        sage: Partitions(30, max_part=29).first()
    34613496        [29, 1]
    34623497
    34633498    TESTS::
    3464    
     3499
    34653500        sage: P = Partitions(5, min_part=2)
    34663501        sage: P == loads(dumps(P))
    34673502        True
    34683503
    34693504        sage: repr( Partitions(5, min_part=2) )
    34703505        'Partitions of the integer 5 satisfying constraints min_part=2'
    3471        
     3506
    34723507        sage: P = Partitions(5, min_part=2)
    34733508        sage: P.first().parent()
    34743509        Partitions...
    def Partitions(n=None, **kwargs): 
    34853520        [[5], [4, 1], [3, 2], [3, 1, 1], [2, 2, 1], [2, 1, 1, 1]]
    34863521        sage: Partitions(6, length=2, max_slope=-1).list()
    34873522        [[5, 1], [4, 2]]
     3523
     3524        sage: Partitions(length=2, max_slope=-1).list()
     3525        Traceback (most recent call last):
     3526        ...
     3527        ValueError: the size must be specified with any keyword argument
    34883528    """
    3489     assert n != infinity, "n cannot be infinite"
     3529    if n == infinity:
     3530        raise ValueError, "n cannot be infinite"
    34903531    if n is None:
    3491         assert(len(kwargs) == 0)
     3532        if len(kwargs) > 0:
     3533            raise ValueError, 'the size must be specified with any keyword argument'
    34923534        return Partitions_all()
    34933535    else:
    34943536        if len(kwargs) == 0:
    def Partitions(n=None, **kwargs): 
    35373579#                return Partitions_constraints(n, **kwargs)
    35383580
    35393581
    3540 # Allows to pickle old constrained Partitions_constraints objects.             
     3582# Allows to pickle old constrained Partitions_constraints objects.
    35413583class Partitions_constraints(IntegerListsLex):
    35423584    def __setstate__(self, data):
    35433585        r"""
    class Partitions_all(InfiniteAbstractCom 
    35863628    def __contains__(self, x):
    35873629        """
    35883630        TESTS::
    3589        
    35903631            sage: P = Partitions()
    35913632            sage: Partition([2,1]) in P
    35923633            True
    class Partitions_all(InfiniteAbstractCom 
    36223663    def __repr__(self):
    36233664        """
    36243665        TESTS::
    3625        
     3666
    36263667            sage: repr(Partitions())
    36273668            'Partitions'
    36283669        """
    class Partitions_all(InfiniteAbstractCom 
    36313672    def _infinite_cclass_slice(self, n):
    36323673        """
    36333674        Needed by InfiniteAbstractCombinatorialClass to build __iter__.
    3634  
    3635         TESTS:
     3675
     3676        TESTS::
     3677
    36363678            sage: Partitions()._infinite_cclass_slice(4) == Partitions(4)
    36373679            True
    36383680            sage: it = iter(Partitions())    # indirect doctest
    class Partitions_all(InfiniteAbstractCom 
    36423684        return Partitions_n(n)
    36433685
    36443686
    3645 
    3646 
    3647 
    36483687class Partitions_n(CombinatorialClass):
    36493688    Element = Partition_class
     3689
    36503690    def __init__(self, n):
    36513691        """
    36523692        TESTS::
    class Partitions_n(CombinatorialClass): 
    36573697        """
    36583698        self.n = n
    36593699
     3700
    36603701    def __contains__(self, x):
    36613702        """
    36623703        TESTS::
    class Partitions_n(CombinatorialClass): 
    36863727
    36873728        EXAMPLES::
    36883729
    3689             sage: Partitions(4)._an_element_()
     3730            sage: Partitions(4).an_element()  # indirect doctest
    36903731            [3, 1]
    3691             sage: Partitions(0)._an_element_()
     3732            sage: Partitions(0).an_element()
    36923733            []
    3693             sage: Partitions(1)._an_element_()
     3734            sage: Partitions(1).an_element()
    36943735            [1]
    36953736        """
    36963737        if self.n == 0:
    class Partitions_n(CombinatorialClass): 
    37013742            lst = [self.n-1, 1]
    37023743        return self._element_constructor_(lst)
    37033744
    3704     def cardinality(self, algorithm='default'):
     3745    def cardinality(self, algorithm='bober'):
    37053746        r"""
     3747        Returns the number of partitions of the specified size.
     3748
    37063749        INPUT:
    37073750
    3708         - ``algorithm``
    3709 
    3710           - (default: ``default``)
    3711 
    3712           - ``'bober'`` - use Jonathan Bober's implementation (*very*
    3713             fast, but relatively new)
    3714 
    3715           - ``'gap'`` - use GAP (VERY *slow*)
    3716 
    3717           - ``'pari'`` - use PARI. Speed seems the same as GAP until
    3718             `n` is in the thousands, in which case PARI is faster.
    3719 
    3720           - ``'default'`` - ``'bober'`` when k is not specified;
    3721             otherwise use ``'gap'``.
    3722        
    3723         Use the function ``partitions(n)`` to return a
    3724         generator over all partitions of `n`.
    3725        
    3726         It is possible to associate with every partition of the integer n a
    3727         conjugacy class of permutations in the symmetric group on n points
    3728         and vice versa. Therefore p(n) = NrPartitions(n) is the number of
    3729         conjugacy classes of the symmetric group on n points.
    3730        
     3751        - ``algorithm``  - (default: 'bober')
     3752
     3753            - ``'bober'`` - use Jonathan Bober's implementation (*very* fast).
     3754                            The default
     3755
     3756            - ``'gap'`` - use GAP (VERY *slow*)
     3757
     3758            - ``'pari'`` - use PARI. Speed seems the same as GAP until
     3759                `n` is in the thousands, in which case PARI is faster.
     3760
     3761            - ``'default'`` - ``'bober'`` when k is not specified;
     3762                otherwise use ``'gap'``.
     3763
     3764        Use the function :meth:`partitions` to return a generator over all
     3765        partitions of `n`.
     3766
     3767        It is possible to associate with every partition of the integer `n` a
     3768        conjugacy class of permutations in the symmetric group on `n` points
     3769        and vice versa. Therefore ``p(n) = NrPartitions(n)`` is the number of
     3770        conjugacy classes of the symmetric group on `n` points.
     3771
    37313772        EXAMPLES::
    3732        
     3773
    37333774            sage: v = Partitions(5).list(); v
    37343775            [[5], [4, 1], [3, 2], [3, 1, 1], [2, 2, 1], [2, 1, 1, 1], [1, 1, 1, 1, 1]]
    37353776            sage: len(v)
    class Partitions_n(CombinatorialClass): 
    37403781            7
    37413782            sage: Partitions(5).cardinality(algorithm='bober')
    37423783            7
    3743        
     3784
    37443785        The input must be a nonnegative integer or a ValueError is raised.
    3745        
     3786
    37463787        ::
    3747        
     3788
    37483789            sage: Partitions(10).cardinality()
    37493790            42
    37503791            sage: Partitions(3).cardinality()
    class Partitions_n(CombinatorialClass): 
    37593800            37338
    37603801            sage: Partitions(100).cardinality()
    37613802            190569292
    3762        
     3803
    37633804        A generating function for p(n) is given by the reciprocal of
    37643805        Euler's function:
    3765        
    3766        
     3806
    37673807        .. math::
    3768        
     3808
    37693809           \sum_{n=0}^\infty p(n)x^n = \prod_{k=1}^\infty \left(\frac {1}{1-x^k} \right).
    3770        
    3771        
    3772        
     3810
    37733811        We use Sage to verify that the first several coefficients do
    37743812        instead agree::
    3775        
     3813
    37763814            sage: q = PowerSeriesRing(QQ, 'q', default_prec=9).gen()
    3777             sage: prod([(1-q^k)^(-1) for k in range(1,9)])  ## partial product of 
     3815            sage: prod([(1-q^k)^(-1) for k in range(1,9)])  ## partial product of
    37783816            1 + q + 2*q^2 + 3*q^3 + 5*q^4 + 7*q^5 + 11*q^6 + 15*q^7 + 22*q^8 + O(q^9)
    37793817            sage: [Partitions(k) .cardinality()for k in range(2,10)]
    37803818            [2, 3, 5, 7, 11, 15, 22, 30]
    3781        
     3819
    37823820        REFERENCES:
    37833821
    37843822        - http://en.wikipedia.org/wiki/Partition\_(number\_theory)
    37853823        """
    3786         return number_of_partitions(self.n, algorithm=algorithm)
    3787 
     3824        if algorithm == 'bober':
     3825            return cached_number_of_partitions(self.n)
     3826
     3827        elif algorithm == 'gap':
     3828            return ZZ( gap.eval("NrPartitions(%s)"%(ZZ(self.n))) )
     3829
     3830        elif algorithm == 'pari':
     3831            return ZZ(pari(ZZ(self.n)).numbpart())
     3832
     3833        raise ValueError, "unknown algorithm '%s'"%algorithm
    37883834
    37893835    def random_element(self, measure = 'uniform'):
    37903836        """
    class Partitions_n(CombinatorialClass): 
    37923838
    37933839        INPUT:
    37943840
    3795          - ``measure`` -
    3796 
    3797             - ``uniform`` - (default) pick a element for the uniform mesure.
    3798                             see :meth:`random_element_uniform`
    3799 
    3800             - ``Plancherel`` - use plancherel measure.
    3801                             see :meth:`random_element_plancherel`
     3841        - ``measure``
     3842
     3843            - ``uniform`` -- (default) pick a element for the uniform mesure.
     3844                                see :meth:`random_element_uniform`
     3845
     3846            - ``Plancherel`` -- use plancherel measure.
     3847                                see :meth:`random_element_plancherel`
    38023848
    38033849        EXAMPLES::
    38043850
    class Partitions_n(CombinatorialClass): 
    38343880        ALGORITHM:
    38353881
    38363882         - It is a python Implementation of RANDPAR, see [nw] below.  The
    3837            complexity is unkown, there may be better algorithms.  TODO: Check
    3838            in Knuth AOCP4.
     3883           complexity is unknown, there may be better algorithms.
     3884
     3885           .. TODO: :
     3886
     3887               Check in Knuth AOCP4.
    38393888
    38403889         - There is also certainly a lot of room for optimizations, see
    38413890           comments in the code.
    class Partitions_n(CombinatorialClass): 
    38573906            # equiprobable.
    38583907
    38593908            # The following could be made faster by a clever use of floats
    3860             rand = randrange(0, n*_numpart(n))  # cached number_of_partition
     3909            rand = randrange(0, n*cached_number_of_partitions(n))  # cached number_of_partition
    38613910
    38623911            # It is better to start by the j = 1 pairs because they are the
    38633912            # most probable. Maybe there is an even more clever order.
    class Partitions_n(CombinatorialClass): 
    38653914                d = 1
    38663915                r = n-j        # n - d*j
    38673916                while  r >= 0:
    3868                     rand -= d * _numpart(r)
     3917                    rand -= d * cached_number_of_partitions(r)
    38693918                    if rand < 0: break
    38703919                    d +=1
    38713920                    r -= j
    class Partitions_n(CombinatorialClass): 
    38963945
    38973946        ALGORITHM:
    38983947
    3899          - insert by robinson-schensted a uniform random permutations of n and
     3948         - insert by Robinson-Schensted a uniform random permutations of n and
    39003949           returns the shape of the resulting tableau. The complexity is
    39013950           `O(n\ln(n))` which is likely optimal. However, the implementation
    39023951           could be optimized.
    class Partitions_n(CombinatorialClass): 
    39113960        """
    39123961        Returns the lexicographically first partition of a positive integer
    39133962        n. This is the partition [n].
    3914        
     3963
    39153964        EXAMPLES::
    3916        
     3965
    39173966            sage: Partitions(4).first()
    39183967            [4]
    39193968        """
    class Partitions_n(CombinatorialClass): 
    39233972        """
    39243973        Returns the lexicographically last partition of the positive
    39253974        integer n. This is the all-ones partition.
    3926        
     3975
    39273976        EXAMPLES::
    3928        
     3977
    39293978            sage: Partitions(4).last()
    39303979            [1, 1, 1, 1]
    39313980        """
    class Partitions_n(CombinatorialClass): 
    39363985    def __iter__(self):
    39373986        """
    39383987        An iterator for the partitions of n.
    3939        
     3988
    39403989        EXAMPLES::
    3941        
     3990
    39423991            sage: [x for x in Partitions(4)]
    39433992            [[4], [3, 1], [2, 2], [2, 1, 1], [1, 1, 1, 1]]
    39443993        """
    39453994        for p in self._fast_iterator():
    39463995            yield Partition_class(p)
    39473996
    3948            
     3997
    39493998    def _fast_iterator(self):
    39503999        """
    39514000        A fast iterator for the partitions of n which returns lists and not
    39524001        partition types.
    3953        
     4002
    39544003        EXAMPLES::
    3955        
     4004
    39564005            sage: p = Partitions(4)
    39574006            sage: it = p._fast_iterator()
    39584007            sage: it.next()
    class Partitions_n(CombinatorialClass): 
    39704019        if self.n == 0:
    39714020            yield []
    39724021            return
    3973        
     4022
    39744023        # modify the partitions of n-1 to form the partitions of n
    39754024        for p in Partitions_n(self.n-1)._fast_iterator():
    39764025            if p and (len(p) < 2 or p[-2] > p[-1]):
    39774026                yield p[:-1] + [p[-1] + 1]
    3978             yield p + [1]   
     4027            yield p + [1]
    39794028
    39804029
    39814030class Partitions_parts_in(CombinatorialClass):
    class Partitions_parts_in(CombinatorialC 
    39834032    def __init__(self, n, parts):
    39844033        """
    39854034        TESTS::
    3986        
     4035
    39874036            sage: p = Partitions(5, parts_in=[1,2,3])
    39884037            sage: p == loads(dumps(p))
    39894038            True
    class Partitions_parts_in(CombinatorialC 
    39944043    def __contains__(self, x):
    39954044        """
    39964045        TESTS::
    3997        
     4046
    39984047            sage: p = Partitions(5, parts_in=[1,2])
    39994048            sage: [2,1,1,1] in p
    40004049            True
    40014050            sage: [4,1] in p
    40024051            False
    40034052        """
    4004         return (x in Partitions_all() and sum(x) == self.n and 
     4053        return (x in Partitions_all() and sum(x) == self.n and
    40054054                all(p in self.parts for p in x))
    40064055
    40074056    def __repr__(self):
    40084057        """
    40094058        TESTS::
    4010        
     4059
    40114060            sage: repr(Partitions(5, parts_in=[1,2,3]))
    40124061            'Partitions of the integer 5 with parts in [1, 2, 3]'
    40134062        """
    class Partitions_parts_in(CombinatorialC 
    40624111        Return the lexicographically first partition of a positive
    40634112        integer `n` with the specified parts, or None if no such
    40644113        partition exists.
    4065        
     4114
    40664115        EXAMPLES::
    4067        
     4116
    40684117            sage: Partitions(9, parts_in=[3,4]).first()
    40694118            [3, 3, 3]
    40704119            sage: Partitions(6, parts_in=[1..6]).first()
    class Partitions_parts_in(CombinatorialC 
    40874136            sage: p._findfirst(0, p.parts[:])
    40884137            []
    40894138            sage: p._findfirst(p.n, [10])
    4090            
     4139
    40914140        """
    40924141        if n == 0:
    40934142            return []
    class Partitions_parts_in(CombinatorialC 
    41054154        Returns the lexicographically last partition of the positive
    41064155        integer `n` with the specified parts, or None if no such
    41074156        partition exists.
    4108        
     4157
    41094158        EXAMPLES::
    41104159
    41114160            sage: Partitions(15, parts_in=[2,3]).last()
    41124161            [3, 2, 2, 2, 2, 2, 2]
    4113             sage: Partitions(30, parts_in=[4,7,8,10,11]).last() 
     4162            sage: Partitions(30, parts_in=[4,7,8,10,11]).last()
    41144163            [7, 7, 4, 4, 4, 4]
    41154164            sage: Partitions(10, parts_in=[3,6]).last() is None
    41164165            True
    41174166            sage: Partitions(50, parts_in=[11,12,13]).last()
    41184167            [13, 13, 12, 12]
    4119             sage: Partitions(30, parts_in=[4,7,8,10,11]).last() 
     4168            sage: Partitions(30, parts_in=[4,7,8,10,11]).last()
    41204169            [7, 7, 4, 4, 4, 4]
    41214170
    41224171        TESTS::
    class Partitions_parts_in(CombinatorialC 
    41444193        - ``n``: nonnegative integer
    41454194        - ``parts``: a sorted list of positive integers.
    41464195
    4147         OUTPUT::
     4196        OUTPUT:
    41484197
    41494198        A list of integers in weakly decreasing order, or None. The
    41504199        output is just a list, not a Partition object.
    class Partitions_parts_in(CombinatorialC 
    41854234    def __iter__(self):
    41864235        """
    41874236        An iterator a list of the partitions of n.
    4188        
     4237
    41894238        EXAMPLES::
    4190        
     4239
    41914240            sage: [x for x in Partitions(4)]
    41924241            [[4], [3, 1], [2, 2], [2, 1, 1], [1, 1, 1, 1]]
    41934242        """
    41944243        for p in self._fast_iterator(self.n, self.parts[:]):
    41954244            yield Partition_class(p)
    41964245
    4197            
     4246
    41984247    def _fast_iterator(self, n, parts):
    41994248        """
    42004249        A fast iterator for the partitions of n which returns lists and
    42014250        not partition types. This function is not intended to be called
    42024251        directly.
    4203        
     4252
    42044253        INPUT:
    42054254
    42064255        - ``n``: nonnegative integer.
    class Partitions_parts_in(CombinatorialC 
    42194268        If the parts in ``parts`` are sorted in increasing order, this
    42204269        function returns weakly decreasing lists. If ``parts`` is not
    42214270        sorted, your lists won't be, either.
    4222        
     4271
    42234272        EXAMPLES::
    4224        
     4273
    42254274            sage: p = Partitions(4)
    42264275            sage: it = p._fast_iterator()
    42274276            sage: it.next()
    class Partitions_starting(CombinatorialC 
    42424291    def __init__(self, n, starting_partition):
    42434292        """
    42444293        EXAMPLES::
    4245        
     4294
    42464295            sage: Partitions(3, starting=[2,1])
    42474296            Partitions of the integer 3 starting with [2, 1]
    42484297            sage: Partitions(3, starting=[2,1]).list()
    42494298            [[2, 1], [1, 1, 1]]
    4250        
     4299
    42514300        TESTS::
    4252        
     4301
    42534302            sage: p = Partitions(3, starting=[2,1])
    42544303            sage: p == loads(dumps(p))
    42554304            True
    class Partitions_starting(CombinatorialC 
    42604309    def __repr__(self):
    42614310        """
    42624311        EXAMPLES::
    4263        
     4312
    42644313            sage: Partitions(3, starting=[2,1]).__repr__()
    42654314            'Partitions of the integer 3 starting with [2, 1]'
    42664315        """
    class Partitions_starting(CombinatorialC 
    42694318    def __contains__(self, x):
    42704319        """
    42714320        EXAMPLES::
    4272        
     4321
    42734322            sage: p = Partitions(3, starting=[2,1])
    42744323            sage: [1,1] in p
    42754324            False
    class Partitions_starting(CombinatorialC 
    42854334    def first(self):
    42864335        """
    42874336        EXAMPLES::
    4288        
     4337
    42894338            sage: Partitions(3, starting=[2,1]).first()
    42904339            [2, 1]
    42914340        """
    class Partitions_starting(CombinatorialC 
    42944343    def next(self, part):
    42954344        """
    42964345        EXAMPLES::
    4297        
     4346
    42984347            sage: Partitions(3, starting=[2,1]).next(Partition([2,1]))
    42994348            [1, 1, 1]
    43004349        """
    class Partitions_ending(CombinatorialCla 
    43044353    def __init__(self, n, ending_partition):
    43054354        """
    43064355        EXAMPLES::
    4307        
     4356
    43084357            sage: Partitions(4, ending=[1,1,1,1]).list()
    43094358            [[4], [3, 1], [2, 2], [2, 1, 1], [1, 1, 1, 1]]
    43104359            sage: Partitions(4, ending=[2,2]).list()
    43114360            [[4], [3, 1], [2, 2]]
    43124361            sage: Partitions(4, ending=[4]).list()
    43134362            [[4]]
    4314        
     4363
    43154364        TESTS::
    4316        
     4365
    43174366            sage: p = Partitions(4, ending=[1,1,1,1])
    43184367            sage: p == loads(dumps(p))
    43194368            True
    4320         """       
     4369        """
    43214370        self.n = n
    43224371        self._ending = Partition(ending_partition)
    43234372
    43244373    def __repr__(self):
    43254374        """
    43264375        EXAMPLES::
    4327        
     4376
    43284377            sage: Partitions(4, ending=[1,1,1,1]).__repr__()
    43294378            'Partitions of the integer 4 ending with [1, 1, 1, 1]'
    43304379        """
    class Partitions_ending(CombinatorialCla 
    43334382    def __contains__(self, x):
    43344383        """
    43354384        EXAMPLES::
    4336        
     4385
    43374386            sage: p = Partitions(4, ending=[2,2])
    43384387            sage: [4] in p
    43394388            True
    class Partitions_ending(CombinatorialCla 
    43474396    def first(self):
    43484397        """
    43494398        EXAMPLES::
    4350        
     4399
    43514400            sage: Partitions(4, ending=[1,1,1,1]).first()
    43524401            [4]
    43534402        """
    class Partitions_ending(CombinatorialCla 
    43564405    def next(self, part):
    43574406        """
    43584407        EXAMPLES::
    4359        
     4408
    43604409            sage: Partitions(4, ending=[1,1,1,1]).next(Partition([4]))
    43614410            [3, 1]
    43624411            sage: Partitions(4, ending=[1,1,1,1]).next(Partition([1,1,1,1])) is None
    class Partitions_ending(CombinatorialCla 
    43664415            return None
    43674416        else:
    43684417            return part.next()
    4369        
     4418
    43704419
    43714420def PartitionsInBox(h, w):
    43724421    """
    43734422    Returns the combinatorial class of partitions that fit in a h by w
    43744423    box.
    4375    
     4424
    43764425    EXAMPLES::
    4377    
     4426
    43784427        sage: PartitionsInBox(2,2)
    43794428        Integer partitions which fit in a 2 x 2 box
    43804429        sage: PartitionsInBox(2,2).list()
    class PartitionsInBox_hw(CombinatorialCl 
    43864435    def __init__(self, h, w):
    43874436        """
    43884437        TESTS::
    4389        
     4438
    43904439            sage: p = PartitionsInBox(2,2)
    43914440            sage: p == loads(dumps(p))
    43924441            True
    class PartitionsInBox_hw(CombinatorialCl 
    44004449    def __contains__(self, x):
    44014450        """
    44024451        EXAMPLES::
    4403        
     4452
    44044453            sage: [] in PartitionsInBox(2,2)
    44054454            True
    44064455            sage: [2,1] in PartitionsInBox(2,2)
    class PartitionsInBox_hw(CombinatorialCl 
    44124461        """
    44134462        return x in Partitions_all() and len(x) <= self.h \
    44144463               and (len(x) == 0 or x[0] <= self.w)
    4415    
     4464
    44164465    def list(self):
    44174466        """
    44184467        Returns a list of all the partitions inside a box of height h and
    44194468        width w.
    4420        
     4469
    44214470        EXAMPLES::
    4422        
     4471
    44234472            sage: PartitionsInBox(2,2).list()
    44244473            [[], [1], [1, 1], [2], [2, 1], [2, 2]]
    44254474
    44264475         TESTS::
    4427        
     4476
    44284477            sage: type(PartitionsInBox(0,0)[0]) # check for 10890
    44294478            <class 'sage.combinat.partition.Partition_class'>
    44304479        """
    class PartitionsInBox_hw(CombinatorialCl 
    44424491                l = new_list
    44434492
    44444493            return [Partition(filter(lambda x: x!=0, p)) for p in l]
    4445            
    4446            
     4494
     4495
    44474496#########################################################################
    44484497
    44494498#### partitions
    def partitions_set(S,k=None, use_file=Tr 
    44534502    An unordered partition of a set `S` is a set of pairwise
    44544503    disjoint nonempty subsets with union `S` and is represented
    44554504    by a sorted list of such subsets.
    4456    
     4505
    44574506    partitions_set returns the list of all unordered partitions of the
    44584507    list `S` of increasing positive integers into k pairwise
    44594508    disjoint nonempty sets. If k is omitted then all partitions are
    44604509    returned.
    4461    
     4510
    44624511    The Bell number `B_n`, named in honor of Eric Temple Bell,
    44634512    is the number of different partitions of a set with n elements.
    4464    
    4465     .. warning::
     4513
     4514    .. WARNING::
    44664515
    44674516       Wraps GAP - hence S must be a list of objects that have string
    44684517       representations that can be interpreted by the GAP
    44694518       interpreter. If mset consists of at all complicated Sage
    44704519       objects, this function does *not* do what you expect. See
    44714520       SetPartitions in ``combinat/set_partition``.
    4472    
    4473     .. warning::
     4521
     4522    .. WARNING::
    44744523
    44754524       This function is inefficient. The runtime is dominated by
    44764525       parsing the output from GAP.
    4477    
     4526
    44784527    Wraps GAP's PartitionsSet.
    4479    
     4528
    44804529    EXAMPLES::
    44814530   
    44824531        sage: S = [1,2,3,4]
     4532        sage: from sage.combinat.partition import partitions_set
    44834533        sage: partitions_set(S,2)
    4484         [[[1], [2, 3, 4]],
    4485          [[1, 2], [3, 4]],
    4486          [[1, 2, 3], [4]],
    4487          [[1, 2, 4], [3]],
    4488          [[1, 3], [2, 4]],
    4489          [[1, 3, 4], [2]],
    4490          [[1, 4], [2, 3]]]
    4491    
    4492     REFERENCES:
     4534        doctest:1: DeprecationWarning: partitions_set is deprecated. Use SetPartitions instead.
     4535        See http://trac.sagemath.org/13072 for details.
     4536        Set partitions of [1, 2, 3, 4] with 2 parts
    44934537
    44944538    - http://en.wikipedia.org/wiki/Partition_of_a_set
    44954539    """
    4496     if k is None:
    4497         ans=gap("PartitionsSet(%s)"%S).str(use_file=use_file)
    4498     else:
    4499         ans=gap("PartitionsSet(%s,%s)"%(S,k)).str(use_file=use_file)
    4500     return eval(ans)
     4540    from sage.misc.superseded import deprecation
     4541    deprecation(13072,'partitions_set is deprecated. Use SetPartitions instead.')
     4542    return sage.combinat.set_partition.SetPartitions(S,k)
     4543
    45014544
    45024545def number_of_partitions_set(S,k):
    45034546    r"""
    45044547    Returns the size of ``partitions_set(S,k)``. Wraps
    45054548    GAP's NrPartitionsSet.
    4506    
     4549
    45074550    The Stirling number of the second kind is the number of partitions
    45084551    of a set of size n into k blocks.
    45094552   
    45104553    EXAMPLES::
    45114554   
    45124555        sage: mset = [1,2,3,4]
     4556        sage: from sage.combinat.partition import number_of_partitions_set
    45134557        sage: number_of_partitions_set(mset,2)
     4558        doctest:1: DeprecationWarning: number_of_partitions_set is deprecated. Use SetPartitions().cardinality() instead.
     4559        See http://trac.sagemath.org/13072 for details.
    45144560        7
    45154561        sage: stirling_number2(4,2)
    45164562        7
    4517    
     4563
    45184564    REFERENCES
    45194565
    45204566    - http://en.wikipedia.org/wiki/Partition_of_a_set
    45214567    """
    4522     if k is None:
    4523         ans=gap.eval("NrPartitionsSet(%s)"%S)
    4524     else:
    4525         ans=gap.eval("NrPartitionsSet(%s,%s)"%(S,ZZ(k)))
    4526     return ZZ(ans)
    4527 
    4528 def partitions_list(n,k=None):
    4529     r"""
    4530     This function will be deprecated in a future version of Sage and
    4531     eventually removed. Use Partitions(n).list() or Partitions(n,
    4532     length=k).list() instead.
    4533    
    4534     Original docstring follows.
    4535    
    4536     An unordered partition of `n` is an unordered sum
    4537     `n = p_1+p_2 +\ldots+ p_k` of positive integers and is
    4538     represented by the list `p = [p_1,p_2,\ldots,p_k]`, in
    4539     nonincreasing order, i.e., `p1\geq p_2 ...\geq p_k`.
    4540    
    4541     INPUT:
    4542    
    4543    
    4544     -  ``n, k`` - positive integer
    4545    
    4546    
    4547     ``partitions_list(n,k)`` returns the list of all
    4548     (unordered) partitions of the positive integer n into sums with k
    4549     summands. If k is omitted then all partitions are returned.
    4550    
    4551     Do not call partitions_list with an n much larger than 40, in
    4552     which case there are 37338 partitions, since the list will simply
    4553     become too large.
    4554    
    4555     Wraps GAP's Partitions.
    4556    
    4557     EXAMPLES::
    4558    
    4559         sage: partitions_list(10,2)
    4560         [[5, 5], [6, 4], [7, 3], [8, 2], [9, 1]]
    4561         sage: partitions_list(5)
    4562         [[1, 1, 1, 1, 1], [2, 1, 1, 1], [2, 2, 1], [3, 1, 1], [3, 2], [4, 1], [5]]
    4563     """
    4564     n = ZZ(n)
    4565     if n <= 0:
    4566         raise ValueError, "n (=%s) must be a positive integer"%n
    4567     if k is None:
    4568         ans=gap.eval("Partitions(%s)"%(n))
    4569     else:
    4570         ans=gap.eval("Partitions(%s,%s)"%(n,k))
    4571     return eval(ans.replace('\n',''))
    4572 
     4568    from sage.misc.superseded import deprecation
     4569    deprecation(13072,'number_of_partitions_set is deprecated. Use SetPartitions().cardinality() instead.')
     4570    return sage.combinat.set_partition.SetPartitions(S,k).cardinality()
    45734571
    45744572def number_of_partitions(n,k=None, algorithm='default'):
    45754573    r"""
    4576     Returns the size of partitions_list(n,k).
    4577    
     4574    Returns the number of partitions of `n` with, optionally, at most `k`
     4575    parts.
     4576
     4577    The options of ``sage.combinat.partition.number_of_partitions`` are being
     4578    deprecated :trac:`13072` in favour of :meth:`Partitions().cardinality()`
     4579    so that ``number_of_partitions()`` can become a stripped down version of
     4580    the fastest algorithm available (currently this is due to Bober, but an
     4581    faster implementation using FLINT will soon be merged into sage).
     4582
    45784583    INPUT:
    4579    
    4580    
     4584
    45814585    -  ``n`` - an integer
    4582    
    4583     -  ``k`` - (default: None); if specified, instead
     4586
     4587    -  ``k`` - (default: ``None``); if specified, instead
    45844588       returns the cardinality of the set of all (unordered) partitions of
    4585        the positive integer n into sums with k summands.
    4586    
     4589       the positive integer ``n`` into sums with ``k`` summands.
     4590       [Will be deprecated: please use PartitionTuples(level, size).cardinality() ]
     4591
    45874592    -  ``algorithm`` - (default: 'default')
    4588    
    4589     -  ``'default'`` - If k is not None, then use Gap (very
    4590        slow). If k is None, use Jonathan Bober's highly optimized
    4591        implementation (this is the fastest code in the world for this
    4592        problem).
    4593    
    4594     -  ``'bober'`` - use Jonathan Bober's implementation
    4595    
    4596     -  ``'gap'`` - use GAP (VERY *slow*)
    4597    
    4598     -  ``'pari'`` - use PARI. Speed seems the same as GAP until
    4599        `n` is in the thousands, in which case PARI is
    4600        faster. *But* PARI has a bug, e.g., on 64-bit Linux
    4601        PARI-2.3.2 outputs numbpart(147007)%1000 as 536 when it should
    4602        be 533!. So do not use this option.
    4603    
    4604    
    4605     IMPLEMENTATION: Wraps GAP's NrPartitions or PARI's numbpart
    4606     function.
    4607    
    4608     Use the function ``partitions(n)`` to return a
    4609     generator over all partitions of `n`.
    4610    
    4611     It is possible to associate with every partition of the integer n a
    4612     conjugacy class of permutations in the symmetric group on n points
    4613     and vice versa. Therefore p(n) = NrPartitions(n) is the number of
    4614     conjugacy classes of the symmetric group on n points.
    4615    
     4593       [Will be deprecated except in Partition().cardinality() ]
     4594
     4595       -  ``'default'`` - If k is not ``None``, then use Gap (very
     4596           slow). If k is ``None``, use Jonathan Bober's highly optimized
     4597           implementation.
     4598
     4599       -  ``'bober'`` - use Jonathan Bober's implementation
     4600
     4601       -  ``'gap'`` - use GAP (VERY *slow*)
     4602
     4603       -  ``'pari'`` - use PARI. Speed seems the same as GAP until
     4604           `n` is in the thousands, in which case PARI is
     4605           faster. *But* PARI has a bug, e.g., on 64-bit Linux
     4606           PARI-2.3.2 outputs numbpart(147007)%1000 as 536 when it should
     4607           be 533!. So do not use this option.
     4608
    46164609    EXAMPLES::
    4617    
    4618         sage: v = list(partitions(5)); v
    4619         [(1, 1, 1, 1, 1), (1, 1, 1, 2), (1, 2, 2), (1, 1, 3), (2, 3), (1, 4), (5,)]
     4610
     4611        sage: v = Partitions(5).list(); v
     4612        [[5], [4, 1], [3, 2], [3, 1, 1], [2, 2, 1], [2, 1, 1, 1], [1, 1, 1, 1, 1]]
    46204613        sage: len(v)
    46214614        7
    46224615        sage: number_of_partitions(5, algorithm='gap')
     4616        doctest:1: DeprecationWarning: sage.combinat.number_of_partitions is deprecated. Use  Partitions().cardinality(algorithm='gap')
     4617        See http://trac.sagemath.org/13072 for details.
    46234618        7
    46244619        sage: number_of_partitions(5, algorithm='pari')
     4620        doctest:1: DeprecationWarning: sage.combinat.number_of_partitions is deprecated. Use  Partitions().cardinality(algorithm='pari')
     4621        See http://trac.sagemath.org/13072 for details.
    46254622        7
    46264623        sage: number_of_partitions(5, algorithm='bober')
    46274624        7
    4628    
     4625
    46294626    The input must be a nonnegative integer or a ValueError is raised.
    4630    
     4627
    46314628    ::
    4632    
     4629
    46334630        sage: number_of_partitions(-5)
    46344631        Traceback (most recent call last):
    46354632        ...
    46364633        ValueError: n (=-5) must be a nonnegative integer
    4637    
     4634
    46384635    ::
    4639    
     4636
    46404637        sage: number_of_partitions(10,2)
     4638        doctest:1: DeprecationWarning: sage.combinat.number_of_partitions(size, level) is deprecated. Use PartitionTuples(level, size).cardinality() instead.
     4639        See http://trac.sagemath.org/13072 for details.
    46414640        5
     4641
    46424642        sage: number_of_partitions(10)
    46434643        42
    46444644        sage: number_of_partitions(3)
    def number_of_partitions(n,k=None, algor 
    46554655        190569292
    46564656        sage: number_of_partitions(100000)
    46574657        27493510569775696512677516320986352688173429315980054758203125984302147328114964173055050741660736621590157844774296248940493063070200461792764493033510116079342457190155718943509725312466108452006369558934464248716828789832182345009262853831404597021307130674510624419227311238999702284408609370935531629697851569569892196108480158600569421098519
    4658    
    4659     A generating function for p(n) is given by the reciprocal of
     4658
     4659    A generating function for the partition function is given by the reciprocal of
    46604660    Euler's function:
    4661    
    4662    
     4661
    46634662    .. math::
    4664    
    4665              \sum_{n=0}^\infty p(n)x^n = \prod_{k=1}^\infty \left(\frac {1}{1-x^k} \right).     
    4666    
    4667    
    4668    
     4663
     4664             \sum_{n=0}^\infty p(n)x^n = \prod_{k=1}^\infty \left(\frac {1}{1-x^k} \right).
     4665
    46694666    We use Sage to verify that the first several coefficients do
    46704667    instead agree::
    4671    
     4668
    46724669        sage: q = PowerSeriesRing(QQ, 'q', default_prec=9).gen()
    4673         sage: prod([(1-q^k)^(-1) for k in range(1,9)])  ## partial product of 
     4670        sage: prod([(1-q^k)^(-1) for k in range(1,9)])  ## partial product of
    46744671        1 + q + 2*q^2 + 3*q^3 + 5*q^4 + 7*q^5 + 11*q^6 + 15*q^7 + 22*q^8 + O(q^9)
    46754672        sage: [number_of_partitions(k) for k in range(2,10)]
    46764673        [2, 3, 5, 7, 11, 15, 22, 30]
    4677    
     4674
    46784675    REFERENCES:
    46794676
    46804677    - http://en.wikipedia.org/wiki/Partition\_(number\_theory)
    4681    
     4678
    46824679    TESTS::
    4683    
     4680
    46844681        sage: n = 500 + randint(0,500)
    46854682        sage: number_of_partitions( n - (n % 385) + 369) % 385 == 0
    46864683        True
    def number_of_partitions(n,k=None, algor 
    47054702        sage: n = 1000000 + randint(0,1000000)
    47064703        sage: number_of_partitions( n - (n % 385) + 369) % 385 == 0
    47074704        True
    4708         sage: n = 100000000 + randint(0,100000000) 
     4705        sage: n = 100000000 + randint(0,100000000)
    47094706        sage: number_of_partitions( n - (n % 385) + 369) % 385 == 0  # long time (4s on sage.math, 2011)
    47104707        True
    4711    
     4708
    47124709    Another consistency test for n up to 500::
    4713    
     4710
    47144711        sage: len([n for n in [1..500] if number_of_partitions(n) != number_of_partitions(n,algorithm='pari')])
    47154712        0
    47164713    """
     4714    from sage.misc.superseded import deprecation
    47174715    n = ZZ(n)
    47184716    if n < 0:
    47194717        raise ValueError, "n (=%s) must be a nonnegative integer"%n
    def number_of_partitions(n,k=None, algor 
    47254723            algorithm = 'bober'
    47264724        else:
    47274725            algorithm = 'gap'
    4728            
     4726
    47294727    if algorithm == 'gap':
    47304728        if k is None:
     4729            deprecation(13072,"sage.combinat.number_of_partitions is deprecated. Use  Partitions().cardinality(algorithm='gap')")
    47314730            ans=gap.eval("NrPartitions(%s)"%(ZZ(n)))
    47324731        else:
     4732            deprecation(13072,'sage.combinat.number_of_partitions(size, level) is deprecated. Use PartitionTuples(level, size).cardinality() instead.')
    47334733            ans=gap.eval("NrPartitions(%s,%s)"%(ZZ(n),ZZ(k)))
    47344734        return ZZ(ans)
    4735    
     4735
    47364736    if k is not None:
    47374737        raise ValueError, "only the GAP algorithm works if k is specified."
    47384738
    47394739    if algorithm == 'bober':
    4740         return partitions_ext.number_of_partitions(n)
    4741        
     4740        return cached_number_of_partitions(n)
     4741
    47424742    elif algorithm == 'pari':
     4743        deprecation(13072,"sage.combinat.number_of_partitions is deprecated. Use  Partitions().cardinality(algorithm='pari')")
    47434744        return ZZ(pari(ZZ(n)).numbpart())
    4744    
     4745
    47454746    raise ValueError, "unknown algorithm '%s'"%algorithm
    47464747
    4747 
    4748 # Some function e.g.: Partitions(n).random() heavily use number_of_partitions
    4749 # so I'm caching the result
     4748# This function was previously used to cache number_of_partitions with the
     4749# justification that "Some function e.g.: Partitions(n).random() heavily use
     4750# number_of_partitions", however, the random() method of Partitions() seems to be
     4751# the only place where this was used.
     4752from sage.misc.superseded import deprecated_function_alias
     4753_numpart = deprecated_function_alias(13072, sage.combinat.partitions.number_of_partitions)
     4754
     4755# Rather than caching an under used function I have cached the default
     4756# number_of_partitions functions which is currently that implemented by Bober,
     4757# although this will soon need to be replaced by the FLINT implementation.
     4758# AM :trac:`13072`
    47504759from sage.misc.all import cached_function
    4751 _numpart = cached_function(number_of_partitions)
    4752 
    4753 def partitions(n):
    4754     r"""
    4755     Generator of all the partitions of the integer `n`.
    4756    
    4757     INPUT:
    4758    
    4759    
    4760     -  ``n`` - int
    4761    
    4762    
    4763     To compute the number of partitions of `n` use
    4764     ``number_of_partitions(n)``.
    4765    
    4766     EXAMPLES::
    4767    
    4768         sage: partitions(3)
    4769         <generator object partitions at 0x...>
    4770         sage: list(partitions(3))
    4771         [(1, 1, 1), (1, 2), (3,)]
    4772    
    4773     AUTHORS:
    4774 
    4775     - Adapted from David Eppstein, Jan Van lent, George Yoshida;
    4776       Python Cookbook 2, Recipe 19.16.
    4777     """
    4778     n = ZZ(n)
    4779     # base case of the recursion: zero is the sum of the empty tuple
    4780     if n == 0:
    4781         yield ( )
    4782         return
    4783     # modify the partitions of n-1 to form the partitions of n
    4784     for p in partitions(n-1):
    4785         yield (1,) + p
    4786         if p and (len(p) < 2 or p[1] > p[0]):
    4787             yield (p[0] + 1,) + p[1:]
     4760cached_number_of_partitions = cached_function( bober_number_of_partitions )
    47884761
    47894762def cyclic_permutations_of_partition(partition):
    47904763    """
    47914764    Returns all combinations of cyclic permutations of each cell of the
    47924765    partition.
    4793    
     4766
    47944767    AUTHORS:
    47954768
    47964769    - Robert L. Miller
    4797    
     4770
    47984771    EXAMPLES::
    4799    
    4800         sage: from sage.combinat.partition import cyclic_permutations_of_partition         
     4772
     4773        sage: from sage.combinat.partition import cyclic_permutations_of_partition
    48014774        sage: cyclic_permutations_of_partition([[1,2,3,4],[5,6,7]])
     4775        doctest:1: DeprecationWarning: cyclic_permutations_of_partition is being removed from the global namespace. Use sage.combinat.set_partition.cyclic_permutations_of_set_partition instead.
     4776        See http://trac.sagemath.org/13072 for details.
     4777        doctest:...: DeprecationWarning: cyclic_permutations_of_partition_iterator is being removed from the global namespace. Please use sage.combinat.set_partition.cyclic_permutations_of_set_partition_iterator instead.
     4778        See http://trac.sagemath.org/13072 for details.
     4779        doctest:...: DeprecationWarning: cyclic_permutations_of_partition_iterator is being removed from the global namespace. Please use sage.combinat.set_partition.cyclic_permutations_of_set_partition_iterator instead.
     4780        See http://trac.sagemath.org/13072 for details.
    48024781        [[[1, 2, 3, 4], [5, 6, 7]],
    48034782         [[1, 2, 4, 3], [5, 6, 7]],
    48044783         [[1, 3, 2, 4], [5, 6, 7]],
    def cyclic_permutations_of_partition(par 
    48114790         [[1, 3, 4, 2], [5, 7, 6]],
    48124791         [[1, 4, 2, 3], [5, 7, 6]],
    48134792         [[1, 4, 3, 2], [5, 7, 6]]]
    4814    
     4793
    48154794    Note that repeated elements are not considered equal::
    4816    
     4795
    48174796        sage: cyclic_permutations_of_partition([[1,2,3],[4,4,4]])
    48184797        [[[1, 2, 3], [4, 4, 4]],
    48194798         [[1, 3, 2], [4, 4, 4]],
    48204799         [[1, 2, 3], [4, 4, 4]],
    48214800         [[1, 3, 2], [4, 4, 4]]]
    48224801    """
     4802    from sage.misc.superseded import deprecation
     4803    deprecation(13072,'cyclic_permutations_of_partition is being removed from the global namespace. Use sage.combinat.set_partition.cyclic_permutations_of_set_partition instead.')
    48234804    return list(cyclic_permutations_of_partition_iterator(partition))
    48244805
     4806
    48254807def cyclic_permutations_of_partition_iterator(partition):
    48264808    """
    48274809    Iterates over all combinations of cyclic permutations of each cell
    48284810    of the partition.
    4829    
     4811
    48304812    AUTHORS:
    48314813
    48324814    - Robert L. Miller
    4833    
     4815
    48344816    EXAMPLES::
    4835    
    4836         sage: from sage.combinat.partition import cyclic_permutations_of_partition         
     4817
     4818        sage: from sage.combinat.partition import cyclic_permutations_of_partition_iterator
    48374819        sage: list(cyclic_permutations_of_partition_iterator([[1,2,3,4],[5,6,7]]))
     4820        doctest:1: DeprecationWarning: cyclic_permutations_of_partition_iterator is being removed from the global namespace. Please use sage.combinat.set_partition.cyclic_permutations_of_set_partition_iterator instead.
     4821        See http://trac.sagemath.org/13072 for details.
    48384822        [[[1, 2, 3, 4], [5, 6, 7]],
    48394823         [[1, 2, 4, 3], [5, 6, 7]],
    48404824         [[1, 3, 2, 4], [5, 6, 7]],
    def cyclic_permutations_of_partition_ite 
    48474831         [[1, 3, 4, 2], [5, 7, 6]],
    48484832         [[1, 4, 2, 3], [5, 7, 6]],
    48494833         [[1, 4, 3, 2], [5, 7, 6]]]
    4850    
     4834
    48514835    Note that repeated elements are not considered equal::
    4852    
     4836
    48534837        sage: list(cyclic_permutations_of_partition_iterator([[1,2,3],[4,4,4]]))
    48544838        [[[1, 2, 3], [4, 4, 4]],
    48554839         [[1, 3, 2], [4, 4, 4]],
    48564840         [[1, 2, 3], [4, 4, 4]],
    48574841         [[1, 3, 2], [4, 4, 4]]]
    48584842    """
     4843    from sage.misc.superseded import deprecation
     4844    deprecation(13072,'cyclic_permutations_of_partition_iterator is being removed from the global namespace. Please use sage.combinat.set_partition.cyclic_permutations_of_set_partition_iterator instead.')
    48594845    if len(partition) == 1:
    48604846        for i in cyclic_permutations_iterator(partition[0]):
    48614847            yield [i]
    def cyclic_permutations_of_partition_ite 
    48644850            for perm in cyclic_permutations_iterator(partition[0]):
    48654851                yield [perm] + right
    48664852
     4853
     4854def partitions(n):
     4855    r"""
     4856    Generator of all the partitions of the integer `n`.
     4857
     4858    To compute the number of partitions of `n` use :meth:`number_of_partitions`.
     4859
     4860    INPUT:
     4861
     4862    -  ``n`` -- An integer
     4863
     4864    EXAMPLES::
     4865
     4866        sage: partitions(3)
     4867        <generator object partitions at 0x...>
     4868        sage: list(partitions(3))
     4869        doctest:1: DeprecationWarning: partitions is deprecated. Use Partitions() instead.
     4870        See http://trac.sagemath.org/13072 for details.
     4871        doctest:...: DeprecationWarning: partitions is deprecated. Use Partitions() instead.
     4872        See http://trac.sagemath.org/13072 for details.
     4873        [(1, 1, 1), (1, 2), (3,)]
     4874
     4875    AUTHORS:
     4876
     4877    - Adapted from David Eppstein, Jan Van lent, George Yoshida;
     4878      Python Cookbook 2, Recipe 19.16.
     4879    """
     4880    from sage.misc.superseded import deprecation
     4881    deprecation(13072,'partitions is deprecated. Use Partitions() instead.')
     4882    n = ZZ(n)
     4883    # base case of the recursion: zero is the sum of the empty tuple
     4884    if n == 0:
     4885        yield ( )
     4886        return
     4887    # modify the partitions of n-1 to form the partitions of n
     4888    for p in partitions(n-1):
     4889        yield (1,) + p
     4890        if p and (len(p) < 2 or p[1] > p[0]):
     4891            yield (p[0] + 1,) + p[1:]
     4892
     4893
    48674894def ferrers_diagram(pi):
    48684895    """
    48694896    Return the Ferrers diagram of pi.
    def ferrers_diagram(pi): 
    48904917def ordered_partitions(n,k=None):
    48914918    r"""
    48924919    An ordered partition of `n` is an ordered sum
    4893    
     4920
    48944921    .. math::
    4895    
    4896                 n = p_1+p_2 + \cdots + p_k     
    4897    
    4898    
     4922
     4923                n = p_1+p_2 + \cdots + p_k
     4924
     4925
    48994926    of positive integers and is represented by the list
    49004927    `p = [p_1,p_2,\cdots ,p_k]`. If `k` is omitted
    49014928    then all ordered partitions are returned.
    4902    
     4929
    49034930    ``ordered_partitions(n,k)`` returns the list of all
    49044931    (ordered) partitions of the positive integer n into sums with k
    49054932    summands.
    4906    
     4933
    49074934    Do not call ``ordered_partitions`` with an n much
    49084935    larger than 15, since the list will simply become too large.
    4909    
     4936
    49104937    Wraps GAP's OrderedPartitions.
    4911    
     4938
    49124939    The number of ordered partitions `T_n` of
    49134940    `\{ 1, 2, ..., n \}` has the generating function is
    4914    
     4941
    49154942    .. math::
    49164943   
    49174944             \sum_n {T_n \over n!} x^n = {1 \over 2-e^x}.     
    49184945   
    4919    
    4920    
    49214946    EXAMPLES::
    49224947   
     4948        sage: from sage.combinat.partition import ordered_partitions
    49234949        sage: ordered_partitions(10,2)
     4950        doctest:1: DeprecationWarning: ordered_partitions is deprecated. Use OrderedPartitions instead.
     4951        See http://trac.sagemath.org/13072 for details.
    49244952        [[1, 9], [2, 8], [3, 7], [4, 6], [5, 5], [6, 4], [7, 3], [8, 2], [9, 1]]
    49254953   
    49264954    ::
    def ordered_partitions(n,k=None): 
    49324960
    49334961    - http://en.wikipedia.org/wiki/Ordered_partition_of_a_set
    49344962    """
     4963    from sage.misc.superseded import deprecation
     4964    deprecation(13072,'ordered_partitions is deprecated. Use OrderedPartitions instead.')
    49354965    if k is None:
    49364966        ans=gap.eval("OrderedPartitions(%s)"%(ZZ(n)))
    49374967    else:
    def number_of_ordered_partitions(n,k=Non 
    49424972    """
    49434973    Returns the size of ordered_partitions(n,k). Wraps GAP's
    49444974    NrOrderedPartitions.
    4945    
     4975
    49464976    It is possible to associate with every partition of the integer n a
    49474977    conjugacy class of permutations in the symmetric group on n points
    49484978    and vice versa. Therefore p(n) = NrPartitions(n) is the number of
    def number_of_ordered_partitions(n,k=Non 
    49504980   
    49514981    EXAMPLES::
    49524982   
     4983        sage: from sage.combinat.partition import number_of_ordered_partitions
    49534984        sage: number_of_ordered_partitions(10,2)