# 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 sage: Partition(core=[],quotient=([2, 1], , [1, 1, 1])) [11, 5, 5, 3, 2, 2, 2] We can compute the 0-1 sequence and go back and forth:: sage: Partition(zero_one=[1, 1, 1, 1, 0, 1, 0]) [5, 4] sage: all(Partition(zero_one=mu.zero_one_sequence()) == mu for n in range(5) for mu in Partitions(n)) True We can compute the Frobenius coordinates (or beta numbers), and go back and forth:: * a list (the default) * using exponential notation * by Frobenius coordinates (also called beta numbers) * specifying its 0-1 sequence * specifying the core and the quotient * specifying the core and the canonical quotient (TODO) [11, 5, 5, 3, 2, 2, 2] sage: Partition(frobenius_coordinates=([3,2],[4,0])) [4, 4, 1, 1, 1] sage: Partition(zero_one=[1, 1, 1, 1, 0, 1, 0]) [5, 4] sage: [2,1] in Partitions() True sage: [2,1,0] in Partitions() return from_frobenius_coordinates(keyword['frobenius_coordinates']) elif 'exp' in keyword and len(keyword)==1: return from_exp(keyword['exp']) elif 'zero_one' in keyword and len(keyword)==1: return from_zero_one(keyword['zero_one']) elif 'core' in keyword and 'quotient' in keyword and len(keyword)==2: return from_core_and_quotient(keyword['core'], keyword['quotient']) elif 'core' in keyword and 'canonical_quotient' in keyword and len(keyword)==2: for i in reversed(range(len(exp))): p += [i+1]*exp[i] return Partition(p) def from_zero_one(seq): """ Returns a partition from its 0-1 sequence. 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. INPUT:: 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). EXAMPLES:: sage: Partition(zero_one=[]) [] sage: Partition(zero_one=[1,0])  sage: Partition(zero_one=[1, 1, 1, 1, 0, 1, 0]) [5, 4] TESTS:: sage: all(Partition(zero_one=mu.zero_one_sequence()) == mu for n in range(10) for mu in Partitions(n)) True """ tmp = [i for i in range(len(seq)) if seq[i] == 0] return Partition([tmp[i]-i for i in range(len(tmp)-1,-1,-1)]) def from_core_and_quotient(core, quotient): """ prevLen = p[i] res.append((0, prevLen)) return res def zero_one_sequence(self): """ Computes the 0-1 sequence of the partition. 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. OUTPUT:: 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). EXAMPLES:: sage: Partition([5,4]).zero_one_sequence() [1, 1, 1, 1, 0, 1, 0] sage: Partition([]).zero_one_sequence() [] sage: Partition().zero_one_sequence() [1, 1, 0] TESTS:: sage: all(Partition(zero_one=mu.zero_one_sequence()) == mu for n in range(10) for mu in Partitions(n)) True """ tmp = [self.get_part(i)-i for i in range(len(self))] return ([Integer(not (i in tmp)) for i in range(-len(self)+1,self.get_part(0)+1)]) def core(self, length): """