# Is there a function to partition an integer set?

First I give an example. For an integer set $$(0,1,2,3,4)$$, there are eight kinds of subdivision or partition like this $$(0,4);\\~~(0,1)(1,4);~~(0,2)(2,4);~~(0,3)(3,4);\\ (0,1)(1,2)(2,4);~~(0,1)(1,3)(3,4);~~(0,2)(2,3)(3,4);~~\\(0,1)(1,2)(2,3)(3,4);$$

For a more general set $$(0,1,2,...,n)$$, there are $$2^{n-1}$$ kinds of partition.I believe that there must be a special name for this kind of partition mathematically. How can I realize it in MMA?

P[n] will return the set you are asking

P[n_] := Partition[Join[{0}, #, {n}], 2, 1] & /@ Subsets[Range[n - 1]]

P[4]


{{{0, 4}}, {{0, 1}, {1, 4}}, {{0, 2}, {2, 4}}, {{0, 3}, {3, 4}}, {{0, 1}, {1, 2}, {2, 4}}, {{0, 1}, {1, 3}, {3, 4}}, {{0, 2}, {2, 3}, {3, 4}}, {{0, 1}, {1, 2}, {2, 3}, {3, 4}}}

• Thanks, it works well!!! Commented Apr 1, 2019 at 9:08
• @user10709 I'm glad I helped! Commented Apr 1, 2019 at 9:10
• Of course, you can combine the functions so that only one application of Map[] is needed: Partition[Join[{0}, #, {n}], 2, 1] & /@ Subsets[Range[n - 1]]. Commented Apr 1, 2019 at 14:35
• @J.M.isslightlypensive yes, you are right Commented Apr 1, 2019 at 14:52