I'm trying to develop a function that computes some numerators for scattering amplitudes and I need to generate a collection of tree diagrams that contain a set of particles (effectively numbers) {1,2,...,n}
. For that I need to find all the possible partitions of the set of particles, with the order not mattering. The only thing is that both the first and last particle (i.e. numbers 1 and n) have to be at the beginning and end of the first subset, respectively. For example, a couple of valid partitions for n=6 would be {{1,3,6},{2,4},{5}}
and {{1,2,4,6},{3},{5}}
. For this, I found the very useful function KSetPartitions. However, I need to modify it so that I include the detail that the last particle n has to be at the end of the first subset. Could anyone provide me with some help on how to do that? I'm fairly new to Mathematica and I don't see exactly what I would need to change. Thanks in advance.
1 Answer
Through the discussion there seems to be an assumption that the desired output are partitions of the original list in three blocks. That's what I'm using below.
My approach is to generate all possible blocks using e.g. KSetPartitions
and then remove those that do not satisfy the desired pattern. This, of course, is rather inefficient, but it requires no modification of the existing function, and it works well for small $n$ (e.g. $n\leq15$ or so).
For the $n=6$ case:
With[{n = 6},
all = ResourceFunction["KSetPartitions"][n, 3];
Cases[all, {{1, ___, n}, ___}]
]
(* Out:
{
{{1,4,5,6},{2},{3}},
{{1,5,6},{2},{3,4}},
{{1,3,5,6},{2},{4}},
{{1,6},{2},{3,4,5}},
{{1,3,6},{2},{4,5}},
{{1,3,4,6},{2},{5}},
{{1,4,6},{2},{3,5}},
{{1,5,6},{2,3},{4}},
{{1,5,6},{2,4},{3}},
{{1,2,5,6},{3},{4}},
{{1,6},{2,3},{4,5}},
{{1,6},{2,4,5},{3}},
{{1,2,6},{3},{4,5}},
{{1,4,6},{2,3},{5}},
{{1,2,4,6},{3},{5}},
{{1,4,6},{2,5},{3}},
{{1,6},{2,3,4},{5}},
{{1,6},{2,5},{3,4}},
{{1,2,6},{3,4},{5}},
{{1,6},{2,3,5},{4}},
{{1,6},{2,4},{3,5}},
{{1,2,6},{3,5},{4}},
{{1,2,3,6},{4},{5}},
{{1,3,6},{2,4},{5}},
{{1,3,6},{2,5},{4}}
}
*)
The above results contain the sample desired output indicated by OP, although there seem to be 25 such cases, and not 24 as OP mentioned.
Select
orCases
) rather than trying to modify the function's code to obtain exactly what you want. Additionally, if you want to find pool partitions, you may find the ResourceFunctionSetPartitions
(notice no K) relevant too. $\endgroup$SetPartitions
may not be very useful, since I do care about the ordering within each subset $\endgroup$KSetPartitions
has the exact same caveat asSetPartitions
, i.e. that "Both the order of the blocks and the order within each block are ignored." $\endgroup$n=6
,what is the result? Does it contain{{1,4,6},{2,3},{5}}
? $\endgroup$