Ticket #11410: trac_11410-zero_one_sequence_partitions-pod.patch

File trac_11410-zero_one_sequence_partitions-pod.patch, 4.8 KB (added by pdehaye, 9 years ago)
  • sage/combinat/partition.py

    # HG changeset patch
    # User Paul-Olivier Dehaye <paulolivier@gmail.com>
    # Date 1307877330 -7200
    # Node ID 425019200d881072db27f4544a6427c4a657ea81
    # Parent  7e9fef684658489bedab81def4f0027734fbe603
    #11410: 0-1 sequence for partitions
    
    diff -r 7e9fef684658 -r 425019200d88 sage/combinat/partition.py
    a b  
    198198    sage: Partition(core=[],quotient=([2, 1], [4], [1, 1, 1]))
    199199    [11, 5, 5, 3, 2, 2, 2]
    200200
     201We can compute the 0-1 sequence and go back and forth::
     202
     203    sage: Partition(zero_one=[1, 1, 1, 1, 0, 1, 0])
     204    [5, 4]
     205    sage: all(Partition(zero_one=mu.zero_one_sequence()) == mu for n in range(5) for mu in Partitions(n))
     206    True
     207   
     208
    201209We can compute the Frobenius coordinates (or beta numbers), and go back
    202210and forth::
    203211
     
    247255      * a list (the default)
    248256      * using exponential notation
    249257      * by Frobenius coordinates (also called beta numbers)
     258      * specifying its 0-1 sequence
    250259      * specifying the core and the quotient
    251260      * specifying the core and the canonical quotient (TODO)
    252261
     
    269278        [11, 5, 5, 3, 2, 2, 2]
    270279        sage: Partition(frobenius_coordinates=([3,2],[4,0]))
    271280        [4, 4, 1, 1, 1]
     281        sage: Partition(zero_one=[1, 1, 1, 1, 0, 1, 0])
     282        [5, 4]
    272283        sage: [2,1] in Partitions()
    273284        True
    274285        sage: [2,1,0] in Partitions()
     
    288299        return from_frobenius_coordinates(keyword['frobenius_coordinates'])
    289300    elif 'exp' in keyword and len(keyword)==1:
    290301        return from_exp(keyword['exp'])
     302    elif 'zero_one' in keyword and len(keyword)==1:
     303        return from_zero_one(keyword['zero_one'])   
    291304    elif 'core' in keyword and 'quotient' in keyword and len(keyword)==2:
    292305        return from_core_and_quotient(keyword['core'], keyword['quotient'])
    293306    elif 'core' in keyword and 'canonical_quotient' in keyword and len(keyword)==2:
     
    362375    for i in reversed(range(len(exp))):
    363376        p += [i+1]*exp[i]
    364377    return Partition(p)
     378   
     379def from_zero_one(seq):
     380    """ Returns a partition from its 0-1 sequence.
     381   
     382        The 0-1 sequence is the sequence (infinite in both directions) indicating the steps taken when following the outer rim of the diagram of the partition. Every 0-1 sequence eventually ends with 1s and eventually starts with 0s. Heading 0s and 1s are omitted. In the English notation, a 1 corresponds to an East step, while a 0 corresponds to a North step.
     383   
     384        INPUT::
     385            The heading 0s and trailing 1s should be omitted in the input sequence, so the input should be a finite sequence starting with a 1 and ending with a 0 (unless it is empty, for the empty partition).
     386           
     387        EXAMPLES::
     388       
     389            sage: Partition(zero_one=[])
     390            []
     391            sage: Partition(zero_one=[1,0])
     392            [1]
     393            sage: Partition(zero_one=[1, 1, 1, 1, 0, 1, 0])
     394            [5, 4]
     395           
     396        TESTS::
     397           
     398            sage: all(Partition(zero_one=mu.zero_one_sequence()) == mu for n in range(10) for mu in Partitions(n))
     399            True
     400                       
     401    """
     402    tmp = [i for i in range(len(seq)) if seq[i] == 0]
     403    return Partition([tmp[i]-i for i in range(len(tmp)-1,-1,-1)])
    365404
    366405def from_core_and_quotient(core, quotient):
    367406    """
     
    17131752            prevLen = p[i]
    17141753        res.append((0, prevLen))
    17151754        return res
     1755       
     1756    def zero_one_sequence(self):
     1757        """ Computes the 0-1 sequence of the partition.
     1758   
     1759        The 0-1 sequence is the sequence (infinite in both directions) indicating the steps taken
     1760        when following the outer rim of the diagram of the partition. Every 0-1 sequence eventually
     1761        ends with 1s and eventually starts with 0s. Heading 0s and 1s are omitted. In the English
     1762        notation, a 1 corresponds to an East step, while a 0 corresponds to a North step.
     1763       
     1764        OUTPUT::
     1765       
     1766            The heading 0s and trailing 1s are omitted, so the output sequence is finite should start with a 1 and end with a 0 (unless it is empty, for the empty partition).
     1767           
     1768        EXAMPLES::
     1769            sage: Partition([5,4]).zero_one_sequence()
     1770            [1, 1, 1, 1, 0, 1, 0]
     1771            sage: Partition([]).zero_one_sequence()
     1772            []
     1773            sage: Partition([2]).zero_one_sequence()
     1774            [1, 1, 0]
     1775               
     1776        TESTS::
     1777            sage: all(Partition(zero_one=mu.zero_one_sequence()) == mu for n in range(10) for mu in Partitions(n))
     1778            True
     1779               
     1780        """
     1781        tmp = [self.get_part(i)-i for i in range(len(self))]
     1782        return ([Integer(not (i in tmp)) for i in range(-len(self)+1,self.get_part(0)+1)])
    17161783
    17171784    def core(self, length):
    17181785        """