Ë
    7^(hŒ? ã                  óÌ  — d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 ddl
mZmZ ddlmZmZmZmZ ddlmZ dd	lmZ dd
lmZmZmZ ddlmZmZmZmZmZ ddl m!Z! ddl"m#Z#m$Z$ ddl%m&Z& ddl'm(Z(m)Z)m*Z* ddl+m,Z,m-Z- ddl.m/Z/ ddl0m1Z1m2Z2 ddl3m4Z4m5Z5 ddl6m7Z7m8Z8 ddl9m:Z: ddl;m<Z= ddl>m?Z? ddl@mAZAmBZBmCZC ddlDmEZE ddlFmGZG ddlHmIZJ ddlKmLZL ddlMmNZN ddlOmPZPmQZQmRZR ddlSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^ dd l_m`Z`maZambZbmcZcmdZdmeZe dd!lfmgZg dd"lhmiZi dd#ljmkZkmlZlmmZm dd$lnmoZo dd%lpmqZqmrZr dd&l;Zsdd&ltZtdd'lumvZv d(„ Zwel G d)„ d*e«      «       Zxel G d+„ d,ex«      «       Zyeld-„ «       Zzd.„ Z{eld/„ «       Z|d0„ Z}d1„ Z~eldyd2„«       Zeld3„ «       Z€eld4„ «       Z�eld5„ «       Z‚eld6„ «       Zƒeld7„ «       Z„eld8„ «       Z…eld9„ «       Z†eld:„ «       Z‡eld;„ «       Zˆeld<„ «       Z‰eld=„ «       ZŠeld>„ «       Z‹eld?„ «       ZŒeld@„ «       Z�eldA„ «       ZŽeldB„ «       Z�eldC„ «       Z�eldDdEœdF„«       Z‘eldG„ «       Z’eldH„ «       Z“eldI„ «       Z”eldzdJ„«       Z•eldK„ «       Z–eldzdL„«       Z—eldM„ «       Z˜eldN„ «       Z™eldO„ «       ZšeldP„ «       Z›eldQ„ «       ZœeldR„ «       Z�eldS„ «       ZželdT„ «       ZŸeldU„ «       Z eldV„ «       Z¡eldW„ «       Z¢eldX„ «       Z£dY„ Z¤dZ„ Z¥d[„ Z¦d\„ Z§d]„ Z¨d^„ Z©d_„ Zªd`„ Z«da„ Z¬eldb„ «       Z­eldc„ «       Z®eldd„ «       Z¯eldDdeœdf„«       Z°eld{dg„«       Z±eld|dh„«       Z²eld}di„«       Z³eld~dk„«       Z´eld~dl„«       Zµelddm„«       Z¶eldn„ «       Z·eldo„ «       Z¸eldjdpœdq„«       Z¹eldr„ «       Zºelds„ «       ZIeldt„ «       Z»el G du„ dve«      «       Z¼eldw„ «       Z½dx„ Z¾y&)€z8User-friendly public interface to polynomial functions. é    )Úannotations)ÚwrapsÚreduce©Úmul)ÚOptional)ÚCounterÚdefaultdict)ÚSÚExprÚAddÚTuple)ÚBasic)Ú
_sympifyit)ÚFactorsÚ	factor_ncÚfactor_terms)Úpure_complexÚevalfÚfastlogÚ_evalf_with_bounded_errorÚquad_to_mpmath)Ú
Derivative)ÚMulÚ_keep_coeff)Úilcm)ÚIÚIntegerÚequal_valued)Ú
RelationalÚEquality)Úordered)ÚDummyÚSymbol)ÚsympifyÚ_sympify)Úpreorder_traversalÚ	bottom_up)ÚBooleanAtom)Úpolyoptions)Úconstruct_domain)ÚFFÚQQÚZZ)ÚDomainElement)Úmatrix_fglm)Úgroebner)ÚMonomial)Úmonomial_key)ÚDMPÚDMFÚANP)ÚOperationNotSupportedÚDomainErrorÚCoercionFailedÚUnificationFailedÚGeneratorsNeededÚPolynomialErrorÚMultivariatePolynomialErrorÚExactQuotientFailedÚPolificationFailedÚComputationFailedÚGeneratorsError)Úbasic_from_dictÚ
_sort_gensÚ_unify_gensÚ_dict_reorderÚ_dict_from_exprÚ_parallel_dict_from_expr)Útogether)Údup_isolate_real_roots_list)ÚgroupÚpublicÚ
filldedent)Úsympy_deprecation_warning)ÚiterableÚsiftN)ÚNoConvergencec                ó.   ‡ — t        ‰ «      ˆ fd„«       }|S )Nc                ó  •— t        |«      }t        |t        «      r	 ‰| |«      S t        |t        «      r3 | j                  |g| j
                  ¢­d| j                  iŽ} ‰| |«      S t        |t        «      r'	  | j                  |g| j
                  ¢­Ž } ‰| |«      S t        S # t        $ r[ |j                  rt        cY S t        | j                  «       ‰j                  «      } ||«      }|t        urt        ddd¬«       |cY S w xY w)NÚdomaina@  
                        Mixing Poly with non-polynomial expressions in binary
                        operations is deprecated. Either explicitly convert
                        the non-Poly operand to a Poly with as_poly() or
                        convert the Poly to an Expr with as_expr().
                        z1.6z)deprecated-poly-nonpoly-binary-operations)Údeprecated_since_versionÚactive_deprecations_target)r&   Ú
isinstanceÚPolyr   Ú	from_exprÚgensrS   r   r<   Ú	is_MatrixÚNotImplementedÚgetattrÚas_exprÚ__name__rM   )ÚfÚgÚexpr_methodÚresultÚfuncs       €úS/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/sympy/polys/polytools.pyÚwrapperz_polifyit.<locals>.wrapperF   s÷   ø€ ä�Q‹KˆÜ�aœÔÙ˜˜1“:ÐÜ˜œ7Ô#Ø�—‘˜AÐ8 §¡Ò8¨q¯x©xÑ8ˆAÙ˜˜1“:ÐÜ˜œ4Ô ð"Ø�A—K‘K Ð+ A§F¡FÒ+�ñ& ˜A˜q“zÐ!ä!Ð!øô) #ò Ø—;’;Ü)Ò)Ü% a§i¡i£k°4·=±=ÓA�Ù$ Q›�Ø¤Ñ/Ü-ðð 27Ø3^õ	ð ’ð!ús   Á:B& Â&D
ÃAD
Ä	D
)r   )rc   re   s   ` rd   Ú	_polifyitrf   E   s    ø€ Ü
ˆ4ƒ[ó"ó ð"ð> €Nó    c                  ó$  ‡ — e Zd ZU dZdZdZdZdZded<   ded<   dÄd	„Z	e
d
„ «       Zed„ «       Zed„ «       Zd„ Ze
d„ «       Ze
d„ «       Ze
d„ «       Ze
d„ «       Ze
d„ «       Ze
d„ «       Ze
d„ «       Ze
d„ «       Ze
d„ «       Zˆ fd„Zed„ «       Zed„ «       Zed„ «       Zed„ «       Zed„ «       Zed„ «       Zd„ Z d„ Z!dÅd „Z"d!„ Z#d"„ Z$d#„ Z%d$„ Z&d%„ Z'd&„ Z(dÆd'„Z)d(„ Z*d)„ Z+d*„ Z,d+„ Z-d,„ Z.d-„ Z/d.„ Z0dÆd/„Z1dÆd0„Z2dÆd1„Z3dÆd2„Z4dÆd3„Z5d4„ Z6d5„ Z7d6„ Z8d7„ Z9d8„ Z:dÇd9„Z;dÈd:„Z<d;„ Z=d<„ Z>d=„ Z?d>„ Z@dÈd?„ZAd@„ ZBdA„ ZCdB„ ZDdC„ ZEdD„ ZFdE„ ZGdF„ ZHdG„ ZIdH„ ZJdI„ ZKdJ„ ZLdK„ ZMdL„ ZNdM„ ZOdN„ ZPdO„ ZQdP„ ZRdQ„ ZSdÉdR„ZTdÉdS„ZUdÉdT„ZVdÉdU„ZWdV„ ZXdÊdW„ZYdX„ ZZdY„ Z[dZ„ Z\d[„ Z]dÆd\„Z^d]„ Z_dÆd^„Z`d_„ Zad`„ ZbdËda„ZcdÆdb„ZddÆdc„ZedÆdd„ZfdÆde„Zgdf„ Zhdg„ ZidÈdh„Zjdi„ Zkdj„ Zldk„ ZmemZndÌdl„Zodm„ ZpdÉdn„ZqdÉdo„ZrdÉdp„Zsdq„ Ztdr„ ZudÈds„Zvdt„ ZwdÆdu„ZxdÆdv„Zydw„ Zzdx„ Z{dy„ Z|dz„ Z}dÉd{„Z~d|„ Zd}„ Z€d~„ Z�d„ Z‚d€„ Zƒd�„ Z„d‚„ Z…dÉdƒ„Z†d„„ Z‡d…„ Zˆd†„ Z‰d‡„ ZŠdÈdˆ„Z‹dÈd‰„ZŒdÍdŠ„Z�d‹„ ZŽdÎdŒ„Z�dÏd�„Z�dÅdŽ„Z‘dÉd�„Z’dÐd�„Z“dÐd‘„Z”dÑd’„Z•d“„ Z–d”„ Z—d•„ Z˜d–„ Z™d—„ Zšd˜„ Z›dÈd™„Zœdš„ Z�dÒd›„Zžedœ„ «       ZŸed�„ «       Z edž„ «       Z¡edŸ„ «       Z¢ed „ «       Z£ed¡„ «       Z¤ed¢„ «       Z¥ed£„ «       Z¦ed¤„ «       Z§ed¥„ «       Z¨ed¦„ «       Z©ed§„ «       Zªed¨„ «       Z«ed©„ «       Z¬dª„ Z­d«„ Z®e¯d¬„ «       Z°e¯d­„ «       Z±e¯d®„ «       Z²e¯d¯„ «       Z³e¯d°„ «       Z´e¯d±„ «       Zµ e¶d²e·«      d³„ «       Z¸e¯d´„ «       Z¹e¯dµ„ «       Zºe¯d¶„ «       Z»e¯d·„ «       Z¼e¯d¸„ «       Z½e¯d¹„ «       Z¾ e¶dºe·«      d»„ «       Z¿ e¶dºe·«      d¼„ «       ZÀ e¶d½e·«      d¾„ «       ZÁ e¶dºe·«      d¿„ «       ZÂdÀ„ ZÃdÈdÁ„ZÄdÈdÂ„ZÅdÃ„ ZÆˆ xZÇS )ÓrW   aP  
    Generic class for representing and operating on polynomial expressions.

    See :ref:`polys-docs` for general documentation.

    Poly is a subclass of Basic rather than Expr but instances can be
    converted to Expr with the :py:meth:`~.Poly.as_expr` method.

    .. deprecated:: 1.6

       Combining Poly with non-Poly objects in binary operations is
       deprecated. Explicitly convert both objects to either Poly or Expr
       first. See :ref:`deprecated-poly-nonpoly-binary-operations`.

    Examples
    ========

    >>> from sympy import Poly
    >>> from sympy.abc import x, y

    Create a univariate polynomial:

    >>> Poly(x*(x**2 + x - 1)**2)
    Poly(x**5 + 2*x**4 - x**3 - 2*x**2 + x, x, domain='ZZ')

    Create a univariate polynomial with specific domain:

    >>> from sympy import sqrt
    >>> Poly(x**2 + 2*x + sqrt(3), domain='R')
    Poly(1.0*x**2 + 2.0*x + 1.73205080756888, x, domain='RR')

    Create a multivariate polynomial:

    >>> Poly(y*x**2 + x*y + 1)
    Poly(x**2*y + x*y + 1, x, y, domain='ZZ')

    Create a univariate polynomial, where y is a constant:

    >>> Poly(y*x**2 + x*y + 1,x)
    Poly(y*x**2 + y*x + 1, x, domain='ZZ[y]')

    You can evaluate the above polynomial as a function of y:

    >>> Poly(y*x**2 + x*y + 1,x).eval(2)
    6*y + 1

    See Also
    ========

    sympy.core.expr.Expr

    ©ÚreprY   Tg�—nƒ $@r4   rj   ztuple[Expr, ...]rY   c                óä  — t        j                  ||«      }d|v rt        d«      ‚t        |t        t
        t        t        f«      r| j                  ||«      S t        |t        ¬«      r=t        |t        «      r| j                  ||«      S | j                  t        |«      |«      S t        |t!        |«      t        u¬«      }|j"                  r| j%                  ||«      S | j'                  ||«      S )z:Create a new polynomial instance out of something useful. Úorderz&'order' keyword is not implemented yet)Úexclude)Úevaluate)ÚoptionsÚbuild_optionsÚNotImplementedErrorrV   r4   r5   r6   r/   Ú_from_domain_elementrN   ÚstrÚdictÚ
_from_dictÚ
_from_listÚlistr%   ÚtypeÚis_PolyÚ
_from_polyÚ
_from_expr©Úclsrj   rY   ÚargsÚopts        rd   Ú__new__zPoly.__new__ª   sÅ   € ä×#Ñ# D¨$Ó/ˆà�c‰>Ü%Ð&NÓOÐOä�cœC¤¤c¬=Ð9Ô:Ø×+Ñ+¨C°Ó5Ð5Ü�c¤3Õ'Ü˜#œtÔ$Ø—~‘~ c¨3Ó/Ð/à—~‘~¤d¨3£i°Ó5Ð5ä˜#¬¨S«	¼Ð(<Ô=ˆCà�{Š{Ø—~‘~ c¨3Ó/Ð/à—~‘~ c¨3Ó/Ð/rg   c                óà   — t        |t        «      st        d|z  «      ‚|j                  t	        |«      dz
  k7  rt        d|›d|›�«      ‚t        j                  | «      }||_        ||_        |S )z:Construct :class:`Poly` instance from raw representation. z%invalid polynomial representation: %sé   zinvalid arguments: z, )	rV   r4   r<   ÚlevÚlenr   r€   rj   rY   )r}   rj   rY   Úobjs       rd   ÚnewzPoly.newÉ   sh   € ô ˜#œsÔ#Ü!Ø7¸#Ñ=ó?ð ?à�W‰Wœ˜D›	 A™Ò%Ý!ÂÁdÐ"KÓLÐLä�m‰m˜CÓ ˆØˆŒØˆŒàˆ
rg   c                ó^   — t        | j                  j                  «       g| j                  ¢­Ž S ©N)rB   rj   Úto_sympy_dictrY   ©Úselfs    rd   Úexprz	Poly.exprØ   s#   € ä˜tŸx™x×5Ñ5Ó7ÐD¸$¿)¹)ÒDÐDrg   c                ó6   — | j                   f| j                  z   S rˆ   )rŒ   rY   rŠ   s    rd   r~   z	Poly.argsÜ   s   € à—	‘	ˆ|˜dŸi™iÑ'Ð'rg   c                ó6   — | j                   f| j                  z   S rˆ   ri   rŠ   s    rd   Ú_hashable_contentzPoly._hashable_contentà   s   € Ø—‘ˆ{˜TŸY™YÑ&Ð&rg   c                óR   — t        j                  ||«      }| j                  ||«      S )ú(Construct a polynomial from a ``dict``. )ro   rp   ru   r|   s        rd   Ú	from_dictzPoly.from_dictã   ó'   € ô ×#Ñ# D¨$Ó/ˆØ�~‰~˜c 3Ó'Ð'rg   c                óR   — t        j                  ||«      }| j                  ||«      S )ú(Construct a polynomial from a ``list``. )ro   rp   rv   r|   s        rd   Ú	from_listzPoly.from_listé   r“   rg   c                óR   — t        j                  ||«      }| j                  ||«      S )ú*Construct a polynomial from a polynomial. )ro   rp   rz   r|   s        rd   Ú	from_polyzPoly.from_polyï   r“   rg   c                óR   — t        j                  ||«      }| j                  ||«      S ©ú+Construct a polynomial from an expression. )ro   rp   r{   r|   s        rd   rX   zPoly.from_exprõ   r“   rg   c                ó6  — |j                   }|st        d«      ‚t        |«      dz
  }|j                  }|€t	        ||¬«      \  }}n,|j                  «       D ]  \  }}|j                  |«      ||<   Œ  | j                  t        j                  |||«      g|¢­Ž S )r‘   z0Cannot initialize from 'dict' without generatorsr‚   ©r   )
rY   r;   r„   rS   r+   ÚitemsÚconvertr†   r4   r’   )r}   rj   r   rY   ÚlevelrS   ÚmonomÚcoeffs           rd   ru   zPoly._from_dictû   sŸ   € ð �x‰xˆáÜ"ØBóDð Dô �D“	˜A‘ˆØ—‘ˆàˆ>Ü*¨3°CÔ8‰KˆF‘Cà #§	¡	£ò 3‘��uØ#Ÿ^™^¨EÓ2��E’
ð3ð ˆs�w‰w”s—}‘} S¨%°Ó8Ð@¸4Ò@Ð@rg   c                óN  — |j                   }|st        d«      ‚t        |«      dk7  rt        d«      ‚t        |«      dz
  }|j                  }|€t        ||¬«      \  }}nt        t        |j                  |«      «      } | j                  t        j                  |||«      g|¢­Ž S )r•   z0Cannot initialize from 'list' without generatorsr‚   z#'list' representation not supportedrž   )rY   r;   r„   r=   rS   r+   rw   Úmapr    r†   r4   r–   )r}   rj   r   rY   r¡   rS   s         rd   rv   zPoly._from_list  s¢   € ð �x‰xˆáÜ"ØBóDð Dä�‹Y˜!Š^Ü-Ø5ó7ð 7ô �D“	˜A‘ˆØ—‘ˆàˆ>Ü*¨3°CÔ8‰KˆF‘Cä”s˜6Ÿ>™>¨3Ó/Ó0ˆCàˆs�w‰w”s—}‘} S¨%°Ó8Ð@¸4Ò@Ð@rg   c                óÖ  — | |j                   k7  r' | j                  |j                  g|j                  ¢­Ž }|j                  }|j                  }|j
                  }|r_|j                  |k7  rPt        |j                  «      t        |«      k7  r | j                  |j                  «       |«      S  |j                  |Ž }d|v r|r|j                  |«      }|S |du r|j                  «       }|S )r˜   rS   T)Ú	__class__r†   rj   rY   ÚfieldrS   Úsetr{   r]   ÚreorderÚ
set_domainÚto_field)r}   rj   r   rY   r¨   rS   s         rd   rz   zPoly._from_poly%  sÈ   € ð �#—-‘-ÒØ�#—'‘'˜#Ÿ'™'Ð- C§H¡HÒ-ˆCà�x‰xˆØ—	‘	ˆØ—‘ˆá�C—H‘H Ò$Ü�3—8‘8‹}¤ D£	Ò)Ø—~‘~ c§k¡k£m°SÓ9Ð9à!�c—k‘k 4Ð(�à�s‰?™vØ—.‘. Ó(ˆCð ˆ
ð �d‰]Ø—,‘,“.ˆCàˆ
rg   c                óD   — t        ||«      \  }}| j                  ||«      S r›   )rF   ru   )r}   rj   r   s      rd   r{   zPoly._from_expr<  s%   € ô # 3¨Ó,‰ˆˆSØ�~‰~˜c 3Ó'Ð'rg   c                óÂ   — |j                   }|j                  }t        |«      dz
  }|j                  |«      g} | j                  t        j                  |||«      g|¢­Ž S ©Nr‚   )rY   rS   r„   r    r†   r4   r–   )r}   rj   r   rY   rS   r¡   s         rd   rr   zPoly._from_domain_elementB  sU   € à�x‰xˆØ—‘ˆä�D“	˜A‘ˆØ�~‰~˜cÓ"Ð#ˆàˆs�w‰w”s—}‘} S¨%°Ó8Ð@¸4Ò@Ð@rg   c                ó    •— t         ‰| �  «       S rˆ   ©ÚsuperÚ__hash__©r‹   r§   s    €rd   r³   zPoly.__hash__L  ó   ø€ Ü‰wÑÓ!Ð!rg   c                óÚ   — t        «       }| j                  }t        t        |«      «      D ]0  }| j	                  «       D ]  }||   sŒ	|||   j
                  z  } Œ0 Œ2 || j                  z  S )a�  
        Free symbols of a polynomial expression.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y, z

        >>> Poly(x**2 + 1).free_symbols
        {x}
        >>> Poly(x**2 + y).free_symbols
        {x, y}
        >>> Poly(x**2 + y, x).free_symbols
        {x, y}
        >>> Poly(x**2 + y, x, z).free_symbols
        {x, y}

        )r©   rY   Úranger„   ÚmonomsÚfree_symbolsÚfree_symbols_in_domain)r‹   ÚsymbolsrY   Úir¢   s        rd   r¹   zPoly.free_symbolsO  sr   € ô* “%ˆØ�y‰yˆÜ”s˜4“yÓ!ò 	ˆAØŸ™›ò �Ø˜“8Ø˜t A™w×3Ñ3Ñ3�GÙñð	ð ˜×4Ñ4Ñ4Ð4rg   c                ó  — | j                   j                  t        «       }}|j                  r"|j                  D ]  }||j
                  z  }Œ |S |j                  r$| j                  «       D ]  }||j
                  z  }Œ |S )aj  
        Free symbols of the domain of ``self``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y

        >>> Poly(x**2 + 1).free_symbols_in_domain
        set()
        >>> Poly(x**2 + y).free_symbols_in_domain
        set()
        >>> Poly(x**2 + y, x).free_symbols_in_domain
        {y}

        )rj   Údomr©   Úis_Compositer»   r¹   Úis_EXÚcoeffs)r‹   rS   r»   Úgenr£   s        rd   rº   zPoly.free_symbols_in_domainn  s   € ð& Ÿ(™(Ÿ,™,¬«�ˆà×ÒØ—~‘~ò ,�Ø˜3×+Ñ+Ñ+‘ð,ð ˆð	 �\Š\ØŸ™›ò .�Ø˜5×-Ñ-Ñ-‘ð.ð ˆrg   c                ó    — | j                   d   S )zÊ
        Return the principal generator.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**2 + 1, x).gen
        x

        r   ©rY   rŠ   s    rd   rÂ   zPoly.genŒ  s   € ð �y‰y˜‰|Ðrg   c                ó"   — | j                  «       S )aŠ  Get the ground domain of a :py:class:`~.Poly`

        Returns
        =======

        :py:class:`~.Domain`:
            Ground domain of the :py:class:`~.Poly`.

        Examples
        ========

        >>> from sympy import Poly, Symbol
        >>> x = Symbol('x')
        >>> p = Poly(x**2 + x)
        >>> p
        Poly(x**2 + x, x, domain='ZZ')
        >>> p.domain
        ZZ
        )Ú
get_domainrŠ   s    rd   rS   zPoly.domain�  s   € ð* �‰Ó Ð rg   c                óÀ   —  | j                   | j                  j                  | j                  j                  | j                  j                  «      g| j
                  ¢­Ž S )z3Return zero polynomial with ``self``'s properties. )r†   rj   Úzerorƒ   r¾   rY   rŠ   s    rd   rÈ   z	Poly.zero´  s=   € ð ˆt�x‰x˜Ÿ™Ÿ™ d§h¡h§l¡l°D·H±H·L±LÓAÐNÀDÇIÁIÒNÐNrg   c                óÀ   —  | j                   | j                  j                  | j                  j                  | j                  j                  «      g| j
                  ¢­Ž S )z2Return one polynomial with ``self``'s properties. )r†   rj   Úonerƒ   r¾   rY   rŠ   s    rd   rÊ   zPoly.one¹  s=   € ð ˆt�x‰x˜Ÿ™Ÿ™ T§X¡X§\¡\°4·8±8·<±<Ó@ÐMÀ4Ç9Á9ÒMÐMrg   c                óN   — | j                  |«      \  }}}} ||«       ||«      fS )aÓ  
        Make ``f`` and ``g`` belong to the same domain.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> f, g = Poly(x/2 + 1), Poly(2*x + 1)

        >>> f
        Poly(1/2*x + 1, x, domain='QQ')
        >>> g
        Poly(2*x + 1, x, domain='ZZ')

        >>> F, G = f.unify(g)

        >>> F
        Poly(1/2*x + 1, x, domain='QQ')
        >>> G
        Poly(2*x + 1, x, domain='QQ')

        )Ú_unify)r_   r`   Ú_ÚperÚFÚGs         rd   Úunifyz
Poly.unify¾  s+   € ð2 —x‘x “{‰ˆˆ3��1Ù�1‹v‘s˜1“vˆ~Ðrg   c           
     ób  ‡— t        |«      }|j                  sm	 | j                  j                  j	                  |«      }| j                  j                  | j
                  | j                  | j                  j                  |«      fS t        | j                  t        «      �r<t        |j                  t        «      �r!t        | j                  |j                  «      }| j                  j                  j                  |j                  j                  |«      t        |«      dz
  }}| j                  |k7  r²t        | j                  j!                  «       | j                  |«      \  }}| j                  j                  |k7  r3|D �cg c](  }|j#                  || j                  j                  «      ‘Œ* }}t        j$                  t'        t)        t+        ||«      «      «      ||«      }	n| j                  j#                  |«      }	|j                  |k7  r²t        |j                  j!                  «       |j                  |«      \  }
}|j                  j                  |k7  r3|D �cg c](  }|j#                  ||j                  j                  «      ‘Œ* }}t        j$                  t'        t)        t+        |
|«      «      «      ||«      }n-|j                  j#                  |«      }nt        d| ›d|›�«      ‚| j,                  Š||d fˆfd„	}|||	|fS # t        $ r t        d| ›d|›�«      ‚w xY wc c}w c c}w )NúCannot unify ú with r‚   c                óp   •— |�!|d | ||dz   d  z   }|s|j                  | «      S  ‰j                  | g|¢­Ž S r¯   ©Úto_sympyr†   ©rj   r¾   rY   Úremover}   s       €rd   rÎ   zPoly._unify.<locals>.per  óL   ø€ ØÐ!Ø˜G˜V�} t¨F°Q©J¨KÐ'8Ñ8�áØŸ<™<¨Ó,Ð,à�3—7‘7˜3Ð& Ò&Ð&rg   )r%   ry   rj   r¾   Ú
from_sympyrÎ   Ú
ground_newr9   r:   rV   r4   rD   rY   rÑ   r„   rE   Úto_dictr    r’   rt   rw   Úzipr§   )r_   r`   Úg_coeffrY   r¾   rƒ   Úf_monomsÚf_coeffsÚcrÏ   Úg_monomsÚg_coeffsrÐ   rÎ   r}   s                 @rd   rÌ   zPoly._unifyÚ  sX  ø€ Ü�A‹Jˆà�yŠyðJØŸ%™%Ÿ)™)×.Ñ.¨qÓ1�ð —u‘u—y‘y !§%¡%¨¯©°·±×0@Ñ0@ÀÓ0IÐIÐIä�a—e‘eœSÕ!¤j°·±¼Õ&<Ü˜qŸv™v q§v¡vÓ.ˆDà—u‘u—y‘y—‘ q§u¡u§y¡y°$Ó7¼¸T»ÀQ¹�ˆCà�v‰v˜Š~Ü%2Ø—E‘E—M‘M“O Q§V¡V¨Tó&3Ñ"�˜(ð —5‘5—9‘9 Ò#ØCKÖL¸a §¡¨A¨q¯u©u¯y©yÕ 9ÐL�HÐLä—M‘M¤$¤t¬C°¸(Ó,CÓ'DÓ"EÀsÈCÓP‘à—E‘E—M‘M #Ó&�à�v‰v˜Š~Ü%2Ø—E‘E—M‘M“O Q§V¡V¨Tó&3Ñ"�˜(ð —5‘5—9‘9 Ò#ØCKÖL¸a §¡¨A¨q¯u©u¯y©yÕ 9ÐL�HÐLä—M‘M¤$¤t¬C°¸(Ó,CÓ'DÓ"EÀsÈCÓP‘à—E‘E—M‘M #Ó&‘å#ÂÁAÐ$FÓGÐGà�k‰kˆà 4°õ 	'ð �C˜˜Aˆ~Ðøô[ "ò LÝ'ÂQÉÐ(JÓKÐKðLüò  Mùò  Ms   š%L	 Æ-L'É-L,Ì	L$c                óÆ   — |€| j                   }|�5|d| ||dz   d z   }|s%| j                  j                  j                  |«      S  | j                  j
                  |g|¢­Ž S )ab  
        Create a Poly out of the given representation.

        Examples
        ========

        >>> from sympy import Poly, ZZ
        >>> from sympy.abc import x, y

        >>> from sympy.polys.polyclasses import DMP

        >>> a = Poly(x**2 + 1)

        >>> a.per(DMP([ZZ(1), ZZ(1)], ZZ), gens=[y])
        Poly(y + 1, y, domain='ZZ')

        Nr‚   )rY   rj   r¾   r×   r§   r†   )r_   rj   rY   rÙ   s       rd   rÎ   zPoly.per  si   € ð$ ˆ<Ø—6‘6ˆDàÐØ˜˜�= 4¨°©
¨Ð#4Ñ4ˆDáØ—u‘u—y‘y×)Ñ)¨#Ó.Ð.àˆq�{‰{�‰˜sÐ* TÒ*Ð*rg   c                ó®   — t        j                  | j                  d|i«      }| j                  | j                  j                  |j                  «      «      S )z Set the ground domain of ``f``. rS   )ro   rp   rY   rÎ   rj   r    rS   )r_   rS   r   s      rd   r«   zPoly.set_domain,  s=   € ä×#Ñ# A§F¡F¨X°vÐ,>Ó?ˆØ�u‰u�Q—U‘U—]‘] 3§:¡:Ó.Ó/Ð/rg   c                ó.   — | j                   j                  S )z Get the ground domain of ``f``. )rj   r¾   ©r_   s    rd   rÆ   zPoly.get_domain1  s   € à�u‰u�y‰yÐrg   c                ót   — t         j                  j                  |«      }| j                  t	        |«      «      S )zò
        Set the modulus of ``f``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(5*x**2 + 2*x - 1, x).set_modulus(2)
        Poly(x**2 + 1, x, modulus=2)

        )ro   ÚModulusÚ
preprocessr«   r,   )r_   Úmoduluss     rd   Úset_moduluszPoly.set_modulus5  s+   € ô —/‘/×,Ñ,¨WÓ5ˆØ�|‰|œB˜w›KÓ(Ð(rg   c                ó‚   — | j                  «       }|j                  rt        |j                  «       «      S t	        d«      ‚)zÖ
        Get the modulus of ``f``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**2 + 1, modulus=2).get_modulus()
        2

        z$not a polynomial over a Galois field)rÆ   Úis_FiniteFieldr   Úcharacteristicr<   )r_   rS   s     rd   Úget_moduluszPoly.get_modulusF  s8   € ð —‘“ˆà× Ò Ü˜6×0Ñ0Ó2Ó3Ð3ä!Ð"HÓIÐIrg   c                óÞ   — || j                   v r1|j                  r| j                  ||«      S 	 | j                  ||«      S | j                  «       j                  ||«      S # t        $ r Y Œ+w xY w)z)Internal implementation of :func:`subs`. )rY   Ú	is_numberÚevalÚreplacer<   r]   Úsubs)r_   Úoldr†   s      rd   Ú
_eval_subszPoly._eval_subs[  sj   € à�!—&‘&‰=Ø�}Š}Ø—v‘v˜c 3Ó'Ð'ðØŸ9™9 S¨#Ó.Ð.ð �y‰y‹{×Ñ  SÓ)Ð)øô 'ò Ùðús   ®A  Á 	A,Á+A,c                óÆ   — | j                   j                  «       \  }}t        | j                  «      D ��cg c]  \  }}||vsŒ|‘Œ }}}| j	                  ||¬«      S c c}}w )a  
        Remove unnecessary generators from ``f``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import a, b, c, d, x

        >>> Poly(a + x, a, b, c, d, x).exclude()
        Poly(a + x, a, x, domain='ZZ')

        rÄ   )rj   rm   Ú	enumeraterY   rÎ   )r_   ÚJr†   ÚjrÂ   rY   s         rd   rm   zPoly.excludeh  sV   € ð —‘—‘“‰ˆˆ3Ü"+¨A¯F©FÓ"3×B™˜˜3°qÀ²z’ÐBˆÑBà�u‰u�S˜tˆuÓ$Ð$ùó Cs   ¶AÁAc                ó¼  — |€&| j                   r| j                  |}}nt        d«      ‚||k(  s|| j                  vr| S || j                  v r~|| j                  vrp| j	                  «       }|j
                  r||j                  vrFt        | j                  «      }|||j                  |«      <   | j                  | j                  |¬«      S t        d|›d|›d| ›�«      ‚)a  
        Replace ``x`` with ``y`` in generators list.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y

        >>> Poly(x**2 + 1, x).replace(x, y)
        Poly(y**2 + 1, y, domain='ZZ')

        z(syntax supported only in univariate caserÄ   zCannot replace rÔ   ú in )Úis_univariaterÂ   r<   rY   rÆ   r¿   r»   rw   ÚindexrÎ   rj   )r_   ÚxÚyÚ_ignorer¾   rY   s         rd   rõ   zPoly.replace{  sÃ   € ð ˆ9Ø�ŠØ—u‘u˜a�1‘ä%Ø>ó@ð @ð �Š6�Q˜aŸf™f‘_ØˆHà�—‘‰;˜1 A§F¡F™?Ø—,‘,“.ˆCà×#Ò# q°·±Ñ';Ü˜AŸF™F“|�Ø&'��T—Z‘Z “]Ñ#Ø—u‘u˜QŸU™U¨�uÓ.Ð.åÂ1ÂaÉÐKÓLÐLrg   c                óB   —  | j                  «       j                  |i |¤ŽS )z-Match expression from Poly. See Basic.match())r]   Úmatch)r_   r~   Úkwargss      rd   r  z
Poly.matchž  s    € à ˆq�y‰y‹{× Ñ  $Ð1¨&Ñ1Ð1rg   c                óØ  — t        j                  d|«      }|st        | j                  |¬«      }n,t	        | j                  «      t	        |«      k7  rt        d«      ‚t        t        t        t        | j                  j                  «       | j                  |«      Ž «      «      }| j                  t        j                  |t        |«      dz
  | j                  j                   «      |¬«      S )a  
        Efficiently apply new order of generators.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y

        >>> Poly(x**2 + x*y**2, x, y).reorder(y, x)
        Poly(y**2*x + x**2, y, x, domain='ZZ')

        © rž   z7generators list can differ only up to order of elementsr‚   rÄ   )ro   ÚOptionsrC   rY   r©   r<   rt   rw   rÞ   rE   rj   rÝ   rÎ   r4   r’   r„   r¾   )r_   rY   r~   r   rj   s        rd   rª   zPoly.reorder¢  sª   € ô �o‰o˜b $Ó'ˆáÜ˜aŸf™f¨#Ô.‰DÜ�—‘‹[œC ›IÒ%Ü!ØIóKð Kô ”4œœ]¨1¯5©5¯=©=«?¸A¿F¹FÀDÓIÐJÓKÓLˆà�u‰u”S—]‘] 3¬¨D«	°A©°q·u±u·y±yÓAÈˆuÓMÐMrg   c                ór  — | j                  d¬«      }| j                  |«      }i }|j                  «       D ])  \  }}t        |d| «      rt	        d| z  «      ‚||||d <   Œ+ | j
                  |d } | j                  t        j                  |t        |«      dz
  | j                  j                  «      g|¢­Ž S )a(  
        Remove dummy generators from ``f`` that are to the left of
        specified ``gen`` in the generators as ordered. When ``gen``
        is an integer, it refers to the generator located at that
        position within the tuple of generators of ``f``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y, z

        >>> Poly(y**2 + y*z**2, x, y, z).ltrim(y)
        Poly(y**2 + y*z**2, y, z, domain='ZZ')
        >>> Poly(z, x, y, z).ltrim(-1)
        Poly(z, z, domain='ZZ')

        T)ÚnativeNzCannot left trim %sr‚   )Úas_dictÚ_gen_to_levelrŸ   Úanyr<   rY   r†   r4   r’   r„   rj   r¾   )r_   rÂ   rj   rü   Útermsr¢   r£   rY   s           rd   Últrimz
Poly.ltrim¼  s²   € ð& �i‰i˜tˆiÓ$ˆØ�O‰O˜CÓ ˆàˆàŸI™I›Kò 	%‰LˆE�5ä�5˜˜!�9Œ~ä%Ð&;¸aÑ&?Ó@Ð@à$ˆE�%˜˜�)Òð	%ð �v‰v�a�bˆzˆàˆq�u‰u”S—]‘] 5¬#¨d«)°a©-¸¿¹¿¹ÓCÐKÀdÒKÐKrg   c                ó   — t        «       }|D ]/  }	 | j                  j                  |«      }|j                  |«       Œ1 | j                  «       D ]  }t        |«      D ]  \  }}||vsŒ|sŒ  y Œ! y# t        $ r t        | ›d|›d�«      ‚w xY w)aJ  
        Return ``True`` if ``Poly(f, *gens)`` retains ground domain.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y, z

        >>> Poly(x*y + 1, x, y, z).has_only_gens(x, y)
        True
        >>> Poly(x*y + z, x, y, z).has_only_gens(x, y)
        False

        ú doesn't have ú as generatorFT)r©   rY   r   ÚaddÚ
ValueErrorrA   r¸   rú   )r_   rY   ÚindicesrÂ   r   r¢   r¼   Úelts           rd   Úhas_only_genszPoly.has_only_gensà  sª   € ô  “%ˆàò 	#ˆCð#ØŸ™Ÿ™ SÓ)�ð
 —‘˜EÕ"ð	#ð —X‘X“Zò 	!ˆEÜ# EÓ*ò !‘��3Ø˜GÒ#ªÚ ñ!ð	!ð
 øô ò BÜ%Ú9:ºCÐ@óBð BðBús   ‘A2Á2Bc                óž   — t        | j                  d«      r| j                  j                  «       }nt        | d«      ‚| j	                  |«      S )zø
        Make the ground domain a ring.

        Examples
        ========

        >>> from sympy import Poly, QQ
        >>> from sympy.abc import x

        >>> Poly(x**2 + 1, domain=QQ).to_ring()
        Poly(x**2 + 1, x, domain='ZZ')

        Úto_ring)Úhasattrrj   r  r7   rÎ   ©r_   rb   s     rd   r  zPoly.to_ring  s<   € ô �1—5‘5˜)Ô$Ø—U‘U—]‘]“_‰Fä'¨¨9Ó5Ð5à�u‰u�V‹}Ðrg   c                óž   — t        | j                  d«      r| j                  j                  «       }nt        | d«      ‚| j	                  |«      S )zý
        Make the ground domain a field.

        Examples
        ========

        >>> from sympy import Poly, ZZ
        >>> from sympy.abc import x

        >>> Poly(x**2 + 1, x, domain=ZZ).to_field()
        Poly(x**2 + 1, x, domain='QQ')

        r¬   )r  rj   r¬   r7   rÎ   r  s     rd   r¬   zPoly.to_field  ó=   € ô �1—5‘5˜*Ô%Ø—U‘U—^‘^Ó%‰Fä'¨¨:Ó6Ð6à�u‰u�V‹}Ðrg   c                óž   — t        | j                  d«      r| j                  j                  «       }nt        | d«      ‚| j	                  |«      S )zý
        Make the ground domain exact.

        Examples
        ========

        >>> from sympy import Poly, RR
        >>> from sympy.abc import x

        >>> Poly(x**2 + 1.0, x, domain=RR).to_exact()
        Poly(x**2 + 1, x, domain='QQ')

        Úto_exact)r  rj   r   r7   rÎ   r  s     rd   r   zPoly.to_exact,  r  rg   c                ó°   — t        | j                  d¬«      || j                  j                  xs d¬«      \  }}| j	                  || j
                  |¬«      S )a   
        Recalculate the ground domain of a polynomial.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> f = Poly(x**2 + 1, x, domain='QQ[y]')
        >>> f
        Poly(x**2 + 1, x, domain='QQ[y]')

        >>> f.retract()
        Poly(x**2 + 1, x, domain='ZZ')
        >>> f.retract(field=True)
        Poly(x**2 + 1, x, domain='QQ')

        T©rÈ   N)r¨   Ú	composite©rS   )r+   r  rS   r¿   r’   rY   )r_   r¨   r¾   rj   s       rd   ÚretractzPoly.retractA  sM   € ô( $ A§I¡I°4 IÓ$8Ø 1§8¡8×#8Ñ#8Ò#@¸DôB‰ˆˆSà�{‰{˜3 §¡¨sˆ{Ó3Ð3rg   c                ó  — |€d||}}}n| j                  |«      }t        |«      t        |«      }}t        | j                  d«      r| j                  j	                  |||«      }nt        | d«      ‚| j                  |«      S )z1Take a continuous subsequence of terms of ``f``. r   Úslice)r  Úintr  rj   r'  r7   rÎ   )r_   r  ÚmÚnrü   rb   s         rd   r'  z
Poly.sliceY  sr   € àˆ9Ø˜˜A�!ˆq‰Aà—‘ Ó"ˆAä�1‹v”s˜1“vˆ1ˆä�1—5‘5˜'Ô"Ø—U‘U—[‘[  A qÓ)‰Fä'¨¨7Ó3Ð3à�u‰u�V‹}Ðrg   c                ó¦   — | j                   j                  |¬«      D �cg c]'  }| j                   j                  j                  |«      ‘Œ) c}S c c}w )aQ  
        Returns all non-zero coefficients from ``f`` in lex order.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**3 + 2*x + 3, x).coeffs()
        [1, 2, 3]

        See Also
        ========
        all_coeffs
        coeff_monomial
        nth

        ©rl   )rj   rÁ   r¾   r×   )r_   rl   râ   s      rd   rÁ   zPoly.coeffsi  s:   € ð( 01¯u©u¯|©|À%¨|Ó/HÖI¨!�—‘—	‘	×"Ñ" 1Õ%ÒIÐIùÒIs   Ÿ,Ac                ó:   — | j                   j                  |¬«      S )aU  
        Returns all non-zero monomials from ``f`` in lex order.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y

        >>> Poly(x**2 + 2*x*y**2 + x*y + 3*y, x, y).monoms()
        [(2, 0), (1, 2), (1, 1), (0, 1)]

        See Also
        ========
        all_monoms

        r,  )rj   r¸   ©r_   rl   s     rd   r¸   zPoly.monoms  s   € ð$ �u‰u�|‰| %ˆ|Ó(Ð(rg   c                ó¶   — | j                   j                  |¬«      D ��cg c],  \  }}|| j                   j                  j                  |«      f‘Œ. c}}S c c}}w )ac  
        Returns all non-zero terms from ``f`` in lex order.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y

        >>> Poly(x**2 + 2*x*y**2 + x*y + 3*y, x, y).terms()
        [((2, 0), 1), ((1, 2), 2), ((1, 1), 1), ((0, 1), 3)]

        See Also
        ========
        all_terms

        r,  )rj   r  r¾   r×   )r_   rl   r)  râ   s       rd   r  z
Poly.terms“  sC   € ð$ 89·u±u·{±{È°{Ó7O×P©t¨q°!��A—E‘E—I‘I×&Ñ& qÓ)Ò*ÓPÐPùÓPs    1Ac                ó¢   — | j                   j                  «       D �cg c]'  }| j                   j                  j                  |«      ‘Œ) c}S c c}w )a  
        Returns all coefficients from a univariate polynomial ``f``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**3 + 2*x - 1, x).all_coeffs()
        [1, 0, 2, -1]

        )rj   Ú
all_coeffsr¾   r×   )r_   râ   s     rd   r1  zPoly.all_coeffs§  s8   € ð 01¯u©u×/?Ñ/?Ó/AÖB¨!�—‘—	‘	×"Ñ" 1Õ%ÒBÐBùÒBs   �,Ac                ó6   — | j                   j                  «       S )a?  
        Returns all monomials from a univariate polynomial ``f``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**3 + 2*x - 1, x).all_monoms()
        [(3,), (2,), (1,), (0,)]

        See Also
        ========
        all_terms

        )rj   Ú
all_monomsrè   s    rd   r3  zPoly.all_monoms·  s   € ð$ �u‰u×ÑÓ!Ð!rg   c                ó²   — | j                   j                  «       D ��cg c],  \  }}|| j                   j                  j                  |«      f‘Œ. c}}S c c}}w )a  
        Returns all terms from a univariate polynomial ``f``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**3 + 2*x - 1, x).all_terms()
        [((3,), 1), ((2,), 0), ((1,), 2), ((0,), -1)]

        )rj   Ú	all_termsr¾   r×   )r_   r)  râ   s      rd   r5  zPoly.all_termsË  s?   € ð 89·u±u·±Ó7H×I©t¨q°!��A—E‘E—I‘I×&Ñ& qÓ)Ò*ÓIÐIùÓIs   ž1Ac                óô   — i }| j                  «       D ]@  \  }} |||«      }t        |t        «      r|\  }}n|}|sŒ*||vr|||<   Œ4t        d|z  «      ‚  | j                  |g|xs | j
                  ¢­i |¤ŽS )ah  
        Apply a function to all terms of ``f``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> def func(k, coeff):
        ...     k = k[0]
        ...     return coeff//10**(2-k)

        >>> Poly(x**2 + 20*x + 400).termwise(func)
        Poly(x**2 + 2*x + 4, x, domain='ZZ')

        z%s monomial was generated twice)r  rV   Útupler<   r’   rY   )r_   rc   rY   r~   r  r¢   r£   rb   s           rd   ÚtermwisezPoly.termwiseÛ  s˜   € ð$ ˆàŸG™G›Iò 	C‰LˆE�5Ù˜% Ó'ˆFä˜&¤%Ô(Ø%‘�‘uà�âØ Ñ%Ø#(�E˜%’Lä)Ø9¸EÑAóCð Cð	Cð ˆq�{‰{˜5Ð< D¢N¨A¯F©FÒ<°tÑ<Ð<rg   c                ó4   — t        | j                  «       «      S )zá
        Returns the number of non-zero terms in ``f``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**2 + 2*x - 1).length()
        3

        )r„   r  rè   s    rd   ÚlengthzPoly.length   s   € ô �1—9‘9“;ÓÐrg   c                óv   — |r| j                   j                  |¬«      S | j                   j                  |¬«      S )a  
        Switch to a ``dict`` representation.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y

        >>> Poly(x**2 + 2*x*y**2 - y, x, y).as_dict()
        {(0, 1): -1, (1, 2): 2, (2, 0): 1}

        r"  )rj   rÝ   r‰   )r_   r  rÈ   s      rd   r  zPoly.as_dict  s4   € ñ Ø—5‘5—=‘= d�=Ó+Ð+à—5‘5×&Ñ&¨DÐ&Ó1Ð1rg   c                ón   — |r| j                   j                  «       S | j                   j                  «       S )z%Switch to a ``list`` representation. )rj   Úto_listÚto_sympy_list)r_   r  s     rd   Úas_listzPoly.as_list#  s(   € áØ—5‘5—=‘=“?Ð"à—5‘5×&Ñ&Ó(Ð(rg   c                óv  — |s| j                   S t        |«      dk(  r\t        |d   t        «      rI|d   }t	        | j
                  «      }|j                  «       D ]  \  }}	 |j                  |«      }|||<   Œ t        | j                  j                  «       g|¢­Ž S # t        $ r t        | ›d|›d�«      ‚w xY w)ar  
        Convert a Poly instance to an Expr instance.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y

        >>> f = Poly(x**2 + 2*x*y**2 - y, x, y)

        >>> f.as_expr()
        x**2 + 2*x*y**2 - y
        >>> f.as_expr({x: 5})
        10*y**2 - y + 25
        >>> f.as_expr(5, 6)
        379

        r‚   r   r  r  )rŒ   r„   rV   rt   rw   rY   rŸ   r   r  rA   rB   rj   r‰   )r_   rY   ÚmappingrÂ   Úvaluer   s         rd   r]   zPoly.as_expr*  s½   € ñ( Ø—6‘6ˆMäˆt‹9˜Š>œj¨¨a©´$Ô7Ø˜1‘gˆGÜ˜Ÿ™“<ˆDà%Ÿm™m›oò (‘
��Uð(Ø ŸJ™J s›O�Eð
 #(�D˜’Kð(ô ˜qŸu™u×2Ñ2Ó4Ð<°tÒ<Ð<øô "ò FÜ)Ú=>ÂÐDóFð FðFús   Á!BÂB8c                ó^   — 	 t        | g|¢­i |¤Ž}|j                  sy|S # t        $ r Y yw xY w)a{  Converts ``self`` to a polynomial or returns ``None``.

        >>> from sympy import sin
        >>> from sympy.abc import x, y

        >>> print((x**2 + x*y).as_poly())
        Poly(x**2 + x*y, x, y, domain='ZZ')

        >>> print((x**2 + x*y).as_poly(x, y))
        Poly(x**2 + x*y, x, y, domain='ZZ')

        >>> print((x**2 + sin(y)).as_poly(x, y))
        None

        N)rW   ry   r<   )r‹   rY   r~   Úpolys       rd   Úas_polyzPoly.as_polyP  s<   € ð 	Ü˜Ð,˜tÒ, tÑ,ˆDà—<’<Øà�øÜò 	Ùð	ús   ‚  ž   	,«,c                óž   — t        | j                  d«      r| j                  j                  «       }nt        | d«      ‚| j	                  |«      S )a  
        Convert algebraic coefficients to rationals.

        Examples
        ========

        >>> from sympy import Poly, I
        >>> from sympy.abc import x

        >>> Poly(x**2 + I*x + 1, x, extension=I).lift()
        Poly(x**4 + 3*x**2 + 1, x, domain='QQ')

        Úlift)r  rj   rG  r7   rÎ   r  s     rd   rG  z	Poly.liftj  s<   € ô �1—5‘5˜&Ô!Ø—U‘U—Z‘Z“\‰Fä'¨¨6Ó2Ð2à�u‰u�V‹}Ðrg   c                ó¨   — t        | j                  d«      r| j                  j                  «       \  }}nt        | d«      ‚|| j	                  |«      fS )a+  
        Reduce degree of ``f`` by mapping ``x_i**m`` to ``y_i``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y

        >>> Poly(x**6*y**2 + x**3 + 1, x, y).deflate()
        ((3, 2), Poly(x**2*y + x + 1, x, y, domain='ZZ'))

        Údeflate)r  rj   rI  r7   rÎ   ©r_   rû   rb   s      rd   rI  zPoly.deflate  sE   € ô �1—5‘5˜)Ô$ØŸ™Ÿ™›‰IˆA‰vä'¨¨9Ó5Ð5à�!—%‘%˜“-ÐÐrg   c                óŒ  — | j                   j                  }|j                  r| S |j                  st	        d|z  «      ‚t        | j                   d«      r| j                   j                  |¬«      }nt        | d«      ‚|r|j                  | j                  z   }n| j                  |j                  z   } | j                  |g|¢­Ž S )a�  
        Inject ground domain generators into ``f``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y

        >>> f = Poly(x**2*y + x*y**3 + x*y + 1, x)

        >>> f.inject()
        Poly(x**2*y + x*y**3 + x*y + 1, x, y, domain='ZZ')
        >>> f.inject(front=True)
        Poly(y**3*x + y*x**2 + y*x + 1, y, x, domain='ZZ')

        z Cannot inject generators over %sÚinject©Úfront)rj   r¾   Úis_Numericalry   r8   r  rL  r7   r»   rY   r†   )r_   rN  r¾   rb   rY   s        rd   rL  zPoly.inject”  s£   € ð$ �e‰e�i‰iˆà×ÒØˆHØ—’ÜÐ@À3ÑFÓGÐGä�1—5‘5˜(Ô#Ø—U‘U—\‘\¨�\Ó.‰Fä'¨¨8Ó4Ð4áØ—;‘; §¡Ñ'‰Dà—6‘6˜CŸK™KÑ'ˆDàˆq�u‰u�VÐ#˜dÒ#Ð#rg   c                óæ  — | j                   j                  }|j                  st        d|z  «      ‚t	        |«      }| j
                  d| |k(  r| j
                  |d d}}n1| j
                  | d |k(  r| j
                  d|  d}}nt        d«      ‚ |j                  |Ž }t        | j                   d«      r| j                   j                  ||¬«      }nt        | d«      ‚ | j                  |g|¢­Ž S )aŽ  
        Eject selected generators into the ground domain.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y

        >>> f = Poly(x**2*y + x*y**3 + x*y + 1, x, y)

        >>> f.eject(x)
        Poly(x*y**3 + (x**2 + x)*y + 1, y, domain='ZZ[x]')
        >>> f.eject(y)
        Poly(y*x**2 + (y**3 + y)*x + 1, x, domain='ZZ[y]')

        zCannot eject generators over %sNTFz'can only eject front or back generatorsÚejectrM  )rj   r¾   rO  r8   r„   rY   rq   rL  r  rQ  r7   r†   )r_   rY   r¾   ÚkÚ_gensrN  rb   s          rd   rQ  z
Poly.eject¹  së   € ð$ �e‰e�i‰iˆà×ÒÜÐ?À#ÑEÓFÐFä�‹Iˆà�6‰6�"�1ˆ:˜ÒØŸ6™6 ! "˜: t�5‰EØ�V‰V�Q�B�Cˆ[˜DÒ ØŸ6™6 # A 2˜;¨�5‰Eä%Ø9ó;ð ;ð ˆc�j‰j˜$Ðˆä�1—5‘5˜'Ô"Ø—U‘U—[‘[ ¨E�[Ó2‰Fä'¨¨7Ó3Ð3àˆq�u‰u�VÐ$˜eÒ$Ð$rg   c                ó¨   — t        | j                  d«      r| j                  j                  «       \  }}nt        | d«      ‚|| j	                  |«      fS )a  
        Remove GCD of terms from the polynomial ``f``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y

        >>> Poly(x**6*y**2 + x**3*y, x, y).terms_gcd()
        ((3, 1), Poly(x**3*y + 1, x, y, domain='ZZ'))

        Ú	terms_gcd)r  rj   rU  r7   rÎ   rJ  s      rd   rU  zPoly.terms_gcdã  sF   € ô �1—5‘5˜+Ô&ØŸ™Ÿ™Ó)‰IˆA‰vä'¨¨;Ó7Ð7à�!—%‘%˜“-ÐÐrg   c                ó    — t        | j                  d«      r| j                  j                  |«      }nt        | d«      ‚| j	                  |«      S )zö
        Add an element of the ground domain to ``f``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x + 1).add_ground(2)
        Poly(x + 3, x, domain='ZZ')

        Ú
add_ground)r  rj   rW  r7   rÎ   ©r_   r£   rb   s      rd   rW  zPoly.add_groundø  óA   € ô �1—5‘5˜,Ô'Ø—U‘U×%Ñ% eÓ,‰Fä'¨¨<Ó8Ð8à�u‰u�V‹}Ðrg   c                ó    — t        | j                  d«      r| j                  j                  |«      }nt        | d«      ‚| j	                  |«      S )zý
        Subtract an element of the ground domain from ``f``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x + 1).sub_ground(2)
        Poly(x - 1, x, domain='ZZ')

        Ú
sub_ground)r  rj   r[  r7   rÎ   rX  s      rd   r[  zPoly.sub_ground  rY  rg   c                ó    — t        | j                  d«      r| j                  j                  |«      }nt        | d«      ‚| j	                  |«      S )zÿ
        Multiply ``f`` by a an element of the ground domain.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x + 1).mul_ground(2)
        Poly(2*x + 2, x, domain='ZZ')

        Ú
mul_ground)r  rj   r]  r7   rÎ   rX  s      rd   r]  zPoly.mul_ground"  rY  rg   c                ó    — t        | j                  d«      r| j                  j                  |«      }nt        | d«      ‚| j	                  |«      S )aO  
        Quotient of ``f`` by a an element of the ground domain.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(2*x + 4).quo_ground(2)
        Poly(x + 2, x, domain='ZZ')

        >>> Poly(2*x + 3).quo_ground(2)
        Poly(x + 1, x, domain='ZZ')

        Ú
quo_ground)r  rj   r_  r7   rÎ   rX  s      rd   r_  zPoly.quo_ground7  sA   € ô" �1—5‘5˜,Ô'Ø—U‘U×%Ñ% eÓ,‰Fä'¨¨<Ó8Ð8à�u‰u�V‹}Ðrg   c                ó    — t        | j                  d«      r| j                  j                  |«      }nt        | d«      ‚| j	                  |«      S )a£  
        Exact quotient of ``f`` by a an element of the ground domain.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(2*x + 4).exquo_ground(2)
        Poly(x + 2, x, domain='ZZ')

        >>> Poly(2*x + 3).exquo_ground(2)
        Traceback (most recent call last):
        ...
        ExactQuotientFailed: 2 does not divide 3 in ZZ

        Úexquo_ground)r  rj   ra  r7   rÎ   rX  s      rd   ra  zPoly.exquo_groundO  sA   € ô& �1—5‘5˜.Ô)Ø—U‘U×'Ñ'¨Ó.‰Fä'¨¨>Ó:Ð:à�u‰u�V‹}Ðrg   c                óž   — t        | j                  d«      r| j                  j                  «       }nt        | d«      ‚| j	                  |«      S )zò
        Make all coefficients in ``f`` positive.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**2 - 1, x).abs()
        Poly(x**2 + 1, x, domain='ZZ')

        Úabs)r  rj   rc  r7   rÎ   r  s     rd   rc  zPoly.absi  s<   € ô �1—5‘5˜%Ô Ø—U‘U—Y‘Y“[‰Fä'¨¨5Ó1Ð1à�u‰u�V‹}Ðrg   c                óž   — t        | j                  d«      r| j                  j                  «       }nt        | d«      ‚| j	                  |«      S )a4  
        Negate all coefficients in ``f``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**2 - 1, x).neg()
        Poly(-x**2 + 1, x, domain='ZZ')

        >>> -Poly(x**2 - 1, x)
        Poly(-x**2 + 1, x, domain='ZZ')

        Úneg)r  rj   re  r7   rÎ   r  s     rd   re  zPoly.neg~  ó<   € ô" �1—5‘5˜%Ô Ø—U‘U—Y‘Y“[‰Fä'¨¨5Ó1Ð1à�u‰u�V‹}Ðrg   c                óö   — t        |«      }|j                  s| j                  |«      S | j                  |«      \  }}}}t	        | j
                  d«      r|j                  |«      }nt        | d«      ‚ ||«      S )a[  
        Add two polynomials ``f`` and ``g``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**2 + 1, x).add(Poly(x - 2, x))
        Poly(x**2 + x - 1, x, domain='ZZ')

        >>> Poly(x**2 + 1, x) + Poly(x - 2, x)
        Poly(x**2 + x - 1, x, domain='ZZ')

        r  )r%   ry   rW  rÌ   r  rj   r  r7   ©r_   r`   rÍ   rÎ   rÏ   rÐ   rb   s          rd   r  zPoly.add–  ói   € ô" �A‹Jˆà�yŠyØ—<‘< “?Ð"à—x‘x “{‰ˆˆ3��1ä�1—5‘5˜%Ô Ø—U‘U˜1“X‰Fä'¨¨5Ó1Ð1á�6‹{Ðrg   c                óö   — t        |«      }|j                  s| j                  |«      S | j                  |«      \  }}}}t	        | j
                  d«      r|j                  |«      }nt        | d«      ‚ ||«      S )a`  
        Subtract two polynomials ``f`` and ``g``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**2 + 1, x).sub(Poly(x - 2, x))
        Poly(x**2 - x + 3, x, domain='ZZ')

        >>> Poly(x**2 + 1, x) - Poly(x - 2, x)
        Poly(x**2 - x + 3, x, domain='ZZ')

        Úsub)r%   ry   r[  rÌ   r  rj   rk  r7   rh  s          rd   rk  zPoly.subµ  ri  rg   c                óö   — t        |«      }|j                  s| j                  |«      S | j                  |«      \  }}}}t	        | j
                  d«      r|j                  |«      }nt        | d«      ‚ ||«      S )ap  
        Multiply two polynomials ``f`` and ``g``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**2 + 1, x).mul(Poly(x - 2, x))
        Poly(x**3 - 2*x**2 + x - 2, x, domain='ZZ')

        >>> Poly(x**2 + 1, x)*Poly(x - 2, x)
        Poly(x**3 - 2*x**2 + x - 2, x, domain='ZZ')

        r   )r%   ry   r]  rÌ   r  rj   r   r7   rh  s          rd   r   zPoly.mulÔ  ri  rg   c                óž   — t        | j                  d«      r| j                  j                  «       }nt        | d«      ‚| j	                  |«      S )a3  
        Square a polynomial ``f``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x - 2, x).sqr()
        Poly(x**2 - 4*x + 4, x, domain='ZZ')

        >>> Poly(x - 2, x)**2
        Poly(x**2 - 4*x + 4, x, domain='ZZ')

        Úsqr)r  rj   rn  r7   rÎ   r  s     rd   rn  zPoly.sqró  rf  rg   c                ó¶   — t        |«      }t        | j                  d«      r| j                  j                  |«      }nt	        | d«      ‚| j                  |«      S )aX  
        Raise ``f`` to a non-negative power ``n``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x - 2, x).pow(3)
        Poly(x**3 - 6*x**2 + 12*x - 8, x, domain='ZZ')

        >>> Poly(x - 2, x)**3
        Poly(x**3 - 6*x**2 + 12*x - 8, x, domain='ZZ')

        Úpow)r(  r  rj   rp  r7   rÎ   ©r_   r*  rb   s      rd   rp  zPoly.pow  sG   € ô" �‹Fˆä�1—5‘5˜%Ô Ø—U‘U—Y‘Y˜q“\‰Fä'¨¨5Ó1Ð1à�u‰u�V‹}Ðrg   c                ó¼   — | j                  |«      \  }}}}t        | j                  d«      r|j                  |«      \  }}nt	        | d«      ‚ ||«       ||«      fS )a#  
        Polynomial pseudo-division of ``f`` by ``g``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**2 + 1, x).pdiv(Poly(2*x - 4, x))
        (Poly(2*x + 4, x, domain='ZZ'), Poly(20, x, domain='ZZ'))

        Úpdiv)rÌ   r  rj   rs  r7   )r_   r`   rÍ   rÎ   rÏ   rÐ   ÚqÚrs           rd   rs  z	Poly.pdiv%  sW   € ð —x‘x “{‰ˆˆ3��1ä�1—5‘5˜&Ô!Ø—6‘6˜!“9‰DˆA‰qä'¨¨6Ó2Ð2á�1‹v‘s˜1“vˆ~Ðrg   c                ó¦   — | j                  |«      \  }}}}t        | j                  d«      r|j                  |«      }nt	        | d«      ‚ ||«      S )aN  
        Polynomial pseudo-remainder of ``f`` by ``g``.

        Caveat: The function prem(f, g, x) can be safely used to compute
          in Z[x] _only_ subresultant polynomial remainder sequences (prs's).

          To safely compute Euclidean and Sturmian prs's in Z[x]
          employ anyone of the corresponding functions found in
          the module sympy.polys.subresultants_qq_zz. The functions
          in the module with suffix _pg compute prs's in Z[x] employing
          rem(f, g, x), whereas the functions with suffix _amv
          compute prs's in Z[x] employing rem_z(f, g, x).

          The function rem_z(f, g, x) differs from prem(f, g, x) in that
          to compute the remainder polynomials in Z[x] it premultiplies
          the divident times the absolute value of the leading coefficient
          of the divisor raised to the power degree(f, x) - degree(g, x) + 1.


        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**2 + 1, x).prem(Poly(2*x - 4, x))
        Poly(20, x, domain='ZZ')

        Úprem)rÌ   r  rj   rw  r7   rh  s          rd   rw  z	Poly.prem<  sK   € ð< —x‘x “{‰ˆˆ3��1ä�1—5‘5˜&Ô!Ø—V‘V˜A“Y‰Fä'¨¨6Ó2Ð2á�6‹{Ðrg   c                ó¦   — | j                  |«      \  }}}}t        | j                  d«      r|j                  |«      }nt	        | d«      ‚ ||«      S )aœ  
        Polynomial pseudo-quotient of ``f`` by ``g``.

        See the Caveat note in the function prem(f, g).

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**2 + 1, x).pquo(Poly(2*x - 4, x))
        Poly(2*x + 4, x, domain='ZZ')

        >>> Poly(x**2 - 1, x).pquo(Poly(2*x - 2, x))
        Poly(2*x + 2, x, domain='ZZ')

        Úpquo)rÌ   r  rj   ry  r7   rh  s          rd   ry  z	Poly.pquoc  sK   € ð& —x‘x “{‰ˆˆ3��1ä�1—5‘5˜&Ô!Ø—V‘V˜A“Y‰Fä'¨¨6Ó2Ð2á�6‹{Ðrg   c                ó&  — | j                  |«      \  }}}}t        | j                  d«      r	 |j                  |«      }nt        | d«      ‚ ||«      S # t        $ r3}|j                  | j                  «       |j                  «       «      ‚d}~ww xY w)a¼  
        Polynomial exact pseudo-quotient of ``f`` by ``g``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**2 - 1, x).pexquo(Poly(2*x - 2, x))
        Poly(2*x + 2, x, domain='ZZ')

        >>> Poly(x**2 + 1, x).pexquo(Poly(2*x - 4, x))
        Traceback (most recent call last):
        ...
        ExactQuotientFailed: 2*x - 4 does not divide x**2 + 1

        ÚpexquoN)rÌ   r  rj   r{  r>   r†   r]   r7   )r_   r`   rÍ   rÎ   rÏ   rÐ   rb   Úexcs           rd   r{  zPoly.pexquo  s�   € ð& —x‘x “{‰ˆˆ3��1ä�1—5‘5˜(Ô#ð8ØŸ™ !›‘ô (¨¨8Ó4Ð4á�6‹{Ðøô 'ò 8Ø—g‘g˜aŸi™i›k¨1¯9©9«;Ó7Ð7ûð8ús   ®A Á	BÁ.BÂBc                ó¤  — | j                  |«      \  }}}}d}|r:|j                  r.|j                  s"|j                  «       |j                  «       }}d}t	        | j
                  d«      r|j                  |«      \  }}	nt        | d«      ‚|r%	 |j                  «       |	j                  «       }}
|
|}	} ||«       ||	«      fS # t        $ r Y Œw xY w)a®  
        Polynomial division with remainder of ``f`` by ``g``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**2 + 1, x).div(Poly(2*x - 4, x))
        (Poly(1/2*x + 1, x, domain='QQ'), Poly(5, x, domain='QQ'))

        >>> Poly(x**2 + 1, x).div(Poly(2*x - 4, x), auto=False)
        (Poly(0, x, domain='ZZ'), Poly(x**2 + 1, x, domain='ZZ'))

        FTÚdiv)
rÌ   Úis_RingÚis_Fieldr¬   r  rj   r~  r7   r  r9   )r_   r`   Úautor¾   rÎ   rÏ   rÐ   r%  rt  ru  ÚQÚRs               rd   r~  zPoly.divž  sÁ   € ð" Ÿ™ !›‰ˆˆS�!�QØˆá�C—K’K¨¯ªØ—:‘:“< §¡£ˆqˆAØˆGä�1—5‘5˜%Ô Ø—5‘5˜“8‰DˆA‰qä'¨¨5Ó1Ð1áðØ—y‘y“{ A§I¡I£K�1�ð ˜!�1�á�1‹v‘s˜1“vˆ~Ðøô "ò Ùðús   Â C Ã	CÃCc                óf  — | j                  |«      \  }}}}d}|r:|j                  r.|j                  s"|j                  «       |j                  «       }}d}t	        | j
                  d«      r|j                  |«      }nt        | d«      ‚|r	 |j                  «       } ||«      S # t        $ r Y Œw xY w)ao  
        Computes the polynomial remainder of ``f`` by ``g``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**2 + 1, x).rem(Poly(2*x - 4, x))
        Poly(5, x, domain='ZZ')

        >>> Poly(x**2 + 1, x).rem(Poly(2*x - 4, x), auto=False)
        Poly(x**2 + 1, x, domain='ZZ')

        FTÚrem)
rÌ   r  r€  r¬   r  rj   r…  r7   r  r9   )	r_   r`   r�  r¾   rÎ   rÏ   rÐ   r%  ru  s	            rd   r…  zPoly.remÅ  ó¡   € ð" Ÿ™ !›‰ˆˆS�!�QØˆá�C—K’K¨¯ªØ—:‘:“< §¡£ˆqˆAØˆGä�1—5‘5˜%Ô Ø—‘�a“‰Aä'¨¨5Ó1Ð1áðØ—I‘I“K�ñ �1‹vˆøô "ò Ùðúó   ÂB$ Â$	B0Â/B0c                óf  — | j                  |«      \  }}}}d}|r:|j                  r.|j                  s"|j                  «       |j                  «       }}d}t	        | j
                  d«      r|j                  |«      }nt        | d«      ‚|r	 |j                  «       } ||«      S # t        $ r Y Œw xY w)aa  
        Computes polynomial quotient of ``f`` by ``g``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**2 + 1, x).quo(Poly(2*x - 4, x))
        Poly(1/2*x + 1, x, domain='QQ')

        >>> Poly(x**2 - 1, x).quo(Poly(x - 1, x))
        Poly(x + 1, x, domain='ZZ')

        FTÚquo)
rÌ   r  r€  r¬   r  rj   r‰  r7   r  r9   )	r_   r`   r�  r¾   rÎ   rÏ   rÐ   r%  rt  s	            rd   r‰  zPoly.quoê  r†  r‡  c                óæ  — | j                  |«      \  }}}}d}|r:|j                  r.|j                  s"|j                  «       |j                  «       }}d}t	        | j
                  d«      r	 |j                  |«      }nt        | d«      ‚|r	 |j                  «       } ||«      S # t        $ r3}	|	j                  | j                  «       |j                  «       «      ‚d}	~	ww xY w# t        $ r Y ŒRw xY w)a¸  
        Computes polynomial exact quotient of ``f`` by ``g``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**2 - 1, x).exquo(Poly(x - 1, x))
        Poly(x + 1, x, domain='ZZ')

        >>> Poly(x**2 + 1, x).exquo(Poly(2*x - 4, x))
        Traceback (most recent call last):
        ...
        ExactQuotientFailed: 2*x - 4 does not divide x**2 + 1

        FTÚexquoN)rÌ   r  r€  r¬   r  rj   r‹  r>   r†   r]   r7   r  r9   )
r_   r`   r�  r¾   rÎ   rÏ   rÐ   r%  rt  r|  s
             rd   r‹  z
Poly.exquo  sÖ   € ð& Ÿ™ !›‰ˆˆS�!�QØˆá�C—K’K¨¯ªØ—:‘:“< §¡£ˆqˆAØˆGä�1—5‘5˜'Ô"ð8Ø—G‘G˜A“J‘ô (¨¨7Ó3Ð3áðØ—I‘I“K�ñ �1‹vˆøô 'ò 8Ø—g‘g˜aŸi™i›k¨1¯9©9«;Ó7Ð7ûð8ûô "ò Ùðús*   Á,B% ÂC$ Â%	C!Â..CÃC!Ã$	C0Ã/C0c                ó*  — t        |t        «      rDt        | j                  «      }| |cxk  r|k  rn n|dk  r||z   S |S t	        d|›d|›d|›�«      ‚	 | j                  j                  t        |«      «      S # t        $ r t	        d|z  «      ‚w xY w)z3Returns level associated with the given generator. r   ú-z
 <= gen < z expected, got z"a valid generator expected, got %s)rV   r(  r„   rY   r<   r   r%   r  )r_   rÂ   r:  s      rd   r  zPoly._gen_to_level9  sœ   € ä�cœ3ÔÜ˜Ÿ™“[ˆFàˆw˜#Ô& Õ&Ø˜’7Ø! C™<Ð'à�Jå%Ú'-ªv±sð'<ó =ð =ð@Ø—v‘v—|‘|¤G¨C£LÓ1Ð1øÜò @Ü%Ø8¸3Ñ>ó@ð @ð@ús   Á#A: Á:Bc                óÌ   — | j                  |«      }t        | j                  d«      r2| j                  j                  |«      }|dk  rt        j
                  }|S t        | d«      ‚)au  
        Returns degree of ``f`` in ``x_j``.

        The degree of 0 is negative infinity.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y

        >>> Poly(x**2 + y*x + 1, x, y).degree()
        2
        >>> Poly(x**2 + y*x + y, x, y).degree(y)
        1
        >>> Poly(0, x).degree()
        -oo

        Údegreer   )r  r  rj   r�  r   ÚNegativeInfinityr7   )r_   rÂ   rü   Úds       rd   r�  zPoly.degreeM  sU   € ð( �O‰O˜CÓ ˆä�1—5‘5˜(Ô#Ø—‘—‘˜Q“ˆAØ�1ŠuÜ×&Ñ&�ØˆHä'¨¨8Ó4Ð4rg   c                óz   — t        | j                  d«      r| j                  j                  «       S t        | d«      ‚)zé
        Returns a list of degrees of ``f``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y

        >>> Poly(x**2 + y*x + 1, x, y).degree_list()
        (2, 1)

        Údegree_list)r  rj   r“  r7   rè   s    rd   r“  zPoly.degree_listk  s2   € ô �1—5‘5˜-Ô(Ø—5‘5×$Ñ$Ó&Ð&ä'¨¨=Ó9Ð9rg   c                óz   — t        | j                  d«      r| j                  j                  «       S t        | d«      ‚)a  
        Returns the total degree of ``f``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y

        >>> Poly(x**2 + y*x + 1, x, y).total_degree()
        2
        >>> Poly(x + y**5, x, y).total_degree()
        5

        Útotal_degree)r  rj   r•  r7   rè   s    rd   r•  zPoly.total_degree~  s2   € ô  �1—5‘5˜.Ô)Ø—5‘5×%Ñ%Ó'Ð'ä'¨¨>Ó:Ð:rg   c                ó¢  — t        |t        «      st        dt        |«      z  «      ‚|| j                  v r(| j                  j                  |«      }| j                  }n%t        | j                  «      }| j                  |fz   }t        | j                  d«      r,| j                  | j                  j                  |«      |¬«      S t        | d«      ‚)aÚ  
        Returns the homogeneous polynomial of ``f``.

        A homogeneous polynomial is a polynomial whose all monomials with
        non-zero coefficients have the same total degree. If you only
        want to check if a polynomial is homogeneous, then use
        :func:`Poly.is_homogeneous`. If you want not only to check if a
        polynomial is homogeneous but also compute its homogeneous order,
        then use :func:`Poly.homogeneous_order`.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y, z

        >>> f = Poly(x**5 + 2*x**2*y**2 + 9*x*y**3)
        >>> f.homogenize(z)
        Poly(x**5 + 2*x**2*y**2*z + 9*x*y**3*z, x, y, z, domain='ZZ')

        z``Symbol`` expected, got %sÚ
homogenizerÄ   Úhomogeneous_order)rV   r$   Ú	TypeErrorrx   rY   r   r„   r  rj   rÎ   r—  r7   )r_   Úsr¼   rY   s       rd   r—  zPoly.homogenize“  s¢   € ô, ˜!œVÔ$ÜÐ9¼DÀ»GÑCÓDÐDØ�—‘‰;Ø—‘—‘˜Q“ˆAØ—6‘6‰Dä�A—F‘F“ˆAØ—6‘6˜Q˜D‘=ˆDÜ�1—5‘5˜,Ô'Ø—5‘5˜Ÿ™×)Ñ)¨!Ó,°4�5Ó8Ð8Ü# AÐ':Ó;Ð;rg   c                óz   — t        | j                  d«      r| j                  j                  «       S t        | d«      ‚)a-  
        Returns the homogeneous order of ``f``.

        A homogeneous polynomial is a polynomial whose all monomials with
        non-zero coefficients have the same total degree. This degree is
        the homogeneous order of ``f``. If you only want to check if a
        polynomial is homogeneous, then use :func:`Poly.is_homogeneous`.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y

        >>> f = Poly(x**5 + 2*x**3*y**2 + 9*x*y**4)
        >>> f.homogeneous_order()
        5

        r˜  )r  rj   r˜  r7   rè   s    rd   r˜  zPoly.homogeneous_orderµ  s4   € ô( �1—5‘5Ð-Ô.Ø—5‘5×*Ñ*Ó,Ð,ä'¨Ð+>Ó?Ð?rg   c                óò   — |�| j                  |«      d   S t        | j                  d«      r| j                  j                  «       }nt	        | d«      ‚| j                  j
                  j                  |«      S )zâ
        Returns the leading coefficient of ``f``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(4*x**3 + 2*x**2 + 3*x, x).LC()
        4

        r   ÚLC)rÁ   r  rj   r�  r7   r¾   r×   )r_   rl   rb   s      rd   r�  zPoly.LCÎ  s`   € ð ÐØ—8‘8˜E“? 1Ñ%Ð%ä�1—5‘5˜$ÔØ—U‘U—X‘X“Z‰Fä'¨¨4Ó0Ð0à�u‰u�y‰y×!Ñ! &Ó)Ð)rg   c                óÆ   — t        | j                  d«      r| j                  j                  «       }nt        | d«      ‚| j                  j                  j                  |«      S )zá
        Returns the trailing coefficient of ``f``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**3 + 2*x**2 + 3*x, x).TC()
        0

        ÚTC)r  rj   rŸ  r7   r¾   r×   r  s     rd   rŸ  zPoly.TCæ  sG   € ô �1—5‘5˜$ÔØ—U‘U—X‘X“Z‰Fä'¨¨4Ó0Ð0à�u‰u�y‰y×!Ñ! &Ó)Ð)rg   c                ón   — t        | j                  d«      r| j                  |«      d   S t        | d«      ‚)zæ
        Returns the last non-zero coefficient of ``f``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**3 + 2*x**2 + 3*x, x).EC()
        3

        rÁ   éÿÿÿÿÚEC)r  rj   rÁ   r7   r.  s     rd   r¢  zPoly.ECû  s2   € ô �1—5‘5˜(Ô#Ø—8‘8˜E“? 2Ñ&Ð&ä'¨¨4Ó0Ð0rg   c                ó\   —  | j                   t        || j                  «      j                  Ž S )aE  
        Returns the coefficient of ``monom`` in ``f`` if there, else None.

        Examples
        ========

        >>> from sympy import Poly, exp
        >>> from sympy.abc import x, y

        >>> p = Poly(24*x*y*exp(8) + 23*x, x, y)

        >>> p.coeff_monomial(x)
        23
        >>> p.coeff_monomial(y)
        0
        >>> p.coeff_monomial(x*y)
        24*exp(8)

        Note that ``Expr.coeff()`` behaves differently, collecting terms
        if possible; the Poly must be converted to an Expr to use that
        method, however:

        >>> p.as_expr().coeff(x)
        24*y*exp(8) + 23
        >>> p.as_expr().coeff(y)
        24*x*exp(8)
        >>> p.as_expr().coeff(x*y)
        24*exp(8)

        See Also
        ========
        nth: more efficient query using exponents of the monomial's generators

        )Únthr2   rY   Ú	exponents)r_   r¢   s     rd   Úcoeff_monomialzPoly.coeff_monomial  s'   € ðF ˆq�u‰u”h˜u a§f¡fÓ-×7Ñ7Ð8Ð8rg   c                óJ  — t        | j                  d«      r]t        |«      t        | j                  «      k7  rt	        d«      ‚ | j                  j
                  t        t        t        |«      «      Ž }nt        | d«      ‚| j                  j                  j                  |«      S )a.  
        Returns the ``n``-th coefficient of ``f`` where ``N`` are the
        exponents of the generators in the term of interest.

        Examples
        ========

        >>> from sympy import Poly, sqrt
        >>> from sympy.abc import x, y

        >>> Poly(x**3 + 2*x**2 + 3*x, x).nth(2)
        2
        >>> Poly(x**3 + 2*x*y**2 + y**2, x, y).nth(1, 2)
        2
        >>> Poly(4*sqrt(x)*y)
        Poly(4*y*(sqrt(x)), y, sqrt(x), domain='ZZ')
        >>> _.nth(1, 1)
        4

        See Also
        ========
        coeff_monomial

        r¤  z,exponent of each generator must be specified)r  rj   r„   rY   r  r¤  rw   r¥   r(  r7   r¾   r×   )r_   ÚNrb   s      rd   r¤  zPoly.nth3  sw   € ô2 �1—5‘5˜%Ô Ü�1‹vœ˜QŸV™V›Ò$Ü Ð!OÓPÐPØ�Q—U‘U—Y‘Y¤¤S¬¨a£[Ó 1Ð2‰Fä'¨¨5Ó1Ð1à�u‰u�y‰y×!Ñ! &Ó)Ð)rg   c                ó   — t        d«      ‚)NzyEither convert to Expr with `as_expr` method to use Expr's coeff method or else use the `coeff_monomial` method of Polys.©rq   )r_   r  r*  Úrights       rd   r£   z
Poly.coeffU  s   € ô "ð0ó1ð 	1rg   c                óR   — t        | j                  |«      d   | j                  «      S )aƒ  
        Returns the leading monomial of ``f``.

        The Leading monomial signifies the monomial having
        the highest power of the principal generator in the
        expression f.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y

        >>> Poly(4*x**2 + 2*x*y**2 + x*y + 3*y, x, y).LM()
        x**2*y**0

        r   ©r2   r¸   rY   r.  s     rd   ÚLMzPoly.LMa  s"   € ô$ ˜Ÿ™ ›¨Ñ*¨A¯F©FÓ3Ð3rg   c                óR   — t        | j                  |«      d   | j                  «      S )zû
        Returns the last non-zero monomial of ``f``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y

        >>> Poly(4*x**2 + 2*x*y**2 + x*y + 3*y, x, y).EM()
        x**0*y**1

        r¡  r­  r.  s     rd   ÚEMzPoly.EMu  s"   € ô ˜Ÿ™ ›¨Ñ+¨Q¯V©VÓ4Ð4rg   c                ó`   — | j                  |«      d   \  }}t        || j                  «      |fS )a—  
        Returns the leading term of ``f``.

        The Leading term signifies the term having
        the highest power of the principal generator in the
        expression f along with its coefficient.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y

        >>> Poly(4*x**2 + 2*x*y**2 + x*y + 3*y, x, y).LT()
        (x**2*y**0, 4)

        r   ©r  r2   rY   ©r_   rl   r¢   r£   s       rd   ÚLTzPoly.LT…  s0   € ð$ —w‘w˜u“~ aÑ(‰ˆˆuÜ˜˜qŸv™vÓ&¨Ð-Ð-rg   c                ó`   — | j                  |«      d   \  }}t        || j                  «      |fS )zü
        Returns the last non-zero term of ``f``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y

        >>> Poly(4*x**2 + 2*x*y**2 + x*y + 3*y, x, y).ET()
        (x**0*y**1, 3)

        r¡  r²  r³  s       rd   ÚETzPoly.ETš  s0   € ð —w‘w˜u“~ bÑ)‰ˆˆuÜ˜˜qŸv™vÓ&¨Ð-Ð-rg   c                óÆ   — t        | j                  d«      r| j                  j                  «       }nt        | d«      ‚| j                  j                  j                  |«      S )z×
        Returns maximum norm of ``f``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(-x**2 + 2*x - 3, x).max_norm()
        3

        Úmax_norm)r  rj   r¸  r7   r¾   r×   r  s     rd   r¸  zPoly.max_norm«  sH   € ô �1—5‘5˜*Ô%Ø—U‘U—^‘^Ó%‰Fä'¨¨:Ó6Ð6à�u‰u�y‰y×!Ñ! &Ó)Ð)rg   c                óÆ   — t        | j                  d«      r| j                  j                  «       }nt        | d«      ‚| j                  j                  j                  |«      S )zÑ
        Returns l1 norm of ``f``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(-x**2 + 2*x - 3, x).l1_norm()
        6

        Úl1_norm)r  rj   rº  r7   r¾   r×   r  s     rd   rº  zPoly.l1_normÀ  óG   € ô �1—5‘5˜)Ô$Ø—U‘U—]‘]“_‰Fä'¨¨9Ó5Ð5à�u‰u�y‰y×!Ñ! &Ó)Ð)rg   c                óö  — | }|j                   j                  j                  st        j                  |fS |j                  «       }|j                  r$|j                   j                  j                  «       }t        |j                   d«      r|j                   j                  «       \  }}nt        |d«      ‚|j                  |«      |j                  |«      }}|r|j                  s||fS ||j                  «       fS )aƒ  
        Clear denominators, but keep the ground domain.

        Examples
        ========

        >>> from sympy import Poly, S, QQ
        >>> from sympy.abc import x

        >>> f = Poly(x/2 + S(1)/3, x, domain=QQ)

        >>> f.clear_denoms()
        (6, Poly(3*x + 2, x, domain='QQ'))
        >>> f.clear_denoms(convert=True)
        (6, Poly(3*x + 2, x, domain='ZZ'))

        Úclear_denoms)rj   r¾   r€  r   ÚOnerÆ   Úhas_assoc_RingÚget_ringr  r½  r7   r×   rÎ   r  )r‹   r    r_   r¾   r£   rb   s         rd   r½  zPoly.clear_denomsÕ  sÁ   € ð$ ˆà�u‰u�y‰y×!Ò!Ü—5‘5˜!�8ˆOà�l‰l‹nˆØ×ÒØ—%‘%—)‘)×$Ñ$Ó&ˆCä�1—5‘5˜.Ô)ØŸE™E×.Ñ.Ó0‰MˆE‘6ä'¨¨>Ó:Ð:à—<‘< Ó&¨¯©¨f«ˆqˆá˜c×0Ò0Ø˜!�8ˆOà˜!Ÿ)™)›+Ð%Ð%rg   c                ó*  — | }|j                  |«      \  }}}} ||«      } ||«      }|j                  r|j                  s||fS |j                  d¬«      \  }}|j                  d¬«      \  }}|j	                  |«      }|j	                  |«      }||fS )aš  
        Clear denominators in a rational function ``f/g``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y

        >>> f = Poly(x**2/y + 1, x)
        >>> g = Poly(x**3 + y, x)

        >>> p, q = f.rat_clear_denoms(g)

        >>> p
        Poly(x**2 + y, x, domain='ZZ[y]')
        >>> q
        Poly(y*x**3 + y**2, x, domain='ZZ[y]')

        T©r    )rÌ   r€  r¿  r½  r]  )r‹   r`   r_   r¾   rÎ   ÚaÚbs          rd   Úrat_clear_denomszPoly.rat_clear_denomsü  s“   € ð* ˆàŸ™ !›‰ˆˆS�!�Qá�‹FˆÙ�‹Fˆà—’ ×!3Ò!3Ø�a�4ˆKà�~‰~ dˆ~Ó+‰ˆˆ1Ø�~‰~ dˆ~Ó+‰ˆˆ1à�L‰L˜‹OˆØ�L‰L˜‹Oˆà�!ˆtˆrg   c                óø  — | }|j                  dd«      r0|j                  j                  j                  r|j	                  «       }t        |j                  d«      r•|s+|j                  |j                  j                  d¬«      «      S |j                  }|D ]F  }t        |t        «      r|\  }}n|d}}|j                  t        |«      |j                  |«      «      }ŒH |j                  |«      S t        |d«      ‚)a‚  
        Computes indefinite integral of ``f``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y

        >>> Poly(x**2 + 2*x + 1, x).integrate()
        Poly(1/3*x**3 + x**2 + x, x, domain='QQ')

        >>> Poly(x*y**2 + x, x, y).integrate((0, 1), (1, 0))
        Poly(1/2*x**2*y**2 + 1/2*x**2, x, y, domain='QQ')

        r�  TÚ	integrater‚   ©r)  )Úgetrj   r¾   r  r¬   r  rÎ   rÇ  rV   r7  r(  r  r7   )r‹   Úspecsr~   r_   rj   ÚspecrÂ   r)  s           rd   rÇ  zPoly.integrate#	  sÑ   € ð" ˆà�8‰8�F˜DÔ! a§e¡e§i¡i×&7Ò&7Ø—
‘
“ˆAä�1—5‘5˜+Ô&ÙØ—u‘u˜QŸU™UŸ_™_¨q˜_Ó1Ó2Ð2à—%‘%ˆCàò B�Ü˜d¤EÔ*Ø!‘F�C™à! 1˜�Cà—m‘m¤C¨£F¨A¯O©O¸CÓ,@ÓA‘ðBð —5‘5˜“:Ðä'¨¨;Ó7Ð7rg   c                ó²  — |j                  dd«      st        | g|¢­i |¤ŽS t        | j                  d«      r•|s+| j	                  | j                  j                  d¬«      «      S | j                  }|D ]F  }t        |t        «      r|\  }}n|d}}|j                  t        |«      | j                  |«      «      }ŒH | j	                  |«      S t        | d«      ‚)aX  
        Computes partial derivative of ``f``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y

        >>> Poly(x**2 + 2*x + 1, x).diff()
        Poly(2*x + 2, x, domain='ZZ')

        >>> Poly(x*y**2 + x, x, y).diff((0, 0), (1, 1))
        Poly(2*x*y, x, y, domain='ZZ')

        rn   TÚdiffr‚   rÈ  )rÉ  r   r  rj   rÎ   rÍ  rV   r7  r(  r  r7   )r_   rÊ  r  rj   rË  rÂ   r)  s          rd   rÍ  z	Poly.diffK	  sÃ   € ð" �z‰z˜* dÔ+Ü˜aÐ2 %Ò2¨6Ñ2Ð2ä�1—5‘5˜&Ô!ÙØ—u‘u˜QŸU™UŸZ™Z¨!˜Z›_Ó-Ð-à—%‘%ˆCàò =�Ü˜d¤EÔ*Ø!‘F�C™à! 1˜�Cà—h‘hœs 1›v q§¡°sÓ';Ó<‘ð=ð —5‘5˜“:Ðä'¨¨6Ó2Ð2rg   c                ó¢  — | }|€¹t        |t        «      r.|}|j                  «       D ]  \  }}|j                  ||«      }Œ |S t        |t        t
        f«      r`|}t        |«      t        |j                  «      kD  rt        d«      ‚t        |j                  |«      D ]  \  }}|j                  ||«      }Œ |S d|}}	n|j                  |«      }	t        |j                  d«      st        |d«      ‚	 |j                  j                  ||	«      }
|j-                  |
|	¬«      S # t        $ r¤ |s%t        d|›d|j                  j                   ›�«      ‚t#        |g«      \  }\  }|j%                  «       j'                  ||j                  «      }|j)                  |«      }|j+                  ||«      }|j                  j                  ||	«      }
Y Œ¿w xY w)aÁ  
        Evaluate ``f`` at ``a`` in the given variable.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y, z

        >>> Poly(x**2 + 2*x + 3, x).eval(2)
        11

        >>> Poly(2*x*y + 3*x + y + 2, x, y).eval(x, 2)
        Poly(5*y + 8, y, domain='ZZ')

        >>> f = Poly(2*x*y + 3*x + y + 2*z, x, y, z)

        >>> f.eval({x: 2})
        Poly(5*y + 2*z + 6, y, z, domain='ZZ')
        >>> f.eval({x: 2, y: 5})
        Poly(2*z + 31, z, domain='ZZ')
        >>> f.eval({x: 2, y: 5, z: 7})
        45

        >>> f.eval((2, 5))
        Poly(2*z + 31, z, domain='ZZ')
        >>> f(2, 5)
        Poly(2*z + 31, z, domain='ZZ')

        ztoo many values providedr   rô   zCannot evaluate at rþ   ©rÙ   )rV   rt   rŸ   rô   r7  rw   r„   rY   r  rÞ   r  r  rj   r7   r9   r8   r¾   r+   rÆ   Úunify_with_symbolsr«   r    rÎ   )r‹   r  rÃ  r�  r_   rA  rÂ   rB  Úvaluesrü   rb   Úa_domainÚ
new_domains                rd   rô   z	Poly.evals	  s£  € ð> ˆàˆ9Ü˜!œTÔ"Ø�à")§-¡-£/ò +‘J�C˜ØŸ™˜s EÓ*‘Að+ð �Ü˜A¤¤t˜}Ô-Ø�ä�v“;¤ Q§V¡V£Ò,Ü$Ð%?Ó@Ð@ä"% a§f¡f¨fÓ"5ò +‘J�C˜ØŸ™˜s EÓ*‘Að+ð �à˜!�1‘à—‘ Ó"ˆAä�q—u‘u˜fÔ%Ü'¨¨6Ó2Ð2ð	*Ø—U‘U—Z‘Z  1Ó%ˆFð �u‰u�V AˆuÓ&Ð&øô ò 
	*ÙÝ!Â1ÀaÇeÁeÇiÂiÐ"PÓQÐQä 0°!°Ó 5‘�™#˜1ØŸ\™\›^×>Ñ>¸xÈÏÉÓP�
à—L‘L Ó,�Ø×&Ñ& q¨(Ó3�àŸ™Ÿ™ A qÓ)’ð
	*ús   Ã2D! Ä!B*GÇGc                ó$   — | j                  |«      S )az  
        Evaluate ``f`` at the give values.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y, z

        >>> f = Poly(2*x*y + 3*x + y + 2*z, x, y, z)

        >>> f(2)
        Poly(5*y + 2*z + 6, y, z, domain='ZZ')
        >>> f(2, 5)
        Poly(2*z + 31, z, domain='ZZ')
        >>> f(2, 5, 7)
        45

        )rô   )r_   rÑ  s     rd   Ú__call__zPoly.__call__¾	  s   € ð( �v‰v�f‹~Ðrg   c                ó  — | j                  |«      \  }}}}|r,|j                  r |j                  «       |j                  «       }}t        | j                  d«      r|j                  |«      \  }}nt        | d«      ‚ ||«       ||«      fS )aÑ  
        Half extended Euclidean algorithm of ``f`` and ``g``.

        Returns ``(s, h)`` such that ``h = gcd(f, g)`` and ``s*f = h (mod g)``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> f = x**4 - 2*x**3 - 6*x**2 + 12*x + 15
        >>> g = x**3 + x**2 - 4*x - 4

        >>> Poly(f).half_gcdex(Poly(g))
        (Poly(-1/5*x + 3/5, x, domain='QQ'), Poly(x + 1, x, domain='QQ'))

        Ú
half_gcdex)rÌ   r  r¬   r  rj   r×  r7   )	r_   r`   r�  r¾   rÎ   rÏ   rÐ   rš  Úhs	            rd   r×  zPoly.half_gcdexÔ	  su   € ð& Ÿ™ !›‰ˆˆS�!�Qá�C—K’KØ—:‘:“< §¡£ˆqˆAä�1—5‘5˜,Ô'Ø—<‘< “?‰DˆA‰qä'¨¨<Ó8Ð8á�1‹v‘s˜1“vˆ~Ðrg   c                ó(  — | j                  |«      \  }}}}|r,|j                  r |j                  «       |j                  «       }}t        | j                  d«      r|j                  |«      \  }}}	nt        | d«      ‚ ||«       ||«       ||	«      fS )a  
        Extended Euclidean algorithm of ``f`` and ``g``.

        Returns ``(s, t, h)`` such that ``h = gcd(f, g)`` and ``s*f + t*g = h``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> f = x**4 - 2*x**3 - 6*x**2 + 12*x + 15
        >>> g = x**3 + x**2 - 4*x - 4

        >>> Poly(f).gcdex(Poly(g))
        (Poly(-1/5*x + 3/5, x, domain='QQ'),
         Poly(1/5*x**2 - 6/5*x + 2, x, domain='QQ'),
         Poly(x + 1, x, domain='QQ'))

        Úgcdex)rÌ   r  r¬   r  rj   rÚ  r7   )
r_   r`   r�  r¾   rÎ   rÏ   rÐ   rš  ÚtrØ  s
             rd   rÚ  z
Poly.gcdexó	  s~   € ð* Ÿ™ !›‰ˆˆS�!�Qá�C—K’KØ—:‘:“< §¡£ˆqˆAä�1—5‘5˜'Ô"Ø—g‘g˜a“j‰GˆAˆq‘!ä'¨¨7Ó3Ð3á�1‹v‘s˜1“v™s 1›vÐ%Ð%rg   c                ó  — | j                  |«      \  }}}}|r,|j                  r |j                  «       |j                  «       }}t        | j                  d«      r|j                  |«      }nt        | d«      ‚ ||«      S )a’  
        Invert ``f`` modulo ``g`` when possible.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**2 - 1, x).invert(Poly(2*x - 1, x))
        Poly(-4/3, x, domain='QQ')

        >>> Poly(x**2 - 1, x).invert(Poly(x - 1, x))
        Traceback (most recent call last):
        ...
        NotInvertible: zero divisor

        Úinvert)rÌ   r  r¬   r  rj   rÝ  r7   )r_   r`   r�  r¾   rÎ   rÏ   rÐ   rb   s           rd   rÝ  zPoly.invert
  si   € ð& Ÿ™ !›‰ˆˆS�!�Qá�C—K’KØ—:‘:“< §¡£ˆqˆAä�1—5‘5˜(Ô#Ø—X‘X˜a“[‰Fä'¨¨8Ó4Ð4á�6‹{Ðrg   c                ó²   — t        | j                  d«      r%| j                  j                  t        |«      «      }nt	        | d«      ‚| j                  |«      S )ad  
        Compute ``f**(-1)`` mod ``x**n``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(1, x).revert(2)
        Poly(1, x, domain='ZZ')

        >>> Poly(1 + x, x).revert(1)
        Poly(1, x, domain='ZZ')

        >>> Poly(x**2 - 2, x).revert(2)
        Traceback (most recent call last):
        ...
        NotReversible: only units are reversible in a ring

        >>> Poly(1/x, x).revert(1)
        Traceback (most recent call last):
        ...
        PolynomialError: 1/x contains an element of the generators set

        Úrevert)r  rj   rß  r(  r7   rÎ   rq  s      rd   rß  zPoly.revert3
  sC   € ô6 �1—5‘5˜(Ô#Ø—U‘U—\‘\¤# a£&Ó)‰Fä'¨¨8Ó4Ð4à�u‰u�V‹}Ðrg   c                óÀ   — | j                  |«      \  }}}}t        | j                  d«      r|j                  |«      }nt	        | d«      ‚t        t        ||«      «      S )ad  
        Computes the subresultant PRS of ``f`` and ``g``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**2 + 1, x).subresultants(Poly(x**2 - 1, x))
        [Poly(x**2 + 1, x, domain='ZZ'),
         Poly(x**2 - 1, x, domain='ZZ'),
         Poly(-2, x, domain='ZZ')]

        Úsubresultants)rÌ   r  rj   rá  r7   rw   r¥   rh  s          rd   rá  zPoly.subresultantsU
  sT   € ð  —x‘x “{‰ˆˆ3��1ä�1—5‘5˜/Ô*Ø—_‘_ QÓ'‰Fä'¨¨?Ó;Ð;ä”C˜˜VÓ$Ó%Ð%rg   c                ó  — | j                  |«      \  }}}}t        | j                  d«      r+|r|j                  ||¬«      \  }}n|j                  |«      }nt	        | d«      ‚|r ||d¬«      t        t        |«      «      fS  ||d¬«      S )a‘  
        Computes the resultant of ``f`` and ``g`` via PRS.

        If includePRS=True, it includes the subresultant PRS in the result.
        Because the PRS is used to calculate the resultant, this is more
        efficient than calling :func:`subresultants` separately.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> f = Poly(x**2 + 1, x)

        >>> f.resultant(Poly(x**2 - 1, x))
        4
        >>> f.resultant(Poly(x**2 - 1, x), includePRS=True)
        (4, [Poly(x**2 + 1, x, domain='ZZ'), Poly(x**2 - 1, x, domain='ZZ'),
             Poly(-2, x, domain='ZZ')])

        Ú	resultant©Ú
includePRSr   rÏ  )rÌ   r  rj   rã  r7   rw   r¥   )	r_   r`   rå  rÍ   rÎ   rÏ   rÐ   rb   rƒ  s	            rd   rã  zPoly.resultantn
  s‡   € ð. —x‘x “{‰ˆˆ3��1ä�1—5‘5˜+Ô&ÙØŸK™K¨°j˜KÓA‘	�™àŸ™ Q›‘ä'¨¨;Ó7Ð7áÙ˜ qÔ)¬4´°C¸³Ó+<Ð=Ð=Ù�6 !Ô$Ð$rg   c                ó¢   — t        | j                  d«      r| j                  j                  «       }nt        | d«      ‚| j	                  |d¬«      S )zà
        Computes the discriminant of ``f``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**2 + 2*x + 3, x).discriminant()
        -8

        Údiscriminantr   rÏ  )r  rj   rç  r7   rÎ   r  s     rd   rç  zPoly.discriminant“
  sD   € ô �1—5‘5˜.Ô)Ø—U‘U×'Ñ'Ó)‰Fä'¨¨>Ó:Ð:à�u‰u�V AˆuÓ&Ð&rg   c                ó    — ddl m}  || |«      S )a  Compute the *dispersion set* of two polynomials.

        For two polynomials `f(x)` and `g(x)` with `\deg f > 0`
        and `\deg g > 0` the dispersion set `\operatorname{J}(f, g)` is defined as:

        .. math::
            \operatorname{J}(f, g)
            & := \{a \in \mathbb{N}_0 | \gcd(f(x), g(x+a)) \neq 1\} \\
            &  = \{a \in \mathbb{N}_0 | \deg \gcd(f(x), g(x+a)) \geq 1\}

        For a single polynomial one defines `\operatorname{J}(f) := \operatorname{J}(f, f)`.

        Examples
        ========

        >>> from sympy import poly
        >>> from sympy.polys.dispersion import dispersion, dispersionset
        >>> from sympy.abc import x

        Dispersion set and dispersion of a simple polynomial:

        >>> fp = poly((x - 3)*(x + 3), x)
        >>> sorted(dispersionset(fp))
        [0, 6]
        >>> dispersion(fp)
        6

        Note that the definition of the dispersion is not symmetric:

        >>> fp = poly(x**4 - 3*x**2 + 1, x)
        >>> gp = fp.shift(-3)
        >>> sorted(dispersionset(fp, gp))
        [2, 3, 4]
        >>> dispersion(fp, gp)
        4
        >>> sorted(dispersionset(gp, fp))
        []
        >>> dispersion(gp, fp)
        -oo

        Computing the dispersion also works over field extensions:

        >>> from sympy import sqrt
        >>> fp = poly(x**2 + sqrt(5)*x - 1, x, domain='QQ<sqrt(5)>')
        >>> gp = poly(x**2 + (2 + sqrt(5))*x + sqrt(5), x, domain='QQ<sqrt(5)>')
        >>> sorted(dispersionset(fp, gp))
        [2]
        >>> sorted(dispersionset(gp, fp))
        [1, 4]

        We can even perform the computations for polynomials
        having symbolic coefficients:

        >>> from sympy.abc import a
        >>> fp = poly(4*x**4 + (4*a + 8)*x**3 + (a**2 + 6*a + 4)*x**2 + (a**2 + 2*a)*x, x)
        >>> sorted(dispersionset(fp))
        [0, 1]

        See Also
        ========

        dispersion

        References
        ==========

        1. [ManWright94]_
        2. [Koepf98]_
        3. [Abramov71]_
        4. [Man93]_
        r   )Údispersionset)Úsympy.polys.dispersionré  )r_   r`   ré  s      rd   ré  zPoly.dispersionset¨
  s   € õP 	9Ù˜Q Ó"Ð"rg   c                ó    — ddl m}  || |«      S )aï  Compute the *dispersion* of polynomials.

        For two polynomials `f(x)` and `g(x)` with `\deg f > 0`
        and `\deg g > 0` the dispersion `\operatorname{dis}(f, g)` is defined as:

        .. math::
            \operatorname{dis}(f, g)
            & := \max\{ J(f,g) \cup \{0\} \} \\
            &  = \max\{ \{a \in \mathbb{N} | \gcd(f(x), g(x+a)) \neq 1\} \cup \{0\} \}

        and for a single polynomial `\operatorname{dis}(f) := \operatorname{dis}(f, f)`.

        Examples
        ========

        >>> from sympy import poly
        >>> from sympy.polys.dispersion import dispersion, dispersionset
        >>> from sympy.abc import x

        Dispersion set and dispersion of a simple polynomial:

        >>> fp = poly((x - 3)*(x + 3), x)
        >>> sorted(dispersionset(fp))
        [0, 6]
        >>> dispersion(fp)
        6

        Note that the definition of the dispersion is not symmetric:

        >>> fp = poly(x**4 - 3*x**2 + 1, x)
        >>> gp = fp.shift(-3)
        >>> sorted(dispersionset(fp, gp))
        [2, 3, 4]
        >>> dispersion(fp, gp)
        4
        >>> sorted(dispersionset(gp, fp))
        []
        >>> dispersion(gp, fp)
        -oo

        Computing the dispersion also works over field extensions:

        >>> from sympy import sqrt
        >>> fp = poly(x**2 + sqrt(5)*x - 1, x, domain='QQ<sqrt(5)>')
        >>> gp = poly(x**2 + (2 + sqrt(5))*x + sqrt(5), x, domain='QQ<sqrt(5)>')
        >>> sorted(dispersionset(fp, gp))
        [2]
        >>> sorted(dispersionset(gp, fp))
        [1, 4]

        We can even perform the computations for polynomials
        having symbolic coefficients:

        >>> from sympy.abc import a
        >>> fp = poly(4*x**4 + (4*a + 8)*x**3 + (a**2 + 6*a + 4)*x**2 + (a**2 + 2*a)*x, x)
        >>> sorted(dispersionset(fp))
        [0, 1]

        See Also
        ========

        dispersionset

        References
        ==========

        1. [ManWright94]_
        2. [Koepf98]_
        3. [Abramov71]_
        4. [Man93]_
        r   )Ú
dispersion)rê  rì  )r_   r`   rì  s      rd   rì  zPoly.dispersionó
  s   € õP 	6Ù˜!˜QÓÐrg   c                óÌ   — | j                  |«      \  }}}}t        | j                  d«      r|j                  |«      \  }}}nt	        | d«      ‚ ||«       ||«       ||«      fS )a#  
        Returns the GCD of ``f`` and ``g`` and their cofactors.

        Returns polynomials ``(h, cff, cfg)`` such that ``h = gcd(f, g)``, and
        ``cff = quo(f, h)`` and ``cfg = quo(g, h)`` are, so called, cofactors
        of ``f`` and ``g``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**2 - 1, x).cofactors(Poly(x**2 - 3*x + 2, x))
        (Poly(x - 1, x, domain='ZZ'),
         Poly(x + 1, x, domain='ZZ'),
         Poly(x - 2, x, domain='ZZ'))

        Ú	cofactors)rÌ   r  rj   rî  r7   )	r_   r`   rÍ   rÎ   rÏ   rÐ   rØ  ÚcffÚcfgs	            rd   rî  zPoly.cofactors>  s`   € ð( —x‘x “{‰ˆˆ3��1ä�1—5‘5˜+Ô&ØŸ+™+ a›.‰KˆAˆs‘Cä'¨¨;Ó7Ð7á�1‹v‘s˜3“x¡ S£Ð)Ð)rg   c                ó¦   — | j                  |«      \  }}}}t        | j                  d«      r|j                  |«      }nt	        | d«      ‚ ||«      S )a  
        Returns the polynomial GCD of ``f`` and ``g``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**2 - 1, x).gcd(Poly(x**2 - 3*x + 2, x))
        Poly(x - 1, x, domain='ZZ')

        Úgcd)rÌ   r  rj   rò  r7   rh  s          rd   rò  zPoly.gcd[  óK   € ð —x‘x “{‰ˆˆ3��1ä�1—5‘5˜%Ô Ø—U‘U˜1“X‰Fä'¨¨5Ó1Ð1á�6‹{Ðrg   c                ó¦   — | j                  |«      \  }}}}t        | j                  d«      r|j                  |«      }nt	        | d«      ‚ ||«      S )a  
        Returns polynomial LCM of ``f`` and ``g``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**2 - 1, x).lcm(Poly(x**2 - 3*x + 2, x))
        Poly(x**3 - 2*x**2 - x + 2, x, domain='ZZ')

        Úlcm)rÌ   r  rj   rõ  r7   rh  s          rd   rõ  zPoly.lcmr  ró  rg   c                óê   — | j                   j                  j                  |«      }t        | j                   d«      r| j                   j	                  |«      }nt        | d«      ‚| j                  |«      S )a  
        Reduce ``f`` modulo a constant ``p``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(2*x**3 + 3*x**2 + 5*x + 7, x).trunc(3)
        Poly(-x**3 - x + 1, x, domain='ZZ')

        Útrunc)rj   r¾   r    r  r÷  r7   rÎ   )r_   Úprb   s      rd   r÷  z
Poly.trunc‰  sV   € ð �E‰E�I‰I×Ñ˜aÓ ˆä�1—5‘5˜'Ô"Ø—U‘U—[‘[ “^‰Fä'¨¨7Ó3Ð3à�u‰u�V‹}Ðrg   c                ó  — | }|r0|j                   j                  j                  r|j                  «       }t	        |j                   d«      r|j                   j                  «       }nt        |d«      ‚|j                  |«      S )az  
        Divides all coefficients by ``LC(f)``.

        Examples
        ========

        >>> from sympy import Poly, ZZ
        >>> from sympy.abc import x

        >>> Poly(3*x**2 + 6*x + 9, x, domain=ZZ).monic()
        Poly(x**2 + 2*x + 3, x, domain='QQ')

        >>> Poly(3*x**2 + 4*x + 2, x, domain=ZZ).monic()
        Poly(x**2 + 4/3*x + 2/3, x, domain='QQ')

        Úmonic)rj   r¾   r  r¬   r  rú  r7   rÎ   ©r‹   r�  r_   rb   s       rd   rú  z
Poly.monic   s_   € ð" ˆá�A—E‘E—I‘I×%Ò%Ø—
‘
“ˆAä�1—5‘5˜'Ô"Ø—U‘U—[‘[“]‰Fä'¨¨7Ó3Ð3à�u‰u�V‹}Ðrg   c                óÆ   — t        | j                  d«      r| j                  j                  «       }nt        | d«      ‚| j                  j                  j                  |«      S )zå
        Returns the GCD of polynomial coefficients.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(6*x**2 + 8*x + 12, x).content()
        2

        Úcontent)r  rj   rý  r7   r¾   r×   r  s     rd   rý  zPoly.content½  r»  rg   c                óî   — t        | j                  d«      r| j                  j                  «       \  }}nt        | d«      ‚| j                  j                  j                  |«      | j                  |«      fS )a  
        Returns the content and a primitive form of ``f``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(2*x**2 + 8*x + 12, x).primitive()
        (2, Poly(x**2 + 4*x + 6, x, domain='ZZ'))

        Ú	primitive)r  rj   rÿ  r7   r¾   r×   rÎ   )r_   Úcontrb   s      rd   rÿ  zPoly.primitiveÒ  sY   € ô �1—5‘5˜+Ô&ØŸ5™5Ÿ?™?Ó,‰LˆD‘&ä'¨¨;Ó7Ð7à�u‰u�y‰y×!Ñ! $Ó'¨¯©¨v«Ð6Ð6rg   c                ó¦   — | j                  |«      \  }}}}t        | j                  d«      r|j                  |«      }nt	        | d«      ‚ ||«      S )a  
        Computes the functional composition of ``f`` and ``g``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**2 + x, x).compose(Poly(x - 1, x))
        Poly(x**2 - x, x, domain='ZZ')

        Úcompose)rÌ   r  rj   r  r7   rh  s          rd   r  zPoly.composeç  sK   € ð —x‘x “{‰ˆˆ3��1ä�1—5‘5˜)Ô$Ø—Y‘Y˜q“\‰Fä'¨¨9Ó5Ð5á�6‹{Ðrg   c                óº   — t        | j                  d«      r| j                  j                  «       }nt        | d«      ‚t	        t        | j                  |«      «      S )a=  
        Computes a functional decomposition of ``f``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**4 + 2*x**3 - x - 1, x, domain='ZZ').decompose()
        [Poly(x**2 - x - 1, x, domain='ZZ'), Poly(x**2 + x, x, domain='ZZ')]

        Ú	decompose)r  rj   r  r7   rw   r¥   rÎ   r  s     rd   r  zPoly.decomposeþ  sE   € ô �1—5‘5˜+Ô&Ø—U‘U—_‘_Ó&‰Fä'¨¨;Ó7Ð7ä”C˜Ÿ™˜vÓ&Ó'Ð'rg   c                óV   — | j                  | j                  j                  |«      «      S )am  
        Efficiently compute Taylor shift ``f(x + a)``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**2 - 2*x + 1, x).shift(2)
        Poly(x**2 + 2*x + 1, x, domain='ZZ')

        See Also
        ========

        shift_list: Analogous method for multivariate polynomials.
        )rÎ   rj   Úshift©r_   rÃ  s     rd   r  z
Poly.shift  s   € ð$ �u‰u�Q—U‘U—[‘[ “^Ó$Ð$rg   c                óV   — | j                  | j                  j                  |«      «      S )ah  
        Efficiently compute Taylor shift ``f(X + A)``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y

        >>> Poly(x*y, [x,y]).shift_list([1, 2]) == Poly((x+1)*(y+2), [x,y])
        True

        See Also
        ========

        shift: Analogous method for univariate polynomials.
        )rÎ   rj   Ú
shift_listr  s     rd   r	  zPoly.shift_list'  s"   € ð$ �u‰u�Q—U‘U×%Ñ% aÓ(Ó)Ð)rg   c                óB  — |j                  |«      \  }}| j                  |«      \  }}|j                  |«      \  }}t        |j                  d«      r1|j                  j                  |j                  |j                  «      }nt	        |d«      ‚|j                  |«      S )a3  
        Efficiently evaluate the functional transformation ``q**n * f(p/q)``.


        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**2 - 2*x + 1, x).transform(Poly(x + 1, x), Poly(x - 1, x))
        Poly(4, x, domain='ZZ')

        Ú	transform)rÑ   r  rj   r  r7   rÎ   )r_   rø  rt  ÚPr‚  rÏ   rb   s          rd   r  zPoly.transform;  s|   € ð �w‰w�q‹z‰ˆˆ1Ø�w‰w�q‹z‰ˆˆ1Ø�w‰w�q‹z‰ˆˆ1ä�1—5‘5˜+Ô&Ø—U‘U—_‘_ Q§U¡U¨A¯E©EÓ2‰Fä'¨¨;Ó7Ð7à�u‰u�V‹}Ðrg   c                ó"  — | }|r0|j                   j                  j                  r|j                  «       }t	        |j                   d«      r|j                   j                  «       }nt        |d«      ‚t        t        |j                  |«      «      S )a“  
        Computes the Sturm sequence of ``f``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**3 - 2*x**2 + x - 3, x).sturm()
        [Poly(x**3 - 2*x**2 + x - 3, x, domain='QQ'),
         Poly(3*x**2 - 4*x + 1, x, domain='QQ'),
         Poly(2/9*x + 25/9, x, domain='QQ'),
         Poly(-2079/4, x, domain='QQ')]

        Ústurm)
rj   r¾   r  r¬   r  r  r7   rw   r¥   rÎ   rû  s       rd   r  z
Poly.sturmU  sg   € ð" ˆá�A—E‘E—I‘I×%Ò%Ø—
‘
“ˆAä�1—5‘5˜'Ô"Ø—U‘U—[‘[“]‰Fä'¨¨7Ó3Ð3ä”C˜Ÿ™˜vÓ&Ó'Ð'rg   c                óÔ   — t        | j                  d«      r| j                  j                  «       }nt        | d«      ‚|D ��cg c]  \  }}| j	                  |«      |f‘Œ c}}S c c}}w )aI  
        Computes greatest factorial factorization of ``f``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> f = x**5 + 2*x**4 - x**3 - 2*x**2

        >>> Poly(f).gff_list()
        [(Poly(x, x, domain='ZZ'), 1), (Poly(x + 2, x, domain='ZZ'), 4)]

        Úgff_list)r  rj   r  r7   rÎ   )r_   rb   r`   rR  s       rd   r  zPoly.gff_listr  sS   € ô  �1—5‘5˜*Ô%Ø—U‘U—^‘^Ó%‰Fä'¨¨:Ó6Ð6à*0×1¡$ ! Q�—‘�q“˜1’Ó1Ð1ùÓ1s   ÁA$c                óž   — t        | j                  d«      r| j                  j                  «       }nt        | d«      ‚| j	                  |«      S )a¿  
        Computes the product, ``Norm(f)``, of the conjugates of
        a polynomial ``f`` defined over a number field ``K``.

        Examples
        ========

        >>> from sympy import Poly, sqrt
        >>> from sympy.abc import x

        >>> a, b = sqrt(2), sqrt(3)

        A polynomial over a quadratic extension.
        Two conjugates x - a and x + a.

        >>> f = Poly(x - a, x, extension=a)
        >>> f.norm()
        Poly(x**2 - 2, x, domain='QQ')

        A polynomial over a quartic extension.
        Four conjugates x - a, x - a, x + a and x + a.

        >>> f = Poly(x - a, x, extension=(a, b))
        >>> f.norm()
        Poly(x**4 - 4*x**2 + 4, x, domain='QQ')

        Únorm)r  rj   r  r7   rÎ   )r_   ru  s     rd   r  z	Poly.norm‰  s;   € ô8 �1—5‘5˜&Ô!Ø—‘—
‘
“‰Aä'¨¨6Ó2Ð2à�u‰u�Q‹xˆrg   c                óÊ   — t        | j                  d«      r| j                  j                  «       \  }}}nt        | d«      ‚|| j	                  |«      | j	                  |«      fS )ah  
        Computes square-free norm of ``f``.

        Returns ``s``, ``f``, ``r``, such that ``g(x) = f(x-sa)`` and
        ``r(x) = Norm(g(x))`` is a square-free polynomial over ``K``,
        where ``a`` is the algebraic extension of the ground domain.

        Examples
        ========

        >>> from sympy import Poly, sqrt
        >>> from sympy.abc import x

        >>> s, f, r = Poly(x**2 + 1, x, extension=[sqrt(3)]).sqf_norm()

        >>> s
        [1]
        >>> f
        Poly(x**2 - 2*sqrt(3)*x + 4, x, domain='QQ<sqrt(3)>')
        >>> r
        Poly(x**4 - 4*x**2 + 16, x, domain='QQ')

        Úsqf_norm)r  rj   r  r7   rÎ   )r_   rš  r`   ru  s       rd   r  zPoly.sqf_norm¬  sR   € ô0 �1—5‘5˜*Ô%Ø—e‘e—n‘nÓ&‰GˆAˆq‘!ä'¨¨:Ó6Ð6à�!—%‘%˜“(˜AŸE™E !›HÐ$Ð$rg   c                óž   — t        | j                  d«      r| j                  j                  «       }nt        | d«      ‚| j	                  |«      S )zü
        Computes square-free part of ``f``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**3 - 3*x - 2, x).sqf_part()
        Poly(x**2 - x - 2, x, domain='ZZ')

        Úsqf_part)r  rj   r  r7   rÎ   r  s     rd   r  zPoly.sqf_partË  r  rg   c                ó&  — t        | j                  d«      r| j                  j                  |«      \  }}nt        | d«      ‚| j                  j                  j                  |«      |D ��cg c]  \  }}| j                  |«      |f‘Œ c}}fS c c}}w )a   
        Returns a list of square-free factors of ``f``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> f = 2*x**5 + 16*x**4 + 50*x**3 + 76*x**2 + 56*x + 16

        >>> Poly(f).sqf_list()
        (2, [(Poly(x + 1, x, domain='ZZ'), 2),
             (Poly(x + 2, x, domain='ZZ'), 3)])

        >>> Poly(f).sqf_list(all=True)
        (2, [(Poly(1, x, domain='ZZ'), 1),
             (Poly(x + 1, x, domain='ZZ'), 2),
             (Poly(x + 2, x, domain='ZZ'), 3)])

        Úsqf_list)r  rj   r  r7   r¾   r×   rÎ   )r_   Úallr£   Úfactorsr`   rR  s         rd   r  zPoly.sqf_listà  sq   € ô, �1—5‘5˜*Ô%ØŸU™UŸ^™^¨CÓ0‰NˆE‘7ä'¨¨:Ó6Ð6à�u‰u�y‰y×!Ñ! %Ó(ÀW×*M¹T¸QÀ¨A¯E©E°!«H°aª=Ó*MÐMÐMùÓ*Ms   Á+Bc                óÖ   — t        | j                  d«      r| j                  j                  |«      }nt        | d«      ‚|D ��cg c]  \  }}| j	                  |«      |f‘Œ c}}S c c}}w )a‰  
        Returns a list of square-free factors of ``f``.

        Examples
        ========

        >>> from sympy import Poly, expand
        >>> from sympy.abc import x

        >>> f = expand(2*(x + 1)**3*x**4)
        >>> f
        2*x**7 + 6*x**6 + 6*x**5 + 2*x**4

        >>> Poly(f).sqf_list_include()
        [(Poly(2, x, domain='ZZ'), 1),
         (Poly(x + 1, x, domain='ZZ'), 3),
         (Poly(x, x, domain='ZZ'), 4)]

        >>> Poly(f).sqf_list_include(all=True)
        [(Poly(2, x, domain='ZZ'), 1),
         (Poly(1, x, domain='ZZ'), 2),
         (Poly(x + 1, x, domain='ZZ'), 3),
         (Poly(x, x, domain='ZZ'), 4)]

        Úsqf_list_include)r  rj   r  r7   rÎ   )r_   r  r  r`   rR  s        rd   r  zPoly.sqf_list_includeý  sY   € ô4 �1—5‘5Ð,Ô-Ø—e‘e×,Ñ,¨SÓ1‰Gä'¨Ð+=Ó>Ð>à*1×2¡$ ! Q�—‘�q“˜1’Ó2Ð2ùÓ2s   ÁA%c                ó¼  — t        | j                  d«      r	 | j                  j                  «       \  }}nt        | d«      ‚| j                  j                  j                  |«      |D ��cg c]  \  }}| j                  |«      |f‘Œ c}}fS # t        $ r? | j	                  «       dk(  r| j                  «       g fcY S t        j                  | dfgfcY S w xY wc c}}w )a~  
        Returns a list of irreducible factors of ``f``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y

        >>> f = 2*x**5 + 2*x**4*y + 4*x**3 + 4*x**2*y + 2*x + 2*y

        >>> Poly(f).factor_list()
        (2, [(Poly(x + y, x, y, domain='ZZ'), 1),
             (Poly(x**2 + 1, x, y, domain='ZZ'), 2)])

        Úfactor_listr   r‚   )r  rj   r  r8   r�  r]   r   r¾  r7   r¾   r×   rÎ   )r_   r£   r  r`   rR  s        rd   r  zPoly.factor_list  s¼   € ô" �1—5‘5˜-Ô(ð+Ø!"§¡×!2Ñ!2Ó!4‘�‘wô (¨¨=Ó9Ð9à�u‰u�y‰y×!Ñ! %Ó(ÀW×*M¹T¸QÀ¨A¯E©E°!«H°aª=Ó*MÐMÐMøô ò +Ø—8‘8“: ’?ØŸ9™9›;¨˜?Ò*äŸ5™5 A q 6 (˜?Ò*ð	+üó +Ns   ˜B Á+CÂ.CÂ=CÃCc                óþ   — t        | j                  d«      r	 | j                  j                  «       }nt	        | d«      ‚|D ��cg c]  \  }}| j                  |«      |f‘Œ c}}S # t        $ r | dfgcY S w xY wc c}}w )a�  
        Returns a list of irreducible factors of ``f``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y

        >>> f = 2*x**5 + 2*x**4*y + 4*x**3 + 4*x**2*y + 2*x + 2*y

        >>> Poly(f).factor_list_include()
        [(Poly(2*x + 2*y, x, y, domain='ZZ'), 1),
         (Poly(x**2 + 1, x, y, domain='ZZ'), 2)]

        Úfactor_list_includer‚   )r  rj   r   r8   r7   rÎ   )r_   r  r`   rR  s       rd   r   zPoly.factor_list_include<  s{   € ô" �1—5‘5Ð/Ô0ð ØŸ%™%×3Ñ3Ó5‘ô (¨Ð+@ÓAÐAà*1×2¡$ ! Q�—‘�q“˜1’Ó2Ð2øô ò  Ø˜A˜�x’ð üó
 3s   ˜A% ÁA9Á%A6Á5A6c                óh  — |�%t        j                  |«      }|dk  rt        d«      ‚|�t        j                  |«      }|�t        j                  |«      }t        | j                  d«      r"| j                  j                  ||||||¬«      }nt        | d«      ‚|rLd„ }|st        t        ||«      «      S d„ }	|\  }
}t        t        ||
«      «      t        t        |	|«      «      fS d„ }|st        t        ||«      «      S d„ }	|\  }
}t        t        ||
«      «      t        t        |	|«      «      fS )	aÑ  
        Compute isolating intervals for roots of ``f``.

        For real roots the Vincent-Akritas-Strzebonski (VAS) continued fractions method is used.

        References
        ==========
        .. [#] Alkiviadis G. Akritas and Adam W. Strzebonski: A Comparative Study of Two Real Root
            Isolation Methods . Nonlinear Analysis: Modelling and Control, Vol. 10, No. 4, 297-304, 2005.
        .. [#] Alkiviadis G. Akritas, Adam W. Strzebonski and Panagiotis S. Vigklas: Improving the
            Performance of the Continued Fractions Method Using new Bounds of Positive Roots. Nonlinear
            Analysis: Modelling and Control, Vol. 13, No. 3, 265-279, 2008.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**2 - 3, x).intervals()
        [((-2, -1), 1), ((1, 2), 1)]
        >>> Poly(x**2 - 3, x).intervals(eps=1e-2)
        [((-26/15, -19/11), 1), ((19/11, 26/15), 1)]

        r   ú!'eps' must be a positive rationalÚ	intervals©r  ÚepsÚinfÚsupÚfastÚsqfc                ó`   — | \  }}t        j                  |«      t        j                  |«      fS rˆ   ©r-   r×   )Úintervalrš  rÛ  s      rd   Ú_realzPoly.intervals.<locals>._realƒ  s&   € Ø‘��1ÜŸ™ A›¬¯©°A«Ð7Ð7rg   c                óà   — | \  \  }}\  }}t        j                  |«      t        t        j                  |«      z  z   t        j                  |«      t        t        j                  |«      z  z   fS rˆ   ©r-   r×   r   )Ú	rectangleÚuÚvrš  rÛ  s        rd   Ú_complexz Poly.intervals.<locals>._complexŠ  sW   € Ø!*‘‘��A™˜˜AÜŸ™ A›¬¬2¯;©;°q«>Ñ)9Ñ9ÜŸ™ A›¬¬2¯;©;°q«>Ñ)9Ñ9ð;ð ;rg   c                ój   — | \  \  }}}t        j                  |«      t        j                  |«      f|fS rˆ   r+  )r,  rš  rÛ  rR  s       rd   r-  zPoly.intervals.<locals>._real“  s/   € Ø$‘	‘��A˜ÜŸ™ Q›¬¯©°Q«Ð8¸!Ð<Ð<rg   c                óê   — | \  \  \  }}\  }}}t        j                  |«      t        t        j                  |«      z  z   t        j                  |«      t        t        j                  |«      z  z   f|fS rˆ   r/  )r0  r1  r2  rš  rÛ  rR  s         rd   r3  z Poly.intervals.<locals>._complexš  sg   € Ø&/Ñ#Ñ ‘�!�Q™˜!˜Q !ÜŸ™ Q›¬!¬B¯K©K¸«NÑ*:Ñ:ÜŸ™ Q›¬!¬B¯K©K¸«NÑ*:Ñ:ð<Ø=>ð@ð @rg   )	r-   r    r  r  rj   r#  r7   rw   r¥   )r_   r  r%  r&  r'  r(  r)  rb   r-  r3  Ú	real_partÚcomplex_parts               rd   r#  zPoly.intervalsW  s3  € ð4 ˆ?Ü—*‘*˜S“/ˆCà�aŠxÜ Ð!DÓEÐEàˆ?Ü—*‘*˜S“/ˆCØˆ?Ü—*‘*˜S“/ˆCä�1—5‘5˜+Ô&Ø—U‘U—_‘_Ø˜S c¨s¸À3ð %ó H‰Fô (¨¨;Ó7Ð7áò8ñ ÜœC  vÓ.Ó/Ð/ò;ð
 '-Ñ#ˆI�|äœ˜E 9Ó-Ó.´´S¸À<Ó5PÓ0QÐQÐQò=ñ ÜœC  vÓ.Ó/Ð/ò@ð
 '-Ñ#ˆI�|äœ˜E 9Ó-Ó.´´S¸À<Ó5PÓ0QÐQÐQrg   c                óÚ  — |r| j                   st        d«      ‚t        j                  |«      t        j                  |«      }}|�%t        j                  |«      }|dk  rt	        d«      ‚|�t        |«      }n|€d}t        | j                  d«      r$| j                  j                  |||||¬«      \  }}nt        | d«      ‚t        j                  |«      t        j                  |«      fS )a  
        Refine an isolating interval of a root to the given precision.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**2 - 3, x).refine_root(1, 2, eps=1e-2)
        (19/11, 26/15)

        z&only square-free polynomials supportedr   r"  r‚   Úrefine_root)r%  Ústepsr(  )Úis_sqfr<   r-   r    r  r(  r  rj   r9  r7   r×   )	r_   rš  rÛ  r%  r:  r(  Ú	check_sqfr   ÚTs	            rd   r9  zPoly.refine_root£  sÉ   € ñ ˜QŸXšXÜ!Ð"JÓKÐKä�z‰z˜!‹}œbŸj™j¨›mˆ1ˆàˆ?Ü—*‘*˜S“/ˆCà�aŠxÜ Ð!DÓEÐEàÐÜ˜“J‰EØˆ[ØˆEä�1—5‘5˜-Ô(Ø—5‘5×$Ñ$ Q¨¨s¸%ÀdÐ$ÓK‰DˆA‰qä'¨¨=Ó9Ð9ä�{‰{˜1‹~œrŸ{™{¨1›~Ð-Ð-rg   c                ód  — d\  }}|�rt        |«      }|t        j                  u rd}nR|j                  «       \  }}|st	        j
                  |«      }n't        t        t        j
                  ||f«      «      d}}|�rt        |«      }|t        j                  u rd}nR|j                  «       \  }}|st	        j
                  |«      }n't        t        t        j
                  ||f«      «      d}}|rL|rJt        | j                  d«      r(| j                  j                  ||¬«      }t        |«      S t        | d«      ‚|r|�|t        j                  f}|r|�|t        j                  f}t        | j                  d«      r(| j                  j                  ||¬«      }t        |«      S t        | d«      ‚)a<  
        Return the number of roots of ``f`` in ``[inf, sup]`` interval.

        Examples
        ========

        >>> from sympy import Poly, I
        >>> from sympy.abc import x

        >>> Poly(x**4 - 4, x).count_roots(-3, 3)
        2
        >>> Poly(x**4 - 4, x).count_roots(0, 1 + 3*I)
        1

        ©TTNFÚcount_real_roots©r&  r'  Úcount_complex_roots)r%   r   r�  Úas_real_imagr-   r    rw   r¥   ÚInfinityr  rj   r@  r7   rÈ   rB  r   )r_   r&  r'  Úinf_realÚsup_realÚreÚimÚcounts           rd   Úcount_rootszPoly.count_rootsÈ  s�  € ð  (Ñˆ�(àˆ?Ü˜#“,ˆCà”a×(Ñ(Ñ(Ø‘à×)Ñ)Ó+‘��BáÜŸ*™* S›/‘Cä$(¬¬R¯Z©Z¸"¸b¸Ó)BÓ$CÀU˜�Càˆ?Ü˜#“,ˆCà”a—j‘jÑ Ø‘à×)Ñ)Ó+‘��BáÜŸ*™* S›/‘Cä$(¬¬R¯Z©Z¸"¸b¸Ó)BÓ$CÀU˜�Cá™Ü�q—u‘uÐ0Ô1ØŸ™×.Ñ.°3¸CÐ.Ó@�ô �u‹~Ðô ,¨AÐ/AÓBÐBá˜C˜OØœBŸG™G�n�á˜C˜OØœBŸG™G�n�ä�q—u‘uÐ3Ô4ØŸ™×1Ñ1°c¸sÐ1ÓC�ô �u‹~Ðô ,¨AÐ/DÓEÐErg   c                óZ   — t         j                  j                  j                  | ||¬«      S )a  
        Get an indexed root of a polynomial.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> f = Poly(2*x**3 - 7*x**2 + 4*x + 4)

        >>> f.root(0)
        -1/2
        >>> f.root(1)
        2
        >>> f.root(2)
        2
        >>> f.root(3)
        Traceback (most recent call last):
        ...
        IndexError: root index out of [-3, 2] range, got 3

        >>> Poly(x**5 + x + 1).root(0)
        CRootOf(x**3 - x**2 + 1, 0)

        ©Úradicals)ÚsympyÚpolysÚrootoftoolsÚrootof)r_   r   rM  s      rd   Úrootz	Poly.root  s&   € ô6 �{‰{×&Ñ&×-Ñ-¨a°ÀÐ-ÓJÐJrg   c                óŽ   — t         j                  j                  j                  j	                  | |¬«      }|r|S t        |d¬«      S )a�  
        Return a list of real roots with multiplicities.

        See :func:`real_roots` for more explanation.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(2*x**3 - 7*x**2 + 4*x + 4).real_roots()
        [-1/2, 2, 2]
        >>> Poly(x**3 + x + 1).real_roots()
        [CRootOf(x**3 + x + 1, 0)]
        rL  F©Úmultiple)rN  rO  rP  ÚCRootOfÚ
real_rootsrJ   )r_   rU  rM  Úrealss       rd   rW  zPoly.real_roots$  s>   € ô" —‘×'Ñ'×/Ñ/×:Ñ:¸1ÀxÐ:ÓPˆáØˆLä˜¨Ô/Ð/rg   c                óŽ   — t         j                  j                  j                  j	                  | |¬«      }|r|S t        |d¬«      S )aÑ  
        Return a list of real and complex roots with multiplicities.

        See :func:`all_roots` for more explanation.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(2*x**3 - 7*x**2 + 4*x + 4).all_roots()
        [-1/2, 2, 2]
        >>> Poly(x**3 + x + 1).all_roots()
        [CRootOf(x**3 + x + 1, 0),
         CRootOf(x**3 + x + 1, 1),
         CRootOf(x**3 + x + 1, 2)]

        rL  FrT  )rN  rO  rP  rV  Ú	all_rootsrJ   )r_   rU  rM  Úrootss       rd   rZ  zPoly.all_roots<  s>   € ô( —‘×'Ñ'×/Ñ/×9Ñ9¸!ÀhÐ9ÓOˆáØˆLä˜¨Ô/Ð/rg   c                óâ  ‡
— | j                   rt        d| z  «      ‚| j                  «       dk  rg S | j                  j                  t
        u r'| j                  «       D �cg c]  }t        |«      ‘Œ }}nï| j                  j                  t        u rY| j                  «       D �cg c]  }|j                  ‘Œ }}t        |Ž }| j                  «       D �cg c]  }t        ||z  «      ‘Œ }}nz| j                  «       D �cg c]"  }|j                  |¬«      j                  «       ‘Œ$ }}t        j                  |«      5  	 |D �cg c]  }t        j                  |Ž ‘Œ }}	 ddd«       t        j$                  j&                  }|t        j$                  _        ddlmŠ
 	 t        j,                  |||d| j                  «       dz  ¬	«      }	t/        t1        t2        t5        |	ˆ
fd
„¬«      «      «      }	|t        j$                  _        |	S c c}w c c}w c c}w c c}w c c}w # t         $ r# t#        d| j                  j                  z  «      ‚w xY w# 1 sw Y   ŒðxY w# t6        $ ru 	 t        j,                  |||d| j                  «       dz  ¬	«      }	t/        t1        t2        t5        |	ˆ
fd„¬«      «      «      }	n# t6        $ r t7        d|›d|›�«      ‚w xY wY Œèw xY w# |t        j$                  _        w xY w)aš  
        Compute numerical approximations of roots of ``f``.

        Parameters
        ==========

        n ... the number of digits to calculate
        maxsteps ... the maximum number of iterations to do

        If the accuracy `n` cannot be reached in `maxsteps`, it will raise an
        exception. You need to rerun with higher maxsteps.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**2 - 3).nroots(n=15)
        [-1.73205080756888, 1.73205080756888]
        >>> Poly(x**2 - 3).nroots(n=30)
        [-1.73205080756887729352744634151, 1.73205080756887729352744634151]

        z$Cannot compute numerical roots of %sr   )r*  z!Numerical domain expected, got %sN)ÚsignFé
   )ÚmaxstepsÚcleanupÚerrorÚ	extraprecc                ó†   •— | j                   rdnd| j                  t        | j                   «       ‰| j                   «      fS ©Nr‚   r   ©ÚimagÚrealrc  ©ru  r]  s    €rd   ú<lambda>zPoly.nroots.<locals>.<lambda>—  s1   ø€ °!·&²&©Q¸aÀÇÁÌÈQÏVÉVËÑVZÐ[\×[aÑ[aÓVbÐ,c€ rg   ©Úkeyé   c                ó†   •— | j                   rdnd| j                  t        | j                   «       ‰| j                   «      fS rd  re  rh  s    €rd   ri  zPoly.nroots.<locals>.<lambda>ž  s4   ø€ °a·f²f±À!ÀQÇVÁVÌSÐQR×QWÑQWË[ÑZ^Ð_`×_eÑ_eÓZfÐ0g€ rg   z$convergence to root failed; try n < z or maxsteps > )Úis_multivariater=   r�  rj   r¾   r.   r1  r(  r-   rt  r   r   rC  ÚmpmathÚworkdpsÚmpcr™  r8   ÚmpÚdpsÚ$sympy.functions.elementary.complexesr]  Ú	polyrootsrw   r¥   r%   ÚsortedrP   )r_   r*  r_  r`  r£   rÁ   ÚdenomsÚfacrs  r[  r]  s             @rd   ÚnrootszPoly.nrootsW  sŽ  ø€ ð2 ×ÒÜ-Ø6¸Ñ:ó<ð <ð �8‰8‹:˜Š?ØˆIð
 �5‰5�9‰9œ‰?Ø./¯l©l«nÖ= U”c˜%•jÐ=ˆFÑ=Ø�U‰U�Y‰Yœ"‰_Ø+,¯<©<«>Ö: %�e—g“gÐ:ˆFÐ:Ü˜�-ˆCØ23·,±,³.ÖA¨”c˜% ™)•nÐAˆFÑAð "#§¡£ö1Øð —k‘k A�kÓ&×3Ñ3Õ5ð 1ˆFð 1ä—‘ Ó"ñ 'ð'Ø>DÖE°UœfŸj™j¨%Ò0ÐE�FÑE÷'ô �i‰i�m‰mˆØŒ�	‰	Œå=ð	 ô ×$Ñ$ V°hØ#¨5¸A¿H¹H»JÀr¹MôKˆEô
 œœWÜ�uÓ"cÔdófó gˆEð  ŒF�I‰IŒMàˆùòW >ùâ:ùâAùò1ùò FøÜ ò 'Ü%Ð&IØŸE™EŸI™Iñ'&ó 'ð 'ð'ú÷'ð 'ûô* ò 
	"ð	"ä×(Ñ(¨¸(Ø#¨5¸A¿H¹H»JÀr¹MôK�äœS¤Ü˜5Ó&gÔhójó k‘øä ò "Ý#â‘xð!ó"ð "ð"úñ ð
	"ûð  ŒF�I‰I�Mús†   ÁHÂ"HÃHÃ;'HÄ9I
Ä;HÄ?HÅHÆAI ÈHÈ,IÉI
É
IÉ	KÉ AJ3Ê2KÊ3KËKËK ËKËK ËK.c                óÆ   — | j                   rt        d| z  «      ‚i }| j                  «       d   D ].  \  }}|j                  sŒ|j	                  «       \  }}||| |z  <   Œ0 |S )a  
        Compute roots of ``f`` by factorization in the ground domain.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**6 - 4*x**4 + 4*x**3 - x**2).ground_roots()
        {0: 2, 1: 2}

        z!Cannot compute ground roots of %sr‚   )rn  r=   r  Ú	is_linearr1  )r_   r[  ÚfactorrR  rÃ  rÄ  s         rd   Úground_rootszPoly.ground_roots¨  sx   € ð ×ÒÜ-Ø3°aÑ7ó9ð 9ð ˆàŸ™›¨Ñ+ò 	 ‰IˆF�AØ×ÓØ×(Ñ(Ó*‘��1Ø��q�b˜‘d’ð	 ð
 ˆrg   c                óR  — | j                   rt        d«      ‚t        |«      }|j                  r|dk\  rt	        |«      }nt        d|z  «      ‚| j                  }t        d«      }| j                  | j                  j                  ||z  |z
  ||«      «      }|j                  ||«      S )af  
        Construct a polynomial with n-th powers of roots of ``f``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> f = Poly(x**4 - x**2 + 1)

        >>> f.nth_power_roots_poly(2)
        Poly(x**4 - 2*x**3 + 3*x**2 - 2*x + 1, x, domain='ZZ')
        >>> f.nth_power_roots_poly(3)
        Poly(x**4 + 2*x**2 + 1, x, domain='ZZ')
        >>> f.nth_power_roots_poly(4)
        Poly(x**4 + 2*x**3 + 3*x**2 + 2*x + 1, x, domain='ZZ')
        >>> f.nth_power_roots_poly(12)
        Poly(x**4 - 4*x**3 + 6*x**2 - 4*x + 1, x, domain='ZZ')

        zmust be a univariate polynomialr‚   z&'n' must an integer and n >= 1, got %srÛ  )rn  r=   r%   Ú
is_Integerr(  r  rÂ   r#   rã  r§   rX   rõ   )r_   r*  r¨  r  rÛ  ru  s         rd   Únth_power_roots_polyzPoly.nth_power_roots_polyÃ  sš   € ð, ×ÒÜ-Ø1ó3ð 3ô �A‹Jˆà�<Š<˜A šFÜ�A“‰AäÐEÈÑIÓJÐJà�E‰EˆÜ�#‹Jˆà�K‰K˜Ÿ™×-Ñ-¨a°©d°Q©h¸¸1Ó=Ó>ˆà�y‰y˜˜A‹Ðrg   c                óô   — | j                   rt        d«      ‚| j                  «       }|j                  s&|j                  s|j
                  st        d|z  «      ‚| j                  || j                  «       «      S )a†  
        Find roots of a square-free polynomial ``f`` from ``candidates``.

        Explanation
        ===========

        If ``f`` is a square-free polynomial and ``candidates`` is a superset
        of the roots of ``f``, then ``f.which_real_roots(candidates)`` returns a
        list containing exactly the set of roots of ``f``. The domain must be
        :ref:`ZZ`, :ref:`QQ`, or :ref:`QQ(a)` and``f`` must be univariate and
        square-free.

        The list ``candidates`` must be a superset of the real roots of ``f``
        and ``f.which_real_roots(candidates)`` returns the set of real roots
        of ``f``. The output preserves the order of the order of ``candidates``.

        Examples
        ========

        >>> from sympy import Poly, sqrt
        >>> from sympy.abc import x

        >>> f = Poly(x**4 - 1)
        >>> f.which_real_roots([-1, 1, 0, -2, 2])
        [-1, 1]
        >>> f.which_real_roots([-1, 1, 1, 1, 1])
        [-1, 1]

        This method is useful as lifting to rational coefficients
        produced extraneous roots, which we can filter out with
        this method.

        >>> f = Poly(sqrt(2)*x**3 + x**2 - 1, x, extension=True)
        >>> f.lift()
        Poly(-2*x**6 + x**4 - 2*x**2 + 1, x, domain='QQ')
        >>> f.lift().real_roots()
        [-sqrt(2)/2, sqrt(2)/2]
        >>> f.which_real_roots(f.lift().real_roots())
        [sqrt(2)/2]

        This procedure is already done internally when calling
        `.real_roots()` on a polynomial with algebraic coefficients.

        >>> f.real_roots()
        [sqrt(2)/2]

        See Also
        ========

        same_root
        which_all_roots
        úMust be a univariate polynomialz#root counting not supported over %s)	rn  r=   rÆ   Úis_ZZÚis_QQÚis_AlgebraicFieldrq   Ú_which_rootsrJ  )r_   Ú
candidatesr¾   s      rd   Úwhich_real_rootszPoly.which_real_rootsë  sn   € ðj ×ÒÜ-Ø1ó3ð 3ð �l‰l‹nˆà—	’	˜SŸYšY¨#×*?Ò*?Ü%Ø5¸Ñ;ó=ð =ð �~‰~˜j¨!¯-©-«/Ó:Ð:rg   c                óp   — | j                   rt        d«      ‚| j                  || j                  «       «      S )a]  
        Find roots of a square-free polynomial ``f`` from ``candidates``.

        Explanation
        ===========

        If ``f`` is a square-free polynomial and ``candidates`` is a superset
        of the roots of ``f``, then ``f.which_all_roots(candidates)`` returns a
        list containing exactly the set of roots of ``f``. The polynomial``f``
        must be univariate and square-free.

        The list ``candidates`` must be a superset of the complex roots of
        ``f`` and ``f.which_all_roots(candidates)`` returns exactly the
        set of all complex roots of ``f``. The output preserves the order of
        the order of ``candidates``.

        Examples
        ========

        >>> from sympy import Poly, I
        >>> from sympy.abc import x

        >>> f = Poly(x**4 - 1)
        >>> f.which_all_roots([-1, 1, -I, I, 0])
        [-1, 1, -I, I]
        >>> f.which_all_roots([-1, 1, -I, I, I, I])
        [-1, 1, -I, I]

        This method is useful as lifting to rational coefficients
        produced extraneous roots, which we can filter out with
        this method.

        >>> f = Poly(x**2 + I*x - 1, x, extension=True)
        >>> f.lift()
        Poly(x**4 - x**2 + 1, x, domain='ZZ')
        >>> f.lift().all_roots()
        [CRootOf(x**4 - x**2 + 1, 0),
        CRootOf(x**4 - x**2 + 1, 1),
        CRootOf(x**4 - x**2 + 1, 2),
        CRootOf(x**4 - x**2 + 1, 3)]
        >>> f.which_all_roots(f.lift().all_roots())
        [CRootOf(x**4 - x**2 + 1, 0), CRootOf(x**4 - x**2 + 1, 2)]

        This procedure is already done internally when calling
        `.all_roots()` on a polynomial with algebraic coefficients,
        or polynomials with Gaussian domains.

        >>> f.all_roots()
        [CRootOf(x**4 - x**2 + 1, 0), CRootOf(x**4 - x**2 + 1, 2)]

        See Also
        ========

        same_root
        which_real_roots
        r‚  )rn  r=   r†  r�  )r_   r‡  s     rd   Úwhich_all_rootszPoly.which_all_roots,  s7   € ðr ×ÒÜ-Ø1ó3ð 3ð �~‰~˜j¨!¯(©(«*Ó5Ð5rg   c                óZ  — d}t        |«      }t        |«      |kD  rxt        |j                  «       «      D ]H  } | |«      j	                  |d|z  ¬«      }t        |«      j                  dk\  sŒ8|j                  |«       ŒJ |dz  }t        |«      |kD  rŒxt        |j                  «       «      S )Nr^  é   )Úmaxn)r	   r„   rw   Úkeysr   rc  Ú_precÚpop)r_   r‡  Ú	num_rootsÚprecÚroot_countsru  Úf_rs          rd   r†  zPoly._which_rootsk  s¡   € Øˆä˜jÓ)ˆä�+Ó Ò*Ü˜+×*Ñ*Ó,Ó-ò '�á˜“d—j‘j ¨A¨d©F�jÓ3�Ü�s“8—>‘> QÓ&Ø—O‘O AÕ&ð	'ð �A‰IˆDô �+Ó Ó*ô �K×$Ñ$Ó&Ó'Ð'rg   c                óº  ‡— | j                   rt        d«      ‚| j                  j                  «       }| j                  j                  «       j                  |«      }|dz  }t        d|z  di «      \  }}}}t        |«      }|dz  |dz  z   Šˆfd„}	 |	|«       |	|«      }}
|
j                  |j                  z
  dz  |
j                  |j                  z
  dz  z   |k  S )a  
        Decide whether two roots of this polynomial are equal.

        Examples
        ========

        >>> from sympy import Poly, cyclotomic_poly, exp, I, pi
        >>> f = Poly(cyclotomic_poly(5))
        >>> r0 = exp(2*I*pi/5)
        >>> indices = [i for i, r in enumerate(f.all_roots()) if f.same_root(r, r0)]
        >>> print(indices)
        [3]

        Raises
        ======

        DomainError
            If the domain of the polynomial is not :ref:`ZZ`, :ref:`QQ`,
            :ref:`RR`, or :ref:`CC`.
        MultivariatePolynomialError
            If the polynomial is not univariate.
        PolynomialError
            If the polynomial is of degree < 2.

        See Also
        ========

        which_real_roots
        which_all_roots
        r‚  é	   r‚   rŒ  c                ó0   •— t        t        | ‰¬«      «      S )NrÈ  )r   r   )r  r)  s    €rd   ri  z Poly.same_root.<locals>.<lambda>ª  s   ø€ ”~Ô&?ÀÀQÔ&GÓH€ rg   )rn  r=   rj   Úmignotte_sep_bound_squaredrS   Ú	get_fieldr×   r   r   rg  rf  )r_   rÃ  rÄ  Údom_delta_sqÚdelta_sqÚeps_sqru  rÍ   r*  ÚevÚAÚBr)  s               @rd   Ú	same_rootzPoly.same_root{  sÙ   ø€ ð> ×ÒÜ-Ø1ó3ð 3ð —u‘u×7Ñ7Ó9ˆØ—8‘8×%Ñ%Ó'×0Ñ0°Ó>ˆð ˜A‘ˆä˜1˜V™8 Q¨Ó+‰
ˆˆ1ˆa�Ü�A‹Jˆà�!‰V˜˜A™ÑˆãHˆñ �!‹u‘b˜“eˆ1ˆØ—‘˜Ÿ™‘ !Ñ# q§v¡v°·±¡¸Ñ&:Ñ:¸VÑCÐCrg   c                óf  — | j                  |«      \  }}}}t        |d«      r|j                  ||¬«      }nt        | d«      ‚|sY|j                  r|j                  «       }|\  }}	}
}|j                  |«      }|j                  |	«      }	||	z   ||
«       ||«      fS t        t        ||«      «      S )aÐ  
        Cancel common factors in a rational function ``f/g``.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(2*x**2 - 2, x).cancel(Poly(x**2 - 2*x + 1, x))
        (1, Poly(2*x + 2, x, domain='ZZ'), Poly(x - 1, x, domain='ZZ'))

        >>> Poly(2*x**2 - 2, x).cancel(Poly(x**2 - 2*x + 1, x), include=True)
        (Poly(2*x + 2, x, domain='ZZ'), Poly(x - 1, x, domain='ZZ'))

        Úcancel)Úinclude)	rÌ   r  r¢  r7   r¿  rÀ  r×   r7  r¥   )r_   r`   r£  r¾   rÎ   rÏ   rÐ   rb   ÚcpÚcqrø  rt  s               rd   r¢  zPoly.cancel³  s­   € ð" Ÿ™ !›‰ˆˆS�!�Qä�1�hÔØ—X‘X˜a¨�XÓ1‰Fä'¨¨8Ó4Ð4áØ×!Ò!Ø—l‘l“n�à!‰LˆB��A�qà—‘˜bÓ!ˆBØ—‘˜bÓ!ˆBà�b‘5™#˜a›&¡# a£&Ð(Ð(äœ˜S &Ó)Ó*Ð*rg   c                ór  — | j                   r| j                  t        t        fvrt	        d«      ‚| j
                  r%| j                  t        k(  r| t        j                  fS | j                  «       }|j                  «       \  }}|j                  t        |j                  «      |«      j                  «       |fS )aQ  
        Turn any univariate polynomial over :ref:`QQ` or :ref:`ZZ` into a monic
        polynomial over :ref:`ZZ`, by scaling the roots as necessary.

        Explanation
        ===========

        This operation can be performed whether or not *f* is irreducible; when
        it is, this can be understood as determining an algebraic integer
        generating the same field as a root of *f*.

        Examples
        ========

        >>> from sympy import Poly, S
        >>> from sympy.abc import x
        >>> f = Poly(x**2/2 + S(1)/4 * x + S(1)/8, x, domain='QQ')
        >>> f.make_monic_over_integers_by_scaling_roots()
        (Poly(x**2 + 2*x + 4, x, domain='ZZ'), 4)

        Returns
        =======

        Pair ``(g, c)``
            g is the polynomial

            c is the integer by which the roots had to be scaled

        z,Polynomial must be univariate over ZZ or QQ.)rÿ   rS   r.   r-   r  Úis_monicrÊ   rú  r½  r  rW   rÂ   r  )r_   Úfmrâ   rÍ   s       rd   Ú)make_monic_over_integers_by_scaling_rootsz.Poly.make_monic_over_integers_by_scaling_rootsØ  s‡   € ð< �Š !§(¡(´2´r°(Ñ":ÜÐKÓLÐLØ�:Š:˜!Ÿ(™(¤bš.Ø”b—f‘f�9Ðà—‘“ˆBØ—?‘?Ó$‰DˆAˆqØ—<‘<¤ R§V¡V£¨aÓ0×8Ñ8Ó:¸AÐ=Ð=rg   c                ó  — ddl m}m}m}m} | j
                  r$| j                  r| j                  t        t        fvrt        d«      ‚||||dœ}t        |j                  «       «      }	| j                  «       }
|
|	kD  rt        d|	› d�«      ‚|
dk  rt        d«      ‚|
dk(  rdd	lm} |j                   d
}}n>|
dk(  rddlm} |j$                  d}}n$| j'                  «       \  }} ||
   |||¬«      \  }}|r|n|j)                  «       }||fS )aŽ  
        Compute the Galois group of this polynomial.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x
        >>> f = Poly(x**4 - 2)
        >>> G, _ = f.galois_group(by_name=True)
        >>> print(G)
        S4TransitiveSubgroups.D4

        See Also
        ========

        sympy.polys.numberfields.galoisgroups.galois_group

        r   )Ú_galois_group_degree_3Ú_galois_group_degree_4_lookupÚ(_galois_group_degree_5_lookup_ext_factorÚ_galois_group_degree_6_lookupz<Polynomial must be irreducible and univariate over ZZ or QQ.)é   é   é   é   zOnly polynomials up to degree z are supported.r‚   z(Constant polynomial has no Galois group.)ÚS1TransitiveSubgroupsTrŒ  )ÚS2TransitiveSubgroupsF)Ú	max_triesÚ	randomize)Ú%sympy.polys.numberfields.galoisgroupsr«  r¬  r­  r®  rÿ   Úis_irreduciblerS   r.   r-   r  ÚmaxrŽ  r�  Úsympy.combinatorics.galoisr³  ÚS1r´  ÚS2r©  Úget_perm_group)r_   Úby_namerµ  r¶  r«  r¬  r­  r®  ÚggÚmax_supportedr*  r³  ÚnameÚaltr´  r`   rÍ   rÐ   s                     rd   Úgalois_groupzPoly.galois_groupÿ  s  € ÷(	
ó 	
ð
 —’Ø×#Ò#Ø�x‰x¤¤B˜xÑ'äÐ[Ó\Ð\à%Ø,Ø7Ø,ñ	
ˆô ˜BŸG™G›I›ˆØ�H‰H‹JˆØˆ}ÒÜÐ=¸m¸_ÈOÐ\Ó]Ð]Ø�ŠUÜÐGÓHÐHØ�!ŠVÝHØ-×0Ñ0°$�#‰DØ�!ŠVÝHØ-×0Ñ0°%�#‰Dà×>Ñ>Ó@‰DˆAˆqØ˜˜1™˜a¨9À	ÔJ‰IˆD�#Ù‰D ×!4Ñ!4Ó!6ˆØ�#ˆvˆrg   c                ó.   — | j                   j                  S )a  
        Returns ``True`` if ``f`` is a zero polynomial.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(0, x).is_zero
        True
        >>> Poly(1, x).is_zero
        False

        )rj   Úis_zerorè   s    rd   rÅ  zPoly.is_zero5  s   € ð" �u‰u�}‰}Ðrg   c                ó.   — | j                   j                  S )a  
        Returns ``True`` if ``f`` is a unit polynomial.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(0, x).is_one
        False
        >>> Poly(1, x).is_one
        True

        )rj   Úis_onerè   s    rd   rÇ  zPoly.is_oneH  ó   € ð" �u‰u�|‰|Ðrg   c                ó.   — | j                   j                  S )a   
        Returns ``True`` if ``f`` is a square-free polynomial.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**2 - 2*x + 1, x).is_sqf
        False
        >>> Poly(x**2 - 1, x).is_sqf
        True

        )rj   r;  rè   s    rd   r;  zPoly.is_sqf[  rÈ  rg   c                ó.   — | j                   j                  S )a   
        Returns ``True`` if the leading coefficient of ``f`` is one.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x + 2, x).is_monic
        True
        >>> Poly(2*x + 2, x).is_monic
        False

        )rj   r§  rè   s    rd   r§  zPoly.is_monicn  s   € ð" �u‰u�~‰~Ðrg   c                ó.   — | j                   j                  S )a;  
        Returns ``True`` if GCD of the coefficients of ``f`` is one.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(2*x**2 + 6*x + 12, x).is_primitive
        False
        >>> Poly(x**2 + 3*x + 6, x).is_primitive
        True

        )rj   Úis_primitiverè   s    rd   rÌ  zPoly.is_primitive�  ó   € ð" �u‰u×!Ñ!Ð!rg   c                ó.   — | j                   j                  S )aJ  
        Returns ``True`` if ``f`` is an element of the ground domain.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y

        >>> Poly(x, x).is_ground
        False
        >>> Poly(2, x).is_ground
        True
        >>> Poly(y, x).is_ground
        True

        )rj   Ú	is_groundrè   s    rd   rÏ  zPoly.is_ground”  s   € ð& �u‰u�‰Ðrg   c                ó.   — | j                   j                  S )a,  
        Returns ``True`` if ``f`` is linear in all its variables.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y

        >>> Poly(x + y + 2, x, y).is_linear
        True
        >>> Poly(x*y + 2, x, y).is_linear
        False

        )rj   r{  rè   s    rd   r{  zPoly.is_linear©  s   € ð" �u‰u�‰Ðrg   c                ó.   — | j                   j                  S )a6  
        Returns ``True`` if ``f`` is quadratic in all its variables.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y

        >>> Poly(x*y + 2, x, y).is_quadratic
        True
        >>> Poly(x*y**2 + 2, x, y).is_quadratic
        False

        )rj   Úis_quadraticrè   s    rd   rÒ  zPoly.is_quadratic¼  rÍ  rg   c                ó.   — | j                   j                  S )a%  
        Returns ``True`` if ``f`` is zero or has only one term.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(3*x**2, x).is_monomial
        True
        >>> Poly(3*x**2 + 1, x).is_monomial
        False

        )rj   Úis_monomialrè   s    rd   rÔ  zPoly.is_monomialÏ  s   € ð" �u‰u× Ñ Ð rg   c                ó.   — | j                   j                  S )aZ  
        Returns ``True`` if ``f`` is a homogeneous polynomial.

        A homogeneous polynomial is a polynomial whose all monomials with
        non-zero coefficients have the same total degree. If you want not
        only to check if a polynomial is homogeneous but also compute its
        homogeneous order, then use :func:`Poly.homogeneous_order`.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y

        >>> Poly(x**2 + x*y, x, y).is_homogeneous
        True
        >>> Poly(x**3 + x*y, x, y).is_homogeneous
        False

        )rj   Úis_homogeneousrè   s    rd   rÖ  zPoly.is_homogeneousâ  s   € ð, �u‰u×#Ñ#Ð#rg   c                ó.   — | j                   j                  S )aG  
        Returns ``True`` if ``f`` has no factors over its domain.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> Poly(x**2 + x + 1, x, modulus=2).is_irreducible
        True
        >>> Poly(x**2 + 1, x, modulus=2).is_irreducible
        False

        )rj   r¸  rè   s    rd   r¸  zPoly.is_irreducibleú  s   € ð" �u‰u×#Ñ#Ð#rg   c                ó2   — t        | j                  «      dk(  S )a»  
        Returns ``True`` if ``f`` is a univariate polynomial.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y

        >>> Poly(x**2 + x + 1, x).is_univariate
        True
        >>> Poly(x*y**2 + x*y + 1, x, y).is_univariate
        False
        >>> Poly(x*y**2 + x*y + 1, x).is_univariate
        True
        >>> Poly(x**2 + x + 1, x, y).is_univariate
        False

        r‚   ©r„   rY   rè   s    rd   rÿ   zPoly.is_univariate  ó   € ô* �1—6‘6‹{˜aÑÐrg   c                ó2   — t        | j                  «      dk7  S )aÅ  
        Returns ``True`` if ``f`` is a multivariate polynomial.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x, y

        >>> Poly(x**2 + x + 1, x).is_multivariate
        False
        >>> Poly(x*y**2 + x*y + 1, x, y).is_multivariate
        True
        >>> Poly(x*y**2 + x*y + 1, x).is_multivariate
        False
        >>> Poly(x**2 + x + 1, x, y).is_multivariate
        True

        r‚   rÙ  rè   s    rd   rn  zPoly.is_multivariate$  rÚ  rg   c                ó.   — | j                   j                  S )a“  
        Returns ``True`` if ``f`` is a cyclotomic polnomial.

        Examples
        ========

        >>> from sympy import Poly
        >>> from sympy.abc import x

        >>> f = x**16 + x**14 - x**10 + x**8 - x**6 + x**2 + 1

        >>> Poly(f).is_cyclotomic
        False

        >>> g = x**16 + x**14 - x**10 - x**8 - x**6 + x**2 + 1

        >>> Poly(g).is_cyclotomic
        True

        )rj   Úis_cyclotomicrè   s    rd   rÝ  zPoly.is_cyclotomic;  s   € ð, �u‰u×"Ñ"Ð"rg   c                ó"   — | j                  «       S rˆ   )rc  rè   s    rd   Ú__abs__zPoly.__abs__S  ó   € Ø�u‰u‹wˆrg   c                ó"   — | j                  «       S rˆ   )re  rè   s    rd   Ú__neg__zPoly.__neg__V  rà  rg   c                ó$   — | j                  |«      S rˆ   ©r  ©r_   r`   s     rd   Ú__add__zPoly.__add__Y  ó   € à�u‰u�Q‹xˆrg   c                ó$   — |j                  | «      S rˆ   rä  rå  s     rd   Ú__radd__zPoly.__radd__]  rç  rg   c                ó$   — | j                  |«      S rˆ   ©rk  rå  s     rd   Ú__sub__zPoly.__sub__a  rç  rg   c                ó$   — |j                  | «      S rˆ   rë  rå  s     rd   Ú__rsub__zPoly.__rsub__e  rç  rg   c                ó$   — | j                  |«      S rˆ   r   rå  s     rd   Ú__mul__zPoly.__mul__i  rç  rg   c                ó$   — |j                  | «      S rˆ   r   rå  s     rd   Ú__rmul__zPoly.__rmul__m  rç  rg   r*  c                óR   — |j                   r|dk\  r| j                  |«      S t        S )Nr   )r  rp  r[   )r_   r*  s     rd   Ú__pow__zPoly.__pow__q  s"   € à�<Š<˜A šFØ—5‘5˜“8ˆOä!Ð!rg   c                ó$   — | j                  |«      S rˆ   ©r~  rå  s     rd   Ú
__divmod__zPoly.__divmod__x  rç  rg   c                ó$   — |j                  | «      S rˆ   rö  rå  s     rd   Ú__rdivmod__zPoly.__rdivmod__|  rç  rg   c                ó$   — | j                  |«      S rˆ   ©r…  rå  s     rd   Ú__mod__zPoly.__mod__€  rç  rg   c                ó$   — |j                  | «      S rˆ   rû  rå  s     rd   Ú__rmod__zPoly.__rmod__„  rç  rg   c                ó$   — | j                  |«      S rˆ   ©r‰  rå  s     rd   Ú__floordiv__zPoly.__floordiv__ˆ  rç  rg   c                ó$   — |j                  | «      S rˆ   r   rå  s     rd   Ú__rfloordiv__zPoly.__rfloordiv__Œ  rç  rg   r`   c                óD   — | j                  «       |j                  «       z  S rˆ   ©r]   rå  s     rd   Ú__truediv__zPoly.__truediv__�  ó   € à�y‰y‹{˜1Ÿ9™9›;Ñ&Ð&rg   c                óD   — |j                  «       | j                  «       z  S rˆ   r  rå  s     rd   Ú__rtruediv__zPoly.__rtruediv__”  r  rg   Úotherc                ór  — | |}}|j                   s-	 |j                  ||j                  |j                  «       ¬«      }|j                  |j                  k7  ry|j                  j                  |j                  j                  k7  ry|j                  |j                  k(  S # t        t
        t        f$ r Y yw xY w©Nr$  F)	ry   r§   rY   rÆ   r<   r8   r9   rj   r¾   )r‹   r
  r_   r`   s       rd   Ú__eq__zPoly.__eq__˜  s’   € à�Uˆ1ˆà�yŠyðØ—K‘K  1§6¡6°!·,±,³.�KÓA�ð �6‰6�Q—V‘VÒØà�5‰5�9‰9˜Ÿ™Ÿ	™	Ò!Øà�u‰u˜Ÿ™‰~Ðøô $¤[´.ÐAò Ùðús   ’,B ÂB6Â5B6c                ó   — | |k(   S rˆ   r  rå  s     rd   Ú__ne__zPoly.__ne__ª  s   € à˜‘6ˆzÐrg   c                ó   — | j                    S rˆ   )rÅ  rè   s    rd   Ú__bool__zPoly.__bool__®  s   € Ø—9‘9ˆ}Ðrg   c                óD   — |s| |k(  S | j                  t        |«      «      S rˆ   )Ú
_strict_eqr%   ©r_   r`   Ústricts      rd   ÚeqzPoly.eq±  s!   € ÙØ˜‘6ˆMà—<‘<¤¨£
Ó+Ð+rg   c                ó*   — | j                  ||¬«       S )N©r  )r  r  s      rd   ÚnezPoly.ne·  s   € Ø—4‘4˜ &�4Ó)Ð)Ð)rg   c                ó¶   — t        || j                  «      xrB | j                  |j                  k(  xr' | j                  j	                  |j                  d¬«      S ©NTr  )rV   r§   rY   rj   r  rå  s     rd   r  zPoly._strict_eqº  s@   € Ü˜!˜QŸ[™[Ó)Ò_¨a¯f©f¸¿¹Ñ.>Ò_À1Ç5Á5Ç8Á8ÈAÏEÉEÐZ^À8ÓC_Ð_rg   )ÚreturnrW   ©NNrˆ   )FF)F©T©r   )r‚   F©NT)r  z#tuple[Expr, list[tuple[Poly, int]]])FNNNFF©NNFFr?  ©rl  é2   T)Fé   F)Èr^   Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__Úis_commutativery   Ú_op_priorityÚ__annotations__r€   Úclassmethodr†   ÚpropertyrŒ   r~   r�   r’   r–   r™   rX   ru   rv   rz   r{   rr   r³   r¹   rº   rÂ   rS   rÈ   rÊ   rÑ   rÌ   rÎ   r«   rÆ   rí   rñ   rø   rm   rõ   r  rª   r  r  r  r¬   r   r%  r'  rÁ   r¸   r  r1  r3  r5  r8  r:  r  r?  r]   rE  rG  rI  rL  rQ  rU  rW  r[  r]  r_  ra  rc  re  r  rk  r   rn  rp  rs  rw  ry  r{  r~  r…  r‰  r‹  r  r�  r“  r•  r—  r˜  r�  rŸ  r¢  r¦  r¤  r£   r®  r°  r´  r¶  r¸  rº  r½  rÅ  rÇ  rÍ  Ú_eval_derivativerô   rÕ  r×  rÚ  rÝ  rß  rá  rã  rç  ré  rì  rî  rò  rõ  r÷  rú  rý  rÿ  r  r  r  r	  r  r  r  r  r  r  r  r  r  r   r#  r9  rJ  rR  rW  rZ  ry  r}  r€  rˆ  rŠ  r†  r   r¢  r©  rÃ  rÅ  rÇ  r;  r§  rÌ  rÏ  r{  rÒ  rÔ  rÖ  r¸  rÿ   rn  rÝ  rß  râ  rf   ræ  ré  rì  rî  rð  rò  r   r[   rô  r÷  rù  rü  rþ  r  r  r  r	  r  r  r  r  r  r  Ú__classcell__©r§   s   @rd   rW   rW   j   s  ø… ñ3ðj  €Ià€NØ€GØ€Là	ƒHØ
Óó0ð> ñó ðð ñEó ðEð ñ(ó ð(ò'ð ñ(ó ð(ð
 ñ(ó ð(ð
 ñ(ó ð(ð
 ñ(ó ð(ð
 ñAó ðAð& ñAó ðAð* ñó ðð, ñ(ó ð(ð
 ñAó ðAô"ð ñ5ó ð5ð< ñó ðð: ñó ðð  ñ!ó ð!ð, ñOó ðOð ñNó ðNòò83ój+ò:0ò
ò)ò"Jò**ò%ó&!MòF2òNò4"LòH òDò*ò*ó*4ó0ó Jó,)ó(Qò(Cò "ò(Jò #=òJ ó 2ó&)ò$=òLò4ò* ó*#$òJ(%òT ò*ò*ò*ò*ò0ò4ò*ò0ò>ò>ò>ò0ò4ò.%òNò8ó>%óN#óJ#óJ(òT@ó(5ò<:ò&;ò* <òD@ó2*ò0*ó*1ò&#9òJ *óD
1ó4ó(5ó .ó*.ò"*ò**ó*%&òN%òN&8òP$3ðL ÐóI'òVó,ó>&óBò> òD&ó2#%òJ'ó*I#óVI òV*ò:ò.ò.ó.ò:*ò*7ò*ò.(ò*%ò(*ò(ó4(ò:2ò.!òF%ò>ó*Nó:3óBNò<3ó6JRóX#.óJ=ó~Kó:0ó00ó6Oòbò6&òP?;òB=6ò~(ò 6Dóp#+òJ%>óN4ðl ñó ðð$ ñó ðð$ ñó ðð$ ñó ðð$ ñ"ó ð"ð$ ñó ðð( ñó ðð$ ñ"ó ð"ð$ ñ!ó ð!ð$ ñ$ó ð$ð. ñ$ó ð$ð$ ñ ó ð ð, ñ ó ð ð, ñ#ó ð#ò.òð ñó ðð ñó ðð ñó ðð ñó ðð ñó ðð ñó ðñ ��^Ó$ñ"ó %ð"ð ñó ðð ñó ðð ñó ðð ñó ðð ñó ðð ñó ðñ ��^Ó$ñ'ó %ð'ñ ��^Ó$ñ'ó %ð'ñ �˜Ó(ñó )ðñ" ��^Ó$ñó %ðòó,ó*ö`rg   rW   c                  ób   ‡ — e Zd ZdZd„ Zˆ fd„Zed„ «       Z ede	«      d„ «       Z
d„ Zd„ Zˆ xZS )	ÚPurePolyz)Class for representing pure polynomials. c                ó   — | j                   fS )z$Allow SymPy to hash Poly instances. )rj   rŠ   s    rd   r�   zPurePoly._hashable_contentÂ  s   € à—‘ˆ{Ðrg   c                ó    •— t         ‰| �  «       S rˆ   r±   r´   s    €rd   r³   zPurePoly.__hash__Æ  rµ   rg   c                ó   — | j                   S )aR  
        Free symbols of a polynomial.

        Examples
        ========

        >>> from sympy import PurePoly
        >>> from sympy.abc import x, y

        >>> PurePoly(x**2 + 1).free_symbols
        set()
        >>> PurePoly(x**2 + y).free_symbols
        set()
        >>> PurePoly(x**2 + y, x).free_symbols
        {y}

        )rº   rŠ   s    rd   r¹   zPurePoly.free_symbolsÉ  s   € ð& ×*Ñ*Ð*rg   r
  c                ó€  — | |}}|j                   s-	 |j                  ||j                  |j                  «       ¬«      }t        |j                  «      t        |j                  «      k7  ry|j                  j                  |j                  j                  k7  rg	 |j                  j                  j                  |j                  j                  |j                  «      }|j                  |«      }|j                  |«      }|j                  |j                  k(  S # t        t
        t        f$ r Y yw xY w# t        $ r Y yw xY wr  )ry   r§   rY   rÆ   r<   r8   r9   r„   rj   r¾   rÑ   r:   r«   )r‹   r
  r_   r`   r¾   s        rd   r  zPurePoly.__eq__Þ  sñ   € à�Uˆ1ˆà�yŠyðØ—K‘K  1§6¡6°!·,±,³.�KÓA�ô ˆq�v‰v‹;œ#˜aŸf™f›+Ò%Øà�5‰5�9‰9˜Ÿ™Ÿ	™	Ò!ðØ—e‘e—i‘i—o‘o a§e¡e§i¡i°·±Ó8�ð —‘˜SÓ!ˆAØ—‘˜SÓ!ˆAà�u‰u˜Ÿ™‰~Ðøô $¤[´.ÐAò Ùðûô %ò Ùðús$   ’,D ÂAD1 ÄD.Ä-D.Ä1	D=Ä<D=c                ó€   — t        || j                  «      xr' | j                  j                  |j                  d¬«      S r  )rV   r§   rj   r  rå  s     rd   r  zPurePoly._strict_eqö  s-   € Ü˜!˜QŸ[™[Ó)ÒJ¨a¯e©e¯h©h°q·u±uÀT¨hÓ.JÐJrg   c                ót  ‡— t        |«      }|j                  sk	 | j                  j                  | j                  | j                  | j                  j	                  | j                  j                  j                  |«      «      fS t        | j                  «      t        |j                  «      k7  rt        d| ›d|›�«      ‚t        | j                  t        «      rt        |j                  t        «      st        d| ›d|›�«      ‚| j                  Š| j                  }| j                  j                  j                  |j                  j                  |«      }| j                  j                  |«      }|j                  j                  |«      }||d fˆfd„	}||||fS # t        $ r t        d| ›d|›�«      ‚w xY w)NrÓ   rÔ   c                óp   •— |�!|d | ||dz   d  z   }|s|j                  | «      S  ‰j                  | g|¢­Ž S r¯   rÖ   rØ   s       €rd   rÎ   zPurePoly._unify.<locals>.per  rÚ   rg   )r%   ry   rj   r¾   rÎ   rÛ   r9   r:   r„   rY   rV   r4   r§   rÑ   r    )r_   r`   rY   r¾   rÏ   rÐ   rÎ   r}   s          @rd   rÌ   zPurePoly._unifyù  sB  ø€ Ü�A‹Jˆà�yŠyðLØ—u‘u—y‘y !§%¡%¨¯©°·±·	±	¸!¿%¹%¿)¹)×:NÑ:NÈqÓ:QÓ0RÐRÐRô ˆq�v‰v‹;œ#˜aŸf™f›+Ò%Ý#ÂÁAÐ$FÓGÐGä˜1Ÿ5™5¤#Ô&¬:°a·e±e¼SÔ+AÝ#ÂÁAÐ$FÓGÐGà�k‰kˆØ�v‰vˆà�e‰e�i‰i�o‰o˜aŸe™eŸi™i¨Ó.ˆà�E‰E�M‰M˜#ÓˆØ�E‰E�M‰M˜#Óˆà 4°õ 	'ð �C˜˜Aˆ~Ðøô5 "ò LÝ'ÂQÉÐ(JÓKÐKðLús   šA)F ÆF7)r^   r%  r&  r'  r�   r³   r-  r¹   r   r[   r  r  rÌ   r/  r0  s   @rd   r2  r2  ¾  sJ   ø„ á3òô"ð ñ+ó ð+ñ( �˜Ó(ñó )ðò.Kö rg   r2  c                óF   — t        j                  ||«      }t        | |«      S r›   )ro   rp   Ú_poly_from_expr)rŒ   rY   r~   r   s       rd   Úpoly_from_exprr<    s#   € ô ×
Ñ
  dÓ
+€CÜ˜4 Ó%Ð%rg   c                ó  — | t        | «      } }t        | t        «      st        ||| «      ‚| j                  rU| j
                  j                  | |«      }|j                  |_        |j                  |_        |j                  €d|_	        ||fS |j                  r| j                  «       } t        | |«      \  }}|j                  st        ||| «      ‚t        t        t        |j                  «       «      Ž «      \  }}|j                  }|€t        ||¬«      \  |_        }nt        t!        |j"                  |«      «      }t%        t        t        ||«      «      «      }t&        j)                  ||«      }|j                  €d|_	        ||fS )rœ   Trž   F)r%   rV   r   r?   ry   r§   rz   rY   rS   rO  ÚexpandrF   rw   rÞ   rŸ   r+   r¥   rÛ   rt   rW   ru   )rŒ   r   ÚorigrD  rj   r¸   rÁ   rS   s           rd   r;  r;  #  sE  € à”w˜t“}ˆ$€Dä�dœEÔ"Ü   d¨DÓ1Ð1Ø	�ŠØ�~‰~×(Ñ(¨¨sÓ3ˆà—9‘9ˆŒØ—[‘[ˆŒ
à�9‰9ÐØˆCŒIà�SˆyÐØ	�ŠØ�{‰{‹}ˆä˜t SÓ)�H€CˆØ�8Š8Ü   d¨DÓ1Ð1äœ#œt C§I¡I£KÓ0Ð1Ó2�N€FˆFØ�Z‰Z€Fà€~Ü-¨f¸#Ô>ÑˆŒ
‘Fä”c˜&×+Ñ+¨VÓ4Ó5ˆä
Œt”C˜ Ó'Ó(Ó
)€CÜ�?‰?˜3 Ó$€Dà
‡y�yÐØˆŒ	à�ˆ9Ðrg   c                óF   — t        j                  ||«      }t        | |«      S )ú(Construct polynomials from expressions. )ro   rp   Ú_parallel_poly_from_expr)ÚexprsrY   r~   r   s       rd   Úparallel_poly_from_exprrD  K  s#   € ô ×
Ñ
  dÓ
+€CÜ# E¨3Ó/Ð/rg   c           	     ój  — t        | «      dk(  r¬| \  }}t        |t        «      r—t        |t        «      r‡|j                  j	                  ||«      }|j                  j	                  ||«      }|j                  |«      \  }}|j                  |_        |j                  |_        |j                  €d|_        ||g|fS t        | «      g } }g g }}d}t        |«      D ]  \  }}	t        |	«      }	t        |	t        «      rL|	j                  r|j                  |«       n0|j                  |«       |j                  r|	j                  «       }	nd}| j                  |	«       Œ� |rt!        ||| d«      ‚|r|D ]  }| |   j#                  «       | |<   Œ t%        | |«      \  }
}|j                  st!        ||| d«      ‚ddlm} |j                  D ]  }t        ||«      sŒt+        d«      ‚ g g }}g }g }|
D ]i  }t        t-        t        |j/                  «       «      Ž «      \  }}|j1                  |«       |j                  |«       |j                  t        |«      «       Œk |j                  }|€t3        ||¬«      \  |_        }nt        t5        |j6                  |«      «      }|D ]  }|j                  |d| «       ||d }Œ g }t-        ||«      D ]J  \  }}t9        t        t-        ||«      «      «      }t        j;                  ||«      }|j                  |«       ŒL |j                  €t=        |«      |_        ||fS )	rA  rŒ  NTFr   ©Ú	Piecewisez&Piecewise generators do not make senserž   )r„   rV   rW   r§   rz   rÑ   rY   rS   rO  rw   rú   r%   r   ry   Úappendr>  r?   r]   rG   Ú$sympy.functions.elementary.piecewiserG  r<   rÞ   rŸ   Úextendr+   r¥   rÛ   rt   ru   Úbool)rC  r   r_   r`   ÚorigsÚ_exprsÚ_polysÚfailedr¼   rŒ   ÚrepsrG  rR  Úcoeffs_listÚlengthsr3  r1  rj   r¸   rÁ   rS   rO  rD  s                          rd   rB  rB  R  s  € ä
ˆ5ƒz�Q‚Ø‰ˆˆ1ä�aœÔ¤:¨a´Ô#6Ø—‘×&Ñ& q¨#Ó.ˆAØ—‘×&Ñ& q¨#Ó.ˆAà—7‘7˜1“:‰DˆAˆqà—v‘vˆCŒHØŸ™ˆCŒJà�y‰yÐ Ø �”	à�q�6˜3�;Ðä˜“; ˆ5€EØ˜ˆF€Fà€Fä˜UÓ#ò ‰ˆˆ4Ü�t‹}ˆä�dœEÔ"Ø�|Š|Ø—‘˜aÕ à—‘˜aÔ à—:’:ØŸ;™;›=‘DàˆFà�‰�TÕðñ  Ü   e¨U°DÓ9Ð9áàò 	*ˆAØ˜Q‘x×'Ñ'Ó)ˆE�!ŠHð	*ô )¨°Ó4�I€Dˆ#Ø�8Š8Ü   e¨U°DÓ9Ð9å>Ø�X‰Xò LˆÜ�a˜Õ#Ü!Ð"JÓKÐKðLð ˜r�€Kà€JØ€Jàò $ˆÜœc¤4¨¯	©	«Ó#4Ð5Ó6‰ˆ�à×Ñ˜6Ô"Ø×Ñ˜&Ô!à�‰”s˜6“{Õ#ð$ð �Z‰Z€Fà€~Ü"2°;ÀCÔ"HÑˆŒ
‘Käœ3˜v×0Ñ0°+Ó>Ó?ˆàò &ˆØ×Ñ˜+ b q˜/Ô*Ø! ! "�o‰ð&ð €Eä˜j¨*Ó5ò ‰ˆ�Ü”4œ˜F FÓ+Ó,Ó-ˆÜ�‰˜s CÓ(ˆØ�‰�TÕðð
 ‡y�yÐÜ˜“LˆŒ	à�#ˆ:Ðrg   c                ó.   — t        | «      } || vr|| |<   | S )z7Add a new ``(key, value)`` pair to arguments ``dict``. )rt   )r~   rk  rB  s      rd   Ú_update_argsrT  °  s    € ä�‹:€Dà
�$�ØˆˆS‰	à€Krg   c                ó   — t        | d¬«      } t        |d¬«      j                  }| j                  r| }|j                  «       j                  }n.| j                  }|s |rt	        | «      \  }}nt	        | |«      \  }}|r"| rt
        j                  S t
        j                  S |sT| j                  r*|j                  vrt	        | j                  «       «      \  }}|j                  vrnt
        j                  S | j                  sRt        | j                  «      dkD  r:t        t        d| ›dt        t        | j                  «      «      ›d|›d�«      «      ‚j                  |«      }t!        |t"        «      rt%        |«      S t
        j                  S )a”  
    Return the degree of ``f`` in the given variable.

    The degree of 0 is negative infinity.

    Examples
    ========

    >>> from sympy import degree
    >>> from sympy.abc import x, y

    >>> degree(x**2 + y*x + 1, gen=x)
    2
    >>> degree(x**2 + y*x + 1, gen=y)
    1
    >>> degree(0, x)
    -oo

    See also
    ========

    sympy.polys.polytools.Poly.total_degree
    degree_list
    Tr  r‚   zj
         A symbolic generator of interest is required for a multivariate
         expression like func = z, e.g. degree(func, gen = z)) instead of
         degree(func, gen = z).
        )r%   Ú	is_Numberry   r]   r<  r   ÚZeror�  rY   r„   r¹   r™  rL   Únextr"   r�  rV   r(  r   )r_   rÂ   Ú
gen_is_Numrø  ÚisNumrÍ   rb   s          rd   r�  r�  º  s8  € ô6 	�˜$Ô€AÜ˜ TÔ*×4Ñ4€JØ‡y‚yØˆØ—	‘	“×%Ñ%‰à—‘ˆÙÙÜ% aÓ(‘�‘1ä% a¨Ó-‘��1áÙŒq�v‰vÐ2¤× 2Ñ 2Ð2áØ�9Š9˜ A§F¡FÑ*ä! !§)¡)£+Ó.‰DˆAˆqØ�a—f‘fÑÜ—6‘6ˆMØ�YŠYœ3˜qŸ~™~Ó.°Ò2Ü�
ò ”$”w˜qŸ~™~Ó.Õ/²ð	$6ó 7ó 8ð 	8ð
 �X‰X�c‹]€FÜ(¨´Ô5Œ7�6‹?ÐM¼1×;MÑ;MÐMrg   c                ó  — t        | «      }|j                  r|j                  «       }|j                  rd}t        |«      S | j                  r|xs | j                  }t        ||«      j                  «       }t        |«      S )aÂ  
    Return the total_degree of ``f`` in the given variables.

    Examples
    ========
    >>> from sympy import total_degree, Poly
    >>> from sympy.abc import x, y

    >>> total_degree(1)
    0
    >>> total_degree(x + x*y)
    2
    >>> total_degree(x + x*y, x)
    1

    If the expression is a Poly and no variables are given
    then the generators of the Poly will be used:

    >>> p = Poly(x + x*y, y)
    >>> total_degree(p)
    1

    To deal with the underlying expression of the Poly, convert
    it to an Expr:

    >>> total_degree(p.as_expr())
    2

    This is done automatically if any variables are given:

    >>> total_degree(p, x)
    1

    See also
    ========
    degree
    r   )r%   ry   r]   rV  rY   rW   r•  r   )r_   rY   rø  Úrvs       rd   r•  r•  õ  sl   € ôP 	�‹
€AØ‡y‚yØ�I‰I‹KˆØ‡{‚{Øˆô �2‹;Ðð	 �9Š9Ø’>˜1Ÿ6™6ˆDÜ�!�T‹]×'Ñ'Ó)ˆä�2‹;Ðrg   c                óä   — t        j                  |dg«       	 t        | g|¢­i |¤Ž\  }}|j                  «       }t        t        t        |«      «      S # t        $ r}t	        dd|«      ‚d}~ww xY w)zÓ
    Return a list of degrees of ``f`` in all variables.

    Examples
    ========

    >>> from sympy import degree_list
    >>> from sympy.abc import x, y

    >>> degree_list(x**2 + y*x + 1)
    (2, 1)

    rO  r“  r‚   N)	ro   Úallowed_flagsr<  r?   r@   r“  r7  r¥   r   )r_   rY   r~   rÏ   r   r|  Údegreess          rd   r“  r“  *  ss   € ô ×Ñ˜$  	Ô*ð7Ü Ð1 DÒ1¨DÑ1‰ˆˆ3ð �m‰m‹o€Gä””W˜gÓ&Ó'Ð'øô ò 7Ü ¨q°#Ó6Ð6ûð7ús   ™A Á	A/ÁA*Á*A/c                óÊ   — t        j                  |dg«       	 t        | g|¢­i |¤Ž\  }}|j                  |j                  ¬«      S # t        $ r}t	        dd|«      ‚d}~ww xY w)zÀ
    Return the leading coefficient of ``f``.

    Examples
    ========

    >>> from sympy import LC
    >>> from sympy.abc import x, y

    >>> LC(4*x**2 + 2*x*y**2 + x*y + 3*y)
    4

    rO  r�  r‚   Nr,  )ro   r^  r<  r?   r@   r�  rl   ©r_   rY   r~   rÏ   r   r|  s         rd   r�  r�  E  sk   € ô ×Ñ˜$  	Ô*ð.Ü Ð1 DÒ1¨DÑ1‰ˆˆ3ð �4‰4�c—i‘iˆ4Ó Ð øô ò .Ü  a¨Ó-Ð-ûð.ús   ™A Á	A"ÁAÁA"c                óê   — t        j                  |dg«       	 t        | g|¢­i |¤Ž\  }}|j                  |j                  ¬«      }|j                  «       S # t        $ r}t	        dd|«      ‚d}~ww xY w)zÀ
    Return the leading monomial of ``f``.

    Examples
    ========

    >>> from sympy import LM
    >>> from sympy.abc import x, y

    >>> LM(4*x**2 + 2*x*y**2 + x*y + 3*y)
    x**2

    rO  r®  r‚   Nr,  )ro   r^  r<  r?   r@   r®  rl   r]   )r_   rY   r~   rÏ   r   r|  r¢   s          rd   r®  r®  ^  sv   € ô ×Ñ˜$  	Ô*ð.Ü Ð1 DÒ1¨DÑ1‰ˆˆ3ð �D‰D�s—y‘yˆDÓ!€EØ�=‰=‹?Ðøô	 ò .Ü  a¨Ó-Ð-ûð.ús   ™A Á	A2Á A-Á-A2c                óö   — t        j                  |dg«       	 t        | g|¢­i |¤Ž\  }}|j                  |j                  ¬«      \  }}||j                  «       z  S # t        $ r}t	        dd|«      ‚d}~ww xY w)z¾
    Return the leading term of ``f``.

    Examples
    ========

    >>> from sympy import LT
    >>> from sympy.abc import x, y

    >>> LT(4*x**2 + 2*x*y**2 + x*y + 3*y)
    4*x**2

    rO  r´  r‚   Nr,  )ro   r^  r<  r?   r@   r´  rl   r]   )r_   rY   r~   rÏ   r   r|  r¢   r£   s           rd   r´  r´  x  s   € ô ×Ñ˜$  	Ô*ð.Ü Ð1 DÒ1¨DÑ1‰ˆˆ3ð —4‘4˜cŸi™i�4Ó(�L€Eˆ5Ø�—‘“Ñ Ð øô	 ò .Ü  a¨Ó-Ð-ûð.ús   ™A Á	A8Á&A3Á3A8c                ó$  — t        j                  |dg«       	 t        | |fg|¢­i |¤Ž\  \  }}}|j                  |«      \  }}	|j                  s |j                  «       |	j                  «       fS ||	fS # t        $ r}t	        dd|«      ‚d}~ww xY w)zÏ
    Compute polynomial pseudo-division of ``f`` and ``g``.

    Examples
    ========

    >>> from sympy import pdiv
    >>> from sympy.abc import x

    >>> pdiv(x**2 + 1, 2*x - 4)
    (2*x + 4, 20)

    rO  rs  rŒ  N)ro   r^  rD  r?   r@   rs  rO  r]   ©
r_   r`   rY   r~   rÏ   rÐ   r   r|  rt  ru  s
             rd   rs  rs  ’  s–   € ô ×Ñ˜$  	Ô*ð0Ü-¨q°!¨fÐD°tÒD¸tÑD‰‰ˆˆA�ð �6‰6�!‹9�D€A€qà�9Š9Ø�y‰y‹{˜AŸI™I›KÐ'Ð'à�!ˆtˆøô ò 0Ü ¨¨3Ó/Ð/ûð0ús   ™A4 Á4	BÁ=B
Â
Bc                óú   — t        j                  |dg«       	 t        | |fg|¢­i |¤Ž\  \  }}}|j                  |«      }|j                  s|j                  «       S |S # t        $ r}t	        dd|«      ‚d}~ww xY w)zÅ
    Compute polynomial pseudo-remainder of ``f`` and ``g``.

    Examples
    ========

    >>> from sympy import prem
    >>> from sympy.abc import x

    >>> prem(x**2 + 1, 2*x - 4)
    20

    rO  rw  rŒ  N)ro   r^  rD  r?   r@   rw  rO  r]   ©	r_   r`   rY   r~   rÏ   rÐ   r   r|  ru  s	            rd   rw  rw  °  sƒ   € ô ×Ñ˜$  	Ô*ð0Ü-¨q°!¨fÐD°tÒD¸tÑD‰‰ˆˆA�ð 	
�‰ˆq‹	€Aà�9Š9Ø�y‰y‹{Ðàˆøô ò 0Ü ¨¨3Ó/Ð/ûð0úó   ™A Á	A:Á(A5Á5A:c                ó.  — t        j                  |dg«       	 t        | |fg|¢­i |¤Ž\  \  }}}	 |j                  |«      }|j                  s|j                  «       S |S # t        $ r}t	        dd|«      ‚d}~ww xY w# t        $ r t        | |«      ‚w xY w)zõ
    Compute polynomial pseudo-quotient of ``f`` and ``g``.

    Examples
    ========

    >>> from sympy import pquo
    >>> from sympy.abc import x

    >>> pquo(x**2 + 1, 2*x - 4)
    2*x + 4
    >>> pquo(x**2 - 1, 2*x - 1)
    2*x + 1

    rO  ry  rŒ  N)	ro   r^  rD  r?   r@   ry  r>   rO  r]   ©	r_   r`   rY   r~   rÏ   rÐ   r   r|  rt  s	            rd   ry  ry  Î  s¥   € ô" ×Ñ˜$  	Ô*ð0Ü-¨q°!¨fÐD°tÒD¸tÑD‰‰ˆˆA�ð(Ø�F‰F�1‹Iˆð �9Š9Ø�y‰y‹{Ðàˆøô ò 0Ü ¨¨3Ó/Ð/ûð0ûô
 ò (Ü! ! QÓ'Ð'ð(ús"   ™A  ±A> Á 	A;Á)A6Á6A;Á>Bc                óú   — t        j                  |dg«       	 t        | |fg|¢­i |¤Ž\  \  }}}|j                  |«      }|j                  s|j                  «       S |S # t        $ r}t	        dd|«      ‚d}~ww xY w)a_  
    Compute polynomial exact pseudo-quotient of ``f`` and ``g``.

    Examples
    ========

    >>> from sympy import pexquo
    >>> from sympy.abc import x

    >>> pexquo(x**2 - 1, 2*x - 2)
    2*x + 2

    >>> pexquo(x**2 + 1, 2*x - 4)
    Traceback (most recent call last):
    ...
    ExactQuotientFailed: 2*x - 4 does not divide x**2 + 1

    rO  r{  rŒ  N)ro   r^  rD  r?   r@   r{  rO  r]   rj  s	            rd   r{  r{  ñ  sƒ   € ô( ×Ñ˜$  	Ô*ð2Ü-¨q°!¨fÐD°tÒD¸tÑD‰‰ˆˆA�ð 	
�‰�‹€Aà�9Š9Ø�y‰y‹{Ðàˆøô ò 2Ü ¨!¨SÓ1Ð1ûð2úrh  c                ó>  — t        j                  |ddg«       	 t        | |fg|¢­i |¤Ž\  \  }}}|j                  ||j                  ¬«      \  }}	|j                  s |j                  «       |	j                  «       fS ||	fS # t        $ r}t	        dd|«      ‚d}~ww xY w)a  
    Compute polynomial division of ``f`` and ``g``.

    Examples
    ========

    >>> from sympy import div, ZZ, QQ
    >>> from sympy.abc import x

    >>> div(x**2 + 1, 2*x - 4, domain=ZZ)
    (0, x**2 + 1)
    >>> div(x**2 + 1, 2*x - 4, domain=QQ)
    (x/2 + 1, 5)

    r�  rO  r~  rŒ  N©r�  )	ro   r^  rD  r?   r@   r~  r�  rO  r]   re  s
             rd   r~  r~    s¢   € ô" ×Ñ˜$ ¨Ð 1Ô2ð/Ü-¨q°!¨fÐD°tÒD¸tÑD‰‰ˆˆA�ð �5‰5�˜Ÿ™ˆ5Ó"�D€A€qà�9Š9Ø�y‰y‹{˜AŸI™I›KÐ'Ð'à�!ˆtˆøô ò /Ü  q¨#Ó.Ð.ûð/ús   šB Â	BÂ
BÂBc                ó  — t        j                  |ddg«       	 t        | |fg|¢­i |¤Ž\  \  }}}|j                  ||j                  ¬«      }|j                  s|j                  «       S |S # t        $ r}t	        dd|«      ‚d}~ww xY w)a  
    Compute polynomial remainder of ``f`` and ``g``.

    Examples
    ========

    >>> from sympy import rem, ZZ, QQ
    >>> from sympy.abc import x

    >>> rem(x**2 + 1, 2*x - 4, domain=ZZ)
    x**2 + 1
    >>> rem(x**2 + 1, 2*x - 4, domain=QQ)
    5

    r�  rO  r…  rŒ  Nrm  )	ro   r^  rD  r?   r@   r…  r�  rO  r]   rg  s	            rd   r…  r…  4  ó�   € ô" ×Ñ˜$ ¨Ð 1Ô2ð/Ü-¨q°!¨fÐD°tÒD¸tÑD‰‰ˆˆA�ð 	
�‰ˆa�c—h‘hˆÓ€Aà�9Š9Ø�y‰y‹{Ðàˆøô ò /Ü  q¨#Ó.Ð.ûð/úó   šA, Á,	BÁ5BÂBc                ó  — t        j                  |ddg«       	 t        | |fg|¢­i |¤Ž\  \  }}}|j                  ||j                  ¬«      }|j                  s|j                  «       S |S # t        $ r}t	        dd|«      ‚d}~ww xY w)zç
    Compute polynomial quotient of ``f`` and ``g``.

    Examples
    ========

    >>> from sympy import quo
    >>> from sympy.abc import x

    >>> quo(x**2 + 1, 2*x - 4)
    x/2 + 1
    >>> quo(x**2 - 1, x - 1)
    x + 1

    r�  rO  r‰  rŒ  Nrm  )	ro   r^  rD  r?   r@   r‰  r�  rO  r]   rj  s	            rd   r‰  r‰  T  ro  rp  c                ó  — t        j                  |ddg«       	 t        | |fg|¢­i |¤Ž\  \  }}}|j                  ||j                  ¬«      }|j                  s|j                  «       S |S # t        $ r}t	        dd|«      ‚d}~ww xY w)aQ  
    Compute polynomial exact quotient of ``f`` and ``g``.

    Examples
    ========

    >>> from sympy import exquo
    >>> from sympy.abc import x

    >>> exquo(x**2 - 1, x - 1)
    x + 1

    >>> exquo(x**2 + 1, 2*x - 4)
    Traceback (most recent call last):
    ...
    ExactQuotientFailed: 2*x - 4 does not divide x**2 + 1

    r�  rO  r‹  rŒ  Nrm  )	ro   r^  rD  r?   r@   r‹  r�  rO  r]   rj  s	            rd   r‹  r‹  t  s�   € ô( ×Ñ˜$ ¨Ð 1Ô2ð1Ü-¨q°!¨fÐD°tÒD¸tÑD‰‰ˆˆA�ð 	
�‰�˜Ÿ™ˆÓ!€Aà�9Š9Ø�y‰y‹{Ðàˆøô ò 1Ü ¨¨CÓ0Ð0ûð1úrp  c                ó  — t        j                  |ddg«       	 t        | |fg|¢­i |¤Ž\  \  }}}|j                  ||j                  ¬«      \  }}|j                  s |j                  «       |j                  «       fS ||fS # t        $ rw}t	        |j
                  «      \  }\  }	}
	 |j                  |	|
«      \  }}|j                  |«      |j                  |«      fcY d}~S # t        $ r t        dd|«      ‚w xY wd}~ww xY w)aT  
    Half extended Euclidean algorithm of ``f`` and ``g``.

    Returns ``(s, h)`` such that ``h = gcd(f, g)`` and ``s*f = h (mod g)``.

    Examples
    ========

    >>> from sympy import half_gcdex
    >>> from sympy.abc import x

    >>> half_gcdex(x**4 - 2*x**3 - 6*x**2 + 12*x + 15, x**3 + x**2 - 4*x - 4)
    (3/5 - x/5, x + 1)

    r�  rO  Nr×  rŒ  rm  )ro   r^  rD  r?   r+   rC  r×  r×   rq   r@   r�  rO  r]   )r_   r`   rY   r~   rÏ   rÐ   r   r|  rS   rÃ  rÄ  rš  rØ  s                rd   r×  r×  —  s  € ô" ×Ñ˜$ ¨Ð 1Ô2ð
:Ü-¨q°!¨fÐD°tÒD¸tÑD‰‰ˆˆA�ð �<‰<˜ §¡ˆ<Ó)�D€A€qà�9Š9Ø�y‰y‹{˜AŸI™I›KÐ'Ð'à�!ˆtˆøô ò :Ü)¨#¯)©)Ó4‰ˆ‘��Að	:Ø×$Ñ$ Q¨Ó*‰DˆAˆqð —?‘? 1Ó% v§¡°qÓ'9Ð9Õ9øô #ò 	:Ü# L°!°SÓ9Ð9ð	:þð:ús5   šB Â	DÂ
C<Â&C"Â;!C<ÃDÃ"C9Ã9C<Ã<Dc                óL  — t        j                  |ddg«       	 t        | |fg|¢­i |¤Ž\  \  }}}|j                  ||j                  ¬«      \  }}}|j                  s/|j                  «       |j                  «       |j                  «       fS |||fS # t        $ rˆ}t	        |j
                  «      \  }\  }	}
	 |j                  |	|
«      \  }}}|j                  |«      |j                  |«      |j                  |«      fcY d}~S # t        $ r t        dd|«      ‚w xY wd}~ww xY w)aZ  
    Extended Euclidean algorithm of ``f`` and ``g``.

    Returns ``(s, t, h)`` such that ``h = gcd(f, g)`` and ``s*f + t*g = h``.

    Examples
    ========

    >>> from sympy import gcdex
    >>> from sympy.abc import x

    >>> gcdex(x**4 - 2*x**3 - 6*x**2 + 12*x + 15, x**3 + x**2 - 4*x - 4)
    (3/5 - x/5, x**2/5 - 6*x/5 + 2, x + 1)

    r�  rO  NrÚ  rŒ  rm  )ro   r^  rD  r?   r+   rC  rÚ  r×   rq   r@   r�  rO  r]   )r_   r`   rY   r~   rÏ   rÐ   r   r|  rS   rÃ  rÄ  rš  rÛ  rØ  s                 rd   rÚ  rÚ  ¾  s  € ô" ×Ñ˜$ ¨Ð 1Ô2ð
NÜ-¨q°!¨fÐD°tÒD¸tÑD‰‰ˆˆA�ð �g‰g�a˜cŸh™hˆgÓ'�G€A€qˆ!à�9Š9Ø�y‰y‹{˜AŸI™I›K¨¯©«Ð4Ð4à�!�Qˆwˆøô ò NÜ)¨#¯)©)Ó4‰ˆ‘��Að	NØ—l‘l 1 aÓ(‰GˆAˆq�!ð —?‘? 1Ó% v§¡°qÓ'9¸6¿?¹?È1Ó;MÐMÕMøô #ò 	5Ü# G¨Q°Ó4Ð4ð	5þðNús5   šB Â	D#ÂDÂ7DÃ1DÃ>D#ÄDÄDÄD#c                ó²  — t        j                  |ddg«       	 t        | |fg|¢­i |¤Ž\  \  }}}|j                  ||j                  ¬«      }|j                  s|j                  «       S |S # t        $ ra}t	        |j
                  «      \  }\  }	}
	 |j                  |j                  |	|
«      «      cY d}~S # t        $ r t        dd|«      ‚w xY wd}~ww xY w)a/  
    Invert ``f`` modulo ``g`` when possible.

    Examples
    ========

    >>> from sympy import invert, S, mod_inverse
    >>> from sympy.abc import x

    >>> invert(x**2 - 1, 2*x - 1)
    -4/3

    >>> invert(x**2 - 1, x - 1)
    Traceback (most recent call last):
    ...
    NotInvertible: zero divisor

    For more efficient inversion of Rationals,
    use the :obj:`sympy.core.intfunc.mod_inverse` function:

    >>> mod_inverse(3, 5)
    2
    >>> (S(2)/5).invert(S(7)/3)
    5/2

    See Also
    ========
    sympy.core.intfunc.mod_inverse

    r�  rO  NrÝ  rŒ  rm  )ro   r^  rD  r?   r+   rC  r×   rÝ  rq   r@   r�  rO  r]   )r_   r`   rY   r~   rÏ   rÐ   r   r|  rS   rÃ  rÄ  rØ  s               rd   rÝ  rÝ  å  sÓ   € ô@ ×Ñ˜$ ¨Ð 1Ô2ð6Ü-¨q°!¨fÐD°tÒD¸tÑD‰‰ˆˆA�ð 	
�‰�˜Ÿ™ˆÓ"€Aà�9Š9Ø�y‰y‹{Ðàˆøô ò 6Ü)¨#¯)©)Ó4‰ˆ‘��Að	6Ø—?‘? 6§=¡=°°AÓ#6Ó7Õ7øÜ"ò 	6Ü# H¨a°Ó5Ð5ð	6þð6ús/   šA, Á,	CÁ5CÂ B7Â1CÂ7CÃCÃCc                ó   — t        j                  |dg«       	 t        | |fg|¢­i |¤Ž\  \  }}}|j                  |«      }|j                  s|D �	cg c]  }	|	j                  «       ‘Œ c}	S |S # t        $ r}t	        dd|«      ‚d}~ww xY wc c}	w )zã
    Compute subresultant PRS of ``f`` and ``g``.

    Examples
    ========

    >>> from sympy import subresultants
    >>> from sympy.abc import x

    >>> subresultants(x**2 + 1, x**2 - 1)
    [x**2 + 1, x**2 - 1, -2]

    rO  rá  rŒ  N)ro   r^  rD  r?   r@   rá  rO  r]   )
r_   r`   rY   r~   rÏ   rÐ   r   r|  rb   ru  s
             rd   rá  rá    s“   € ô ×Ñ˜$  	Ô*ð9Ü-¨q°!¨fÐD°tÒD¸tÑD‰‰ˆˆA�ð �_‰_˜QÓ€Fà�9Š9Ø%+Ö, �—	‘	•Ò,Ð,àˆøô ò 9Ü °°CÓ8Ð8ûð9üò -s   ™A- ÁBÁ-	BÁ6BÂBFrä  c               ó¢  — t        j                  |dg«       	 t        | |fg|¢­i |¤Ž\  \  }}}|r|j                  ||¬«      \  }	}
n|j                  |«      }	|j                  s@|r.|	j                  «       
D �cg c]  }|j                  «       ‘Œ c}fS |	j                  «       S |r|	
fS |	S # t        $ r}t	        dd|«      ‚d}~ww xY wc c}w )z½
    Compute resultant of ``f`` and ``g``.

    Examples
    ========

    >>> from sympy import resultant
    >>> from sympy.abc import x

    >>> resultant(x**2 + 1, x**2 - 1)
    4

    rO  rã  rŒ  Nrä  )ro   r^  rD  r?   r@   rã  rO  r]   )r_   r`   rå  rY   r~   rÏ   rÐ   r   r|  rb   rƒ  ru  s               rd   rã  rã  7  sÔ   € ô ×Ñ˜$  	Ô*ð5Ü-¨q°!¨fÐD°tÒD¸tÑD‰‰ˆˆA�ñ Ø—K‘K ¨j�KÓ9‰	ˆ‘à—‘˜Q“ˆà�9Š9ÙØ—>‘>Ó#¸1Ö%=°a a§i¡i¥kÒ%=Ð=Ð=Ø�~‰~ÓÐáØ˜1�9ÐØˆøô ò 5Ü ¨Q°Ó4Ð4ûð5üò &>s   ™B. Á;CÂ.	C	Â7CÃC	c                óî   — t        j                  |dg«       	 t        | g|¢­i |¤Ž\  }}|j                  «       }|j                  s|j                  «       S |S # t        $ r}t	        dd|«      ‚d}~ww xY w)z¹
    Compute discriminant of ``f``.

    Examples
    ========

    >>> from sympy import discriminant
    >>> from sympy.abc import x

    >>> discriminant(x**2 + 2*x + 3)
    -8

    rO  rç  r‚   N)ro   r^  r<  r?   r@   rç  rO  r]   ©r_   rY   r~   rÏ   r   r|  rb   s          rd   rç  rç  \  s{   € ô ×Ñ˜$  	Ô*ð8Ü Ð1 DÒ1¨DÑ1‰ˆˆ3ð �^‰^Ó€Fà�9Š9Ø�~‰~ÓÐàˆøô ò 8Ü °°3Ó7Ð7ûð8úó   ™A Á	A4Á"A/Á/A4c                ó2  — t        j                  |dg«       	 t        | |fg|¢­i |¤Ž\  \  }}}|j                  |«      \  }}}|j                  s/|j                  «       |j                  «       |j                  «       fS |||fS # t        $ rˆ}t	        |j
                  «      \  }\  }	}
	 |j                  |	|
«      \  }}}|j                  |«      |j                  |«      |j                  |«      fcY d}~S # t        $ r t        dd|«      ‚w xY wd}~ww xY w)a�  
    Compute GCD and cofactors of ``f`` and ``g``.

    Returns polynomials ``(h, cff, cfg)`` such that ``h = gcd(f, g)``, and
    ``cff = quo(f, h)`` and ``cfg = quo(g, h)`` are, so called, cofactors
    of ``f`` and ``g``.

    Examples
    ========

    >>> from sympy import cofactors
    >>> from sympy.abc import x

    >>> cofactors(x**2 - 1, x**2 - 3*x + 2)
    (x - 1, x + 1, x - 2)

    rO  Nrî  rŒ  )ro   r^  rD  r?   r+   rC  rî  r×   rq   r@   rO  r]   )r_   r`   rY   r~   rÏ   rÐ   r   r|  rS   rÃ  rÄ  rØ  rï  rð  s                 rd   rî  rî  z  s  € ô& ×Ñ˜$  	Ô*ð
RÜ-¨q°!¨fÐD°tÒD¸tÑD‰‰ˆˆA�ð —+‘+˜a“.�K€A€sˆCà�9Š9Ø�y‰y‹{˜CŸK™K›M¨3¯;©;«=Ð8Ð8à�#�sˆ{Ðøô ò RÜ)¨#¯)©)Ó4‰ˆ‘��Að	RØ ×*Ñ*¨1¨aÓ0‰KˆAˆs�Cð —?‘? 1Ó% v§¡°sÓ';¸V¿_¹_ÈSÓ=QÐQÕQøô #ò 	9Ü# K°°CÓ8Ð8ð	9þðRús5   ™B Â	DÂDÂ*C7Ã 1DÃ1DÃ7DÄDÄDc                ó0  ‡‡— t        | «      } ˆˆfd„} || «      }|�|S t        j                  ‰dg«       	 t        | g‰¢­i ‰¤Ž\  }}t	        | «      dkD  r€t        d„ | D «       «      rn| d   }| dd D �cg c]  }||z  j                  «       ‘Œ }	}t        d„ |	D «       «      r4d}
|	D ]  }t        |
|j                  «       d   «      }
Œ! t        ||
z  «      S |s)|j                  st        j                  S t!        d|¬
«      S |d   |dd }}|D ]!  }|j#                  |«      }|j$                  sŒ! n |j                  s|j'                  «       S |S c c}w # t        $ r6} ||j                  «      }|�|cY d}~S t        d	t	        | «      |«      ‚d}~ww xY w)zÑ
    Compute GCD of a list of polynomials.

    Examples
    ========

    >>> from sympy import gcd_list
    >>> from sympy.abc import x

    >>> gcd_list([x**3 - 1, x**2 - 1, x**2 - 3*x + 2])
    x - 1

    c                óì   •— ‰sq‰sot        | «      \  }}|s|j                  S |j                  rG|d   |dd  }}|D ]'  }|j                  ||«      }|j	                  |«      sŒ' n |j                  |«      S y ©Nr   r‚   )r+   rÈ   rO  rò  rÇ  r×   ©ÚseqrS   Únumbersrb   Únumberr~   rY   s        €€rd   Útry_non_polynomial_gcdz(gcd_list.<locals>.try_non_polynomial_gcd´  s�   ø€ Ù™DÜ.¨sÓ3‰OˆF�GáØ—{‘{Ð"Ø×$Ò$Ø")¨!¡*¨g°a°b¨k˜�à%ò �FØ#ŸZ™Z¨°Ó7�Fà—}‘} VÕ,Ùð	ð —‘ vÓ.Ð.àrg   NrO  r‚   c              3  óP   K  — | ]  }|j                   xr |j                  –— Œ  y ­wrˆ   ©Úis_algebraicÚis_irrational©Ú.0r  s     rd   ú	<genexpr>zgcd_list.<locals>.<genexpr>Ò  ó$   è ø€ ÒVÈ3 × 0Ñ 0Ò F°S×5FÑ5FÓ FÑVùó   ‚$&r¡  c              3  ó4   K  — | ]  }|j                   –— Œ y ­wrˆ   ©Úis_rational©r‰  Úfrcs     rd   rŠ  zgcd_list.<locals>.<genexpr>Õ  ó   è ø€ Ò2 s�3—?•?Ñ2ùó   ‚r   Úgcd_listrž   )r%   ro   r^  rD  r„   r  Úratsimprõ  Úas_numer_denomrc  r?   rC  r@   rO  r   rW  rW   rò  rÇ  r]   )r€  rY   r~   rƒ  rb   rO  r   rÃ  r  ÚlstÚlcr‘  r|  rD  s    ``           rd   r”  r”  £  s¨  ù€ ô �#‹,€Cõñ& $ CÓ(€FàÐØˆä×Ñ˜$  	Ô*ð?Ü,¨SÐ@°4Ò@¸4Ñ@‰
ˆˆsô ˆs‹8�aŠ<œCÑVÐRUÔVÔVØ�B‘ˆAØ14°S°b°Ö;¨#�Q�s‘U—O‘OÕ%Ð;ˆCÐ;ÜÑ2¨cÔ2Ô2Ø�Øò :�CÜ˜R ×!3Ñ!3Ó!5°aÑ!8Ó9‘Bð:ô ˜1˜R™4“yÐ ñ Ø�yŠyÜ—6‘6ˆMä˜˜sÔ#Ð#à˜!‘H˜e A B˜iˆE€Fàò ˆØ—‘˜DÓ!ˆà�=‹=Ùð	ð �9Š9Ø�~‰~ÓÐàˆùòC <øô ò ?Ù'¨¯	©	Ó2ˆàÐØ�Mä# J´°C³¸#Ó>Ð>ûð?ús6   ¸>E Á6EÂAE ÅE Å	FÅFÅ4FÅ:FÆFc                óþ  — t        | d«      r|�|f|z   }t        | g|¢­i |¤ŽS |€t        d«      ‚t        j                  |dg«       	 t        | |fg|¢­i |¤Ž\  \  }}}t        t        | |f«      \  }}|j                  rb|j                  rV|j                  rJ|j                  r>||z  j                  «       }	|	j                  rt        ||	j                  «       d   z  «      S |j%                  |«      }|j*                  s|j-                  «       S |S # t        $ ra}
t        |
j                   «      \  }\  }}	 |j#                  |j%                  ||«      «      cY d}
~
S # t&        $ r t)        dd|
«      ‚w xY wd}
~
ww xY w)zµ
    Compute GCD of ``f`` and ``g``.

    Examples
    ========

    >>> from sympy import gcd
    >>> from sympy.abc import x

    >>> gcd(x**2 - 1, x**2 - 3*x + 2)
    x - 1

    Ú__iter__Nz2gcd() takes 2 arguments or a sequence of argumentsrO  r   rò  rŒ  )r  r”  r™  ro   r^  rD  r¥   r%   r†  r‡  r•  r�  rc  r–  r?   r+   rC  r×   rò  rq   r@   rO  r]   ©r_   r`   rY   r~   rÏ   rÐ   r   rÃ  rÄ  r‘  r|  rS   rb   s                rd   rò  rò  ø  sj  € ô ˆq�*ÔØˆ=Ø�4˜$‘;ˆDä˜Ð)˜DÒ) DÑ)Ð)Ø	
ˆÜÐLÓMÐMä×Ñ˜$  	Ô*ð3Ü-¨q°!¨fÐD°tÒD¸tÑD‰‰ˆˆA�ô ”7˜Q ˜FÓ#‰ˆˆ1Ø�>Š>˜aŸošo°!·.².ÀQÇ_Â_Ø�Q‘3—-‘-“/ˆCØ�Šä˜1˜S×/Ñ/Ó1°!Ñ4Ñ4Ó5Ð5ð �U‰U�1‹X€Fà�9Š9Ø�~‰~ÓÐàˆøô ò 3Ü)¨#¯)©)Ó4‰ˆ‘��Að	3Ø—?‘? 6§:¡:¨a°Ó#3Ó4Õ4øÜ"ò 	3Ü# E¨1¨cÓ2Ð2ð	3þð3ús1   Á	BD Ä	E<ÄE7Ä7 EÅE<ÅE4Å4E7Å7E<c                ó  ‡‡— t        | «      } dˆˆfd„} || «      }|�|S t        j                  ‰dg«       	 t        | g‰¢­i ‰¤Ž\  }}t	        | «      dkD  rwt        d„ | D «       «      re| d   }| dd D �cg c]  }||z  j                  «       ‘Œ }	}t        d„ |	D «       «      r+d}
|	D ]  }t        |
|j                  «       d   «      }
Œ! ||
z  S |s)|j                  st        j                  S t        d|¬	«      S |d
   |dd }}|D ]  }|j                  |«      }Œ |j                  s|j!                  «       S |S c c}w # t        $ r6} ||j                  «      }|�|cY d}~S t        dt	        | «      |«      ‚d}~ww xY w)zï
    Compute LCM of a list of polynomials.

    Examples
    ========

    >>> from sympy import lcm_list
    >>> from sympy.abc import x

    >>> lcm_list([x**3 - 1, x**2 - 1, x**2 - 3*x + 2])
    x**5 - x**4 - 2*x**3 - x**2 + x + 2

    c                óä   •— ‰sm‰skt        | «      \  }}|s|j                  |j                  «      S |j                  r4|d   |dd  }}|D ]  }|j	                  ||«      }Œ |j                  |«      S y r~  )r+   r×   rÊ   rO  rõ  r  s        €€rd   Útry_non_polynomial_lcmz(lcm_list.<locals>.try_non_polynomial_lcm=  s{   ø€ Ù™DÜ.¨sÓ3‰OˆF�GáØ—‘ v§z¡zÓ2Ð2Ø×$Ò$Ø")¨!¡*¨g°a°b¨k˜�à%ò 8�FØ#ŸZ™Z¨°Ó7‘Fð8ð —‘ vÓ.Ð.àrg   NrO  r‚   c              3  óP   K  — | ]  }|j                   xr |j                  –— Œ  y ­wrˆ   r…  rˆ  s     rd   rŠ  zlcm_list.<locals>.<genexpr>X  r‹  rŒ  r¡  c              3  ó4   K  — | ]  }|j                   –— Œ y ­wrˆ   rŽ  r�  s     rd   rŠ  zlcm_list.<locals>.<genexpr>[  r’  r“  Úlcm_listrž   r   )r  zOptional[Expr])r%   ro   r^  rD  r„   r  r•  rõ  r–  r?   rC  r@   rO  r   r¾  rW   r]   )r€  rY   r~   rž  rb   rO  r   rÃ  r  r—  r˜  r‘  r|  rD  s    ``           rd   r¡  r¡  ,  s–  ù€ ô �#‹,€Cöñ  $ CÓ(€FàÐØˆä×Ñ˜$  	Ô*ð?Ü,¨SÐ@°4Ò@¸4Ñ@‰
ˆˆsô ˆs‹8�aŠ<œCÑVÐRUÔVÔVØ�B‘ˆAØ14°S°b°Ö;¨#�Q�s‘U—O‘OÕ%Ð;ˆCÐ;ÜÑ2¨cÔ2Ô2Ø�Øò :�CÜ˜R ×!3Ñ!3Ó!5°aÑ!8Ó9‘Bð:à˜‘t�ñ Ø�yŠyÜ—5‘5ˆLä˜˜sÔ#Ð#à˜!‘H˜e A B˜iˆE€Fàò "ˆØ—‘˜DÓ!‰ð"ð �9Š9Ø�~‰~ÓÐàˆùò; <øô ò ?Ù'¨¯	©	Ó2ˆàÐØ�Mä# J´°C³¸#Ó>Ð>ûð?ús5   ¹>E  Á7D;Â>E  Ä;E  Å 	E?Å	E:ÅE?Å$E:Å:E?c                óì  — t        | d«      r|�|f|z   }t        | g|¢­i |¤ŽS |€t        d«      ‚t        j                  |dg«       	 t        | |fg|¢­i |¤Ž\  \  }}}t        t        | |f«      \  }}|j                  rY|j                  rM|j                  rA|j                  r5||z  j                  «       }	|	j                  r||	j                  «       d   z  S |j#                  |«      }|j(                  s|j+                  «       S |S # t        $ ra}
t        |
j                  «      \  }\  }}	 |j!                  |j#                  ||«      «      cY d}
~
S # t$        $ r t'        dd|
«      ‚w xY wd}
~
ww xY w)zÅ
    Compute LCM of ``f`` and ``g``.

    Examples
    ========

    >>> from sympy import lcm
    >>> from sympy.abc import x

    >>> lcm(x**2 - 1, x**2 - 3*x + 2)
    x**3 - 2*x**2 - x + 2

    rš  Nz2lcm() takes 2 arguments or a sequence of argumentsrO  r‚   rõ  rŒ  )r  r¡  r™  ro   r^  rD  r¥   r%   r†  r‡  r•  r�  r–  r?   r+   rC  r×   rõ  rq   r@   rO  r]   r›  s                rd   rõ  rõ  z  se  € ô ˆq�*ÔØˆ=Ø�4˜$‘;ˆDä˜Ð)˜DÒ) DÑ)Ð)Ø	
ˆÜÐLÓMÐMä×Ñ˜$  	Ô*ð3Ü-¨q°!¨fÐD°tÒD¸tÑD‰‰ˆˆA�ô ”7˜Q ˜FÓ#‰ˆˆ1Ø�>Š>˜aŸošo°!·.².ÀQÇ_Â_Ø�Q‘3—-‘-“/ˆCØ�ŠØ˜×+Ñ+Ó-¨aÑ0Ñ0Ð0ð �U‰U�1‹X€Fà�9Š9Ø�~‰~ÓÐàˆøô ò 3Ü)¨#¯)©)Ó4‰ˆ‘��Að	3Ø—?‘? 6§:¡:¨a°Ó#3Ó4Õ4øÜ"ò 	3Ü# E¨1¨cÓ2Ð2ð	3þð3ús1   Á	BD	 Ä		E3ÄE.Ä. EÅE3ÅE+Å+E.Å.E3c           
     ó6  ‡‡— t        | «      }t        | t        «      r(t        ˆˆfd„| j                  | j                  fD «       Ž S t        | t
        «      rt        d| ›�«      ‚t        | t        «      r| j                  r|S ‰j                  dd«      rY | j                  | j                  D �cg c]  }t        |g‰¢­i ‰¤Ž‘Œ c}Ž }‰j                  d«       d‰d<   t        |g‰¢­i ‰¤ŽS ‰j                  dd«      }t        j                  ‰dg«       	 t!        | g‰¢­i ‰¤Ž\  }}|j                  «       \  }
} |j&                  j(                  rZ|j&                  j*                  r| j-                  d¬
«      \  }} | j/                  «       \  }} |j&                  j*                  r|z  }nt0        j2                  }t5        t7        | j8                  |
«      D ��cg c]
  \  }}||z  ‘Œ c}}Ž }t;        |d«      rt0        j2                  }|dk(  r|S |rt=        ||| j?                  «       z  «      S t=        || j?                  «       d¬«      jA                  «       \  }} t=        ||| z  d¬«      S c c}w # t"        $ r}	|	j$                  cY d	}	~	S d	}	~	ww xY wc c}}w )az  
    Remove GCD of terms from ``f``.

    If the ``deep`` flag is True, then the arguments of ``f`` will have
    terms_gcd applied to them.

    If a fraction is factored out of ``f`` and ``f`` is an Add, then
    an unevaluated Mul will be returned so that automatic simplification
    does not redistribute it. The hint ``clear``, when set to False, can be
    used to prevent such factoring when all coefficients are not fractions.

    Examples
    ========

    >>> from sympy import terms_gcd, cos
    >>> from sympy.abc import x, y
    >>> terms_gcd(x**6*y**2 + x**3*y, x, y)
    x**3*y*(x**3*y + 1)

    The default action of polys routines is to expand the expression
    given to them. terms_gcd follows this behavior:

    >>> terms_gcd((3+3*x)*(x+x*y))
    3*x*(x*y + x + y + 1)

    If this is not desired then the hint ``expand`` can be set to False.
    In this case the expression will be treated as though it were comprised
    of one or more terms:

    >>> terms_gcd((3+3*x)*(x+x*y), expand=False)
    (3*x + 3)*(x*y + x)

    In order to traverse factors of a Mul or the arguments of other
    functions, the ``deep`` hint can be used:

    >>> terms_gcd((3 + 3*x)*(x + x*y), expand=False, deep=True)
    3*x*(x + 1)*(y + 1)
    >>> terms_gcd(cos(x + x*y), deep=True)
    cos(x*(y + 1))

    Rationals are factored out by default:

    >>> terms_gcd(x + y/2)
    (2*x + y)/2

    Only the y-term had a coefficient that was a fraction; if one
    does not want to factor out the 1/2 in cases like this, the
    flag ``clear`` can be set to False:

    >>> terms_gcd(x + y/2, clear=False)
    x + y/2
    >>> terms_gcd(x*y/2 + y**2, clear=False)
    y*(x/2 + y)

    The ``clear`` flag is ignored if all coefficients are fractions:

    >>> terms_gcd(x/3 + y/2, clear=False)
    (2*x + 3*y)/6

    See Also
    ========
    sympy.core.exprtools.gcd_terms, sympy.core.exprtools.factor_terms

    c              3  ó<   •K  — | ]  }t        |g‰¢­i ‰¤Ž–— Œ y ­wrˆ   )rU  )r‰  rš  r~   rY   s     €€rd   rŠ  zterms_gcd.<locals>.<genexpr>ó  s    øè ø€ ÒN¸!œ) AÐ5¨Ò5°Õ5ÑNùs   ƒz3Inequalities cannot be used with terms_gcd. Found: ÚdeepFr>  ÚclearTrO  NrÂ  r‚   )r¦  )!r%   rV   r!   ÚlhsÚrhsr    r™  r   Úis_AtomrÉ  rc   r~   rU  r�  ro   r^  r<  r?   rŒ   rS   r  r€  r½  rÿ  r   r¾  r   rÞ   rY   r   r   r]   Úas_coeff_Mul)r_   rY   r~   r?  rÃ  r†   r¦  rÏ   r   r|  rû   Údenomr£   r  rü   Úterms    ``             rd   rU  rU  ­  s3  ù€ ôF �1‹:€Dä�!”XÔÜÔNÀÇÁÀqÇuÁu¸~ÔNÐOÐOÜ	�A”zÔ	"ÝÑRSÐUÓVÐVä�aœÔ !§)¢)Øˆà‡x�x�˜ÔØˆa�f‰f¸A¿F¹FÖC°q”y Ð2 TÒ2¨TÓ2ÒCÐDˆØ�‰�ÔØˆˆX‰Ü˜Ð,˜tÒ, tÑ,Ð,à�H‰H�W˜dÓ#€EÜ×Ñ˜$  	Ô*ðÜ Ð1 DÒ1¨DÑ1‰ˆˆ3ð �;‰;‹=�D€A€qà
‡z�z×ÒØ�:‰:×ÒØ—~‘~¨d�~Ó3‰HˆE�1à—;‘;“=‰ˆˆqà�:‰:×ÒØ�U‰N‰Eä—‘ˆä¤# a§f¡f¨a£.×1™$˜!˜Q��A“Ó1Ð2€DÜ�E˜1ÔÜ—‘ˆØ�1Š9ØˆKáÜ˜5 $ q§y¡y£{Ñ"2Ó3Ð3ô ˜5 !§)¡)£+°UÔ;×HÑHÓJ�H€Eˆ1Ü�u˜d 1™f¨EÔ2Ð2ùòK Døô ò Ø�x‰x�ûðüó  2s*   Â.I.ÄI3 ÇJ
É3	JÉ<JÊJÊJc                ó  — t        j                  |ddg«       	 t        | g|¢­i |¤Ž\  }}|j                  t        |«      «      }|j                  s|j                  «       S |S # t        $ r}t	        dd|«      ‚d}~ww xY w)zË
    Reduce ``f`` modulo a constant ``p``.

    Examples
    ========

    >>> from sympy import trunc
    >>> from sympy.abc import x

    >>> trunc(2*x**3 + 3*x**2 + 5*x + 7, 3)
    -x**3 - x + 1

    r�  rO  r÷  r‚   N)	ro   r^  r<  r?   r@   r÷  r%   rO  r]   )r_   rø  rY   r~   rÏ   r   r|  rb   s           rd   r÷  r÷  #  s„   € ô ×Ñ˜$ ¨Ð 1Ô2ð1Ü Ð1 DÒ1¨DÑ1‰ˆˆ3ð �W‰W”W˜Q“ZÓ €Fà�9Š9Ø�~‰~ÓÐàˆøô ò 1Ü ¨¨CÓ0Ð0ûð1ús   šA$ Á$	A?Á-A:Á:A?c                ó  — t        j                  |ddg«       	 t        | g|¢­i |¤Ž\  }}|j                  |j                  ¬«      }|j                  s|j                  «       S |S # t        $ r}t	        dd|«      ‚d}~ww xY w)zÍ
    Divide all coefficients of ``f`` by ``LC(f)``.

    Examples
    ========

    >>> from sympy import monic
    >>> from sympy.abc import x

    >>> monic(3*x**2 + 4*x + 2)
    x**2 + 4*x/3 + 2/3

    r�  rO  rú  r‚   Nrm  )	ro   r^  r<  r?   r@   rú  r�  rO  r]   ry  s          rd   rú  rú  A  s†   € ô ×Ñ˜$ ¨Ð 1Ô2ð1Ü Ð1 DÒ1¨DÑ1‰ˆˆ3ð �W‰W˜#Ÿ(™(ˆWÓ#€Fà�9Š9Ø�~‰~ÓÐàˆøô ò 1Ü ¨¨CÓ0Ð0ûð1ús   šA& Á&	BÁ/A<Á<Bc                ó²   — t        j                  |dg«       	 t        | g|¢­i |¤Ž\  }}|j                  «       S # t        $ r}t	        dd|«      ‚d}~ww xY w)z¸
    Compute GCD of coefficients of ``f``.

    Examples
    ========

    >>> from sympy import content
    >>> from sympy.abc import x

    >>> content(6*x**2 + 8*x + 12)
    2

    rO  rý  r‚   N)ro   r^  r<  r?   r@   rý  ra  s         rd   rý  rý  _  sb   € ô ×Ñ˜$  	Ô*ð3Ü Ð1 DÒ1¨DÑ1‰ˆˆ3ð �9‰9‹;Ðøô ò 3Ü 	¨1¨cÓ2Ð2ûð3ús   ™; »	AÁAÁAc                óü   — t        j                  |dg«       	 t        | g|¢­i |¤Ž\  }}|j                  «       \  }}|j                  s||j                  «       fS ||fS # t        $ r}t	        dd|«      ‚d}~ww xY w)a•  
    Compute content and the primitive form of ``f``.

    Examples
    ========

    >>> from sympy.polys.polytools import primitive
    >>> from sympy.abc import x

    >>> primitive(6*x**2 + 8*x + 12)
    (2, 3*x**2 + 4*x + 6)

    >>> eq = (2 + 2*x)*x + 2

    Expansion is performed by default:

    >>> primitive(eq)
    (2, x**2 + x + 1)

    Set ``expand`` to False to shut this off. Note that the
    extraction will not be recursive; use the as_content_primitive method
    for recursive, non-destructive Rational extraction.

    >>> primitive(eq, expand=False)
    (1, x*(2*x + 2) + 2)

    >>> eq.as_content_primitive()
    (2, x*(x + 1) + 1)

    rO  rÿ  r‚   N)ro   r^  r<  r?   r@   rÿ  rO  r]   )r_   rY   r~   rÏ   r   r|  r   rb   s           rd   rÿ  rÿ  x  s‰   € ô@ ×Ñ˜$  	Ô*ð5Ü Ð1 DÒ1¨DÑ1‰ˆˆ3ð —;‘;“=�L€Dˆ&Ø�9Š9Ø�V—^‘^Ó%Ð%Ð%à�Vˆ|Ðøô ò 5Ü ¨Q°Ó4Ð4ûð5ús   ™A  Á 	A;Á)A6Á6A;c                óú   — t        j                  |dg«       	 t        | |fg|¢­i |¤Ž\  \  }}}|j                  |«      }|j                  s|j                  «       S |S # t        $ r}t	        dd|«      ‚d}~ww xY w)zÀ
    Compute functional composition ``f(g)``.

    Examples
    ========

    >>> from sympy import compose
    >>> from sympy.abc import x

    >>> compose(x**2 + x, x - 1)
    x**2 - x

    rO  r  rŒ  N)ro   r^  rD  r?   r@   r  rO  r]   )	r_   r`   rY   r~   rÏ   rÐ   r   r|  rb   s	            rd   r  r  ¦  s„   € ô ×Ñ˜$  	Ô*ð3Ü-¨q°!¨fÐD°tÒD¸tÑD‰‰ˆˆA�ð �Y‰Y�q‹\€Fà�9Š9Ø�~‰~ÓÐàˆøô ò 3Ü 	¨1¨cÓ2Ð2ûð3úrh  c                ó  — t        j                  |dg«       	 t        | g|¢­i |¤Ž\  }}|j                  «       }|j                  s|D �cg c]  }|j                  «       ‘Œ c}S |S # t        $ r}t	        dd|«      ‚d}~ww xY wc c}w )zÜ
    Compute functional decomposition of ``f``.

    Examples
    ========

    >>> from sympy import decompose
    >>> from sympy.abc import x

    >>> decompose(x**4 + 2*x**3 - x - 1)
    [x**2 - x - 1, x**2 + x]

    rO  r  r‚   N)ro   r^  r<  r?   r@   r  rO  r]   ©r_   rY   r~   rÏ   r   r|  rb   ru  s           rd   r  r  Ä  sˆ   € ô ×Ñ˜$  	Ô*ð5Ü Ð1 DÒ1¨DÑ1‰ˆˆ3ð �[‰[‹]€Fà�9Š9Ø%+Ö, �—	‘	•Ò,Ð,àˆøô ò 5Ü ¨Q°Ó4Ð4ûð5üò -s   ™A' ÁBÁ'	BÁ0A=Á=Bc                ó.  — t        j                  |ddg«       	 t        | g|¢­i |¤Ž\  }}|j                  |j                  ¬«      }|j                  s|D �cg c]  }|j                  «       ‘Œ c}S |S # t        $ r}t	        dd|«      ‚d}~ww xY wc c}w )zò
    Compute Sturm sequence of ``f``.

    Examples
    ========

    >>> from sympy import sturm
    >>> from sympy.abc import x

    >>> sturm(x**3 - 2*x**2 + x - 3)
    [x**3 - 2*x**2 + x - 3, 3*x**2 - 4*x + 1, 2*x/9 + 25/9, -2079/4]

    r�  rO  r  r‚   Nrm  )	ro   r^  r<  r?   r@   r  r�  rO  r]   r³  s           rd   r  r  â  s”   € ô ×Ñ˜$ ¨Ð 1Ô2ð1Ü Ð1 DÒ1¨DÑ1‰ˆˆ3ð �W‰W˜#Ÿ(™(ˆWÓ#€Fà�9Š9Ø%+Ö, �—	‘	•Ò,Ð,àˆøô ò 1Ü ¨¨CÓ0Ð0ûð1üò -s   šA4 ÁBÁ4	BÁ=B
Â
Bc                ó$  — t        j                  |dg«       	 t        | g|¢­i |¤Ž\  }}|j                  «       }|j                  s%|D ��cg c]  \  }}|j                  «       |f‘Œ c}}S |S # t        $ r}t	        dd|«      ‚d}~ww xY wc c}}w )a&  
    Compute a list of greatest factorial factors of ``f``.

    Note that the input to ff() and rf() should be Poly instances to use the
    definitions here.

    Examples
    ========

    >>> from sympy import gff_list, ff, Poly
    >>> from sympy.abc import x

    >>> f = Poly(x**5 + 2*x**4 - x**3 - 2*x**2, x)

    >>> gff_list(f)
    [(Poly(x, x, domain='ZZ'), 1), (Poly(x + 2, x, domain='ZZ'), 4)]

    >>> (ff(Poly(x), 1)*ff(Poly(x + 2), 4)) == f
    True

    >>> f = Poly(x**12 + 6*x**11 - 11*x**10 - 56*x**9 + 220*x**8 + 208*x**7 -         1401*x**6 + 1090*x**5 + 2715*x**4 - 6720*x**3 - 1092*x**2 + 5040*x, x)

    >>> gff_list(f)
    [(Poly(x**3 + 7, x, domain='ZZ'), 2), (Poly(x**2 + 5*x, x, domain='ZZ'), 3)]

    >>> ff(Poly(x**3 + 7, x), 2)*ff(Poly(x**2 + 5*x, x), 3) == f
    True

    rO  r  r‚   N)ro   r^  r<  r?   r@   r  rO  r]   )	r_   rY   r~   rÏ   r   r|  r  r`   rR  s	            rd   r  r     s’   € ô@ ×Ñ˜$  	Ô*ð4Ü Ð1 DÒ1¨DÑ1‰ˆˆ3ð �j‰j‹l€Gà�9Š9Ø-4×5¡T Q¨�—‘“˜aÒ Ó5Ð5àˆøô ò 4Ü 
¨A¨sÓ3Ð3ûð4üó 6s   ™A. ÁBÁ.	B	Á7BÂB	c                ó   — t        d«      ‚)z3Compute greatest factorial factorization of ``f``. zsymbolic falling factorialrª  ©r_   rY   r~   s      rd   Úgffr¸  /  s   € ô Ð:Ó
;Ð;rg   c                óX  — t        j                  |dg«       	 t        | g|¢­i |¤Ž\  }}|j                  «       \  }}}|D �	cg c]  }	t        |	«      ‘Œ }
}	|j                  s!|
|j                  «       |j                  «       fS |
||fS # t        $ r}t	        dd|«      ‚d}~ww xY wc c}	w )a¿  
    Compute square-free norm of ``f``.

    Returns ``s``, ``f``, ``r``, such that ``g(x) = f(x-sa)`` and
    ``r(x) = Norm(g(x))`` is a square-free polynomial over ``K``,
    where ``a`` is the algebraic extension of the ground domain.

    Examples
    ========

    >>> from sympy import sqf_norm, sqrt
    >>> from sympy.abc import x

    >>> sqf_norm(x**2 + 1, extension=[sqrt(3)])
    ([1], x**2 - 2*sqrt(3)*x + 4, x**4 - 4*x**2 + 16)

    rO  r  r‚   N)	ro   r^  r<  r?   r@   r  r   rO  r]   )r_   rY   r~   rÏ   r   r|  rš  r`   ru  ÚsiÚs_exprs              rd   r  r  5  s®   € ô& ×Ñ˜$  	Ô*ð4Ü Ð1 DÒ1¨DÑ1‰ˆˆ3ð �j‰j‹l�G€A€qˆ!à$%Ö&˜bŒg�b�kÐ&€FÐ&à�9Š9Ø�q—y‘y“{ A§I¡I£KÐ/Ð/à�q˜!ˆ|Ðøô ò 4Ü 
¨A¨sÓ3Ð3ûð4üò
 's   ™B	 ÁB'Â		B$ÂBÂB$c                óî   — t        j                  |dg«       	 t        | g|¢­i |¤Ž\  }}|j                  «       }|j                  s|j                  «       S |S # t        $ r}t	        dd|«      ‚d}~ww xY w)z¿
    Compute square-free part of ``f``.

    Examples
    ========

    >>> from sympy import sqf_part
    >>> from sympy.abc import x

    >>> sqf_part(x**3 - 3*x - 2)
    x**2 - x - 2

    rO  r  r‚   N)ro   r^  r<  r?   r@   r  rO  r]   ry  s          rd   r  r  Y  sz   € ô ×Ñ˜$  	Ô*ð4Ü Ð1 DÒ1¨DÑ1‰ˆˆ3ð �Z‰Z‹\€Fà�9Š9Ø�~‰~ÓÐàˆøô ò 4Ü 
¨A¨sÓ3Ð3ûð4úrz  c                ó    — | j                   j                  «       }t        |«      t        | j                  «      t	        | j
                  «      |fS )zSort a list of polys.©rj   r=  r„   rY   rs   rS   )rD  rj   s     rd   Ú_poly_sort_keyr¿  w  s8   € à
�(‰(×
Ñ
Ó
€CÜ�‹H”c˜$Ÿ)™)“n¤c¨$¯+©+Ó&6¸Ð<Ð<rg   c                ó4   — |dk(  rd„ }nd„ }t        | |¬«      S )z&Sort a list of ``(expr, exp)`` pairs. r)  c                ó¬   — | \  }}|j                   j                  «       }|t        |«      t        |j                  «      t	        |j
                  «      |fS rˆ   r¾  ©r…   rD  Úexprj   s       rd   rk  z_sorted_factors.<locals>.key€  sC   € Ø‰IˆD�#Ø—(‘(×"Ñ"Ó$ˆCØœ˜S›¤3 t§y¡y£>´3°t·{±{Ó3CÀSÐIÐIrg   c                ó¬   — | \  }}|j                   j                  «       }t        |«      t        |j                  «      |t	        |j
                  «      |fS rˆ   r¾  rÂ  s       rd   rk  z_sorted_factors.<locals>.key…  sC   € Ø‰IˆD�#Ø—(‘(×"Ñ"Ó$ˆCÜ˜“Hœc $§)¡)›n¨c´3°t·{±{Ó3CÀSÐIÐIrg   rj  )rv  )r  Úmethodrk  s      rd   Ú_sorted_factorsrÆ  }  s$   € à�‚ó	Jò
	Jô
 �'˜sÔ#Ð#rg   c                óf   — t        | D ��cg c]  \  }}|j                  «       |z  ‘Œ c}}Ž S c c}}w )z*Multiply a list of ``(expr, exp)`` pairs. )r   r]   )r  r_   rR  s      rd   Ú_factors_productrÈ  �  s)   € ä¨G×4¡D A q�—‘“˜a“Ó4Ð5Ð5ùÓ4s   ‹-
c           
     ój  ‡— t         j                  g }}t        j                  | «      D �cg c]   }t	        |d«      r|j                  «       n|‘Œ" }}|D �]  }|j                  st        |t        «      rt        |«      r||z  }Œ1|j                  rj|j                  t         j                  k7  rM|j                  \  }}	|j                  r|	j                  r||z  }Œ‡|j                  r&|j                  ||	f«       Œ§|t         j                  }	}	 t        ||«      \  }
}t!        |
|dz   «      } |«       \  }}|t         j                  urV|	j"                  r	|||	z  z  }nA|j$                  r|j                  ||	f«       n!|j                  |t         j                  f«       |	t         j                  u r|j'                  |«       �Œo|	j(                  r+|j'                  |D ��cg c]  \  }}|||	z  f‘Œ c}}«       �Œ¦g }|D ]I  \  }Š|j+                  «       j$                  r|j                  |‰|	z  f«       Œ7|j                  |‰f«       ŒK |j                  t-        |«      |	f«       �Œ |dk(  r<|D ��ch c]  \  }}|’Œ	 c}}D �‡cg c]  Št3        t4        ˆfd„|D «       «      ‰f‘Œ }}t7        t8        «      }|D ]  \  Š}|‰xx   |z  cc<   Œ |t;        |j=                  «       «      fS c c}w c c}}w # t.        $ r(}|j                  |j0                  |	f«       Y d}~�ŒÎd}~ww xY wc c}}w c c}w )z.Helper function for :func:`_symbolic_factor`. Ú_eval_factorÚ_listNr)  c              3  ó4   •K  — | ]  \  }}|‰k(  sŒ|–— Œ y ­wrˆ   r  )r‰  r_   rÍ   rR  s      €rd   rŠ  z(_symbolic_factor_list.<locals>.<genexpr>Æ  s   øè ø€ Ò A¡t q¨!¸!¸q»&¤Ñ Aùs   ƒ‘)r   r¾  r   Ú	make_argsr  rÊ  rV  rV   r   r   Úis_PowÚbaseÚExp1r~   rH  r;  r\   r  Úis_positiverJ  Ú
is_integerr]   rÈ  r?   rŒ   r   r   r
   r(  rw   rŸ   )rŒ   r   rÅ  r£   r  r¼   r~   ÚargrÏ  rÃ  rD  rÍ   rc   Ú_coeffÚ_factorsr_   rR  r
  r|  r\  r2  s                   `    rd   Ú_symbolic_factor_listrÖ  ’  sÓ  ø€ ä—U‘U˜Bˆ7€Eô —‘˜tÓ$ö&Øô !(¨¨>Ô :ˆA�N‰NÔÀÑAð &€Dð &àó ,?ˆØ�=Š=œZ¨¬TÔ2´|ÀCÔ7HØ�S‰LˆEØØ�ZŠZ˜CŸH™H¬¯©Ò.ØŸ™‰IˆD�#Ø�~Š~ #§-¢-Ø˜‘�ØØ�~Š~Ø—‘  c˜{Ô+ØàœQŸU™U�#ˆDð	?Ü% d¨CÓ0‰GˆD�!ô ˜4 ¨'Ñ!1Ó2ˆDá#›vÑˆF�HØœQŸU™UÑ"Ø—>’>Ø˜V S™[Ñ(‘EØ×'Ò'Ø—N‘N F¨C =Õ1à—O‘O V¬Q¯U©U OÔ4à”a—e‘e‰|Ø—‘˜xÖ(Ø—’Ø—‘°x×@©t¨q°!  A c¡E¢
Ó@ÖAà�à$ò -‘D�A�qØ—y‘y“{×.Ò.ØŸ™¨¨1¨S©5 zÕ2àŸ™ a¨ VÕ,ð	-ð —‘Ô 0°Ó 7¸Ð=Ö>ðY,?ðZ �‚à+2×3¡4 1 ašQÓ3÷5Øô œ3Ó A¨wÔ AÓBÀAÒFð 5ˆð 5ô 
”SÓ	€BØò ‰ˆˆ1Ø
ˆ1‹�‰
Œðà”$�r—x‘x“zÓ"Ð"Ð"ùòm&ùóH  Aøô# "ò 	,Ø�N‰N˜CŸH™H c˜?×+Ò+ûð	,üó< 4ùò5s/   «%K+ÄK6ÇK0É3L*Ê"L0Ë6	L'Ë?L"Ì"L'c           
     óÀ  — t        | t        «      rOt        | d«      r| j                  «       S t	        t        | |d   ¬«      ||«      \  }}t        |t        |«      «      S t        | d«      r2 | j                  | j                  D �cg c]  }t        |||«      ‘Œ c}Ž S t        | d«      r*| j                  | D �cg c]  }t        |||«      ‘Œ c}«      S | S c c}w c c}w )z%Helper function for :func:`_factor`. rÊ  Úfraction)rØ  r~   rš  )rV   r   r  rÊ  rÖ  rH   r   rÈ  rc   r~   Ú_symbolic_factorr§   )rŒ   r   rÅ  r£   r  rÓ  s         rd   rÙ  rÙ  Ï  sÇ   € ä�$œÔÜ�4˜Ô'Ø×$Ñ$Ó&Ð&Ü.¬x¸ÀsÈ:ÁÔ/WÐY\Ð^dÓe‰ˆˆwÜ˜5Ô"2°7Ó";Ó<Ð<Ü	��vÔ	Øˆt�y‰yÈÏÉÖSÀ#Ô+¨C°°fÕ=ÒSÐTÐTÜ	��zÔ	"Ø�~‰~ÈTÖRÀcÔ/°°S¸&ÕAÒRÓSÐSàˆùò	 TùâRs   ÂCÂ9Cc                óf  — t        j                  |ddg«       t        j                  ||«      }t        | «      } t	        | t
        t        f«      �rHt	        | t        «      r| d}}nt        | «      j                  «       \  }}t        |||«      \  }}t        |||«      \  }	}
|
r|j                  st        d| z  «      ‚|j                  ddi«      }||
fD ];  }t        |«      D ]+  \  }\  }}|j                  rŒt        ||«      \  }}||f||<   Œ- Œ= t!        ||«      }t!        |
|«      }
|j"                  sH|D ��cg c]  \  }}|j%                  «       |f‘Œ }}}|
D ��cg c]  \  }}|j%                  «       |f‘Œ }
}}||	z  }|j                  s||fS |||
fS t        d| z  «      ‚c c}}w c c}}w )z>Helper function for :func:`sqf_list` and :func:`factor_list`. ÚfracrO  r‚   za polynomial expected, got %sr>  T)ro   r^  rp   r%   rV   r   rW   rH   r–  rÖ  rÛ  r<   Úclonerú   ry   r;  rÆ  rO  r]   )rŒ   rY   r~   rÅ  r   Únumerr«  r¤  Úfpr¥  ÚfqÚ_optr  r¼   r_   rR  rÍ   r£   s                     rd   Ú_generic_factor_listrá  Þ  s±  € ä×Ñ˜$ ¨Ð 1Ô2Ü
×
Ñ
  dÓ
+€Cä�4‹=€Dä�$œœt˜Õ%Ü�dœDÔ!Ø �5‰Eä# D›>×8Ñ8Ó:‰LˆE�5ä& u¨c°6Ó:‰ˆˆBÜ& u¨c°6Ó:‰ˆˆBá�c—h’hÜ!Ð"AÀDÑ"HÓIÐIà�y‰y˜( DÐ)Ó*ˆà˜B�xò 	(ˆGÜ& wÓ/ò (‘	�‘6�A�qØ—y“yÜ*¨1¨dÓ3‘D�A�qØ"# Q �G˜A’Jñ(ð	(ô ˜R Ó(ˆÜ˜R Ó(ˆà�yŠyØ/1×2¡t q¨!�1—9‘9“; Ò"Ð2ˆBÑ2Ø/1×2¡t q¨!�1—9‘9“; Ò"Ð2ˆBÑ2à�2‘ˆà�xŠxØ˜"�9Ðà˜"˜b�=Ð äÐ=ÀÑDÓEÐEùó 3ùÛ2s   Ä<F'Å F-c                ó´   — |j                  dd«      }t        j                  |g «       t        j                  ||«      }||d<   t	        t        | «      ||«      S )z4Helper function for :func:`sqf` and :func:`factor`. rØ  T)r�  ro   r^  rp   rÙ  r%   )rŒ   rY   r~   rÅ  rØ  r   s         rd   Ú_generic_factorrã  
  sP   € à�x‰x˜
 DÓ)€HÜ×Ñ˜$ Ô#Ü
×
Ñ
  dÓ
+€CØ€Cˆ
�OÜœG D›M¨3°Ó7Ð7rg   c                óö   ‡— ddl mŠ d	ˆfd„	}d	ˆfd„	}d„ }| j                  «       j                  rI || «      rA| j	                  «       } || |«      }|r|d   |d   d|d   fS  || |«      }|rdd|d   |d   fS y)
a!  
    try to transform a polynomial to have rational coefficients

    try to find a transformation ``x = alpha*y``

    ``f(x) = lc*alpha**n * g(y)`` where ``g`` is a polynomial with
    rational coefficients, ``lc`` the leading coefficient.

    If this fails, try ``x = y + beta``
    ``f(x) = g(y)``

    Returns ``None`` if ``g`` not found;
    ``(lc, alpha, None, g)`` in case of rescaling
    ``(None, None, beta, g)`` in case of translation

    Notes
    =====

    Currently it transforms only polynomials without roots larger than 2.

    Examples
    ========

    >>> from sympy import sqrt, Poly, simplify
    >>> from sympy.polys.polytools import to_rational_coeffs
    >>> from sympy.abc import x
    >>> p = Poly(((x**2-1)*(x-2)).subs({x:x*(1 + sqrt(2))}), x, domain='EX')
    >>> lc, r, _, g = to_rational_coeffs(p)
    >>> lc, r
    (7 + 5*sqrt(2), 2 - 2*sqrt(2))
    >>> g
    Poly(x**3 + x**2 - 1/4*x - 1/4, x, domain='QQ')
    >>> r1 = simplify(1/r)
    >>> Poly(lc*r**3*(g.as_expr()).subs({x:x*r1}), x, domain='EX') == p
    True

    r   ©ÚsimplifyNc                óî  •— t        | j                  «      dk(  r| j                  d   j                  sd| fS | j                  «       }| j	                  «       }|xs |j                  «       }|j                  «       dd }|D �cg c]
  } ‰|«      ‘Œ }}t        |«      dkD  rÐ|d   rË ‰|d   |d   z  «      }g }t        t        |«      «      D ]5  } ‰||   ||dz   z  z  «      }|j                  s y|j                  |«       Œ7  ‰d|z  «      }	| j                  d   }
|
|z  g}t        d|dz   «      D ]"  }|j                  ||dz
     |
||z
  z  z  «       Œ$ t        |Ž } t        | «      } ||	| fS yc c}w )a$  
        try rescaling ``x -> alpha*x`` to convert f to a polynomial
        with rational coefficients.
        Returns ``alpha, f``; if the rescaling is successful,
        ``alpha`` is the rescaling factor, and ``f`` is the rescaled
        polynomial; else ``alpha`` is ``None``.
        r‚   r   Néþÿÿÿr¡  )r„   rY   r©  r�  r�  rú  r1  r·   r�  rH  r   rW   )r_   Úf1r*  r˜  rÁ   ÚcoeffxÚ
rescale1_xÚcoeffs1r¼   Ú	rescale_xr  r2  ræ  s               €rd   Ú_try_rescalez(to_rational_coeffs.<locals>._try_rescale;  s‡  ø€ ô �1—6‘6‹{˜aÒ¨¯©¨q©	×':Ò':Ø˜�7ˆNØ�H‰H‹JˆØ�T‰T‹VˆØÒ�2—8‘8“:ˆØ—‘“  Ð$ˆØ17Ö8 v‘(˜6Õ"Ð8ˆÐ8Üˆv‹;˜Š?˜v bšzÙ! &¨¡*¨V°B©ZÑ"7Ó8ˆJØˆGÜœ3˜v›;Ó'ò (�Ù! &¨¡)¨J¸¸Q¹Ñ,?Ñ"?Ó@�Ø×)Ò)Øð ð —‘˜vÕ&ð	(ñ % Q z¡\Ó2�	Ø—F‘F˜1‘I�Ø˜‘T�F�Ü˜q ! a¡%›ò 8�AØ—H‘H˜W Q¨¡U™^¨A°°A±©JÑ6Õ7ð8ä˜�G�Ü˜“G�Ø˜9 aÐ'Ð'Øùò% 9s   ÂE2c                ó¬  •— t        | j                  «      dk(  r| j                  d   j                  sd| fS | j                  «       }|xs |j	                  «       }|j                  «       dd } ‰	|d   «      }|j                  rP|j                  sDt        |j                  d„ d¬«      \  }} |j                  |Ž  |z  }|j                  |«      }||fS y)a+  
        try translating ``x -> x + alpha`` to convert f to a polynomial
        with rational coefficients.
        Returns ``alpha, f``; if the translating is successful,
        ``alpha`` is the translating factor, and ``f`` is the shifted
        polynomial; else ``alpha`` is ``None``.
        r‚   r   Nc                ó   — | j                   du S r   rŽ  )Úzs    rd   ri  z<to_rational_coeffs.<locals>._try_translate.<locals>.<lambda>m  s   € ˜!Ÿ-™-¨4Ð/€ rg   T©Úbinary)r„   rY   r©  r�  rú  r1  Úis_Addr�  rO   r~   rc   r  )
r_   ré  r*  rÁ   râ   ÚratÚnonratÚalphaÚf2ræ  s
            €rd   Ú_try_translatez*to_rational_coeffs.<locals>._try_translate]  sÀ   ø€ ô �1—6‘6‹{˜aÒ¨¯©¨q©	×':Ò':Ø˜�7ˆNØ�H‰H‹JˆØÒ�2—8‘8“:ˆØ—‘“  Ð$ˆÙ�V˜A‘YÓˆØ�8Š8˜AŸMšMÜ˜qŸv™vÙ/¸ô>‰KˆC�à�Q—V‘V˜V�_Ð$ QÑ&ˆEØ—‘˜%“ˆBØ˜"�9ÐØrg   c                ó�  — | j                  «       }d}|D ]¨  }t        j                  |«      D ]Ž  }t        |«      j                  }|j                  «       D ��cg c]8  \  }}|j                  r'|j                  r|j                  dk\  r|j                  ‘Œ: }}}|sŒnt        |«      dk(  rd}t        |«      dkD  sŒ�  y Œª |S c c}}w )zS
        Return True if ``f`` is a sum with square roots but no other root
        FrŒ  T)rÁ   r   rÍ  r   r  rŸ   ró   Úis_Rationalrt  Úminr¹  )	rø  rÁ   Úhas_sqr  r  r_   rÄ  Úwxru  s	            rd   Ú_has_square_rootsz-to_rational_coeffs.<locals>._has_square_rootss  s¿   € ð —‘“ˆØˆØò 
	!ˆAÜ—]‘] 1Ó%ò 	!�Ü˜A“J×&Ñ&�Ø'(§w¡w£y÷ B™e˜a Ø—K’K B§N¢N°r·t±t¸q²yð —T“Tð B�ñ BáØÜ�q“6˜Q’;Ø!�FÜ�q“6˜A“:Ú ñ	!ð
	!ð ˆùóBs   Á=C
r‚   rŒ  rˆ   )Úsympy.simplify.simplifyræ  rÆ   rÀ   rú  )r_   rî  rù  rÿ  ré  ru  ræ  s         @rd   Úto_rational_coeffsr    s�   ø€ õL 1õ õDò,ð& 	‡|�|ƒ~×ÒÑ 1°!Ô 4Ø�W‰W‹YˆÙ˜˜BÓˆÙØ�Q‘4˜˜1™˜t Q q¡TÐ)Ð)á˜q "Ó%ˆAÙØ˜T 1 Q¡4¨¨1©Ð-Ð-Ørg   c           
     óþ  — ddl m} t        | |d¬«      }|j                  «       }t	        |«      }|sy|\  }}}}	t        |	j                  «       «      }
|re ||
d   |z  ||z  z  «      } |d|z  «      }g }|
dd d   D ]5  }|j                   ||d   j                  |||z  i«      «      |d   f«       Œ7 ||fS |
d   }g }|
dd d   D ]/  }|j                  |d   j                  |||z
  i«      |d   f«       Œ1 ||fS )a  
    helper function to factor polynomial using to_rational_coeffs

    Examples
    ========

    >>> from sympy.polys.polytools import _torational_factor_list
    >>> from sympy.abc import x
    >>> from sympy import sqrt, expand, Mul
    >>> p = expand(((x**2-1)*(x-2)).subs({x:x*(1 + sqrt(2))}))
    >>> factors = _torational_factor_list(p, x); factors
    (-2, [(-x*(1 + sqrt(2))/2 + 1, 1), (-x*(1 + sqrt(2)) - 1, 1), (-x*(1 + sqrt(2)) + 1, 1)])
    >>> expand(factors[0]*Mul(*[z[0] for z in factors[1]])) == p
    True
    >>> p = expand(((x**2-1)*(x-2)).subs({x:x + sqrt(2)}))
    >>> factors = _torational_factor_list(p, x); factors
    (1, [(x - 2 + sqrt(2), 1), (x - 1 + sqrt(2), 1), (x + 1 + sqrt(2), 1)])
    >>> expand(factors[0]*Mul(*[z[0] for z in factors[1]])) == p
    True

    r   rå  ÚEXr$  Nr‚   )	r   ræ  rW   r�  r  r  r]   rH  rö   )rø  r  ræ  Úp1r*  Úresr˜  ru  rÛ  r`   r  râ   Úr1rÃ  rñ  s                  rd   Ú_torational_factor_listr  ’  s,  € õ, 1Ü	ˆa�˜4Ô	 €BØ
�	‰	‹€AÜ
˜RÓ
 €CÙØØ�K€Bˆˆ1ˆaÜ˜!Ÿ)™)›+Ó&€GÙ	Ù�W˜Q‘Z ‘] 1 a¡4Ñ'Ó(ˆÙ�a˜‘c‹]ˆØˆØ˜˜�˜Q‘ò 	=ˆAØ�H‰H‘h˜q ™tŸy™y¨!¨Q¨r©T¨Ó3Ó4°a¸±dÐ;Õ<ð	=ð ˆqˆ6€Mð	 �A‰JˆØˆØ˜˜�˜Q‘ò 	4ˆAØ�H‰H�a˜‘d—i‘i  A¨¡E 
Ó+¨Q¨q©TÐ2Õ3ð	4àˆqˆ6€Mrg   c                ó    — t        | ||d¬«      S )zÿ
    Compute a list of square-free factors of ``f``.

    Examples
    ========

    >>> from sympy import sqf_list
    >>> from sympy.abc import x

    >>> sqf_list(2*x**5 + 16*x**4 + 50*x**3 + 76*x**2 + 56*x + 16)
    (2, [(x + 1, 2), (x + 2, 3)])

    r)  ©rÅ  ©rá  r·  s      rd   r  r  ¾  s   € ô    4¨°eÔ<Ð<rg   c                ó    — t        | ||d¬«      S )zë
    Compute square-free factorization of ``f``.

    Examples
    ========

    >>> from sympy import sqf
    >>> from sympy.abc import x

    >>> sqf(2*x**5 + 16*x**4 + 50*x**3 + 76*x**2 + 56*x + 16)
    2*(x + 1)**2*(x + 2)**3

    r)  r	  )rã  r·  s      rd   r)  r)  Ð  s   € ô ˜1˜d D°Ô7Ð7rg   c                ó    — t        | ||d¬«      S )a  
    Compute a list of irreducible factors of ``f``.

    Examples
    ========

    >>> from sympy import factor_list
    >>> from sympy.abc import x, y

    >>> factor_list(2*x**5 + 2*x**4*y + 4*x**3 + 4*x**2*y + 2*x + 2*y)
    (2, [(x + y, 1), (x**2 + 1, 2)])

    r|  r	  r
  r·  s      rd   r  r  â  s   € ô    4¨°hÔ?Ð?rg   )r¥  c               ó€  ‡‡— t        | «      } |ryˆˆfd„}t        | |«      } i }| j                  t        t        «      }|D ]5  }t        |g‰¢­i ‰¤Ž}|j                  s|j                  sŒ+||k7  sŒ1|||<   Œ7 | j                  |«      S 	 t        | ‰‰d¬«      S # t        $ r | j                  st        | «      cY S ‚ w xY w)a  
    Compute the factorization of expression, ``f``, into irreducibles. (To
    factor an integer into primes, use ``factorint``.)

    There two modes implemented: symbolic and formal. If ``f`` is not an
    instance of :class:`Poly` and generators are not specified, then the
    former mode is used. Otherwise, the formal mode is used.

    In symbolic mode, :func:`factor` will traverse the expression tree and
    factor its components without any prior expansion, unless an instance
    of :class:`~.Add` is encountered (in this case formal factorization is
    used). This way :func:`factor` can handle large or symbolic exponents.

    By default, the factorization is computed over the rationals. To factor
    over other domain, e.g. an algebraic or finite field, use appropriate
    options: ``extension``, ``modulus`` or ``domain``.

    Examples
    ========

    >>> from sympy import factor, sqrt, exp
    >>> from sympy.abc import x, y

    >>> factor(2*x**5 + 2*x**4*y + 4*x**3 + 4*x**2*y + 2*x + 2*y)
    2*(x + y)*(x**2 + 1)**2

    >>> factor(x**2 + 1)
    x**2 + 1
    >>> factor(x**2 + 1, modulus=2)
    (x + 1)**2
    >>> factor(x**2 + 1, gaussian=True)
    (x - I)*(x + I)

    >>> factor(x**2 - 2, extension=sqrt(2))
    (x - sqrt(2))*(x + sqrt(2))

    >>> factor((x**2 - 1)/(x**2 + 4*x + 4))
    (x - 1)*(x + 1)/(x + 2)**2
    >>> factor((x**2 + 4*x + 4)**10000000*(x**2 + 1))
    (x + 2)**20000000*(x**2 + 1)

    By default, factor deals with an expression as a whole:

    >>> eq = 2**(x**2 + 2*x + 1)
    >>> factor(eq)
    2**(x**2 + 2*x + 1)

    If the ``deep`` flag is True then subexpressions will
    be factored:

    >>> factor(eq, deep=True)
    2**((x + 1)**2)

    If the ``fraction`` flag is False then rational expressions
    will not be combined. By default it is True.

    >>> factor(5*x + 3*exp(2 - 7*x), deep=True)
    (5*x*exp(7*x) + 3*exp(2))*exp(-7*x)
    >>> factor(5*x + 3*exp(2 - 7*x), deep=True, fraction=False)
    5*x + 3*exp(2)*exp(-7*x)

    See Also
    ========
    sympy.ntheory.factor_.factorint

    c                óZ   •— t        | g‰¢­i ‰¤Ž}|j                  s|j                  r|S | S )zS
            Factor, but avoid changing the expression when unable to.
            )r|  Úis_MulrÎ  )rŒ   rx  r~   rY   s     €€rd   Ú_try_factorzfactor.<locals>._try_factor:  s0   ø€ ô ˜Ð- Ò-¨Ñ-ˆCØ�zŠz˜SŸZšZØ�
ØˆKrg   r|  r	  )r%   r(   Úatomsr   r   r|  r  rÎ  Úxreplacerã  r<   r)  r   )	r_   r¥  rY   r~   r  ÚpartialsÚmuladdrø  rx  s	     ``     rd   r|  r|  ô  sÇ   ù€ ôH 	�‹
€AÙõ	ô �a˜Ó%ˆð ˆØ—‘œœcÓ"ˆØò 	"ˆAÜ˜Ð*˜TÒ* TÑ*ˆCØ—
’
˜cŸj›j¨c°Q«hØ!�˜’ð	"ð �z‰z˜(Ó#Ð#ðÜ˜q $¨°XÔ>Ð>øÜò Ø×ÒÜ˜Q“<Òàð	ús   Â
B Â B=Â;B=c           	     óü  — t        | d«      s#	 t        | «      } | j                  ||||||¬«      S t	        | d¬«      \  }}	t        |	j                  «      dkD  rt        ‚t        |«      D ]"  \  }
}|j                  j                  «       ||
<   Œ$ |�+|	j                  j                  |«      }|dk  rt        d«      ‚|�|	j                  j                  |«      }|�|	j                  j                  |«      }t        ||	j                  |||||¬«      }g }|D ]S  \  \  }}}|	j                  j                  |«      |	j                  j                  |«      }}|j!                  ||f|f«       ŒU |S # t        $ r g cY S w xY w)	a/  
    Compute isolating intervals for roots of ``f``.

    Examples
    ========

    >>> from sympy import intervals
    >>> from sympy.abc import x

    >>> intervals(x**2 - 3)
    [((-2, -1), 1), ((1, 2), 1)]
    >>> intervals(x**2 - 3, eps=1e-2)
    [((-26/15, -19/11), 1), ((19/11, 26/15), 1)]

    rš  r$  r-   r$  r‚   r   r"  )r%  r&  r'  r  r(  )r  rW   r;   r#  rD  r„   rY   r=   rú   rj   r=  rS   r    r  rI   r×   rH  )rÏ   r  r%  r&  r'  r  r(  r)  rO  r   r¼   rD  r#  rb   rš  rÛ  r  s                    rd   r#  r#  W  sƒ  € ô" �1�jÔ!ð	Ü�Q“ˆAð �{‰{˜s¨°¸#ÀDÈcˆ{ÓRÐRä,¨Q°tÔ<‰
ˆˆsäˆs�x‰x‹=˜1ÒÜ-Ð-ä  Ó'ò 	*‰GˆAˆtØ—x‘x×'Ñ'Ó)ˆE�!ŠHð	*ð ˆ?Ø—*‘*×$Ñ$ SÓ)ˆCà�aŠxÜ Ð!DÓEÐEàˆ?Ø—*‘*×$Ñ$ SÓ)ˆCØˆ?Ø—*‘*×$Ñ$ SÓ)ˆCä/°°s·z±zØ˜ #¨f¸4ôAˆ	ð ˆà(ò 	-‰O‰FˆQ��GØ—:‘:×&Ñ& qÓ)¨3¯:©:×+>Ñ+>¸qÓ+AˆqˆAØ�M‰M˜A˜q˜6 7Ð+Õ,ð	-ð ˆøôC  ò 	ØŠIð	ús   ŽE- Å-E;Å:E;c                óà   — 	 t        | «      }t        | t         «      s!|j                  j                  st	        d«      ‚|j                  ||||||¬«      S # t
        $ r t	        d| z  «      ‚w xY w)zí
    Refine an isolating interval of a root to the given precision.

    Examples
    ========

    >>> from sympy import refine_root
    >>> from sympy.abc import x

    >>> refine_root(x**2 - 3, 1, 2, eps=1e-2)
    (19/11, 26/15)

    úgenerator must be a Symbolz,Cannot refine a root of %s, not a polynomial)r%  r:  r(  r<  )rW   rV   rÂ   Ú	is_Symbolr<   r;   r9  )r_   rš  rÛ  r%  r:  r(  r<  rÏ   s           rd   r9  r9  �  sz   € ð	@Ü�‹GˆÜ˜!œTÔ"¨1¯5©5¯?ª?ô "Ð">Ó?Ð?ð
 �=‰=˜˜A 3¨e¸$È)ˆ=ÓTÐTøô	 ò @ÜØ:¸QÑ>ó@ð 	@ð@ús   ‚<A ÁA-c                óÜ   — 	 t        | d¬«      }t        | t         «      s!|j                  j                  st	        d«      ‚|j                  ||¬«      S # t
        $ r t	        d| z  «      ‚w xY w)až  
    Return the number of roots of ``f`` in ``[inf, sup]`` interval.

    If one of ``inf`` or ``sup`` is complex, it will return the number of roots
    in the complex rectangle with corners at ``inf`` and ``sup``.

    Examples
    ========

    >>> from sympy import count_roots, I
    >>> from sympy.abc import x

    >>> count_roots(x**4 - 4, -3, 3)
    2
    >>> count_roots(x**4 - 4, 0, 1 + 3*I)
    1

    F©Úgreedyr  z*Cannot count roots of %s, not a polynomialrA  )rW   rV   rÂ   r  r<   r;   rJ  )r_   r&  r'  rÏ   s       rd   rJ  rJ  ¬  so   € ð(PÜ�˜5Ô!ˆÜ˜!œTÔ"¨1¯5©5¯?ª?ô "Ð">Ó?Ð?ð �=‰=˜S cˆ=Ó*Ð*øô ò PÜÐJÈQÑNÓOÐOðPús   ‚>A ÁA+Tc                ó‚  — 	 t        | t        «      r3|r.| j                  j                  st        | j                  d¬«      }n | }n|rt        | d¬«      }nt        | d¬«      }t        | t        «      s!|j
                  j                  st        d«      ‚|j                  ||¬«      S # t        $ r t        d| z  «      ‚w xY w)aÃ  
    Returns the real and complex roots of ``f`` with multiplicities.

    Explanation
    ===========

    Finds all real and complex roots of a univariate polynomial with rational
    coefficients of any degree exactly. The roots are represented in the form
    given by :func:`~.rootof`. This is equivalent to using :func:`~.rootof` to
    find each of the indexed roots.

    Examples
    ========

    >>> from sympy import all_roots
    >>> from sympy.abc import x, y

    >>> print(all_roots(x**3 + 1))
    [-1, 1/2 - sqrt(3)*I/2, 1/2 + sqrt(3)*I/2]

    Simple radical formulae are used in some cases but the cubic and quartic
    formulae are avoided. Instead most non-rational roots will be represented
    as :class:`~.ComplexRootOf`:

    >>> print(all_roots(x**3 + x + 1))
    [CRootOf(x**3 + x + 1, 0), CRootOf(x**3 + x + 1, 1), CRootOf(x**3 + x + 1, 2)]

    All roots of any polynomial with rational coefficients of any degree can be
    represented using :py:class:`~.ComplexRootOf`. The use of
    :py:class:`~.ComplexRootOf` bypasses limitations on the availability of
    radical formulae for quintic and higher degree polynomials _[1]:

    >>> p = x**5 - x - 1
    >>> for r in all_roots(p): print(r)
    CRootOf(x**5 - x - 1, 0)
    CRootOf(x**5 - x - 1, 1)
    CRootOf(x**5 - x - 1, 2)
    CRootOf(x**5 - x - 1, 3)
    CRootOf(x**5 - x - 1, 4)
    >>> [r.evalf(3) for r in all_roots(p)]
    [1.17, -0.765 - 0.352*I, -0.765 + 0.352*I, 0.181 - 1.08*I, 0.181 + 1.08*I]

    Irrational algebraic coefficients are handled by :func:`all_roots`
    if `extension=True` is set.

    >>> from sympy import sqrt, expand
    >>> p = expand((x - sqrt(2))*(x - sqrt(3)))
    >>> print(p)
    x**2 - sqrt(3)*x - sqrt(2)*x + sqrt(6)
    >>> all_roots(p)
    Traceback (most recent call last):
    ...
    NotImplementedError: sorted roots not supported over EX
    >>> all_roots(p, extension=True)
    [sqrt(2), sqrt(3)]

    Algebraic coefficients can be complex as well.

    >>> from sympy import I
    >>> all_roots(x**2 - I, extension=True)
    [-sqrt(2)/2 - sqrt(2)*I/2, sqrt(2)/2 + sqrt(2)*I/2]
    >>> all_roots(x**2 - sqrt(2)*I, extension=True)
    [-2**(3/4)/2 - 2**(3/4)*I/2, 2**(3/4)/2 + 2**(3/4)*I/2]

    Transcendental coefficients cannot currently be handled by
    :func:`all_roots`. In the case of algebraic or transcendental coefficients
    :func:`~.ground_roots` might be able to find some roots by factorisation:

    >>> from sympy import ground_roots
    >>> ground_roots(p, x, extension=True)
    {sqrt(2): 1, sqrt(3): 1}

    If the coefficients are numeric then :func:`~.nroots` can be used to find
    all roots approximately:

    >>> from sympy import nroots
    >>> nroots(p, 5)
    [1.4142, 1.732]

    If the coefficients are symbolic then :func:`sympy.polys.polyroots.roots`
    or :func:`~.ground_roots` should be used instead:

    >>> from sympy import roots, ground_roots
    >>> p = x**2 - 3*x*y + 2*y**2
    >>> roots(p, x)
    {y: 1, 2*y: 1}
    >>> ground_roots(p, x)
    {y: 1, 2*y: 1}

    Parameters
    ==========

    f : :class:`~.Expr` or :class:`~.Poly`
        A univariate polynomial with rational (or ``Float``) coefficients.
    multiple : ``bool`` (default ``True``).
        Whether to return a ``list`` of roots or a list of root/multiplicity
        pairs.
    radicals : ``bool`` (default ``True``)
        Use simple radical formulae rather than :py:class:`~.ComplexRootOf` for
        some irrational roots.
    extension: ``bool`` (default ``False``)
        Whether to construct an algebraic extension domain before computing
        the roots. Setting to ``True`` is necessary for finding roots of a
        polynomial with (irrational) algebraic coefficients but can be slow.

    Returns
    =======

    A list of :class:`~.Expr` (usually :class:`~.ComplexRootOf`) representing
    the roots is returned with each root repeated according to its multiplicity
    as a root of ``f``. The roots are always uniquely ordered with real roots
    coming before complex roots. The real roots are in increasing order.
    Complex roots are ordered by increasing real part and then increasing
    imaginary part.

    If ``multiple=False`` is passed then a list of root/multiplicity pairs is
    returned instead.

    If ``radicals=False`` is passed then all roots will be represented as
    either rational numbers or :class:`~.ComplexRootOf`.

    See also
    ========

    Poly.all_roots:
        The underlying :class:`Poly` method used by :func:`~.all_roots`.
    rootof:
        Compute a single numbered root of a univariate polynomial.
    real_roots:
        Compute all the real roots using :func:`~.rootof`.
    ground_roots:
        Compute some roots in the ground domain by factorisation.
    nroots:
        Compute all roots using approximate numerical techniques.
    sympy.polys.polyroots.roots:
        Compute symbolic expressions for roots using radical formulae.

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Abel%E2%80%93Ruffini_theorem
    T©Ú	extensionFr  r  ú1Cannot compute real roots of %s, not a polynomial©rU  rM  )
rV   rW   rS   r…  rŒ   rÂ   r  r<   r;   rZ  ©r_   rU  rM  r  rÏ   s        rd   rZ  rZ  Í  s³   € ð`EÜ�aœÔÙ §¡×!;Ò!;Ü˜Ÿ™¨4Ô0‘à‘áÜ˜ dÔ+‘ä˜ 5Ô)�ä˜!œTÔ"¨1¯5©5¯?ª?ô "Ð">Ó?Ð?ð
 �;‰; °8ˆ;Ó<Ð<øô	 ò EÜØ?À!ÑCóEð 	EðEúó   ‚BB& Â&B>c                ó‚  — 	 t        | t        «      r3|r.| j                  j                  st        | j                  d¬«      }n | }n|rt        | d¬«      }nt        | d¬«      }t        | t        «      s!|j
                  j                  st        d«      ‚|j                  ||¬«      S # t        $ r t        d| z  «      ‚w xY w)ax  
    Returns the real roots of ``f`` with multiplicities.

    Explanation
    ===========

    Finds all real roots of a univariate polynomial with rational coefficients
    of any degree exactly. The roots are represented in the form given by
    :func:`~.rootof`. This is equivalent to using :func:`~.rootof` or
    :func:`~.all_roots` and filtering out only the real roots. However if only
    the real roots are needed then :func:`real_roots` is more efficient than
    :func:`~.all_roots` because it computes only the real roots and avoids
    costly complex root isolation routines.

    Examples
    ========

    >>> from sympy import real_roots
    >>> from sympy.abc import x, y

    >>> real_roots(2*x**3 - 7*x**2 + 4*x + 4)
    [-1/2, 2, 2]
    >>> real_roots(2*x**3 - 7*x**2 + 4*x + 4, multiple=False)
    [(-1/2, 1), (2, 2)]

    Real roots of any polynomial with rational coefficients of any degree can
    be represented using :py:class:`~.ComplexRootOf`:

    >>> p = x**9 + 2*x + 2
    >>> print(real_roots(p))
    [CRootOf(x**9 + 2*x + 2, 0)]
    >>> [r.evalf(3) for r in real_roots(p)]
    [-0.865]

    All rational roots will be returned as rational numbers. Roots of some
    simple factors will be expressed using radical or other formulae (unless
    ``radicals=False`` is passed). All other roots will be expressed as
    :class:`~.ComplexRootOf`.

    >>> p = (x + 7)*(x**2 - 2)*(x**3 + x + 1)
    >>> print(real_roots(p))
    [-7, -sqrt(2), CRootOf(x**3 + x + 1, 0), sqrt(2)]
    >>> print(real_roots(p, radicals=False))
    [-7, CRootOf(x**2 - 2, 0), CRootOf(x**3 + x + 1, 0), CRootOf(x**2 - 2, 1)]

    All returned root expressions will numerically evaluate to real numbers
    with no imaginary part. This is in contrast to the expressions generated by
    the cubic or quartic formulae as used by :func:`~.roots` which suffer from
    casus irreducibilis [1]_:

    >>> from sympy import roots
    >>> p = 2*x**3 - 9*x**2 - 6*x + 3
    >>> [r.evalf(5) for r in roots(p, multiple=True)]
    [5.0365 - 0.e-11*I, 0.33984 + 0.e-13*I, -0.87636 + 0.e-10*I]
    >>> [r.evalf(5) for r in real_roots(p, x)]
    [-0.87636, 0.33984, 5.0365]
    >>> [r.is_real for r in roots(p, multiple=True)]
    [None, None, None]
    >>> [r.is_real for r in real_roots(p)]
    [True, True, True]

    Using :func:`real_roots` is equivalent to using :func:`~.all_roots` (or
    :func:`~.rootof`) and filtering out only the real roots:

    >>> from sympy import all_roots
    >>> r = [r for r in all_roots(p) if r.is_real]
    >>> real_roots(p) == r
    True

    If only the real roots are wanted then using :func:`real_roots` is faster
    than using :func:`~.all_roots`. Using :func:`real_roots` avoids complex root
    isolation which can be a lot slower than real root isolation especially for
    polynomials of high degree which typically have many more complex roots
    than real roots.

    Irrational algebraic coefficients are handled by :func:`real_roots`
    if `extension=True` is set.

    >>> from sympy import sqrt, expand
    >>> p = expand((x - sqrt(2))*(x - sqrt(3)))
    >>> print(p)
    x**2 - sqrt(3)*x - sqrt(2)*x + sqrt(6)
    >>> real_roots(p)
    Traceback (most recent call last):
    ...
    NotImplementedError: sorted roots not supported over EX
    >>> real_roots(p, extension=True)
    [sqrt(2), sqrt(3)]

    Transcendental coefficients cannot currently be handled by
    :func:`real_roots`. In the case of algebraic or transcendental coefficients
    :func:`~.ground_roots` might be able to find some roots by factorisation:

    >>> from sympy import ground_roots
    >>> ground_roots(p, x, extension=True)
    {sqrt(2): 1, sqrt(3): 1}

    If the coefficients are numeric then :func:`~.nroots` can be used to find
    all roots approximately:

    >>> from sympy import nroots
    >>> nroots(p, 5)
    [1.4142, 1.732]

    If the coefficients are symbolic then :func:`sympy.polys.polyroots.roots`
    or :func:`~.ground_roots` should be used instead.

    >>> from sympy import roots, ground_roots
    >>> p = x**2 - 3*x*y + 2*y**2
    >>> roots(p, x)
    {y: 1, 2*y: 1}
    >>> ground_roots(p, x)
    {y: 1, 2*y: 1}

    Parameters
    ==========

    f : :class:`~.Expr` or :class:`~.Poly`
        A univariate polynomial with rational (or ``Float``) coefficients.
    multiple : ``bool`` (default ``True``).
        Whether to return a ``list`` of roots or a list of root/multiplicity
        pairs.
    radicals : ``bool`` (default ``True``)
        Use simple radical formulae rather than :py:class:`~.ComplexRootOf` for
        some irrational roots.
    extension: ``bool`` (default ``False``)
        Whether to construct an algebraic extension domain before computing
        the roots. Setting to ``True`` is necessary for finding roots of a
        polynomial with (irrational) algebraic coefficients but can be slow.

    Returns
    =======

    A list of :class:`~.Expr` (usually :class:`~.ComplexRootOf`) representing
    the real roots is returned. The roots are arranged in increasing order and
    are repeated according to their multiplicities as roots of ``f``.

    If ``multiple=False`` is passed then a list of root/multiplicity pairs is
    returned instead.

    If ``radicals=False`` is passed then all roots will be represented as
    either rational numbers or :class:`~.ComplexRootOf`.

    See also
    ========

    Poly.real_roots:
        The underlying :class:`Poly` method used by :func:`real_roots`.
    rootof:
        Compute a single numbered root of a univariate polynomial.
    all_roots:
        Compute all real and non-real roots using :func:`~.rootof`.
    ground_roots:
        Compute some roots in the ground domain by factorisation.
    nroots:
        Compute all roots using approximate numerical techniques.
    sympy.polys.polyroots.roots:
        Compute symbolic expressions for roots using radical formulae.

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Casus_irreducibilis
    Tr  Fr  r  r  r   )
rV   rW   rS   r…  rŒ   rÂ   r  r<   r;   rW  r!  s        rd   rW  rW  u  s³   € ðLEÜ�aœÔÙ §¡×!;Ò!;Ü˜Ÿ™¨4Ô0‘à‘áÜ˜ dÔ+‘ä˜ 5Ô)�ä˜!œTÔ"¨1¯5©5¯?ª?ô "Ð">Ó?Ð?ð
 �<‰< °Hˆ<Ó=Ð=øô	 ò EÜØ?À!ÑCóEð 	EðEúr"  c                óÞ   — 	 t        | d¬«      }t        | t         «      s!|j                  j                  st	        d«      ‚|j                  |||¬«      S # t
        $ r t	        d| z  «      ‚w xY w)aL  
    Compute numerical approximations of roots of ``f``.

    Examples
    ========

    >>> from sympy import nroots
    >>> from sympy.abc import x

    >>> nroots(x**2 - 3, n=15)
    [-1.73205080756888, 1.73205080756888]
    >>> nroots(x**2 - 3, n=30)
    [-1.73205080756887729352744634151, 1.73205080756887729352744634151]

    Fr  r  z6Cannot compute numerical roots of %s, not a polynomial)r*  r_  r`  )rW   rV   rÂ   r  r<   r;   ry  )r_   r*  r_  r`  rÏ   s        rd   ry  ry  3  sw   € ð"	JÜ�˜5Ô!ˆÜ˜!œTÔ"¨1¯5©5¯?ª?ô "Ð">Ó?Ð?ð
 �8‰8�a (°Gˆ8Ó<Ð<øô	 ò JÜØDÀqÑHóJð 	JðJús   ‚>A ÁA,c                ó  — t        j                  |g «       	 t        | g|¢­i |¤Ž\  }}t        | t        «      s!|j
                  j                  st        d«      ‚|j                  «       S # t        $ r}t        dd|«      ‚d}~ww xY w)zñ
    Compute roots of ``f`` by factorization in the ground domain.

    Examples
    ========

    >>> from sympy import ground_roots
    >>> from sympy.abc import x

    >>> ground_roots(x**6 - 4*x**4 + 4*x**3 - x**2)
    {0: 2, 1: 2}

    r  r}  r‚   N)ro   r^  r<  rV   rW   rÂ   r  r<   r?   r@   r}  ra  s         rd   r}  r}  R  sƒ   € ô ×Ñ˜$ Ô#ð8Ü Ð1 DÒ1¨DÑ1‰ˆˆ3Ü˜!œTÔ"¨1¯5©5¯?ª?ô "Ð">Ó?Ð?ð �>‰>ÓÐøô ò 8Ü °°3Ó7Ð7ûð8ús   ˜AA+ Á+	BÁ4BÂBc                óP  — t        j                  |g «       	 t        | g|¢­i |¤Ž\  }}t        | t        «      s!|j
                  j                  st        d«      ‚|j                  |«      }|j                  s|j                  «       S |S # t        $ r}t        dd|«      ‚d}~ww xY w)a¦  
    Construct a polynomial with n-th powers of roots of ``f``.

    Examples
    ========

    >>> from sympy import nth_power_roots_poly, factor, roots
    >>> from sympy.abc import x

    >>> f = x**4 - x**2 + 1
    >>> g = factor(nth_power_roots_poly(f, 2))

    >>> g
    (x**2 - x + 1)**2

    >>> R_f = [ (r**2).expand() for r in roots(f) ]
    >>> R_g = roots(g).keys()

    >>> set(R_f) == set(R_g)
    True

    r  r€  r‚   N)ro   r^  r<  rV   rW   rÂ   r  r<   r?   r@   r€  rO  r]   )r_   r*  rY   r~   rÏ   r   r|  rb   s           rd   r€  r€  p  s£   € ô0 ×Ñ˜$ Ô#ð@Ü Ð1 DÒ1¨DÑ1‰ˆˆ3Ü˜!œTÔ"¨1¯5©5¯?ª?ô "Ð">Ó?Ð?ð ×#Ñ# AÓ&€Fà�9Š9Ø�~‰~ÓÐàˆøô ò @ÜÐ 6¸¸3Ó?Ð?ûð@ús   ˜AB
 Â
	B%ÂB Â B%)Ú	_signsimpc               óž  ‡— ddl m} ddlm} t	        j
                  |dg«       t        | «      } |r || «      } i }d|v r|d   |d<   t        | t        «      sO| j                  s t        | t        «      st        | t        «      s| S t        | d¬«      } | j                  «       \  }}n•t        | «      dk(  ry| \  }}t        |t        «      rCt        |t        «      r3|j                   |d<   |j"                  |d	<   |j%                  dd«      |d<   |j'                  «       |j'                  «       }}nt)        d
| z  «      ‚ddlmŠ 	 | j/                  ‰«      r
t1        «       ‚ |||fg|¢­i |¤Ž\  }	\  }
}|	j2                  s3t        | t        «      s| j5                  «       S t6        j8                  ||fS 	 d|
jE                  |«      c}\  }}|j%                  dd«      rd|vr|	jX                  |d<   t        | t        «      s$||j'                  «       |j'                  «       z  z  S |j'                  «       |j'                  «       }}|j%                  dd«      s|||fS |t        |g|¢­i |¤Žt        |g|¢­i |¤ŽfS # t0        $ �rJ}| j:                  r| j/                  ‰«      st1        |«      ‚| j<                  s| j>                  rjtA        | jB                  ˆfd„d¬«      \  }}|D �cg c]  }tE        |«      ‘Œ nc c}w }} | jF                  tE         | jF                  |Ž «      g|¢­Ž cY d}~S g }tI        | «      }tK        |«       |D ]_  }t        |tL        «      st        |t        «      sŒ$	 |jO                  |tE        |«      f«       |jQ                  «        ŒR# tR        $ r Y Œ]w xY w | jU                  tW        |«      «      cY d}~S d}~ww xY w)a[  
    Cancel common factors in a rational function ``f``.

    Examples
    ========

    >>> from sympy import cancel, sqrt, Symbol, together
    >>> from sympy.abc import x
    >>> A = Symbol('A', commutative=False)

    >>> cancel((2*x**2 - 2)/(x**2 - 2*x + 1))
    (2*x + 2)/(x - 1)
    >>> cancel((sqrt(3) + sqrt(15)*A)/(sqrt(2) + sqrt(10)*A))
    sqrt(6)/2

    Note: due to automatic distribution of Rationals, a sum divided by an integer
    will appear as a sum. To recover a rational form use `together` on the result:

    >>> cancel(x/2 + 1)
    x/2 + 1
    >>> together(_)
    (x + 2)/2
    r   )Úsignsimp)ÚsringrO  T)ÚradicalrŒ  rY   rS   zunexpected argument: %srF  c                óH   •— | j                   du xr | j                  ‰«       S r   )r)  Úhas)r  rG  s    €rd   ri  zcancel.<locals>.<lambda>ß  s'   ø€ Ø× Ñ  DÐ(ÒA°·±°yÓ1AÐ-Að rg   rò  Nr‚   F)-r   r)  Úsympy.polys.ringsr*  ro   r^  r%   rV   r   rV  r    r   r   r–  r„   rW   rY   rS   rÉ  r]   r  rI  rG  r-  r<   Úngensr>  r   r¾  r)  rô  r  rO   r~   r¢  rc   r'   rX  r)   rH  Úskiprq   r  rt   r»   )r_   r'  rY   r~   r)  r*  r   rø  rt  rƒ  rÏ   rÐ   Úmsgrâ   Úncr¼   rP  ÚpotÚer  r‚  rG  s                        @rd   r¢  r¢  œ  sV  ø€ õ2 1Ý'Ü×Ñ˜$  	Ô*ä�‹
€AÙÙ�Q‹KˆØ
€CØ�$�Ø˜G‘}ˆˆG‰ä�aœÔØ�;Š;œ* Q¬
Ô3¼:ÀaÌÔ;NØˆHÜ˜ DÔ)ˆØ×ÑÓ!‰ˆ‰1ä	ˆQ‹�1ŠØ‰ˆˆ1Ü�aœÔ¤:¨a´Ô#6ØŸ&™&ˆC�‰KØŸH™HˆC�‰MØŸ7™7 7¨DÓ1ˆC�‰LØ�y‰y‹{˜AŸI™I›Kˆ1‰äÐ2°QÑ6Ó7Ð7å>ð*Ø�5‰5�ÔÜ!Ó#Ð#Ù˜1˜a˜&Ð0 4Ò0¨4Ñ0‰	ˆ‰6ˆAˆqØ�wŠwÜ˜a¤Ô'Ø—x‘x“zÐ!ä—u‘u˜a �{Ð"ð	 ð: �1—8‘8˜A“;€I€A�vˆˆ1Ø
‡w�wˆw˜Ô 6°Ñ#4Ø—i‘iˆˆF‰ä�aœÔØ�!—)‘)“+˜aŸi™i›kÑ)Ñ*Ð*à�y‰y‹{˜AŸI™I›Kˆ1ˆØ�w‰w�w Ô&Ø�a˜�7ˆNà”d˜1Ð+˜tÒ+ sÑ+¬T°!Ð-B°dÒ-B¸cÑ-BÐBÐBøôG ó *Ø×Ò A§E¡E¨)Ô$4Ü! #Ó&Ð&à�8Š8�q—x’xÜ˜Ÿ™ó "Bàô‰EˆAˆrð &(Ö( ”&˜•)Ñ(ùÒ(ˆBÐ(Ø�1—6‘6œ&  §¡¨ Ó,Ð2¨rÒ2Õ2àˆDÜ$ QÓ'ˆCÜ�ŒIØò �Ü˜a¤Ô-´ZÀÄ4Ô5HØðØ—K‘K ¤F¨1£I Ô/Ø—H‘H•JøÜ*ò Ùðúðð —:‘:œd 4›jÓ)Õ)ûð-*úsb   ÅAI8 ÆI8 É8
OÊA"OË$K7Ë60OÌ&OÌ,>OÍ+,NÎOÎ	N$Î!OÎ#N$Î$OÏOÏOc                óZ  — t        j                  |ddg«       	 t        | gt        |«      z   g|¢­i |¤Ž\  }}|j                  }d}|j                  r;|j                  r/|j                  s#|j                  d|j                  «       i«      }d}dd	lm}	  |	|j                  |j                  |j                  «      \  }
}t!        |«      D ]L  \  }}|j#                  |j                  «      j$                  j'                  «       }|
j)                  |«      ||<   ŒN |d   j+                  |d
d «      \  }}|D �cg c]!  }t,        j/                  t1        |«      |«      ‘Œ# }}t,        j/                  t1        |«      |«      }|r3	 |D �cg c]  }|j3                  «       ‘Œ c}|j3                  «       }}||}}|j6                  s.|D �cg c]  }|j9                  «       ‘Œ c}|j9                  «       fS ||fS # t        $ r}t        dd|«      ‚d}~ww xY wc c}w c c}w # t4        $ r Y Œqw xY wc c}w )a<  
    Reduces a polynomial ``f`` modulo a set of polynomials ``G``.

    Given a polynomial ``f`` and a set of polynomials ``G = (g_1, ..., g_n)``,
    computes a set of quotients ``q = (q_1, ..., q_n)`` and the remainder ``r``
    such that ``f = q_1*g_1 + ... + q_n*g_n + r``, where ``r`` vanishes or ``r``
    is a completely reduced polynomial with respect to ``G``.

    Examples
    ========

    >>> from sympy import reduced
    >>> from sympy.abc import x, y

    >>> reduced(2*x**4 + y**2 - x**2 + y**3, [x**3 - x, y**3 - y])
    ([2*x, 1], x**2 + y**2 + y)

    rO  r�  Úreducedr   NFrS   T©Úxringr‚   )ro   r^  rD  rw   r?   r@   rS   r�  r  r€  rÜ  r™  r.  r8  rY   rl   rú   r«   rj   rÝ   r’   r~  rW   ru   rt   r  r9   rO  r]   )r_   rÐ   rY   r~   rO  r   r|  rS   r%  r8  Ú_ringrÍ   r¼   rD  r‚  ru  rt  Ú_QÚ_rs                      rd   r6  r6     sê  € ô( ×Ñ˜$ ¨&Ð 1Ô2ð3Ü,¨a¨S´4¸³7©]ÐJ¸TÒJÀTÑJ‰
ˆˆsð �Z‰Z€FØ€Gà
‡x‚x�F—N’N¨6¯?ª?Ø�i‰i˜ 6×#3Ñ#3Ó#5Ð6Ó7ˆØˆå'Ù�S—X‘X˜sŸz™z¨3¯9©9Ó5�H€Eˆ1ä˜UÓ#ò )‰ˆˆ4Ø�‰˜sŸz™zÓ*×.Ñ.×6Ñ6Ó8ˆØ—?‘? 4Ó(ˆˆaŠð)ð �‰8�<‰<˜˜a˜b˜	Ó"�D€A€qà01Ö2¨1Œ�‰œ˜a› #Õ	&Ð2€AÐ2Ü�‰œ˜Q› Ó%€Aáð	Ø+,Ö- a�a—i‘i•kÒ-¨q¯y©y«{�ˆBð �rˆqˆAà�9Š9Ø%&Ö' �—	‘	•Ò'¨¯©«Ð4Ð4à�!ˆtˆøôC ò 3Ü 	¨1¨cÓ2Ð2ûð3üò& 	3ùò
 .øÜò 	Ùð	üò (sG   šG1 Ä7&HÆH ÆHÆH ÇH(Ç1	HÇ:HÈHÈH È	H%È$H%c                ó    — t        | g|¢­i |¤ŽS )a‚  
    Computes the reduced Groebner basis for a set of polynomials.

    Use the ``order`` argument to set the monomial ordering that will be
    used to compute the basis. Allowed orders are ``lex``, ``grlex`` and
    ``grevlex``. If no order is specified, it defaults to ``lex``.

    For more information on Groebner bases, see the references and the docstring
    of :func:`~.solve_poly_system`.

    Examples
    ========

    Example taken from [1].

    >>> from sympy import groebner
    >>> from sympy.abc import x, y

    >>> F = [x*y - 2*y, 2*y**2 - x**2]

    >>> groebner(F, x, y, order='lex')
    GroebnerBasis([x**2 - 2*y**2, x*y - 2*y, y**3 - 2*y], x, y,
                  domain='ZZ', order='lex')
    >>> groebner(F, x, y, order='grlex')
    GroebnerBasis([y**3 - 2*y, x**2 - 2*y**2, x*y - 2*y], x, y,
                  domain='ZZ', order='grlex')
    >>> groebner(F, x, y, order='grevlex')
    GroebnerBasis([y**3 - 2*y, x**2 - 2*y**2, x*y - 2*y], x, y,
                  domain='ZZ', order='grevlex')

    By default, an improved implementation of the Buchberger algorithm is
    used. Optionally, an implementation of the F5B algorithm can be used. The
    algorithm can be set using the ``method`` flag or with the
    :func:`sympy.polys.polyconfig.setup` function.

    >>> F = [x**2 - x - 1, (2*x - 1) * y - (x**10 - (1 - x)**10)]

    >>> groebner(F, x, y, method='buchberger')
    GroebnerBasis([x**2 - x - 1, y - 55], x, y, domain='ZZ', order='lex')
    >>> groebner(F, x, y, method='f5b')
    GroebnerBasis([x**2 - x - 1, y - 55], x, y, domain='ZZ', order='lex')

    References
    ==========

    1. [Buchberger01]_
    2. [Cox97]_

    )ÚGroebnerBasis©rÏ   rY   r~   s      rd   r1   r1   <  s   € ôf ˜Ð*˜TÒ* TÑ*Ð*rg   c                ó4   — t        | g|¢­i |¤Žj                  S )a[  
    Checks if the ideal generated by a Groebner basis is zero-dimensional.

    The algorithm checks if the set of monomials not divisible by the
    leading monomial of any element of ``F`` is bounded.

    References
    ==========

    David A. Cox, John B. Little, Donal O'Shea. Ideals, Varieties and
    Algorithms, 3rd edition, p. 230

    )r=  Úis_zero_dimensionalr>  s      rd   r@  r@  r  s   € ô ˜Ð*˜TÒ* TÑ*×>Ñ>Ð>rg   c                  óÎ   — e Zd ZdZd„ Zed„ «       Zed„ «       Zed„ «       Z	ed„ «       Z
ed„ «       Zed„ «       Zed	„ «       Zd
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zed„ «       Zd„ Zdd„Zd„ Zy)r=  z%Represents a reduced Groebner basis. c                ó"  — t        j                  |ddg«       	 t        |g|¢­i |¤Ž\  }}ddlm}  ||j                  |j                  |j                  «      }|D �	cg c].  }	|	sŒ|j                  |	j                  j                  «       «      ‘Œ0 }}	t        |||j                  ¬«      }
|
D �cg c]  }t         j#                  ||«      ‘Œ }
}| j%                  |
|«      S # t        $ r}t	        dt        |«      |«      ‚d}~ww xY wc c}	w c c}w )z>Compute a reduced Groebner basis for a system of polynomials. rO  rÅ  r1   Nr   )ÚPolyRingr	  )ro   r^  rD  r?   r@   r„   r.  rC  rY   rS   rl   r’   rj   rÝ   Ú	_groebnerrÅ  rW   ru   Ú_new)r}   rÏ   rY   r~   rO  r   r|  rC  ÚringrD  rÐ   r`   s               rd   r€   zGroebnerBasis.__new__ˆ  sî   € ä×Ñ˜d W¨hÐ$7Ô8ð	=Ü0°ÐB°TÒB¸TÑB‰JˆE�3õ 	/Ù˜Ÿ™ #§*¡*¨c¯i©iÓ8ˆà@EÖN¸Ê�—‘ §¡× 0Ñ 0Ó 2Õ3ÐNˆÐNä�e˜T¨#¯*©*Ô5ˆØ./Ö0¨ŒT�_‰_˜Q Õ$Ð0ˆÐ0à�x‰x˜˜3ÓÐøô "ò 	=Ü# J´°A³¸Ó<Ð<ûð	=üò Oùò 1s)   šC  ÁDÁ&+DÂ/DÃ 	DÃ)C?Ã?Dc                ó^   — t        j                  | «      }t        |«      |_        ||_        |S rˆ   )r   r€   r7  Ú_basisÚ_options)r}   Úbasisro   r…   s       rd   rE  zGroebnerBasis._new›  s'   € ä�m‰m˜CÓ ˆä˜5“\ˆŒ
ØˆŒàˆ
rg   c                óp   — d„ | j                   D «       }t        |Ž t        | j                  j                  Ž fS )Nc              3  ó<   K  — | ]  }|j                  «       –— Œ y ­wrˆ   r  )r‰  rø  s     rd   rŠ  z%GroebnerBasis.args.<locals>.<genexpr>¦  s   è ø€ Ò2 �—‘—Ñ2ùs   ‚)rH  r   rI  rY   )r‹   rJ  s     rd   r~   zGroebnerBasis.args¤  s.   € á2 d§k¡kÔ2ˆÜ�u�œu d§m¡m×&8Ñ&8Ð9Ð:Ð:rg   c                ó\   — | j                   D �cg c]  }|j                  «       ‘Œ c}S c c}w rˆ   )rH  r]   ©r‹   rD  s     rd   rC  zGroebnerBasis.exprs©  s    € à+/¯;©;Ö7 4�—‘•Ò7Ð7ùÒ7s   �)c                ó,   — t        | j                  «      S rˆ   )rw   rH  rŠ   s    rd   rO  zGroebnerBasis.polys­  s   € ä�D—K‘KÓ Ð rg   c                ó.   — | j                   j                  S rˆ   )rI  rY   rŠ   s    rd   rY   zGroebnerBasis.gens±  s   € à�}‰}×!Ñ!Ð!rg   c                ó.   — | j                   j                  S rˆ   )rI  rS   rŠ   s    rd   rS   zGroebnerBasis.domainµ  s   € à�}‰}×#Ñ#Ð#rg   c                ó.   — | j                   j                  S rˆ   )rI  rl   rŠ   s    rd   rl   zGroebnerBasis.order¹  s   € à�}‰}×"Ñ"Ð"rg   c                ó,   — t        | j                  «      S rˆ   )r„   rH  rŠ   s    rd   Ú__len__zGroebnerBasis.__len__½  s   € Ü�4—;‘;ÓÐrg   c                ó‚   — | j                   j                  rt        | j                  «      S t        | j                  «      S rˆ   )rI  rO  ÚiterrC  rŠ   s    rd   rš  zGroebnerBasis.__iter__À  s-   € Ø�=‰=×ÒÜ˜Ÿ
™
Ó#Ð#ä˜Ÿ
™
Ó#Ð#rg   c                ór   — | j                   j                  r| j                  }||   S | j                  }||   S rˆ   )rI  rO  rC  )r‹   ÚitemrJ  s      rd   Ú__getitem__zGroebnerBasis.__getitem__Æ  s9   € Ø�=‰=×ÒØ—J‘JˆEð �T‰{Ðð —J‘JˆEà�T‰{Ðrg   c                ór   — t        | j                  t        | j                  j	                  «       «      f«      S rˆ   )ÚhashrH  r7  rI  rŸ   rŠ   s    rd   r³   zGroebnerBasis.__hash__Î  s(   € Ü�T—[‘[¤%¨¯©×(;Ñ(;Ó(=Ó">Ð?Ó@Ð@rg   c                ó  — t        || j                  «      r4| j                  |j                  k(  xr | j                  |j                  k(  S t	        |«      r2| j
                  t        |«      k(  xs | j                  t        |«      k(  S y)NF)rV   r§   rH  rI  rN   rO  rw   rC  ©r‹   r
  s     rd   r  zGroebnerBasis.__eq__Ñ  sd   € Ü�e˜TŸ^™^Ô,Ø—;‘; %§,¡,Ñ.ÒR°4·=±=ÀEÇNÁNÑ3RÐRÜ�eŒ_Ø—:‘:¤ e£Ñ,ÒI°·
±
¼dÀ5»kÑ0IÐIàrg   c                ó   — | |k(   S rˆ   r  r]  s     rd   r  zGroebnerBasis.__ne__Ù  s   € Ø˜5‘=Ð Ð rg   c                óð   — d„ }t        dgt        | j                  «      z  «      }| j                  j                  }| j
                  D ]"  }|j                  |¬«      } ||«      sŒ||z  }Œ$ t        |«      S )a{  
        Checks if the ideal generated by a Groebner basis is zero-dimensional.

        The algorithm checks if the set of monomials not divisible by the
        leading monomial of any element of ``F`` is bounded.

        References
        ==========

        David A. Cox, John B. Little, Donal O'Shea. Ideals, Varieties and
        Algorithms, 3rd edition, p. 230

        c                ó:   — t        t        t        | «      «      dk(  S r¯   )Úsumr¥   rK  )Úmonomials    rd   Ú
single_varz5GroebnerBasis.is_zero_dimensional.<locals>.single_varë  s   € Ü”sœ4 Ó*Ó+¨qÑ0Ð0rg   r   r,  )r2   r„   rY   rI  rl   rO  r®  r  )r‹   rc  r¥  rl   rD  rb  s         rd   r@  z!GroebnerBasis.is_zero_dimensionalÜ  sr   € ò	1ô ˜a˜S¤ T§Y¡Y£Ñ/Ó0ˆ	Ø—‘×#Ñ#ˆà—J‘Jò 	&ˆDØ—w‘w U�wÓ+ˆHá˜(Õ#Ø˜XÑ%‘	ð		&ô �9‹~Ðrg   c                ó   — | j                   }|j                  }t        |«      }||k(  r| S | j                  st	        d«      ‚t        | j                  «      }|j                  }|j                  |j                  «       |dœ«      }ddl
m}  ||j                  |j                  |«      \  }}	t        |«      D ]L  \  }
}|j                  |j                  «      j                  j!                  «       }|j#                  |«      ||
<   ŒN t%        |||«      }|D �cg c]!  }t&        j)                  t+        |«      |«      ‘Œ# }}|j,                  s)|D �cg c]  }|j/                  d¬«      d   ‘Œ }}||_        | j1                  ||«      S c c}w c c}w )aÙ  
        Convert a Groebner basis from one ordering to another.

        The FGLM algorithm converts reduced Groebner bases of zero-dimensional
        ideals from one ordering to another. This method is often used when it
        is infeasible to compute a Groebner basis with respect to a particular
        ordering directly.

        Examples
        ========

        >>> from sympy.abc import x, y
        >>> from sympy import groebner

        >>> F = [x**2 - 3*y - x + 1, y**2 - 2*x + y - 1]
        >>> G = groebner(F, x, y, order='grlex')

        >>> list(G.fglm('lex'))
        [2*x - y**2 - y + 1, y**4 + 2*y**3 - 3*y**2 - 16*y + 7]
        >>> list(groebner(F, x, y, order='lex'))
        [2*x - y**2 - y + 1, y**4 + 2*y**3 - 3*y**2 - 16*y + 7]

        References
        ==========

        .. [1] J.C. Faugere, P. Gianni, D. Lazard, T. Mora (1994). Efficient
               Computation of Zero-dimensional Groebner Bases by Change of
               Ordering

        z?Cannot convert Groebner bases of ideals with positive dimension)rS   rl   r   r7  TrÂ  r‚   )rI  rl   r3   r@  rq   rw   rH  rS   rÜ  r™  r.  r8  rY   rú   r«   rj   rÝ   r’   r0   rW   ru   rt   r€  r½  rE  )r‹   rl   r   Ú	src_orderÚ	dst_orderrO  rS   r8  r9  rÍ   r¼   rD  rÐ   r`   s                 rd   ÚfglmzGroebnerBasis.fglmü  sc  € ð> �m‰mˆà—I‘Iˆ	Ü  Ó'ˆ	à˜	Ò!ØˆKà×'Ò'Ü%Ð&gÓhÐhä�T—[‘[Ó!ˆØ—‘ˆà�i‰iØ×&Ñ&Ó(Øñ
ó ˆõ
 	,Ù˜Ÿ™ 3§:¡:¨yÓ9‰ˆˆqä  Ó'ò 	-‰GˆAˆtØ—?‘? 3§:¡:Ó.×2Ñ2×:Ñ:Ó<ˆDØ—‘ tÓ,ˆE�!ŠHð	-ô ˜˜u iÓ0ˆØ45Ö6¨qŒT�_‰_œT !›W cÕ*Ð6ˆÐ6à�ŠØ:;Ö<°Q�—‘¨�Ó-¨aÓ0Ð<ˆAÐ<ØˆCŒJà�y‰y˜˜CÓ Ð ùò 7ùò =s   Ä&FÅFc                óì  — t        |t        «      rT|j                  | j                  j                  k7  rt	        d«      ‚|j                  | j                  j                  «      }n t        j                  || j                  «      }|gt        | j                  «      z   }| j                  }|j                  }d}|r;|j                  r/|j                  s#|j                  d|j                  «       i«      }d}ddlm}  ||j                  |j                  |j                   «      \  }	}
t#        |«      D ]L  \  }}|j                  |j                  «      j$                  j'                  «       }|	j)                  |«      ||<   ŒN |d   j+                  |dd «      \  }}|D �cg c]!  }t        j-                  t/        |«      |«      ‘Œ# }}t        j-                  t/        |«      |«      }|r3	 |D �cg c]  }|j1                  «       ‘Œ c}|j1                  «       }}||}}|j4                  s.|D �cg c]  }|j7                  «       ‘Œ c}|j7                  «       fS ||fS c c}w c c}w # t2        $ r Y ŒSw xY wc c}w )	a0  
        Reduces a polynomial modulo a Groebner basis.

        Given a polynomial ``f`` and a set of polynomials ``G = (g_1, ..., g_n)``,
        computes a set of quotients ``q = (q_1, ..., q_n)`` and the remainder ``r``
        such that ``f = q_1*f_1 + ... + q_n*f_n + r``, where ``r`` vanishes or ``r``
        is a completely reduced polynomial with respect to ``G``.

        Examples
        ========

        >>> from sympy import groebner, expand, Poly
        >>> from sympy.abc import x, y

        >>> f = 2*x**4 - x**2 + y**3 + y**2
        >>> G = groebner([x**3 - x, y**3 - y])

        >>> G.reduce(f)
        ([2*x, 1], x**2 + y**2 + y)
        >>> Q, r = _

        >>> expand(sum(q*g for q, g in zip(Q, G)) + r)
        2*x**4 - x**2 + y**3 + y**2
        >>> _ == f
        True

        # Using Poly input
        >>> f_poly = Poly(f, x, y)
        >>> G = groebner([Poly(x**3 - x), Poly(y**3 - y)])

        >>> G.reduce(f_poly)
        ([Poly(2*x, x, y, domain='ZZ'), Poly(1, x, y, domain='ZZ')], Poly(x**2 + y**2 + y, x, y, domain='ZZ'))

        z;Polynomial generators don't match Groebner basis generatorsFrS   Tr   r7  r‚   N)rV   rW   rY   rI  r  r«   rS   r{   rw   rH  r  r€  rÜ  r™  r.  r8  rl   rú   rj   rÝ   r’   r~  ru   rt   r  r9   rO  r]   )r‹   rŒ   r�  rD  rO  r   rS   r%  r8  r9  rÍ   r¼   r‚  ru  rt  r:  r;  s                    rd   r   zGroebnerBasis.reduce>  s   € ôF �dœDÔ!à�y‰y˜DŸM™M×.Ñ.Ò.Ü Ð!^Ó_Ð_Ø—?‘? 4§=¡=×#7Ñ#7Ó8‰Dô —?‘? 4¨¯©Ó7ˆDà�œ˜dŸk™kÓ*Ñ*ˆà�m‰mˆØ—‘ˆàˆá�F—N’N¨6¯?ª?Ø—)‘)˜X v×'7Ñ'7Ó'9Ð:Ó;ˆCØˆGå+Ù˜Ÿ™ 3§:¡:¨s¯y©yÓ9‰ˆˆqä  Ó'ò 	-‰GˆAˆtØ—?‘? 3§:¡:Ó.×2Ñ2×:Ñ:Ó<ˆDØ—‘ tÓ,ˆE�!ŠHð	-ð �Q‰x�|‰|˜E ! "˜IÓ&‰ˆˆ1à45Ö6¨qŒT�_‰_œT !›W cÕ*Ð6ˆÐ6Ü�O‰OœD ›G SÓ)ˆáðØ/0Ö1¨!˜!Ÿ)™)�+Ò1°1·9±9³;�B�ð ˜2�1�à�yŠyØ)*Ö+ A�A—I‘I•KÒ+¨Q¯Y©Y«[Ð8Ð8à�a�4ˆKùò 7ùò
 2øÜ!ò Ùðüò ,s0   Æ&IÇ(I" Ç,IÈI" È*I1ÉI" É"	I.É-I.c                ó0   — | j                  |«      d   dk(  S )am  
        Check if ``poly`` belongs the ideal generated by ``self``.

        Examples
        ========

        >>> from sympy import groebner
        >>> from sympy.abc import x, y

        >>> f = 2*x**3 + y**3 + 3*y
        >>> G = groebner([x**2 + y**2 - 1, x*y - 2])

        >>> G.contains(f)
        True
        >>> G.contains(f + 1)
        False

        r‚   r   )r   rN  s     rd   ÚcontainszGroebnerBasis.containsŽ  s   € ð& �{‰{˜4Ó  Ñ# qÑ(Ð(rg   Nr  )r^   r%  r&  r'  r€   r,  rE  r-  r~   rC  rO  rY   rS   rl   rT  rš  rY  r³   r  r  r@  rg  r   rj  r  rg   rd   r=  r=  „  sÜ   „ á/ò ð& ñó ðð ñ;ó ð;ð ñ8ó ð8ð ñ!ó ð!ð ñ"ó ð"ð ñ$ó ð$ð ñ#ó ð#ò ò$òòAòò!ð ñó ðò>@!óDNó`)rg   r=  c                óÚ   ‡‡— t        j                  ‰g «       ˆˆfd„Št        | «      } | j                  rt	        | g|¢­i ‰¤ŽS d‰vrd‰d<   t        j
                  |‰«      } ‰| |«      S )zû
    Efficiently transform an expression into a polynomial.

    Examples
    ========

    >>> from sympy import poly
    >>> from sympy.abc import x

    >>> poly(x*(x**2 + x - 1)**2)
    Poly(x**5 + 2*x**4 - x**3 - 2*x**2 + x, x, domain='ZZ')

    c                ó6  •— g g }}t        j                  | «      D �]`  }g g }}t        j                  |«      D ]»  }|j                  r|j	                   ‰
||«      «       Œ(|j
                  rw|j                  j                  ra|j                  j                  rK|j                  dk\  r<|j	                   ‰
|j                  |«      j                  |j                  «      «       Œ«|j	                  |«       Œ½ |s|j	                  |«       Œï|d   }|dd  D ]  }|j                  |«      }Œ |r?t        |Ž }|j                  r||z  }n%|j                  t        j                  ||«      «      }|j	                  |«       �Œc |st        j                  | |«      }	na|d   }	|dd  D ]  }|	j                  |«      }	Œ |r?t        |Ž }|j                  r|	|z  }	n%|	j                  t        j                  ||«      «      }	 |	j                  |j!                  dd«      i ‰¤ŽS )Nr   r‚   rY   r  )r   rÍ  r   rô  rH  rÎ  rÏ  rÃ  r  rp  r   rV  rW   r{   r  rª   rÉ  )rŒ   r   r  Ú
poly_termsr¬  r  Úpoly_factorsr|  Úproductrb   Ú_polyr~   s             €€rd   rp  zpoly.<locals>._polyµ  sä  ø€ Ø ˆzˆä—M‘M $Ó'ó 	+ˆDØ$&¨�\ˆGäŸ-™-¨Ó-ò +�Ø—=’=Ø ×'Ñ'©¨f°cÓ(:Õ;Ø—]’] v§{¡{×'9Ò'9ØŸ
™
×-Ò-°&·*±*À²/Ø ×'Ñ'Ù˜fŸk™k¨3Ó/×3Ñ3°F·J±JÓ?õAð —N‘N 6Õ*ð+ñ  Ø—‘˜TÕ"à& q™/�à*¨1¨2Ð.ò 2�FØ%Ÿk™k¨&Ó1‘Gð2ñ Ü  '˜]�Fà×'Ò'Ø 6Ñ)™à")§+¡+¬d¯o©o¸fÀcÓ.JÓ"K˜à×!Ñ! 'Ö*ð;	+ñ> Ü—_‘_ T¨3Ó/‰Fà ‘]ˆFà" 1 2˜ò *�ØŸ™ DÓ)‘ð*ñ Ü˜E�{�à—>’>Ø˜d‘N‘Fà#ŸZ™Z¬¯©¸¸cÓ(BÓC�Fàˆv�~‰~˜sŸw™w v¨rÓ2Ð;°dÑ;Ð;rg   r>  F)ro   r^  r%   ry   rW   rp   )rŒ   rY   r~   r   rp  s     ` @rd   rD  rD  ¤  sr   ù€ ô ×Ñ˜$ Ô#õ2<ôh �4‹=€Dà‡|‚|Ü�DÐ(˜4Ò( 4Ñ(Ð(à�tÑØˆˆX‰ä
×
Ñ
  dÓ
+€Cá��sÓÐrg   c                ó:  — | dk  rt        d|›d| ›�«      ‚|d   |dd }}|€t        |d¬«      \  }}t         |t        | «      g|¢|‘­Ž |«      }|€ t        j                  |t        d«      «      }nt        j                  ||«      }|r|S |j                  «       S )	aŠ  Common interface to the low-level polynomial generating functions
    in orthopolys and appellseqs.

    Parameters
    ==========

    n : int
        Index of the polynomial, which may or may not equal its degree.
    f : callable
        Low-level generating function to use.
    K : Domain or None
        Domain in which to perform the computations. If None, use the smallest
        field containing the rationals and the extra parameters of x (see below).
    name : str
        Name of an arbitrary individual polynomial in the sequence generated
        by f, only used in the error message for invalid n.
    x : seq
        The first element of this argument is the main variable of all
        polynomials in this sequence. Any further elements are extra
        parameters required by f.
    polys : bool, optional
        If True, return a Poly, otherwise (default) return an expression.
    r   zCannot generate z
 of index r‚   NT)r¨   r  )	r  r+   r4   r(  r2  r†   r#   rW   r]   )	r*  r_   ÚKrÁ  r  rO  ÚheadÚtailrD  s	            rd   Ú
named_polyru  ö  sž   € ð0 	ˆ1‚uÝºTÁ1ÐEÓFÐFØ�1‘�q˜˜�uˆ$€DØ€yÜ" 4¨tÔ4‰ˆˆ4Ü‰q”�Q“Ð"˜$Ð" Ò" AÓ&€DØ€|Ü�|‰|˜D¤%¨£*Ó-‰ä�x‰x˜˜dÓ#ˆÙˆ4Ð,˜dŸl™l›nÐ,rg   r  rˆ   )FNNNFFFr!  r  )TTFr"  )¿r'  Ú
__future__r   Ú	functoolsr   r   Úoperatorr   Útypingr   Úcollectionsr	   r
   Ú
sympy.corer   r   r   r   Úsympy.core.basicr   Úsympy.core.decoratorsr   Úsympy.core.exprtoolsr   r   r   Úsympy.core.evalfr   r   r   r   r   Úsympy.core.functionr   Úsympy.core.mulr   r   Úsympy.core.intfuncr   Úsympy.core.numbersr   r   r   Úsympy.core.relationalr    r!   Úsympy.core.sortingr"   Úsympy.core.symbolr#   r$   Úsympy.core.sympifyr%   r&   Úsympy.core.traversalr'   r(   Úsympy.logic.boolalgr)   Úsympy.polysr*   ro   Úsympy.polys.constructorr+   Úsympy.polys.domainsr,   r-   r.   Ú!sympy.polys.domains.domainelementr/   Úsympy.polys.fglmtoolsr0   Úsympy.polys.groebnertoolsr1   rD  Úsympy.polys.monomialsr2   Úsympy.polys.orderingsr3   Úsympy.polys.polyclassesr4   r5   r6   Úsympy.polys.polyerrorsr7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   Úsympy.polys.polyutilsrB   rC   rD   rE   rF   rG   Úsympy.polys.rationaltoolsrH   Úsympy.polys.rootisolationrI   Úsympy.utilitiesrJ   rK   rL   Úsympy.utilities.exceptionsrM   Úsympy.utilities.iterablesrN   rO   rN  ro  Úmpmath.libmp.libhyperrP   rf   rW   r2  r<  r;  rD  rB  rT  r�  r•  r“  r�  r®  r´  rs  rw  ry  r{  r~  r…  r‰  r‹  r×  rÚ  rÝ  rá  rã  rç  rî  r”  rò  r¡  rõ  rU  r÷  rú  rý  rÿ  r  r  r  r  r¸  r  r  r¿  rÆ  rÈ  rÖ  rÙ  rá  rã  r  r  r  r)  r  r|  r#  r9  rJ  rZ  rW  ry  r}  r€  r¢  r6  r@  r=  rD  ru  r  rg   rd   ú<module>r›     s  ðÙ >å "ç #Ý Ý ß ,÷ó õ #Ý ,ß AÑ A÷Mõ Må *ß +Ý #ß 7Ñ 7ß 6Ý &ß +ß 0ß >Ý +Ý .Ý 4ß *Ñ *Ý ;Ý -Ý ;Ý *Ý .ß 1Ñ 1÷	÷ 	÷ 	ñ 	÷÷ õ /Ý Aß 5Ñ 5Ý @ß 4ó ã Ý /ò!ðJ ôPE`ˆ5ó PE`ó ðPE`ðfJ ôZˆtó Zó ðZðz ñ&ó ð&ò%ðP ñ0ó ð0ò[ò|ð ò7Nó ð7Nðt ñ1ó ð1ðh ñ(ó ð(ð4 ñ!ó ð!ð0 ñó ðð2 ñ!ó ð!ð2 ñó ðð: ñó ðð: ñó ððD ñó ððD ñó ðð> ñó ðð> ñó ðð> ñó ððD ñ#ó ð#ðL ñ#ó ð#ðL ñ0ó ð0ðf ñó ðð: Ø&+ó !ó ð!ðH ñó ðð: ñ%ó ð%ðP ñQó ðQðh ò0ó ð0ðf ñJó ðJðZ ò/ó ð/ðd ñr3ó ðr3ðj ñó ðð: ñó ðð: ñó ðð0 ñ*ó ð*ðZ ñó ðð: ñó ðð: ñó ðð: ñ+ó ð+ð\ ñ<ó ð<ð
 ñ ó ð ðF ñó ðò:=ò$ò 6ò
:#òzò)FòX8ò|ò~)ðX ñ=ó ð=ð" ñ8ó ð8ð" ñ@ó ð@ð" Øó _ó ð_ðD ò4ó ð4ðn òUó ðUð8 ò+ó ð+ð@ òd=ó ðd=ðN òz>ó ðz>ðz ò=ó ð=ð< ñó ðð: ñ(ó ð(ðV Ø#ó `Có ð`CðF ñ8ó ð8ðv ñ2+ó ð2+ðj ñ?ó ð?ð" ô\)�Eó \)ó ð\)ð~ ñNó ðNób"-rg   