This is an extension of my previous post $P=QR$ decomposition of given list

Now for this time, I want to decompose arbitrary list $P$ into three pieces for ordered or non-ordered cases.

Based on the response of @Bill, I consider $P=QR'$ and make $R'=RS$ decomposition, but I realized my input $R$ is no longer a list but a array of lists.

For example, based on the code from @Bill,


To decompose $R$ into $R_1, R_2$, For each case of an array $Q$, I mean $Q[[i]]$, assign $R[[i]]$ as $P$ and then do the similar thing.

I want my code to do for the arbitrary given list, but this case, it seems not good.

Actually, I need $P=QRST$ decomposition but with $P=QRS$ I think I can handle $P=QRST$ decomposition easily.

For unordered case; following are my wrong trials using "for"

P = {a1, a2, a3};
Q = Subsets[P, {1, Length[P] - 1}]
R1 = Map[Complement[P, #] &, Q] 
For[i = 1, i <= Length[R1], i++,
R[[i]]=Subsets[R1[[i]], {1, Length[R1[[i]]] - 1}];
S[[i]]=Complement[R1[[i]], R[[i]] ]; ]

First of all, I notice my decomposition is totally wrong. Dividing the size of element of $Q$ is right, but the number is wrong. Even for three entries and dividing into three parts, the size two should be neglected but the above does not care about it. And Identifying R[[i]] is also totally wrong, because what Susbsets[R1[[1]],{1, Length[R1[[1]]] - 1}] = {{a2},{a3}}....

After @Bill 's response to this post, I realized to make it work for unordered partitions, there should be


for the unordered subsets. First I think of splitting the given array into three; then realized the Mathematica splits the list in an ordered way. i.e., splitting {1,2,3} into three it only produce {{1},{2},{3}}


1 Answer 1


Check this very carefully to make certain it is correct for this example and any others.


which gives values of Q,R,S of


There are lots of other ways of writing that, but I haven't found what I would believe is the simplest possible way of doing that.

Likewise for the unordered partitions.

  • $\begingroup$ wow thanks, last night I tried to make an ordered/unordered case using your previous answers but failed due to inconsistency of size of partition. I am thinking of an unordered case, but problem of dividing the given list into three parts in an unordered way is quite hard. At this moment, since I consider these kinds of decomposition at the level of length 5, I just implement by hand but for the future and curiosity, I want some general approach using Mathematica. $\endgroup$
    – phy_math
    Commented Jul 31, 2021 at 6:41
  • $\begingroup$ Can you give me more hints or methods for unordered partition? I am okay with the complexity $\endgroup$
    – phy_math
    Commented Jul 31, 2021 at 6:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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