Here's another way, if the ys all appear in the denominator. We convert the expression to a polynomial with y -> 1/u and use some of the polynomial functions.
expr1 = x + (2 x^2)/y - (3 x^3)/y^2;
FromCoefficientRules[
MapAt[Abs, CoefficientRules[expr1 /. y -> 1/u, {x, u}], {All, {-1}}],
{x, 1/y}]
(* x + (3 x^3)/y^2 + (2 x^2)/y *)
Another example:
Normal@Series[-2 Exp[-x^2/y], {x, 0, 7}]
(* -2 + x^6/(3 y^3) - x^4/y^2 + (2 x^2)/y *)
FromCoefficientRules[
MapAt[Abs,
CoefficientRules[Normal@Series[-2 Exp[-x^2/y], {x, 0, 7}] /. y -> 1/u, {x, u}],
{All, -1}],
{x, 1/y}]
(* 2 + x^6/(3 y^3) + x^4/y^2 + (2 x^2)/y *)
To answer the implicit question about how to figure out what went wrong with the pattern replacement (the case of the disappearing /), it is a good idea to start by examining the FullForm of the expression.
FullForm[expr1]
(* Plus[x, Times[-3, Power[x, 3], Power[y, -2]], Times[2, Power[x, 2], Power[y, -1]]] *)
And if you have trouble seeing the problem, you can use some of the other pattern-matching functions to test your patterns. Here Cases can be helpful.
Cases[expr1, n_?Negative, Infinity]
(* {-3, -2, -1} *)
Now look where those negative numbers come from. One is a coefficient; the others are exponents from powers of y. All are multiplied by -1 by your replacement, which converts the negative powers of y to positive powers, in effect removing the / from each.
exp = x + (2 x^2)/y - (3 x^3)/y^2 + (- Sin[z]^2 - Cos[z]^2)/(-z)and tryFullSimplify /@ exp– halirutan Nov 07 '13 at 03:18