Ticket #5790: trac_5790_review_nt.patch

File trac_5790_review_nt.patch, 15.7 KB (added by nthiery, 8 months ago)

For the record. Don't apply.

  • sage/combinat/partition.py

    old new  
    2020- Dan Drake (2009-03-28): deprecate RestrictedPartitions and implement 
    2121  Partitions_parts_in 
    2222 
    23 EXAMPLES: There are 5 partitions of the integer 4. 
     23EXAMPLES: 
    2424 
    25 :: 
     25There are 5 partitions of the integer 4:: 
    2626 
    2727    sage: Partitions(4).cardinality() 
    2828    5 
     
    3030    [[4], [3, 1], [2, 2], [2, 1, 1], [1, 1, 1, 1]] 
    3131 
    3232We can use the method .first() to get the 'first' partition of a 
    33 number. 
    34  
    35 :: 
     33number:: 
    3634 
    3735    sage: Partitions(4).first() 
    3836    [4] 
    3937 
    4038Using the method .next(), we can calculate the 'next' partition. 
    41 When we are at the last partition, None will be returned. 
    42  
    43 :: 
     39When we are at the last partition, None will be returned:: 
    4440 
    4541    sage: Partitions(4).next([4]) 
    4642    [3, 1] 
     
    4844    True 
    4945 
    5046We can use ``iter`` to get an object which iterates over the partitions one 
    51 by one to save memory.  Note that when we do something like  
    52 ``for part in Partitions(4)`` this iterator is used in the background. 
    53    
    54 :: 
     47by one to save memory.  Note that when we do something like 
     48``for part in Partitions(4)`` this iterator is used in the background:: 
    5549 
    5650    sage: g = iter(Partitions(4)) 
    5751 
     
    9589 
    9690The min_part options is complementary to max_part and selects 
    9791partitions having only 'large' parts. Here is the list of all 
    98 partitions of 4 with each part at least 2. 
    99  
    100 :: 
     92partitions of 4 with each part at least 2:: 
    10193 
    10294    sage: Partitions(4, min_part=2).list() 
    10395    [[4], [2, 2]] 
     
    119111 
    120112Finally, here are the partitions of 4 with [1,1,1] as an inner 
    121113bound. Note that inner sets min_length to the length of its 
    122 argument. 
    123  
    124 :: 
     114argument:: 
    125115 
    126116    sage: Partitions(4, inner=[1,1,1]).list() 
    127117    [[2, 1, 1], [1, 1, 1, 1]] 
     
    143133    [[7, 4], [6, 5], [6, 4, 1], [6, 3, 2], [5, 4, 2], [5, 3, 2, 1]] 
    144134 
    145135Partition objects can also be created individually with the 
    146 Partition function. 
    147  
    148 :: 
     136Partition function:: 
    149137 
    150138    sage: Partition([2,1]) 
    151139    [2, 1] 
     
    154142methods that we can use. For example, we can get the conjugate of a 
    155143partition. Geometrically, the conjugate of a partition is the 
    156144reflection of that partition through its main diagonal. Of course, 
    157 this operation is an involution. 
    158  
    159 :: 
     145this operation is an involution:: 
    160146 
    161147    sage: Partition([4,1]).conjugate() 
    162148    [2, 1, 1, 1] 
     
    165151 
    166152We can go back and forth between the exponential notations of a 
    167153partition. The exponential notation can be padded with extra 
    168 zeros. 
    169  
    170 :: 
     154zeros:: 
    171155 
    172156    sage: Partition([6,4,4,2,1]).to_exp() 
    173157    [1, 1, 0, 2, 0, 1] 
     
    180164    sage: Partition([6,4,4,2,1]).to_exp(10) 
    181165    [1, 1, 0, 2, 0, 1, 0, 0, 0, 0] 
    182166 
    183 We can get the coordinates of the corners of a partition. 
    184  
    185 :: 
     167We can get the coordinates of the corners of a partition:: 
    186168 
    187169    sage: Partition([4,3,1]).corners() 
    188170    [[0, 3], [1, 2], [2, 0]] 
    189171 
    190172We can compute the core and quotient of a partition and build 
    191 the partition back up from them. 
    192  
    193 :: 
     173the partition back up from them:: 
    194174 
    195175    sage: Partition([6,3,2,2]).core(3) 
    196176    [2, 1, 1] 
     
    208188#       Copyright (C) 2007 Mike Hansen <mhansen@gmail.com>,  
    209189# 
    210190#  Distributed under the terms of the GNU General Public License (GPL) 
    211 # 
    212 #    This code is distributed in the hope that it will be useful, 
    213 #    but WITHOUT ANY WARRANTY; without even the implied warranty of 
    214 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
    215 #    General Public License for more details. 
    216 # 
    217 #  The full text of the GPL is available at: 
    218 # 
    219191#                  http://www.gnu.org/licenses/ 
    220192#***************************************************************************** 
    221193 
    222194from sage.interfaces.all import gap, gp 
    223195from sage.rings.all import QQ, ZZ, infinity, factorial, gcd 
    224 from sage.misc.all import prod, sage_eval 
     196from sage.misc.all import prod 
    225197from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing 
    226198import sage.combinat.misc as misc 
    227199import sage.combinat.skew_partition 
     
    239211from integer_list import IntegerListsLex 
    240212from sage.functions.other import ceil 
    241213 
    242 def Partition(mu=None, **key_word):                                               
    243     """                                                                           
    244     A partition is a weakly decreasing ordered sequence of non-negative           
    245     integers. This function returns a Sage partition object which can             
    246     be specified in one of the following ways::                                   
    247       * a list (the default)                                                      
    248       * using exponential notation                                                
    249       * by beta numbers (TODO)                                                    
    250       * specifying the core and the quotient                                      
    251       * specifying the core and the canonical quotient (TODO)                     
    252     See the examples below.                                                       
    253                                                                                   
    254     Sage follows the usual python conventions when dealing with partitions,       
    255     so that the first part of the partition ``mu=Partition([4,3,2,2])`` is        
    256     ``mu[0]``, the second part is ``mu[1]`` and so on. As is usual, Sage ignores  
    257     trailing zeros at the end of partitions.                                      
    258                                                                                   
    259     EXAMPLES::                                                                    
    260                                                                                   
    261         sage: Partition([3,2,1])                                                  
    262         [3, 2, 1]                                                                 
    263         sage: Partition([3,2,1,0])                                                
    264         [3, 2, 1]                                                                 
     214def Partition(mu=None, **keyword): 
     215    """ 
     216    A partition is a weakly decreasing ordered sequence of non-negative 
     217    integers. This function returns a Sage partition object which can 
     218    be specified in one of the following ways:: 
     219 
     220      * a list (the default) 
     221      * using exponential notation 
     222      * by beta numbers (TODO) 
     223      * specifying the core and the quotient 
     224      * specifying the core and the canonical quotient (TODO) 
     225 
     226    See the examples below. 
     227 
     228    Sage follows the usual python conventions when dealing with partitions, 
     229    so that the first part of the partition ``mu=Partition([4,3,2,2])`` is 
     230    ``mu[0]``, the second part is ``mu[1]`` and so on. As is usual, Sage ignores 
     231    trailing zeros at the end of partitions. 
     232 
     233    EXAMPLES:: 
     234 
     235        sage: Partition([3,2,1]) 
     236        [3, 2, 1] 
     237        sage: Partition([3,2,1,0]) 
     238        [3, 2, 1] 
    265239        sage: Partition(exp=[2,1,1]) 
    266240        [3, 2, 1, 1] 
    267241        sage: Partition(core=[2,1], quotient=[[2,1],[3],[1,1,1]]) 
     
    275249        ... 
    276250        ValueError: [1, 2, 3] is not a valid partition 
    277251    """ 
    278     if mu is not None and len(key_word)==0: 
     252    if mu is not None and len(keyword)==0: 
    279253        mu = [i for i in mu if i != 0] 
    280254        if mu in Partitions_all(): 
    281255            return Partition_class(mu) 
    282256        else: 
    283257            raise ValueError, "%s is not a valid partition"%mu 
    284     elif 'beta_numbers' in key_word and len(key_word)==1: 
     258    elif 'beta_numbers' in keyword and len(keyword)==1: 
    285259        raise NotImplementedError 
    286     elif 'exp' in key_word and len(key_word)==1: 
    287         return from_exp(key_word['exp']) 
    288     elif 'core' in key_word and 'quotient' in key_word and len(key_word)==2: 
    289         return from_core_and_quotient(key_word['core'], key_word['quotient']) 
    290     elif 'core' in key_word and 'canonical_quotient' in key_word and len(key_word)==2: 
     260    elif 'exp' in keyword and len(keyword)==1: 
     261        return from_exp(keyword['exp']) 
     262    elif 'core' in keyword and 'quotient' in keyword and len(keyword)==2: 
     263        return from_core_and_quotient(keyword['core'], keyword['quotient']) 
     264    elif 'core' in keyword and 'canonical_quotient' in keyword and len(keyword)==2: 
    291265        raise NotImplementedError 
    292     elif 'core_and_quotient' in key_word and len(key_word)==1: 
     266    elif 'core_and_quotient' in keyword and len(keyword)==1: 
    293267        from sage.misc.misc import deprecation 
    294268        deprecation('"core_and_quotient=(*)" is deprecated. Use "core=[*], quotient=[*]" instead.') 
    295         return from_core_and_quotient(*key_word['core_and_quotient']) 
     269        return from_core_and_quotient(*keyword['core_and_quotient']) 
    296270    else: 
    297271        raise ValueError, 'incorrect syntax for Partition()' 
    298272 
     
    304278 
    305279       This function is for internal use only;  
    306280       use Partition(exp=*) instead. 
    307      
     281 
    308282    EXAMPLES:: 
    309      
     283 
    310284        sage: Partition(exp=[1,2,1]) 
    311285        [3, 2, 2, 1] 
    312286    """ 
     
    318292def from_core_and_quotient(core, quotient): 
    319293    """ 
    320294    ** This function is being deprecated - use Partition(core=*, quotient=*) instead ** 
    321      
     295 
    322296    Returns a partition from its core and quotient. 
    323297     
    324298    Algorithm from mupad-combinat. 
     
    327301 
    328302       This function is for internal use only;  
    329303       use Partition(core=*, quotient=*) instead. 
    330      
     304 
    331305    EXAMPLES:: 
    332      
     306 
    333307        sage: Partition(core=[2,1], quotient=[[2,1],[3],[1,1,1]]) 
    334308        [11, 5, 5, 3, 2, 2, 2] 
    335309    """ 
     
    397371 
    398372        return sage.combinat.skew_partition.SkewPartition([self[:], p]) 
    399373         
    400     def power(self,k): 
     374    def power(self, k): 
    401375        """ 
    402         partition_power( pi, k ) returns the partition corresponding to 
    403         the `k`-th power of a permutation with cycle structure pi 
    404         (thus describes the powermap of symmetric groups). 
     376        Returns the cycle type of the `k`-th power of any permutation 
     377        with cycle type ``self`` (thus describes the powermap of 
     378        symmetric groups). 
    405379         
    406380        Wraps GAP's PowerPartition. 
    407381         
     
    514488 
    515489    def sign(self): 
    516490        r""" 
    517         Returns the sign of a permutation with cycle type of the partition. 
     491        Returns the sign of any permutation with cycle type ``self``. 
    518492         
    519493        This function corresponds to a homomorphism from the symmetric 
    520494        group `S_n` into the cyclic group of order 2, whose kernel 
     
    12671241    def centralizer_size(self, t=0, q=0): 
    12681242        """ 
    12691243        Returns the size of the centralizer of any permutation of cycle type 
    1270         p. If m_i is the multiplicity of i as a part of p, this is given 
     1244        ``self``. If m_i is the multiplicity of i as a part of p, this is given 
    12711245        by `\prod_i (i^m[i])*(m[i]!)`. Including the optional 
    12721246        parameters t and q gives the q-t analog which is the former product 
    12731247        times `\prod_{i=1}^{length(p)} (1 - q^{p[i]}) / (1 - t^{p[i]}).` 
     
    12941268    def aut(self): 
    12951269        r""" 
    12961270        Returns a factor for the number of permutations with cycle type 
    1297         self. self.aut() returns 
     1271        ``self``. self.aut() returns 
    12981272        `1^{j_1}j_1! \cdots n^{j_n}j_n!` where `j_k` 
    12991273        is the number of parts in self equal to k. 
    13001274         
     
    14171391        return res 
    14181392 
    14191393    def r_core(self, length): 
    1420       """ *** deprecate *** """ 
    1421       from sage.misc.misc import deprecation 
    1422       deprecation('r_core is deprecated. Use core instead.') 
    1423       return self.core(self, length) 
     1394        """ 
     1395        This function is deprecated. 
     1396 
     1397        EXAMPLES:: 
     1398 
     1399            sage: Partition([6,3,2,2]).r_core(3) 
     1400            doctest:1: DeprecationWarning: r_core is deprecated. Please use core instead. 
     1401            [2, 1, 1] 
     1402 
     1403        Please use :meth:`core` instead:: 
     1404 
     1405            sage: Partition([6,3,2,2]).core(3) 
     1406            [2, 1, 1] 
     1407 
     1408        """ 
     1409        from sage.misc.misc import deprecation 
     1410        deprecation('r_core is deprecated. Please use core instead.') 
     1411        return self.core(length) 
    14241412 
    14251413    def core(self, length): 
    14261414        """ 
    14271415        Returns the core of the partition -- in the literature the core is 
    1428         commonly referred to as the k-core, p-core, r-core, ... . The 
     1416        commonly referred to as the `k`-core, `p`-core, `r`-core, ... . The 
    14291417        construction of the core can be visualized by repeatedly removing 
    1430         border strips of size r from p until this is no longer possible. 
     1418        border strips of size `r` from ``self`` until this is no longer possible. 
    14311419        The remaining partition is the core. 
    1432          
     1420 
    14331421        EXAMPLES:: 
    1434          
     1422 
    14351423            sage: Partition([6,3,2,2]).core(3) 
    14361424            [2, 1, 1] 
    14371425            sage: Partition([]).core(3) 
    14381426            [] 
    14391427            sage: Partition([8,7,7,4,1,1,1,1,1]).core(3) 
    14401428            [2, 1, 1] 
    1441          
     1429 
    14421430        TESTS:: 
    1443          
     1431 
    14441432            sage: Partition([3,3,3,2,1]).core(3) 
    14451433            [] 
    14461434            sage: Partition([10,8,7,7]).core(4) 
     
    14711459        return filter(lambda x: x != 0, part) 
    14721460 
    14731461    def r_quotient(self, length): 
    1474         """ *** deprecate *** """ 
    1475         from sage.misc.misc import deprecation 
    1476         deprecation('r_quotient is deprecated. Use quotient instead.') 
    1477         return self.quotient(self,length) 
     1462        """ 
     1463        This function is deprecated. 
     1464 
     1465        EXAMPLES:: 
     1466 
     1467            sage: Partition([6,3,2,2]).r_quotient(3) 
     1468            doctest:1: DeprecationWarning: r_quotient is deprecated. Please use quotient instead. 
     1469            [[], [], [2, 1]] 
    14781470 
     1471        Please use :meth:`quotient` instead:: 
     1472 
     1473            sage: Partition([6,3,2,2]).quotient(3) 
     1474            [[], [], [2, 1]] 
     1475        """ 
     1476        from sage.misc.misc import deprecation 
     1477        deprecation('r_quotient is deprecated. Please use quotient instead.') 
     1478        return self.quotient(length) 
    14791479 
    14801480    def quotient(self, length): 
    14811481        """ 
    14821482        Returns the quotient of the partition  -- in the literature the 
    1483         core is commonly referred to as the k-core, p-core, r-core, ... . The 
    1484         quotient is a list of r partitions, constructed in the following 
    1485         way. Label each cell in p with its content, modulo r. Let R_i be 
    1486         the set of rows ending in a box labelled i, and C_i be the set of 
    1487         columns ending in a box labelled i. Then the jth component of the 
    1488         quotient of p is the partition defined by intersecting R_j with 
    1489         C_j+1. 
    1490          
     1483        core is commonly referred to as the `k`-core, `p`-core, `r`-core, ... . The 
     1484        quotient is a list of `r` partitions, constructed in the following 
     1485        way. Label each cell in `p` with its content, modulo `r`. Let `R_i` be 
     1486        the set of rows ending in a box labelled `i`, and `C_i` be the set of 
     1487        columns ending in a box labelled `i`. Then the `j`-th component of the 
     1488        quotient of `p` is the partition defined by intersecting `R_j` with 
     1489        `C_j+1`. 
     1490 
    14911491        EXAMPLES:: 
    14921492 
    14931493            sage: Partition([7,7,5,3,3,3,1]).quotient(3) 
     
    42514251def partition_power(pi,k): 
    42524252    """ 
    42534253    partition_power( pi, k ) returns the partition corresponding to 
    4254     the `k`-th power of a permutation with cycle structure pi 
     4254    the `k`-th power of a permutation with cycle structure ``pi`` 
    42554255    (thus describes the powermap of symmetric groups). 
    42564256     
    42574257    Wraps GAP's PowerPartition. 
     
    42954295    is exactly the alternating group `A_n`. Partitions of sign 
    42964296    `1` are called even partitions while partitions of sign 
    42974297    `-1` are called odd. 
    4298     
     4298 
    42994299    This function is deprecated: use Partition( pi ).sign() instead. 
    43004300 
    43014301    EXAMPLES:: 
    4302      
     4302 
    43034303        sage: Partition([5,3]).sign() 
    43044304        1 
    43054305        sage: Partition([5,2]).sign() 
     
    43904390    from sage.misc.misc import deprecation 
    43914391    deprecation('"partition_associated deprecated. Use Partition(pi).conjugte() instead') 
    43924392    return Partition(pi).conjugate() 
    4393              
     4393