Ticket #11410: trac_11410-zero_one_sequence_partitions-pod.v2.patch

File trac_11410-zero_one_sequence_partitions-pod.v2.patch, 5.2 KB (added by chapoton, 7 years ago)
  • sage/combinat/partition.py

    # HG changeset patch
    # User Paul-Olivier Dehaye <paulolivier@gmail.com>
    # Date 1307877330 -7200
    # Node ID c3ca4487a971375f5ff6b7b2a741551bf23573c5
    # Parent  bf82caf6e2b785824a1f3e462aad966197e68014
    trac #11410: bijection between 0-1 sequences and partitions
    
    diff --git a/sage/combinat/partition.py b/sage/combinat/partition.py
    a b  
     1
    12r"""
    23Partitions
    34
    the partition back up from them:: 
    234235    sage: Partition(core=[],quotient=([2, 1], [4], [1, 1, 1]))
    235236    [11, 5, 5, 3, 2, 2, 2]
    236237
     238We can compute the `0-1` sequence and go back and forth::
     239
     240    sage: Partitions().from_zero_one([1, 1, 1, 1, 0, 1, 0])
     241    [5, 4]
     242    sage: all(Partitions().from_zero_one(mu.zero_one_sequence()) == mu for n in range(5) for mu in Partitions(n))
     243    True
     244
    237245We can compute the Frobenius coordinates and go back and forth::
    238246
    239247    sage: Partition([7,3,1]).frobenius_coordinates()
    class Partition(CombinatorialObject, Ele 
    485493    - a list (the default)
    486494    - using exponential notation
    487495    - by Frobenius coordinates
     496    - specifying its `0-1` sequence
    488497    - specifying the core and the quotient
    489498
    490499    See the examples below.
    class Partition(CombinatorialObject, Ele 
    550559        [11, 5, 5, 3, 2, 2, 2]
    551560        sage: Partition(frobenius_coordinates=([3,2],[4,0]))
    552561        [4, 4, 1, 1, 1]
     562        sage: Partitions().from_zero_one([1, 1, 1, 1, 0, 1, 0])
     563        [5, 4]
    553564        sage: [2,1] in Partitions()
    554565        True
    555566        sage: [2,1,0] in Partitions()
    class Partition(CombinatorialObject, Ele 
    612623            return Partitions().from_exp(keyword['exp'])
    613624        elif 'frobenius_coordinates' in keyword and len(keyword) == 1:
    614625            return Partitions().from_frobenius_coordinates(keyword['frobenius_coordinates'])
     626        elif 'zero_one' in keyword and len(keyword) == 1:
     627            return Partitions().from_zero_one(keyword['zero_one'])
    615628        else:
    616629            raise ValueError('incorrect syntax for Partition()')
    617630
    class Partition(CombinatorialObject, Ele 
    27002713        res.append((0, prevLen))
    27012714        return res
    27022715
     2716    def zero_one_sequence(self):
     2717        r"""
     2718        Computes the finite `0-1` sequence of the partition.
     2719
     2720        The full `0-1` sequence is the sequence (infinite in both
     2721        directions) indicating the steps taken when following the
     2722        outer rim of the diagram of the partition. In the English
     2723        notation, a 1 corresponds to an East step, while a 0
     2724        corresponds to a North step.
     2725
     2726        Every full `0-1` sequence starts with infinitely many 0's and
     2727        ends with infinitely many 1's.
     2728
     2729        OUTPUT:
     2730
     2731        The finite `0-1` sequence is obtained from the full `0-1`
     2732        sequence by omitting all heading 0's and trailing 1's. The
     2733        output sequence is finite, starts with a 1 and ends with a
     2734        0 (unless it is empty, for the empty partition).
     2735
     2736        EXAMPLES::
     2737
     2738            sage: Partition([5,4]).zero_one_sequence()
     2739            [1, 1, 1, 1, 0, 1, 0]
     2740            sage: Partition([]).zero_one_sequence()
     2741            []
     2742            sage: Partition([2]).zero_one_sequence()
     2743            [1, 1, 0]
     2744
     2745        TESTS::
     2746
     2747            sage: all(Partitions().from_zero_one(mu.zero_one_sequence()) == mu for n in range(10) for mu in Partitions(n))
     2748            True
     2749        """
     2750        tmp = [self.get_part(i)-i for i in range(len(self))]
     2751        return ([Integer(not (i in tmp)) for i in range(-len(self)+1,self.get_part(0)+1)])
     2752
    27032753    def core(self, length):
    27042754        """
    27052755        Return the core of the partition -- in the literature the core is
    class Partitions(UniqueRepresentation, P 
    40764126            p += [i+1]*exp[i]
    40774127        return self.element_class(self, p)
    40784128
     4129    def from_zero_one(self, seq):
     4130        r"""
     4131        Returns a partition from its `0-1` sequence.
     4132
     4133        The full `0-1` sequence is the sequence (infinite in both
     4134        directions) indicating the steps taken when following the outer
     4135        rim of the diagram of the partition. In the English notation, a 1
     4136        corresponds to an East step, while a 0 corresponds to a North
     4137        step. Every `0-1` sequence starts with infinitely many 0's and ends
     4138        with infinitely many 1's.
     4139
     4140        INPUT:
     4141
     4142        The input should be a finite sequence of 0's and 1's. The
     4143        heading 0's and trailing 1's will be discarded.
     4144
     4145        EXAMPLES::
     4146
     4147            sage: Partitions().from_zero_one([])
     4148            []
     4149            sage: Partitions().from_zero_one([1,0])
     4150            [1]
     4151            sage: Partitions().from_zero_one([1, 1, 1, 1, 0, 1, 0])
     4152            [5, 4]
     4153
     4154        Heading 0's and trailing 1's are correctly handled::
     4155
     4156            sage: Partitions().from_zero_one([0,0,1,1,1,1,0,1,0,1,1,1])
     4157            [5, 4]
     4158
     4159        TESTS::
     4160
     4161            sage: all(Partitions().from_zero_one(mu.zero_one_sequence()) == mu for n in range(10) for mu in Partitions(n))
     4162            True
     4163        """
     4164        tmp = [i for i in range(len(seq)) if seq[i] == 0]
     4165        return Partition([tmp[i]-i for i in range(len(tmp)-1,-1,-1)])
     4166
    40794167    def from_core_and_quotient(self, core, quotient):
    40804168        """
    40814169        Returns a partition from its core and quotient.