Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

enter image description here

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.

share|improve this question

SetPartitions[{1, 2, 3}]



{{{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}}}

share|improve this answer
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[
             Map[{Sort[order[[1 ;; #]]], Sort[order[[# + 1 ;; -1]]]} &, 
                 Range[0, Length[order]/2]]


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}}}
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.