Ask Your Question

Iterate over Set partitions of given length

asked 2020-03-28 21:22:34 +0100

tassio gravatar image

(Definition: for a set $S$, and a partition $P=\{P_1,P_2,\ldots,P_k\}$ of $S$, we say that the length of $P$ is $k$.)

I want to iterate over all partitions of $S$ whose length is $k$.

Motivation: I am testing a property for graphs which satisfy a certain coloring-property (which is not standard coloring). So I need to check, in turn, whether a partition in $1,2,\ldots,p$ parts will satisfy the restriction for this particular type of coloring, before I can proceed to the test I want to make.

If it helps, for traditional (proper) graph coloring there is an iterator that does precisely the type of thing I am looking for; it is called all_graph_colorings.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-03-28 22:25:30 +0100

vdelecroix gravatar image

Where have you searched!?

sage: for s in SetPartitions([1,2,3,4,5], 3):
....:     print(s)
{{1, 4, 5}, {2}, {3}}
{{1, 5}, {2, 4}, {3}}
{{1, 5}, {2}, {3, 4}}
{{1, 2, 3}, {4}, {5}}
edit flag offensive delete link more


Indeed, I apologize. I was experimenting with this function as of last night. Thanks! (I guess one mistake was only looking in the documentations for graph functions, hoping to find something in the methods for chromatic number calculation & related things.)

tassio gravatar imagetassio ( 2020-03-29 14:38:25 +0100 )edit

If you feel like the documentation is lacking links to other part of Sage this would be a valuable addition.

vdelecroix gravatar imagevdelecroix ( 2020-03-29 17:58:16 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2020-03-28 21:22:34 +0100

Seen: 211 times

Last updated: Mar 28 '20