1
$\begingroup$

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,

P={a1,a2,a3,a4};
(*ordered*)
Q=Table[Take[P,i],{i,Length[P]-1}]
R=Table[Drop[P,i],{i,Length[P]-1}]
(*unordered*)
Q=Subsets[P,{1,Length[P]-1}]
R=Map[Complement[P,#]&,Q] 

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

 v=Map[TakeList[P,#]&,Flatten[Map[Permutations,IntegerPartitions[Length[P],{3}]],1]];

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

$\endgroup$

1 Answer 1

2
$\begingroup$

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

P={a1,a2,a3,a4,a5,a6};
(*ordered*)
v=Map[TakeList[P,#]&,Flatten[Map[Permutations,IntegerPartitions[Length[P],{3}]],1]];
Q=Map[#[[1]]&,v]
R=Map[#[[2]]&,v]
S=Map[#[[3]]&,v]

which gives values of Q,R,S of

{{a1,a2,a3,a4},{a1},{a1},{a1,a2,a3},{a1,a2,a3},{a1,a2},{a1,a2},{a1},{a1},{a1,a2}}
{{a5},{a2,a3,a4,a5},{a2},{a4,a5},{a4},{a3,a4,a5},{a3},{a2,a3,a4},{a2,a3},{a3,a4}}
{{a6},{a6},{a3,a4,a5,a6},{a6},{a5,a6},{a6},{a4,a5,a6},{a5,a6},{a4,a5,a6},{a5,a6}}

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.

$\endgroup$
2
  • $\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.