Repository: sympy/sympy

Issue:
sympy cannot simplify sign(x) * abs(x)
```
>>> from sympy import Symbol, sign
>>> x = Symbol('x', real=True)
>>> x_new = abs(x)*sign(x)
>>> x_new
Abs(x)*sign(x)
>>> x_new.simplify()
Abs(x)*sign(x)
```

I would expect the result to be just `x`. gh-19277 may be related.


Discussion:

Patch:
diff --git a/sympy/functions/elementary/piecewise.py b/sympy/functions/elementary/piecewise.py
index c4a3d60fb6..7b8eea208e 100644
--- a/sympy/functions/elementary/piecewise.py
+++ b/sympy/functions/elementary/piecewise.py
@@ -1238,9 +1238,10 @@ def piecewise_simplify(expr, **kwargs):
             if eqs and not other:
                 eqs = list(ordered(eqs))
                 for e in eqs:
-                    # these blessed lhs objects behave like Symbols
-                    # and the rhs are simple replacements for the "symbols"
-                    if _blessed(e):
+                    # allow 2 args to collapse into 1 for any e
+                    # otherwise limit simplification to only simple-arg
+                    # Eq instances
+                    if len(args) == 2 or _blessed(e):
                         _prevexpr = _prevexpr.subs(*e.args)
                         _expr = _expr.subs(*e.args)
             # Did it evaluate to the same?
diff --git a/sympy/simplify/simplify.py b/sympy/simplify/simplify.py
index b79aba30f5..33c8e58ae6 100644
--- a/sympy/simplify/simplify.py
+++ b/sympy/simplify/simplify.py
@@ -615,6 +615,11 @@ def done(e):
     from sympy.simplify.hyperexpand import hyperexpand
     from sympy.functions.special.bessel import BesselBase
     from sympy import Sum, Product, Integral
+    from sympy.functions.elementary.complexes import sign, Abs
+
+    # must come before `Piecewise` since this introduces more `Piecewise` terms
+    if expr.has(sign):
+        expr = expr.rewrite(Abs)
 
     # Deal with Piecewise separately to avoid recursive growth of expressions
     if expr.has(Piecewise):


Test patch:
diff --git a/sympy/series/tests/test_gruntz.py b/sympy/series/tests/test_gruntz.py
index a7fa3199d7..c1b2b55db3 100644
--- a/sympy/series/tests/test_gruntz.py
+++ b/sympy/series/tests/test_gruntz.py
@@ -397,7 +397,7 @@ def test_I():
     assert gruntz(I*x, x, oo) == I*oo
     assert gruntz(y*I*x, x, oo) == y*I*oo
     assert gruntz(y*3*I*x, x, oo) == y*I*oo
-    assert gruntz(y*3*sin(I)*x, x, oo).simplify() == sign(y)*I*oo
+    assert gruntz(y*3*sin(I)*x, x, oo).simplify().rewrite(sign) == sign(y)*I*oo
 
 
 def test_issue_4814():
diff --git a/sympy/simplify/tests/test_simplify.py b/sympy/simplify/tests/test_simplify.py
index 3a137151b9..52934ff97f 100644
--- a/sympy/simplify/tests/test_simplify.py
+++ b/sympy/simplify/tests/test_simplify.py
@@ -897,3 +897,16 @@ def test_issue_17292():
     assert simplify(abs(x)/abs(x**2)) == 1/abs(x)
     # this is bigger than the issue: check that deep processing works
     assert simplify(5*abs((x**2 - 1)/(x - 1))) == 5*Abs(x + 1)
+
+def test_issue_19484():
+    assert simplify(sign(x) * Abs(x)) == x
+
+    e = x + sign(x + x**3)
+    assert simplify(Abs(x + x**3)*e) == x**3 + x*Abs(x**3 + x) + x
+
+    e = x**2 + sign(x**3 + 1)
+    assert simplify(Abs(x**3 + 1) * e) == x**3 + x**2*Abs(x**3 + 1) + 1
+
+    f = Function('f')
+    e = x + sign(x + f(x)**3)
+    assert simplify(Abs(x + f(x)**3) * e) == x*Abs(x + f(x)**3) + x + f(x)**3