# [seqfan] Re: Partitioning the sequence (?)

Peter Pein petsie at dordos.net
Sat Dec 27 16:02:23 CET 2008

```zak seidov schrieb:
> Joshua,
> this (with "s" at end!) is better
> but still is not what i need:
>
> <<DiscreteMath`Combinatorica`;Partitions[4]
> {{4},{3,1},{2,2},{2,1,1},{1,1,1,1}}
>
> while this is OK:
> << DiscreteMath`Combinatorica`; Permutations /@ Partitions[4]
> {{{4}},{{3,1},{1,3}},{{2,2}},{{2,1,1},{1,2,1},{1,1,2}},{{1,1,1,1}}}
>
> - exactly what Franklin gave in his message below
> (though in the reverse order).
> thx, zak
>
> That is we need some editing of
>
> %t A080577 <<DiscreteMath`Combinatorica`; Partition[6]
>
> this way :
>
> %t A080577 <<DiscreteMath`Combinatorica`; Permutations /@  Partitions[6] -
> Zak Seidov (zakseidov(AT)yahoo.com) Dec 25 2008
>
>

Hi Zak, dear list,

Well, IMHO the oneliner in A080577 should read:
%t A080577 <<DiscreteMath`Combinatorica`; Flatten[ Partitions /@ Range[7] ]
to get the seq. A080577

I know the permutations of partitions as compositions. Mathematica had no such
function until ver. 5.2 (or I did not find it).

To get the compositions in reverse lexicographic order, simply type

Compositions[0] = {{}};
Compositions[(n_Integer)?Positive] :=
Flatten[Table[
Prepend[#1, k]& /@ Compositions[n - k],
{k, n, 1, -1}], 1]

into Mma to get e.g.
In[3]:= Compositions[4]
Out[3]=
{{4}, {3, 1}, {2, 2}, {2, 1, 1}, {1, 3}, {1, 2, 1}, {1, 1, 2}, {1, 1, 1, 1}}

and with Flatten[ Compositions /@ Range[6] ] we end at A066099.

Happy new year,
Peter

P.S.: sorry, if this mail receives you more than once. There are strange
difficulties with thunderbird.

```