So I have this replacement rule that tends to work in most cases, except occasionally in cases like this:
p[{3, 4}] p[{5, 6}] p[{1, 4, 6}] p[{2, 3, 5}] //.
{p[list1_] p[list2_] :>
If[Length[Intersection[list1, list2]] != 0, p[Union[list1, list2]]]}
the problem seems to be that every time it evaluates the replacement rule, it only looks at the first two terms. If there's no replacement to be done it then just doesn't do anything. Does anybody know a way to maybe "scramble" the terms in the list or make the replacement look at every part of the expression?
If
evaluates toFalse
, probablyp[{3, 4}] p[{5, 6}] p[{1, 4, 6}] p[{2, 3, 5}] //. {p[list1_] p[list2_] -> If[Length[Intersection[list1, list2]] != 0, p[Union[list1, list2]], p[list1] p[list2]]}
? $\endgroup$p[{1,2}] p[{2,3}] p[{4}] p[{5,6}] p[{6,1}]
. $\endgroup$p[{1,2,3,5,6}] p[{4}]
$\endgroup$