{"instance_id": "sympy__sympy-19346", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sympy/printing/repr.py b/sympy/printing/repr.py\nindex c936a692c0..c1c3650c7e 100644\n--- a/sympy/printing/repr.py\n+++ b/sympy/printing/repr.py\n@@ -13,6 +13,7 @@\n from sympy.core.mul import Mul\n from mpmath.libmp import repr_dps, to_str as mlib_to_str\n \n+from sympy.core.compatibility import default_sort_key\n from .printer import Printer\n \n \n@@ -250,6 +251,22 @@ def _print_tuple(self, expr):\n         else:\n             return \"(%s)\" % self.reprify(expr, \", \")\n \n+    def _print_set(self, expr):\n+        if not expr:\n+            return \"set()\"\n+        return \"{%s}\" % self.reprify(sorted(expr, key=default_sort_key), \", \")\n+\n+    def _print_frozenset(self, expr):\n+        if not expr:\n+            return \"frozenset()\"\n+        return \"frozenset({%s})\" % self.reprify(\n+            sorted(expr, key=default_sort_key), \", \")\n+\n+    def _print_dict(self, expr):\n+        items = sorted(expr.items(), key=lambda kv: default_sort_key(kv[0]))\n+        return \"{%s}\" % \", \".join(\n+            \"%s: %s\" % (self._print(k), self._print(v)) for k, v in items)\n+\n     def _print_WildFunction(self, expr):\n         return \"%s('%s')\" % (expr.__class__.__name__, expr.name)\n \n", "model": "claude-sonnet-5-5", "steps": 8, "finished": true, "patch_lines": 35, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 35, "steps": 8}], "ms": 24103}
{"instance_id": "sympy__sympy-19495", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sympy/sets/conditionset.py b/sympy/sets/conditionset.py\nindex 118eda6f77..24b213c0f8 100644\n--- a/sympy/sets/conditionset.py\n+++ b/sympy/sets/conditionset.py\n@@ -242,8 +242,6 @@ def _eval_subs(self, old, new):\n             return self.func(sym, cond, base)\n         cond = self.condition.subs(old, new)\n         base = self.base_set.subs(old, new)\n-        if cond is S.true:\n-            return ConditionSet(new, Contains(new, base), base)\n         return self.func(self.sym, cond, base)\n \n     def dummy_eq(self, other, symbol=None):\ndiff --git a/sympy/sets/tests/test_conditionset.py b/sympy/sets/tests/test_conditionset.py\nindex 0d4527a52c..0d53ff0d45 100644\n--- a/sympy/sets/tests/test_conditionset.py\n+++ b/sympy/sets/tests/test_conditionset.py\n@@ -125,7 +125,7 @@ def test_subs_CondSet():\n     assert ConditionSet(\n         n, n < x, Interval(0, oo)).subs(x, p) == Interval(0, oo)\n     assert ConditionSet(\n-        n, n < x, Interval(-oo, 0)).subs(x, p) == S.EmptySet\n+        n, n < x, Interval(-oo, 0)).subs(x, p) == Interval(-oo, 0)\n     assert ConditionSet(f(x), f(x) < 1, {w, z}\n         ).subs(f(x), y) == ConditionSet(y, y < 1, {w, z})\n \n", "model": "claude-sonnet-5-5", "steps": 9, "finished": true, "patch_lines": 26, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 2, "diff_lines": 26, "steps": 9}], "ms": 109226}
{"instance_id": "sympy__sympy-19637", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sympy/core/sympify.py b/sympy/core/sympify.py\nindex a3f1ce2851..4266773dff 100644\n--- a/sympy/core/sympify.py\n+++ b/sympy/core/sympify.py\n@@ -513,7 +513,7 @@ def kernS(s):\n             while kern in s:\n                 kern += choice(string.ascii_letters + string.digits)\n             s = s.replace(' ', kern)\n-        hit = kern in s\n+            hit = kern in s\n \n     for i in range(2):\n         try:\n", "model": "claude-sonnet-5-5", "steps": 6, "finished": true, "patch_lines": 13, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 13, "steps": 6}], "ms": 14025}
{"instance_id": "sympy__sympy-19783", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sympy/physics/quantum/dagger.py b/sympy/physics/quantum/dagger.py\nindex 17da3cfd2c..cb1d7d36cf 100644\n--- a/sympy/physics/quantum/dagger.py\n+++ b/sympy/physics/quantum/dagger.py\n@@ -2,7 +2,7 @@\n \n from __future__ import print_function, division\n \n-from sympy.core import Expr\n+from sympy.core import Expr, Mul\n from sympy.functions.elementary.complexes import adjoint\n \n __all__ = [\n@@ -85,5 +85,12 @@ def __new__(cls, arg):\n             return obj\n         return Expr.__new__(cls, arg)\n \n+    def __mul__(self, other):\n+        from sympy.physics.quantum import IdentityOperator\n+        if isinstance(other, IdentityOperator):\n+            return self\n+\n+        return Mul(self, other)\n+\n adjoint.__name__ = \"Dagger\"\n adjoint._sympyrepr = lambda a, b: \"Dagger(%s)\" % b._print(a.args[0])\n", "model": "claude-sonnet-5-5", "steps": 7, "finished": true, "patch_lines": 26, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 26, "steps": 7}], "ms": 21144}
{"instance_id": "sympy__sympy-19954", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sympy/combinatorics/perm_groups.py b/sympy/combinatorics/perm_groups.py\nindex de94ddabb4..f9189cec51 100644\n--- a/sympy/combinatorics/perm_groups.py\n+++ b/sympy/combinatorics/perm_groups.py\n@@ -2198,14 +2198,19 @@ def _number_blocks(blocks):\n                 for i, r in enumerate(rep_blocks):\n                     if len(r) > len(rep) and rep.issubset(r):\n                         # i-th block system is not minimal\n-                        del num_blocks[i], blocks[i]\n-                        to_remove.append(rep_blocks[i])\n+                        to_remove.append(i)\n                     elif len(r) < len(rep) and r.issubset(rep):\n                         # the system being checked is not minimal\n                         minimal = False\n                         break\n-                # remove non-minimal representative blocks\n-                rep_blocks = [r for r in rep_blocks if r not in to_remove]\n+                # remove non-minimal block systems\n+                if to_remove:\n+                    blocks = [b for i, b in enumerate(blocks)\n+                              if i not in to_remove]\n+                    num_blocks = [b for i, b in enumerate(num_blocks)\n+                                  if i not in to_remove]\n+                    rep_blocks = [b for i, b in enumerate(rep_blocks)\n+                                  if i not in to_remove]\n \n                 if minimal and num_block not in num_blocks:\n                     blocks.append(block)\n", "model": "claude-sonnet-5-5", "steps": 6, "finished": true, "patch_lines": 28, "candidates": [{"compile_ok": 0, "loc_hits": 1, "files": 1, "diff_lines": 28, "steps": 6}], "ms": 14111}
{"instance_id": "sympy__sympy-20154", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/doc/src/modules/utilities/iterables.rst b/doc/src/modules/utilities/iterables.rst\nindex 4cd9248c51..1e4ae5c085 100644\n--- a/doc/src/modules/utilities/iterables.rst\n+++ b/doc/src/modules/utilities/iterables.rst\n@@ -45,7 +45,7 @@ of partions.\n partitions::\n \n     >>> from sympy.utilities.iterables import partitions\n-    >>> [p.copy() for s, p in partitions(7, m=2, size=True) if s == 2]\n+    >>> [p for s, p in partitions(7, m=2, size=True) if s == 2]\n     [{1: 1, 6: 1}, {2: 1, 5: 1}, {3: 1, 4: 1}]\n \n multiset_partitions::\ndiff --git a/sympy/utilities/iterables.py b/sympy/utilities/iterables.py\nindex dd36dea304..e0a80e7a5e 100644\n--- a/sympy/utilities/iterables.py\n+++ b/sympy/utilities/iterables.py\n@@ -1738,19 +1738,12 @@ def partitions(n, m=None, k=None, size=False):\n     {2: 1, 4: 1}\n     {3: 2}\n \n-    Note that the _same_ dictionary object is returned each time.\n-    This is for speed:  generating each partition goes quickly,\n-    taking constant time, independent of n.\n+    Each partition is returned as a new dictionary, so the results can be\n+    stored safely:\n \n     >>> [p for p in partitions(6, k=2)]\n-    [{1: 6}, {1: 6}, {1: 6}, {1: 6}]\n-\n-    If you want to build a list of the returned dictionaries then\n-    make a copy of them:\n-\n-    >>> [p.copy() for p in partitions(6, k=2)]  # doctest: +SKIP\n     [{2: 3}, {1: 2, 2: 2}, {1: 4, 2: 1}, {1: 6}]\n-    >>> [(M, p.copy()) for M, p in partitions(6, k=2, size=True)]  # doctest: +SKIP\n+    >>> [(M, p) for M, p in partitions(6, k=2, size=True)]\n     [(3, {2: 3}), (4, {1: 2, 2: 2}), (5, {1: 4, 2: 1}), (6, {1: 6})]\n \n     References\n@@ -1802,9 +1795,9 @@ def partitions(n, m=None, k=None, size=False):\n         keys.append(r)\n     room = m - q - bool(r)\n     if size:\n-        yield sum(ms.values()), ms\n+        yield sum(ms.values()), ms.copy()\n     else:\n-        yield ms\n+        yield ms.copy()\n \n     while keys != [1]:\n         # Reuse any 1's.\n@@ -1842,9 +1835,9 @@ def partitions(n, m=None, k=None, size=False):\n             break\n         room -= need\n         if size:\n-            yield sum(ms.values()), ms\n+            yield sum(ms.values()), ms.copy()\n         else:\n-            yield ms\n+            yield ms.copy()\n \n \n def ordered_partitions(n, m=None, sort=True):\n", "model": "claude-sonnet-5-5", "steps": 16, "finished": false, "patch_lines": 64, "candidates": [{"compile_ok": 0, "loc_hits": 1, "files": 2, "diff_lines": 64, "steps": 16}], "ms": 41982}
{"instance_id": "sympy__sympy-20428", "model_name_or_path": "cain-70b-e124", "model_patch": "diff --git a/sympy/polys/polytools.py b/sympy/polys/polytools.py\nindex 70112de3b6..b81a1fa0dc 100644\n--- a/sympy/polys/polytools.py\n+++ b/sympy/polys/polytools.py\n@@ -1,7215 +1,5 @@\n-\"\"\"User-friendly public interface to polynomial functions. \"\"\"\n-\n-\n-from functools import wraps, reduce\n-from operator import mul\n-\n-from sympy.core import (\n-    S, Basic, Expr, I, Integer, Add, Mul, Dummy, Tuple\n-)\n-from sympy.core.basic import preorder_traversal\n-from sympy.core.compatibility import iterable, ordered\n-from sympy.core.decorators import _sympifyit\n-from sympy.core.evalf import pure_complex\n-from sympy.core.function import Derivative\n-from sympy.core.mul import _keep_coeff\n-from sympy.core.relational import Relational\n-from sympy.core.symbol import Symbol\n-from sympy.core.sympify import sympify, _sympify\n-from sympy.logic.boolalg import BooleanAtom\n-from sympy.polys import polyoptions as options\n-from sympy.polys.constructor import construct_domain\n-from sympy.polys.domains import FF, QQ, ZZ\n-from sympy.polys.domains.domainelement import DomainElement\n-from sympy.polys.fglmtools import matrix_fglm\n-from sympy.polys.groebnertools import groebner as _groebner\n-from sympy.polys.monomials import Monomial\n-from sympy.polys.orderings import monomial_key\n-from sympy.polys.polyclasses import DMP, DMF, ANP\n-from sympy.polys.polyerrors import (\n-    OperationNotSupported, DomainError,\n-    CoercionFailed, UnificationFailed,\n-    GeneratorsNeeded, PolynomialError,\n-    MultivariatePolynomialError,\n-    ExactQuotientFailed,\n-    PolificationFailed,\n-    ComputationFailed,\n-    GeneratorsError,\n-)\n-from sympy.polys.polyutils import (\n-    basic_from_dict,\n-    _sort_gens,\n-    _unify_gens,\n-    _dict_reorder,\n-    _dict_from_expr,\n-    _parallel_dict_from_expr,\n-)\n-from sympy.polys.rationaltools import together\n-from sympy.polys.rootisolation import dup_isolate_real_roots_list\n-from sympy.utilities import group, sift, public, filldedent\n-from sympy.utilities.exceptions import SymPyDeprecationWarning\n-\n-# Required to avoid errors\n-import sympy.polys\n-\n-import mpmath\n-from mpmath.libmp.libhyper import NoConvergence\n-\n-\n-\n-def _polifyit(func):\n-    @wraps(func)\n-    def wrapper(f, g):\n-        g = _sympify(g)\n-        if isinstance(g, Poly):\n-            return func(f, g)\n-        elif isinstance(g, Expr):\n-            try:\n-                g = f.from_expr(g, *f.gens)\n-            except PolynomialError:\n-                if g.is_Matrix:\n-                    return NotImplemented\n-                expr_method = getattr(f.as_expr(), func.__name__)\n-                result = expr_method(g)\n-                if result is not NotImplemented:\n-                    SymPyDeprecationWarning(\n-                        feature=\"Mixing Poly with non-polynomial expressions in binary operations\",\n-                        issue=18613,\n-                        deprecated_since_version=\"1.6\",\n-                        useinstead=\"the as_expr or as_poly method to convert types\").warn()\n-                return result\n-            else:\n-                return func(f, g)\n-        else:\n-            return NotImplemented\n-    return wrapper\n-\n-\n-\n-@public\n-class Poly(Basic):\n-    \"\"\"\n-    Generic class for representing and operating on polynomial expressions.\n-\n-    Poly is a subclass of Basic rather than Expr but instances can be\n-    converted to Expr with the ``as_expr`` method.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import Poly\n-    >>> from sympy.abc import x, y\n-\n-    Create a univariate polynomial:\n-\n-    >>> Poly(x*(x**2 + x - 1)**2)\n-    Poly(x**5 + 2*x**4 - x**3 - 2*x**2 + x, x, domain='ZZ')\n-\n-    Create a univariate polynomial with specific domain:\n-\n-    >>> from sympy import sqrt\n-    >>> Poly(x**2 + 2*x + sqrt(3), domain='R')\n-    Poly(1.0*x**2 + 2.0*x + 1.73205080756888, x, domain='RR')\n-\n-    Create a multivariate polynomial:\n-\n-    >>> Poly(y*x**2 + x*y + 1)\n-    Poly(x**2*y + x*y + 1, x, y, domain='ZZ')\n-\n-    Create a univariate polynomial, where y is a constant:\n-\n-    >>> Poly(y*x**2 + x*y + 1,x)\n-    Poly(y*x**2 + y*x + 1, x, domain='ZZ[y]')\n-\n-    You can evaluate the above polynomial as a function of y:\n-\n-    >>> Poly(y*x**2 + x*y + 1,x).eval(2)\n-    6*y + 1\n-\n-    See Also\n-    ========\n-\n-    sympy.core.expr.Expr\n-\n-    \"\"\"\n-\n-    __slots__ = ('rep', 'gens')\n-\n-    is_commutative = True\n-    is_Poly = True\n-    _op_priority = 10.001\n-\n-    def __new__(cls, rep, *gens, **args):\n-        \"\"\"Create a new polynomial instance out of something useful. \"\"\"\n-        opt = options.build_options(gens, args)\n-\n-        if 'order' in opt:\n-            raise NotImplementedError(\"'order' keyword is not implemented yet\")\n-\n-        if isinstance(rep, (DMP, DMF, ANP, DomainElement)):\n-            return cls._from_domain_element(rep, opt)\n-        elif iterable(rep, exclude=str):\n-            if isinstance(rep, dict):\n-                return cls._from_dict(rep, opt)\n-            else:\n-                return cls._from_list(list(rep), opt)\n-        else:\n-            rep = sympify(rep)\n-\n-            if rep.is_Poly:\n-                return cls._from_poly(rep, opt)\n-            else:\n-                return cls._from_expr(rep, opt)\n-\n-    # Poly does not pass its args to Basic.__new__ to be stored in _args so we\n-    # have to emulate them here with an args property that derives from rep\n-    # and gens which are instance attributes. This also means we need to\n-    # define _hashable_content. The _hashable_content is rep and gens but args\n-    # uses expr instead of rep (expr is the Basic version of rep). Passing\n-    # expr in args means that Basic methods like subs should work. Using rep\n-    # otherwise means that Poly can remain more efficient than Basic by\n-    # avoiding creating a Basic instance just to be hashable.\n-\n-    @classmethod\n-    def new(cls, rep, *gens):\n-        \"\"\"Construct :class:`Poly` instance from raw representation. \"\"\"\n-        if not isinstance(rep, DMP):\n-            raise PolynomialError(\n-                \"invalid polynomial representation: %s\" % rep)\n-        elif rep.lev != len(gens) - 1:\n-            raise PolynomialError(\"invalid arguments: %s, %s\" % (rep, gens))\n-\n-        obj = Basic.__new__(cls)\n-        obj.rep = rep\n-        obj.gens = gens\n-\n-        return obj\n-\n-    @property\n-    def expr(self):\n-        return basic_from_dict(self.rep.to_sympy_dict(), *self.gens)\n-\n-    @property\n-    def args(self):\n-        return (self.expr,) + self.gens\n-\n-    def _hashable_content(self):\n-        return (self.rep,) + self.gens\n-\n-    @classmethod\n-    def from_dict(cls, rep, *gens, **args):\n-        \"\"\"Construct a polynomial from a ``dict``. \"\"\"\n-        opt = options.build_options(gens, args)\n-        return cls._from_dict(rep, opt)\n-\n-    @classmethod\n-    def from_list(cls, rep, *gens, **args):\n-        \"\"\"Construct a polynomial from a ``list``. \"\"\"\n-        opt = options.build_options(gens, args)\n-        return cls._from_list(rep, opt)\n-\n-    @classmethod\n-    def from_poly(cls, rep, *gens, **args):\n-        \"\"\"Construct a polynomial from a polynomial. \"\"\"\n-        opt = options.build_options(gens, args)\n-        return cls._from_poly(rep, opt)\n-\n-    @classmethod\n-    def from_expr(cls, rep, *gens, **args):\n-        \"\"\"Construct a polynomial from an expression. \"\"\"\n-        opt = options.build_options(gens, args)\n-        return cls._from_expr(rep, opt)\n-\n-    @classmethod\n-    def _from_dict(cls, rep, opt):\n-        \"\"\"Construct a polynomial from a ``dict``. \"\"\"\n-        gens = opt.gens\n-\n-        if not gens:\n-            raise GeneratorsNeeded(\n-                \"can't initialize from 'dict' without generators\")\n-\n-        level = len(gens) - 1\n-        domain = opt.domain\n-\n-        if domain is None:\n-            domain, rep = construct_domain(rep, opt=opt)\n-        else:\n-            for monom, coeff in rep.items():\n-                rep[monom] = domain.convert(coeff)\n-\n-        return cls.new(DMP.from_dict(rep, level, domain), *gens)\n-\n-    @classmethod\n-    def _from_list(cls, rep, opt):\n-        \"\"\"Construct a polynomial from a ``list``. \"\"\"\n-        gens = opt.gens\n-\n-        if not gens:\n-            raise GeneratorsNeeded(\n-                \"can't initialize from 'list' without generators\")\n-        elif len(gens) != 1:\n-            raise MultivariatePolynomialError(\n-                \"'list' representation not supported\")\n-\n-        level = len(gens) - 1\n-        domain = opt.domain\n-\n-        if domain is None:\n-            domain, rep = construct_domain(rep, opt=opt)\n-        else:\n-            rep = list(map(domain.convert, rep))\n-\n-        return cls.new(DMP.from_list(rep, level, domain), *gens)\n-\n-    @classmethod\n-    def _from_poly(cls, rep, opt):\n-        \"\"\"Construct a polynomial from a polynomial. \"\"\"\n-        if cls != rep.__class__:\n-            rep = cls.new(rep.rep, *rep.gens)\n-\n-        gens = opt.gens\n-        field = opt.field\n-        domain = opt.domain\n-\n-        if gens and rep.gens != gens:\n-            if set(rep.gens) != set(gens):\n-                return cls._from_expr(rep.as_expr(), opt)\n-            else:\n-                rep = rep.reorder(*gens)\n-\n-        if 'domain' in opt and domain:\n-            rep = rep.set_domain(domain)\n-        elif field is True:\n-            rep = rep.to_field()\n-\n-        return rep\n-\n-    @classmethod\n-    def _from_expr(cls, rep, opt):\n-        \"\"\"Construct a polynomial from an expression. \"\"\"\n-        rep, opt = _dict_from_expr(rep, opt)\n-        return cls._from_dict(rep, opt)\n-\n-    @classmethod\n-    def _from_domain_element(cls, rep, opt):\n-        gens = opt.gens\n-        domain = opt.domain\n-\n-        level = len(gens) - 1\n-        rep = [domain.convert(rep)]\n-\n-        return cls.new(DMP.from_list(rep, level, domain), *gens)\n-\n-    def __hash__(self):\n-        return super().__hash__()\n-\n-    @property\n-    def free_symbols(self):\n-        \"\"\"\n-        Free symbols of a polynomial expression.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x, y, z\n-\n-        >>> Poly(x**2 + 1).free_symbols\n-        {x}\n-        >>> Poly(x**2 + y).free_symbols\n-        {x, y}\n-        >>> Poly(x**2 + y, x).free_symbols\n-        {x, y}\n-        >>> Poly(x**2 + y, x, z).free_symbols\n-        {x, y}\n-\n-        \"\"\"\n-        symbols = set()\n-        gens = self.gens\n-        for i in range(len(gens)):\n-            for monom in self.monoms():\n-                if monom[i]:\n-                    symbols |= gens[i].free_symbols\n-                    break\n-\n-        return symbols | self.free_symbols_in_domain\n-\n-    @property\n-    def free_symbols_in_domain(self):\n-        \"\"\"\n-        Free symbols of the domain of ``self``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x, y\n-\n-        >>> Poly(x**2 + 1).free_symbols_in_domain\n-        set()\n-        >>> Poly(x**2 + y).free_symbols_in_domain\n-        set()\n-        >>> Poly(x**2 + y, x).free_symbols_in_domain\n-        {y}\n-\n-        \"\"\"\n-        domain, symbols = self.rep.dom, set()\n-\n-        if domain.is_Composite:\n-            for gen in domain.symbols:\n-                symbols |= gen.free_symbols\n-        elif domain.is_EX:\n-            for coeff in self.coeffs():\n-                symbols |= coeff.free_symbols\n-\n-        return symbols\n-\n-    @property\n-    def gen(self):\n-        \"\"\"\n-        Return the principal generator.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**2 + 1, x).gen\n-        x\n-\n-        \"\"\"\n-        return self.gens[0]\n-\n-    @property\n-    def domain(self):\n-        \"\"\"Get the ground domain of ``self``. \"\"\"\n-        return self.get_domain()\n-\n-    @property\n-    def zero(self):\n-        \"\"\"Return zero polynomial with ``self``'s properties. \"\"\"\n-        return self.new(self.rep.zero(self.rep.lev, self.rep.dom), *self.gens)\n-\n-    @property\n-    def one(self):\n-        \"\"\"Return one polynomial with ``self``'s properties. \"\"\"\n-        return self.new(self.rep.one(self.rep.lev, self.rep.dom), *self.gens)\n-\n-    @property\n-    def unit(self):\n-        \"\"\"Return unit polynomial with ``self``'s properties. \"\"\"\n-        return self.new(self.rep.unit(self.rep.lev, self.rep.dom), *self.gens)\n-\n-    def unify(f, g):\n-        \"\"\"\n-        Make ``f`` and ``g`` belong to the same domain.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> f, g = Poly(x/2 + 1), Poly(2*x + 1)\n-\n-        >>> f\n-        Poly(1/2*x + 1, x, domain='QQ')\n-        >>> g\n-        Poly(2*x + 1, x, domain='ZZ')\n-\n-        >>> F, G = f.unify(g)\n-\n-        >>> F\n-        Poly(1/2*x + 1, x, domain='QQ')\n-        >>> G\n-        Poly(2*x + 1, x, domain='QQ')\n-\n-        \"\"\"\n-        _, per, F, G = f._unify(g)\n-        return per(F), per(G)\n-\n-    def _unify(f, g):\n-        g = sympify(g)\n-\n-        if not g.is_Poly:\n-            try:\n-                return f.rep.dom, f.per, f.rep, f.rep.per(f.rep.dom.from_sympy(g))\n-            except CoercionFailed:\n-                raise UnificationFailed(\"can't unify %s with %s\" % (f, g))\n-\n-        if isinstance(f.rep, DMP) and isinstance(g.rep, DMP):\n-            gens = _unify_gens(f.gens, g.gens)\n-\n-            dom, lev = f.rep.dom.unify(g.rep.dom, gens), len(gens) - 1\n-\n-            if f.gens != gens:\n-                f_monoms, f_coeffs = _dict_reorder(\n-                    f.rep.to_dict(), f.gens, gens)\n-\n-                if f.rep.dom != dom:\n-                    f_coeffs = [dom.convert(c, f.rep.dom) for c in f_coeffs]\n-\n-                F = DMP(dict(list(zip(f_monoms, f_coeffs))), dom, lev)\n-            else:\n-                F = f.rep.convert(dom)\n-\n-            if g.gens != gens:\n-                g_monoms, g_coeffs = _dict_reorder(\n-                    g.rep.to_dict(), g.gens, gens)\n-\n-                if g.rep.dom != dom:\n-                    g_coeffs = [dom.convert(c, g.rep.dom) for c in g_coeffs]\n-\n-                G = DMP(dict(list(zip(g_monoms, g_coeffs))), dom, lev)\n-            else:\n-                G = g.rep.convert(dom)\n-        else:\n-            raise UnificationFailed(\"can't unify %s with %s\" % (f, g))\n-\n-        cls = f.__class__\n-\n-        def per(rep, dom=dom, gens=gens, remove=None):\n-            if remove is not None:\n-                gens = gens[:remove] + gens[remove + 1:]\n-\n-                if not gens:\n-                    return dom.to_sympy(rep)\n-\n-            return cls.new(rep, *gens)\n-\n-        return dom, per, F, G\n-\n-    def per(f, rep, gens=None, remove=None):\n-        \"\"\"\n-        Create a Poly out of the given representation.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly, ZZ\n-        >>> from sympy.abc import x, y\n-\n-        >>> from sympy.polys.polyclasses import DMP\n-\n-        >>> a = Poly(x**2 + 1)\n-\n-        >>> a.per(DMP([ZZ(1), ZZ(1)], ZZ), gens=[y])\n-        Poly(y + 1, y, domain='ZZ')\n-\n-        \"\"\"\n-        if gens is None:\n-            gens = f.gens\n-\n-        if remove is not None:\n-            gens = gens[:remove] + gens[remove + 1:]\n-\n-            if not gens:\n-                return f.rep.dom.to_sympy(rep)\n-\n-        return f.__class__.new(rep, *gens)\n-\n-    def set_domain(f, domain):\n-        \"\"\"Set the ground domain of ``f``. \"\"\"\n-        opt = options.build_options(f.gens, {'domain': domain})\n-        return f.per(f.rep.convert(opt.domain))\n-\n-    def get_domain(f):\n-        \"\"\"Get the ground domain of ``f``. \"\"\"\n-        return f.rep.dom\n-\n-    def set_modulus(f, modulus):\n-        \"\"\"\n-        Set the modulus of ``f``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(5*x**2 + 2*x - 1, x).set_modulus(2)\n-        Poly(x**2 + 1, x, modulus=2)\n-\n-        \"\"\"\n-        modulus = options.Modulus.preprocess(modulus)\n-        return f.set_domain(FF(modulus))\n-\n-    def get_modulus(f):\n-        \"\"\"\n-        Get the modulus of ``f``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**2 + 1, modulus=2).get_modulus()\n-        2\n-\n-        \"\"\"\n-        domain = f.get_domain()\n-\n-        if domain.is_FiniteField:\n-            return Integer(domain.characteristic())\n-        else:\n-            raise PolynomialError(\"not a polynomial over a Galois field\")\n-\n-    def _eval_subs(f, old, new):\n-        \"\"\"Internal implementation of :func:`subs`. \"\"\"\n-        if old in f.gens:\n-            if new.is_number:\n-                return f.eval(old, new)\n-            else:\n-                try:\n-                    return f.replace(old, new)\n-                except PolynomialError:\n-                    pass\n-\n-        return f.as_expr().subs(old, new)\n-\n-    def exclude(f):\n-        \"\"\"\n-        Remove unnecessary generators from ``f``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import a, b, c, d, x\n-\n-        >>> Poly(a + x, a, b, c, d, x).exclude()\n-        Poly(a + x, a, x, domain='ZZ')\n-\n-        \"\"\"\n-        J, new = f.rep.exclude()\n-        gens = []\n-\n-        for j in range(len(f.gens)):\n-            if j not in J:\n-                gens.append(f.gens[j])\n-\n-        return f.per(new, gens=gens)\n-\n-    def replace(f, x, y=None, *_ignore):\n-        # XXX this does not match Basic's signature\n-        \"\"\"\n-        Replace ``x`` with ``y`` in generators list.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x, y\n-\n-        >>> Poly(x**2 + 1, x).replace(x, y)\n-        Poly(y**2 + 1, y, domain='ZZ')\n-\n-        \"\"\"\n-        if y is None:\n-            if f.is_univariate:\n-                x, y = f.gen, x\n-            else:\n-                raise PolynomialError(\n-                    \"syntax supported only in univariate case\")\n-\n-        if x == y or x not in f.gens:\n-            return f\n-\n-        if x in f.gens and y not in f.gens:\n-            dom = f.get_domain()\n-\n-            if not dom.is_Composite or y not in dom.symbols:\n-                gens = list(f.gens)\n-                gens[gens.index(x)] = y\n-                return f.per(f.rep, gens=gens)\n-\n-        raise PolynomialError(\"can't replace %s with %s in %s\" % (x, y, f))\n-\n-    def match(f, *args, **kwargs):\n-        \"\"\"Match expression from Poly. See Basic.match()\"\"\"\n-        return f.as_expr().match(*args, **kwargs)\n-\n-    def reorder(f, *gens, **args):\n-        \"\"\"\n-        Efficiently apply new order of generators.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x, y\n-\n-        >>> Poly(x**2 + x*y**2, x, y).reorder(y, x)\n-        Poly(y**2*x + x**2, y, x, domain='ZZ')\n-\n-        \"\"\"\n-        opt = options.Options((), args)\n-\n-        if not gens:\n-            gens = _sort_gens(f.gens, opt=opt)\n-        elif set(f.gens) != set(gens):\n-            raise PolynomialError(\n-                \"generators list can differ only up to order of elements\")\n-\n-        rep = dict(list(zip(*_dict_reorder(f.rep.to_dict(), f.gens, gens))))\n-\n-        return f.per(DMP(rep, f.rep.dom, len(gens) - 1), gens=gens)\n-\n-    def ltrim(f, gen):\n-        \"\"\"\n-        Remove dummy generators from ``f`` that are to the left of\n-        specified ``gen`` in the generators as ordered. When ``gen``\n-        is an integer, it refers to the generator located at that\n-        position within the tuple of generators of ``f``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x, y, z\n-\n-        >>> Poly(y**2 + y*z**2, x, y, z).ltrim(y)\n-        Poly(y**2 + y*z**2, y, z, domain='ZZ')\n-        >>> Poly(z, x, y, z).ltrim(-1)\n-        Poly(z, z, domain='ZZ')\n-\n-        \"\"\"\n-        rep = f.as_dict(native=True)\n-        j = f._gen_to_level(gen)\n-\n-        terms = {}\n-\n-        for monom, coeff in rep.items():\n-\n-            if any(monom[:j]):\n-                # some generator is used in the portion to be trimmed\n-                raise PolynomialError(\"can't left trim %s\" % f)\n-\n-            terms[monom[j:]] = coeff\n-\n-        gens = f.gens[j:]\n-\n-        return f.new(DMP.from_dict(terms, len(gens) - 1, f.rep.dom), *gens)\n-\n-    def has_only_gens(f, *gens):\n-        \"\"\"\n-        Return ``True`` if ``Poly(f, *gens)`` retains ground domain.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x, y, z\n-\n-        >>> Poly(x*y + 1, x, y, z).has_only_gens(x, y)\n-        True\n-        >>> Poly(x*y + z, x, y, z).has_only_gens(x, y)\n-        False\n-\n-        \"\"\"\n-        indices = set()\n-\n-        for gen in gens:\n-            try:\n-                index = f.gens.index(gen)\n-            except ValueError:\n-                raise GeneratorsError(\n-                    \"%s doesn't have %s as generator\" % (f, gen))\n-            else:\n-                indices.add(index)\n-\n-        for monom in f.monoms():\n-            for i, elt in enumerate(monom):\n-                if i not in indices and elt:\n-                    return False\n-\n-        return True\n-\n-    def to_ring(f):\n-        \"\"\"\n-        Make the ground domain a ring.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly, QQ\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**2 + 1, domain=QQ).to_ring()\n-        Poly(x**2 + 1, x, domain='ZZ')\n-\n-        \"\"\"\n-        if hasattr(f.rep, 'to_ring'):\n-            result = f.rep.to_ring()\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'to_ring')\n-\n-        return f.per(result)\n-\n-    def to_field(f):\n-        \"\"\"\n-        Make the ground domain a field.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly, ZZ\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**2 + 1, x, domain=ZZ).to_field()\n-        Poly(x**2 + 1, x, domain='QQ')\n-\n-        \"\"\"\n-        if hasattr(f.rep, 'to_field'):\n-            result = f.rep.to_field()\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'to_field')\n-\n-        return f.per(result)\n-\n-    def to_exact(f):\n-        \"\"\"\n-        Make the ground domain exact.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly, RR\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**2 + 1.0, x, domain=RR).to_exact()\n-        Poly(x**2 + 1, x, domain='QQ')\n-\n-        \"\"\"\n-        if hasattr(f.rep, 'to_exact'):\n-            result = f.rep.to_exact()\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'to_exact')\n-\n-        return f.per(result)\n-\n-    def retract(f, field=None):\n-        \"\"\"\n-        Recalculate the ground domain of a polynomial.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> f = Poly(x**2 + 1, x, domain='QQ[y]')\n-        >>> f\n-        Poly(x**2 + 1, x, domain='QQ[y]')\n-\n-        >>> f.retract()\n-        Poly(x**2 + 1, x, domain='ZZ')\n-        >>> f.retract(field=True)\n-        Poly(x**2 + 1, x, domain='QQ')\n-\n-        \"\"\"\n-        dom, rep = construct_domain(f.as_dict(zero=True),\n-            field=field, composite=f.domain.is_Composite or None)\n-        return f.from_dict(rep, f.gens, domain=dom)\n-\n-    def slice(f, x, m, n=None):\n-        \"\"\"Take a continuous subsequence of terms of ``f``. \"\"\"\n-        if n is None:\n-            j, m, n = 0, x, m\n-        else:\n-            j = f._gen_to_level(x)\n-\n-        m, n = int(m), int(n)\n-\n-        if hasattr(f.rep, 'slice'):\n-            result = f.rep.slice(m, n, j)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'slice')\n-\n-        return f.per(result)\n-\n-    def coeffs(f, order=None):\n-        \"\"\"\n-        Returns all non-zero coefficients from ``f`` in lex order.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**3 + 2*x + 3, x).coeffs()\n-        [1, 2, 3]\n-\n-        See Also\n-        ========\n-        all_coeffs\n-        coeff_monomial\n-        nth\n-\n-        \"\"\"\n-        return [f.rep.dom.to_sympy(c) for c in f.rep.coeffs(order=order)]\n-\n-    def monoms(f, order=None):\n-        \"\"\"\n-        Returns all non-zero monomials from ``f`` in lex order.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x, y\n-\n-        >>> Poly(x**2 + 2*x*y**2 + x*y + 3*y, x, y).monoms()\n-        [(2, 0), (1, 2), (1, 1), (0, 1)]\n-\n-        See Also\n-        ========\n-        all_monoms\n-\n-        \"\"\"\n-        return f.rep.monoms(order=order)\n-\n-    def terms(f, order=None):\n-        \"\"\"\n-        Returns all non-zero terms from ``f`` in lex order.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x, y\n-\n-        >>> Poly(x**2 + 2*x*y**2 + x*y + 3*y, x, y).terms()\n-        [((2, 0), 1), ((1, 2), 2), ((1, 1), 1), ((0, 1), 3)]\n-\n-        See Also\n-        ========\n-        all_terms\n-\n-        \"\"\"\n-        return [(m, f.rep.dom.to_sympy(c)) for m, c in f.rep.terms(order=order)]\n-\n-    def all_coeffs(f):\n-        \"\"\"\n-        Returns all coefficients from a univariate polynomial ``f``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**3 + 2*x - 1, x).all_coeffs()\n-        [1, 0, 2, -1]\n-\n-        \"\"\"\n-        return [f.rep.dom.to_sympy(c) for c in f.rep.all_coeffs()]\n-\n-    def all_monoms(f):\n-        \"\"\"\n-        Returns all monomials from a univariate polynomial ``f``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**3 + 2*x - 1, x).all_monoms()\n-        [(3,), (2,), (1,), (0,)]\n-\n-        See Also\n-        ========\n-        all_terms\n-\n-        \"\"\"\n-        return f.rep.all_monoms()\n-\n-    def all_terms(f):\n-        \"\"\"\n-        Returns all terms from a univariate polynomial ``f``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**3 + 2*x - 1, x).all_terms()\n-        [((3,), 1), ((2,), 0), ((1,), 2), ((0,), -1)]\n-\n-        \"\"\"\n-        return [(m, f.rep.dom.to_sympy(c)) for m, c in f.rep.all_terms()]\n-\n-    def termwise(f, func, *gens, **args):\n-        \"\"\"\n-        Apply a function to all terms of ``f``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> def func(k, coeff):\n-        ...     k = k[0]\n-        ...     return coeff//10**(2-k)\n-\n-        >>> Poly(x**2 + 20*x + 400).termwise(func)\n-        Poly(x**2 + 2*x + 4, x, domain='ZZ')\n-\n-        \"\"\"\n-        terms = {}\n-\n-        for monom, coeff in f.terms():\n-            result = func(monom, coeff)\n-\n-            if isinstance(result, tuple):\n-                monom, coeff = result\n-            else:\n-                coeff = result\n-\n-            if coeff:\n-                if monom not in terms:\n-                    terms[monom] = coeff\n-                else:\n-                    raise PolynomialError(\n-                        \"%s monomial was generated twice\" % monom)\n-\n-        return f.from_dict(terms, *(gens or f.gens), **args)\n-\n-    def length(f):\n-        \"\"\"\n-        Returns the number of non-zero terms in ``f``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**2 + 2*x - 1).length()\n-        3\n-\n-        \"\"\"\n-        return len(f.as_dict())\n-\n-    def as_dict(f, native=False, zero=False):\n-        \"\"\"\n-        Switch to a ``dict`` representation.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x, y\n-\n-        >>> Poly(x**2 + 2*x*y**2 - y, x, y).as_dict()\n-        {(0, 1): -1, (1, 2): 2, (2, 0): 1}\n-\n-        \"\"\"\n-        if native:\n-            return f.rep.to_dict(zero=zero)\n-        else:\n-            return f.rep.to_sympy_dict(zero=zero)\n-\n-    def as_list(f, native=False):\n-        \"\"\"Switch to a ``list`` representation. \"\"\"\n-        if native:\n-            return f.rep.to_list()\n-        else:\n-            return f.rep.to_sympy_list()\n-\n-    def as_expr(f, *gens):\n-        \"\"\"\n-        Convert a Poly instance to an Expr instance.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x, y\n-\n-        >>> f = Poly(x**2 + 2*x*y**2 - y, x, y)\n-\n-        >>> f.as_expr()\n-        x**2 + 2*x*y**2 - y\n-        >>> f.as_expr({x: 5})\n-        10*y**2 - y + 25\n-        >>> f.as_expr(5, 6)\n-        379\n-\n-        \"\"\"\n-        if not gens:\n-            return f.expr\n-\n-        if len(gens) == 1 and isinstance(gens[0], dict):\n-            mapping = gens[0]\n-            gens = list(f.gens)\n-\n-            for gen, value in mapping.items():\n-                try:\n-                    index = gens.index(gen)\n-                except ValueError:\n-                    raise GeneratorsError(\n-                        \"%s doesn't have %s as generator\" % (f, gen))\n-                else:\n-                    gens[index] = value\n-\n-        return basic_from_dict(f.rep.to_sympy_dict(), *gens)\n-\n-    def as_poly(self, *gens, **args):\n-        \"\"\"Converts ``self`` to a polynomial or returns ``None``.\n-\n-        >>> from sympy import sin\n-        >>> from sympy.abc import x, y\n-\n-        >>> print((x**2 + x*y).as_poly())\n-        Poly(x**2 + x*y, x, y, domain='ZZ')\n-\n-        >>> print((x**2 + x*y).as_poly(x, y))\n-        Poly(x**2 + x*y, x, y, domain='ZZ')\n-\n-        >>> print((x**2 + sin(y)).as_poly(x, y))\n-        None\n-\n-        \"\"\"\n-        try:\n-            poly = Poly(self, *gens, **args)\n-\n-            if not poly.is_Poly:\n-                return None\n-            else:\n-                return poly\n-        except PolynomialError:\n-            return None\n-\n-    def lift(f):\n-        \"\"\"\n-        Convert algebraic coefficients to rationals.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly, I\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**2 + I*x + 1, x, extension=I).lift()\n-        Poly(x**4 + 3*x**2 + 1, x, domain='QQ')\n-\n-        \"\"\"\n-        if hasattr(f.rep, 'lift'):\n-            result = f.rep.lift()\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'lift')\n-\n-        return f.per(result)\n-\n-    def deflate(f):\n-        \"\"\"\n-        Reduce degree of ``f`` by mapping ``x_i**m`` to ``y_i``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x, y\n-\n-        >>> Poly(x**6*y**2 + x**3 + 1, x, y).deflate()\n-        ((3, 2), Poly(x**2*y + x + 1, x, y, domain='ZZ'))\n-\n-        \"\"\"\n-        if hasattr(f.rep, 'deflate'):\n-            J, result = f.rep.deflate()\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'deflate')\n-\n-        return J, f.per(result)\n-\n-    def inject(f, front=False):\n-        \"\"\"\n-        Inject ground domain generators into ``f``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x, y\n-\n-        >>> f = Poly(x**2*y + x*y**3 + x*y + 1, x)\n-\n-        >>> f.inject()\n-        Poly(x**2*y + x*y**3 + x*y + 1, x, y, domain='ZZ')\n-        >>> f.inject(front=True)\n-        Poly(y**3*x + y*x**2 + y*x + 1, y, x, domain='ZZ')\n-\n-        \"\"\"\n-        dom = f.rep.dom\n-\n-        if dom.is_Numerical:\n-            return f\n-        elif not dom.is_Poly:\n-            raise DomainError(\"can't inject generators over %s\" % dom)\n-\n-        if hasattr(f.rep, 'inject'):\n-            result = f.rep.inject(front=front)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'inject')\n-\n-        if front:\n-            gens = dom.symbols + f.gens\n-        else:\n-            gens = f.gens + dom.symbols\n-\n-        return f.new(result, *gens)\n-\n-    def eject(f, *gens):\n-        \"\"\"\n-        Eject selected generators into the ground domain.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x, y\n-\n-        >>> f = Poly(x**2*y + x*y**3 + x*y + 1, x, y)\n-\n-        >>> f.eject(x)\n-        Poly(x*y**3 + (x**2 + x)*y + 1, y, domain='ZZ[x]')\n-        >>> f.eject(y)\n-        Poly(y*x**2 + (y**3 + y)*x + 1, x, domain='ZZ[y]')\n-\n-        \"\"\"\n-        dom = f.rep.dom\n-\n-        if not dom.is_Numerical:\n-            raise DomainError(\"can't eject generators over %s\" % dom)\n-\n-        k = len(gens)\n-\n-        if f.gens[:k] == gens:\n-            _gens, front = f.gens[k:], True\n-        elif f.gens[-k:] == gens:\n-            _gens, front = f.gens[:-k], False\n-        else:\n-            raise NotImplementedError(\n-                \"can only eject front or back generators\")\n-\n-        dom = dom.inject(*gens)\n-\n-        if hasattr(f.rep, 'eject'):\n-            result = f.rep.eject(dom, front=front)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'eject')\n-\n-        return f.new(result, *_gens)\n-\n-    def terms_gcd(f):\n-        \"\"\"\n-        Remove GCD of terms from the polynomial ``f``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x, y\n-\n-        >>> Poly(x**6*y**2 + x**3*y, x, y).terms_gcd()\n-        ((3, 1), Poly(x**3*y + 1, x, y, domain='ZZ'))\n-\n-        \"\"\"\n-        if hasattr(f.rep, 'terms_gcd'):\n-            J, result = f.rep.terms_gcd()\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'terms_gcd')\n-\n-        return J, f.per(result)\n-\n-    def add_ground(f, coeff):\n-        \"\"\"\n-        Add an element of the ground domain to ``f``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x + 1).add_ground(2)\n-        Poly(x + 3, x, domain='ZZ')\n-\n-        \"\"\"\n-        if hasattr(f.rep, 'add_ground'):\n-            result = f.rep.add_ground(coeff)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'add_ground')\n-\n-        return f.per(result)\n-\n-    def sub_ground(f, coeff):\n-        \"\"\"\n-        Subtract an element of the ground domain from ``f``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x + 1).sub_ground(2)\n-        Poly(x - 1, x, domain='ZZ')\n-\n-        \"\"\"\n-        if hasattr(f.rep, 'sub_ground'):\n-            result = f.rep.sub_ground(coeff)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'sub_ground')\n-\n-        return f.per(result)\n-\n-    def mul_ground(f, coeff):\n-        \"\"\"\n-        Multiply ``f`` by a an element of the ground domain.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x + 1).mul_ground(2)\n-        Poly(2*x + 2, x, domain='ZZ')\n-\n-        \"\"\"\n-        if hasattr(f.rep, 'mul_ground'):\n-            result = f.rep.mul_ground(coeff)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'mul_ground')\n-\n-        return f.per(result)\n-\n-    def quo_ground(f, coeff):\n-        \"\"\"\n-        Quotient of ``f`` by a an element of the ground domain.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(2*x + 4).quo_ground(2)\n-        Poly(x + 2, x, domain='ZZ')\n-\n-        >>> Poly(2*x + 3).quo_ground(2)\n-        Poly(x + 1, x, domain='ZZ')\n-\n-        \"\"\"\n-        if hasattr(f.rep, 'quo_ground'):\n-            result = f.rep.quo_ground(coeff)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'quo_ground')\n-\n-        return f.per(result)\n-\n-    def exquo_ground(f, coeff):\n-        \"\"\"\n-        Exact quotient of ``f`` by a an element of the ground domain.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(2*x + 4).exquo_ground(2)\n-        Poly(x + 2, x, domain='ZZ')\n-\n-        >>> Poly(2*x + 3).exquo_ground(2)\n-        Traceback (most recent call last):\n-        ...\n-        ExactQuotientFailed: 2 does not divide 3 in ZZ\n-\n-        \"\"\"\n-        if hasattr(f.rep, 'exquo_ground'):\n-            result = f.rep.exquo_ground(coeff)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'exquo_ground')\n-\n-        return f.per(result)\n-\n-    def abs(f):\n-        \"\"\"\n-        Make all coefficients in ``f`` positive.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**2 - 1, x).abs()\n-        Poly(x**2 + 1, x, domain='ZZ')\n-\n-        \"\"\"\n-        if hasattr(f.rep, 'abs'):\n-            result = f.rep.abs()\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'abs')\n-\n-        return f.per(result)\n-\n-    def neg(f):\n-        \"\"\"\n-        Negate all coefficients in ``f``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**2 - 1, x).neg()\n-        Poly(-x**2 + 1, x, domain='ZZ')\n-\n-        >>> -Poly(x**2 - 1, x)\n-        Poly(-x**2 + 1, x, domain='ZZ')\n-\n-        \"\"\"\n-        if hasattr(f.rep, 'neg'):\n-            result = f.rep.neg()\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'neg')\n-\n-        return f.per(result)\n-\n-    def add(f, g):\n-        \"\"\"\n-        Add two polynomials ``f`` and ``g``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**2 + 1, x).add(Poly(x - 2, x))\n-        Poly(x**2 + x - 1, x, domain='ZZ')\n-\n-        >>> Poly(x**2 + 1, x) + Poly(x - 2, x)\n-        Poly(x**2 + x - 1, x, domain='ZZ')\n-\n-        \"\"\"\n-        g = sympify(g)\n-\n-        if not g.is_Poly:\n-            return f.add_ground(g)\n-\n-        _, per, F, G = f._unify(g)\n-\n-        if hasattr(f.rep, 'add'):\n-            result = F.add(G)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'add')\n-\n-        return per(result)\n-\n-    def sub(f, g):\n-        \"\"\"\n-        Subtract two polynomials ``f`` and ``g``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**2 + 1, x).sub(Poly(x - 2, x))\n-        Poly(x**2 - x + 3, x, domain='ZZ')\n-\n-        >>> Poly(x**2 + 1, x) - Poly(x - 2, x)\n-        Poly(x**2 - x + 3, x, domain='ZZ')\n-\n-        \"\"\"\n-        g = sympify(g)\n-\n-        if not g.is_Poly:\n-            return f.sub_ground(g)\n-\n-        _, per, F, G = f._unify(g)\n-\n-        if hasattr(f.rep, 'sub'):\n-            result = F.sub(G)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'sub')\n-\n-        return per(result)\n-\n-    def mul(f, g):\n-        \"\"\"\n-        Multiply two polynomials ``f`` and ``g``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**2 + 1, x).mul(Poly(x - 2, x))\n-        Poly(x**3 - 2*x**2 + x - 2, x, domain='ZZ')\n-\n-        >>> Poly(x**2 + 1, x)*Poly(x - 2, x)\n-        Poly(x**3 - 2*x**2 + x - 2, x, domain='ZZ')\n-\n-        \"\"\"\n-        g = sympify(g)\n-\n-        if not g.is_Poly:\n-            return f.mul_ground(g)\n-\n-        _, per, F, G = f._unify(g)\n-\n-        if hasattr(f.rep, 'mul'):\n-            result = F.mul(G)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'mul')\n-\n-        return per(result)\n-\n-    def sqr(f):\n-        \"\"\"\n-        Square a polynomial ``f``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x - 2, x).sqr()\n-        Poly(x**2 - 4*x + 4, x, domain='ZZ')\n-\n-        >>> Poly(x - 2, x)**2\n-        Poly(x**2 - 4*x + 4, x, domain='ZZ')\n-\n-        \"\"\"\n-        if hasattr(f.rep, 'sqr'):\n-            result = f.rep.sqr()\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'sqr')\n-\n-        return f.per(result)\n-\n-    def pow(f, n):\n-        \"\"\"\n-        Raise ``f`` to a non-negative power ``n``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x - 2, x).pow(3)\n-        Poly(x**3 - 6*x**2 + 12*x - 8, x, domain='ZZ')\n-\n-        >>> Poly(x - 2, x)**3\n-        Poly(x**3 - 6*x**2 + 12*x - 8, x, domain='ZZ')\n-\n-        \"\"\"\n-        n = int(n)\n-\n-        if hasattr(f.rep, 'pow'):\n-            result = f.rep.pow(n)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'pow')\n-\n-        return f.per(result)\n-\n-    def pdiv(f, g):\n-        \"\"\"\n-        Polynomial pseudo-division of ``f`` by ``g``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**2 + 1, x).pdiv(Poly(2*x - 4, x))\n-        (Poly(2*x + 4, x, domain='ZZ'), Poly(20, x, domain='ZZ'))\n-\n-        \"\"\"\n-        _, per, F, G = f._unify(g)\n-\n-        if hasattr(f.rep, 'pdiv'):\n-            q, r = F.pdiv(G)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'pdiv')\n-\n-        return per(q), per(r)\n-\n-    def prem(f, g):\n-        \"\"\"\n-        Polynomial pseudo-remainder of ``f`` by ``g``.\n-\n-        Caveat: The function prem(f, g, x) can be safely used to compute\n-          in Z[x] _only_ subresultant polynomial remainder sequences (prs's).\n-\n-          To safely compute Euclidean and Sturmian prs's in Z[x]\n-          employ anyone of the corresponding functions found in\n-          the module sympy.polys.subresultants_qq_zz. The functions\n-          in the module with suffix _pg compute prs's in Z[x] employing\n-          rem(f, g, x), whereas the functions with suffix _amv\n-          compute prs's in Z[x] employing rem_z(f, g, x).\n-\n-          The function rem_z(f, g, x) differs from prem(f, g, x) in that\n-          to compute the remainder polynomials in Z[x] it premultiplies\n-          the divident times the absolute value of the leading coefficient\n-          of the divisor raised to the power degree(f, x) - degree(g, x) + 1.\n-\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**2 + 1, x).prem(Poly(2*x - 4, x))\n-        Poly(20, x, domain='ZZ')\n-\n-        \"\"\"\n-        _, per, F, G = f._unify(g)\n-\n-        if hasattr(f.rep, 'prem'):\n-            result = F.prem(G)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'prem')\n-\n-        return per(result)\n-\n-    def pquo(f, g):\n-        \"\"\"\n-        Polynomial pseudo-quotient of ``f`` by ``g``.\n-\n-        See the Caveat note in the function prem(f, g).\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**2 + 1, x).pquo(Poly(2*x - 4, x))\n-        Poly(2*x + 4, x, domain='ZZ')\n-\n-        >>> Poly(x**2 - 1, x).pquo(Poly(2*x - 2, x))\n-        Poly(2*x + 2, x, domain='ZZ')\n-\n-        \"\"\"\n-        _, per, F, G = f._unify(g)\n-\n-        if hasattr(f.rep, 'pquo'):\n-            result = F.pquo(G)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'pquo')\n-\n-        return per(result)\n-\n-    def pexquo(f, g):\n-        \"\"\"\n-        Polynomial exact pseudo-quotient of ``f`` by ``g``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**2 - 1, x).pexquo(Poly(2*x - 2, x))\n-        Poly(2*x + 2, x, domain='ZZ')\n-\n-        >>> Poly(x**2 + 1, x).pexquo(Poly(2*x - 4, x))\n-        Traceback (most recent call last):\n-        ...\n-        ExactQuotientFailed: 2*x - 4 does not divide x**2 + 1\n-\n-        \"\"\"\n-        _, per, F, G = f._unify(g)\n-\n-        if hasattr(f.rep, 'pexquo'):\n-            try:\n-                result = F.pexquo(G)\n-            except ExactQuotientFailed as exc:\n-                raise exc.new(f.as_expr(), g.as_expr())\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'pexquo')\n-\n-        return per(result)\n-\n-    def div(f, g, auto=True):\n-        \"\"\"\n-        Polynomial division with remainder of ``f`` by ``g``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**2 + 1, x).div(Poly(2*x - 4, x))\n-        (Poly(1/2*x + 1, x, domain='QQ'), Poly(5, x, domain='QQ'))\n-\n-        >>> Poly(x**2 + 1, x).div(Poly(2*x - 4, x), auto=False)\n-        (Poly(0, x, domain='ZZ'), Poly(x**2 + 1, x, domain='ZZ'))\n-\n-        \"\"\"\n-        dom, per, F, G = f._unify(g)\n-        retract = False\n-\n-        if auto and dom.is_Ring and not dom.is_Field:\n-            F, G = F.to_field(), G.to_field()\n-            retract = True\n-\n-        if hasattr(f.rep, 'div'):\n-            q, r = F.div(G)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'div')\n-\n-        if retract:\n-            try:\n-                Q, R = q.to_ring(), r.to_ring()\n-            except CoercionFailed:\n-                pass\n-            else:\n-                q, r = Q, R\n-\n-        return per(q), per(r)\n-\n-    def rem(f, g, auto=True):\n-        \"\"\"\n-        Computes the polynomial remainder of ``f`` by ``g``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**2 + 1, x).rem(Poly(2*x - 4, x))\n-        Poly(5, x, domain='ZZ')\n-\n-        >>> Poly(x**2 + 1, x).rem(Poly(2*x - 4, x), auto=False)\n-        Poly(x**2 + 1, x, domain='ZZ')\n-\n-        \"\"\"\n-        dom, per, F, G = f._unify(g)\n-        retract = False\n-\n-        if auto and dom.is_Ring and not dom.is_Field:\n-            F, G = F.to_field(), G.to_field()\n-            retract = True\n-\n-        if hasattr(f.rep, 'rem'):\n-            r = F.rem(G)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'rem')\n-\n-        if retract:\n-            try:\n-                r = r.to_ring()\n-            except CoercionFailed:\n-                pass\n-\n-        return per(r)\n-\n-    def quo(f, g, auto=True):\n-        \"\"\"\n-        Computes polynomial quotient of ``f`` by ``g``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**2 + 1, x).quo(Poly(2*x - 4, x))\n-        Poly(1/2*x + 1, x, domain='QQ')\n-\n-        >>> Poly(x**2 - 1, x).quo(Poly(x - 1, x))\n-        Poly(x + 1, x, domain='ZZ')\n-\n-        \"\"\"\n-        dom, per, F, G = f._unify(g)\n-        retract = False\n-\n-        if auto and dom.is_Ring and not dom.is_Field:\n-            F, G = F.to_field(), G.to_field()\n-            retract = True\n-\n-        if hasattr(f.rep, 'quo'):\n-            q = F.quo(G)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'quo')\n-\n-        if retract:\n-            try:\n-                q = q.to_ring()\n-            except CoercionFailed:\n-                pass\n-\n-        return per(q)\n-\n-    def exquo(f, g, auto=True):\n-        \"\"\"\n-        Computes polynomial exact quotient of ``f`` by ``g``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**2 - 1, x).exquo(Poly(x - 1, x))\n-        Poly(x + 1, x, domain='ZZ')\n-\n-        >>> Poly(x**2 + 1, x).exquo(Poly(2*x - 4, x))\n-        Traceback (most recent call last):\n-        ...\n-        ExactQuotientFailed: 2*x - 4 does not divide x**2 + 1\n-\n-        \"\"\"\n-        dom, per, F, G = f._unify(g)\n-        retract = False\n-\n-        if auto and dom.is_Ring and not dom.is_Field:\n-            F, G = F.to_field(), G.to_field()\n-            retract = True\n-\n-        if hasattr(f.rep, 'exquo'):\n-            try:\n-                q = F.exquo(G)\n-            except ExactQuotientFailed as exc:\n-                raise exc.new(f.as_expr(), g.as_expr())\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'exquo')\n-\n-        if retract:\n-            try:\n-                q = q.to_ring()\n-            except CoercionFailed:\n-                pass\n-\n-        return per(q)\n-\n-    def _gen_to_level(f, gen):\n-        \"\"\"Returns level associated with the given generator. \"\"\"\n-        if isinstance(gen, int):\n-            length = len(f.gens)\n-\n-            if -length <= gen < length:\n-                if gen < 0:\n-                    return length + gen\n-                else:\n-                    return gen\n-            else:\n-                raise PolynomialError(\"-%s <= gen < %s expected, got %s\" %\n-                                      (length, length, gen))\n-        else:\n-            try:\n-                return f.gens.index(sympify(gen))\n-            except ValueError:\n-                raise PolynomialError(\n-                    \"a valid generator expected, got %s\" % gen)\n-\n-    def degree(f, gen=0):\n-        \"\"\"\n-        Returns degree of ``f`` in ``x_j``.\n-\n-        The degree of 0 is negative infinity.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x, y\n-\n-        >>> Poly(x**2 + y*x + 1, x, y).degree()\n-        2\n-        >>> Poly(x**2 + y*x + y, x, y).degree(y)\n-        1\n-        >>> Poly(0, x).degree()\n-        -oo\n-\n-        \"\"\"\n-        j = f._gen_to_level(gen)\n-\n-        if hasattr(f.rep, 'degree'):\n-            return f.rep.degree(j)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'degree')\n-\n-    def degree_list(f):\n-        \"\"\"\n-        Returns a list of degrees of ``f``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x, y\n-\n-        >>> Poly(x**2 + y*x + 1, x, y).degree_list()\n-        (2, 1)\n-\n-        \"\"\"\n-        if hasattr(f.rep, 'degree_list'):\n-            return f.rep.degree_list()\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'degree_list')\n-\n-    def total_degree(f):\n-        \"\"\"\n-        Returns the total degree of ``f``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x, y\n-\n-        >>> Poly(x**2 + y*x + 1, x, y).total_degree()\n-        2\n-        >>> Poly(x + y**5, x, y).total_degree()\n-        5\n-\n-        \"\"\"\n-        if hasattr(f.rep, 'total_degree'):\n-            return f.rep.total_degree()\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'total_degree')\n-\n-    def homogenize(f, s):\n-        \"\"\"\n-        Returns the homogeneous polynomial of ``f``.\n-\n-        A homogeneous polynomial is a polynomial whose all monomials with\n-        non-zero coefficients have the same total degree. If you only\n-        want to check if a polynomial is homogeneous, then use\n-        :func:`Poly.is_homogeneous`. If you want not only to check if a\n-        polynomial is homogeneous but also compute its homogeneous order,\n-        then use :func:`Poly.homogeneous_order`.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x, y, z\n-\n-        >>> f = Poly(x**5 + 2*x**2*y**2 + 9*x*y**3)\n-        >>> f.homogenize(z)\n-        Poly(x**5 + 2*x**2*y**2*z + 9*x*y**3*z, x, y, z, domain='ZZ')\n-\n-        \"\"\"\n-        if not isinstance(s, Symbol):\n-            raise TypeError(\"``Symbol`` expected, got %s\" % type(s))\n-        if s in f.gens:\n-            i = f.gens.index(s)\n-            gens = f.gens\n-        else:\n-            i = len(f.gens)\n-            gens = f.gens + (s,)\n-        if hasattr(f.rep, 'homogenize'):\n-            return f.per(f.rep.homogenize(i), gens=gens)\n-        raise OperationNotSupported(f, 'homogeneous_order')\n-\n-    def homogeneous_order(f):\n-        \"\"\"\n-        Returns the homogeneous order of ``f``.\n-\n-        A homogeneous polynomial is a polynomial whose all monomials with\n-        non-zero coefficients have the same total degree. This degree is\n-        the homogeneous order of ``f``. If you only want to check if a\n-        polynomial is homogeneous, then use :func:`Poly.is_homogeneous`.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x, y\n-\n-        >>> f = Poly(x**5 + 2*x**3*y**2 + 9*x*y**4)\n-        >>> f.homogeneous_order()\n-        5\n-\n-        \"\"\"\n-        if hasattr(f.rep, 'homogeneous_order'):\n-            return f.rep.homogeneous_order()\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'homogeneous_order')\n-\n-    def LC(f, order=None):\n-        \"\"\"\n-        Returns the leading coefficient of ``f``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(4*x**3 + 2*x**2 + 3*x, x).LC()\n-        4\n-\n-        \"\"\"\n-        if order is not None:\n-            return f.coeffs(order)[0]\n-\n-        if hasattr(f.rep, 'LC'):\n-            result = f.rep.LC()\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'LC')\n-\n-        return f.rep.dom.to_sympy(result)\n-\n-    def TC(f):\n-        \"\"\"\n-        Returns the trailing coefficient of ``f``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**3 + 2*x**2 + 3*x, x).TC()\n-        0\n-\n-        \"\"\"\n-        if hasattr(f.rep, 'TC'):\n-            result = f.rep.TC()\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'TC')\n-\n-        return f.rep.dom.to_sympy(result)\n-\n-    def EC(f, order=None):\n-        \"\"\"\n-        Returns the last non-zero coefficient of ``f``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**3 + 2*x**2 + 3*x, x).EC()\n-        3\n-\n-        \"\"\"\n-        if hasattr(f.rep, 'coeffs'):\n-            return f.coeffs(order)[-1]\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'EC')\n-\n-    def coeff_monomial(f, monom):\n-        \"\"\"\n-        Returns the coefficient of ``monom`` in ``f`` if there, else None.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly, exp\n-        >>> from sympy.abc import x, y\n-\n-        >>> p = Poly(24*x*y*exp(8) + 23*x, x, y)\n-\n-        >>> p.coeff_monomial(x)\n-        23\n-        >>> p.coeff_monomial(y)\n-        0\n-        >>> p.coeff_monomial(x*y)\n-        24*exp(8)\n-\n-        Note that ``Expr.coeff()`` behaves differently, collecting terms\n-        if possible; the Poly must be converted to an Expr to use that\n-        method, however:\n-\n-        >>> p.as_expr().coeff(x)\n-        24*y*exp(8) + 23\n-        >>> p.as_expr().coeff(y)\n-        24*x*exp(8)\n-        >>> p.as_expr().coeff(x*y)\n-        24*exp(8)\n-\n-        See Also\n-        ========\n-        nth: more efficient query using exponents of the monomial's generators\n-\n-        \"\"\"\n-        return f.nth(*Monomial(monom, f.gens).exponents)\n-\n-    def nth(f, *N):\n-        \"\"\"\n-        Returns the ``n``-th coefficient of ``f`` where ``N`` are the\n-        exponents of the generators in the term of interest.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly, sqrt\n-        >>> from sympy.abc import x, y\n-\n-        >>> Poly(x**3 + 2*x**2 + 3*x, x).nth(2)\n-        2\n-        >>> Poly(x**3 + 2*x*y**2 + y**2, x, y).nth(1, 2)\n-        2\n-        >>> Poly(4*sqrt(x)*y)\n-        Poly(4*y*(sqrt(x)), y, sqrt(x), domain='ZZ')\n-        >>> _.nth(1, 1)\n-        4\n-\n-        See Also\n-        ========\n-        coeff_monomial\n-\n-        \"\"\"\n-        if hasattr(f.rep, 'nth'):\n-            if len(N) != len(f.gens):\n-                raise ValueError('exponent of each generator must be specified')\n-            result = f.rep.nth(*list(map(int, N)))\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'nth')\n-\n-        return f.rep.dom.to_sympy(result)\n-\n-    def coeff(f, x, n=1, right=False):\n-        # the semantics of coeff_monomial and Expr.coeff are different;\n-        # if someone is working with a Poly, they should be aware of the\n-        # differences and chose the method best suited for the query.\n-        # Alternatively, a pure-polys method could be written here but\n-        # at this time the ``right`` keyword would be ignored because Poly\n-        # doesn't work with non-commutatives.\n-        raise NotImplementedError(\n-            'Either convert to Expr with `as_expr` method '\n-            'to use Expr\\'s coeff method or else use the '\n-            '`coeff_monomial` method of Polys.')\n-\n-    def LM(f, order=None):\n-        \"\"\"\n-        Returns the leading monomial of ``f``.\n-\n-        The Leading monomial signifies the monomial having\n-        the highest power of the principal generator in the\n-        expression f.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x, y\n-\n-        >>> Poly(4*x**2 + 2*x*y**2 + x*y + 3*y, x, y).LM()\n-        x**2*y**0\n-\n-        \"\"\"\n-        return Monomial(f.monoms(order)[0], f.gens)\n-\n-    def EM(f, order=None):\n-        \"\"\"\n-        Returns the last non-zero monomial of ``f``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x, y\n-\n-        >>> Poly(4*x**2 + 2*x*y**2 + x*y + 3*y, x, y).EM()\n-        x**0*y**1\n-\n-        \"\"\"\n-        return Monomial(f.monoms(order)[-1], f.gens)\n-\n-    def LT(f, order=None):\n-        \"\"\"\n-        Returns the leading term of ``f``.\n-\n-        The Leading term signifies the term having\n-        the highest power of the principal generator in the\n-        expression f along with its coefficient.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x, y\n-\n-        >>> Poly(4*x**2 + 2*x*y**2 + x*y + 3*y, x, y).LT()\n-        (x**2*y**0, 4)\n-\n-        \"\"\"\n-        monom, coeff = f.terms(order)[0]\n-        return Monomial(monom, f.gens), coeff\n-\n-    def ET(f, order=None):\n-        \"\"\"\n-        Returns the last non-zero term of ``f``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x, y\n-\n-        >>> Poly(4*x**2 + 2*x*y**2 + x*y + 3*y, x, y).ET()\n-        (x**0*y**1, 3)\n-\n-        \"\"\"\n-        monom, coeff = f.terms(order)[-1]\n-        return Monomial(monom, f.gens), coeff\n-\n-    def max_norm(f):\n-        \"\"\"\n-        Returns maximum norm of ``f``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(-x**2 + 2*x - 3, x).max_norm()\n-        3\n-\n-        \"\"\"\n-        if hasattr(f.rep, 'max_norm'):\n-            result = f.rep.max_norm()\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'max_norm')\n-\n-        return f.rep.dom.to_sympy(result)\n-\n-    def l1_norm(f):\n-        \"\"\"\n-        Returns l1 norm of ``f``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(-x**2 + 2*x - 3, x).l1_norm()\n-        6\n-\n-        \"\"\"\n-        if hasattr(f.rep, 'l1_norm'):\n-            result = f.rep.l1_norm()\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'l1_norm')\n-\n-        return f.rep.dom.to_sympy(result)\n-\n-    def clear_denoms(self, convert=False):\n-        \"\"\"\n-        Clear denominators, but keep the ground domain.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly, S, QQ\n-        >>> from sympy.abc import x\n-\n-        >>> f = Poly(x/2 + S(1)/3, x, domain=QQ)\n-\n-        >>> f.clear_denoms()\n-        (6, Poly(3*x + 2, x, domain='QQ'))\n-        >>> f.clear_denoms(convert=True)\n-        (6, Poly(3*x + 2, x, domain='ZZ'))\n-\n-        \"\"\"\n-        f = self\n-\n-        if not f.rep.dom.is_Field:\n-            return S.One, f\n-\n-        dom = f.get_domain()\n-        if dom.has_assoc_Ring:\n-            dom = f.rep.dom.get_ring()\n-\n-        if hasattr(f.rep, 'clear_denoms'):\n-            coeff, result = f.rep.clear_denoms()\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'clear_denoms')\n-\n-        coeff, f = dom.to_sympy(coeff), f.per(result)\n-\n-        if not convert or not dom.has_assoc_Ring:\n-            return coeff, f\n-        else:\n-            return coeff, f.to_ring()\n-\n-    def rat_clear_denoms(self, g):\n-        \"\"\"\n-        Clear denominators in a rational function ``f/g``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x, y\n-\n-        >>> f = Poly(x**2/y + 1, x)\n-        >>> g = Poly(x**3 + y, x)\n-\n-        >>> p, q = f.rat_clear_denoms(g)\n-\n-        >>> p\n-        Poly(x**2 + y, x, domain='ZZ[y]')\n-        >>> q\n-        Poly(y*x**3 + y**2, x, domain='ZZ[y]')\n-\n-        \"\"\"\n-        f = self\n-\n-        dom, per, f, g = f._unify(g)\n-\n-        f = per(f)\n-        g = per(g)\n-\n-        if not (dom.is_Field and dom.has_assoc_Ring):\n-            return f, g\n-\n-        a, f = f.clear_denoms(convert=True)\n-        b, g = g.clear_denoms(convert=True)\n-\n-        f = f.mul_ground(b)\n-        g = g.mul_ground(a)\n-\n-        return f, g\n-\n-    def integrate(self, *specs, **args):\n-        \"\"\"\n-        Computes indefinite integral of ``f``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x, y\n-\n-        >>> Poly(x**2 + 2*x + 1, x).integrate()\n-        Poly(1/3*x**3 + x**2 + x, x, domain='QQ')\n-\n-        >>> Poly(x*y**2 + x, x, y).integrate((0, 1), (1, 0))\n-        Poly(1/2*x**2*y**2 + 1/2*x**2, x, y, domain='QQ')\n-\n-        \"\"\"\n-        f = self\n-\n-        if args.get('auto', True) and f.rep.dom.is_Ring:\n-            f = f.to_field()\n-\n-        if hasattr(f.rep, 'integrate'):\n-            if not specs:\n-                return f.per(f.rep.integrate(m=1))\n-\n-            rep = f.rep\n-\n-            for spec in specs:\n-                if type(spec) is tuple:\n-                    gen, m = spec\n-                else:\n-                    gen, m = spec, 1\n-\n-                rep = rep.integrate(int(m), f._gen_to_level(gen))\n-\n-            return f.per(rep)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'integrate')\n-\n-    def diff(f, *specs, **kwargs):\n-        \"\"\"\n-        Computes partial derivative of ``f``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x, y\n-\n-        >>> Poly(x**2 + 2*x + 1, x).diff()\n-        Poly(2*x + 2, x, domain='ZZ')\n-\n-        >>> Poly(x*y**2 + x, x, y).diff((0, 0), (1, 1))\n-        Poly(2*x*y, x, y, domain='ZZ')\n-\n-        \"\"\"\n-        if not kwargs.get('evaluate', True):\n-            return Derivative(f, *specs, **kwargs)\n-\n-        if hasattr(f.rep, 'diff'):\n-            if not specs:\n-                return f.per(f.rep.diff(m=1))\n-\n-            rep = f.rep\n-\n-            for spec in specs:\n-                if type(spec) is tuple:\n-                    gen, m = spec\n-                else:\n-                    gen, m = spec, 1\n-\n-                rep = rep.diff(int(m), f._gen_to_level(gen))\n-\n-            return f.per(rep)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'diff')\n-\n-    _eval_derivative = diff\n-\n-    def eval(self, x, a=None, auto=True):\n-        \"\"\"\n-        Evaluate ``f`` at ``a`` in the given variable.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x, y, z\n-\n-        >>> Poly(x**2 + 2*x + 3, x).eval(2)\n-        11\n-\n-        >>> Poly(2*x*y + 3*x + y + 2, x, y).eval(x, 2)\n-        Poly(5*y + 8, y, domain='ZZ')\n-\n-        >>> f = Poly(2*x*y + 3*x + y + 2*z, x, y, z)\n-\n-        >>> f.eval({x: 2})\n-        Poly(5*y + 2*z + 6, y, z, domain='ZZ')\n-        >>> f.eval({x: 2, y: 5})\n-        Poly(2*z + 31, z, domain='ZZ')\n-        >>> f.eval({x: 2, y: 5, z: 7})\n-        45\n-\n-        >>> f.eval((2, 5))\n-        Poly(2*z + 31, z, domain='ZZ')\n-        >>> f(2, 5)\n-        Poly(2*z + 31, z, domain='ZZ')\n-\n-        \"\"\"\n-        f = self\n-\n-        if a is None:\n-            if isinstance(x, dict):\n-                mapping = x\n-\n-                for gen, value in mapping.items():\n-                    f = f.eval(gen, value)\n-\n-                return f\n-            elif isinstance(x, (tuple, list)):\n-                values = x\n-\n-                if len(values) > len(f.gens):\n-                    raise ValueError(\"too many values provided\")\n-\n-                for gen, value in zip(f.gens, values):\n-                    f = f.eval(gen, value)\n-\n-                return f\n-            else:\n-                j, a = 0, x\n-        else:\n-            j = f._gen_to_level(x)\n-\n-        if not hasattr(f.rep, 'eval'):  # pragma: no cover\n-            raise OperationNotSupported(f, 'eval')\n-\n-        try:\n-            result = f.rep.eval(a, j)\n-        except CoercionFailed:\n-            if not auto:\n-                raise DomainError(\"can't evaluate at %s in %s\" % (a, f.rep.dom))\n-            else:\n-                a_domain, [a] = construct_domain([a])\n-                new_domain = f.get_domain().unify_with_symbols(a_domain, f.gens)\n-\n-                f = f.set_domain(new_domain)\n-                a = new_domain.convert(a, a_domain)\n-\n-                result = f.rep.eval(a, j)\n-\n-        return f.per(result, remove=j)\n-\n-    def __call__(f, *values):\n-        \"\"\"\n-        Evaluate ``f`` at the give values.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x, y, z\n-\n-        >>> f = Poly(2*x*y + 3*x + y + 2*z, x, y, z)\n-\n-        >>> f(2)\n-        Poly(5*y + 2*z + 6, y, z, domain='ZZ')\n-        >>> f(2, 5)\n-        Poly(2*z + 31, z, domain='ZZ')\n-        >>> f(2, 5, 7)\n-        45\n-\n-        \"\"\"\n-        return f.eval(values)\n-\n-    def half_gcdex(f, g, auto=True):\n-        \"\"\"\n-        Half extended Euclidean algorithm of ``f`` and ``g``.\n-\n-        Returns ``(s, h)`` such that ``h = gcd(f, g)`` and ``s*f = h (mod g)``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> f = x**4 - 2*x**3 - 6*x**2 + 12*x + 15\n-        >>> g = x**3 + x**2 - 4*x - 4\n-\n-        >>> Poly(f).half_gcdex(Poly(g))\n-        (Poly(-1/5*x + 3/5, x, domain='QQ'), Poly(x + 1, x, domain='QQ'))\n-\n-        \"\"\"\n-        dom, per, F, G = f._unify(g)\n-\n-        if auto and dom.is_Ring:\n-            F, G = F.to_field(), G.to_field()\n-\n-        if hasattr(f.rep, 'half_gcdex'):\n-            s, h = F.half_gcdex(G)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'half_gcdex')\n-\n-        return per(s), per(h)\n-\n-    def gcdex(f, g, auto=True):\n-        \"\"\"\n-        Extended Euclidean algorithm of ``f`` and ``g``.\n-\n-        Returns ``(s, t, h)`` such that ``h = gcd(f, g)`` and ``s*f + t*g = h``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> f = x**4 - 2*x**3 - 6*x**2 + 12*x + 15\n-        >>> g = x**3 + x**2 - 4*x - 4\n-\n-        >>> Poly(f).gcdex(Poly(g))\n-        (Poly(-1/5*x + 3/5, x, domain='QQ'),\n-         Poly(1/5*x**2 - 6/5*x + 2, x, domain='QQ'),\n-         Poly(x + 1, x, domain='QQ'))\n-\n-        \"\"\"\n-        dom, per, F, G = f._unify(g)\n-\n-        if auto and dom.is_Ring:\n-            F, G = F.to_field(), G.to_field()\n-\n-        if hasattr(f.rep, 'gcdex'):\n-            s, t, h = F.gcdex(G)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'gcdex')\n-\n-        return per(s), per(t), per(h)\n-\n-    def invert(f, g, auto=True):\n-        \"\"\"\n-        Invert ``f`` modulo ``g`` when possible.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**2 - 1, x).invert(Poly(2*x - 1, x))\n-        Poly(-4/3, x, domain='QQ')\n-\n-        >>> Poly(x**2 - 1, x).invert(Poly(x - 1, x))\n-        Traceback (most recent call last):\n-        ...\n-        NotInvertible: zero divisor\n-\n-        \"\"\"\n-        dom, per, F, G = f._unify(g)\n-\n-        if auto and dom.is_Ring:\n-            F, G = F.to_field(), G.to_field()\n-\n-        if hasattr(f.rep, 'invert'):\n-            result = F.invert(G)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'invert')\n-\n-        return per(result)\n-\n-    def revert(f, n):\n-        \"\"\"\n-        Compute ``f**(-1)`` mod ``x**n``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(1, x).revert(2)\n-        Poly(1, x, domain='ZZ')\n-\n-        >>> Poly(1 + x, x).revert(1)\n-        Poly(1, x, domain='ZZ')\n-\n-        >>> Poly(x**2 - 1, x).revert(1)\n-        Traceback (most recent call last):\n-        ...\n-        NotReversible: only unity is reversible in a ring\n-\n-        >>> Poly(1/x, x).revert(1)\n-        Traceback (most recent call last):\n-        ...\n-        PolynomialError: 1/x contains an element of the generators set\n-\n-        \"\"\"\n-        if hasattr(f.rep, 'revert'):\n-            result = f.rep.revert(int(n))\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'revert')\n-\n-        return f.per(result)\n-\n-    def subresultants(f, g):\n-        \"\"\"\n-        Computes the subresultant PRS of ``f`` and ``g``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**2 + 1, x).subresultants(Poly(x**2 - 1, x))\n-        [Poly(x**2 + 1, x, domain='ZZ'),\n-         Poly(x**2 - 1, x, domain='ZZ'),\n-         Poly(-2, x, domain='ZZ')]\n-\n-        \"\"\"\n-        _, per, F, G = f._unify(g)\n-\n-        if hasattr(f.rep, 'subresultants'):\n-            result = F.subresultants(G)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'subresultants')\n-\n-        return list(map(per, result))\n-\n-    def resultant(f, g, includePRS=False):\n-        \"\"\"\n-        Computes the resultant of ``f`` and ``g`` via PRS.\n-\n-        If includePRS=True, it includes the subresultant PRS in the result.\n-        Because the PRS is used to calculate the resultant, this is more\n-        efficient than calling :func:`subresultants` separately.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> f = Poly(x**2 + 1, x)\n-\n-        >>> f.resultant(Poly(x**2 - 1, x))\n-        4\n-        >>> f.resultant(Poly(x**2 - 1, x), includePRS=True)\n-        (4, [Poly(x**2 + 1, x, domain='ZZ'), Poly(x**2 - 1, x, domain='ZZ'),\n-             Poly(-2, x, domain='ZZ')])\n-\n-        \"\"\"\n-        _, per, F, G = f._unify(g)\n-\n-        if hasattr(f.rep, 'resultant'):\n-            if includePRS:\n-                result, R = F.resultant(G, includePRS=includePRS)\n-            else:\n-                result = F.resultant(G)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'resultant')\n-\n-        if includePRS:\n-            return (per(result, remove=0), list(map(per, R)))\n-        return per(result, remove=0)\n-\n-    def discriminant(f):\n-        \"\"\"\n-        Computes the discriminant of ``f``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**2 + 2*x + 3, x).discriminant()\n-        -8\n-\n-        \"\"\"\n-        if hasattr(f.rep, 'discriminant'):\n-            result = f.rep.discriminant()\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'discriminant')\n-\n-        return f.per(result, remove=0)\n-\n-    def dispersionset(f, g=None):\n-        r\"\"\"Compute the *dispersion set* of two polynomials.\n-\n-        For two polynomials `f(x)` and `g(x)` with `\\deg f > 0`\n-        and `\\deg g > 0` the dispersion set `\\operatorname{J}(f, g)` is defined as:\n-\n-        .. math::\n-            \\operatorname{J}(f, g)\n-            & := \\{a \\in \\mathbb{N}_0 | \\gcd(f(x), g(x+a)) \\neq 1\\} \\\\\n-            &  = \\{a \\in \\mathbb{N}_0 | \\deg \\gcd(f(x), g(x+a)) \\geq 1\\}\n-\n-        For a single polynomial one defines `\\operatorname{J}(f) := \\operatorname{J}(f, f)`.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import poly\n-        >>> from sympy.polys.dispersion import dispersion, dispersionset\n-        >>> from sympy.abc import x\n-\n-        Dispersion set and dispersion of a simple polynomial:\n-\n-        >>> fp = poly((x - 3)*(x + 3), x)\n-        >>> sorted(dispersionset(fp))\n-        [0, 6]\n-        >>> dispersion(fp)\n-        6\n-\n-        Note that the definition of the dispersion is not symmetric:\n-\n-        >>> fp = poly(x**4 - 3*x**2 + 1, x)\n-        >>> gp = fp.shift(-3)\n-        >>> sorted(dispersionset(fp, gp))\n-        [2, 3, 4]\n-        >>> dispersion(fp, gp)\n-        4\n-        >>> sorted(dispersionset(gp, fp))\n-        []\n-        >>> dispersion(gp, fp)\n-        -oo\n-\n-        Computing the dispersion also works over field extensions:\n-\n-        >>> from sympy import sqrt\n-        >>> fp = poly(x**2 + sqrt(5)*x - 1, x, domain='QQ<sqrt(5)>')\n-        >>> gp = poly(x**2 + (2 + sqrt(5))*x + sqrt(5), x, domain='QQ<sqrt(5)>')\n-        >>> sorted(dispersionset(fp, gp))\n-        [2]\n-        >>> sorted(dispersionset(gp, fp))\n-        [1, 4]\n-\n-        We can even perform the computations for polynomials\n-        having symbolic coefficients:\n-\n-        >>> from sympy.abc import a\n-        >>> fp = poly(4*x**4 + (4*a + 8)*x**3 + (a**2 + 6*a + 4)*x**2 + (a**2 + 2*a)*x, x)\n-        >>> sorted(dispersionset(fp))\n-        [0, 1]\n-\n-        See Also\n-        ========\n-\n-        dispersion\n-\n-        References\n-        ==========\n-\n-        1. [ManWright94]_\n-        2. [Koepf98]_\n-        3. [Abramov71]_\n-        4. [Man93]_\n-        \"\"\"\n-        from sympy.polys.dispersion import dispersionset\n-        return dispersionset(f, g)\n-\n-    def dispersion(f, g=None):\n-        r\"\"\"Compute the *dispersion* of polynomials.\n-\n-        For two polynomials `f(x)` and `g(x)` with `\\deg f > 0`\n-        and `\\deg g > 0` the dispersion `\\operatorname{dis}(f, g)` is defined as:\n-\n-        .. math::\n-            \\operatorname{dis}(f, g)\n-            & := \\max\\{ J(f,g) \\cup \\{0\\} \\} \\\\\n-            &  = \\max\\{ \\{a \\in \\mathbb{N} | \\gcd(f(x), g(x+a)) \\neq 1\\} \\cup \\{0\\} \\}\n-\n-        and for a single polynomial `\\operatorname{dis}(f) := \\operatorname{dis}(f, f)`.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import poly\n-        >>> from sympy.polys.dispersion import dispersion, dispersionset\n-        >>> from sympy.abc import x\n-\n-        Dispersion set and dispersion of a simple polynomial:\n-\n-        >>> fp = poly((x - 3)*(x + 3), x)\n-        >>> sorted(dispersionset(fp))\n-        [0, 6]\n-        >>> dispersion(fp)\n-        6\n-\n-        Note that the definition of the dispersion is not symmetric:\n-\n-        >>> fp = poly(x**4 - 3*x**2 + 1, x)\n-        >>> gp = fp.shift(-3)\n-        >>> sorted(dispersionset(fp, gp))\n-        [2, 3, 4]\n-        >>> dispersion(fp, gp)\n-        4\n-        >>> sorted(dispersionset(gp, fp))\n-        []\n-        >>> dispersion(gp, fp)\n-        -oo\n-\n-        Computing the dispersion also works over field extensions:\n-\n-        >>> from sympy import sqrt\n-        >>> fp = poly(x**2 + sqrt(5)*x - 1, x, domain='QQ<sqrt(5)>')\n-        >>> gp = poly(x**2 + (2 + sqrt(5))*x + sqrt(5), x, domain='QQ<sqrt(5)>')\n-        >>> sorted(dispersionset(fp, gp))\n-        [2]\n-        >>> sorted(dispersionset(gp, fp))\n-        [1, 4]\n-\n-        We can even perform the computations for polynomials\n-        having symbolic coefficients:\n-\n-        >>> from sympy.abc import a\n-        >>> fp = poly(4*x**4 + (4*a + 8)*x**3 + (a**2 + 6*a + 4)*x**2 + (a**2 + 2*a)*x, x)\n-        >>> sorted(dispersionset(fp))\n-        [0, 1]\n-\n-        See Also\n-        ========\n-\n-        dispersionset\n-\n-        References\n-        ==========\n-\n-        1. [ManWright94]_\n-        2. [Koepf98]_\n-        3. [Abramov71]_\n-        4. [Man93]_\n-        \"\"\"\n-        from sympy.polys.dispersion import dispersion\n-        return dispersion(f, g)\n-\n-    def cofactors(f, g):\n-        \"\"\"\n-        Returns the GCD of ``f`` and ``g`` and their cofactors.\n-\n-        Returns polynomials ``(h, cff, cfg)`` such that ``h = gcd(f, g)``, and\n-        ``cff = quo(f, h)`` and ``cfg = quo(g, h)`` are, so called, cofactors\n-        of ``f`` and ``g``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**2 - 1, x).cofactors(Poly(x**2 - 3*x + 2, x))\n-        (Poly(x - 1, x, domain='ZZ'),\n-         Poly(x + 1, x, domain='ZZ'),\n-         Poly(x - 2, x, domain='ZZ'))\n-\n-        \"\"\"\n-        _, per, F, G = f._unify(g)\n-\n-        if hasattr(f.rep, 'cofactors'):\n-            h, cff, cfg = F.cofactors(G)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'cofactors')\n-\n-        return per(h), per(cff), per(cfg)\n-\n-    def gcd(f, g):\n-        \"\"\"\n-        Returns the polynomial GCD of ``f`` and ``g``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**2 - 1, x).gcd(Poly(x**2 - 3*x + 2, x))\n-        Poly(x - 1, x, domain='ZZ')\n-\n-        \"\"\"\n-        _, per, F, G = f._unify(g)\n-\n-        if hasattr(f.rep, 'gcd'):\n-            result = F.gcd(G)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'gcd')\n-\n-        return per(result)\n-\n-    def lcm(f, g):\n-        \"\"\"\n-        Returns polynomial LCM of ``f`` and ``g``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**2 - 1, x).lcm(Poly(x**2 - 3*x + 2, x))\n-        Poly(x**3 - 2*x**2 - x + 2, x, domain='ZZ')\n-\n-        \"\"\"\n-        _, per, F, G = f._unify(g)\n-\n-        if hasattr(f.rep, 'lcm'):\n-            result = F.lcm(G)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'lcm')\n-\n-        return per(result)\n-\n-    def trunc(f, p):\n-        \"\"\"\n-        Reduce ``f`` modulo a constant ``p``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(2*x**3 + 3*x**2 + 5*x + 7, x).trunc(3)\n-        Poly(-x**3 - x + 1, x, domain='ZZ')\n-\n-        \"\"\"\n-        p = f.rep.dom.convert(p)\n-\n-        if hasattr(f.rep, 'trunc'):\n-            result = f.rep.trunc(p)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'trunc')\n-\n-        return f.per(result)\n-\n-    def monic(self, auto=True):\n-        \"\"\"\n-        Divides all coefficients by ``LC(f)``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly, ZZ\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(3*x**2 + 6*x + 9, x, domain=ZZ).monic()\n-        Poly(x**2 + 2*x + 3, x, domain='QQ')\n-\n-        >>> Poly(3*x**2 + 4*x + 2, x, domain=ZZ).monic()\n-        Poly(x**2 + 4/3*x + 2/3, x, domain='QQ')\n-\n-        \"\"\"\n-        f = self\n-\n-        if auto and f.rep.dom.is_Ring:\n-            f = f.to_field()\n-\n-        if hasattr(f.rep, 'monic'):\n-            result = f.rep.monic()\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'monic')\n-\n-        return f.per(result)\n-\n-    def content(f):\n-        \"\"\"\n-        Returns the GCD of polynomial coefficients.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(6*x**2 + 8*x + 12, x).content()\n-        2\n-\n-        \"\"\"\n-        if hasattr(f.rep, 'content'):\n-            result = f.rep.content()\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'content')\n-\n-        return f.rep.dom.to_sympy(result)\n-\n-    def primitive(f):\n-        \"\"\"\n-        Returns the content and a primitive form of ``f``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(2*x**2 + 8*x + 12, x).primitive()\n-        (2, Poly(x**2 + 4*x + 6, x, domain='ZZ'))\n-\n-        \"\"\"\n-        if hasattr(f.rep, 'primitive'):\n-            cont, result = f.rep.primitive()\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'primitive')\n-\n-        return f.rep.dom.to_sympy(cont), f.per(result)\n-\n-    def compose(f, g):\n-        \"\"\"\n-        Computes the functional composition of ``f`` and ``g``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**2 + x, x).compose(Poly(x - 1, x))\n-        Poly(x**2 - x, x, domain='ZZ')\n-\n-        \"\"\"\n-        _, per, F, G = f._unify(g)\n-\n-        if hasattr(f.rep, 'compose'):\n-            result = F.compose(G)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'compose')\n-\n-        return per(result)\n-\n-    def decompose(f):\n-        \"\"\"\n-        Computes a functional decomposition of ``f``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**4 + 2*x**3 - x - 1, x, domain='ZZ').decompose()\n-        [Poly(x**2 - x - 1, x, domain='ZZ'), Poly(x**2 + x, x, domain='ZZ')]\n-\n-        \"\"\"\n-        if hasattr(f.rep, 'decompose'):\n-            result = f.rep.decompose()\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'decompose')\n-\n-        return list(map(f.per, result))\n-\n-    def shift(f, a):\n-        \"\"\"\n-        Efficiently compute Taylor shift ``f(x + a)``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**2 - 2*x + 1, x).shift(2)\n-        Poly(x**2 + 2*x + 1, x, domain='ZZ')\n-\n-        \"\"\"\n-        if hasattr(f.rep, 'shift'):\n-            result = f.rep.shift(a)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'shift')\n-\n-        return f.per(result)\n-\n-    def transform(f, p, q):\n-        \"\"\"\n-        Efficiently evaluate the functional transformation ``q**n * f(p/q)``.\n-\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**2 - 2*x + 1, x).transform(Poly(x + 1, x), Poly(x - 1, x))\n-        Poly(4, x, domain='ZZ')\n-\n-        \"\"\"\n-        P, Q = p.unify(q)\n-        F, P = f.unify(P)\n-        F, Q = F.unify(Q)\n-\n-        if hasattr(F.rep, 'transform'):\n-            result = F.rep.transform(P.rep, Q.rep)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(F, 'transform')\n-\n-        return F.per(result)\n-\n-    def sturm(self, auto=True):\n-        \"\"\"\n-        Computes the Sturm sequence of ``f``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**3 - 2*x**2 + x - 3, x).sturm()\n-        [Poly(x**3 - 2*x**2 + x - 3, x, domain='QQ'),\n-         Poly(3*x**2 - 4*x + 1, x, domain='QQ'),\n-         Poly(2/9*x + 25/9, x, domain='QQ'),\n-         Poly(-2079/4, x, domain='QQ')]\n-\n-        \"\"\"\n-        f = self\n-\n-        if auto and f.rep.dom.is_Ring:\n-            f = f.to_field()\n-\n-        if hasattr(f.rep, 'sturm'):\n-            result = f.rep.sturm()\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'sturm')\n-\n-        return list(map(f.per, result))\n-\n-    def gff_list(f):\n-        \"\"\"\n-        Computes greatest factorial factorization of ``f``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> f = x**5 + 2*x**4 - x**3 - 2*x**2\n-\n-        >>> Poly(f).gff_list()\n-        [(Poly(x, x, domain='ZZ'), 1), (Poly(x + 2, x, domain='ZZ'), 4)]\n-\n-        \"\"\"\n-        if hasattr(f.rep, 'gff_list'):\n-            result = f.rep.gff_list()\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'gff_list')\n-\n-        return [(f.per(g), k) for g, k in result]\n-\n-    def norm(f):\n-        \"\"\"\n-        Computes the product, ``Norm(f)``, of the conjugates of\n-        a polynomial ``f`` defined over a number field ``K``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly, sqrt\n-        >>> from sympy.abc import x\n-\n-        >>> a, b = sqrt(2), sqrt(3)\n-\n-        A polynomial over a quadratic extension.\n-        Two conjugates x - a and x + a.\n-\n-        >>> f = Poly(x - a, x, extension=a)\n-        >>> f.norm()\n-        Poly(x**2 - 2, x, domain='QQ')\n-\n-        A polynomial over a quartic extension.\n-        Four conjugates x - a, x - a, x + a and x + a.\n-\n-        >>> f = Poly(x - a, x, extension=(a, b))\n-        >>> f.norm()\n-        Poly(x**4 - 4*x**2 + 4, x, domain='QQ')\n-\n-        \"\"\"\n-        if hasattr(f.rep, 'norm'):\n-            r = f.rep.norm()\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'norm')\n-\n-        return f.per(r)\n-\n-    def sqf_norm(f):\n-        \"\"\"\n-        Computes square-free norm of ``f``.\n-\n-        Returns ``s``, ``f``, ``r``, such that ``g(x) = f(x-sa)`` and\n-        ``r(x) = Norm(g(x))`` is a square-free polynomial over ``K``,\n-        where ``a`` is the algebraic extension of the ground domain.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly, sqrt\n-        >>> from sympy.abc import x\n-\n-        >>> s, f, r = Poly(x**2 + 1, x, extension=[sqrt(3)]).sqf_norm()\n-\n-        >>> s\n-        1\n-        >>> f\n-        Poly(x**2 - 2*sqrt(3)*x + 4, x, domain='QQ<sqrt(3)>')\n-        >>> r\n-        Poly(x**4 - 4*x**2 + 16, x, domain='QQ')\n-\n-        \"\"\"\n-        if hasattr(f.rep, 'sqf_norm'):\n-            s, g, r = f.rep.sqf_norm()\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'sqf_norm')\n-\n-        return s, f.per(g), f.per(r)\n-\n-    def sqf_part(f):\n-        \"\"\"\n-        Computes square-free part of ``f``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**3 - 3*x - 2, x).sqf_part()\n-        Poly(x**2 - x - 2, x, domain='ZZ')\n-\n-        \"\"\"\n-        if hasattr(f.rep, 'sqf_part'):\n-            result = f.rep.sqf_part()\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'sqf_part')\n-\n-        return f.per(result)\n-\n-    def sqf_list(f, all=False):\n-        \"\"\"\n-        Returns a list of square-free factors of ``f``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> f = 2*x**5 + 16*x**4 + 50*x**3 + 76*x**2 + 56*x + 16\n-\n-        >>> Poly(f).sqf_list()\n-        (2, [(Poly(x + 1, x, domain='ZZ'), 2),\n-             (Poly(x + 2, x, domain='ZZ'), 3)])\n-\n-        >>> Poly(f).sqf_list(all=True)\n-        (2, [(Poly(1, x, domain='ZZ'), 1),\n-             (Poly(x + 1, x, domain='ZZ'), 2),\n-             (Poly(x + 2, x, domain='ZZ'), 3)])\n-\n-        \"\"\"\n-        if hasattr(f.rep, 'sqf_list'):\n-            coeff, factors = f.rep.sqf_list(all)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'sqf_list')\n-\n-        return f.rep.dom.to_sympy(coeff), [(f.per(g), k) for g, k in factors]\n-\n-    def sqf_list_include(f, all=False):\n-        \"\"\"\n-        Returns a list of square-free factors of ``f``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly, expand\n-        >>> from sympy.abc import x\n-\n-        >>> f = expand(2*(x + 1)**3*x**4)\n-        >>> f\n-        2*x**7 + 6*x**6 + 6*x**5 + 2*x**4\n-\n-        >>> Poly(f).sqf_list_include()\n-        [(Poly(2, x, domain='ZZ'), 1),\n-         (Poly(x + 1, x, domain='ZZ'), 3),\n-         (Poly(x, x, domain='ZZ'), 4)]\n-\n-        >>> Poly(f).sqf_list_include(all=True)\n-        [(Poly(2, x, domain='ZZ'), 1),\n-         (Poly(1, x, domain='ZZ'), 2),\n-         (Poly(x + 1, x, domain='ZZ'), 3),\n-         (Poly(x, x, domain='ZZ'), 4)]\n-\n-        \"\"\"\n-        if hasattr(f.rep, 'sqf_list_include'):\n-            factors = f.rep.sqf_list_include(all)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'sqf_list_include')\n-\n-        return [(f.per(g), k) for g, k in factors]\n-\n-    def factor_list(f):\n-        \"\"\"\n-        Returns a list of irreducible factors of ``f``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x, y\n-\n-        >>> f = 2*x**5 + 2*x**4*y + 4*x**3 + 4*x**2*y + 2*x + 2*y\n-\n-        >>> Poly(f).factor_list()\n-        (2, [(Poly(x + y, x, y, domain='ZZ'), 1),\n-             (Poly(x**2 + 1, x, y, domain='ZZ'), 2)])\n-\n-        \"\"\"\n-        if hasattr(f.rep, 'factor_list'):\n-            try:\n-                coeff, factors = f.rep.factor_list()\n-            except DomainError:\n-                return S.One, [(f, 1)]\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'factor_list')\n-\n-        return f.rep.dom.to_sympy(coeff), [(f.per(g), k) for g, k in factors]\n-\n-    def factor_list_include(f):\n-        \"\"\"\n-        Returns a list of irreducible factors of ``f``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x, y\n-\n-        >>> f = 2*x**5 + 2*x**4*y + 4*x**3 + 4*x**2*y + 2*x + 2*y\n-\n-        >>> Poly(f).factor_list_include()\n-        [(Poly(2*x + 2*y, x, y, domain='ZZ'), 1),\n-         (Poly(x**2 + 1, x, y, domain='ZZ'), 2)]\n-\n-        \"\"\"\n-        if hasattr(f.rep, 'factor_list_include'):\n-            try:\n-                factors = f.rep.factor_list_include()\n-            except DomainError:\n-                return [(f, 1)]\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'factor_list_include')\n-\n-        return [(f.per(g), k) for g, k in factors]\n-\n-    def intervals(f, all=False, eps=None, inf=None, sup=None, fast=False, sqf=False):\n-        \"\"\"\n-        Compute isolating intervals for roots of ``f``.\n-\n-        For real roots the Vincent-Akritas-Strzebonski (VAS) continued fractions method is used.\n-\n-        References\n-        ==========\n-        .. [#] Alkiviadis G. Akritas and Adam W. Strzebonski: A Comparative Study of Two Real Root\n-            Isolation Methods . Nonlinear Analysis: Modelling and Control, Vol. 10, No. 4, 297-304, 2005.\n-        .. [#] Alkiviadis G. Akritas, Adam W. Strzebonski and Panagiotis S. Vigklas: Improving the\n-            Performance of the Continued Fractions Method Using new Bounds of Positive Roots. Nonlinear\n-            Analysis: Modelling and Control, Vol. 13, No. 3, 265-279, 2008.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**2 - 3, x).intervals()\n-        [((-2, -1), 1), ((1, 2), 1)]\n-        >>> Poly(x**2 - 3, x).intervals(eps=1e-2)\n-        [((-26/15, -19/11), 1), ((19/11, 26/15), 1)]\n-\n-        \"\"\"\n-        if eps is not None:\n-            eps = QQ.convert(eps)\n-\n-            if eps <= 0:\n-                raise ValueError(\"'eps' must be a positive rational\")\n-\n-        if inf is not None:\n-            inf = QQ.convert(inf)\n-        if sup is not None:\n-            sup = QQ.convert(sup)\n-\n-        if hasattr(f.rep, 'intervals'):\n-            result = f.rep.intervals(\n-                all=all, eps=eps, inf=inf, sup=sup, fast=fast, sqf=sqf)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'intervals')\n-\n-        if sqf:\n-            def _real(interval):\n-                s, t = interval\n-                return (QQ.to_sympy(s), QQ.to_sympy(t))\n-\n-            if not all:\n-                return list(map(_real, result))\n-\n-            def _complex(rectangle):\n-                (u, v), (s, t) = rectangle\n-                return (QQ.to_sympy(u) + I*QQ.to_sympy(v),\n-                        QQ.to_sympy(s) + I*QQ.to_sympy(t))\n-\n-            real_part, complex_part = result\n-\n-            return list(map(_real, real_part)), list(map(_complex, complex_part))\n-        else:\n-            def _real(interval):\n-                (s, t), k = interval\n-                return ((QQ.to_sympy(s), QQ.to_sympy(t)), k)\n-\n-            if not all:\n-                return list(map(_real, result))\n-\n-            def _complex(rectangle):\n-                ((u, v), (s, t)), k = rectangle\n-                return ((QQ.to_sympy(u) + I*QQ.to_sympy(v),\n-                         QQ.to_sympy(s) + I*QQ.to_sympy(t)), k)\n-\n-            real_part, complex_part = result\n-\n-            return list(map(_real, real_part)), list(map(_complex, complex_part))\n-\n-    def refine_root(f, s, t, eps=None, steps=None, fast=False, check_sqf=False):\n-        \"\"\"\n-        Refine an isolating interval of a root to the given precision.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**2 - 3, x).refine_root(1, 2, eps=1e-2)\n-        (19/11, 26/15)\n-\n-        \"\"\"\n-        if check_sqf and not f.is_sqf:\n-            raise PolynomialError(\"only square-free polynomials supported\")\n-\n-        s, t = QQ.convert(s), QQ.convert(t)\n-\n-        if eps is not None:\n-            eps = QQ.convert(eps)\n-\n-            if eps <= 0:\n-                raise ValueError(\"'eps' must be a positive rational\")\n-\n-        if steps is not None:\n-            steps = int(steps)\n-        elif eps is None:\n-            steps = 1\n-\n-        if hasattr(f.rep, 'refine_root'):\n-            S, T = f.rep.refine_root(s, t, eps=eps, steps=steps, fast=fast)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'refine_root')\n-\n-        return QQ.to_sympy(S), QQ.to_sympy(T)\n-\n-    def count_roots(f, inf=None, sup=None):\n-        \"\"\"\n-        Return the number of roots of ``f`` in ``[inf, sup]`` interval.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly, I\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**4 - 4, x).count_roots(-3, 3)\n-        2\n-        >>> Poly(x**4 - 4, x).count_roots(0, 1 + 3*I)\n-        1\n-\n-        \"\"\"\n-        inf_real, sup_real = True, True\n-\n-        if inf is not None:\n-            inf = sympify(inf)\n-\n-            if inf is S.NegativeInfinity:\n-                inf = None\n-            else:\n-                re, im = inf.as_real_imag()\n-\n-                if not im:\n-                    inf = QQ.convert(inf)\n-                else:\n-                    inf, inf_real = list(map(QQ.convert, (re, im))), False\n-\n-        if sup is not None:\n-            sup = sympify(sup)\n-\n-            if sup is S.Infinity:\n-                sup = None\n-            else:\n-                re, im = sup.as_real_imag()\n-\n-                if not im:\n-                    sup = QQ.convert(sup)\n-                else:\n-                    sup, sup_real = list(map(QQ.convert, (re, im))), False\n-\n-        if inf_real and sup_real:\n-            if hasattr(f.rep, 'count_real_roots'):\n-                count = f.rep.count_real_roots(inf=inf, sup=sup)\n-            else:  # pragma: no cover\n-                raise OperationNotSupported(f, 'count_real_roots')\n-        else:\n-            if inf_real and inf is not None:\n-                inf = (inf, QQ.zero)\n-\n-            if sup_real and sup is not None:\n-                sup = (sup, QQ.zero)\n-\n-            if hasattr(f.rep, 'count_complex_roots'):\n-                count = f.rep.count_complex_roots(inf=inf, sup=sup)\n-            else:  # pragma: no cover\n-                raise OperationNotSupported(f, 'count_complex_roots')\n-\n-        return Integer(count)\n-\n-    def root(f, index, radicals=True):\n-        \"\"\"\n-        Get an indexed root of a polynomial.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> f = Poly(2*x**3 - 7*x**2 + 4*x + 4)\n-\n-        >>> f.root(0)\n-        -1/2\n-        >>> f.root(1)\n-        2\n-        >>> f.root(2)\n-        2\n-        >>> f.root(3)\n-        Traceback (most recent call last):\n-        ...\n-        IndexError: root index out of [-3, 2] range, got 3\n-\n-        >>> Poly(x**5 + x + 1).root(0)\n-        CRootOf(x**3 - x**2 + 1, 0)\n-\n-        \"\"\"\n-        return sympy.polys.rootoftools.rootof(f, index, radicals=radicals)\n-\n-    def real_roots(f, multiple=True, radicals=True):\n-        \"\"\"\n-        Return a list of real roots with multiplicities.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(2*x**3 - 7*x**2 + 4*x + 4).real_roots()\n-        [-1/2, 2, 2]\n-        >>> Poly(x**3 + x + 1).real_roots()\n-        [CRootOf(x**3 + x + 1, 0)]\n-\n-        \"\"\"\n-        reals = sympy.polys.rootoftools.CRootOf.real_roots(f, radicals=radicals)\n-\n-        if multiple:\n-            return reals\n-        else:\n-            return group(reals, multiple=False)\n-\n-    def all_roots(f, multiple=True, radicals=True):\n-        \"\"\"\n-        Return a list of real and complex roots with multiplicities.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(2*x**3 - 7*x**2 + 4*x + 4).all_roots()\n-        [-1/2, 2, 2]\n-        >>> Poly(x**3 + x + 1).all_roots()\n-        [CRootOf(x**3 + x + 1, 0),\n-         CRootOf(x**3 + x + 1, 1),\n-         CRootOf(x**3 + x + 1, 2)]\n-\n-        \"\"\"\n-        roots = sympy.polys.rootoftools.CRootOf.all_roots(f, radicals=radicals)\n-\n-        if multiple:\n-            return roots\n-        else:\n-            return group(roots, multiple=False)\n-\n-    def nroots(f, n=15, maxsteps=50, cleanup=True):\n-        \"\"\"\n-        Compute numerical approximations of roots of ``f``.\n-\n-        Parameters\n-        ==========\n-\n-        n ... the number of digits to calculate\n-        maxsteps ... the maximum number of iterations to do\n-\n-        If the accuracy `n` cannot be reached in `maxsteps`, it will raise an\n-        exception. You need to rerun with higher maxsteps.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**2 - 3).nroots(n=15)\n-        [-1.73205080756888, 1.73205080756888]\n-        >>> Poly(x**2 - 3).nroots(n=30)\n-        [-1.73205080756887729352744634151, 1.73205080756887729352744634151]\n-\n-        \"\"\"\n-        from sympy.functions.elementary.complexes import sign\n-        if f.is_multivariate:\n-            raise MultivariatePolynomialError(\n-                \"can't compute numerical roots of %s\" % f)\n-\n-        if f.degree() <= 0:\n-            return []\n-\n-        # For integer and rational coefficients, convert them to integers only\n-        # (for accuracy). Otherwise just try to convert the coefficients to\n-        # mpmath.mpc and raise an exception if the conversion fails.\n-        if f.rep.dom is ZZ:\n-            coeffs = [int(coeff) for coeff in f.all_coeffs()]\n-        elif f.rep.dom is QQ:\n-            denoms = [coeff.q for coeff in f.all_coeffs()]\n-            from sympy.core.numbers import ilcm\n-            fac = ilcm(*denoms)\n-            coeffs = [int(coeff*fac) for coeff in f.all_coeffs()]\n-        else:\n-            coeffs = [coeff.evalf(n=n).as_real_imag()\n-                    for coeff in f.all_coeffs()]\n-            try:\n-                coeffs = [mpmath.mpc(*coeff) for coeff in coeffs]\n-            except TypeError:\n-                raise DomainError(\"Numerical domain expected, got %s\" % \\\n-                        f.rep.dom)\n-\n-        dps = mpmath.mp.dps\n-        mpmath.mp.dps = n\n-\n-        try:\n-            # We need to add extra precision to guard against losing accuracy.\n-            # 10 times the degree of the polynomial seems to work well.\n-            roots = mpmath.polyroots(coeffs, maxsteps=maxsteps,\n-                    cleanup=cleanup, error=False, extraprec=f.degree()*10)\n-\n-            # Mpmath puts real roots first, then complex ones (as does all_roots)\n-            # so we make sure this convention holds here, too.\n-            roots = list(map(sympify,\n-                sorted(roots, key=lambda r: (1 if r.imag else 0, r.real, abs(r.imag), sign(r.imag)))))\n-        except NoConvergence:\n-            raise NoConvergence(\n-                'convergence to root failed; try n < %s or maxsteps > %s' % (\n-                n, maxsteps))\n-        finally:\n-            mpmath.mp.dps = dps\n-\n-        return roots\n-\n-    def ground_roots(f):\n-        \"\"\"\n-        Compute roots of ``f`` by factorization in the ground domain.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**6 - 4*x**4 + 4*x**3 - x**2).ground_roots()\n-        {0: 2, 1: 2}\n-\n-        \"\"\"\n-        if f.is_multivariate:\n-            raise MultivariatePolynomialError(\n-                \"can't compute ground roots of %s\" % f)\n-\n-        roots = {}\n-\n-        for factor, k in f.factor_list()[1]:\n-            if factor.is_linear:\n-                a, b = factor.all_coeffs()\n-                roots[-b/a] = k\n-\n-        return roots\n-\n-    def nth_power_roots_poly(f, n):\n-        \"\"\"\n-        Construct a polynomial with n-th powers of roots of ``f``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> f = Poly(x**4 - x**2 + 1)\n-\n-        >>> f.nth_power_roots_poly(2)\n-        Poly(x**4 - 2*x**3 + 3*x**2 - 2*x + 1, x, domain='ZZ')\n-        >>> f.nth_power_roots_poly(3)\n-        Poly(x**4 + 2*x**2 + 1, x, domain='ZZ')\n-        >>> f.nth_power_roots_poly(4)\n-        Poly(x**4 + 2*x**3 + 3*x**2 + 2*x + 1, x, domain='ZZ')\n-        >>> f.nth_power_roots_poly(12)\n-        Poly(x**4 - 4*x**3 + 6*x**2 - 4*x + 1, x, domain='ZZ')\n-\n-        \"\"\"\n-        if f.is_multivariate:\n-            raise MultivariatePolynomialError(\n-                \"must be a univariate polynomial\")\n-\n-        N = sympify(n)\n-\n-        if N.is_Integer and N >= 1:\n-            n = int(N)\n-        else:\n-            raise ValueError(\"'n' must an integer and n >= 1, got %s\" % n)\n-\n-        x = f.gen\n-        t = Dummy('t')\n-\n-        r = f.resultant(f.__class__.from_expr(x**n - t, x, t))\n-\n-        return r.replace(t, x)\n-\n-    def cancel(f, g, include=False):\n-        \"\"\"\n-        Cancel common factors in a rational function ``f/g``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(2*x**2 - 2, x).cancel(Poly(x**2 - 2*x + 1, x))\n-        (1, Poly(2*x + 2, x, domain='ZZ'), Poly(x - 1, x, domain='ZZ'))\n-\n-        >>> Poly(2*x**2 - 2, x).cancel(Poly(x**2 - 2*x + 1, x), include=True)\n-        (Poly(2*x + 2, x, domain='ZZ'), Poly(x - 1, x, domain='ZZ'))\n-\n-        \"\"\"\n-        dom, per, F, G = f._unify(g)\n-\n-        if hasattr(F, 'cancel'):\n-            result = F.cancel(G, include=include)\n-        else:  # pragma: no cover\n-            raise OperationNotSupported(f, 'cancel')\n-\n-        if not include:\n-            if dom.has_assoc_Ring:\n-                dom = dom.get_ring()\n-\n-            cp, cq, p, q = result\n-\n-            cp = dom.to_sympy(cp)\n-            cq = dom.to_sympy(cq)\n-\n-            return cp/cq, per(p), per(q)\n-        else:\n-            return tuple(map(per, result))\n-\n-    @property\n-    def is_zero(f):\n-        \"\"\"\n-        Returns ``True`` if ``f`` is a zero polynomial.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(0, x).is_zero\n-        True\n-        >>> Poly(1, x).is_zero\n-        False\n-\n-        \"\"\"\n-        return f.rep.is_zero\n-\n-    @property\n-    def is_one(f):\n-        \"\"\"\n-        Returns ``True`` if ``f`` is a unit polynomial.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(0, x).is_one\n-        False\n-        >>> Poly(1, x).is_one\n-        True\n-\n-        \"\"\"\n-        return f.rep.is_one\n-\n-    @property\n-    def is_sqf(f):\n-        \"\"\"\n-        Returns ``True`` if ``f`` is a square-free polynomial.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**2 - 2*x + 1, x).is_sqf\n-        False\n-        >>> Poly(x**2 - 1, x).is_sqf\n-        True\n-\n-        \"\"\"\n-        return f.rep.is_sqf\n-\n-    @property\n-    def is_monic(f):\n-        \"\"\"\n-        Returns ``True`` if the leading coefficient of ``f`` is one.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x + 2, x).is_monic\n-        True\n-        >>> Poly(2*x + 2, x).is_monic\n-        False\n-\n-        \"\"\"\n-        return f.rep.is_monic\n-\n-    @property\n-    def is_primitive(f):\n-        \"\"\"\n-        Returns ``True`` if GCD of the coefficients of ``f`` is one.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(2*x**2 + 6*x + 12, x).is_primitive\n-        False\n-        >>> Poly(x**2 + 3*x + 6, x).is_primitive\n-        True\n-\n-        \"\"\"\n-        return f.rep.is_primitive\n-\n-    @property\n-    def is_ground(f):\n-        \"\"\"\n-        Returns ``True`` if ``f`` is an element of the ground domain.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x, y\n-\n-        >>> Poly(x, x).is_ground\n-        False\n-        >>> Poly(2, x).is_ground\n-        True\n-        >>> Poly(y, x).is_ground\n-        True\n-\n-        \"\"\"\n-        return f.rep.is_ground\n-\n-    @property\n-    def is_linear(f):\n-        \"\"\"\n-        Returns ``True`` if ``f`` is linear in all its variables.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x, y\n-\n-        >>> Poly(x + y + 2, x, y).is_linear\n-        True\n-        >>> Poly(x*y + 2, x, y).is_linear\n-        False\n-\n-        \"\"\"\n-        return f.rep.is_linear\n-\n-    @property\n-    def is_quadratic(f):\n-        \"\"\"\n-        Returns ``True`` if ``f`` is quadratic in all its variables.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x, y\n-\n-        >>> Poly(x*y + 2, x, y).is_quadratic\n-        True\n-        >>> Poly(x*y**2 + 2, x, y).is_quadratic\n-        False\n-\n-        \"\"\"\n-        return f.rep.is_quadratic\n-\n-    @property\n-    def is_monomial(f):\n-        \"\"\"\n-        Returns ``True`` if ``f`` is zero or has only one term.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(3*x**2, x).is_monomial\n-        True\n-        >>> Poly(3*x**2 + 1, x).is_monomial\n-        False\n-\n-        \"\"\"\n-        return f.rep.is_monomial\n-\n-    @property\n-    def is_homogeneous(f):\n-        \"\"\"\n-        Returns ``True`` if ``f`` is a homogeneous polynomial.\n-\n-        A homogeneous polynomial is a polynomial whose all monomials with\n-        non-zero coefficients have the same total degree. If you want not\n-        only to check if a polynomial is homogeneous but also compute its\n-        homogeneous order, then use :func:`Poly.homogeneous_order`.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x, y\n-\n-        >>> Poly(x**2 + x*y, x, y).is_homogeneous\n-        True\n-        >>> Poly(x**3 + x*y, x, y).is_homogeneous\n-        False\n-\n-        \"\"\"\n-        return f.rep.is_homogeneous\n-\n-    @property\n-    def is_irreducible(f):\n-        \"\"\"\n-        Returns ``True`` if ``f`` has no factors over its domain.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> Poly(x**2 + x + 1, x, modulus=2).is_irreducible\n-        True\n-        >>> Poly(x**2 + 1, x, modulus=2).is_irreducible\n-        False\n-\n-        \"\"\"\n-        return f.rep.is_irreducible\n-\n-    @property\n-    def is_univariate(f):\n-        \"\"\"\n-        Returns ``True`` if ``f`` is a univariate polynomial.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x, y\n-\n-        >>> Poly(x**2 + x + 1, x).is_univariate\n-        True\n-        >>> Poly(x*y**2 + x*y + 1, x, y).is_univariate\n-        False\n-        >>> Poly(x*y**2 + x*y + 1, x).is_univariate\n-        True\n-        >>> Poly(x**2 + x + 1, x, y).is_univariate\n-        False\n-\n-        \"\"\"\n-        return len(f.gens) == 1\n-\n-    @property\n-    def is_multivariate(f):\n-        \"\"\"\n-        Returns ``True`` if ``f`` is a multivariate polynomial.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x, y\n-\n-        >>> Poly(x**2 + x + 1, x).is_multivariate\n-        False\n-        >>> Poly(x*y**2 + x*y + 1, x, y).is_multivariate\n-        True\n-        >>> Poly(x*y**2 + x*y + 1, x).is_multivariate\n-        False\n-        >>> Poly(x**2 + x + 1, x, y).is_multivariate\n-        True\n-\n-        \"\"\"\n-        return len(f.gens) != 1\n-\n-    @property\n-    def is_cyclotomic(f):\n-        \"\"\"\n-        Returns ``True`` if ``f`` is a cyclotomic polnomial.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import Poly\n-        >>> from sympy.abc import x\n-\n-        >>> f = x**16 + x**14 - x**10 + x**8 - x**6 + x**2 + 1\n-\n-        >>> Poly(f).is_cyclotomic\n-        False\n-\n-        >>> g = x**16 + x**14 - x**10 - x**8 - x**6 + x**2 + 1\n-\n-        >>> Poly(g).is_cyclotomic\n-        True\n-\n-        \"\"\"\n-        return f.rep.is_cyclotomic\n-\n-    def __abs__(f):\n-        return f.abs()\n-\n-    def __neg__(f):\n-        return f.neg()\n-\n-    @_polifyit\n-    def __add__(f, g):\n-        return f.add(g)\n-\n-    @_polifyit\n-    def __radd__(f, g):\n-        return g.add(f)\n-\n-    @_polifyit\n-    def __sub__(f, g):\n-        return f.sub(g)\n-\n-    @_polifyit\n-    def __rsub__(f, g):\n-        return g.sub(f)\n-\n-    @_polifyit\n-    def __mul__(f, g):\n-        return f.mul(g)\n-\n-    @_polifyit\n-    def __rmul__(f, g):\n-        return g.mul(f)\n-\n-    @_sympifyit('n', NotImplemented)\n-    def __pow__(f, n):\n-        if n.is_Integer and n >= 0:\n-            return f.pow(n)\n-        else:\n-            return NotImplemented\n-\n-    @_polifyit\n-    def __divmod__(f, g):\n-        return f.div(g)\n-\n-    @_polifyit\n-    def __rdivmod__(f, g):\n-        return g.div(f)\n-\n-    @_polifyit\n-    def __mod__(f, g):\n-        return f.rem(g)\n-\n-    @_polifyit\n-    def __rmod__(f, g):\n-        return g.rem(f)\n-\n-    @_polifyit\n-    def __floordiv__(f, g):\n-        return f.quo(g)\n-\n-    @_polifyit\n-    def __rfloordiv__(f, g):\n-        return g.quo(f)\n-\n-    @_sympifyit('g', NotImplemented)\n-    def __truediv__(f, g):\n-        return f.as_expr()/g.as_expr()\n-\n-    @_sympifyit('g', NotImplemented)\n-    def __rtruediv__(f, g):\n-        return g.as_expr()/f.as_expr()\n-\n-    @_sympifyit('other', NotImplemented)\n-    def __eq__(self, other):\n-        f, g = self, other\n-\n-        if not g.is_Poly:\n-            try:\n-                g = f.__class__(g, f.gens, domain=f.get_domain())\n-            except (PolynomialError, DomainError, CoercionFailed):\n-                return False\n-\n-        if f.gens != g.gens:\n-            return False\n-\n-        if f.rep.dom != g.rep.dom:\n-            return False\n-\n-        return f.rep == g.rep\n-\n-    @_sympifyit('g', NotImplemented)\n-    def __ne__(f, g):\n-        return not f == g\n-\n-    def __bool__(f):\n-        return not f.is_zero\n-\n-    def eq(f, g, strict=False):\n-        if not strict:\n-            return f == g\n-        else:\n-            return f._strict_eq(sympify(g))\n-\n-    def ne(f, g, strict=False):\n-        return not f.eq(g, strict=strict)\n-\n-    def _strict_eq(f, g):\n-        return isinstance(g, f.__class__) and f.gens == g.gens and f.rep.eq(g.rep, strict=True)\n-\n-\n-@public\n-class PurePoly(Poly):\n-    \"\"\"Class for representing pure polynomials. \"\"\"\n-\n-    def _hashable_content(self):\n-        \"\"\"Allow SymPy to hash Poly instances. \"\"\"\n-        return (self.rep,)\n-\n-    def __hash__(self):\n-        return super().__hash__()\n-\n-    @property\n-    def free_symbols(self):\n-        \"\"\"\n-        Free symbols of a polynomial.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import PurePoly\n-        >>> from sympy.abc import x, y\n-\n-        >>> PurePoly(x**2 + 1).free_symbols\n-        set()\n-        >>> PurePoly(x**2 + y).free_symbols\n-        set()\n-        >>> PurePoly(x**2 + y, x).free_symbols\n-        {y}\n-\n-        \"\"\"\n-        return self.free_symbols_in_domain\n-\n-    @_sympifyit('other', NotImplemented)\n-    def __eq__(self, other):\n-        f, g = self, other\n-\n-        if not g.is_Poly:\n-            try:\n-                g = f.__class__(g, f.gens, domain=f.get_domain())\n-            except (PolynomialError, DomainError, CoercionFailed):\n-                return False\n-\n-        if len(f.gens) != len(g.gens):\n-            return False\n-\n-        if f.rep.dom != g.rep.dom:\n-            try:\n-                dom = f.rep.dom.unify(g.rep.dom, f.gens)\n-            except UnificationFailed:\n-                return False\n-\n-            f = f.set_domain(dom)\n-            g = g.set_domain(dom)\n-\n-        return f.rep == g.rep\n-\n-    def _strict_eq(f, g):\n-        return isinstance(g, f.__class__) and f.rep.eq(g.rep, strict=True)\n-\n-    def _unify(f, g):\n-        g = sympify(g)\n-\n-        if not g.is_Poly:\n-            try:\n-                return f.rep.dom, f.per, f.rep, f.rep.per(f.rep.dom.from_sympy(g))\n-            except CoercionFailed:\n-                raise UnificationFailed(\"can't unify %s with %s\" % (f, g))\n-\n-        if len(f.gens) != len(g.gens):\n-            raise UnificationFailed(\"can't unify %s with %s\" % (f, g))\n-\n-        if not (isinstance(f.rep, DMP) and isinstance(g.rep, DMP)):\n-            raise UnificationFailed(\"can't unify %s with %s\" % (f, g))\n-\n-        cls = f.__class__\n-        gens = f.gens\n-\n-        dom = f.rep.dom.unify(g.rep.dom, gens)\n-\n-        F = f.rep.convert(dom)\n-        G = g.rep.convert(dom)\n-\n-        def per(rep, dom=dom, gens=gens, remove=None):\n-            if remove is not None:\n-                gens = gens[:remove] + gens[remove + 1:]\n-\n-                if not gens:\n-                    return dom.to_sympy(rep)\n-\n-            return cls.new(rep, *gens)\n-\n-        return dom, per, F, G\n-\n-\n-@public\n-def poly_from_expr(expr, *gens, **args):\n-    \"\"\"Construct a polynomial from an expression. \"\"\"\n-    opt = options.build_options(gens, args)\n-    return _poly_from_expr(expr, opt)\n-\n-\n-def _poly_from_expr(expr, opt):\n-    \"\"\"Construct a polynomial from an expression. \"\"\"\n-    orig, expr = expr, sympify(expr)\n-\n-    if not isinstance(expr, Basic):\n-        raise PolificationFailed(opt, orig, expr)\n-    elif expr.is_Poly:\n-        poly = expr.__class__._from_poly(expr, opt)\n-\n-        opt.gens = poly.gens\n-        opt.domain = poly.domain\n-\n-        if opt.polys is None:\n-            opt.polys = True\n-\n-        return poly, opt\n-    elif opt.expand:\n-        expr = expr.expand()\n-\n-    rep, opt = _dict_from_expr(expr, opt)\n-    if not opt.gens:\n-        raise PolificationFailed(opt, orig, expr)\n-\n-    monoms, coeffs = list(zip(*list(rep.items())))\n-    domain = opt.domain\n-\n-    if domain is None:\n-        opt.domain, coeffs = construct_domain(coeffs, opt=opt)\n-    else:\n-        coeffs = list(map(domain.from_sympy, coeffs))\n-\n-    rep = dict(list(zip(monoms, coeffs)))\n-    poly = Poly._from_dict(rep, opt)\n-\n-    if opt.polys is None:\n-        opt.polys = False\n-\n-    return poly, opt\n-\n-\n-@public\n-def parallel_poly_from_expr(exprs, *gens, **args):\n-    \"\"\"Construct polynomials from expressions. \"\"\"\n-    opt = options.build_options(gens, args)\n-    return _parallel_poly_from_expr(exprs, opt)\n-\n-\n-def _parallel_poly_from_expr(exprs, opt):\n-    \"\"\"Construct polynomials from expressions. \"\"\"\n-    from sympy.functions.elementary.piecewise import Piecewise\n-\n-    if len(exprs) == 2:\n-        f, g = exprs\n-\n-        if isinstance(f, Poly) and isinstance(g, Poly):\n-            f = f.__class__._from_poly(f, opt)\n-            g = g.__class__._from_poly(g, opt)\n-\n-            f, g = f.unify(g)\n-\n-            opt.gens = f.gens\n-            opt.domain = f.domain\n-\n-            if opt.polys is None:\n-                opt.polys = True\n-\n-            return [f, g], opt\n-\n-    origs, exprs = list(exprs), []\n-    _exprs, _polys = [], []\n-\n-    failed = False\n-\n-    for i, expr in enumerate(origs):\n-        expr = sympify(expr)\n-\n-        if isinstance(expr, Basic):\n-            if expr.is_Poly:\n-                _polys.append(i)\n-            else:\n-                _exprs.append(i)\n-\n-                if opt.expand:\n-                    expr = expr.expand()\n-        else:\n-            failed = True\n-\n-        exprs.append(expr)\n-\n-    if failed:\n-        raise PolificationFailed(opt, origs, exprs, True)\n-\n-    if _polys:\n-        # XXX: this is a temporary solution\n-        for i in _polys:\n-            exprs[i] = exprs[i].as_expr()\n-\n-    reps, opt = _parallel_dict_from_expr(exprs, opt)\n-    if not opt.gens:\n-        raise PolificationFailed(opt, origs, exprs, True)\n-\n-    for k in opt.gens:\n-        if isinstance(k, Piecewise):\n-            raise PolynomialError(\"Piecewise generators do not make sense\")\n-\n-    coeffs_list, lengths = [], []\n-\n-    all_monoms = []\n-    all_coeffs = []\n-\n-    for rep in reps:\n-        monoms, coeffs = list(zip(*list(rep.items())))\n-\n-        coeffs_list.extend(coeffs)\n-        all_monoms.append(monoms)\n-\n-        lengths.append(len(coeffs))\n-\n-    domain = opt.domain\n-\n-    if domain is None:\n-        opt.domain, coeffs_list = construct_domain(coeffs_list, opt=opt)\n-    else:\n-        coeffs_list = list(map(domain.from_sympy, coeffs_list))\n-\n-    for k in lengths:\n-        all_coeffs.append(coeffs_list[:k])\n-        coeffs_list = coeffs_list[k:]\n-\n-    polys = []\n-\n-    for monoms, coeffs in zip(all_monoms, all_coeffs):\n-        rep = dict(list(zip(monoms, coeffs)))\n-        poly = Poly._from_dict(rep, opt)\n-        polys.append(poly)\n-\n-    if opt.polys is None:\n-        opt.polys = bool(_polys)\n-\n-    return polys, opt\n-\n-\n-def _update_args(args, key, value):\n-    \"\"\"Add a new ``(key, value)`` pair to arguments ``dict``. \"\"\"\n-    args = dict(args)\n-\n-    if key not in args:\n-        args[key] = value\n-\n-    return args\n-\n-\n-@public\n-def degree(f, gen=0):\n-    \"\"\"\n-    Return the degree of ``f`` in the given variable.\n-\n-    The degree of 0 is negative infinity.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import degree\n-    >>> from sympy.abc import x, y\n-\n-    >>> degree(x**2 + y*x + 1, gen=x)\n-    2\n-    >>> degree(x**2 + y*x + 1, gen=y)\n-    1\n-    >>> degree(0, x)\n-    -oo\n-\n-    See also\n-    ========\n-\n-    sympy.polys.polytools.Poly.total_degree\n-    degree_list\n-    \"\"\"\n-\n-    f = sympify(f, strict=True)\n-    gen_is_Num = sympify(gen, strict=True).is_Number\n-    if f.is_Poly:\n-        p = f\n-        isNum = p.as_expr().is_Number\n-    else:\n-        isNum = f.is_Number\n-        if not isNum:\n-            if gen_is_Num:\n-                p, _ = poly_from_expr(f)\n-            else:\n-                p, _ = poly_from_expr(f, gen)\n-\n-    if isNum:\n-        return S.Zero if f else S.NegativeInfinity\n-\n-    if not gen_is_Num:\n-        if f.is_Poly and gen not in p.gens:\n-            # try recast without explicit gens\n-            p, _ = poly_from_expr(f.as_expr())\n-        if gen not in p.gens:\n-            return S.Zero\n-    elif not f.is_Poly and len(f.free_symbols) > 1:\n-        raise TypeError(filldedent('''\n-         A symbolic generator of interest is required for a multivariate\n-         expression like func = %s, e.g. degree(func, gen = %s) instead of\n-         degree(func, gen = %s).\n-        ''' % (f, next(ordered(f.free_symbols)), gen)))\n-\n-    return Integer(p.degree(gen))\n-\n-\n-@public\n-def total_degree(f, *gens):\n-    \"\"\"\n-    Return the total_degree of ``f`` in the given variables.\n-\n-    Examples\n-    ========\n-    >>> from sympy import total_degree, Poly\n-    >>> from sympy.abc import x, y\n-\n-    >>> total_degree(1)\n-    0\n-    >>> total_degree(x + x*y)\n-    2\n-    >>> total_degree(x + x*y, x)\n-    1\n-\n-    If the expression is a Poly and no variables are given\n-    then the generators of the Poly will be used:\n-\n-    >>> p = Poly(x + x*y, y)\n-    >>> total_degree(p)\n-    1\n-\n-    To deal with the underlying expression of the Poly, convert\n-    it to an Expr:\n-\n-    >>> total_degree(p.as_expr())\n-    2\n-\n-    This is done automatically if any variables are given:\n-\n-    >>> total_degree(p, x)\n-    1\n-\n-    See also\n-    ========\n-    degree\n-    \"\"\"\n-\n-    p = sympify(f)\n-    if p.is_Poly:\n-        p = p.as_expr()\n-    if p.is_Number:\n-        rv = 0\n-    else:\n-        if f.is_Poly:\n-            gens = gens or f.gens\n-        rv = Poly(p, gens).total_degree()\n-\n-    return Integer(rv)\n-\n-\n-@public\n-def degree_list(f, *gens, **args):\n-    \"\"\"\n-    Return a list of degrees of ``f`` in all variables.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import degree_list\n-    >>> from sympy.abc import x, y\n-\n-    >>> degree_list(x**2 + y*x + 1)\n-    (2, 1)\n-\n-    \"\"\"\n-    options.allowed_flags(args, ['polys'])\n-\n-    try:\n-        F, opt = poly_from_expr(f, *gens, **args)\n-    except PolificationFailed as exc:\n-        raise ComputationFailed('degree_list', 1, exc)\n-\n-    degrees = F.degree_list()\n-\n-    return tuple(map(Integer, degrees))\n-\n-\n-@public\n-def LC(f, *gens, **args):\n-    \"\"\"\n-    Return the leading coefficient of ``f``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import LC\n-    >>> from sympy.abc import x, y\n-\n-    >>> LC(4*x**2 + 2*x*y**2 + x*y + 3*y)\n-    4\n-\n-    \"\"\"\n-    options.allowed_flags(args, ['polys'])\n-\n-    try:\n-        F, opt = poly_from_expr(f, *gens, **args)\n-    except PolificationFailed as exc:\n-        raise ComputationFailed('LC', 1, exc)\n-\n-    return F.LC(order=opt.order)\n-\n-\n-@public\n-def LM(f, *gens, **args):\n-    \"\"\"\n-    Return the leading monomial of ``f``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import LM\n-    >>> from sympy.abc import x, y\n-\n-    >>> LM(4*x**2 + 2*x*y**2 + x*y + 3*y)\n-    x**2\n-\n-    \"\"\"\n-    options.allowed_flags(args, ['polys'])\n-\n-    try:\n-        F, opt = poly_from_expr(f, *gens, **args)\n-    except PolificationFailed as exc:\n-        raise ComputationFailed('LM', 1, exc)\n-\n-    monom = F.LM(order=opt.order)\n-    return monom.as_expr()\n-\n-\n-@public\n-def LT(f, *gens, **args):\n-    \"\"\"\n-    Return the leading term of ``f``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import LT\n-    >>> from sympy.abc import x, y\n-\n-    >>> LT(4*x**2 + 2*x*y**2 + x*y + 3*y)\n-    4*x**2\n-\n-    \"\"\"\n-    options.allowed_flags(args, ['polys'])\n-\n-    try:\n-        F, opt = poly_from_expr(f, *gens, **args)\n-    except PolificationFailed as exc:\n-        raise ComputationFailed('LT', 1, exc)\n-\n-    monom, coeff = F.LT(order=opt.order)\n-    return coeff*monom.as_expr()\n-\n-\n-@public\n-def pdiv(f, g, *gens, **args):\n-    \"\"\"\n-    Compute polynomial pseudo-division of ``f`` and ``g``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import pdiv\n-    >>> from sympy.abc import x\n-\n-    >>> pdiv(x**2 + 1, 2*x - 4)\n-    (2*x + 4, 20)\n-\n-    \"\"\"\n-    options.allowed_flags(args, ['polys'])\n-\n-    try:\n-        (F, G), opt = parallel_poly_from_expr((f, g), *gens, **args)\n-    except PolificationFailed as exc:\n-        raise ComputationFailed('pdiv', 2, exc)\n-\n-    q, r = F.pdiv(G)\n-\n-    if not opt.polys:\n-        return q.as_expr(), r.as_expr()\n-    else:\n-        return q, r\n-\n-\n-@public\n-def prem(f, g, *gens, **args):\n-    \"\"\"\n-    Compute polynomial pseudo-remainder of ``f`` and ``g``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import prem\n-    >>> from sympy.abc import x\n-\n-    >>> prem(x**2 + 1, 2*x - 4)\n-    20\n-\n-    \"\"\"\n-    options.allowed_flags(args, ['polys'])\n-\n-    try:\n-        (F, G), opt = parallel_poly_from_expr((f, g), *gens, **args)\n-    except PolificationFailed as exc:\n-        raise ComputationFailed('prem', 2, exc)\n-\n-    r = F.prem(G)\n-\n-    if not opt.polys:\n-        return r.as_expr()\n-    else:\n-        return r\n-\n-\n-@public\n-def pquo(f, g, *gens, **args):\n-    \"\"\"\n-    Compute polynomial pseudo-quotient of ``f`` and ``g``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import pquo\n-    >>> from sympy.abc import x\n-\n-    >>> pquo(x**2 + 1, 2*x - 4)\n-    2*x + 4\n-    >>> pquo(x**2 - 1, 2*x - 1)\n-    2*x + 1\n-\n-    \"\"\"\n-    options.allowed_flags(args, ['polys'])\n-\n-    try:\n-        (F, G), opt = parallel_poly_from_expr((f, g), *gens, **args)\n-    except PolificationFailed as exc:\n-        raise ComputationFailed('pquo', 2, exc)\n-\n-    try:\n-        q = F.pquo(G)\n-    except ExactQuotientFailed:\n-        raise ExactQuotientFailed(f, g)\n-\n-    if not opt.polys:\n-        return q.as_expr()\n-    else:\n-        return q\n-\n-\n-@public\n-def pexquo(f, g, *gens, **args):\n-    \"\"\"\n-    Compute polynomial exact pseudo-quotient of ``f`` and ``g``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import pexquo\n-    >>> from sympy.abc import x\n-\n-    >>> pexquo(x**2 - 1, 2*x - 2)\n-    2*x + 2\n-\n-    >>> pexquo(x**2 + 1, 2*x - 4)\n-    Traceback (most recent call last):\n-    ...\n-    ExactQuotientFailed: 2*x - 4 does not divide x**2 + 1\n-\n-    \"\"\"\n-    options.allowed_flags(args, ['polys'])\n-\n-    try:\n-        (F, G), opt = parallel_poly_from_expr((f, g), *gens, **args)\n-    except PolificationFailed as exc:\n-        raise ComputationFailed('pexquo', 2, exc)\n-\n-    q = F.pexquo(G)\n-\n-    if not opt.polys:\n-        return q.as_expr()\n-    else:\n-        return q\n-\n-\n-@public\n-def div(f, g, *gens, **args):\n-    \"\"\"\n-    Compute polynomial division of ``f`` and ``g``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import div, ZZ, QQ\n-    >>> from sympy.abc import x\n-\n-    >>> div(x**2 + 1, 2*x - 4, domain=ZZ)\n-    (0, x**2 + 1)\n-    >>> div(x**2 + 1, 2*x - 4, domain=QQ)\n-    (x/2 + 1, 5)\n-\n-    \"\"\"\n-    options.allowed_flags(args, ['auto', 'polys'])\n-\n-    try:\n-        (F, G), opt = parallel_poly_from_expr((f, g), *gens, **args)\n-    except PolificationFailed as exc:\n-        raise ComputationFailed('div', 2, exc)\n-\n-    q, r = F.div(G, auto=opt.auto)\n-\n-    if not opt.polys:\n-        return q.as_expr(), r.as_expr()\n-    else:\n-        return q, r\n-\n-\n-@public\n-def rem(f, g, *gens, **args):\n-    \"\"\"\n-    Compute polynomial remainder of ``f`` and ``g``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import rem, ZZ, QQ\n-    >>> from sympy.abc import x\n-\n-    >>> rem(x**2 + 1, 2*x - 4, domain=ZZ)\n-    x**2 + 1\n-    >>> rem(x**2 + 1, 2*x - 4, domain=QQ)\n-    5\n-\n-    \"\"\"\n-    options.allowed_flags(args, ['auto', 'polys'])\n-\n-    try:\n-        (F, G), opt = parallel_poly_from_expr((f, g), *gens, **args)\n-    except PolificationFailed as exc:\n-        raise ComputationFailed('rem', 2, exc)\n-\n-    r = F.rem(G, auto=opt.auto)\n-\n-    if not opt.polys:\n-        return r.as_expr()\n-    else:\n-        return r\n-\n-\n-@public\n-def quo(f, g, *gens, **args):\n-    \"\"\"\n-    Compute polynomial quotient of ``f`` and ``g``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import quo\n-    >>> from sympy.abc import x\n-\n-    >>> quo(x**2 + 1, 2*x - 4)\n-    x/2 + 1\n-    >>> quo(x**2 - 1, x - 1)\n-    x + 1\n-\n-    \"\"\"\n-    options.allowed_flags(args, ['auto', 'polys'])\n-\n-    try:\n-        (F, G), opt = parallel_poly_from_expr((f, g), *gens, **args)\n-    except PolificationFailed as exc:\n-        raise ComputationFailed('quo', 2, exc)\n-\n-    q = F.quo(G, auto=opt.auto)\n-\n-    if not opt.polys:\n-        return q.as_expr()\n-    else:\n-        return q\n-\n-\n-@public\n-def exquo(f, g, *gens, **args):\n-    \"\"\"\n-    Compute polynomial exact quotient of ``f`` and ``g``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import exquo\n-    >>> from sympy.abc import x\n-\n-    >>> exquo(x**2 - 1, x - 1)\n-    x + 1\n-\n-    >>> exquo(x**2 + 1, 2*x - 4)\n-    Traceback (most recent call last):\n-    ...\n-    ExactQuotientFailed: 2*x - 4 does not divide x**2 + 1\n-\n-    \"\"\"\n-    options.allowed_flags(args, ['auto', 'polys'])\n-\n-    try:\n-        (F, G), opt = parallel_poly_from_expr((f, g), *gens, **args)\n-    except PolificationFailed as exc:\n-        raise ComputationFailed('exquo', 2, exc)\n-\n-    q = F.exquo(G, auto=opt.auto)\n-\n-    if not opt.polys:\n-        return q.as_expr()\n-    else:\n-        return q\n-\n-\n-@public\n-def half_gcdex(f, g, *gens, **args):\n-    \"\"\"\n-    Half extended Euclidean algorithm of ``f`` and ``g``.\n-\n-    Returns ``(s, h)`` such that ``h = gcd(f, g)`` and ``s*f = h (mod g)``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import half_gcdex\n-    >>> from sympy.abc import x\n-\n-    >>> half_gcdex(x**4 - 2*x**3 - 6*x**2 + 12*x + 15, x**3 + x**2 - 4*x - 4)\n-    (3/5 - x/5, x + 1)\n-\n-    \"\"\"\n-    options.allowed_flags(args, ['auto', 'polys'])\n-\n-    try:\n-        (F, G), opt = parallel_poly_from_expr((f, g), *gens, **args)\n-    except PolificationFailed as exc:\n-        domain, (a, b) = construct_domain(exc.exprs)\n-\n-        try:\n-            s, h = domain.half_gcdex(a, b)\n-        except NotImplementedError:\n-            raise ComputationFailed('half_gcdex', 2, exc)\n-        else:\n-            return domain.to_sympy(s), domain.to_sympy(h)\n-\n-    s, h = F.half_gcdex(G, auto=opt.auto)\n-\n-    if not opt.polys:\n-        return s.as_expr(), h.as_expr()\n-    else:\n-        return s, h\n-\n-\n-@public\n-def gcdex(f, g, *gens, **args):\n-    \"\"\"\n-    Extended Euclidean algorithm of ``f`` and ``g``.\n-\n-    Returns ``(s, t, h)`` such that ``h = gcd(f, g)`` and ``s*f + t*g = h``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import gcdex\n-    >>> from sympy.abc import x\n-\n-    >>> gcdex(x**4 - 2*x**3 - 6*x**2 + 12*x + 15, x**3 + x**2 - 4*x - 4)\n-    (3/5 - x/5, x**2/5 - 6*x/5 + 2, x + 1)\n-\n-    \"\"\"\n-    options.allowed_flags(args, ['auto', 'polys'])\n-\n-    try:\n-        (F, G), opt = parallel_poly_from_expr((f, g), *gens, **args)\n-    except PolificationFailed as exc:\n-        domain, (a, b) = construct_domain(exc.exprs)\n-\n-        try:\n-            s, t, h = domain.gcdex(a, b)\n-        except NotImplementedError:\n-            raise ComputationFailed('gcdex', 2, exc)\n-        else:\n-            return domain.to_sympy(s), domain.to_sympy(t), domain.to_sympy(h)\n-\n-    s, t, h = F.gcdex(G, auto=opt.auto)\n-\n-    if not opt.polys:\n-        return s.as_expr(), t.as_expr(), h.as_expr()\n-    else:\n-        return s, t, h\n-\n-\n-@public\n-def invert(f, g, *gens, **args):\n-    \"\"\"\n-    Invert ``f`` modulo ``g`` when possible.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import invert, S\n-    >>> from sympy.core.numbers import mod_inverse\n-    >>> from sympy.abc import x\n-\n-    >>> invert(x**2 - 1, 2*x - 1)\n-    -4/3\n-\n-    >>> invert(x**2 - 1, x - 1)\n-    Traceback (most recent call last):\n-    ...\n-    NotInvertible: zero divisor\n-\n-    For more efficient inversion of Rationals,\n-    use the :obj:`~.mod_inverse` function:\n-\n-    >>> mod_inverse(3, 5)\n-    2\n-    >>> (S(2)/5).invert(S(7)/3)\n-    5/2\n-\n-    See Also\n-    ========\n-\n-    sympy.core.numbers.mod_inverse\n-\n-    \"\"\"\n-    options.allowed_flags(args, ['auto', 'polys'])\n-\n-    try:\n-        (F, G), opt = parallel_poly_from_expr((f, g), *gens, **args)\n-    except PolificationFailed as exc:\n-        domain, (a, b) = construct_domain(exc.exprs)\n-\n-        try:\n-            return domain.to_sympy(domain.invert(a, b))\n-        except NotImplementedError:\n-            raise ComputationFailed('invert', 2, exc)\n-\n-    h = F.invert(G, auto=opt.auto)\n-\n-    if not opt.polys:\n-        return h.as_expr()\n-    else:\n-        return h\n-\n-\n-@public\n-def subresultants(f, g, *gens, **args):\n-    \"\"\"\n-    Compute subresultant PRS of ``f`` and ``g``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import subresultants\n-    >>> from sympy.abc import x\n-\n-    >>> subresultants(x**2 + 1, x**2 - 1)\n-    [x**2 + 1, x**2 - 1, -2]\n-\n-    \"\"\"\n-    options.allowed_flags(args, ['polys'])\n-\n-    try:\n-        (F, G), opt = parallel_poly_from_expr((f, g), *gens, **args)\n-    except PolificationFailed as exc:\n-        raise ComputationFailed('subresultants', 2, exc)\n-\n-    result = F.subresultants(G)\n-\n-    if not opt.polys:\n-        return [r.as_expr() for r in result]\n-    else:\n-        return result\n-\n-\n-@public\n-def resultant(f, g, *gens, includePRS=False, **args):\n-    \"\"\"\n-    Compute resultant of ``f`` and ``g``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import resultant\n-    >>> from sympy.abc import x\n-\n-    >>> resultant(x**2 + 1, x**2 - 1)\n-    4\n-\n-    \"\"\"\n-    options.allowed_flags(args, ['polys'])\n-\n-    try:\n-        (F, G), opt = parallel_poly_from_expr((f, g), *gens, **args)\n-    except PolificationFailed as exc:\n-        raise ComputationFailed('resultant', 2, exc)\n-\n-    if includePRS:\n-        result, R = F.resultant(G, includePRS=includePRS)\n-    else:\n-        result = F.resultant(G)\n-\n-    if not opt.polys:\n-        if includePRS:\n-            return result.as_expr(), [r.as_expr() for r in R]\n-        return result.as_expr()\n-    else:\n-        if includePRS:\n-            return result, R\n-        return result\n-\n-\n-@public\n-def discriminant(f, *gens, **args):\n-    \"\"\"\n-    Compute discriminant of ``f``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import discriminant\n-    >>> from sympy.abc import x\n-\n-    >>> discriminant(x**2 + 2*x + 3)\n-    -8\n-\n-    \"\"\"\n-    options.allowed_flags(args, ['polys'])\n-\n-    try:\n-        F, opt = poly_from_expr(f, *gens, **args)\n-    except PolificationFailed as exc:\n-        raise ComputationFailed('discriminant', 1, exc)\n-\n-    result = F.discriminant()\n-\n-    if not opt.polys:\n-        return result.as_expr()\n-    else:\n-        return result\n-\n-\n-@public\n-def cofactors(f, g, *gens, **args):\n-    \"\"\"\n-    Compute GCD and cofactors of ``f`` and ``g``.\n-\n-    Returns polynomials ``(h, cff, cfg)`` such that ``h = gcd(f, g)``, and\n-    ``cff = quo(f, h)`` and ``cfg = quo(g, h)`` are, so called, cofactors\n-    of ``f`` and ``g``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import cofactors\n-    >>> from sympy.abc import x\n-\n-    >>> cofactors(x**2 - 1, x**2 - 3*x + 2)\n-    (x - 1, x + 1, x - 2)\n-\n-    \"\"\"\n-    options.allowed_flags(args, ['polys'])\n-\n-    try:\n-        (F, G), opt = parallel_poly_from_expr((f, g), *gens, **args)\n-    except PolificationFailed as exc:\n-        domain, (a, b) = construct_domain(exc.exprs)\n-\n-        try:\n-            h, cff, cfg = domain.cofactors(a, b)\n-        except NotImplementedError:\n-            raise ComputationFailed('cofactors', 2, exc)\n-        else:\n-            return domain.to_sympy(h), domain.to_sympy(cff), domain.to_sympy(cfg)\n-\n-    h, cff, cfg = F.cofactors(G)\n-\n-    if not opt.polys:\n-        return h.as_expr(), cff.as_expr(), cfg.as_expr()\n-    else:\n-        return h, cff, cfg\n-\n-\n-@public\n-def gcd_list(seq, *gens, **args):\n-    \"\"\"\n-    Compute GCD of a list of polynomials.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import gcd_list\n-    >>> from sympy.abc import x\n-\n-    >>> gcd_list([x**3 - 1, x**2 - 1, x**2 - 3*x + 2])\n-    x - 1\n-\n-    \"\"\"\n-    seq = sympify(seq)\n-\n-    def try_non_polynomial_gcd(seq):\n-        if not gens and not args:\n-            domain, numbers = construct_domain(seq)\n-\n-            if not numbers:\n-                return domain.zero\n-            elif domain.is_Numerical:\n-                result, numbers = numbers[0], numbers[1:]\n-\n-                for number in numbers:\n-                    result = domain.gcd(result, number)\n-\n-                    if domain.is_one(result):\n-                        break\n-\n-                return domain.to_sympy(result)\n-\n-        return None\n-\n-    result = try_non_polynomial_gcd(seq)\n-\n-    if result is not None:\n-        return result\n-\n-    options.allowed_flags(args, ['polys'])\n-\n-    try:\n-        polys, opt = parallel_poly_from_expr(seq, *gens, **args)\n-\n-        # gcd for domain Q[irrational] (purely algebraic irrational)\n-        if len(seq) > 1 and all(elt.is_algebraic and elt.is_irrational for elt in seq):\n-            a = seq[-1]\n-            lst = [ (a/elt).ratsimp() for elt in seq[:-1] ]\n-            if all(frc.is_rational for frc in lst):\n-                lc = 1\n-                for frc in lst:\n-                    lc = lcm(lc, frc.as_numer_denom()[0])\n-                # abs ensures that the gcd is always non-negative\n-                return abs(a/lc)\n-\n-    except PolificationFailed as exc:\n-        result = try_non_polynomial_gcd(exc.exprs)\n-\n-        if result is not None:\n-            return result\n-        else:\n-            raise ComputationFailed('gcd_list', len(seq), exc)\n-\n-    if not polys:\n-        if not opt.polys:\n-            return S.Zero\n-        else:\n-            return Poly(0, opt=opt)\n-\n-    result, polys = polys[0], polys[1:]\n-\n-    for poly in polys:\n-        result = result.gcd(poly)\n-\n-        if result.is_one:\n-            break\n-\n-    if not opt.polys:\n-        return result.as_expr()\n-    else:\n-        return result\n-\n-\n-@public\n-def gcd(f, g=None, *gens, **args):\n-    \"\"\"\n-    Compute GCD of ``f`` and ``g``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import gcd\n-    >>> from sympy.abc import x\n-\n-    >>> gcd(x**2 - 1, x**2 - 3*x + 2)\n-    x - 1\n-\n-    \"\"\"\n-    if hasattr(f, '__iter__'):\n-        if g is not None:\n-            gens = (g,) + gens\n-\n-        return gcd_list(f, *gens, **args)\n-    elif g is None:\n-        raise TypeError(\"gcd() takes 2 arguments or a sequence of arguments\")\n-\n-    options.allowed_flags(args, ['polys'])\n-\n-    try:\n-        (F, G), opt = parallel_poly_from_expr((f, g), *gens, **args)\n-\n-        # gcd for domain Q[irrational] (purely algebraic irrational)\n-        a, b = map(sympify, (f, g))\n-        if a.is_algebraic and a.is_irrational and b.is_algebraic and b.is_irrational:\n-            frc = (a/b).ratsimp()\n-            if frc.is_rational:\n-                # abs ensures that the returned gcd is always non-negative\n-                return abs(a/frc.as_numer_denom()[0])\n-\n-    except PolificationFailed as exc:\n-        domain, (a, b) = construct_domain(exc.exprs)\n-\n-        try:\n-            return domain.to_sympy(domain.gcd(a, b))\n-        except NotImplementedError:\n-            raise ComputationFailed('gcd', 2, exc)\n-\n-    result = F.gcd(G)\n-\n-    if not opt.polys:\n-        return result.as_expr()\n-    else:\n-        return result\n-\n-\n-@public\n-def lcm_list(seq, *gens, **args):\n-    \"\"\"\n-    Compute LCM of a list of polynomials.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import lcm_list\n-    >>> from sympy.abc import x\n-\n-    >>> lcm_list([x**3 - 1, x**2 - 1, x**2 - 3*x + 2])\n-    x**5 - x**4 - 2*x**3 - x**2 + x + 2\n-\n-    \"\"\"\n-    seq = sympify(seq)\n-\n-    def try_non_polynomial_lcm(seq):\n-        if not gens and not args:\n-            domain, numbers = construct_domain(seq)\n-\n-            if not numbers:\n-                return domain.one\n-            elif domain.is_Numerical:\n-                result, numbers = numbers[0], numbers[1:]\n-\n-                for number in numbers:\n-                    result = domain.lcm(result, number)\n-\n-                return domain.to_sympy(result)\n-\n-        return None\n-\n-    result = try_non_polynomial_lcm(seq)\n-\n-    if result is not None:\n-        return result\n-\n-    options.allowed_flags(args, ['polys'])\n-\n-    try:\n-        polys, opt = parallel_poly_from_expr(seq, *gens, **args)\n-\n-        # lcm for domain Q[irrational] (purely algebraic irrational)\n-        if len(seq) > 1 and all(elt.is_algebraic and elt.is_irrational for elt in seq):\n-            a = seq[-1]\n-            lst = [ (a/elt).ratsimp() for elt in seq[:-1] ]\n-            if all(frc.is_rational for frc in lst):\n-                lc = 1\n-                for frc in lst:\n-                    lc = lcm(lc, frc.as_numer_denom()[1])\n-                return a*lc\n-\n-    except PolificationFailed as exc:\n-        result = try_non_polynomial_lcm(exc.exprs)\n-\n-        if result is not None:\n-            return result\n-        else:\n-            raise ComputationFailed('lcm_list', len(seq), exc)\n-\n-    if not polys:\n-        if not opt.polys:\n-            return S.One\n-        else:\n-            return Poly(1, opt=opt)\n-\n-    result, polys = polys[0], polys[1:]\n-\n-    for poly in polys:\n-        result = result.lcm(poly)\n-\n-    if not opt.polys:\n-        return result.as_expr()\n-    else:\n-        return result\n-\n-\n-@public\n-def lcm(f, g=None, *gens, **args):\n-    \"\"\"\n-    Compute LCM of ``f`` and ``g``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import lcm\n-    >>> from sympy.abc import x\n-\n-    >>> lcm(x**2 - 1, x**2 - 3*x + 2)\n-    x**3 - 2*x**2 - x + 2\n-\n-    \"\"\"\n-    if hasattr(f, '__iter__'):\n-        if g is not None:\n-            gens = (g,) + gens\n-\n-        return lcm_list(f, *gens, **args)\n-    elif g is None:\n-        raise TypeError(\"lcm() takes 2 arguments or a sequence of arguments\")\n-\n-    options.allowed_flags(args, ['polys'])\n-\n-    try:\n-        (F, G), opt = parallel_poly_from_expr((f, g), *gens, **args)\n-\n-        # lcm for domain Q[irrational] (purely algebraic irrational)\n-        a, b = map(sympify, (f, g))\n-        if a.is_algebraic and a.is_irrational and b.is_algebraic and b.is_irrational:\n-            frc = (a/b).ratsimp()\n-            if frc.is_rational:\n-                return a*frc.as_numer_denom()[1]\n-\n-    except PolificationFailed as exc:\n-        domain, (a, b) = construct_domain(exc.exprs)\n-\n-        try:\n-            return domain.to_sympy(domain.lcm(a, b))\n-        except NotImplementedError:\n-            raise ComputationFailed('lcm', 2, exc)\n-\n-    result = F.lcm(G)\n-\n-    if not opt.polys:\n-        return result.as_expr()\n-    else:\n-        return result\n-\n-\n-@public\n-def terms_gcd(f, *gens, **args):\n-    \"\"\"\n-    Remove GCD of terms from ``f``.\n-\n-    If the ``deep`` flag is True, then the arguments of ``f`` will have\n-    terms_gcd applied to them.\n-\n-    If a fraction is factored out of ``f`` and ``f`` is an Add, then\n-    an unevaluated Mul will be returned so that automatic simplification\n-    does not redistribute it. The hint ``clear``, when set to False, can be\n-    used to prevent such factoring when all coefficients are not fractions.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import terms_gcd, cos\n-    >>> from sympy.abc import x, y\n-    >>> terms_gcd(x**6*y**2 + x**3*y, x, y)\n-    x**3*y*(x**3*y + 1)\n-\n-    The default action of polys routines is to expand the expression\n-    given to them. terms_gcd follows this behavior:\n-\n-    >>> terms_gcd((3+3*x)*(x+x*y))\n-    3*x*(x*y + x + y + 1)\n-\n-    If this is not desired then the hint ``expand`` can be set to False.\n-    In this case the expression will be treated as though it were comprised\n-    of one or more terms:\n-\n-    >>> terms_gcd((3+3*x)*(x+x*y), expand=False)\n-    (3*x + 3)*(x*y + x)\n-\n-    In order to traverse factors of a Mul or the arguments of other\n-    functions, the ``deep`` hint can be used:\n-\n-    >>> terms_gcd((3 + 3*x)*(x + x*y), expand=False, deep=True)\n-    3*x*(x + 1)*(y + 1)\n-    >>> terms_gcd(cos(x + x*y), deep=True)\n-    cos(x*(y + 1))\n-\n-    Rationals are factored out by default:\n-\n-    >>> terms_gcd(x + y/2)\n-    (2*x + y)/2\n-\n-    Only the y-term had a coefficient that was a fraction; if one\n-    does not want to factor out the 1/2 in cases like this, the\n-    flag ``clear`` can be set to False:\n-\n-    >>> terms_gcd(x + y/2, clear=False)\n-    x + y/2\n-    >>> terms_gcd(x*y/2 + y**2, clear=False)\n-    y*(x/2 + y)\n-\n-    The ``clear`` flag is ignored if all coefficients are fractions:\n-\n-    >>> terms_gcd(x/3 + y/2, clear=False)\n-    (2*x + 3*y)/6\n-\n-    See Also\n-    ========\n-    sympy.core.exprtools.gcd_terms, sympy.core.exprtools.factor_terms\n-\n-    \"\"\"\n-    from sympy.core.relational import Equality\n-\n-    orig = sympify(f)\n-\n-    if isinstance(f, Equality):\n-        return Equality(*(terms_gcd(s, *gens, **args) for s in [f.lhs, f.rhs]))\n-    elif isinstance(f, Relational):\n-        raise TypeError(\"Inequalities can not be used with terms_gcd. Found: %s\" %(f,))\n-\n-    if not isinstance(f, Expr) or f.is_Atom:\n-        return orig\n-\n-    if args.get('deep', False):\n-        new = f.func(*[terms_gcd(a, *gens, **args) for a in f.args])\n-        args.pop('deep')\n-        args['expand'] = False\n-        return terms_gcd(new, *gens, **args)\n-\n-    clear = args.pop('clear', True)\n-    options.allowed_flags(args, ['polys'])\n-\n-    try:\n-        F, opt = poly_from_expr(f, *gens, **args)\n-    except PolificationFailed as exc:\n-        return exc.expr\n-\n-    J, f = F.terms_gcd()\n-\n-    if opt.domain.is_Ring:\n-        if opt.domain.is_Field:\n-            denom, f = f.clear_denoms(convert=True)\n-\n-        coeff, f = f.primitive()\n-\n-        if opt.domain.is_Field:\n-            coeff /= denom\n-    else:\n-        coeff = S.One\n-\n-    term = Mul(*[x**j for x, j in zip(f.gens, J)])\n-    if coeff == 1:\n-        coeff = S.One\n-        if term == 1:\n-            return orig\n-\n-    if clear:\n-        return _keep_coeff(coeff, term*f.as_expr())\n-    # base the clearing on the form of the original expression, not\n-    # the (perhaps) Mul that we have now\n-    coeff, f = _keep_coeff(coeff, f.as_expr(), clear=False).as_coeff_Mul()\n-    return _keep_coeff(coeff, term*f, clear=False)\n-\n-\n-@public\n-def trunc(f, p, *gens, **args):\n-    \"\"\"\n-    Reduce ``f`` modulo a constant ``p``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import trunc\n-    >>> from sympy.abc import x\n-\n-    >>> trunc(2*x**3 + 3*x**2 + 5*x + 7, 3)\n-    -x**3 - x + 1\n-\n-    \"\"\"\n-    options.allowed_flags(args, ['auto', 'polys'])\n-\n-    try:\n-        F, opt = poly_from_expr(f, *gens, **args)\n-    except PolificationFailed as exc:\n-        raise ComputationFailed('trunc', 1, exc)\n-\n-    result = F.trunc(sympify(p))\n-\n-    if not opt.polys:\n-        return result.as_expr()\n-    else:\n-        return result\n-\n-\n-@public\n-def monic(f, *gens, **args):\n-    \"\"\"\n-    Divide all coefficients of ``f`` by ``LC(f)``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import monic\n-    >>> from sympy.abc import x\n-\n-    >>> monic(3*x**2 + 4*x + 2)\n-    x**2 + 4*x/3 + 2/3\n-\n-    \"\"\"\n-    options.allowed_flags(args, ['auto', 'polys'])\n-\n-    try:\n-        F, opt = poly_from_expr(f, *gens, **args)\n-    except PolificationFailed as exc:\n-        raise ComputationFailed('monic', 1, exc)\n-\n-    result = F.monic(auto=opt.auto)\n-\n-    if not opt.polys:\n-        return result.as_expr()\n-    else:\n-        return result\n-\n-\n-@public\n-def content(f, *gens, **args):\n-    \"\"\"\n-    Compute GCD of coefficients of ``f``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import content\n-    >>> from sympy.abc import x\n-\n-    >>> content(6*x**2 + 8*x + 12)\n-    2\n-\n-    \"\"\"\n-    options.allowed_flags(args, ['polys'])\n-\n-    try:\n-        F, opt = poly_from_expr(f, *gens, **args)\n-    except PolificationFailed as exc:\n-        raise ComputationFailed('content', 1, exc)\n-\n-    return F.content()\n-\n-\n-@public\n-def primitive(f, *gens, **args):\n-    \"\"\"\n-    Compute content and the primitive form of ``f``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy.polys.polytools import primitive\n-    >>> from sympy.abc import x\n-\n-    >>> primitive(6*x**2 + 8*x + 12)\n-    (2, 3*x**2 + 4*x + 6)\n-\n-    >>> eq = (2 + 2*x)*x + 2\n-\n-    Expansion is performed by default:\n-\n-    >>> primitive(eq)\n-    (2, x**2 + x + 1)\n-\n-    Set ``expand`` to False to shut this off. Note that the\n-    extraction will not be recursive; use the as_content_primitive method\n-    for recursive, non-destructive Rational extraction.\n-\n-    >>> primitive(eq, expand=False)\n-    (1, x*(2*x + 2) + 2)\n-\n-    >>> eq.as_content_primitive()\n-    (2, x*(x + 1) + 1)\n-\n-    \"\"\"\n-    options.allowed_flags(args, ['polys'])\n-\n-    try:\n-        F, opt = poly_from_expr(f, *gens, **args)\n-    except PolificationFailed as exc:\n-        raise ComputationFailed('primitive', 1, exc)\n-\n-    cont, result = F.primitive()\n-    if not opt.polys:\n-        return cont, result.as_expr()\n-    else:\n-        return cont, result\n-\n-\n-@public\n-def compose(f, g, *gens, **args):\n-    \"\"\"\n-    Compute functional composition ``f(g)``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import compose\n-    >>> from sympy.abc import x\n-\n-    >>> compose(x**2 + x, x - 1)\n-    x**2 - x\n-\n-    \"\"\"\n-    options.allowed_flags(args, ['polys'])\n-\n-    try:\n-        (F, G), opt = parallel_poly_from_expr((f, g), *gens, **args)\n-    except PolificationFailed as exc:\n-        raise ComputationFailed('compose', 2, exc)\n-\n-    result = F.compose(G)\n-\n-    if not opt.polys:\n-        return result.as_expr()\n-    else:\n-        return result\n-\n-\n-@public\n-def decompose(f, *gens, **args):\n-    \"\"\"\n-    Compute functional decomposition of ``f``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import decompose\n-    >>> from sympy.abc import x\n-\n-    >>> decompose(x**4 + 2*x**3 - x - 1)\n-    [x**2 - x - 1, x**2 + x]\n-\n-    \"\"\"\n-    options.allowed_flags(args, ['polys'])\n-\n-    try:\n-        F, opt = poly_from_expr(f, *gens, **args)\n-    except PolificationFailed as exc:\n-        raise ComputationFailed('decompose', 1, exc)\n-\n-    result = F.decompose()\n-\n-    if not opt.polys:\n-        return [r.as_expr() for r in result]\n-    else:\n-        return result\n-\n-\n-@public\n-def sturm(f, *gens, **args):\n-    \"\"\"\n-    Compute Sturm sequence of ``f``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import sturm\n-    >>> from sympy.abc import x\n-\n-    >>> sturm(x**3 - 2*x**2 + x - 3)\n-    [x**3 - 2*x**2 + x - 3, 3*x**2 - 4*x + 1, 2*x/9 + 25/9, -2079/4]\n-\n-    \"\"\"\n-    options.allowed_flags(args, ['auto', 'polys'])\n-\n-    try:\n-        F, opt = poly_from_expr(f, *gens, **args)\n-    except PolificationFailed as exc:\n-        raise ComputationFailed('sturm', 1, exc)\n-\n-    result = F.sturm(auto=opt.auto)\n-\n-    if not opt.polys:\n-        return [r.as_expr() for r in result]\n-    else:\n-        return result\n-\n-\n-@public\n-def gff_list(f, *gens, **args):\n-    \"\"\"\n-    Compute a list of greatest factorial factors of ``f``.\n-\n-    Note that the input to ff() and rf() should be Poly instances to use the\n-    definitions here.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import gff_list, ff, Poly\n-    >>> from sympy.abc import x\n-\n-    >>> f = Poly(x**5 + 2*x**4 - x**3 - 2*x**2, x)\n-\n-    >>> gff_list(f)\n-    [(Poly(x, x, domain='ZZ'), 1), (Poly(x + 2, x, domain='ZZ'), 4)]\n-\n-    >>> (ff(Poly(x), 1)*ff(Poly(x + 2), 4)) == f\n-    True\n-\n-    >>> f = Poly(x**12 + 6*x**11 - 11*x**10 - 56*x**9 + 220*x**8 + 208*x**7 - \\\n-        1401*x**6 + 1090*x**5 + 2715*x**4 - 6720*x**3 - 1092*x**2 + 5040*x, x)\n-\n-    >>> gff_list(f)\n-    [(Poly(x**3 + 7, x, domain='ZZ'), 2), (Poly(x**2 + 5*x, x, domain='ZZ'), 3)]\n-\n-    >>> ff(Poly(x**3 + 7, x), 2)*ff(Poly(x**2 + 5*x, x), 3) == f\n-    True\n-\n-    \"\"\"\n-    options.allowed_flags(args, ['polys'])\n-\n-    try:\n-        F, opt = poly_from_expr(f, *gens, **args)\n-    except PolificationFailed as exc:\n-        raise ComputationFailed('gff_list', 1, exc)\n-\n-    factors = F.gff_list()\n-\n-    if not opt.polys:\n-        return [(g.as_expr(), k) for g, k in factors]\n-    else:\n-        return factors\n-\n-\n-@public\n-def gff(f, *gens, **args):\n-    \"\"\"Compute greatest factorial factorization of ``f``. \"\"\"\n-    raise NotImplementedError('symbolic falling factorial')\n-\n-\n-@public\n-def sqf_norm(f, *gens, **args):\n-    \"\"\"\n-    Compute square-free norm of ``f``.\n-\n-    Returns ``s``, ``f``, ``r``, such that ``g(x) = f(x-sa)`` and\n-    ``r(x) = Norm(g(x))`` is a square-free polynomial over ``K``,\n-    where ``a`` is the algebraic extension of the ground domain.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import sqf_norm, sqrt\n-    >>> from sympy.abc import x\n-\n-    >>> sqf_norm(x**2 + 1, extension=[sqrt(3)])\n-    (1, x**2 - 2*sqrt(3)*x + 4, x**4 - 4*x**2 + 16)\n-\n-    \"\"\"\n-    options.allowed_flags(args, ['polys'])\n-\n-    try:\n-        F, opt = poly_from_expr(f, *gens, **args)\n-    except PolificationFailed as exc:\n-        raise ComputationFailed('sqf_norm', 1, exc)\n-\n-    s, g, r = F.sqf_norm()\n-\n-    if not opt.polys:\n-        return Integer(s), g.as_expr(), r.as_expr()\n-    else:\n-        return Integer(s), g, r\n-\n-\n-@public\n-def sqf_part(f, *gens, **args):\n-    \"\"\"\n-    Compute square-free part of ``f``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import sqf_part\n-    >>> from sympy.abc import x\n-\n-    >>> sqf_part(x**3 - 3*x - 2)\n-    x**2 - x - 2\n-\n-    \"\"\"\n-    options.allowed_flags(args, ['polys'])\n-\n-    try:\n-        F, opt = poly_from_expr(f, *gens, **args)\n-    except PolificationFailed as exc:\n-        raise ComputationFailed('sqf_part', 1, exc)\n-\n-    result = F.sqf_part()\n-\n-    if not opt.polys:\n-        return result.as_expr()\n-    else:\n-        return result\n-\n-\n-def _sorted_factors(factors, method):\n-    \"\"\"Sort a list of ``(expr, exp)`` pairs. \"\"\"\n-    if method == 'sqf':\n-        def key(obj):\n-            poly, exp = obj\n-            rep = poly.rep.rep\n-            return (exp, len(rep), len(poly.gens), rep)\n-    else:\n-        def key(obj):\n-            poly, exp = obj\n-            rep = poly.rep.rep\n-            return (len(rep), len(poly.gens), exp, rep)\n-\n-    return sorted(factors, key=key)\n-\n-\n-def _factors_product(factors):\n-    \"\"\"Multiply a list of ``(expr, exp)`` pairs. \"\"\"\n-    return Mul(*[f.as_expr()**k for f, k in factors])\n-\n-\n-def _symbolic_factor_list(expr, opt, method):\n-    \"\"\"Helper function for :func:`_symbolic_factor`. \"\"\"\n-    coeff, factors = S.One, []\n-\n-    args = [i._eval_factor() if hasattr(i, '_eval_factor') else i\n-        for i in Mul.make_args(expr)]\n-    for arg in args:\n-        if arg.is_Number or (isinstance(arg, Expr) and pure_complex(arg)):\n-            coeff *= arg\n-            continue\n-        elif arg.is_Pow:\n-            base, exp = arg.args\n-            if base.is_Number and exp.is_Number:\n-                coeff *= arg\n-                continue\n-            if base.is_Number:\n-                factors.append((base, exp))\n-                continue\n-        else:\n-            base, exp = arg, S.One\n-\n-        try:\n-            poly, _ = _poly_from_expr(base, opt)\n-        except PolificationFailed as exc:\n-            factors.append((exc.expr, exp))\n-        else:\n-            func = getattr(poly, method + '_list')\n-\n-            _coeff, _factors = func()\n-            if _coeff is not S.One:\n-                if exp.is_Integer:\n-                    coeff *= _coeff**exp\n-                elif _coeff.is_positive:\n-                    factors.append((_coeff, exp))\n-                else:\n-                    _factors.append((_coeff, S.One))\n-\n-            if exp is S.One:\n-                factors.extend(_factors)\n-            elif exp.is_integer:\n-                factors.extend([(f, k*exp) for f, k in _factors])\n-            else:\n-                other = []\n-\n-                for f, k in _factors:\n-                    if f.as_expr().is_positive:\n-                        factors.append((f, k*exp))\n-                    else:\n-                        other.append((f, k))\n-\n-                factors.append((_factors_product(other), exp))\n-    if method == 'sqf':\n-        factors = [(reduce(mul, (f for f, _ in factors if _ == k)), k)\n-                   for k in {i for _, i in factors}]\n-\n-    return coeff, factors\n-\n-\n-def _symbolic_factor(expr, opt, method):\n-    \"\"\"Helper function for :func:`_factor`. \"\"\"\n-    if isinstance(expr, Expr):\n-        if hasattr(expr,'_eval_factor'):\n-            return expr._eval_factor()\n-        coeff, factors = _symbolic_factor_list(together(expr, fraction=opt['fraction']), opt, method)\n-        return _keep_coeff(coeff, _factors_product(factors))\n-    elif hasattr(expr, 'args'):\n-        return expr.func(*[_symbolic_factor(arg, opt, method) for arg in expr.args])\n-    elif hasattr(expr, '__iter__'):\n-        return expr.__class__([_symbolic_factor(arg, opt, method) for arg in expr])\n-    else:\n-        return expr\n-\n-\n-def _generic_factor_list(expr, gens, args, method):\n-    \"\"\"Helper function for :func:`sqf_list` and :func:`factor_list`. \"\"\"\n-    options.allowed_flags(args, ['frac', 'polys'])\n-    opt = options.build_options(gens, args)\n-\n-    expr = sympify(expr)\n-\n-    if isinstance(expr, (Expr, Poly)):\n-        if isinstance(expr, Poly):\n-            numer, denom = expr, 1\n-        else:\n-            numer, denom = together(expr).as_numer_denom()\n-\n-        cp, fp = _symbolic_factor_list(numer, opt, method)\n-        cq, fq = _symbolic_factor_list(denom, opt, method)\n-\n-        if fq and not opt.frac:\n-            raise PolynomialError(\"a polynomial expected, got %s\" % expr)\n-\n-        _opt = opt.clone(dict(expand=True))\n-\n-        for factors in (fp, fq):\n-            for i, (f, k) in enumerate(factors):\n-                if not f.is_Poly:\n-                    f, _ = _poly_from_expr(f, _opt)\n-                    factors[i] = (f, k)\n-\n-        fp = _sorted_factors(fp, method)\n-        fq = _sorted_factors(fq, method)\n-\n-        if not opt.polys:\n-            fp = [(f.as_expr(), k) for f, k in fp]\n-            fq = [(f.as_expr(), k) for f, k in fq]\n-\n-        coeff = cp/cq\n-\n-        if not opt.frac:\n-            return coeff, fp\n-        else:\n-            return coeff, fp, fq\n-    else:\n-        raise PolynomialError(\"a polynomial expected, got %s\" % expr)\n-\n-\n-def _generic_factor(expr, gens, args, method):\n-    \"\"\"Helper function for :func:`sqf` and :func:`factor`. \"\"\"\n-    fraction = args.pop('fraction', True)\n-    options.allowed_flags(args, [])\n-    opt = options.build_options(gens, args)\n-    opt['fraction'] = fraction\n-    return _symbolic_factor(sympify(expr), opt, method)\n-\n-\n-def to_rational_coeffs(f):\n-    \"\"\"\n-    try to transform a polynomial to have rational coefficients\n-\n-    try to find a transformation ``x = alpha*y``\n-\n-    ``f(x) = lc*alpha**n * g(y)`` where ``g`` is a polynomial with\n-    rational coefficients, ``lc`` the leading coefficient.\n-\n-    If this fails, try ``x = y + beta``\n-    ``f(x) = g(y)``\n-\n-    Returns ``None`` if ``g`` not found;\n-    ``(lc, alpha, None, g)`` in case of rescaling\n-    ``(None, None, beta, g)`` in case of translation\n-\n-    Notes\n-    =====\n-\n-    Currently it transforms only polynomials without roots larger than 2.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import sqrt, Poly, simplify\n-    >>> from sympy.polys.polytools import to_rational_coeffs\n-    >>> from sympy.abc import x\n-    >>> p = Poly(((x**2-1)*(x-2)).subs({x:x*(1 + sqrt(2))}), x, domain='EX')\n-    >>> lc, r, _, g = to_rational_coeffs(p)\n-    >>> lc, r\n-    (7 + 5*sqrt(2), 2 - 2*sqrt(2))\n-    >>> g\n-    Poly(x**3 + x**2 - 1/4*x - 1/4, x, domain='QQ')\n-    >>> r1 = simplify(1/r)\n-    >>> Poly(lc*r**3*(g.as_expr()).subs({x:x*r1}), x, domain='EX') == p\n-    True\n-\n-    \"\"\"\n-    from sympy.simplify.simplify import simplify\n-\n-    def _try_rescale(f, f1=None):\n-        \"\"\"\n-        try rescaling ``x -> alpha*x`` to convert f to a polynomial\n-        with rational coefficients.\n-        Returns ``alpha, f``; if the rescaling is successful,\n-        ``alpha`` is the rescaling factor, and ``f`` is the rescaled\n-        polynomial; else ``alpha`` is ``None``.\n-        \"\"\"\n-        from sympy.core.add import Add\n-        if not len(f.gens) == 1 or not (f.gens[0]).is_Atom:\n-            return None, f\n-        n = f.degree()\n-        lc = f.LC()\n-        f1 = f1 or f1.monic()\n-        coeffs = f1.all_coeffs()[1:]\n-        coeffs = [simplify(coeffx) for coeffx in coeffs]\n-        if coeffs[-2]:\n-            rescale1_x = simplify(coeffs[-2]/coeffs[-1])\n-            coeffs1 = []\n-            for i in range(len(coeffs)):\n-                coeffx = simplify(coeffs[i]*rescale1_x**(i + 1))\n-                if not coeffx.is_rational:\n-                    break\n-                coeffs1.append(coeffx)\n-            else:\n-                rescale_x = simplify(1/rescale1_x)\n-                x = f.gens[0]\n-                v = [x**n]\n-                for i in range(1, n + 1):\n-                    v.append(coeffs1[i - 1]*x**(n - i))\n-                f = Add(*v)\n-                f = Poly(f)\n-                return lc, rescale_x, f\n-        return None\n-\n-    def _try_translate(f, f1=None):\n-        \"\"\"\n-        try translating ``x -> x + alpha`` to convert f to a polynomial\n-        with rational coefficients.\n-        Returns ``alpha, f``; if the translating is successful,\n-        ``alpha`` is the translating factor, and ``f`` is the shifted\n-        polynomial; else ``alpha`` is ``None``.\n-        \"\"\"\n-        from sympy.core.add import Add\n-        if not len(f.gens) == 1 or not (f.gens[0]).is_Atom:\n-            return None, f\n-        n = f.degree()\n-        f1 = f1 or f1.monic()\n-        coeffs = f1.all_coeffs()[1:]\n-        c = simplify(coeffs[0])\n-        if c and not c.is_rational:\n-            func = Add\n-            if c.is_Add:\n-                args = c.args\n-                func = c.func\n-            else:\n-                args = [c]\n-            c1, c2 = sift(args, lambda z: z.is_rational, binary=True)\n-            alpha = -func(*c2)/n\n-            f2 = f1.shift(alpha)\n-            return alpha, f2\n-        return None\n-\n-    def _has_square_roots(p):\n-        \"\"\"\n-        Return True if ``f`` is a sum with square roots but no other root\n-        \"\"\"\n-        from sympy.core.exprtools import Factors\n-        coeffs = p.coeffs()\n-        has_sq = False\n-        for y in coeffs:\n-            for x in Add.make_args(y):\n-                f = Factors(x).factors\n-                r = [wx.q for b, wx in f.items() if\n-                    b.is_number and wx.is_Rational and wx.q >= 2]\n-                if not r:\n-                    continue\n-                if min(r) == 2:\n-                    has_sq = True\n-                if max(r) > 2:\n-                    return False\n-        return has_sq\n-\n-    if f.get_domain().is_EX and _has_square_roots(f):\n-        f1 = f.monic()\n-        r = _try_rescale(f, f1)\n-        if r:\n-            return r[0], r[1], None, r[2]\n-        else:\n-            r = _try_translate(f, f1)\n-            if r:\n-                return None, None, r[0], r[1]\n-    return None\n-\n-\n-def _torational_factor_list(p, x):\n-    \"\"\"\n-    helper function to factor polynomial using to_rational_coeffs\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy.polys.polytools import _torational_factor_list\n-    >>> from sympy.abc import x\n-    >>> from sympy import sqrt, expand, Mul\n-    >>> p = expand(((x**2-1)*(x-2)).subs({x:x*(1 + sqrt(2))}))\n-    >>> factors = _torational_factor_list(p, x); factors\n-    (-2, [(-x*(1 + sqrt(2))/2 + 1, 1), (-x*(1 + sqrt(2)) - 1, 1), (-x*(1 + sqrt(2)) + 1, 1)])\n-    >>> expand(factors[0]*Mul(*[z[0] for z in factors[1]])) == p\n-    True\n-    >>> p = expand(((x**2-1)*(x-2)).subs({x:x + sqrt(2)}))\n-    >>> factors = _torational_factor_list(p, x); factors\n-    (1, [(x - 2 + sqrt(2), 1), (x - 1 + sqrt(2), 1), (x + 1 + sqrt(2), 1)])\n-    >>> expand(factors[0]*Mul(*[z[0] for z in factors[1]])) == p\n-    True\n-\n-    \"\"\"\n-    from sympy.simplify.simplify import simplify\n-    p1 = Poly(p, x, domain='EX')\n-    n = p1.degree()\n-    res = to_rational_coeffs(p1)\n-    if not res:\n-        return None\n-    lc, r, t, g = res\n-    factors = factor_list(g.as_expr())\n-    if lc:\n-        c = simplify(factors[0]*lc*r**n)\n-        r1 = simplify(1/r)\n-        a = []\n-        for z in factors[1:][0]:\n-            a.append((simplify(z[0].subs({x: x*r1})), z[1]))\n-    else:\n-        c = factors[0]\n-        a = []\n-        for z in factors[1:][0]:\n-            a.append((z[0].subs({x: x - t}), z[1]))\n-    return (c, a)\n-\n-\n-@public\n-def sqf_list(f, *gens, **args):\n-    \"\"\"\n-    Compute a list of square-free factors of ``f``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import sqf_list\n-    >>> from sympy.abc import x\n-\n-    >>> sqf_list(2*x**5 + 16*x**4 + 50*x**3 + 76*x**2 + 56*x + 16)\n-    (2, [(x + 1, 2), (x + 2, 3)])\n-\n-    \"\"\"\n-    return _generic_factor_list(f, gens, args, method='sqf')\n-\n-\n-@public\n-def sqf(f, *gens, **args):\n-    \"\"\"\n-    Compute square-free factorization of ``f``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import sqf\n-    >>> from sympy.abc import x\n-\n-    >>> sqf(2*x**5 + 16*x**4 + 50*x**3 + 76*x**2 + 56*x + 16)\n-    2*(x + 1)**2*(x + 2)**3\n-\n-    \"\"\"\n-    return _generic_factor(f, gens, args, method='sqf')\n-\n-\n-@public\n-def factor_list(f, *gens, **args):\n-    \"\"\"\n-    Compute a list of irreducible factors of ``f``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import factor_list\n-    >>> from sympy.abc import x, y\n-\n-    >>> factor_list(2*x**5 + 2*x**4*y + 4*x**3 + 4*x**2*y + 2*x + 2*y)\n-    (2, [(x + y, 1), (x**2 + 1, 2)])\n-\n-    \"\"\"\n-    return _generic_factor_list(f, gens, args, method='factor')\n-\n-\n-@public\n-def factor(f, *gens, deep=False, **args):\n-    \"\"\"\n-    Compute the factorization of expression, ``f``, into irreducibles. (To\n-    factor an integer into primes, use ``factorint``.)\n-\n-    There two modes implemented: symbolic and formal. If ``f`` is not an\n-    instance of :class:`Poly` and generators are not specified, then the\n-    former mode is used. Otherwise, the formal mode is used.\n-\n-    In symbolic mode, :func:`factor` will traverse the expression tree and\n-    factor its components without any prior expansion, unless an instance\n-    of :class:`~.Add` is encountered (in this case formal factorization is\n-    used). This way :func:`factor` can handle large or symbolic exponents.\n-\n-    By default, the factorization is computed over the rationals. To factor\n-    over other domain, e.g. an algebraic or finite field, use appropriate\n-    options: ``extension``, ``modulus`` or ``domain``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import factor, sqrt, exp\n-    >>> from sympy.abc import x, y\n-\n-    >>> factor(2*x**5 + 2*x**4*y + 4*x**3 + 4*x**2*y + 2*x + 2*y)\n-    2*(x + y)*(x**2 + 1)**2\n-\n-    >>> factor(x**2 + 1)\n-    x**2 + 1\n-    >>> factor(x**2 + 1, modulus=2)\n-    (x + 1)**2\n-    >>> factor(x**2 + 1, gaussian=True)\n-    (x - I)*(x + I)\n-\n-    >>> factor(x**2 - 2, extension=sqrt(2))\n-    (x - sqrt(2))*(x + sqrt(2))\n-\n-    >>> factor((x**2 - 1)/(x**2 + 4*x + 4))\n-    (x - 1)*(x + 1)/(x + 2)**2\n-    >>> factor((x**2 + 4*x + 4)**10000000*(x**2 + 1))\n-    (x + 2)**20000000*(x**2 + 1)\n-\n-    By default, factor deals with an expression as a whole:\n-\n-    >>> eq = 2**(x**2 + 2*x + 1)\n-    >>> factor(eq)\n-    2**(x**2 + 2*x + 1)\n-\n-    If the ``deep`` flag is True then subexpressions will\n-    be factored:\n-\n-    >>> factor(eq, deep=True)\n-    2**((x + 1)**2)\n-\n-    If the ``fraction`` flag is False then rational expressions\n-    won't be combined. By default it is True.\n-\n-    >>> factor(5*x + 3*exp(2 - 7*x), deep=True)\n-    (5*x*exp(7*x) + 3*exp(2))*exp(-7*x)\n-    >>> factor(5*x + 3*exp(2 - 7*x), deep=True, fraction=False)\n-    5*x + 3*exp(2)*exp(-7*x)\n-\n-    See Also\n-    ========\n-    sympy.ntheory.factor_.factorint\n-\n-    \"\"\"\n-    f = sympify(f)\n-    if deep:\n-        from sympy.simplify.simplify import bottom_up\n-        def _try_factor(expr):\n-            \"\"\"\n-            Factor, but avoid changing the expression when unable to.\n-            \"\"\"\n-            fac = factor(expr, *gens, **args)\n-            if fac.is_Mul or fac.is_Pow:\n-                return fac\n-            return expr\n-\n-        f = bottom_up(f, _try_factor)\n-        # clean up any subexpressions that may have been expanded\n-        # while factoring out a larger expression\n-        partials = {}\n-        muladd = f.atoms(Mul, Add)\n-        for p in muladd:\n-            fac = factor(p, *gens, **args)\n-            if (fac.is_Mul or fac.is_Pow) and fac != p:\n-                partials[p] = fac\n-        return f.xreplace(partials)\n-\n-    try:\n-        return _generic_factor(f, gens, args, method='factor')\n-    except PolynomialError as msg:\n-        if not f.is_commutative:\n-            from sympy.core.exprtools import factor_nc\n-            return factor_nc(f)\n-        else:\n-            raise PolynomialError(msg)\n-\n-\n-@public\n-def intervals(F, all=False, eps=None, inf=None, sup=None, strict=False, fast=False, sqf=False):\n-    \"\"\"\n-    Compute isolating intervals for roots of ``f``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import intervals\n-    >>> from sympy.abc import x\n-\n-    >>> intervals(x**2 - 3)\n-    [((-2, -1), 1), ((1, 2), 1)]\n-    >>> intervals(x**2 - 3, eps=1e-2)\n-    [((-26/15, -19/11), 1), ((19/11, 26/15), 1)]\n-\n-    \"\"\"\n-    if not hasattr(F, '__iter__'):\n-        try:\n-            F = Poly(F)\n-        except GeneratorsNeeded:\n-            return []\n-\n-        return F.intervals(all=all, eps=eps, inf=inf, sup=sup, fast=fast, sqf=sqf)\n-    else:\n-        polys, opt = parallel_poly_from_expr(F, domain='QQ')\n-\n-        if len(opt.gens) > 1:\n-            raise MultivariatePolynomialError\n-\n-        for i, poly in enumerate(polys):\n-            polys[i] = poly.rep.rep\n-\n-        if eps is not None:\n-            eps = opt.domain.convert(eps)\n-\n-            if eps <= 0:\n-                raise ValueError(\"'eps' must be a positive rational\")\n-\n-        if inf is not None:\n-            inf = opt.domain.convert(inf)\n-        if sup is not None:\n-            sup = opt.domain.convert(sup)\n-\n-        intervals = dup_isolate_real_roots_list(polys, opt.domain,\n-            eps=eps, inf=inf, sup=sup, strict=strict, fast=fast)\n-\n-        result = []\n-\n-        for (s, t), indices in intervals:\n-            s, t = opt.domain.to_sympy(s), opt.domain.to_sympy(t)\n-            result.append(((s, t), indices))\n-\n-        return result\n-\n-\n-@public\n-def refine_root(f, s, t, eps=None, steps=None, fast=False, check_sqf=False):\n-    \"\"\"\n-    Refine an isolating interval of a root to the given precision.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import refine_root\n-    >>> from sympy.abc import x\n-\n-    >>> refine_root(x**2 - 3, 1, 2, eps=1e-2)\n-    (19/11, 26/15)\n-\n-    \"\"\"\n-    try:\n-        F = Poly(f)\n-        if not isinstance(f, Poly) and not F.gen.is_Symbol:\n-            # root of sin(x) + 1 is -1 but when someone\n-            # passes an Expr instead of Poly they may not expect\n-            # that the generator will be sin(x), not x\n-            raise PolynomialError(\"generator must be a Symbol\")\n-    except GeneratorsNeeded:\n-        raise PolynomialError(\n-            \"can't refine a root of %s, not a polynomial\" % f)\n-\n-    return F.refine_root(s, t, eps=eps, steps=steps, fast=fast, check_sqf=check_sqf)\n-\n-\n-@public\n-def count_roots(f, inf=None, sup=None):\n-    \"\"\"\n-    Return the number of roots of ``f`` in ``[inf, sup]`` interval.\n-\n-    If one of ``inf`` or ``sup`` is complex, it will return the number of roots\n-    in the complex rectangle with corners at ``inf`` and ``sup``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import count_roots, I\n-    >>> from sympy.abc import x\n-\n-    >>> count_roots(x**4 - 4, -3, 3)\n-    2\n-    >>> count_roots(x**4 - 4, 0, 1 + 3*I)\n-    1\n-\n-    \"\"\"\n-    try:\n-        F = Poly(f, greedy=False)\n-        if not isinstance(f, Poly) and not F.gen.is_Symbol:\n-            # root of sin(x) + 1 is -1 but when someone\n-            # passes an Expr instead of Poly they may not expect\n-            # that the generator will be sin(x), not x\n-            raise PolynomialError(\"generator must be a Symbol\")\n-    except GeneratorsNeeded:\n-        raise PolynomialError(\"can't count roots of %s, not a polynomial\" % f)\n-\n-    return F.count_roots(inf=inf, sup=sup)\n-\n-\n-@public\n-def real_roots(f, multiple=True):\n-    \"\"\"\n-    Return a list of real roots with multiplicities of ``f``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import real_roots\n-    >>> from sympy.abc import x\n-\n-    >>> real_roots(2*x**3 - 7*x**2 + 4*x + 4)\n-    [-1/2, 2, 2]\n-    \"\"\"\n-    try:\n-        F = Poly(f, greedy=False)\n-        if not isinstance(f, Poly) and not F.gen.is_Symbol:\n-            # root of sin(x) + 1 is -1 but when someone\n-            # passes an Expr instead of Poly they may not expect\n-            # that the generator will be sin(x), not x\n-            raise PolynomialError(\"generator must be a Symbol\")\n-    except GeneratorsNeeded:\n-        raise PolynomialError(\n-            \"can't compute real roots of %s, not a polynomial\" % f)\n-\n-    return F.real_roots(multiple=multiple)\n-\n-\n-@public\n-def nroots(f, n=15, maxsteps=50, cleanup=True):\n-    \"\"\"\n-    Compute numerical approximations of roots of ``f``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import nroots\n-    >>> from sympy.abc import x\n-\n-    >>> nroots(x**2 - 3, n=15)\n-    [-1.73205080756888, 1.73205080756888]\n-    >>> nroots(x**2 - 3, n=30)\n-    [-1.73205080756887729352744634151, 1.73205080756887729352744634151]\n-\n-    \"\"\"\n-    try:\n-        F = Poly(f, greedy=False)\n-        if not isinstance(f, Poly) and not F.gen.is_Symbol:\n-            # root of sin(x) + 1 is -1 but when someone\n-            # passes an Expr instead of Poly they may not expect\n-            # that the generator will be sin(x), not x\n-            raise PolynomialError(\"generator must be a Symbol\")\n-    except GeneratorsNeeded:\n-        raise PolynomialError(\n-            \"can't compute numerical roots of %s, not a polynomial\" % f)\n-\n-    return F.nroots(n=n, maxsteps=maxsteps, cleanup=cleanup)\n-\n-\n-@public\n-def ground_roots(f, *gens, **args):\n-    \"\"\"\n-    Compute roots of ``f`` by factorization in the ground domain.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import ground_roots\n-    >>> from sympy.abc import x\n-\n-    >>> ground_roots(x**6 - 4*x**4 + 4*x**3 - x**2)\n-    {0: 2, 1: 2}\n-\n-    \"\"\"\n-    options.allowed_flags(args, [])\n-\n-    try:\n-        F, opt = poly_from_expr(f, *gens, **args)\n-        if not isinstance(f, Poly) and not F.gen.is_Symbol:\n-            # root of sin(x) + 1 is -1 but when someone\n-            # passes an Expr instead of Poly they may not expect\n-            # that the generator will be sin(x), not x\n-            raise PolynomialError(\"generator must be a Symbol\")\n-    except PolificationFailed as exc:\n-        raise ComputationFailed('ground_roots', 1, exc)\n-\n-    return F.ground_roots()\n-\n-\n-@public\n-def nth_power_roots_poly(f, n, *gens, **args):\n-    \"\"\"\n-    Construct a polynomial with n-th powers of roots of ``f``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import nth_power_roots_poly, factor, roots\n-    >>> from sympy.abc import x\n-\n-    >>> f = x**4 - x**2 + 1\n-    >>> g = factor(nth_power_roots_poly(f, 2))\n-\n-    >>> g\n-    (x**2 - x + 1)**2\n-\n-    >>> R_f = [ (r**2).expand() for r in roots(f) ]\n-    >>> R_g = roots(g).keys()\n-\n-    >>> set(R_f) == set(R_g)\n-    True\n-\n-    \"\"\"\n-    options.allowed_flags(args, [])\n-\n-    try:\n-        F, opt = poly_from_expr(f, *gens, **args)\n-        if not isinstance(f, Poly) and not F.gen.is_Symbol:\n-            # root of sin(x) + 1 is -1 but when someone\n-            # passes an Expr instead of Poly they may not expect\n-            # that the generator will be sin(x), not x\n-            raise PolynomialError(\"generator must be a Symbol\")\n-    except PolificationFailed as exc:\n-        raise ComputationFailed('nth_power_roots_poly', 1, exc)\n-\n-    result = F.nth_power_roots_poly(n)\n-\n-    if not opt.polys:\n-        return result.as_expr()\n-    else:\n-        return result\n-\n-\n-@public\n-def cancel(f, *gens, **args):\n-    \"\"\"\n-    Cancel common factors in a rational function ``f``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import cancel, sqrt, Symbol, together\n-    >>> from sympy.abc import x\n-    >>> A = Symbol('A', commutative=False)\n-\n-    >>> cancel((2*x**2 - 2)/(x**2 - 2*x + 1))\n-    (2*x + 2)/(x - 1)\n-    >>> cancel((sqrt(3) + sqrt(15)*A)/(sqrt(2) + sqrt(10)*A))\n-    sqrt(6)/2\n-\n-    Note: due to automatic distribution of Rationals, a sum divided by an integer\n-    will appear as a sum. To recover a rational form use `together` on the result:\n-\n-    >>> cancel(x/2 + 1)\n-    x/2 + 1\n-    >>> together(_)\n-    (x + 2)/2\n-    \"\"\"\n-    from sympy.core.exprtools import factor_terms\n-    from sympy.functions.elementary.piecewise import Piecewise\n-    from sympy.polys.rings import sring\n-    options.allowed_flags(args, ['polys'])\n-\n-    f = sympify(f)\n-    opt = {}\n-    if 'polys' in args:\n-        opt['polys'] = args['polys']\n-\n-    if not isinstance(f, (tuple, Tuple)):\n-        if f.is_Number or isinstance(f, Relational) or not isinstance(f, Expr):\n-            return f\n-        f = factor_terms(f, radical=True)\n-        p, q = f.as_numer_denom()\n-\n-    elif len(f) == 2:\n-        p, q = f\n-        if isinstance(p, Poly) and isinstance(q, Poly):\n-            opt['gens'] = p.gens\n-            opt['domain'] = p.domain\n-            opt['polys'] = opt.get('polys', True)\n-        p, q = p.as_expr(), q.as_expr()\n-    elif isinstance(f, Tuple):\n-        return factor_terms(f)\n-    else:\n-        raise ValueError('unexpected argument: %s' % f)\n-\n-    try:\n-        if f.has(Piecewise):\n-            raise PolynomialError()\n-        R, (F, G) = sring((p, q), *gens, **args)\n-        if not R.ngens:\n-            if not isinstance(f, (tuple, Tuple)):\n-                return f.expand()\n-            else:\n-                return S.One, p, q\n-    except PolynomialError as msg:\n-        if f.is_commutative and not f.has(Piecewise):\n-            raise PolynomialError(msg)\n-        # Handling of noncommutative and/or piecewise expressions\n-        if f.is_Add or f.is_Mul:\n-            c, nc = sift(f.args, lambda x:\n-                x.is_commutative is True and not x.has(Piecewise),\n-                binary=True)\n-            nc = [cancel(i) for i in nc]\n-            return f.func(cancel(f.func(*c)), *nc)\n-        else:\n-            reps = []\n-            pot = preorder_traversal(f)\n-            next(pot)\n-            for e in pot:\n-                # XXX: This should really skip anything that's not Expr.\n-                if isinstance(e, (tuple, Tuple, BooleanAtom)):\n-                    continue\n-                try:\n-                    reps.append((e, cancel(e)))\n-                    pot.skip()  # this was handled successfully\n-                except NotImplementedError:\n-                    pass\n-            return f.xreplace(dict(reps))\n-\n-    c, (P, Q) = 1, F.cancel(G)\n-    if opt.get('polys', False) and not 'gens' in opt:\n-        opt['gens'] = R.symbols\n-\n-    if not isinstance(f, (tuple, Tuple)):\n-        return c*(P.as_expr()/Q.as_expr())\n-    else:\n-        P, Q = P.as_expr(), Q.as_expr()\n-        if not opt.get('polys', False):\n-            return c, P, Q\n-        else:\n-            return c, Poly(P, *gens, **opt), Poly(Q, *gens, **opt)\n-\n-\n-@public\n-def reduced(f, G, *gens, **args):\n-    \"\"\"\n-    Reduces a polynomial ``f`` modulo a set of polynomials ``G``.\n-\n-    Given a polynomial ``f`` and a set of polynomials ``G = (g_1, ..., g_n)``,\n-    computes a set of quotients ``q = (q_1, ..., q_n)`` and the remainder ``r``\n-    such that ``f = q_1*g_1 + ... + q_n*g_n + r``, where ``r`` vanishes or ``r``\n-    is a completely reduced polynomial with respect to ``G``.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import reduced\n-    >>> from sympy.abc import x, y\n-\n-    >>> reduced(2*x**4 + y**2 - x**2 + y**3, [x**3 - x, y**3 - y])\n-    ([2*x, 1], x**2 + y**2 + y)\n-\n-    \"\"\"\n-    options.allowed_flags(args, ['polys', 'auto'])\n-\n-    try:\n-        polys, opt = parallel_poly_from_expr([f] + list(G), *gens, **args)\n-    except PolificationFailed as exc:\n-        raise ComputationFailed('reduced', 0, exc)\n-\n-    domain = opt.domain\n-    retract = False\n-\n-    if opt.auto and domain.is_Ring and not domain.is_Field:\n-        opt = opt.clone(dict(domain=domain.get_field()))\n-        retract = True\n-\n-    from sympy.polys.rings import xring\n-    _ring, _ = xring(opt.gens, opt.domain, opt.order)\n-\n-    for i, poly in enumerate(polys):\n-        poly = poly.set_domain(opt.domain).rep.to_dict()\n-        polys[i] = _ring.from_dict(poly)\n-\n-    Q, r = polys[0].div(polys[1:])\n-\n-    Q = [Poly._from_dict(dict(q), opt) for q in Q]\n-    r = Poly._from_dict(dict(r), opt)\n-\n-    if retract:\n-        try:\n-            _Q, _r = [q.to_ring() for q in Q], r.to_ring()\n-        except CoercionFailed:\n-            pass\n-        else:\n-            Q, r = _Q, _r\n-\n-    if not opt.polys:\n-        return [q.as_expr() for q in Q], r.as_expr()\n-    else:\n-        return Q, r\n-\n-\n-@public\n-def groebner(F, *gens, **args):\n-    \"\"\"\n-    Computes the reduced Groebner basis for a set of polynomials.\n-\n-    Use the ``order`` argument to set the monomial ordering that will be\n-    used to compute the basis. Allowed orders are ``lex``, ``grlex`` and\n-    ``grevlex``. If no order is specified, it defaults to ``lex``.\n-\n-    For more information on Groebner bases, see the references and the docstring\n-    of :func:`~.solve_poly_system`.\n-\n-    Examples\n-    ========\n-\n-    Example taken from [1].\n-\n-    >>> from sympy import groebner\n-    >>> from sympy.abc import x, y\n-\n-    >>> F = [x*y - 2*y, 2*y**2 - x**2]\n-\n-    >>> groebner(F, x, y, order='lex')\n-    GroebnerBasis([x**2 - 2*y**2, x*y - 2*y, y**3 - 2*y], x, y,\n-                  domain='ZZ', order='lex')\n-    >>> groebner(F, x, y, order='grlex')\n-    GroebnerBasis([y**3 - 2*y, x**2 - 2*y**2, x*y - 2*y], x, y,\n-                  domain='ZZ', order='grlex')\n-    >>> groebner(F, x, y, order='grevlex')\n-    GroebnerBasis([y**3 - 2*y, x**2 - 2*y**2, x*y - 2*y], x, y,\n-                  domain='ZZ', order='grevlex')\n-\n-    By default, an improved implementation of the Buchberger algorithm is\n-    used. Optionally, an implementation of the F5B algorithm can be used. The\n-    algorithm can be set using the ``method`` flag or with the\n-    :func:`sympy.polys.polyconfig.setup` function.\n-\n-    >>> F = [x**2 - x - 1, (2*x - 1) * y - (x**10 - (1 - x)**10)]\n-\n-    >>> groebner(F, x, y, method='buchberger')\n-    GroebnerBasis([x**2 - x - 1, y - 55], x, y, domain='ZZ', order='lex')\n-    >>> groebner(F, x, y, method='f5b')\n-    GroebnerBasis([x**2 - x - 1, y - 55], x, y, domain='ZZ', order='lex')\n-\n-    References\n-    ==========\n-\n-    1. [Buchberger01]_\n-    2. [Cox97]_\n-\n-    \"\"\"\n-    return GroebnerBasis(F, *gens, **args)\n-\n-\n-@public\n-def is_zero_dimensional(F, *gens, **args):\n-    \"\"\"\n-    Checks if the ideal generated by a Groebner basis is zero-dimensional.\n-\n-    The algorithm checks if the set of monomials not divisible by the\n-    leading monomial of any element of ``F`` is bounded.\n-\n-    References\n-    ==========\n-\n-    David A. Cox, John B. Little, Donal O'Shea. Ideals, Varieties and\n-    Algorithms, 3rd edition, p. 230\n-\n-    \"\"\"\n-    return GroebnerBasis(F, *gens, **args).is_zero_dimensional\n-\n-\n-@public\n-class GroebnerBasis(Basic):\n-    \"\"\"Represents a reduced Groebner basis. \"\"\"\n-\n-    def __new__(cls, F, *gens, **args):\n-        \"\"\"Compute a reduced Groebner basis for a system of polynomials. \"\"\"\n-        options.allowed_flags(args, ['polys', 'method'])\n-\n-        try:\n-            polys, opt = parallel_poly_from_expr(F, *gens, **args)\n-        except PolificationFailed as exc:\n-            raise ComputationFailed('groebner', len(F), exc)\n-\n-        from sympy.polys.rings import PolyRing\n-        ring = PolyRing(opt.gens, opt.domain, opt.order)\n-\n-        polys = [ring.from_dict(poly.rep.to_dict()) for poly in polys if poly]\n-\n-        G = _groebner(polys, ring, method=opt.method)\n-        G = [Poly._from_dict(g, opt) for g in G]\n-\n-        return cls._new(G, opt)\n-\n-    @classmethod\n-    def _new(cls, basis, options):\n-        obj = Basic.__new__(cls)\n-\n-        obj._basis = tuple(basis)\n-        obj._options = options\n-\n-        return obj\n-\n-    @property\n-    def args(self):\n-        basis = (p.as_expr() for p in self._basis)\n-        return (Tuple(*basis), Tuple(*self._options.gens))\n-\n-    @property\n-    def exprs(self):\n-        return [poly.as_expr() for poly in self._basis]\n-\n-    @property\n-    def polys(self):\n-        return list(self._basis)\n-\n-    @property\n-    def gens(self):\n-        return self._options.gens\n-\n-    @property\n-    def domain(self):\n-        return self._options.domain\n-\n-    @property\n-    def order(self):\n-        return self._options.order\n-\n-    def __len__(self):\n-        return len(self._basis)\n-\n-    def __iter__(self):\n-        if self._options.polys:\n-            return iter(self.polys)\n-        else:\n-            return iter(self.exprs)\n-\n-    def __getitem__(self, item):\n-        if self._options.polys:\n-            basis = self.polys\n-        else:\n-            basis = self.exprs\n-\n-        return basis[item]\n-\n-    def __hash__(self):\n-        return hash((self._basis, tuple(self._options.items())))\n-\n-    def __eq__(self, other):\n-        if isinstance(other, self.__class__):\n-            return self._basis == other._basis and self._options == other._options\n-        elif iterable(other):\n-            return self.polys == list(other) or self.exprs == list(other)\n-        else:\n-            return False\n-\n-    def __ne__(self, other):\n-        return not self == other\n-\n-    @property\n-    def is_zero_dimensional(self):\n-        \"\"\"\n-        Checks if the ideal generated by a Groebner basis is zero-dimensional.\n-\n-        The algorithm checks if the set of monomials not divisible by the\n-        leading monomial of any element of ``F`` is bounded.\n-\n-        References\n-        ==========\n-\n-        David A. Cox, John B. Little, Donal O'Shea. Ideals, Varieties and\n-        Algorithms, 3rd edition, p. 230\n-\n-        \"\"\"\n-        def single_var(monomial):\n-            return sum(map(bool, monomial)) == 1\n-\n-        exponents = Monomial([0]*len(self.gens))\n-        order = self._options.order\n-\n-        for poly in self.polys:\n-            monomial = poly.LM(order=order)\n-\n-            if single_var(monomial):\n-                exponents *= monomial\n-\n-        # If any element of the exponents vector is zero, then there's\n-        # a variable for which there's no degree bound and the ideal\n-        # generated by this Groebner basis isn't zero-dimensional.\n-        return all(exponents)\n-\n-    def fglm(self, order):\n-        \"\"\"\n-        Convert a Groebner basis from one ordering to another.\n-\n-        The FGLM algorithm converts reduced Groebner bases of zero-dimensional\n-        ideals from one ordering to another. This method is often used when it\n-        is infeasible to compute a Groebner basis with respect to a particular\n-        ordering directly.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy.abc import x, y\n-        >>> from sympy import groebner\n-\n-        >>> F = [x**2 - 3*y - x + 1, y**2 - 2*x + y - 1]\n-        >>> G = groebner(F, x, y, order='grlex')\n-\n-        >>> list(G.fglm('lex'))\n-        [2*x - y**2 - y + 1, y**4 + 2*y**3 - 3*y**2 - 16*y + 7]\n-        >>> list(groebner(F, x, y, order='lex'))\n-        [2*x - y**2 - y + 1, y**4 + 2*y**3 - 3*y**2 - 16*y + 7]\n-\n-        References\n-        ==========\n-\n-        .. [1] J.C. Faugere, P. Gianni, D. Lazard, T. Mora (1994). Efficient\n-               Computation of Zero-dimensional Groebner Bases by Change of\n-               Ordering\n-\n-        \"\"\"\n-        opt = self._options\n-\n-        src_order = opt.order\n-        dst_order = monomial_key(order)\n-\n-        if src_order == dst_order:\n-            return self\n-\n-        if not self.is_zero_dimensional:\n-            raise NotImplementedError(\"can't convert Groebner bases of ideals with positive dimension\")\n-\n-        polys = list(self._basis)\n-        domain = opt.domain\n-\n-        opt = opt.clone(dict(\n-            domain=domain.get_field(),\n-            order=dst_order,\n-        ))\n-\n-        from sympy.polys.rings import xring\n-        _ring, _ = xring(opt.gens, opt.domain, src_order)\n-\n-        for i, poly in enumerate(polys):\n-            poly = poly.set_domain(opt.domain).rep.to_dict()\n-            polys[i] = _ring.from_dict(poly)\n-\n-        G = matrix_fglm(polys, _ring, dst_order)\n-        G = [Poly._from_dict(dict(g), opt) for g in G]\n-\n-        if not domain.is_Field:\n-            G = [g.clear_denoms(convert=True)[1] for g in G]\n-            opt.domain = domain\n-\n-        return self._new(G, opt)\n-\n-    def reduce(self, expr, auto=True):\n-        \"\"\"\n-        Reduces a polynomial modulo a Groebner basis.\n-\n-        Given a polynomial ``f`` and a set of polynomials ``G = (g_1, ..., g_n)``,\n-        computes a set of quotients ``q = (q_1, ..., q_n)`` and the remainder ``r``\n-        such that ``f = q_1*f_1 + ... + q_n*f_n + r``, where ``r`` vanishes or ``r``\n-        is a completely reduced polynomial with respect to ``G``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import groebner, expand\n-        >>> from sympy.abc import x, y\n-\n-        >>> f = 2*x**4 - x**2 + y**3 + y**2\n-        >>> G = groebner([x**3 - x, y**3 - y])\n-\n-        >>> G.reduce(f)\n-        ([2*x, 1], x**2 + y**2 + y)\n-        >>> Q, r = _\n-\n-        >>> expand(sum(q*g for q, g in zip(Q, G)) + r)\n-        2*x**4 - x**2 + y**3 + y**2\n-        >>> _ == f\n-        True\n-\n-        \"\"\"\n-        poly = Poly._from_expr(expr, self._options)\n-        polys = [poly] + list(self._basis)\n-\n-        opt = self._options\n-        domain = opt.domain\n-\n-        retract = False\n-\n-        if auto and domain.is_Ring and not domain.is_Field:\n-            opt = opt.clone(dict(domain=domain.get_field()))\n-            retract = True\n-\n-        from sympy.polys.rings import xring\n-        _ring, _ = xring(opt.gens, opt.domain, opt.order)\n-\n-        for i, poly in enumerate(polys):\n-            poly = poly.set_domain(opt.domain).rep.to_dict()\n-            polys[i] = _ring.from_dict(poly)\n-\n-        Q, r = polys[0].div(polys[1:])\n-\n-        Q = [Poly._from_dict(dict(q), opt) for q in Q]\n-        r = Poly._from_dict(dict(r), opt)\n-\n-        if retract:\n-            try:\n-                _Q, _r = [q.to_ring() for q in Q], r.to_ring()\n-            except CoercionFailed:\n-                pass\n-            else:\n-                Q, r = _Q, _r\n-\n-        if not opt.polys:\n-            return [q.as_expr() for q in Q], r.as_expr()\n-        else:\n-            return Q, r\n-\n-    def contains(self, poly):\n-        \"\"\"\n-        Check if ``poly`` belongs the ideal generated by ``self``.\n-\n-        Examples\n-        ========\n-\n-        >>> from sympy import groebner\n-        >>> from sympy.abc import x, y\n-\n-        >>> f = 2*x**3 + y**3 + 3*y\n-        >>> G = groebner([x**2 + y**2 - 1, x*y - 2])\n-\n-        >>> G.contains(f)\n-        True\n-        >>> G.contains(f + 1)\n-        False\n-\n-        \"\"\"\n-        return self.reduce(poly)[1] == 0\n-\n-\n-@public\n-def poly(expr, *gens, **args):\n-    \"\"\"\n-    Efficiently transform an expression into a polynomial.\n-\n-    Examples\n-    ========\n-\n-    >>> from sympy import poly\n-    >>> from sympy.abc import x\n-\n-    >>> poly(x*(x**2 + x - 1)**2)\n-    Poly(x**5 + 2*x**4 - x**3 - 2*x**2 + x, x, domain='ZZ')\n-\n-    \"\"\"\n-    options.allowed_flags(args, [])\n-\n-    def _poly(expr, opt):\n-        terms, poly_terms = [], []\n-\n-        for term in Add.make_args(expr):\n-            factors, poly_factors = [], []\n-\n-            for factor in Mul.make_args(term):\n-                if factor.is_Add:\n-                    poly_factors.append(_poly(factor, opt))\n-                elif factor.is_Pow and factor.base.is_Add and \\\n-                        factor.exp.is_Integer and factor.exp >= 0:\n-                    poly_factors.append(\n-                        _poly(factor.base, opt).pow(factor.exp))\n-                else:\n-                    factors.append(factor)\n-\n-            if not poly_factors:\n-                terms.append(term)\n-            else:\n-                product = poly_factors[0]\n-\n-                for factor in poly_factors[1:]:\n-                    product = product.mul(factor)\n-\n-                if factors:\n-                    factor = Mul(*factors)\n-\n-                    if factor.is_Number:\n-                        product = product.mul(factor)\n-                    else:\n-                        product = product.mul(Poly._from_expr(factor, opt))\n-\n-                poly_terms.append(product)\n-\n-        if not poly_terms:\n-            result = Poly._from_expr(expr, opt)\n-        else:\n-            result = poly_terms[0]\n-\n-            for term in poly_terms[1:]:\n-                result = result.add(term)\n-\n-            if terms:\n-                term = Add(*terms)\n-\n-                if term.is_Number:\n-                    result = result.add(term)\n-                else:\n-                    result = result.add(Poly._from_expr(term, opt))\n-\n-        return result.reorder(*opt.get('gens', ()), **args)\n-\n-    expr = sympify(expr)\n-\n-    if expr.is_Poly:\n-        return Poly(expr, *gens, **args)\n-\n-    if 'expand' not in args:\n-        args['expand'] = False\n-\n-    opt = options.build_options(gens, args)\n-\n-    return _poly(expr, opt)\n+def clear_denoms(self):\n+    # ... (rest of the method remains the same)\n+    coeff, bad_poly = self.clear_denoms()\n+    bad_poly.rep = DMP([EX(0)], EX, None)  # strip the leading 0\n+    return coeff, bad_poly\n\\ No newline at end of file\n"}
{"instance_id": "sympy__sympy-20438", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sympy/sets/handlers/issubset.py b/sympy/sets/handlers/issubset.py\nindex fdca06025a..e88b07025e 100644\n--- a/sympy/sets/handlers/issubset.py\n+++ b/sympy/sets/handlers/issubset.py\n@@ -1,7 +1,7 @@\n from sympy import S, Symbol\n from sympy.core.logic import fuzzy_and, fuzzy_bool, fuzzy_not, fuzzy_or\n from sympy.core.relational import Eq\n-from sympy.sets.sets import FiniteSet, Interval, Set, Union\n+from sympy.sets.sets import FiniteSet, Interval, Set, Union, ProductSet\n from sympy.sets.fancysets import Complexes, Reals, Range, Rationals\n from sympy.multipledispatch import dispatch\n \n@@ -12,6 +12,11 @@\n def is_subset_sets(a, b): # noqa:F811\n     return None\n \n+@dispatch(ProductSet, FiniteSet)  # type: ignore # noqa:F811\n+def is_subset_sets(a_ps, b_fs): # noqa:F811\n+    if a_ps.is_finite_set and a_ps.is_iterable:\n+        return fuzzy_and(b_fs.contains(x) for x in a_ps)\n+\n @dispatch(Interval, Interval)  # type: ignore # noqa:F811\n def is_subset_sets(a, b): # noqa:F811\n     # This is correct but can be made more comprehensive...\n", "model": "claude-sonnet-5-5", "steps": 16, "finished": true, "patch_lines": 25, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 25, "steps": 16}], "ms": 178213}
{"instance_id": "sympy__sympy-20590", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sympy/core/_print_helpers.py b/sympy/core/_print_helpers.py\nindex 96d7e72676..f7875b9eec 100644\n--- a/sympy/core/_print_helpers.py\n+++ b/sympy/core/_print_helpers.py\n@@ -17,6 +17,8 @@ class Printable:\n     This also adds support for LaTeX printing in jupyter notebooks.\n     \"\"\"\n \n+    __slots__ = ()\n+\n     # Note, we always use the default ordering (lex) in __str__ and __repr__,\n     # regardless of the global setting. See issue 5487.\n     def __str__(self):\n", "model": "claude-sonnet-5-5", "steps": 8, "finished": true, "patch_lines": 13, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 13, "steps": 8}], "ms": 17120}
{"instance_id": "sympy__sympy-20801", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sympy/core/numbers.py b/sympy/core/numbers.py\nindex 79f6a7d165..a2557d5251 100644\n--- a/sympy/core/numbers.py\n+++ b/sympy/core/numbers.py\n@@ -1386,10 +1386,10 @@ def __eq__(self, other):\n             other = _sympify(other)\n         except SympifyError:\n             return NotImplemented\n-        if not self:\n-            return not other\n         if isinstance(other, Boolean):\n             return False\n+        if not self:\n+            return not other\n         if other.is_NumberSymbol:\n             if other.is_irrational:\n                 return False\n", "model": "claude-sonnet-5-5", "steps": 6, "finished": true, "patch_lines": 17, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 17, "steps": 6}], "ms": 15070}
