Ticket #11410: trac_11410zero_one_sequence_partitionspod.v2.patch
File trac_11410zero_one_sequence_partitionspod.v2.patch, 5.2 KB (added by , 7 years ago) 


sage/combinat/partition.py
# HG changeset patch # User PaulOlivier Dehaye <paulolivier@gmail.com> # Date 1307877330 7200 # Node ID c3ca4487a971375f5ff6b7b2a741551bf23573c5 # Parent bf82caf6e2b785824a1f3e462aad966197e68014 trac #11410: bijection between 01 sequences and partitions diff git a/sage/combinat/partition.py b/sage/combinat/partition.py
a b 1 1 2 r""" 2 3 Partitions 3 4 … … the partition back up from them:: 234 235 sage: Partition(core=[],quotient=([2, 1], [4], [1, 1, 1])) 235 236 [11, 5, 5, 3, 2, 2, 2] 236 237 238 We can compute the `01` 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 237 245 We can compute the Frobenius coordinates and go back and forth:: 238 246 239 247 sage: Partition([7,3,1]).frobenius_coordinates() … … class Partition(CombinatorialObject, Ele 485 493  a list (the default) 486 494  using exponential notation 487 495  by Frobenius coordinates 496  specifying its `01` sequence 488 497  specifying the core and the quotient 489 498 490 499 See the examples below. … … class Partition(CombinatorialObject, Ele 550 559 [11, 5, 5, 3, 2, 2, 2] 551 560 sage: Partition(frobenius_coordinates=([3,2],[4,0])) 552 561 [4, 4, 1, 1, 1] 562 sage: Partitions().from_zero_one([1, 1, 1, 1, 0, 1, 0]) 563 [5, 4] 553 564 sage: [2,1] in Partitions() 554 565 True 555 566 sage: [2,1,0] in Partitions() … … class Partition(CombinatorialObject, Ele 612 623 return Partitions().from_exp(keyword['exp']) 613 624 elif 'frobenius_coordinates' in keyword and len(keyword) == 1: 614 625 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']) 615 628 else: 616 629 raise ValueError('incorrect syntax for Partition()') 617 630 … … class Partition(CombinatorialObject, Ele 2700 2713 res.append((0, prevLen)) 2701 2714 return res 2702 2715 2716 def zero_one_sequence(self): 2717 r""" 2718 Computes the finite `01` sequence of the partition. 2719 2720 The full `01` 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 `01` sequence starts with infinitely many 0's and 2727 ends with infinitely many 1's. 2728 2729 OUTPUT: 2730 2731 The finite `01` sequence is obtained from the full `01` 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 2703 2753 def core(self, length): 2704 2754 """ 2705 2755 Return the core of the partition  in the literature the core is … … class Partitions(UniqueRepresentation, P 4076 4126 p += [i+1]*exp[i] 4077 4127 return self.element_class(self, p) 4078 4128 4129 def from_zero_one(self, seq): 4130 r""" 4131 Returns a partition from its `01` sequence. 4132 4133 The full `01` 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 `01` 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 4079 4167 def from_core_and_quotient(self, core, quotient): 4080 4168 """ 4081 4169 Returns a partition from its core and quotient.