Repository: sympy/sympy

Issue:
When applying simplify on a Poly it fails:
Executing the code:

```python
sp.Poly('x**2').simplify()
```

Generates the error:

```
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-51-9795ccd009a0> in <module>
----> 1 sp.Poly('x**2').simplify()

/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sympy/core/expr.py in simplify(self, **kwargs)
   3495         """See the simplify function in sympy.simplify"""
   3496         from sympy.simplify import simplify
-> 3497         return simplify(self, **kwargs)
   3498 
   3499     def nsimplify(self, constants=[], tolerance=None, full=False):

/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sympy/simplify/simplify.py in simplify(expr, ratio, measure, rational, inverse, doit, **kwargs)
    578             x, handled),
    579         lambda x: x.func(*[simplify(i, **kwargs) for i in x.args]),
--> 580         simultaneous=False)
    581     if not isinstance(expr, handled):
    582         return done(expr)

TypeError: replace() got an unexpected keyword argument 'simultaneous'
```

Discussion:

Patch:
diff --git a/sympy/polys/polytools.py b/sympy/polys/polytools.py
index 70112de3b6..ecad5eada7 100644
--- a/sympy/polys/polytools.py
+++ b/sympy/polys/polytools.py
@@ -593,7 +593,7 @@ def exclude(f):
 
         return f.per(new, gens=gens)
 
-    def replace(f, x, y=None, *_ignore):
+    def replace(f, x, y=None, **_ignore):
         # XXX this does not match Basic's signature
         """
         Replace ``x`` with ``y`` in generators list.


Test patch:
diff --git a/sympy/simplify/tests/test_simplify.py b/sympy/simplify/tests/test_simplify.py
index 153dfc752f..5c213d63e8 100644
--- a/sympy/simplify/tests/test_simplify.py
+++ b/sympy/simplify/tests/test_simplify.py
@@ -4,7 +4,7 @@
     Eq, erf, exp, exp_polar, expand, expand_multinomial, factor,
     factorial, Float, Function, gamma, GoldenRatio, hyper,
     hypersimp, I, Integral, integrate, KroneckerDelta, log, logcombine, Lt,
-    Matrix, MatrixSymbol, Mul, nsimplify, oo, pi, Piecewise, posify, rad,
+    Matrix, MatrixSymbol, Mul, nsimplify, oo, pi, Piecewise, Poly, posify, rad,
     Rational, S, separatevars, signsimp, simplify, sign, sin,
     sinc, sinh, solve, sqrt, Sum, Symbol, symbols, sympify, tan,
     zoo)
@@ -910,3 +910,7 @@ def test_issue_19484():
     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
+
+def test_issue_19161():
+    polynomial = Poly('x**2').simplify()
+    assert (polynomial-x**2).simplify() == 0