According to this stackexchange thread, cannot swap sums and products , you cannot interchange sums and products.
$$ \Sigma\Pi x_{i,j} \ne \Pi\Sigma x_{i,j} $$
However, I found in the book, equations 8.61-8.63 patter recognition and machine learning by Bishop, you can do this. Could someone explain why you can interchange sums and products? thank you very much.
It seems to be specific to the algorithm you are looking at. I found a slide with a concrete example: https://www.cs.auckland.ac.nz/compsci773s1t/lectures/773-GGpdfs/773GG-BeliefPropagation-handouts.pdf
Basically the idea is similar to the following example:
$$x_1y_1z_1 + x_1y_1z_2+x_1y_2z_1+x_1y_2z_2 + x_2y_1z_1 + x_2y_1z_2+x_2y_2z_1+x_2y_2z_2 = (x_1+x_2)(y_1+y_2)(z_1+z_2)$$ but with much more variables.
Notice how the product of sum requires much less computation than the sum of product and that's the point of the algorithm.