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 - The Fusion of Science and Community**

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

# Streamlining Replace in Mathematica 8

Loading...

Similar Threads - Streamlining Replace Mathematica | Date |
---|---|

Matlab Replace NaN with next element in Multidimensional Array | Apr 6, 2016 |

[Matlab] Replace pixels of an image with theta of Polar Coordinates | Apr 15, 2014 |

Mathematica : Noncommutative Multiply and Replacement Rules | Apr 4, 2014 |

Streamlines in MATLAB | May 3, 2008 |

Plotting streamlines using Mathematica | Apr 10, 2007 |

**Physics Forums - The Fusion of Science and Community**