Ticket #5790: trac_5790-review.patch

File trac_5790-review.patch, 4.7 KB (added by saliola, 9 months ago)

Apply only 5790.2.patch and this patch (in this order)

  • sage/combinat/partition.py

    # HG changeset patch
    # User Franco Saliola <saliola@gmail.com>
    # Date 1245612237 -7200
    # Node ID eed995d18b83b53bb8a3910c65d00d41bf38ad0d
    # Parent  3ead28f72457a47a670c07c207b330e1c72b2359
    [mq]: trac_5790-review.patch
    
    diff -r 3ead28f72457 -r eed995d18b83 sage/combinat/partition.py
    a b  
    284284    elif 'beta_numbers' in key_word and len(key_word)==1: 
    285285        raise NotImplementedError 
    286286    elif 'exp' in key_word and len(key_word)==1: 
    287         return Partition_class([]).from_exp(key_word['exp']) 
     287        return from_exp(key_word['exp']) 
    288288    elif 'core' in key_word and 'quotient' in key_word and len(key_word)==2: 
    289         return Partition_class([]).from_core_and_quotient(key_word['core'], key_word['quotient']) 
     289        return from_core_and_quotient(key_word['core'], key_word['quotient']) 
    290290    elif 'core' in key_word and 'canonical_quotient' in key_word and len(key_word)==2: 
    291291        raise NotImplementedError 
    292292    elif 'core_and_quotient' in key_word and len(key_word)==1: 
    293293        from sage.misc.misc import deprecation 
    294294        deprecation('"core_and_quotient=(*)" is deprecated. Use "core=[*], quotient=[*]" instead.') 
    295         return Partition_class([]).from_core_and_quotient(*key_word['core_and_quotient']) 
     295        return from_core_and_quotient(*key_word['core_and_quotient']) 
    296296    else: 
    297297        raise ValueError, 'incorrect syntax for Partition()' 
    298298 
    299 def from_exp(a): 
    300     """ 
    301     ** This function is being deprecated - use Partition(exp=*) instead ** 
     299def from_exp(exp): 
     300    """ 
    302301    Returns a partition from its list of multiplicities. 
     302 
     303    .. note:: 
     304 
     305       This function is for internal use only;  
     306       use Partition(exp=*) instead. 
    303307     
    304308    EXAMPLES:: 
    305309     
    306310        sage: Partition(exp=[1,2,1]) 
    307311        [3, 2, 2, 1] 
    308312    """ 
    309     from sage.misc.misc import deprecation 
    310     deprecation('"from_exp" is deprecated. Use "Partition(exp=[*])" instead.') 
    311     return Partition(exp=a) 
     313    p = [] 
     314    for i in reversed(range(len(exp))): 
     315        p += [i+1]*exp[i] 
     316    return Partition(p) 
    312317 
    313318def from_core_and_quotient(core, quotient): 
    314319    """ 
     
    318323     
    319324    Algorithm from mupad-combinat. 
    320325     
     326    .. note:: 
     327 
     328       This function is for internal use only;  
     329       use Partition(core=*, quotient=*) instead. 
     330     
    321331    EXAMPLES:: 
    322332     
    323333        sage: Partition(core=[2,1], quotient=[[2,1],[3],[1,1,1]]) 
    324334        [11, 5, 5, 3, 2, 2, 2] 
    325335    """ 
    326     from sage.misc.misc import deprecation 
    327     deprecation('"from_core_and_quotient" is deprecated. Use "Partition(core=[*],quotient=[*])" instead.') 
    328     return Partition(core=core,quotient=quotient) 
    329      
     336    length = len(quotient) 
     337    k = length*max( [ceil(len(core)/length),len(core)] + [len(q) for q in quotient] ) + length 
     338    v = [ core[i]-(i+1)+1 for i in range(len(core))] + [ -i + 1 for i in range(len(core)+1,k+1) ] 
     339    w = [ filter(lambda x: (x-i) % length == 0, v) for i in range(1, length+1) ] 
     340    new_w = [] 
     341    for i in range(length): 
     342        new_w += [ w[i][j] + length*quotient[i][j] for j in range(len(quotient[i]))] 
     343        new_w += [ w[i][j] for j in range(len(quotient[i]), len(w[i])) ] 
     344    new_w.sort() 
     345    new_w.reverse() 
     346    return Partition([new_w[i-1]+i-1 for i in range(1, len(new_w)+1)]) 
     347 
    330348class Partition_class(CombinatorialObject): 
    331     def from_exp(self,exp): 
    332         """ 
    333         Returns a partition from its list of multiplicities. 
    334          
    335         EXAMPLES:: 
    336          
    337             sage: Partition(exp=[1,2,1]) 
    338             [3, 2, 2, 1] 
    339         """ 
    340         p = [] 
    341         for i in reversed(range(len(exp))): 
    342             p += [i+1]*exp[i] 
    343         return Partition(p) 
    344  
    345     def from_core_and_quotient(self, core, quotient): 
    346         """ 
    347         Returns a partition from its core and quotient. 
    348          
    349         Algorithm from mupad-combinat. 
    350          
    351         EXAMPLES:: 
    352          
    353             sage: Partition(core=[2,1], quotient=[[2,1],[3],[1,1,1]]) 
    354             [11, 5, 5, 3, 2, 2, 2] 
    355         """ 
    356         length = len(quotient) 
    357         k = length*max( [ceil(len(core)/length),len(core)] + [len(q) for q in quotient] ) + length 
    358         v = [ core[i]-(i+1)+1 for i in range(len(core))] + [ -i + 1 for i in range(len(core)+1,k+1) ] 
    359         w = [ filter(lambda x: (x-i) % length == 0, v) for i in range(1, length+1) ] 
    360         new_w = [] 
    361         for i in range(length): 
    362             new_w += [ w[i][j] + length*quotient[i][j] for j in range(len(quotient[i]))] 
    363             new_w += [ w[i][j] for j in range(len(quotient[i]), len(w[i])) ] 
    364         new_w.sort() 
    365         new_w.reverse() 
    366         return Partition([new_w[i-1]+i-1 for i in range(1, len(new_w)+1)]) 
    367  
    368  
    369349    def ferrers_diagram(self): 
    370350        """ 
    371351        Return the Ferrers diagram of pi.