Repository: sympy/sympy

Issue:
Cancel doesn't expand the product of irrational conjugates
```
>>> cancel((2+I)*(3-I))
>>> 7+I

>>> cancel((2+I)*(2-I))
>>> (2+I)*(2-I)
```

I would have expected cancel to return 5.

Discussion:

Patch:
diff --git a/sympy/polys/polytools.py b/sympy/polys/polytools.py
index e148ad1a1a..1f15d8d98c 100644
--- a/sympy/polys/polytools.py
+++ b/sympy/polys/polytools.py
@@ -6625,7 +6625,7 @@ def cancel(f, *gens, **args):
         (F, G), opt = parallel_poly_from_expr((p, q), *gens, **args)
     except PolificationFailed:
         if not isinstance(f, (tuple, Tuple)):
-            return f
+            return f.expand()
         else:
             return S.One, p, q
     except PolynomialError as msg:


Test patch:
diff --git a/sympy/polys/tests/test_polytools.py b/sympy/polys/tests/test_polytools.py
index 89360b21ee..236766afc7 100644
--- a/sympy/polys/tests/test_polytools.py
+++ b/sympy/polys/tests/test_polytools.py
@@ -3315,3 +3315,7 @@ def test_issue_17988():
     p = poly(x - 1)
     M = Matrix([[poly(x + 1), poly(x + 1)]])
     assert p * M == M * p == Matrix([[poly(x**2 - 1), poly(x**2 - 1)]])
+
+def test_issue_18205():
+    assert cancel((2 + I)*(3 - I)) == 7 + I
+    assert cancel((2 + I)*(2 - I)) == 5