Ticket #15350: trac_15350-partitions-et-al-dg.patch

File trac_15350-partitions-et-al-dg.patch, 57.0 KB (added by Darij Grinberg, 9 years ago)

updated: one typo in docstring fixed

  • sage/combinat/partition.py

    # HG changeset patch
    # User darij grinberg <darijgrinberg@gmail.com>
    # Date 1383465089 25200
    # Node ID a9e302f1751bb3fbec1066e784ece7bf502c730f
    # Parent  8f48ebf71e082817f941548c11276c5d76a80096
    trac #15350: various improvements to partitions and related files
    
    diff --git a/sage/combinat/partition.py b/sage/combinat/partition.py
    a b  
    11r"""
    22Partitions
    33
    4 A partition `p` of a nonnegative integer `n` is at
     4A partition `p` of a nonnegative integer `n` is a
    55non-increasing list of positive integers (the *parts* of the
    66partition) with total sum `n`.
    77
    For display options, see :obj:`Partition 
    3131      its conjugate partition by `\lambda^{\prime}`. For more on conjugate
    3232      partitions, see :meth:`Partition.conjugate()`.
    3333
    34     - The comparisons on partitions uses lexicographic order.
     34    - The comparisons on partitions use lexicographic order.
    3535
    3636.. NOTE::
    3737
    AUTHORS: 
    6363
    6464EXAMPLES:
    6565
    66 There are 5 partitions of the integer 4::
     66There are `5` partitions of the integer `4`::
    6767
    6868    sage: Partitions(4).cardinality()
    6969    5
    When we are at the last partition, ``Non 
    8484    sage: Partitions(4).next([1,1,1,1]) is None
    8585    True
    8686
    87 We can use ``iter`` to get an object which iterates over the partitions one
    88 by one to save memory.  Note that when we do something like
     87We can use ``iter`` to get an object which iterates over the partitions
     88one by one to save memory.  Note that when we do something like
    8989``for part in Partitions(4)`` this iterator is used in the background::
    9090
    9191    sage: g = iter(Partitions(4))
    by one to save memory. Note that when w 
    102102    [2, 1, 1]
    103103    [1, 1, 1, 1]
    104104
    105 We can add constraints to to the type of partitions we want. For
    106 example, to get all of the partitions of 4 of length 2, we'd do the
     105We can add constraints to the type of partitions we want. For
     106example, to get all of the partitions of `4` of length `2`, we'd do the
    107107following::
    108108
    109109    sage: Partitions(4, length=2).list()
    110110    [[3, 1], [2, 2]]
    111111
    112 Here is the list of partitions of length at least 2 and the list of
    113 ones with length at most 2::
     112Here is the list of partitions of length at least `2` and the list of
     113ones with length at most `2`::
    114114
    115115    sage: Partitions(4, min_length=2).list()
    116116    [[3, 1], [2, 2], [2, 1, 1], [1, 1, 1, 1]]
    ones with length at most 2:: 
    120120The options ``min_part`` and ``max_part`` can be used to set constraints
    121121on the sizes of all parts. Using ``max_part``, we can select
    122122partitions having only 'small' entries. The following is the list
    123 of the partitions of 4 with parts at most 2::
     123of the partitions of `4` with parts at most `2`::
    124124
    125125    sage: Partitions(4, max_part=2).list()
    126126    [[2, 2], [2, 1, 1], [1, 1, 1, 1]]
    127127
    128128The ``min_part`` options is complementary to ``max_part`` and selects
    129129partitions having only 'large' parts. Here is the list of all
    130 partitions of 4 with each part at least 2::
     130partitions of `4` with each part at least `2`::
    131131
    132132    sage: Partitions(4, min_part=2).list()
    133133    [[4], [2, 2]]
    134134
    135135The options ``inner`` and ``outer`` can be used to set part-by-part
    136 constraints. This is the list of partitions of 4 with ``[3, 1, 1]`` as
    137 an outer bound::
     136constraints. This is the list of partitions of `4` with ``[3, 1, 1]`` as
     137an outer bound (that is, partitions of `4` contained in the partition
     138``[3, 1, 1]``)::
    138139
    139140    sage: Partitions(4, outer=[3,1,1]).list()
    140141    [[3, 1], [2, 1, 1]]
    141142
    142143``outer`` sets ``max_length`` to the length of its argument. Moreover, the
    143 parts of outer may be infinite to clear constraints on specific
    144 parts. Here is the list of the partitions of 4 of length at most 3
    145 such that the second and third part are 1 when they exist::
     144parts of ``outer`` may be infinite to clear constraints on specific
     145parts. Here is the list of the partitions of `4` of length at most `3`
     146such that the second and third part are `1` when they exist::
    146147
    147148    sage: Partitions(4, outer=[oo,1,1]).list()
    148149    [[4], [3, 1], [2, 1, 1]]
    149150
    150 Finally, here are the partitions of 4 with ``[1,1,1]`` as an inner
    151 bound. Note that inner sets ``min_length`` to the length of its
    152 argument::
     151Finally, here are the partitions of `4` with ``[1,1,1]`` as an inner
     152bound (i. e., the partitions of `4` containing the partition ``[1,1,1]``).
     153Note that ``inner`` sets ``min_length`` to the length of its argument::
    153154
    154155    sage: Partitions(4, inner=[1,1,1]).list()
    155156    [[2, 1, 1], [1, 1, 1, 1]]
    argument:: 
    157158The options ``min_slope`` and ``max_slope`` can be used to set
    158159constraints on the slope, that is on the difference ``p[i+1]-p[i]`` of
    159160two consecutive parts. Here is the list of the strictly decreasing
    160 partitions of 4::
     161partitions of `4`::
    161162
    162163    sage: Partitions(4, max_slope=-1).list()
    163164    [[4], [3, 1]]
    164165
    165166The constraints can be combined together in all reasonable ways.
    166 Here are all the partitions of 11 of length between 2 and 4 such
    167 that the difference between two consecutive parts is between -3 and
    168 -1::
     167Here are all the partitions of `11` of length between `2` and `4` such
     168that the difference between two consecutive parts is between `-3` and
     169`-1`::
    169170
    170171    sage: Partitions(11,min_slope=-3,max_slope=-1,min_length=2,max_length=4).list()
    171172    [[7, 4], [6, 5], [6, 4, 1], [6, 3, 2], [5, 4, 2], [5, 3, 2, 1]]
    If we create a partition with extra zero 
    190191
    191192    sage: Partition([4,1,0,0])
    192193    [4, 1]
    193 
    194 The idea of a partition being followed by infinitely many parts of size 0 is
    195 consistent with the ``get_part`` method::
     194    sage: Partition([0])
     195    []
     196    sage: Partition([0,0])
     197    []
     198
     199The idea of a partition being followed by infinitely many parts of size
     200`0` is consistent with the ``get_part`` method::
    196201
    197202    sage: p = Partition([5, 2])
    198203    sage: p.get_part(0)
    consistent with the ``get_part`` method: 
    200205    sage: p.get_part(10)
    201206    0
    202207
    203 We can go back and forth between the exponential notations of a
    204 partition. The exponential notation can be padded with extra
    205 zeros::
     208We can go back and forth between the standard and the exponential
     209notations of a partition. The exponential notation can be padded with
     210extra zeros::
    206211
    207212    sage: Partition([6,4,4,2,1]).to_exp()
    208213    [1, 1, 0, 2, 0, 1]
    zeros:: 
    215220    sage: Partition([6,4,4,2,1]).to_exp(10)
    216221    [1, 1, 0, 2, 0, 1, 0, 0, 0, 0]
    217222
    218 We can get the coordinates of the corners of a partition::
     223We can get the (zero-based!) coordinates of the corners of a
     224partition::
    219225
    220226    sage: Partition([4,3,1]).corners()
    221227    [(0, 3), (1, 2), (2, 0)]
    class Partition(CombinatorialObject, Ele 
    953959
    954960    def _latex_young_diagram(self):
    955961        r"""
    956         LaTeX output as a young diagram.
     962        LaTeX output as a Young diagram.
    957963
    958964        EXAMPLES::
    959965
    class Partition(CombinatorialObject, Ele 
    10681074        r"""
    10691075        Prints the Ferrers diagram.
    10701076
    1071         See :meth:`ferrers_diagram` for more on the ferrers diagram.
     1077        See :meth:`ferrers_diagram` for more on the Ferrers diagram.
    10721078
    10731079        EXAMPLES::
    10741080
    class Partition(CombinatorialObject, Ele 
    11161122        with cycle type ``self`` (thus describes the powermap of
    11171123        symmetric groups).
    11181124
    1119         Wraps GAP's ``PowerPartition``.
     1125        Equivalent to GAP's ``PowerPartition``.
    11201126
    11211127        EXAMPLES::
    11221128
    class Partition(CombinatorialObject, Ele 
    13791385            else:
    13801386                yield Partition(p[:-1] + [ p[-1] - 1 ])
    13811387
    1382 
    13831388    def down_list(self):
    13841389        """
    13851390        Return a list of the partitions that can be obtained from ``self``
    class Partition(CombinatorialObject, Ele 
    14291434        return (a,b)
    14301435
    14311436    def frobenius_rank(self):
    1432         """
    1433         Return the Frobenius rank of the partition.
    1434 
    1435         The Frobenius rank is the number of cells on the main diagonal.
     1437        r"""
     1438        Return the Frobenius rank of the partition ``self``.
     1439
     1440        The Frobenius rank of a partition
     1441        `\lambda = (\lambda_1, \lambda_2, \lambda_3, \cdots)` is
     1442        defined to be the largest `i` such that `\lambda_i \geq i`.
     1443        In other words, it is the number of cells on the main diagonal
     1444        of `\lambda`. In yet other words, it is the size of the largest
     1445        square fitting into the Young diagram of `\lambda`.
    14361446
    14371447        EXAMPLES::
    14381448
    class Partition(CombinatorialObject, Ele 
    14481458            1
    14491459            sage: Partition([2,2,1,1,1,1]).frobenius_rank()
    14501460            2
    1451         """
    1452         mu = self
    1453         if mu.is_empty():
    1454             return 0
    1455         if len(mu) <= mu[0]:
    1456             return len(filter(lambda x: x>=0, [val-i-1 for i, val in enumerate(mu)]))
    1457         else:
    1458             muconj = mu.conjugate()
    1459             return len(filter(lambda x: x>=0, [val-i-1 for i, val in enumerate(muconj)]))
    1460 
     1461            sage: Partition([3,2]).frobenius_rank()
     1462            2
     1463            sage: Partition([3,2,2]).frobenius_rank()
     1464            2
     1465            sage: Partition([8,4,4,4,4]).frobenius_rank()
     1466            4
     1467            sage: Partition([8,4,1]).frobenius_rank()
     1468            2
     1469            sage: Partition([3,3,1]).frobenius_rank()
     1470            2
     1471        """
     1472        for i, x in enumerate(self):
     1473            if x <= i:
     1474                return i
     1475        return len(self)
    14611476
    14621477    def beta_numbers(self, length=None):
    14631478        """
    class Partition(CombinatorialObject, Ele 
    14741489            [6, 4, 2]
    14751490            sage: Partition([4,3,2]).beta_numbers(5)
    14761491            [8, 6, 4, 1, 0]
    1477 
    1478         """
    1479         if length==None: length=self.length()
    1480         elif length<self.length():
    1481             raise ValueError("length must at least the length of the partition")
    1482         beta = [self.hook_lengths()[row][0]+length-self.length() for row in range(self.length())]
    1483         if length > self.length(): beta.extend( range(length-self.length()-1,-1,-1) )
     1492            sage: Partition([]).beta_numbers()
     1493            []
     1494            sage: Partition([]).beta_numbers(3)
     1495            [2, 1, 0]
     1496            sage: Partition([6,4,1,1]).beta_numbers()
     1497            [9, 6, 2, 1]
     1498            sage: Partition([6,4,1,1]).beta_numbers(6)
     1499            [11, 8, 4, 3, 1, 0]
     1500            sage: Partition([1,1,1]).beta_numbers()
     1501            [3, 2, 1]
     1502            sage: Partition([1,1,1]).beta_numbers(4)
     1503            [4, 3, 2, 0]
     1504        """
     1505        true_length = len(self)
     1506        if length == None:
     1507            length = true_length
     1508        elif length < true_length:
     1509            raise ValueError("length must be at least the length of the partition")
     1510        beta = [l + length - i - 1 for (i, l) in enumerate(self)]
     1511        if length > true_length:
     1512            beta.extend( range(length-true_length-1,-1,-1) )
    14841513        return beta
    14851514
     1515    def crank(self):
     1516        r"""
     1517        Return the Dyson crank of ``self``.
     1518
     1519        The Dyson crank of a partition `\lambda` is defined as follows:
     1520        If `\lambda` contains at least one `1`, then the crank is
     1521        `\mu(\lambda) - \omega(\lambda)`, where `\omega(\lambda)` is the
     1522        number of `1`s in `\lambda`, and `\mu(\lambda)` is the number of
     1523        parts of `\lambda` larger than `\omega(\lambda)`. If `\lambda`
     1524        contains no `1`, then the crank is simply the largest part of
     1525        `\lambda`.
     1526
     1527        REFERENCES:
     1528
     1529        .. [AG1988] George E. Andrews, F. G. Garvan,
     1530           *Dyson's crank of a partition*.
     1531           Bull. Amer. Math. Soc. (N.S.) Volume 18, Number 2 (1988),
     1532           167-171.
     1533           http://projecteuclid.org/euclid.bams/1183554533
     1534
     1535        EXAMPLES::
     1536
     1537            sage: Partition([]).crank()
     1538            0
     1539            sage: Partition([3,2,2]).crank()
     1540            3
     1541            sage: Partition([5,4,2,1,1]).crank()
     1542            0
     1543            sage: Partition([1,1,1]).crank()
     1544            -3
     1545            sage: Partition([6,4,4,3]).crank()
     1546            6
     1547            sage: Partition([6,3,3,1,1]).crank()
     1548            1
     1549            sage: Partition([6]).crank()
     1550            6
     1551            sage: Partition([5,1]).crank()
     1552            0
     1553            sage: Partition([4,2]).crank()
     1554            4
     1555            sage: Partition([4,1,1]).crank()
     1556            -1
     1557            sage: Partition([3,3]).crank()
     1558            3
     1559            sage: Partition([3,2,1]).crank()
     1560            1
     1561            sage: Partition([3,1,1,1]).crank()
     1562            -3
     1563            sage: Partition([2,2,2]).crank()
     1564            2
     1565            sage: Partition([2,2,1,1]).crank()
     1566            -2
     1567            sage: Partition([2,1,1,1,1]).crank()
     1568            -4
     1569            sage: Partition([1,1,1,1,1,1]).crank()
     1570            -6
     1571        """
     1572        l = len(self)
     1573        if l == 0:
     1574            return 0
     1575        if self[-1] > 1:
     1576            return self[0]
     1577        ind_1 = self.index(1)
     1578        w = l - ind_1      # w is omega(self).
     1579        m = len([x for x in self if x > w])
     1580        return m - w
     1581
    14861582    def larger_lex(self, rhs):
    14871583        """
    14881584        Return ``True`` if ``self`` is larger than ``rhs`` in lexicographic
    class Partition(CombinatorialObject, Ele 
    15771673        """
    15781674        res = 1
    15791675        for (i,j) in self.cells():
    1580             res *= (a - (i-1)/alpha+j-1)
     1676            res *= (a - (i-1)/alpha + j-1)
    15811677        return res
    15821678
    15831679    def get_part(self, i, default=Integer(0)):
    class Partition(CombinatorialObject, Ele 
    17901886           http://www.sciencedirect.com/science/article/pii/S0195669801905414
    17911887        """
    17921888        # Check for valid input
    1793         if len(self) > 0 and len(self) + self._list[0] - 1 >= n: # -1 since we double count the (0,0) cell
     1889        if len(self) > 0 and len(self) + self._list[0] > n: # >, not >=, since we double count the (0,0) cell
    17941890            raise ValueError("the hook length must be less than n")
    17951891        ret = self
    17961892        # Arbitrary exp
    class Partition(CombinatorialObject, Ele 
    24752571
    24762572    def upper_hook(self, i, j, alpha):
    24772573        r"""
    2478         Return the upper hook length of the cell `(i,j)` in self. When ``alpha
    2479         = 1``, this is just the normal hook length.
     2574        Return the upper hook length of the cell `(i,j)` in ``self``.
     2575        When ``alpha = 1``, this is just the normal hook length.
    24802576
    24812577        The upper hook length of a cell `(i,j)` in a partition
    24822578        `\kappa` is defined by
    24832579
    24842580        .. MATH::
    24852581
    2486             h_*^\kappa(i,j) = \kappa_j^\prime-i+\alpha(\kappa_i - j+1).
     2582            h^*_\kappa(i,j) = \kappa^\prime_j - i + \alpha(\kappa_i - j + 1).
    24872583
    24882584        EXAMPLES::
    24892585
    class Partition(CombinatorialObject, Ele 
    24972593        """
    24982594        p = self
    24992595        conj = self.conjugate()
    2500         return conj[j]-(i+1)+alpha*(p[i]-(j+1)+1)
     2596        return conj[j] - (i+1) + alpha*(p[i]-j)
    25012597
    25022598    def upper_hook_lengths(self, alpha):
    25032599        r"""
    class Partition(CombinatorialObject, Ele 
    25102606
    25112607        .. MATH::
    25122608
    2513             h_*^\kappa(i,j) = \kappa_j^\prime-i+1+\alpha(\kappa_i - j).
     2609            h^*_\kappa(i,j) = \kappa^\prime_j - i + \alpha(\kappa_i - j + 1).
    25142610
    25152611        EXAMPLES::
    25162612
    class Partition(CombinatorialObject, Ele 
    25232619        """
    25242620        p = self
    25252621        conj = p.conjugate()
    2526         return [[conj[j]-(i+1)+alpha*(p[i]-(j+1)+1) for j in range(p[i])] for i in range(len(p))]
     2622        return [[conj[j] - (i+1) + alpha*(p[i]-j) for j in range(p[i])] for i in range(len(p))]
    25272623
    25282624    def lower_hook(self, i, j, alpha):
    25292625        r"""
    2530         Return the lower hook length of the cell `(i,j)` in ``self``. When
    2531         ``alpha = 1``, this is just the normal hook length.
     2626        Return the lower hook length of the cell `(i,j)` in ``self``.
     2627        When ``alpha = 1``, this is just the normal hook length.
    25322628
    25332629        The lower hook length of a cell `(i,j)` in a partition
    25342630        `\kappa` is defined by
    25352631
    25362632        .. MATH::
    25372633
    2538             h_*^\kappa(i,j) = \kappa_j^\prime-i+1+\alpha(\kappa_i - j).
     2634            h_*^\kappa(i,j) = \kappa^\prime_j - i + 1 + \alpha(\kappa_i - j).
    25392635
    25402636        EXAMPLES::
    25412637
    class Partition(CombinatorialObject, Ele 
    25492645        """
    25502646        p = self
    25512647        conj = self.conjugate()
    2552         return conj[j]-(i+1)+1+alpha*(p[i]-(j+1))
    2553 
     2648        return conj[j] - i + alpha*(p[i] - (j+1))
    25542649
    25552650    def lower_hook_lengths(self, alpha):
    25562651        r"""
    class Partition(CombinatorialObject, Ele 
    25632658
    25642659        .. MATH::
    25652660
    2566             h_\kappa^*(i,j) = \kappa_j^\prime-i+\alpha(\kappa_i - j + 1).
     2661            h_*^\kappa(i,j) = \kappa^\prime_j - i + 1 + \alpha(\kappa_i - j).
    25672662
    25682663        EXAMPLES::
    25692664
    class Partition(CombinatorialObject, Ele 
    25762671        """
    25772672        p = self
    25782673        conj = p.conjugate()
    2579         return [[conj[j]-(i+1)+1+alpha*(p[i]-(j+1)) for j in range(p[i])] for i in range(len(p))]
     2674        return [[conj[j] - i + alpha*(p[i]-(j+1)) for j in range(p[i])] for i in range(len(p))]
    25802675
    25812676
    25822677    def weighted_size(self):
    class Partition(CombinatorialObject, Ele 
    25872682
    25882683        .. MATH::
    25892684
    2590             \sum_i i * \lambda_i.
     2685            \sum_i i \cdot \lambda_i,
     2686
     2687        where `\lambda = (\lambda_0, \lambda_1, \lambda_2, \cdots )`.
    25912688
    25922689        This also the sum of the leg length of every cell in `\lambda`, or
    25932690
    class Partition(CombinatorialObject, Ele 
    25952692
    25962693            \sum_i \binom{\lambda^{\prime}_i}{2}
    25972694
    2598         where `\lambda^{\prime}` the conjugate partition of `\lambda`.
     2695        where `\lambda^{\prime}` is the conjugate partition of `\lambda`.
    25992696
    26002697        EXAMPLES::
    26012698
    class Partition(CombinatorialObject, Ele 
    26052702            9
    26062703            sage: Partition([5,2]).weighted_size()
    26072704            2
     2705            sage: Partition([]).weighted_size()
     2706            0
    26082707        """
    26092708        p = self
    26102709        return sum([i*p[i] for i in range(len(p))])
    class Partition(CombinatorialObject, Ele 
    26632762        Return the evaluation of ``self``.
    26642763
    26652764        The **commutative evaluation**, often shortened to **evaluation**, of
    2666         a word (we think of a partition as a word in `\{0, 1, 2, \ldots\}`)
     2765        a word (we think of a partition as a word in `\{1, 2, 3, \ldots\}`)
    26672766        is its image in the free commutative monoid. In other words,
    2668         this counts how many occurrances there are of each letter.
     2767        this counts how many occurrences there are of each letter.
    26692768
    26702769        This is also is known as **Parikh vector** and **abelianization** and
    26712770        has the same output as :meth:`to_exp()`.
    class Partition(CombinatorialObject, Ele 
    27262825            8
    27272826            sage: Partition([2,2,2]).centralizer_size()
    27282827            48
     2828            sage: Partition([2,2,1]).centralizer_size(q=2, t=3)
     2829            9/16
     2830            sage: Partition([]).centralizer_size()
     2831            1
     2832            sage: Partition([]).centralizer_size(q=2, t=4)
     2833            1
    27292834        """
    27302835        p = self
    27312836        a = p.to_exp()
    27322837        size = prod([(i+1)**a[i]*factorial(a[i]) for i in range(len(a))])
    2733         size *= prod( [ (1-q**p[i])/(1-t**p[i]) for i in range(len(p)) ] )
     2838        size *= prod( [ (1-q**j)/(1-t**j) for j in p ] )
    27342839
    27352840        return size
    27362841
    class Partition(CombinatorialObject, Ele 
    27402845        ``self``.
    27412846
    27422847        This method returns `1^{j_1}j_1! \cdots n^{j_n}j_n!` where
    2743         `j_k` is the number of parts in self equal to `k`.
     2848        `j_k` is the number of parts in ``self`` equal to `k`.
    27442849
    27452850        The number of permutations having ``self`` as a cycle type is
    27462851        given by
    27472852
    27482853        .. MATH::
    27492854
    2750             \frac{n!}{1^{j_1}j_1! \cdots n^{j_n}j_n!} .
     2855            \frac{n!}{1^{j_1}j_1! \cdots n^{j_n}j_n!}
     2856
     2857        (where `n` is the size of ``self``).
    27512858
    27522859        EXAMPLES::
    27532860
    class Partition(CombinatorialObject, Ele 
    27652872
    27662873        For consistency with partition tuples there is also an optional
    27672874        ``multicharge`` argument which is an offset to the usual content. By
    2768         setting the ``multicharge`` equal to the 0-element the ring `\ZZ/e\ZZ`
    2769         the corresponding `e`-residue will be returned. This is the content
    2770         modulo `e`.
     2875        setting the ``multicharge`` equal to the 0-element of the ring
     2876        `\ZZ/e\ZZ`, the corresponding `e`-residue will be returned. This is
     2877        the content modulo `e`.
    27712878
    27722879        The content (and residue) do not strictly depend on the partition,
    27732880        however, this method is included because it is often useful in the
    class Partition(CombinatorialObject, Ele 
    30423149
    30433150    def zero_one_sequence(self):
    30443151        r"""
    3045         Computes the finite `0-1` sequence of the partition.
     3152        Compute the finite `0-1` sequence of the partition.
    30463153
    30473154        The full `0-1` sequence is the sequence (infinite in both
    30483155        directions) indicating the steps taken when following the
    class Partition(CombinatorialObject, Ele 
    30683175        The finite `0-1` sequence is obtained from the full `0-1`
    30693176        sequence by omitting all heading 0's and trailing 1's. The
    30703177        output sequence is finite, starts with a 1 and ends with a
    3071         0 (unless it is empty, for the empty partition).
     3178        0 (unless it is empty, for the empty partition). Its length
     3179        is the sum of the first part of the partition with the
     3180        length of the partition.
    30723181
    30733182        REFERENCES:
    30743183
    class Partition(CombinatorialObject, Ele 
    30903199            sage: all(Partitions().from_zero_one(mu.zero_one_sequence()) == mu for n in range(10) for mu in Partitions(n))
    30913200            True
    30923201        """
    3093         tmp = [self.get_part(i)-i for i in range(len(self))]
     3202        tmp = [self[i]-i for i in range(len(self))]
    30943203        return ([Integer(not (i in tmp)) for i in range(-len(self)+1,self.get_part(0)+1)])
    30953204
    30963205    def core(self, length):
    3097         """
    3098         Return the core of the partition -- in the literature the core is
    3099         commonly referred to as the `k`-core, `p`-core, `r`-core, ... . The
    3100         construction of the core can be visualized by repeatedly removing
    3101         border strips of size `r` from ``self`` until this is no longer
    3102         possible. The remaining partition is the core.
     3206        r"""
     3207        Return the ``length``-core of the partition -- in the literature
     3208        the core is commonly referred to as the `k`-core, `p`-core,
     3209        `r`-core, ... .
     3210
     3211        The `r`-core of a partition `\lambda` can be obtained by
     3212        repeatedly removing rim hooks of size `r` from (the Young diagram
     3213        of) `\lambda` until this is no longer possible. The remaining
     3214        partition is the core.
    31033215
    31043216        EXAMPLES::
    31053217
    class Partition(CombinatorialObject, Ele 
    31423254        return Partition(filter(lambda x: x != 0, part))
    31433255
    31443256    def quotient(self, length):
    3145         """
     3257        r"""
    31463258        Return the quotient of the partition  -- in the literature the
    3147         core is commonly referred to as the `k`-core, `p`-core, `r`-core, ... .
    3148         The quotient is a list of `r` partitions, constructed in the following
    3149         way. Label each cell in `p` with its content, modulo `r`. Let `R_i` be
    3150         the set of rows ending in a cell labelled `i`, and `C_i` be the set of
    3151         columns ending in a cell labelled `i`. Then the `j`-th component of the
    3152         quotient of `p` is the partition defined by intersecting `R_j` with
    3153         `C_j+1`.
     3259        quotient is commonly referred to as the `k`-quotient, `p`-quotient,
     3260        `r`-quotient, ... .
     3261
     3262        The `r`-quotient of a partition `\lambda` is a list of `r`
     3263        partitions (labelled from `0` to `r-1`), constructed in the following
     3264        way. Label each cell in the Young diagram of `\lambda` with its
     3265        content modulo `r`. Let `R_i` be the set of rows ending in a cell
     3266        labelled `i`, and `C_i` be the set of columns ending in a cell
     3267        labelled `i`. Then the `j`-th component of the quotient of
     3268        `\lambda` is the partition defined by intersecting `R_j` with
     3269        `C_{j+1}`. (See Theorem 2.7.37 in [JamesKerber]_.)
     3270
     3271        REFERENCES:
     3272
     3273        .. [JamesKerber] Gordon James, Adalbert Kerber,
     3274           *The Representation Theory of the Symmetric Group*,
     3275           Encyclopedia of Mathematics and its Applications, vol. 16,
     3276           Addison-Wesley 1981.
    31543277
    31553278        EXAMPLES::
    31563279
    class Partition(CombinatorialObject, Ele 
    31773300            ([3, 3], [2, 2, 1], [], [3, 3, 3], [1])
    31783301
    31793302            sage: all(p == Partition(core=p.core(k), quotient=p.quotient(k))
    3180             ...       for i in range(10) for p in Partitions(i)
    3181             ...       for k in range(1,6))
     3303            ....:     for i in range(10) for p in Partitions(i)
     3304            ....:     for k in range(1,6))
    31823305            True
    31833306        """
    31843307        p = self
    class Partition(CombinatorialObject, Ele 
    31863309        remainder = len(p) % length
    31873310        part = p[:] + [0]*(length-remainder)
    31883311
    3189 
    31903312        #Add the canonical vector to the partition
    31913313        part = [part[i-1] + len(part)-i for i in range(1, len(part)+1)]
    31923314        result = [None]*length
    class Partition(CombinatorialObject, Ele 
    32133335        be checked by trying to remove border strips of size `k` from ``self``.
    32143336        If this is not possible, then ``self`` is a `k`-core.
    32153337
     3338        A partition is said to be a *`k`-core* if it has no hooks of length
     3339        `k`. Equivalently, a partition is said to be a `k`-core if it is its
     3340        own `k`-core (where the latter is defined as in :meth:`core`).
     3341
    32163342        EXAMPLES::
    32173343
    32183344            sage: p = Partition([12,8,5,5,2,2,1])
    class Partition(CombinatorialObject, Ele 
    32273353
    32283354    def k_interior(self, k):
    32293355        r"""
    3230         Return the partition consisting of the cells of ``self``, whose hook
     3356        Return the partition consisting of the cells of ``self`` whose hook
    32313357        lengths are greater than ``k``.
    32323358
    32333359        EXAMPLES::
    class Partition(CombinatorialObject, Ele 
    32683394
    32693395    def add_cell(self, i, j = None):
    32703396        r"""
    3271         Return a partition corresponding to self with a cell added in row
    3272         ``i``. This does not change ``self``.
     3397        Return a partition corresponding to ``self`` with a cell added in
     3398        row ``i``. (This does not change ``self``.)
    32733399
    32743400        EXAMPLES::
    32753401
    class Partition(CombinatorialObject, Ele 
    32993425    def remove_cell(self, i, j = None):
    33003426        """
    33013427        Return the partition obtained by removing a cell at the end of row
    3302         ``i``.
     3428        ``i`` of ``self``.
    33033429
    33043430        EXAMPLES::
    33053431
    class Partition(CombinatorialObject, Ele 
    35963722                    iv[t] -= 1
    35973723                    j += 1
    35983724                j = sum(shelf[:t+1])
    3599             res.append(Partition([i for i in tmp if i != 0]).conjugate())
     3725            res.append(Partition([u for u in tmp if u != 0]).conjugate())
    36003726        return res
    36013727
    36023728    def remove_horizontal_border_strip(self, k):
    class Partition(CombinatorialObject, Ele 
    36883814
    36893815        .. MATH::
    36903816
    3691             \frac{ 1 - q^a * t^{\ell + 1} }{ 1 - q^{a + 1} * t^{\ell} }
     3817            \frac{ 1 - q^a \cdot t^{\ell + 1} }{ 1 - q^{a + 1} \cdot t^{\ell} }
    36923818
    36933819        where `a` is the arm length of `c` and `\ell` is the leg length of `c`.
    36943820
     3821        The coordinates ``i`` and ``j`` of the cell are understood to be
     3822        `0`-based, so that ``(0, 0)`` is the northwesternmost cell (in
     3823        English notation).
     3824
    36953825        EXAMPLES::
    36963826
    36973827            sage: Partition([3,2,1]).arms_legs_coeff(1,1)
    class Partition(CombinatorialObject, Ele 
    37083838            res /= (1-q**(self.arm_length(i,j)+1) * t**self.leg_length(i,j))
    37093839            return res
    37103840        else:
    3711             return ZZ(1)
     3841            return ZZ.one()
    37123842
    37133843    def atom(self):
    37143844        """
    class Partition(CombinatorialObject, Ele 
    37993929
    38003930    def jacobi_trudi(self):
    38013931        """
    3802         Return the Jacobi-Trudi polynomial of ``self`` thought of as a skew
     3932        Return the Jacobi-Trudi matrix of ``self`` thought of as a skew
    38033933        partition. See :meth:`SkewPartition.jacobi_trudi()
    38043934        <sage.combinat.skew_partition.SkewPartition_class.jacobi_trudi>`.
    38053935
    class Partition(CombinatorialObject, Ele 
    38223952
    38233953    def character_polynomial(self):
    38243954        r"""
    3825         Return the character polynomial associated to the partition ``self``.
    3826 
    3827         The character polynomial `q_\mu` is defined by
     3955        Return the character polynomial associated to the partition
     3956        ``self``.
     3957
     3958        The character polynomial `q_\mu` associated to a partition `\mu`
     3959        is defined by
    38283960
    38293961        .. MATH::
    38303962
    class Partition(CombinatorialObject, Ele 
    38323964            \frac{ \chi^\mu_\alpha }{1^{a_1}2^{a_2}\cdots k^{a_k}a_1!a_2!\cdots
    38333965            a_k!} \prod_{i=1}^{k} (ix_i-1)^{a_i}
    38343966
    3835         where `a_i` is the multiplicity of `i` in `\alpha`.
     3967        where `k` is the size of `\mu`, and `a_i` is the multiplicity of
     3968        `i` in `\alpha`.
    38363969
    38373970        It is computed in the following manner:
    38383971
    class Partition(CombinatorialObject, Ele 
    39574090
    39584091        REFERENCES:
    39594092
    3960         .. [ORV] Olshanski, Regev, Vershik, "Frobenius-Schur functions"
     4093        .. [ORV] Grigori Olshanski, Amitai Regev, Anatoly Vershik,
     4094           *Frobenius-Schur functions*,
     4095           :arxiv:`math/0110077v1`.
     4096           Possibly newer version at
     4097           http://www.wisdom.weizmann.ac.il/~regev/papers/FrobeniusSchurFunctions.ps
    39614098
    39624099        AUTHORS:
    39634100
    Partition_class = deprecated_function_al 
    40744211class Partitions(UniqueRepresentation, Parent):
    40754212    r"""
    40764213    ``Partitions(n, **kwargs)`` returns the combinatorial class of
    4077     integer partitions of `n`, and subject to the constraints given by the
     4214    integer partitions of `n` subject to the constraints given by the
    40784215    keywords.
    40794216
    40804217    Valid keywords are: ``starting``, ``ending``, ``min_part``,
    class Partitions(UniqueRepresentation, P 
    41074244      `k`; the slope is the difference between successive parts.
    41084245
    41094246    - ``parts_in=S`` specifies that the partitions have parts in the set
    4110       `S`, which can be any sequence of positive integers.
     4247      `S`, which can be any sequence of pairwise distinct positive
     4248      integers.
    41114249
    41124250    The ``max_*`` versions, along with ``inner`` and ``ending``, work
    41134251    analogously.
    class Partitions_n(Partitions): 
    48324970
    48334971    def __contains__(self, x):
    48344972        """
    4835         Checks if ``x`` is contained in ``self``.
    4836 
    4837          TESTS::
     4973        Check if ``x`` is contained in ``self``.
     4974
     4975        TESTS::
    48384976
    48394977            sage: p = Partitions(5)
    48404978            sage: [2,1] in p
    class Partitions_n(Partitions): 
    48434981            True
    48444982            sage: [3,2] in p
    48454983            True
     4984            sage: [2,3] in p
     4985            False
    48464986        """
    48474987        return x in _Partitions and sum(x) == self.n
    48484988
    class Partitions_n(Partitions): 
    49425082           \sum_{n=0}^{\infty} p_n x^n = \prod_{k=1}^{\infty} \left( \frac{1}{1-x^k} \right).
    49435083
    49445084        We use Sage to verify that the first several coefficients do
    4945         instead agree::
     5085        indeed agree::
    49465086
    49475087            sage: q = PowerSeriesRing(QQ, 'q', default_prec=9).gen()
    49485088            sage: prod([(1-q^k)^(-1) for k in range(1,9)])  ## partial product of
    class Partitions_n(Partitions): 
    49985138
    49995139    def random_element_uniform(self):
    50005140        """
    5001         Return a random partitions of `n` with uniform probability.
     5141        Return a random partition of `n` with uniform probability.
    50025142
    50035143        EXAMPLES::
    50045144
    class Partitions_n(Partitions): 
    50645204        return Partition(res)
    50655205
    50665206    def random_element_plancherel(self):
    5067         """
    5068         Returns a random partitions of `n`.
     5207        r"""
     5208        Return a random partition of `n`.
    50695209
    50705210        EXAMPLES::
    50715211
    class Partitions_parts_in(Partitions): 
    51655305    """
    51665306    Partitions of `n` with parts in a given set `S`.
    51675307
     5308    This is invoked indirectly when calling
     5309    ``Partitions(n, parts_in=parts)``, where ``parts`` is a list of
     5310    pairwise distinct integers.
     5311
    51685312    TESTS::
    51695313
    51705314        sage: TestSuite( sage.combinat.partition.Partitions_parts_in(6, parts=[2,1]) ).run()
    class Partitions_parts_in(Partitions): 
    52375381        TESTS:
    52385382
    52395383        Let's check the consistency of GAP's function and our own
    5240         algorithm that actually generates the partitions.
    5241 
    5242         ::
     5384        algorithm that actually generates the partitions::
    52435385
    52445386            sage: ps = Partitions(15, parts_in=[1,2,3])
    52455387            sage: ps.cardinality() == len(ps.list())
    class Partitions_parts_in(Partitions): 
    53915533
    53925534    def __iter__(self):
    53935535        """
    5394         An iterator a list of the partitions of `n`.
     5536        An iterator through the partitions of `n` with all parts belonging
     5537        to a particular set.
    53955538
    53965539        EXAMPLES::
    53975540
    class Partitions_ending(Partitions): 
    56355778
    56365779class PartitionsInBox(Partitions):
    56375780    r"""
    5638     All partitions with fit in a `h \times w` box.
    5639    
     5781    All partitions which fit in an `h \times w` box.
     5782
    56405783    EXAMPLES::
    56415784
    56425785        sage: PartitionsInBox(2,2)
    class PartitionsInBox(Partitions): 
    56445787        sage: PartitionsInBox(2,2).list()
    56455788        [[], [1], [1, 1], [2], [2, 1], [2, 2]]
    56465789    """
    5647    
     5790
    56485791    def __init__(self, h, w):
    56495792        """
    56505793        Initialize ``self``.
    class PartitionsInBox(Partitions): 
    56835826            False
    56845827            sage: [2,1,1] in PartitionsInBox(2,2)
    56855828            False
     5829            sage: [3,1] in PartitionsInBox(3, 2)
     5830            False
     5831            sage: [3,1] in PartitionsInBox(2, 3)
     5832            True
    56865833        """
    56875834        return x in _Partitions and len(x) <= self.h \
    56885835               and (len(x) == 0 or x[0] <= self.w)
    class PartitionsInBox(Partitions): 
    56965843
    56975844            sage: PartitionsInBox(2,2).list()
    56985845            [[], [1], [1, 1], [2], [2, 1], [2, 2]]
     5846            sage: PartitionsInBox(2,3).list()
     5847            [[], [1], [1, 1], [2], [2, 1], [2, 2], [3], [3, 1], [3, 2], [3, 3]]
    56995848
    57005849        TESTS:
    57015850
    def number_of_partitions(n, k=None, algo 
    64476596    if n < 0:
    64486597        raise ValueError("n (=%s) must be a nonnegative integer"%n)
    64496598    elif n == 0:
    6450         return ZZ(1)
     6599        return ZZ.one()
    64516600
    64526601    if algorithm == 'default':
    64536602        if k is None:
  • sage/combinat/partition_tuple.py

    diff --git a/sage/combinat/partition_tuple.py b/sage/combinat/partition_tuple.py
    a b A :class:`PartitionTuple` is a tuple of  
    99    n = \lvert \mu \rvert = \lvert \mu^{(1)} \rvert +
    1010    \lvert \mu^{(2)} \rvert + \cdots + \lvert \mu^{(k)} \rvert
    1111
    12 then `\mu` is an `k`-partition of `n`.
     12then `\mu` is a `k`-partition of `n`.
    1313
    1414In representation theory partition tuples arise as the natural indexing
    1515set for the ordinary irreducible representations of:
    class PartitionTuple(CombinatorialObject 
    274274        n = \lvert \mu \rvert = \lvert \mu^{(1)} \rvert +
    275275        \lvert \mu^{(2)} \rvert + \cdots + \lvert \mu^{(k)} \rvert
    276276
    277     then `\mu` is an `k`-partition of `n`.
     277    then `\mu` is a `k`-partition of `n`.
    278278
    279279    In representation theory PartitionTuples arise as the natural indexing
    280280    set for the ordinary irreducible representations of:
    class PartitionTuple(CombinatorialObject 
    659659
    660660    def _latex_young_diagram(self):
    661661        """
    662         LaTeX output as a young diagram.
     662        LaTeX output as a Young diagram.
    663663
    664664        EXAMPLES::
    665665
    class PartitionTuple(CombinatorialObject 
    11601160
    11611161        REFERENCE:
    11621162
    1163         .. [KMR] A. Kleshchev, A. Mathas, and A. Ram, Universal Specht modules
    1164            for cyclotomic Hecke algebras, Proc. LMS (to appear).
     1163        .. [KMR] A. Kleshchev, A. Mathas, and A. Ram, *Universal Specht
     1164           modules for cyclotomic Hecke algebras*,
     1165           Proc. London Math. Soc. (2012) 105 (6): 1245-1289.
     1166           :arxiv:`1102.3519v1`
    11651167
    11661168        """
    11671169        (comp,row,col)=cell
  • sage/combinat/sf/classical.py

    diff --git a/sage/combinat/sf/classical.py b/sage/combinat/sf/classical.py
    a b class SymmetricFunctionAlgebra_classical 
    123123        # Partitions #
    124124        ##############
    125125        if x in sage.combinat.partition.Partitions():
    126             return eclass(self, {sage.combinat.partition.Partition(filter(lambda x: x!=0, x)):R(1)})
     126            return eclass(self, {sage.combinat.partition.Partition(filter(lambda x: x!=0, x)): R.one()})
    127127
    128128        # Todo: discard all of this which is taken care by Sage's coercion
    129129        # (up to changes of base ring)
    class SymmetricFunctionAlgebra_classical 
    180180                if xm:
    181181                    return self._from_dict(t(xm)._monomial_coefficients, coerce=True)
    182182                else:
    183                     return self(0)
     183                    return self.zero()
    184184            else:
    185                 f = lambda part: self._from_dict(t( {part:Integer(1)} )._monomial_coefficients)
     185                f = lambda part: self._from_dict(t( {part: ZZ.one()} )._monomial_coefficients)
    186186                return self._apply_module_endomorphism(x, f)
    187187
    188188
    class SymmetricFunctionAlgebra_classical 
    217217        elif isinstance(x, llt.LLT_generic.Element):
    218218            P = x.parent()
    219219            BR = self.base_ring()
    220             zero = BR(0)
     220            zero = BR.zero()
    221221            PBR = P.base_ring()
    222222            if not BR.has_coerce_map_from(PBR):
    223223                raise TypeError, "no coerce map from x's parent's base ring (= %s) to self's base ring (= %s)"%(PBR, self.base_ring())
  • sage/combinat/sf/dual.py

    diff --git a/sage/combinat/sf/dual.py b/sage/combinat/sf/dual.py
    a b class SymmetricFunctionAlgebra_dual(clas 
    138138        self._inverse_transition_matrices = {}
    139139
    140140        scalar_target = scalar(sage.combinat.partition.Partition([1])).parent()
    141         scalar_target = (scalar_target(1)*dual_basis.base_ring()(1)).parent()
     141        scalar_target = (scalar_target.one()*dual_basis.base_ring().one()).parent()
    142142
    143143        self._sym = sage.combinat.sf.sf.SymmetricFunctions(scalar_target)
    144144        self._p = self._sym.power()
    class SymmetricFunctionAlgebra_dual(clas 
    312312            [-1  1]
    313313        """
    314314        base_ring = self.base_ring()
    315         zero = base_ring(0)
     315        zero = base_ring.zero()
    316316
    317317        # Handle the n == 0 and n == 1 cases separately
    318318        if n == 0 or n == 1:
    319319            part = sage.combinat.partition.Partition([1]*n)
    320             self._to_self_cache[ part ] = { part: base_ring(1) }
    321             self._from_self_cache[ part ] = { part: base_ring(1) }
     320            self._to_self_cache[ part ] = { part: base_ring.one() }
     321            self._from_self_cache[ part ] = { part: base_ring.one() }
    322322            self._transition_matrices[n] = matrix(base_ring, [[1]])
    323323            self._inverse_transition_matrices[n] = matrix(base_ring, [[1]])
    324324            return
    class SymmetricFunctionAlgebra_dual(clas 
    566566
    567567            parent = A
    568568            base_ring = parent.base_ring()
    569             zero = base_ring(0)
     569            zero = base_ring.zero()
    570570
    571571            if dual is None:
    572572                # We need to compute the dual
  • sage/combinat/sf/hall_littlewood.py

    diff --git a/sage/combinat/sf/hall_littlewood.py b/sage/combinat/sf/hall_littlewood.py
    a b class HallLittlewood_p(HallLittlewood_ge 
    952952        """
    953953        from sage.combinat.sf.kfpoly import schur_to_hl
    954954        t = QQt.gen()
    955         zero = self.base_ring()(0)
     955        zero = self.base_ring().zero()
    956956        res_dict = schur_to_hl(part, t)
    957957        f = lambda part2: res_dict.get(part2,zero)
    958958        return f
    class HallLittlewood_qp(HallLittlewood_g 
    11571157        t = QQt.gen()
    11581158
    11591159        if part == []:
    1160             return lambda part2: QQt(1)
     1160            return lambda part2: QQt.one()
    11611161
    11621162        res = hall_littlewood(part) # call to symmetrica (returns in variable x)
    11631163        f = lambda part2: res.coefficient(part2).subs(x=t)
  • sage/combinat/sf/jack.py

    diff --git a/sage/combinat/sf/jack.py b/sage/combinat/sf/jack.py
    a b implementation in sage. 
    88
    99REFERENCES:
    1010
    11     .. [Jack1970] A class of symmetric functions with a parameter, Proc. R
    12        Soc. Edinburgh (A), 69, 1-18.
     11    .. [Jack1970] H. Jack,
     12       *A class of symmetric functions with a parameter*,
     13       Proc. R. Soc. Edinburgh (A), 69, 1-18.
    1314
    14     .. [Ma1995] I. G. Macdonald, Symmetric functions and Hall polynomials, second ed.,
     15    .. [Ma1995] I. G. Macdonald,
     16       *Symmetric functions and Hall polynomials*,
     17       second ed.,
    1518       The Clarendon Press, Oxford University Press, New York, 1995, With contributions
    1619       by A. Zelevinsky, Oxford Science Publications.
    1720"""
  • sage/combinat/sf/k_dual.py

    diff --git a/sage/combinat/sf/k_dual.py b/sage/combinat/sf/k_dual.py
    a b class kMonomial(KBoundedQuotientBasis): 
    10011001            return self([])
    10021002        if la[0] <= self.k:
    10031003            return self(la)
    1004         if self.t==1:
    1005             return self(0)
     1004        if self.t == 1:
     1005            return self.zero()
    10061006        else:
    10071007            kHLP = self._kBoundedRing.kHallLittlewoodP()
    10081008            return self(kHLP._m_to_kHLP_on_basis(la))
    class kbounded_HallLittlewoodP(KBoundedQ 
    11151115            sage: kHLP(mk([2,1])^2)
    11161116            4*HLP3[2, 2, 1, 1] + 6*HLP3[2, 2, 2] + 2*HLP3[3, 2, 1] + 2*HLP3[3, 3]
    11171117        """
    1118         if self.t==1:
     1118        if self.t == 1:
    11191119            if la in self._kbounded_partitions:
    11201120                return self(la)
    11211121            else:
    1122                 return self(0)
     1122                return self.zero()
    11231123        else:
    11241124            HLP = self._kBoundedRing._quotient_basis
    11251125            m = self._kBoundedRing._sym.m()
    class kbounded_HallLittlewoodP(KBoundedQ 
    11591159        """
    11601160        mk = self._kBoundedRing.km()
    11611161        if la not in self._kbounded_partitions:
    1162             return mk(0)
     1162            return mk.zero()
    11631163        if self.t==1:
    11641164            return mk(la)
    11651165        else:
  • sage/combinat/sf/kschur.py

    diff --git a/sage/combinat/sf/kschur.py b/sage/combinat/sf/kschur.py
    a b class kSchurFunctions_generic(sfa.Symmet 
    143143        """
    144144        orig = el
    145145        P = el.parent()
    146         zero = self.base_ring()(0)
     146        zero = self.base_ring().zero()
    147147        out = {}
    148148        while not el.is_zero():
    149149            l = el.support()
    class kSchurFunctions_t(kSchurFunctions_ 
    338338        pass
    339339        if x in sage.combinat.partition.Partitions():
    340340            if len(x) > 0 and max(x) > self.k:
    341                 return self(0)
     341                return self.zero()
    342342            x = sage.combinat.partition.Partition(x)
    343             return self._from_dict({x:self.base_ring()(1)})
     343            return self._from_dict({x:self.base_ring().one()})
    344344
    345345
    346346    def _s_cache(self, n):
    class kSchurFunctions_t(kSchurFunctions_ 
    364364        R = self.base_ring()
    365365        t = self.t
    366366        s = self._s
    367         zero = s(0)
     367        zero = s.zero()
    368368
    369369        if n == 0:
    370370            p = sage.combinat.partition.Partition([])
    371             self._self_to_s_cache[0] = {p: {p:R(1)}}
     371            self._self_to_s_cache[0] = {p: {p:R.one()}}
    372372            return
    373373        else:
    374374            self._self_to_s_cache[n] = {}
  • sage/combinat/sf/powersum.py

    diff --git a/sage/combinat/sf/powersum.py b/sage/combinat/sf/powersum.py
    a b class SymmetricFunctionAlgebra_power(mul 
    4242
    4343    def coproduct_on_generators(self, i):
    4444        r"""
    45         Returns coproduct on generators for power sums `p_i`.
     45        Return coproduct on generators for power sums `p_i`
     46        (for `i > 0`).
     47
    4648        The elements `p_i` are primitive elements.
    4749
    4850        INPUT:
    class SymmetricFunctionAlgebra_power(mul 
    6163            sage: p.coproduct_on_generators(2)
    6264            p[] # p[2] + p[2] # p[]
    6365        """
    64         def P(k): return Partition([k]) if k else Partition([])
     66        Pi = Partition([i])
     67        P0 = Partition([])
    6568        T = self.tensor_square()
    66         return T.sum_of_monomials( [(P(i), P(0)), (P(0), P(i))] )
     69        return T.sum_of_monomials( [(Pi, P0), (P0, Pi)] )
    6770
    6871    def antipode_on_basis(self, partition):
    6972        r"""
    70         Returns the antipode of ``self[partition]``.
    71         The antipode on the generator `p_i` is `-p_i` and the
    72         antipode on `p_\mu` is `(-1)^{length(\mu)} p_\mu`.
     73        Return the antipode of ``self[partition]``.
     74
     75        The antipode on the generator `p_i` (for `i > 0`) is `-p_i`,
     76        and the antipode on `p_\mu` is `(-1)^{length(\mu)} p_\mu`.
    7377
    7478        INPUT:
    7579
    class SymmetricFunctionAlgebra_power(mul 
    98102        return -self[partition]
    99103        #This is slightly faster than: return (-1)**len(partition) * self[partition]
    100104
     105    def bottom_schur_function(self, partition, degree=None):
     106        r"""
     107        Return the least-degree component of ``s[partition]``,
     108        where ``s`` denotes the Schur basis of the symmetric
     109        functions, and the grading is not the usual grading on the
     110        symmetric functions but rather the grading which gives
     111        every `p_i` degree `1`.
     112
     113        This least-degree component has its degree equal to the
     114        Frobenius rank of ``partition``, while the degree with respect
     115        to the usual grading is still the size of ``partition``.
     116
     117        This method requires the base ring to be a (commutative)
     118        `\QQ`-algebra. This restriction is unavoidable, since
     119        the least-degree component (in general) has noninteger
     120        coefficients in all classical bases of the symmetric
     121        functions.
     122
     123        The optional keyword ``degree`` allows taking any
     124        homogeneous component rather than merely the least-degree
     125        one. Specifically, if ``degree`` is set, then the
     126        ``degree``-th component will be returned.
     127
     128        REFERENCES:
     129
     130        .. [ClSt03] Peter Clifford, Richard P. Stanley,
     131           *Bottom Schur functions*.
     132           :arxiv:`math/0311382v2`.
     133
     134        EXAMPLES::
     135
     136            sage: Sym = SymmetricFunctions(QQ)
     137            sage: p = Sym.p()
     138            sage: p.bottom_schur_function([2,2,1])
     139            -1/6*p[3, 2] + 1/4*p[4, 1]
     140            sage: p.bottom_schur_function([2,1])
     141            -1/3*p[3]
     142            sage: p.bottom_schur_function([3])
     143            1/3*p[3]
     144            sage: p.bottom_schur_function([1,1,1])
     145            1/3*p[3]
     146            sage: p.bottom_schur_function(Partition([1,1,1]))
     147            1/3*p[3]
     148            sage: p.bottom_schur_function([2,1], degree=1)
     149            -1/3*p[3]
     150            sage: p.bottom_schur_function([2,1], degree=2)
     151            0
     152            sage: p.bottom_schur_function([2,1], degree=3)
     153            1/3*p[1, 1, 1]
     154            sage: p.bottom_schur_function([2,2,1], degree=3)
     155            1/8*p[2, 2, 1] - 1/6*p[3, 1, 1]
     156        """
     157        from sage.combinat.partition import _Partitions
     158        s = self.realization_of().schur()
     159        partition = _Partitions(partition)
     160        if degree is None:
     161            degree = partition.frobenius_rank()
     162        s_partition = self(s[partition])
     163        return self.sum_of_terms([(p, coeff) for p, coeff
     164                                  in s_partition if len(p) == degree],
     165                                 distinct=True)
     166
    101167    class Element(classical.SymmetricFunctionAlgebra_classical.Element):
    102168        def omega(self):
    103169            r"""
    class SymmetricFunctionAlgebra_power(mul 
    143209
    144210            INPUT:
    145211
    146             - ``x`` -- an power sum symmetric function
     212            - ``x`` -- a power sum symmetric function
    147213            - ``zee`` -- (default: uses standard ``zee`` function) optional
    148214              input specifying the scalar product on the power sum basis with
    149215              normalization `\langle p_{\mu}, p_{\mu} \rangle =
    class SymmetricFunctionAlgebra_power(mul 
    213279            """
    214280            p = self.parent()
    215281            if 1 not in part:
    216                 return p(0)
     282                return p.zero()
    217283            else:
    218284                return len([i for i in part if i == 1]) * p(part[:-1])
    219285
  • sage/combinat/sf/witt.py

    diff --git a/sage/combinat/sf/witt.py b/sage/combinat/sf/witt.py
    a b class SymmetricFunctionAlgebra_witt(mult 
    4949
    5050    .. MATH::
    5151
    52         h_n = \sum_{\lambda \vdash n} w_{\lambda}`
     52        h_n = \sum_{\lambda \vdash n} w_{\lambda}
    5353
    5454    for all nonnegative integers `n`, where `\lambda \vdash n` means
    5555    that `\lambda` is a partition of `n`.
    class SymmetricFunctionAlgebra_witt(mult 
    488488        """
    489489        # Much of this code is adapted from dual.py
    490490        base_ring = self.base_ring()
    491         zero = base_ring(0)
     491        zero = base_ring.zero()
    492492
    493493        from sage.combinat.partition import Partition, Partitions_n
    494494
    495495        # Handle the n == 0 case separately
    496496        if n == 0:
    497497            part = Partition([])
    498             to_self_cache[ part ] = { part: base_ring(1) }
    499             from_self_cache[ part ] = { part: base_ring(1) }
     498            to_self_cache[ part ] = { part: base_ring.one() }
     499            from_self_cache[ part ] = { part: base_ring.one() }
    500500            transition_matrices[n] = matrix(base_ring, [[1]])
    501501            inverse_transition_matrices[n] = matrix(base_ring, [[1]])
    502502            return
  • sage/combinat/skew_partition.py

    diff --git a/sage/combinat/skew_partition.py b/sage/combinat/skew_partition.py
    a b is an involution:: 
    102102    sage: SkewPartition([[4,3,1],[2]]).conjugate().conjugate()
    103103    [4, 3, 1] / [2]
    104104
    105 The :meth:`jacobi_trudy()` method computes the Jacobi-Trudi matrix. See
     105The :meth:`jacobi_trudi()` method computes the Jacobi-Trudi matrix. See
    106106[Mac95]_ for a definition and discussion.
    107107
    108108::
    from sage.graphs.digraph import DiGraph 
    160160from sage.matrix.matrix_space import MatrixSpace
    161161
    162162from sage.combinat.combinat import CombinatorialObject
    163 from sage.combinat.partition import Partitions, PartitionOptions, _Partitions
     163from sage.combinat.partition import PartitionOptions, _Partitions
    164164from sage.combinat.tableau import TableauOptions
    165165from sage.combinat.composition import Compositions
    166166
    class SkewPartition(CombinatorialObject, 
    709709        icorners += [(nn, 0)]
    710710        return icorners
    711711
     712    def frobenius_rank(self):
     713        r"""
     714        Return the Frobenius rank of the skew partition ``self``.
     715
     716        The Frobenius rank of a skew partition `\lambda / \mu` can be
     717        defined in various ways. The quickest one is probably the
     718        following: Writing `\lambda` as
     719        `(\lambda_1, \lambda_2, \cdots , \lambda_N)`, and writing `\mu`
     720        as `(\mu_1, \mu_2, \cdots , \mu_N)`, we define the Frobenius
     721        rank of `\lambda / \mu` to be the number of all
     722        `1 \leq i \leq N` such that
     723
     724        .. MATH::
     725
     726            \lambda_i - i
     727            \not\in \{ \mu_1 - 1, \mu_2 - 2, \cdots , \mu_N - N \}.
     728
     729        In other words, the Frobenius rank of `\lambda / \mu` is the
     730        number of rows in the Jacobi-Trudi matrix of `\lambda / \mu`
     731        which don't contain `h_0`. Further definitions have been
     732        considered in [Stan2002]_ (where Frobenius rank is just being
     733        called rank).
     734
     735        If `\mu` is the empty shape, then the Frobenius rank of
     736        `\lambda / \mu` is just the usual Frobenius rank of the
     737        partition `\lambda` (see
     738        :meth:`~sage.combinat.partition.Partition.frobenius_rank()`).
     739
     740        REFERENCES:
     741
     742        .. [Stan2002] Richard P. Stanley,
     743           *The rank and minimal border strip decompositions of a
     744           skew partition*,
     745           J. Combin. Theory Ser. A 100 (2002), pp. 349-375.
     746           :arxiv:`math/0109092v1`.
     747
     748        EXAMPLES::
     749
     750            sage: SkewPartition([[8,8,7,4], [4,1,1]]).frobenius_rank()
     751            4
     752            sage: SkewPartition([[2,1], [1]]).frobenius_rank()
     753            2
     754            sage: SkewPartition([[2,1,1], [1]]).frobenius_rank()
     755            2
     756            sage: SkewPartition([[2,1,1], [1,1]]).frobenius_rank()
     757            2
     758            sage: SkewPartition([[5,4,3,2], [2,1,1]]).frobenius_rank()
     759            3
     760            sage: SkewPartition([[4,2,1], [3,1,1]]).frobenius_rank()
     761            2
     762            sage: SkewPartition([[4,2,1], [3,2,1]]).frobenius_rank()
     763            1
     764
     765        If the inner shape is empty, then the Frobenius rank of the skew
     766        partition is just the standard Frobenius rank of the partition::
     767
     768            sage: all( SkewPartition([lam, Partition([])]).frobenius_rank()
     769            ....:      == lam.frobenius_rank() for i in range(6)
     770            ....:      for lam in Partitions(i) )
     771            True
     772
     773        If the inner and outer shapes are equal, then the Frobenius rank
     774        is zero::
     775
     776            sage: all( SkewPartition([lam, lam]).frobenius_rank() == 0
     777            ....:      for i in range(6) for lam in Partitions(i) )
     778            True
     779        """
     780        N = len(self[0])
     781        mu_betas = [x - j for (j, x) in enumerate(self[1])]
     782        mu_betas.extend([- j for j in range(len(self[1]), N)])
     783        res = 0
     784        for i, x in enumerate(self[0]):
     785            if not x - i in mu_betas:
     786                res += 1
     787        return res
     788
    712789    def cells(self):
    713790        """
    714791        Return the coordinates of the cells of ``self``. Coordinates are
    class SkewPartition(CombinatorialObject, 
    749826    def to_dag(self):
    750827        """
    751828        Return a directed acyclic graph corresponding to the skew
    752         partition.
     829        partition ``self``.
     830
     831        The directed acyclic graph corresponding to a skew partition
     832        `p` is the digraph whose vertices are the cells of `p`, and
     833        whose edges go from each cell to its lower and right
     834        neighbors (in English notation).
    753835       
    754836        EXAMPLES::
    755837       
    class SkewPartition(CombinatorialObject, 
    782864                    #Check to see if there is anything below
    783865                    if row != len(skew) - 1:
    784866                        if len(skew[row+1]) > column:
    785                             if skew[row+1][column] is not None:
    786                                 newstring = "%d,%d" % (row+1, column)
    787                                 G.add_edge(string, newstring)
     867                            newstring = "%d,%d" % (row+1, column)
     868                            G.add_edge(string, newstring)
    788869        return G
    789870
    790871    def quotient(self, k):
    class SkewPartition(CombinatorialObject, 
    809890
    810891    def rows_intersection_set(self):
    811892        r"""
    812         Return the set of cells in the lines of `\lambda` which intersect the
    813         skew partition.
    814        
     893        Return the set of cells in the rows of the outer shape of
     894        ``self`` which rows intersect the skew diagram of ``self``.
     895
    815896        EXAMPLES::
    816        
     897
    817898            sage: skp = SkewPartition([[3,2,1],[2,1]])
    818899            sage: cells = Set([ (0,0), (0, 1), (0,2), (1, 0), (1, 1), (2, 0)])
    819900            sage: skp.rows_intersection_set() == cells
    class SkewPartition(CombinatorialObject, 
    832913
    833914    def columns_intersection_set(self):
    834915        """
    835         Return the set of cells in the lines of lambda which intersect the
    836         skew partition.
    837        
     916        Return the set of cells in the columns of the outer shape of
     917        ``self`` which columns intersect the skew diagram of ``self``.
     918
    838919        EXAMPLES::
    839        
     920
    840921            sage: skp = SkewPartition([[3,2,1],[2,1]])
    841922            sage: cells = Set([ (0,0), (0, 1), (0,2), (1, 0), (1, 1), (2, 0)])
    842923            sage: skp.columns_intersection_set() == cells
    class SkewPartition(CombinatorialObject, 
    887968
    888969    def jacobi_trudi(self):
    889970        """
     971        Return the Jacobi-Trudi matrix of ``self``.
     972
    890973        EXAMPLES::
    891        
     974
    892975            sage: SkewPartition([[3,2,1],[2,1]]).jacobi_trudi()
    893976            [h[1]    0    0]
    894977            [h[3] h[1]    0]
    class SkewPartition(CombinatorialObject, 
    901984        p = self.outer()
    902985        q = self.inner()
    903986        from sage.combinat.sf.sf import SymmetricFunctions
    904         if len(p) == 0 and len(q) == 0:
     987        nn = len(p)
     988        if nn == 0:
    905989            return MatrixSpace(SymmetricFunctions(QQ).homogeneous(), 0)(0)
    906         nn = len(p)
    907990        h = SymmetricFunctions(QQ).homogeneous()
    908991        H = MatrixSpace(h, nn)
    909992
    910         q  = q + [0]*int(nn-len(q))
     993        q = q + [0]*int(nn-len(q))
    911994        m = []
    912995        for i in range(1,nn+1):
    913996            row = []
    914997            for j in range(1,nn+1):
    915998                v = p[j-1]-q[i-1]-j+i
    916999                if v < 0:
    917                     row.append(h(0))
     1000                    row.append(h.zero())
    9181001                elif v == 0:
    9191002                    row.append(h([]))
    9201003                else:
    class SkewPartitions_rowlengths(SkewPart 
    14971580        if x in SkewPartitions():
    14981581            o = x[0]
    14991582            i = x[1]+[0]*(len(x[0])-len(x[1]))
    1500             return [x[0]-x[1] for x in zip(o,i)] == self.co
     1583            return [u[0]-u[1] for u in zip(o,i)] == self.co
    15011584        return False
    15021585
    15031586    def _repr_(self):
    class SkewPartitions_rowlengths(SkewPart 
    15611644            yield self.element_class(self, [[self.co[0]],[]])
    15621645            return
    15631646
    1564         result = []
    15651647        for sskp in SkewPartitions(row_lengths=self.co[:-1], overlap=self.overlap):
    15661648            for sp in self._from_row_lengths_aux(sskp, self.co[-2], self.co[-1], self.overlap):
    15671649                yield self.element_class(self, sp)