Hi guys,(adsbygoogle = window.adsbygoogle || []).push({});

i have expressions of the type (X*a)(X*b). I want replace this by X^2(a*b).

So i tried building a block which does nothing but

%//.(X*a_)(X*b_)->X^2(a*b).

However, this works only if a is distinct from b. If a and b are equal if HAVE to use the replacement command

%//.(X*a_)(X*a_)->X^2(a*a).

Can I tweak the replace command s.t. Mathematica does the replacement even if a is equal to b, too, without having to write a new replacement command? That would be cool :)

Cheers,

earth2

**Physics Forums | Science Articles, Homework Help, Discussion**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Streamlining Replace in Mathematica 8

**Physics Forums | Science Articles, Homework Help, Discussion**