# How to obtain all the partitions in a set $A$ such that the union of these partitions equals $A$?

I'm trying to make a visual proof on the irrationality of $\sqrt{2}$. At the moment, I've created a figure to show that $b^2$ elements always constitute a square:

And I want to show that it's not possible to make a square with $2b^2$ elements but showing all possible trials of mounting a square with these number of elements. My guess is that I'll need something that allows me to contruct arbitrary partitions:

{a,b,c} → {{a},{b,c}}, {{a,b},{c}}, ...


Such that their union is always equals to {a,b,c} but I have no idea on how to do it. I've tried a few times with Subsets and Partition but I got no success until now.

-

Needs["Combinatorica"];

SetPartitions[{1, 2, 3}]

SetPartitions[{a,b,c,d}]

(*

{{{1, 2, 3}}, {{1}, {2, 3}}, {{1, 2}, {3}}, {{1, 3}, {2}}, {{1}, {2}, {3}}}

{{{a, b, c, d}}, {{a}, {b, c, d}}, {{a, b}, {c, d}}, {{a, c, d}, {b}},
{{a, b, c}, {d}}, {{a, d}, {b, c}}, {{a, b, d}, {c}}, {{a, c}, {b, d}},
{{a}, {b}, {c, d}}, {{a}, {b, c}, {d}}, {{a}, {b, d}, {c}}, {{a, b}, {c}, {d}},
{{a, c}, {b}, {d}}, {{a, d}, {b}, {c}}, {{a}, {b}, {c}, {d}}}

*)

-
Of course there's a Combinatorica for this. I should have guessed. – evanb Apr 4 '14 at 0:53

If you need to just partition into two pieces and not into something like {{a},{b},{c}} (which I assume you do, for that factor of 2)

you can do something like this:

allPartitions[list_] := Union @@ Map[
Function[order,
Map[{Sort[order[[1 ;; #]]], Sort[order[[# + 1 ;; -1]]]} &,
Range[0, Length[order]/2]]
],
Permutations[list]]


Then

allPartitions[{a, b, c, d, e}]
(* gives
{{{}, {a, b, c, d, e}},
{{a}, {b, c, d, e}},
{{b}, {a, c, d, e}},
{{c}, {a, b, d, e}},
{{d}, {a, b, c, e}},
{{e}, {a, b, c, d}},
{{a, b}, {c, d, e}},
{{a, c}, {b, d, e}},
{{a, d}, {b, c, e}},
{{a, e}, {b, c, d}},
{{b, c}, {a, d, e}},
{{b, d}, {a, c, e}},
{{b, e}, {a, c, d}},
{{c, d}, {a, b, e}},
{{c, e}, {a, b, d}},
{{d, e}, {a, b, c}}}
*)
`
-