On Sat, Sep 12, 2009 at 3:44 AM, Erik Stanford <[email protected]>wrote:

>
> For the last couple of days I've been trying to figure out how to get
> Sage to generate a list of partitions of a list. For example, the list
> [1,1,2] would return [ [[1],[1,2]] , [[1,1],[2]] , [[1,1,2]] ] or
> something along those lines. SetPartitions looked like it would have
> been a nice choice, but it discards duplicate values of the same
> number; the ordinary Partitions function looks like it used to do
> that, but there seems to be a disconnect between the documentation and
> the current behavior of the module. Does SAGE support this kind of
> activity, and if so, how would I go about doing it?
>
> If it's in the documentation, I'd be happy to read that. RTFMing
> hasn't gotten me very far at the moment, but that may be because I
> can't find the right part of the M to R.
>
>
>
This inefficient function might do what you want:


def list_partitions(v):
    w = list(enumerate(v))
    S = set([tuple([tuple([a for _, a in list(x)]) for x in p])
                   for p in SetPartitions(w)])
    return [list([list(a) for a in z]) for z in S]

sage: for X in list_partitions2([1,1,2]): print X
[[1, 1, 2]]
[[1, 2], [1]]
[[2], [1], [1]]
[[2], [1, 1]]

sage: for X in list_partitions2([1,1,1,2]): print X
[[2, 1], [1], [1]]
[[2, 1, 1], [1]]
[[1, 1], [1], [2]]
[[1], [1, 2, 1]]
[[1], [1, 1], [2]]
[[1, 1], [1, 2]]
[[1, 2, 1, 1]]
[[1, 1, 1], [2]]
[[1, 1], [2], [1]]

[[1, 1], [2, 1]]
[[1], [1], [1, 2]]
[[1], [1], [2], [1]]
[[2, 1], [1, 1]]
[[1], [2, 1], [1]]


I can't tell since your problem specification isn't precise enough (in
particular, it is worrisome that in your example [1,1,2] you don't seem to
know what the answer is).  Anyway, there is also a mailing list for
sage-combinatorics, which you might post to:

http://groups.google.com/group/sage-combinat-devel

William

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to