1
$\begingroup$

For given arbitrary lists, I want to decompose the list into two parts and assign individual lists.

i.e., I want to decompose, $P=QR$.

And I can think of its decomposition in two cases: ordered and non-ordered cases.

For example, Let $P=\{a1,a2,a3\}$,

For ordered case, I have $2$ cases.

$(Q,R)=\{ (\{a1\}, \{a2,a3\}), (\{a1,a2\}, \{a3\}) \}$

where the ordering of a1,a2,a3 are strictly followed.

For non-ordered case, I have $3+3=6$ possible decomposition. $(Q,R) = \{ (\{a1\}, \{a2, a3\}), (\{a2\}, \{a1,a3\}), (\{a3\}, \{a1,a2\}), (\{a1,a2\}, \{a3\}), (\{a1,a3\},\{a2\}), (\{a2,a3\},\{a1\}) \}$.

And in this case I want to assign $Q[[1]]=\{a1\}, R[[1]]=\{a2,a3\}, $ and so on.

For $P=\{a1, a2,a3,a4\}$ case I have $4+6+4=14$ unordered partitions.

explicitly, neglecting $a$'s I have

$1234= (123,4) + (124,3) + (134,2) + (234,1) + (12,34) + (13,24) + (14,23) + (23,14) + (24,13) + (34,12) + (1,234) + (2,134) + (3,124)+ (4,123)$

For given lists, I want to make ordered and non-ordered partitions via Mathematica.


My little trial, is for ordered case it seems mathematica command table might be good. Because naively, my pseudo code

 Q=Table[{P[1], \cdots, P[[i]]\}, ]
 R=Table[P[[i+1]], ]

seems fine.

And for non-ordered case, subset command might be useful. Because,

Subsets[{a, b, c}]
{{}, {a}, {b}, {c}, {a, b}, {a, c}, {b, c}, {a, b, c}}

except for the empty set and the whole set, I want them as $Q$, but I have trouble identifying $R$.


$\endgroup$

1 Answer 1

1
$\begingroup$

Your intuition for what to try seems good. See if you can study the help pages to understand the following and how it tries to implement your pseudocode.

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]
$\endgroup$

Your Answer

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

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