1
$\begingroup$

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.

$\endgroup$
7
  • $\begingroup$ How many particles are you dealing with? It may be easiest to just filter the result of the function you found after the fact (e.g. using Select or Cases) 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 ResourceFunction SetPartitions (notice no K) relevant too. $\endgroup$
    – MarcoB
    Commented Sep 2, 2022 at 12:10
  • $\begingroup$ I'm working with an arbitrary number of them, which I think is going to make it rather inefficient to modify the result after obtaining it. $\endgroup$
    – Marcosko
    Commented Sep 2, 2022 at 12:21
  • $\begingroup$ And SetPartitions may not be very useful, since I do care about the ordering within each subset $\endgroup$
    – Marcosko
    Commented Sep 2, 2022 at 12:22
  • $\begingroup$ I understand that the number is arbitrary, but how big is it practically speaking? Have you already tried the filtering approach in a practical example? I am also confused by your last comment: KSetPartitions has the exact same caveat as SetPartitions, i.e. that "Both the order of the blocks and the order within each block are ignored." $\endgroup$
    – MarcoB
    Commented Sep 2, 2022 at 14:13
  • $\begingroup$ For n=6,what is the result? Does it contain {{1,4,6},{2,3},{5}}? $\endgroup$
    – cvgmt
    Commented Sep 3, 2022 at 0:56

1 Answer 1

3
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ (+1) typo: n=10 -> n=6 $\endgroup$
    – cvgmt
    Commented Sep 4, 2022 at 1:09
  • $\begingroup$ @cvgmt Fixed, thank you! $\endgroup$
    – MarcoB
    Commented Sep 4, 2022 at 2:54

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.