Repository: sympy/sympy

Issue:
ANP.__new___ not canonicalizing for mod
With
```py3
from sympy.polys.polyclasses import ANP
from sympy import QQ
ANP({(0,):-2, (2,):1}, [1,0,-2], QQ)
```
I get:
```py3
ANP([1, 0, -2], [1, 0, -2], QQ)
```
I think it is wrong because it can be simplified by dividing the mod.

<br>

Here is an unexpected behavior caused by the problem, which raises an error: NotInvertible: zero divisor.
```py3
from sympy import Poly, CRootOf
from sympy.abc import x, y
rr = CRootOf(x**2-2, 0)
Poly(rr**2*y + rr,y,extension=True)
```
Should we add a check for this in `ANP.__new__`?

Discussion:

Fix (patch):
diff --git a/sympy/polys/polyclasses.py b/sympy/polys/polyclasses.py
index 1c12935f36..e930b13220 100644
--- a/sympy/polys/polyclasses.py
+++ b/sympy/polys/polyclasses.py
@@ -2854,6 +2854,8 @@ def __new__(cls, rep, mod, dom):
         else:
             mod = DMP(dup_strip(mod), dom, 0)
 
+        rep = rep.rem(mod)
+
         return cls.new(rep, mod, dom)
 
     @classmethod


Test changes:
diff --git a/sympy/polys/tests/test_polyclasses.py b/sympy/polys/tests/test_polyclasses.py
index 5e2c8f2c3c..5bff63aa9c 100644
--- a/sympy/polys/tests/test_polyclasses.py
+++ b/sympy/polys/tests/test_polyclasses.py
@@ -485,6 +485,10 @@ def test_ANP___init__():
 
     raises(CoercionFailed, lambda: ANP([sqrt(2)], mod, QQ))
 
+    # https://github.com/sympy/sympy/issues/28182
+    f = ANP({(0,): -2, (2,): 1}, [1, 0, -2], QQ)
+    assert f.to_list() == []
+
 
 def test_ANP___eq__():
     a = ANP([QQ(1), QQ(1)], [QQ(1), QQ(0), QQ(1)], QQ)