How to make a replacement rule that will only be applied on parts of an expression that would not break some condition on a whole expression?
For example if we have $\frac{xy}{(x-y)(x+y)}$ and I want to change $y$ to $x$ without turning it to infinity so that it becomes $\frac{x^2}{(x-y)2x}$. Or it not gonna rise some warning, error, etc.