# HG changeset patch
# User PaulOlivier Dehaye <paulolivier@gmail.com>
# Date 1307877330 7200
# Node ID 425019200d881072db27f4544a6427c4a657ea81
# Parent 7e9fef684658489bedab81def4f0027734fbe603
#11410: 01 sequence for partitions
diff r 7e9fef684658 r 425019200d88 sage/combinat/partition.py
a

b


198  198  sage: Partition(core=[],quotient=([2, 1], [4], [1, 1, 1])) 
199  199  [11, 5, 5, 3, 2, 2, 2] 
200  200  
 201  We can compute the 01 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  
201  209  We can compute the Frobenius coordinates (or beta numbers), and go back 
202  210  and forth:: 
203  211  
… 
… 

247  255  * a list (the default) 
248  256  * using exponential notation 
249  257  * by Frobenius coordinates (also called beta numbers) 
 258  * specifying its 01 sequence 
250  259  * specifying the core and the quotient 
251  260  * specifying the core and the canonical quotient (TODO) 
252  261  
… 
… 

269  278  [11, 5, 5, 3, 2, 2, 2] 
270  279  sage: Partition(frobenius_coordinates=([3,2],[4,0])) 
271  280  [4, 4, 1, 1, 1] 
 281  sage: Partition(zero_one=[1, 1, 1, 1, 0, 1, 0]) 
 282  [5, 4] 
272  283  sage: [2,1] in Partitions() 
273  284  True 
274  285  sage: [2,1,0] in Partitions() 
… 
… 

288  299  return from_frobenius_coordinates(keyword['frobenius_coordinates']) 
289  300  elif 'exp' in keyword and len(keyword)==1: 
290  301  return from_exp(keyword['exp']) 
 302  elif 'zero_one' in keyword and len(keyword)==1: 
 303  return from_zero_one(keyword['zero_one']) 
291  304  elif 'core' in keyword and 'quotient' in keyword and len(keyword)==2: 
292  305  return from_core_and_quotient(keyword['core'], keyword['quotient']) 
293  306  elif 'core' in keyword and 'canonical_quotient' in keyword and len(keyword)==2: 
… 
… 

362  375  for i in reversed(range(len(exp))): 
363  376  p += [i+1]*exp[i] 
364  377  return Partition(p) 
 378  
 379  def from_zero_one(seq): 
 380  """ Returns a partition from its 01 sequence. 
 381  
 382  The 01 sequence is the sequence (infinite in both directions) indicating the steps taken when following the outer rim of the diagram of the partition. Every 01 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)]) 
365  404  
366  405  def from_core_and_quotient(core, quotient): 
367  406  """ 
… 
… 

1713  1752  prevLen = p[i] 
1714  1753  res.append((0, prevLen)) 
1715  1754  return res 
 1755  
 1756  def zero_one_sequence(self): 
 1757  """ Computes the 01 sequence of the partition. 
 1758  
 1759  The 01 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 01 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)]) 
1716  1783  
1717  1784  def core(self, length): 
1718  1785  """ 