As was commented, you should probably tell us also about the problematic rule you cannot use but anyway you might be interested in the following approach:
As you (should) know, everything in Mathematica is an expression, in other words it can be expressed as f[x,y,...]
Your expression:
expr = p[{1, 2}] p[{2, 3}]^2 p[{4, 5}]
is actually interpreted as:
FullForm[expr]
Times[p[List[1,2]],Power[p[List[2,3]],2],p[List[4,5]]]
If you are already familiar with replacement rules then you'll certainly understand the following replacement which will transform your expression in a form close to what you'd like:
Given this function:
myTimes[x_, n_Integer] := myTimes @@ ConstantArray[x, n]
see what happens here:
expr /. Power -> myTimes /. Times -> myTimes
myTimes[myTimes[p[{2,3}],p[{2,3}]],p[{1,2}],p[{4,5}]]
Almost done. Let's add the Flat
property to function myTimes
:
SetAttributes[myTimes, Flat]
and do again the same replacement than previously:
newexpr = expr /. Power -> myTimes /. Times -> myTimes
myTimes[p[{2, 3}], p[{2, 3}], p[{1, 2}], p[{4, 5}]]
That's it. The idea is to work on this new and temporary expression with your set of replacement rules. Then, to go back in real world:
newexpr /. myTimes -> Times
p[{1,2}] p[{2,3}]^2 p[{4,5}]
p[{1,2,3}] p[{4,5}]
. I actually think I've found a way around it, although not in the most elegant way. $\endgroup$Times @@ p /@ Union @@@ Gather[ p[{1, 2}] p[{2, 3}]^2 p[{4, 5}] /. a_^b_ :> a /. HoldPattern@Times[a__] :> Sequence @@@ {a}, Intersection[#, #2] != {} &]
$\endgroup$p[{2,3}]
while in your comment you show that at the end you don't take into account this repeated element ... ? $\endgroup$