
    ЦiF                      % S r SSKJr  SSKJr  SSKJrJrJrJ	r	J
r
Jr  SSKJr  SSKJr  SSKJr  SSKJr  SS	KJrJr  SS
KJrJr  SSKJr  SSKJr  SSKJ r   SSK!J"r"J#r#J$r$  SSK%J&r&  SSK'J(r(  SSK)J*r*  SSK+J,r,  SSK-J.r.  SSK/J0r0J1r1J2r2J3r3  SSK4J5r6J7r8J9r9  SSK:J;r;J<r<J=r=  SSK>J?r?  SSK@JArAJBrB  SSKCJDrD  SSKEJFrF  \A\.4S j5       rG\A\.4S j5       rH\A\.4S j5       rI\AS 5       rJS rK0 rLS \MS!'    " S" S#\?\5      rN " S$ S%\&\?\\O5      rPg&)'zSparse polynomial rings.     )annotations)Any)addmulltlegtge)reduce)GeneratorType)Expr)igcd)Symbolsymbols)CantSympifysympify)multinomial_coefficients)IPolys)construct_domain)ninfdmp_to_dictdmp_from_dict)DomainElementPolynomialRingheugcd)MonomialOps)lex)CoercionFailedGeneratorsErrorExactQuotientFailedMultivariatePolynomialError)DomainOrderbuild_options)expr_from_dict_dict_reorder_parallel_dict_from_expr)DefaultPrinting)publicsubsets)is_sequence)pollutec                :    [        XU5      nU4UR                  -   $ )aR  Construct a polynomial ring returning ``(ring, x_1, ..., x_n)``.

Parameters
==========

symbols : str
    Symbol/Expr or sequence of str, Symbol/Expr (non-empty)
domain : :class:`~.Domain` or coercible
order : :class:`~.MonomialOrder` or coercible, optional, defaults to ``lex``

Examples
========

>>> from sympy.polys.rings import ring
>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.orderings import lex

>>> R, x, y, z = ring("x,y,z", ZZ, lex)
>>> R
Polynomial ring in x, y, z over ZZ with lex order
>>> x + y + z
x + y + z
>>> type(_)
<class 'sympy.polys.rings.PolyElement'>

PolyRinggensr   domainorder_rings       P/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/sympy/polys/rings.pyringr8   #   s!    8 We,E8ejj      c                4    [        XU5      nX3R                  4$ )aX  Construct a polynomial ring returning ``(ring, (x_1, ..., x_n))``.

Parameters
==========

symbols : str
    Symbol/Expr or sequence of str, Symbol/Expr (non-empty)
domain : :class:`~.Domain` or coercible
order : :class:`~.MonomialOrder` or coercible, optional, defaults to ``lex``

Examples
========

>>> from sympy.polys.rings import xring
>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.orderings import lex

>>> R, (x, y, z) = xring("x,y,z", ZZ, lex)
>>> R
Polynomial ring in x, y, z over ZZ with lex order
>>> x + y + z
x + y + z
>>> type(_)
<class 'sympy.polys.rings.PolyElement'>

r0   r3   s       r7   xringr;   B   s    8 We,E::r9   c                    [        XU5      n[        UR                   Vs/ s H  oDR                  PM     snUR                  5        U$ s  snf )a\  Construct a polynomial ring and inject ``x_1, ..., x_n`` into the global namespace.

Parameters
==========

symbols : str
    Symbol/Expr or sequence of str, Symbol/Expr (non-empty)
domain : :class:`~.Domain` or coercible
order : :class:`~.MonomialOrder` or coercible, optional, defaults to ``lex``

Examples
========

>>> from sympy.polys.rings import vring
>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.orderings import lex

>>> vring("x,y,z", ZZ, lex)
Polynomial ring in x, y, z over ZZ with lex order
>>> x + y + z # noqa:
x + y + z
>>> type(_)
<class 'sympy.polys.rings.PolyElement'>

)r1   r.   r   namer2   )r   r4   r5   r6   syms        r7   vringr?   a   s=    6 We,E%--1-3hh-15::>L 2s   A	c                   Sn[        U 5      (       d  U /Sp0[        [        [        U 5      5      n [	        X5      n[        X5      u  pTUR                  c  [        U Vs/ s H  n[        UR                  5       5      PM     sn/ 5      n[        XtS9u  Ul        n[        [        Xx5      5      n	U VV
Vs/ s H*  ofR                  5        V
Vs0 s H
  u  pXU   _M     snn
PM,     nn
nn[        UR                  UR                  UR                  5      n[        [        UR                   U5      5      nU(       a  XS   4$ X4$ s  snf s  snn
f s  snn
nf )a   Construct a ring deriving generators and domain from options and input expressions.

Parameters
==========

exprs : :class:`~.Expr` or sequence of :class:`~.Expr` (sympifiable)
symbols : sequence of :class:`~.Symbol`/:class:`~.Expr`
options : keyword arguments understood by :class:`~.Options`

Examples
========

>>> from sympy import sring, symbols

>>> x, y, z = symbols("x,y,z")
>>> R, f = sring(x + 2*y + 3*z)
>>> R
Polynomial ring in x, y, z over ZZ with lex order
>>> f
x + 2*y + 3*z
>>> type(_)
<class 'sympy.polys.rings.PolyElement'>

FT)optr   )r-   listmapr   r&   r)   r4   sumvaluesr   dictzipitemsr1   r2   r5   	from_dict)exprsr   optionssinglerA   repsrepcoeffs
coeffs_dom	coeff_mapmcr6   polyss                 r7   sringrU      s   4 FuvWe$%E

)C )4ID
zzT;TctCJJL)T;R@!1&!B
JV01	EIJTcYY[9[TQaL[9TJSXXszz3995EU__d+,EQx  ~ <
 :Js   #E4EEEEc                .   [        U [        5      (       a  U (       a
  [        U SS9$ S$ [        U [        5      (       a  U 4$ [	        U 5      (       a;  [        S U  5       5      (       a  [        U 5      $ [        S U  5       5      (       a  U $ [        S5      e)NT)seq c              3  B   #    U  H  n[        U[        5      v   M     g 7fN)
isinstancestr.0ss     r7   	<genexpr>!_parse_symbols.<locals>.<genexpr>   s     37az!S!!7   c              3  B   #    U  H  n[        U[        5      v   M     g 7frZ   )r[   r   r]   s     r7   r`   ra      s     6gAt$$grb   zbexpected a string, Symbol or expression or a non-empty sequence of strings, Symbols or expressions)r[   r\   _symbolsr   r-   allr!   r   s    r7   _parse_symbolsrg      s    '3.5xT*=2=	GT	"	"z	W		37333G$$6g666N
~
r9   zdict[Any, Any]_ring_cachec                  &   \ rS rSrSr\4S jrS rS rS r	S r
S rS	 rS'S jrS r\S 5       r\S 5       rS(S jrS rS rS r\rS(S jrS(S jrS rS rS rS rS rS rS rS r S r!\S 5       r"\S 5       r#S  r$S! r%S" r&S# r'S$ r(S% r)S&r*g
))r1      z*Multivariate distributed polynomial ring. c                  ^ [        [        U5      5      n[        U5      n[        R                  " U5      n[
        R                  " T5      mU R                  XUT4n[        R                  U5      nUGc^  UR                  (       a1  [        U5      [        UR                  5      -  (       a  [        S5      e[        R                  U 5      nXVl        [!        U5      Ul        [%        S[&        4SU05      Ul        Xl        XFl        X&l        TUl        SU-  Ul        UR3                  5       Ul        [        UR4                  5      Ul        UR0                  UR8                  4/Ul        U(       a  [=        U5      nUR?                  5       Ul         URC                  5       Ul"        URG                  5       Ul$        URK                  5       Ul&        URO                  5       Ul(        URS                  5       Ul*        URW                  5       Ul,        O/S nXl         Xl"        S Ul$        Xl&        Xl(        Xl*        Xl,        T[Z        L a  [\        Ul/        OU4S jUl/        [a        UR                  UR4                  5       HF  u  p[c        U	[d        5      (       d  M  U	Rf                  n[i        Xk5      (       a  M:  [k        XkU
5        MH     U[        U'   U$ )Nz7polynomial ring and it's ground domain share generatorsPolyElementr8   r   c                    gNrX   rX   )abs     r7   <lambda>"PolyRing.__new__.<locals>.<lambda>   s    rr9   c                    gro   rX   )rp   rq   rS   s      r7   rr   rs      s    br9   c                   > [        U TS9$ )Nkey)max)fr5   s    r7   rr   rs      s    S->r9   )6tuplerg   len	DomainOpt
preprocessOrderOpt__name__rh   getis_Compositesetr   r!   object__new___hash_tuplehash_hashtyperl   dtypengensr4   r5   
zero_monom_gensr2   	_gens_setone_oner   r   monomial_mulpowmonomial_powmulpowmonomial_mulpowldivmonomial_ldivdivmonomial_divlcmmonomial_lcmgcdmonomial_gcdr   rx   leading_expvrG   r[   r   r=   hasattrsetattr)clsr   r4   r5   r   r   objcodegenmonunitsymbol	generatorr=   s      `        r7   r   PolyRing.__new__   s%   w/0G%%f-##E*||WVUCook*;""s7|c&..6I'I%&_``..%C)O[)CI][NVSMJCI!KIJCI!%ZCNyy{CHMCM45CH%e,#*;;= #*;;= &-nn&6#$+LLN!#*;;= #*;;= #*;;= )#* #* &8#$+!#* #* #*  |#& #> %(chh%?!ff--!;;D"3--95 &@ (+K$
r9   c                    U R                   R                  n/ n[        U R                  5       H5  nU R	                  U5      nU R
                  nXU'   UR                  U5        M7     [        U5      $ )z(Return a list of polynomial generators. )r4   r   ranger   monomial_basiszeroappendrz   )selfr   r   iexpvpolys         r7   r   PolyRing._gens  s_    kkootzz"A&&q)D99DJLL	 #
 U|r9   c                H    U R                   U R                  U R                  4$ rZ   )r   r4   r5   r   s    r7   __getnewargs__PolyRing.__getnewargs__  s    dkk4::66r9   c                    U R                   R                  5       nUS	 U H  nUR                  S5      (       d  M  X	 M     U$ )Nr   	monomial_)__dict__copy
startswith)r   staterw   s      r7   __getstate__PolyRing.__getstate__  sA    ""$.!C~~k**J  r9   c                    U R                   $ rZ   r   r   s    r7   __hash__PolyRing.__hash__   s    zzr9   c                    [        U[        5      =(       a]    U R                  U R                  U R                  U R
                  4UR                  UR                  UR                  UR
                  4:H  $ rZ   )r[   r1   r   r4   r   r5   r   others     r7   __eq__PolyRing.__eq__#  sV    %* D\\4;;

DJJ?]]ELL%++u{{CD	Dr9   c                    X:X  + $ rZ   rX   r   s     r7   __ne__PolyRing.__ne__(  s      r9   Nc                    U R                  U=(       d    U R                  U=(       d    U R                  U=(       d    U R                  5      $ rZ   )	__class__r   r4   r5   )r   r   r4   r5   s       r7   clonePolyRing.clone+  s3    ~~g5v7LeNaW[WaWabbr9   c                @    S/U R                   -  nSX!'   [        U5      $ )zReturn the ith-basis element. r      )r   rz   )r   r   basiss      r7   r   PolyRing.monomial_basis.  s"    DJJU|r9   c                "    U R                  5       $ rZ   )r   r   s    r7   r   PolyRing.zero4  s    zz|r9   c                8    U R                  U R                  5      $ rZ   )r   r   r   s    r7   r   PolyRing.one8  s    zz$))$$r9   c                8    U R                   R                  X5      $ rZ   )r4   convertr   elementorig_domains      r7   
domain_newPolyRing.domain_new<  s    {{""788r9   c                :    U R                  U R                  U5      $ rZ   )term_newr   )r   coeffs     r7   
ground_newPolyRing.ground_new?  s    }}T__e44r9   c                V    U R                  U5      nU R                  nU(       a  X#U'   U$ rZ   )r   r   )r   monomr   r   s       r7   r   PolyRing.term_newB  s(    &yyKr9   c                   [        U[        5      (       ap  XR                  :X  a  U$ [        U R                  [        5      (       a5  U R                  R                  UR                  :X  a  U R                  U5      $ [        S5      e[        U[        5      (       a  [        S5      e[        U[        5      (       a  U R                  U5      $ [        U[        5      (       a   U R                  U5      $ [        U[        5      (       a  U R                  U5      $ U R                  U5      $ ! [         a    U R                  U5      s $ f = f)N
conversionparsing)r[   rl   r8   r4   r   r   NotImplementedErrorr\   rF   rI   rB   
from_terms
ValueError	from_listr   	from_exprr   r   s     r7   ring_newPolyRing.ring_newI  s   g{++||#DKK88T[[=M=MQXQ]Q]=]w//),77%%%i00&&>>'**&&/w// &&>>'**??7++  /~~g../s   "D* *EEc                    U R                   nU R                  nUR                  5        H  u  pVU" Xb5      nU(       d  M  XdU'   M     U$ rZ   )r   r   rH   )r   r   r   r   r   r   r   s          r7   rI   PolyRing.from_dicta  sC    __
yy#MMOLEu2Eu#U ,
 r9   c                8    U R                  [        U5      U5      $ rZ   )rI   rF   r   s      r7   r   PolyRing.from_termsl  s    ~~d7m[99r9   c                f    U R                  [        XR                  S-
  U R                  5      5      $ Nr   )rI   r   r   r4   r   s     r7   r   PolyRing.from_listo  s$    ~~k'::a<MNNr9   c                V   ^ ^^^ T R                   mUUUU 4S jmT" [        U5      5      $ )Nc           	       > TR                  U 5      nUb  U$ U R                  (       a-  [        [        [	        [        TU R                  5      5      5      $ U R                  (       a-  [        [        [	        [        TU R                  5      5      5      $ U R                  5       u  p#UR                  (       a  US:  a  T" U5      [        U5      -  $ TR                  TR                  U 5      5      $ r   )r   is_Addr   r   rB   rC   argsis_Mulr   as_base_exp
is_Integerintr   r   )exprr   baseexp_rebuildr4   mappingr   s       r7   r  (PolyRing._rebuild_expr.<locals>._rebuildu  s    D)I$  c4Hdii(@#ABBc4Hdii(@#ABB !,,.	>>cAg#D>3s833??6>>$+?@@r9   )r4   r   )r   r   r  r  r4   s   ` `@@r7   _rebuild_exprPolyRing._rebuild_exprr  s)    	A 	A$ &&r9   c                    [        [        [        U R                  U R                  5      5      5      n U R                  X5      nU R                  U5      $ ! [         a    [        SU < SU< 35      ef = f)Nz6expected an expression convertible to a polynomial in z, got )	rF   rB   rG   r   r2   r  r   r    r   )r   r   r  r   s       r7   r   PolyRing.from_expr  sk    tCdii89:	'%%d4D ==&&  	pcgimnoo	ps   A A4c                V   Uc  U R                   (       a  SnU$ Sn U$ [        U[        5      (       aG  UnSU::  a  X R                   :  a   U$ U R                   * U::  a  US::  a  U* S-
  nU$ [        SU-  5      e[        XR                  5      (       a   U R
                  R                  U5      nU$ [        U[        5      (       a   U R                  R                  U5      nU$ [        SU-  5      e! [         a    [        SU-  5      ef = f! [         a    [        SU-  5      ef = f)z+Compute index of ``gen`` in ``self.gens``. r   r   zinvalid generator index: %szinvalid generator: %szEexpected a polynomial generator, an integer, a string or None, got %s)	r   r[   r   r   r   r2   indexr\   r   )r   genr   s      r7   r
  PolyRing.index  sI   ;zz2 / . - S!!AAv!jj.$ # **!a2gBF   !!>!DEEZZ((@IIOOC(  S!!@LL&&s+  dgjjkk  @ !83!>??@
  @ !83!>??@s   C3 D 3DD(c                    [        [        U R                  U5      5      n[        U R                  5       VVs/ s H  u  p4X2;  d  M  UPM     nnnU(       d  U R
                  $ U R                  US9$ s  snnf )z,Remove specified generators from this ring. rf   )r   rC   r
  	enumerater   r4   r   )r   r2   indicesr   r_   r   s         r7   dropPolyRing.drop  sa    c$**d+,"+DLL"9O"9$!Q=MA"9O;;::g:.. Ps   A2A2c                d    U R                   U   nU(       d  U R                  $ U R                  US9$ )Nrf   )r   r4   r   )r   rw   r   s      r7   __getitem__PolyRing.__getitem__  s.    ,,s#;;::g:..r9   c                    U R                   R                  (       d  [        U R                   S5      (       a#  U R                  U R                   R                   S9$ [	        SU R                   -  5      e)Nr4   r4   z%s is not a composite domain)r4   r   r   r   r   r   s    r7   	to_groundPolyRing.to_ground  sO    ;;##wt{{H'E'E::T[[%7%7:88;dkkIJJr9   c                    [        U 5      $ rZ   r   r   s    r7   	to_domainPolyRing.to_domain  s    d##r9   c                ^    SSK Jn  U" U R                  U R                  U R                  5      $ )Nr   )	FracField)sympy.polys.fieldsr  r   r4   r5   )r   r  s     r7   to_fieldPolyRing.to_field  s     0t{{DJJ??r9   c                2    [        U R                  5      S:H  $ r   r{   r2   r   s    r7   is_univariatePolyRing.is_univariate  s    499~""r9   c                2    [        U R                  5      S:  $ r   r"  r   s    r7   is_multivariatePolyRing.is_multivariate  s    499~!!r9   c                    U R                   nU H-  n[        U[        S9(       a  X R                  " U6 -  nM)  X#-  nM/     U$ )a  
Add a sequence of polynomials or containers of polynomials.

Examples
========

>>> from sympy.polys.rings import ring
>>> from sympy.polys.domains import ZZ

>>> R, x = ring("x", ZZ)
>>> R.add([ x**2 + 2*i + 3 for i in range(4) ])
4*x**2 + 24
>>> _.factor_list()
(4, [(x**2 + 6, 1)])

include)r   r-   r   r   r   objspr   s       r7   r   PolyRing.add  s?    " IIC36XXs^#	  r9   c                    U R                   nU H-  n[        U[        S9(       a  X R                  " U6 -  nM)  X#-  nM/     U$ )ap  
Multiply a sequence of polynomials or containers of polynomials.

Examples
========

>>> from sympy.polys.rings import ring
>>> from sympy.polys.domains import ZZ

>>> R, x = ring("x", ZZ)
>>> R.mul([ x**2 + 2*i + 3 for i in range(4) ])
x**8 + 24*x**6 + 206*x**4 + 744*x**2 + 945
>>> _.factor_list()
(1, [(x**2 + 3, 1), (x**2 + 5, 1), (x**2 + 7, 1), (x**2 + 9, 1)])

r)  )r   r-   r   r   r+  s       r7   r   PolyRing.mul  s?    " HHC36XXs^#	  r9   c                b   [        [        U R                  U5      5      n[        U R                  5       VVs/ s H  u  p4X2;  d  M  UPM     nnn[        U R
                  5       VVs/ s H  u  p6X2;  d  M  UPM     nnnU(       d  U $ U R                  XPR                  " U6 S9$ s  snnf s  snnf )zL
Remove specified generators from the ring and inject them into
its domain.
r   r4   )r   rC   r
  r  r   r2   r   r  )r   r2   r  r   r_   r   r  s          r7   drop_to_groundPolyRing.drop_to_ground  s    
 c$**d+,!*4<<!8M!8A<L1!8M"+DII"6K"6!:J"6KK::gii6F:GG NKs   B%B%(B+7B+c                    X:w  aO  [        U R                  5      R                  [        UR                  5      5      nU R                  [	        U5      S9$ U $ )z+Add the generators of ``other`` to ``self``rf   r   r   unionr   rB   )r   r   symss      r7   composePolyRing.compose  sC    =t||$**3u}}+=>D::d4j:11Kr9   c                    [        U R                  5      R                  [        U5      5      nU R                  [	        U5      S9$ )z9Add the elements of ``symbols`` as generators to ``self``rf   r6  )r   r   r8  s      r7   add_gensPolyRing.add_gens&  s4    4<< &&s7|4zz$t*z--r9   c                  ^ US:  d  XR                   :  a  [        SU< SU R                  < 35      eU(       d  U R                  $ U R                  n[        [        U R                   5      [        U5      5       HR  m[        U4S j[        U R                   5       5       5      nX R                  X0R                  R                  5      -  nMT     U$ )zW
Return the elementary symmetric polynomial of degree *n* over
this ring's generators.
r   z.Cannot generate symmetric polynomial of order z for c              3  @   >#    U  H  n[        UT;   5      v   M     g 7frZ   )r   )r^   r   r_   s     r7   r`   *PolyRing.symmetric_poly.<locals>.<genexpr>7  s     E3Dac!q&kk3D   )r   r   r2   r   r   r,   r   r   rz   r   r4   )r   nr   r   r_   s       @r7   symmetric_polyPolyRing.symmetric_poly+  s    
 q5A

NZ[]a]f]fghh88O99DU4::.A7E53DEEe[[__== 8 Kr9   rX   )NNNrZ   )+r   
__module____qualname____firstlineno____doc__r   r   r   r   r   r   r   r   r   r   propertyr   r   r   r   r   r   __call__rI   r   r   r  r   r
  r  r  r  r  r  r#  r&  r   r   r3  r9  r<  rC  __static_attributes__rX   r9   r7   r1   r1      s    4,/ ?B	7D
!c   % %95,, H	:O'.'>//K$@ # # " "66H.
r9   r1   c                     \ rS rSrSrS rS rS rSrS r	S r
S	 rS
 rS rS rS rS rS rSS jrS rS rS rS rS rS rS rS rS rS rS rS rS r\ S 5       r!\ S 5       r"\ S  5       r#\ S! 5       r$\ S" 5       r%\ S# 5       r&\ S$ 5       r'\ S% 5       r(\ S& 5       r)\ S' 5       r*\ S( 5       r+\ S) 5       r,\ S* 5       r-\ S+ 5       r.\ S, 5       r/\ S- 5       r0\ S. 5       r1S/ r2S0 r3S1 r4S2 r5S3 r6S4 r7S5 r8S6 r9S7 r:S8 r;S9 r<S: r=S; r>S< r?S= r@S> rAS? rBS@ rC\BrD\CrESA rFSB rGSC rHSD rISE rJSF rKSG rLSSH jrMSI rNSSJ jrOSK rPSL rQSM rRSN rSSO rT\ SP 5       rU\ SQ 5       rVSR rW\ SS 5       rXST rYSU rZSSV jr[SSW jr\SSX jr]SY r^SZ r_S[ r`S\ raS] rbS^ rcS_ rdS` reSa rfSb rgSc rhSd riSe rjSf rkSg rlSh rm\mrnSi roSj rpSk rqSl rrSm rsSn rtSo ruSp rvSq rwSr rxSs rySt rzSu r{Sv r|Sw r}Sx r~Sy rSz rSS{ jrSS| jrS} rSS~ jrS rSS jrSS jrSS jrSS jrSS jrS rS rS rS rS rS rS rS rS rS rS rS rSS jrS rSrg)rl   i<  z5Element of multivariate distributed polynomial ring. c                $    U R                  U5      $ rZ   )r   )r   inits     r7   newPolyElement.new?  s    ~~d##r9   c                6    U R                   R                  5       $ rZ   )r8   r  r   s    r7   parentPolyElement.parentB  s    yy""$$r9   c                L    U R                   [        U R                  5       5      4$ rZ   )r8   rB   	itertermsr   s    r7   r   PolyElement.__getnewargs__E  s    		4 0122r9   Nc                    U R                   nUc5  [        U R                  [        U R	                  5       5      45      =U l         nU$ rZ   )r   r   r8   	frozensetrH   )r   r   s     r7   r   PolyElement.__hash__J  s<     

=!%tyy)DJJL2I&J!KKDJr9   c                $    U R                  U 5      $ )a  Return a copy of polynomial self.

Polynomials are mutable; if one is interested in preserving
a polynomial, and one plans to use inplace operations, one
can copy the polynomial. This method makes a shallow copy.

Examples
========

>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.rings import ring

>>> R, x, y = ring('x, y', ZZ)
>>> p = (x + y)**2
>>> p1 = p.copy()
>>> p2 = p
>>> p[R.zero_monom] = 3
>>> p
x**2 + 2*x*y + y**2 + 3
>>> p1
x**2 + 2*x*y + y**2
>>> p2
x**2 + 2*x*y + y**2 + 3

)rO  r   s    r7   r   PolyElement.copyU  s    4 xx~r9   c           	     t   U R                   U:X  a  U $ U R                   R                  UR                  :w  a^  [        [        [	        X R                   R                  UR                  5      6 5      nUR                  X R                   R                  5      $ UR                  X R                   R                  5      $ rZ   )r8   r   rB   rG   r(   r   r4   rI   )r   new_ringtermss      r7   set_ringPolyElement.set_ringq  s    99 KYY("2"22mD))2C2CXEUEUVWXE&&uii.>.>??%%dII,<,<==r9   c                   U(       d  U R                   R                  nOS[        U5      U R                   R                  :w  a0  [	        SU R                   R                  < S[        U5      < 35      e[        U R                  5       /UQ76 $ )Nz"Wrong number of symbols, expected z got )r8   r   r{   r   r   r'   as_expr_dict)r   r   s     r7   as_exprPolyElement.as_exprz  sf    ii''G\TYY__,#g,0 
 d//1<G<<r9   c                    U R                   R                  R                  nU R                  5        VVs0 s H  u  p#X!" U5      _M     snn$ s  snnf rZ   )r8   r4   to_sympyrU  )r   rf  r   r   s       r7   rb  PolyElement.as_expr_dict  sC    99##,,;?>>;KL;K<5x&;KLLLs   Ac           	        U R                   R                  nUR                  (       a  UR                  (       d  UR                  U 4$ UR                  5       nUR                  nUR                  nUR                  nU R                  5        H  nU" X5" U5      5      nM     U R                  U R                  5        VVs/ s H  u  pxXxU-  4PM     snn5      n	X94$ s  snnf rZ   )r8   r4   is_Fieldhas_assoc_Ringr   get_ringr   denomrE   rO  rH   )
r   r4   ground_ringcommonr   rl  r   kvr   s
             r7   clear_denomsPolyElement.clear_denoms  s    !!f&;&;::t##oo'oo[[]Eu.F # xxDJJLBLDA1h-LBC| Cs   >C
c                ^    [        U R                  5       5       H  u  pU(       a  M  X	 M     g)z+Eliminate monomials with zero coefficient. NrB   rH   )r   ro  rp  s      r7   
strip_zeroPolyElement.strip_zero  s#    &DA1G 'r9   c                   U(       d  U (       + $ [        U[        5      (       a/  UR                  U R                  :X  a  [        R	                  X5      $ [        U 5      S:  a  gU R                  U R                  R                  5      U:H  $ )zEquality test for polynomials.

Examples
========

>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.rings import ring

>>> _, x, y = ring('x, y', ZZ)
>>> p1 = (x + y)**2 + (x - y)**2
>>> p1 == 4*x*y
False
>>> p1 == 2*(x**2 + y**2)
True

r   F)r[   rl   r8   rF   r   r{   r   r   p1p2s     r7   r   PolyElement.__eq__  se    " 6MK((RWW-?;;r&&Wq[66"'',,-33r9   c                    X:X  + $ rZ   rX   rx  s     r7   r   PolyElement.__ne__  s
    |r9   c                
   U R                   n[        XR                  5      (       ax  [        U R	                  5       5      [        UR	                  5       5      :w  a  gUR
                  R                  nU R	                  5        H  nU" X   X   U5      (       a  M    g   g[        U 5      S:  a  g UR
                  R                  U5      nUR
                  R                  U R                  5       X5      $ ! [         a     gf = f)z+Approximate equality test for polynomials. FTr   )r8   r[   r   r   keysr4   almosteqr{   r   constr    )ry  rz  	tolerancer8   r  ro  s         r7   r  PolyElement.almosteq  s    wwb**%%2779~RWWY/{{++HWWYrui88   Wq[G[[((, {{++BHHJFF " s   0C5 5
DDc                8    [        U 5      U R                  5       4$ rZ   )r{   r^  r   s    r7   sort_keyPolyElement.sort_key  s    D	4::<((r9   c                    [        XR                  R                  5      (       a%  U" U R                  5       UR                  5       5      $ [        $ rZ   )r[   r8   r   r  NotImplemented)ry  rz  ops      r7   _cmpPolyElement._cmp  s4    b''--((bkkmR[[]33!!r9   c                .    U R                  U[        5      $ rZ   )r  r   rx  s     r7   __lt__PolyElement.__lt__      wwr2r9   c                .    U R                  U[        5      $ rZ   )r  r   rx  s     r7   __le__PolyElement.__le__  r  r9   c                .    U R                  U[        5      $ rZ   )r  r	   rx  s     r7   __gt__PolyElement.__gt__  r  r9   c                .    U R                  U[        5      $ rZ   )r  r
   rx  s     r7   __ge__PolyElement.__ge__  r  r9   c                    U R                   nUR                  U5      nUR                  S:X  a  X2R                  4$ [	        UR
                  5      nXC	 X2R                  US94$ )Nr   rf   )r8   r
  r   r4   rB   r   r   r   r  r8   r   r   s        r7   _dropPolyElement._drop  sV    yyJJsO::?kk>!4<<(G
jjj111r9   c                j   U R                  U5      u  p#U R                  R                  S:X  a0  U R                  (       a  U R	                  S5      $ [        SU-  5      eUR                  nU R                  5        H5  u  pVXR   S:X  a  [        U5      nXr	 Xd[        U5      '   M)  [        SU-  5      e   U$ )Nr   zCannot drop %sr   )
r  r8   r   	is_groundr   r   r   rH   rB   rz   )r   r  r   r8   r   ro  rp  Ks           r7   r  PolyElement.drop  s    **S/99??a~~zz!}$ !1C!78899D

419QA%&qN$%5%;<< % Kr9   c                    U R                   nUR                  U5      n[        UR                  5      nXC	 X2R	                  XBU   S94$ )Nr2  )r8   r
  rB   r   r   r  s        r7   _drop_to_groundPolyElement._drop_to_ground  sC    yyJJsOt||$J**W!W*===r9   c                   U R                   R                  S:X  a  [        S5      eU R                  U5      u  p#UR                  nUR
                  R                  S   nU R                  5        HQ  u  pVUS U XRS-   S  -   nXt;  a  XU   -  R                  U5      XG'   M1  XG==   XU   -  R                  U5      -  ss'   MS     U$ )Nr   z$Cannot drop only generator to groundr   )	r8   r   r   r  r   r4   r2   rU  
mul_ground)r   r  r   r8   r   r   r   mons           r7   r3  PolyElement.drop_to_ground  s    99??aCDD&&s+yykkq! NN,LE)eaCDk)C (]66u=		c8m77>>	 - r9   c                p    [        X R                  R                  S-
  U R                  R                  5      $ r   )r   r8   r   r4   r   s    r7   to_densePolyElement.to_dense   s&    T99??1#4dii6F6FGGr9   c                    [        U 5      $ rZ   )rF   r   s    r7   to_dictPolyElement.to_dict#  s    Dzr9   c                ~   U (       d/  UR                  U R                  R                  R                  5      $ US   nUS   nU R                  nUR                  nUR
                  n	UR                  n
/ nU R                  5        GHt  u  pUR                  R                  U5      nU(       a  SOSnUR                  U5        X:X  a4  UR                  U5      nU(       a  UR                  S5      (       a  USS  nO@U(       a  U* nXR                  R                  R                  :w  a  UR                  XSS9nOS	n/ n[        U	5       H  nUU   nU(       d  M  UR                  UU   USS9nUS:w  aA  U[        U5      :w  d  US
:  a  UR                  UUSS9nOUnUR                  UUU4-  5        Ml  UR                  SU-  5        M     U(       a  U/U-   nUR                  UR                  U5      5        GMw     US
   S;   a)  UR!                  S
5      nUS:X  a  UR#                  S
S5        S	R                  U5      $ )NMulAtom -  + -r   T)strict r   Fz%s)r  r  )_printr8   r4   r   r   r   r   r^  is_negativer   r   r   parenthesizer   r   joinpopinsert)r   printer
precedenceexp_pattern
mul_symbolprec_mul	prec_atomr8   r   r   zmsexpvsr   r   negativesignscoeffsexpvr   r   r   sexpheads                          r7   r\   PolyElement.str&  s   >>$))"2"2"7"788e$v&	yy,,

__::<KD{{..u5H$5%DMM$z . 1 1# 6 6#ABZF"FEII,,000$11%$1OFFE5\1g --gaj)D-Q!8c#h#'&33C53Q"LL~!=>LL/ " 5(MM*//%01? (@ !9&::a=Du}a%wwvr9   c                2    X R                   R                  ;   $ rZ   )r8   r   r   s    r7   is_generatorPolyElement.is_generatorV  s    yy****r9   c                z    U (       + =(       d.    [        U 5      S:H  =(       a    U R                  R                  U ;   $ r   )r{   r8   r   r   s    r7   r  PolyElement.is_groundZ  s+    xLCINKtyy/C/Ct/KLr9   c                f    U (       + =(       d$    [        U 5      S:H  =(       a    U R                  S:H  $ r   )r{   LCr   s    r7   is_monomialPolyElement.is_monomial^  s$    x<CIN;tww!|<r9   c                    [        U 5      S:*  $ r   )r{   r   s    r7   is_termPolyElement.is_termb  s    4yA~r9   c                `    U R                   R                  R                  U R                  5      $ rZ   )r8   r4   r  r  r   s    r7   r  PolyElement.is_negativef  !    yy++DGG44r9   c                `    U R                   R                  R                  U R                  5      $ rZ   )r8   r4   is_positiver  r   s    r7   r  PolyElement.is_positivej  r  r9   c                `    U R                   R                  R                  U R                  5      $ rZ   )r8   r4   is_nonnegativer  r   s    r7   r  PolyElement.is_nonnegativen  !    yy..tww77r9   c                `    U R                   R                  R                  U R                  5      $ rZ   )r8   r4   is_nonpositiver  r   s    r7   r  PolyElement.is_nonpositiver  r  r9   c                    U (       + $ rZ   rX   ry   s    r7   is_zeroPolyElement.is_zerov  s	    ur9   c                2    X R                   R                  :H  $ rZ   )r8   r   r  s    r7   is_onePolyElement.is_onez  s    FFJJr9   c                `    U R                   R                  R                  U R                  5      $ rZ   )r8   r4   r  r  r  s    r7   is_monicPolyElement.is_monic~  s    vv}}##ADD))r9   c                h    U R                   R                  R                  U R                  5       5      $ rZ   )r8   r4   r  contentr  s    r7   is_primitivePolyElement.is_primitive  s!    vv}}##AIIK00r9   c                B    [        S U R                  5        5       5      $ )Nc              3  >   #    U  H  n[        U5      S :*  v   M     g7fr   NrD   r^   r   s     r7   r`   (PolyElement.is_linear.<locals>.<genexpr>       ?u3u:?   re   
itermonomsr  s    r7   	is_linearPolyElement.is_linear      ????r9   c                B    [        S U R                  5        5       5      $ )Nc              3  >   #    U  H  n[        U5      S :*  v   M     g7f)   Nr  r  s     r7   r`   +PolyElement.is_quadratic.<locals>.<genexpr>  r  r  r  r  s    r7   is_quadraticPolyElement.is_quadratic  r  r9   c                p    U R                   R                  (       d  gU R                   R                  U 5      $ NT)r8   r   	dmp_sqf_pr  s    r7   is_squarefreePolyElement.is_squarefree  s%    vv||vv""r9   c                p    U R                   R                  (       d  gU R                   R                  U 5      $ r  )r8   r   dmp_irreducible_pr  s    r7   is_irreduciblePolyElement.is_irreducible  s%    vv||vv''**r9   c                    U R                   R                  (       a  U R                   R                  U 5      $ [        S5      e)Nzcyclotomic polynomial)r8   r#  dup_cyclotomic_pr#   r  s    r7   is_cyclotomicPolyElement.is_cyclotomic  s0    6666**1---.EFFr9   c                z    U R                  U R                  5        VVs/ s H	  u  pX* 4PM     snn5      $ s  snnf rZ   )rO  rU  )r   r   r   s      r7   __neg__PolyElement.__neg__  s2    xxdnn>NP>Nle5&/>NPQQPs   7
c                    U $ rZ   rX   r   s    r7   __pos__PolyElement.__pos__  s    r9   c                   U(       d  U R                  5       $ U R                  n[        XR                  5      (       ag  U R                  5       nUR                  nUR
                  R                  nUR                  5        H  u  pgU" Xe5      U-   nU(       a  XsU'   M  X6	 M!     U$ [        U[        5      (       a  [        UR
                  [        5      (       a%  UR
                  R                  UR                  :X  a  Od[        UR                  R
                  [        5      (       a5  UR                  R
                  R                  U:X  a  UR                  U 5      $ [        $  UR                  U5      nU R                  5       nU(       d  U$ UR                  n	XR                  5       ;  a  XU	'   U$ XU	   * :X  a  X9	 U$ X9==   U-  ss'   U$ ! [         a	    [        s $ f = f)zAdd two polynomials.

Examples
========

>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.rings import ring

>>> _, x, y = ring('x, y', ZZ)
>>> (x + y)**2 + (x - y)**2
2*x**2 + 2*y**2

)r   r8   r[   r   r   r4   r   rH   rl   r   __radd__r  r   r   r  r    )
ry  rz  r8   r-  r   r   ro  rp  cp2r  s
             r7   __add__PolyElement.__add__  s    779wwb**%%	A%%C;;##D
L1$aD # HK(($++~664;;;K;Krww;VBGGNNN;;@S@SW[@[{{2&%%	//"%C 	AB"" H	 B%< H ESLEH  	"!!	"s   #G G G c                   U R                  5       nU(       d  U$ U R                  n UR                  U5      nUR                  nX@R	                  5       ;  a  XU'   U$ XU   * :X  a  X$	 U$ X$==   U-  ss'   U$ ! [
         a	    [        s $ f = frZ   )r   r8   r   r   r  r    r  )ry  rB  r-  r8   r  s        r7   r  PolyElement.__radd__  s    GGIHww	"A B"" H	 2; H EQJEH  	"!!	"s   A8 8B
Bc                   U(       d  U R                  5       $ U R                  n[        XR                  5      (       ag  U R                  5       nUR                  nUR
                  R                  nUR                  5        H  u  pgU" Xe5      U-
  nU(       a  XsU'   M  X6	 M!     U$ [        U[        5      (       a  [        UR
                  [        5      (       a%  UR
                  R                  UR                  :X  a  Od[        UR                  R
                  [        5      (       a5  UR                  R
                  R                  U:X  a  UR                  U 5      $ [        $  UR                  U5      nU R                  5       nUR                  nXR                  5       ;  a  U* X8'   U$ XU   :X  a  X8	 U$ X8==   U-  ss'   U$ ! [         a	    [        s $ f = f)zSubtract polynomial p2 from p1.

Examples
========

>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.rings import ring

>>> _, x, y = ring('x, y', ZZ)
>>> p1 = x + y**2
>>> p2 = x*y + y**2
>>> p1 - p2
-x*y + x

)r   r8   r[   r   r   r4   r   rH   rl   r   __rsub__r  r   r   r  r    )	ry  rz  r8   r-  r   r   ro  rp  r  s	            r7   __sub__PolyElement.__sub__  s~     779wwb**%%	A%%C;;##D
L1$aD # HK(($++~664;;;K;Krww;VBGGNNN;;@S@SW[@[{{2&%%	$B 	AB" H	 2; H ERKEH  	"!!	"s   #G GGc                    U R                   n UR                  U5      nUR                  nU  H
  nX   * X4'   M     X1-  nU$ ! [         a	    [        s $ f = f)zn - p1 with n convertible to the coefficient domain.

Examples
========

>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.rings import ring

>>> _, x, y = ring('x, y', ZZ)
>>> p = x + y
>>> 4 - p
-x - y + 4

)r8   r   r   r    r  )ry  rB  r8   r-  r   s        r7   r   PolyElement.__rsub__'  sc     ww		"A 		A8) FAH  	"!!	"s   A AAc                   U R                   nUR                  nU (       a  U(       d  U$ [        XR                  5      (       a  UR                  nUR
                  R                  nUR                  n[        UR                  5       5      nU R                  5        H'  u  pU H  u  pU" X5      nU" X5      X-  -   X<'   M     M)     UR                  5         U$ [        U[        5      (       a  [        UR
                  [        5      (       a%  UR
                  R                   UR                   :X  a  Od[        UR                   R
                  [        5      (       a5  UR                   R
                  R                   U:X  a  UR                  U 5      $ [        $  UR                  U5      nU R                  5        H  u  pX-  nU(       d  M  XU'   M     U$ ! [         a	    [        s $ f = f)zMultiply two polynomials.

Examples
========

>>> from sympy.polys.domains import QQ
>>> from sympy.polys.rings import ring

>>> _, x, y = ring('x, y', QQ)
>>> p1 = x + y
>>> p2 = x - y
>>> p1*p2
x**2 - y**2

)r8   r   r[   r   r   r4   r   rB   rH   ru  rl   r   __rmul__r  r   r    )ry  rz  r8   r-  r   r   r   p2itexp1v1exp2v2r   rp  s                 r7   __mul__PolyElement.__mul__B  sy     wwIIHJJ''%%C;;##D,,L
#DHHJ $HD&t2C ^be3AF !% ' LLNHK(($++~664;;;K;Krww;VBGGNNN;;@S@SW[@[{{2&%%		$B HHJE1dG ' H  	"!!	"s   G G%$G%c                    U R                   R                  nU(       d  U$  UR                   R                  U5      nU R                  5        H  u  p4X-  nU(       d  M  XRU'   M     U$ ! [         a	    [
        s $ f = f)zp2 * p1 with p2 in the coefficient domain of p1.

Examples
========

>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.rings import ring

>>> _, x, y = ring('x, y', ZZ)
>>> p = x + y
>>> 4 * p
4*x + 4*y

)r8   r   r   rH   r    r  )ry  rz  r-  r(  r)  rp  s         r7   r&  PolyElement.__rmul__t  sw     GGLLH		""2&B HHJE1dG ' H  	"!!	"s   A( (A;:A;c                   U R                   nU(       d  U (       a  UR                  $ [        S5      e[        U 5      S:X  ao  [	        U R                  5       5      S   u  p4UR                  nXBR                  R                  :X  a  XEUR                  X15      '   U$ XA-  XRR                  X15      '   U$ [        U5      nUS:  a  [        S5      eUS:X  a  U R                  5       $ US:X  a  U R                  5       $ US:X  a  X R                  5       -  $ [        U 5      S::  a  U R                  U5      $ U R                  U5      $ )zraise polynomial to power `n`

Examples
========

>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.rings import ring

>>> _, x, y = ring('x, y', ZZ)
>>> p = x + y**2
>>> p**3
x**3 + 3*x**2*y**2 + 3*x*y**4 + y**6

z0**0r   r   zNegative exponentr        )r8   r   r   r{   rB   rH   r   r4   r   r   r   square_pow_multinomial_pow_generic)r   rB  r8   r   r   r-  s         r7   __pow__PolyElement.__pow__  s    yyxx ((Y!^

-a0LE		A'16$##E-. H 27##E-.H Fq5011!V99;!V;;= !V%%Y!^((++$$Q''r9   c                    U R                   R                  nU n US-  (       a  X#-  nUS-  nU(       d   U$ UR                  5       nUS-  nM4  )Nr   r  )r8   r   r3  )r   rB  r-  rS   s       r7   r5  PolyElement._pow_generic  sV    IIMM1uCQ
  
AQA r9   c                   [        [        U 5      U5      R                  5       nU R                  R                  nU R                  R
                  nU R                  5       nU R                  R                  R                  nU R                  R                  nU Hp  u  pUn
U	n[        X5       H!  u  nu  pU(       d  M  U" XU5      n
XU-  -  nM#     [        U
5      nUnUR                  X5      U-   nU(       a  XU'   Mg  X;   d  Mn  X}	 Mr     U$ rZ   )r   r{   rH   r8   r   r   r4   r   rG   rz   r   )r   rB  multinomialsr   r   r^  r   r   multinomialmultinomial_coeffproduct_monomproduct_coeffr   r   r   s                  r7   r4  PolyElement._pow_multinomial  s    /D	1=CCE))33YY))


yy$$yy~~.:*K&M-M'*;'>#^e3$3M#$NM!CZ/M (?
 -(E!EHHU)E1E#UK# /;& r9   c                &   U R                   nUR                  nUR                  n[        U R	                  5       5      nUR
                  R                  nUR                  n[        [        U5      5       H;  nXG   nX   n	[        U5       H!  n
XJ   nU" X5      nU" X5      XU   -  -   X,'   M#     M=     UR                  S5      nUR                  nU R                  5        H  u  pU" X5      nU" X5      US-  -   X+'   M     UR                  5         U$ )zsquare of a polynomial

Examples
========

>>> from sympy.polys.rings import ring
>>> from sympy.polys.domains import ZZ

>>> _, x, y = ring('x, y', ZZ)
>>> p = x + y**2
>>> p.square()
x**2 + 2*x*y**2 + y**4

r  )r8   r   r   rB   r  r4   r   r   r{   imul_numrH   ru  )r   r8   r-  r   r  r   r   r   k1pkjk2r   ro  rp  s                  r7   r3  PolyElement.square  s     yyIIeeDIIK {{((s4y!ABB1XW"2*S""X+5  " JJqMeeJJLDAa#BMAqD(AE ! 	
r9   c                   U R                   nU(       d  [        S5      e[        XR                  5      (       a  U R	                  U5      $ [        U[
        5      (       a  [        UR                  [        5      (       a%  UR                  R                   UR                   :X  a  Od[        UR                   R                  [        5      (       a5  UR                   R                  R                   U:X  a  UR                  U 5      $ [        $  UR                  U5      nU R                  U5      U R                  U5      4$ ! [         a	    [        s $ f = fNpolynomial division)r8   ZeroDivisionErrorr[   r   r   rl   r4   r   __rdivmod__r  r   
quo_ground
rem_groundr    ry  rz  r8   s      r7   
__divmod__PolyElement.__divmod__  s    ww#$9::JJ''66":K(($++~664;;;K;Krww;VBGGNNN;;@S@SW[@[~~b))%%	:$B MM"%r}}R'899  	"!!	"s   D; ;EEc                    [         $ rZ   r  rx  s     r7   rL  PolyElement.__rdivmod__(      r9   c                   U R                   nU(       d  [        S5      e[        XR                  5      (       a  U R	                  U5      $ [        U[
        5      (       a  [        UR                  [        5      (       a%  UR                  R                   UR                   :X  a  Od[        UR                   R                  [        5      (       a5  UR                   R                  R                   U:X  a  UR                  U 5      $ [        $  UR                  U5      nU R                  U5      $ ! [         a	    [        s $ f = frI  )r8   rK  r[   r   remrl   r4   r   __rmod__r  r   rN  r    rO  s      r7   __mod__PolyElement.__mod__+  s    ww#$9::JJ''66":K(($++~664;;;K;Krww;VBGGNNN;;@S@SW[@[{{2&%%	%$B ==$$  	"!!	"s   D* *D=<D=c                    [         $ rZ   rS  rx  s     r7   rX  PolyElement.__rmod__A  rU  r9   c                   U R                   nU(       d  [        S5      e[        XR                  5      (       a)  UR                  (       a  XS-  -  $ U R                  U5      $ [        U[        5      (       a  [        UR                  [        5      (       a%  UR                  R                   UR                   :X  a  Od[        UR                   R                  [        5      (       a5  UR                   R                  R                   U:X  a  UR                  U 5      $ [        $  UR                  U5      nU R                  U5      $ ! [         a	    [        s $ f = f)NrJ  r	  )r8   rK  r[   r   r  quorl   r4   r   __rtruediv__r  r   rM  r    rO  s      r7   __truediv__PolyElement.__truediv__D  s    ww#$9::JJ''~~8}$vvbz!K(($++~664;;;K;Krww;VBGGNNN;;@S@SW[@[r**%%	%$B ==$$  	"!!	"s    E EEc                    [         $ rZ   rS  rx  s     r7   r_  PolyElement.__rtruediv__]  rU  r9   c                   ^^^ U R                   R                  mU R                   R                  nUR                  mU R                   R                  mUR
                  (       a
  UUU4S jnU$ UUU4S jnU$ )Nc                R   > U u  p#Uu  pEUT	:X  a  UnOT" X$5      nUb
  UT" X55      4$ g rZ   rX   
	a_lm_a_lc	b_lm_b_lca_lma_lcb_lmb_lcr   
domain_quor   r  s
          r7   term_div'PolyElement._term_div.<locals>.term_divl  s@    &
&
2: E(4E$ *T"888r9   c                d   > U u  p#Uu  pEUT	:X  a  UnOT" X$5      nUb  X5-  (       d
  UT" X55      4$ g rZ   rX   rf  s
          r7   rn  ro  x  sC    &
&
2: E(4E *T"888r9   )r8   r   r4   r^  r   ri  )r   r4   rn  rm  r   r  s      @@@r7   	_term_divPolyElement._term_dive  sX    YY!!!!ZZ
yy--??
 0 
  r9   c                4   U R                   nSn[        U[        5      (       a  SnU/n[        U5      (       d  [	        S5      eU (       d-  U(       a  UR
                  UR
                  4$ / UR
                  4$ U H  nUR                   U:w  d  M  [        S5      e   [        U5      n[        U5       Vs/ s H  obR
                  PM     nnU R                  5       nUR
                  n	U R                  5       n
U Vs/ s H  oR                  5       PM     nnU(       a  SnSnXe:  ay  US:X  as  UR                  5       nU
" XU   4X   X   X      45      nUb6  Uu  nnXv   R                  UU45      Xv'   UR                  X   UU* 45      nSnOUS-  nXe:  a  US:X  a  Ms  U(       d'  UR                  5       nU	R                  XU   45      n	X	 U(       a  M  WUR                  :X  a  X-  n	U(       a  U(       d  UR
                  U	4$ US   U	4$ Xy4$ s  snf s  snf )a  Division algorithm, see [CLO] p64.

fv array of polynomials
   return qv, r such that
   self = sum(fv[i]*qv[i]) + r

All polynomials are required not to be Laurent polynomials.

Examples
========

>>> from sympy.polys.rings import ring
>>> from sympy.polys.domains import ZZ

>>> _, x, y = ring('x, y', ZZ)
>>> f = x**3
>>> f0 = x - y**2
>>> f1 = x - y
>>> qv, r = f.div((f0, f1))
>>> qv[0]
x**2 + x*y**2 + y**4
>>> qv[1]
0
>>> r
y**6

FTrJ  z"self and f must have the same ringr   r   )r8   r[   rl   re   rK  r   r   r{   r   r   rq  r   _iadd_monom_iadd_poly_monomr   )r   fvr8   
ret_singlery   r_   r   qvr-  rrn  fxexpvsdivoccurredr   termexpv1rS   s                     r7   r   PolyElement.div  s   8 yy
b+&&JB2ww#$9::yy$))++499}$Avv~ !EFF  G!&q*Aii*IIKII>>#-/0Rr"R0AK%K1,~~'w%(BE%(O1LM##HE1E--uaj9BE**2551"+>A"#KFA %K1, (MM44/2G! a" 4??"FAyy!|#!uax5L= + 1s   4H;Hc                   U n[        U[        5      (       a  U/n[        U5      (       d  [        S5      eUR                  nUR
                  nUR                  nUR                  nUR                  nUR                  5       nUR                  n	UR                  5       nUR                  n
U(       a  U Hz  nU" XR                  5      nUc  M  Uu  pUR                  5        H.  u  nnU" X5      nU
" UU5      UU-  -
  nU(       d  UU	 M)  UUU'   M0     UR                  5       nUb  UUU   4n	  O=   U	u  nnUU;   a  UU==   U-  ss'   OUUU'   UU	 UR                  5       nUb  UUU   4n	U(       a  M  U$ rI  )r[   rl   re   rK  r8   r4   r   r   rq  LTr   r   rU  r   )r   Gry   r8   r4   r   r   ry  rn  ltfr   gtqrR   rS   mgcgm1c1ltmltcs                        r7   rW  PolyElement.rem  sq   a%%A1vv#$9::vv{{((II;;=ddFFHeec44(>DA"#++-B)"0 T]QrT1! !"$&AbE #0 ..*C!1S6k " S!8cFcMF AcFcFnn&?qv+C5 a8 r9   c                *    U R                  U5      S   $ Nr   )r   )ry   r  s     r7   r^  PolyElement.quo  s    uuQx{r9   c                P    U R                  U5      u  p#U(       d  U$ [        X5      erZ   )r   r"   )ry   r  qry  s       r7   exquoPolyElement.exquo  s$    uuQxH%a++r9   c                    X R                   R                  ;   a  U R                  5       nOU nUu  p4UR                  U5      nUc  XBU'   U$ XT-  nU(       a  XRU'   U$ X#	 U$ )a  add to self the monomial coeff*x0**i0*x1**i1*...
unless self is a generator -- then just return the sum of the two.

mc is a tuple, (monom, coeff), where monomial is (i0, i1, ...)

Examples
========

>>> from sympy.polys.rings import ring
>>> from sympy.polys.domains import ZZ

>>> _, x, y = ring('x, y', ZZ)
>>> p = x**4 + 2*y
>>> m = (1, 2)
>>> p1 = p._iadd_monom((m, 5))
>>> p1
x**4 + 5*x*y**2 + 2*y
>>> p1 is p
True
>>> p = x
>>> p1 = p._iadd_monom((m, 5))
>>> p1
5*x*y**2 + x
>>> p1 is p
False

)r8   r   r   r   )r   mccpselfr   r   rS   s         r7   rt  PolyElement._iadd_monom
  sr    8 99&&&YY[FFJJt9 4L  JA t  Lr9   c                b   U nX3R                   R                  ;   a  UR                  5       nUu  pEUR                  nUR                   R                  R
                  nUR                   R                  nUR                  5        H)  u  pU" X5      nU" X5      X-  -   nU(       a  XU'   M'  X;	 M+     U$ )a  add to self the product of (p)*(coeff*x0**i0*x1**i1*...)
unless self is a generator -- then just return the sum of the two.

mc is a tuple, (monom, coeff), where monomial is (i0, i1, ...)

Examples
========

>>> from sympy.polys.rings import ring
>>> from sympy.polys.domains import ZZ

>>> _, x, y, z = ring('x, y, z', ZZ)
>>> p1 = x**4 + 2*y
>>> p2 = y + z
>>> m = (1, 2, 3)
>>> p1 = p1._iadd_poly_monom(p2, (m, 3))
>>> p1
x**4 + 3*x*y**3*z**3 + 3*x*y**2*z**4 + 2*y

)r8   r   r   r   r4   r   r   rH   )r   rz  r  ry  rR   rS   r   r   r   ro  rp  kar   s                r7   ru  PolyElement._iadd_poly_monom6  s    * """Bffww~~""ww++HHJDAa#BMAC'E2F  	r9   c                   ^ U R                   R                  U5      mU (       d  [        $ TS:  a  g[        U4S jU R	                  5        5       5      $ )zx
The leading degree in ``x`` or the main variable.

Note that the degree of 0 is negative infinity (``float('-inf')``)

r   c              3  ,   >#    U  H	  oT   v   M     g 7frZ   rX   r^   r   r   s     r7   r`   %PolyElement.degree.<locals>.<genexpr>i       <^EQx^   )r8   r
  r   rx   r  ry   xr   s     @r7   degreePolyElement.degree[  ?     FFLLOKU<Q\\^<<<r9   c                    U (       d  [         4U R                  R                  -  $ [        [	        [
        [        [        U R                  5       6 5      5      5      $ )z{
A tuple containing leading degrees in all variables.

Note that the degree of 0 is negative infinity (``float('-inf')``)

)	r   r8   r   rz   rC   rx   rB   rG   r  r  s    r7   degreesPolyElement.degreesk  >     7166<<''S$sALLN';"<=>>r9   c                   ^ U R                   R                  U5      mU (       d  [        $ TS:  a  g[        U4S jU R	                  5        5       5      $ )zu
The tail degree in ``x`` or the main variable.

Note that the degree of 0 is negative infinity (``float('-inf')``)

r   c              3  ,   >#    U  H	  oT   v   M     g 7frZ   rX   r  s     r7   r`   *PolyElement.tail_degree.<locals>.<genexpr>  r  r  )r8   r
  r   minr  r  s     @r7   tail_degreePolyElement.tail_degreew  r  r9   c                    U (       d  [         4U R                  R                  -  $ [        [	        [
        [        [        U R                  5       6 5      5      5      $ )zx
A tuple containing tail degrees in all variables.

Note that the degree of 0 is negative infinity (``float('-inf')``)

)	r   r8   r   rz   rC   r  rB   rG   r  r  s    r7   tail_degreesPolyElement.tail_degrees  r  r9   c                H    U (       a  U R                   R                  U 5      $ g)a  Leading monomial tuple according to the monomial ordering.

Examples
========

>>> from sympy.polys.rings import ring
>>> from sympy.polys.domains import ZZ

>>> _, x, y, z = ring('x, y, z', ZZ)
>>> p = x**4 + x**3*y + x**2*z**2 + z**7
>>> p.leading_expv()
(4, 0, 0)

N)r8   r   r   s    r7   r   PolyElement.leading_expv  s     99))$//r9   c                `    U R                  XR                  R                  R                  5      $ rZ   )r   r8   r4   r   r   r   s     r7   
_get_coeffPolyElement._get_coeff  s!    xxii..3344r9   c                   US:X  a%  U R                  U R                  R                  5      $ [        XR                  R                  5      (       ac  [        UR                  5       5      n[        U5      S:X  a;  US   u  p4X@R                  R                  R                  :X  a  U R                  U5      $ [        SU-  5      e)a|  
Returns the coefficient that stands next to the given monomial.

Parameters
==========

element : PolyElement (with ``is_monomial = True``) or 1

Examples
========

>>> from sympy.polys.rings import ring
>>> from sympy.polys.domains import ZZ

>>> _, x, y, z = ring("x,y,z", ZZ)
>>> f = 3*x**2*y - x*y*z + 7*z**3 + 23

>>> f.coeff(x**2*y)
3
>>> f.coeff(x*y)
0
>>> f.coeff(1)
23

r   r   zexpected a monomial, got %s)r  r8   r   r[   r   rB   rU  r{   r4   r   r   )r   r   r^  r   r   s        r7   r   PolyElement.coeff  s    4 a<??499#7#78811**,-E5zQ$QxII,,000??5116@AAr9   c                L    U R                  U R                  R                  5      $ )z"Returns the constant coefficient. )r  r8   r   r   s    r7   r  PolyElement.const  s    tyy3344r9   c                @    U R                  U R                  5       5      $ rZ   )r  r   r   s    r7   r  PolyElement.LC  s    t00233r9   c                X    U R                  5       nUc  U R                  R                  $ U$ rZ   )r   r8   r   r  s     r7   LMPolyElement.LM  s*      "<99'''Kr9   c                    U R                   R                  nU R                  5       nU(       a"  U R                   R                  R                  X'   U$ )z
Leading monomial as a polynomial element.

Examples
========

>>> from sympy.polys.rings import ring
>>> from sympy.polys.domains import ZZ

>>> _, x, y = ring('x, y', ZZ)
>>> (3*x*y + y**2).leading_monom()
x*y

)r8   r   r   r4   r   r   r-  r   s      r7   leading_monomPolyElement.leading_monom  s>     IINN  "ii&&**AGr9   c                    U R                  5       nUc6  U R                  R                  U R                  R                  R                  4$ XR                  U5      4$ rZ   )r   r8   r   r4   r   r  r  s     r7   r  PolyElement.LT  sL      "<II(($))*:*:*?*?@@//$/00r9   c                d    U R                   R                  nU R                  5       nUb  X   X'   U$ )zLeading term as a polynomial element.

Examples
========

>>> from sympy.polys.rings import ring
>>> from sympy.polys.domains import ZZ

>>> _, x, y = ring('x, y', ZZ)
>>> (3*x*y + y**2).leading_term()
3*x*y

)r8   r   r   r  s      r7   leading_termPolyElement.leading_term  s3     IINN  "jAGr9   c                   ^ Tc  U R                   R                  mO[        R                  " T5      mT[        L a  [        US SS9$ [        UU4S jSS9$ )Nc                    U S   $ r  rX   )r   s    r7   rr   %PolyElement._sorted.<locals>.<lambda>  s    qr9   T)rw   reversec                   > T" U S   5      $ r  rX   )r   r5   s    r7   rr   r    s    uQxr9   )r8   r5   r~   r}   r   sorted)r   rW   r5   s     `r7   _sortedPolyElement._sorted  sL    =IIOOE''.EC<##94HH##@$OOr9   c                Z    U R                  U5       VVs/ s H  u  p#UPM	     snn$ s  snnf )a  Ordered list of polynomial coefficients.

Parameters
==========

order : :class:`~.MonomialOrder` or coercible, optional

Examples
========

>>> from sympy.polys.rings import ring
>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.orderings import lex, grlex

>>> _, x, y = ring("x, y", ZZ, lex)
>>> f = x*y**7 + 2*x**2*y**3

>>> f.coeffs()
[2, 1]
>>> f.coeffs(grlex)
[1, 2]

r^  )r   r5   _r   s       r7   rO   PolyElement.coeffs  s)    0 (,zz%'8:'881'8:::   'c                Z    U R                  U5       VVs/ s H  u  p#UPM	     snn$ s  snnf )a  Ordered list of polynomial monomials.

Parameters
==========

order : :class:`~.MonomialOrder` or coercible, optional

Examples
========

>>> from sympy.polys.rings import ring
>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.orderings import lex, grlex

>>> _, x, y = ring("x, y", ZZ, lex)
>>> f = x*y**7 + 2*x**2*y**3

>>> f.monoms()
[(2, 3), (1, 7)]
>>> f.monoms(grlex)
[(1, 7), (2, 3)]

r  )r   r5   r   r  s       r7   monomsPolyElement.monoms5  s)    0 (,zz%'8:'885'8:::r  c                T    U R                  [        U R                  5       5      U5      $ )a  Ordered list of polynomial terms.

Parameters
==========

order : :class:`~.MonomialOrder` or coercible, optional

Examples
========

>>> from sympy.polys.rings import ring
>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.orderings import lex, grlex

>>> _, x, y = ring("x, y", ZZ, lex)
>>> f = x*y**7 + 2*x**2*y**3

>>> f.terms()
[((2, 3), 2), ((1, 7), 1)]
>>> f.terms(grlex)
[((1, 7), 1), ((2, 3), 2)]

)r  rB   rH   )r   r5   s     r7   r^  PolyElement.termsO  s     0 ||D.66r9   c                4    [        U R                  5       5      $ )z,Iterator over coefficients of a polynomial. )iterrE   r   s    r7   
itercoeffsPolyElement.itercoeffsi      DKKM""r9   c                4    [        U R                  5       5      $ )z)Iterator over monomials of a polynomial. )r  r  r   s    r7   r  PolyElement.itermonomsm      DIIK  r9   c                4    [        U R                  5       5      $ )z%Iterator over terms of a polynomial. )r  rH   r   s    r7   rU  PolyElement.itertermsq      DJJL!!r9   c                4    [        U R                  5       5      $ )z+Unordered list of polynomial coefficients. )rB   rE   r   s    r7   
listcoeffsPolyElement.listcoeffsu  r  r9   c                4    [        U R                  5       5      $ )z(Unordered list of polynomial monomials. )rB   r  r   s    r7   
listmonomsPolyElement.listmonomsy  r  r9   c                4    [        U R                  5       5      $ )z$Unordered list of polynomial terms. rt  r   s    r7   	listtermsPolyElement.listterms}  r  r9   c                    X R                   R                  ;   a  X-  $ U(       d  U R                  5         gU  H  nX==   U-  ss'   M     U $ )a  multiply inplace the polynomial p by an element in the
coefficient ring, provided p is not one of the generators;
else multiply not inplace

Examples
========

>>> from sympy.polys.rings import ring
>>> from sympy.polys.domains import ZZ

>>> _, x, y = ring('x, y', ZZ)
>>> p = x + y**2
>>> p1 = p.imul_num(3)
>>> p1
3*x + 3*y**2
>>> p1 is p
True
>>> p = x
>>> p1 = p.imul_num(3)
>>> p1
3*x
>>> p1 is p
False

N)r8   r   clear)r-  rS   r   s      r7   rB  PolyElement.imul_num  sD    4    3JGGICFaKF r9   c                    U R                   R                  nUR                  nUR                  nU R	                  5        H  nU" X$5      nM     U$ )z*Returns GCD of polynomial's coefficients. )r8   r4   r   r   r  )ry   r4   contr   r   s        r7   r  PolyElement.content  sB    {{jj\\^Et#D $ r9   c                F    U R                  5       nXR                  U5      4$ )z,Returns content and a primitive polynomial. )r  rM  )ry   r  s     r7   	primitivePolyElement.primitive  s    yy{\\$'''r9   c                J    U (       d  U $ U R                  U R                  5      $ )z5Divides all coefficients by the leading coefficient. )rM  r  r  s    r7   monicPolyElement.monic  s    H<<%%r9   c                    U(       d  U R                   R                  $ U R                  5        VVs/ s H  u  p#X#U-  4PM     nnnU R                  U5      $ s  snnf rZ   )r8   r   rU  rO  )ry   r  r   r   r^  s        r7   r  PolyElement.mul_ground  sJ    66;;78{{}F}|u5'"}FuuU| Gs   Ac                    U R                   R                  nU R                  5        VVs/ s H  u  p4U" X15      U4PM     nnnU R                  U5      $ s  snnf rZ   )r8   r   rH   rO  )ry   r   r   f_monomf_coeffr^  s         r7   	mul_monomPolyElement.mul_monom  sQ    vv**RSRYRYR[]R[>Ng</9R[]uuU| ^s   Ac                \   Uu  p#U (       a  U(       d  U R                   R                  $ X R                   R                  :X  a  U R                  U5      $ U R                   R                  nU R                  5        VVs/ s H  u  pVU" XR5      Xc-  4PM     nnnU R                  U5      $ s  snnf rZ   )r8   r   r   r  r   rH   rO  )ry   r}  r   r   r   r   r  r^  s           r7   mul_termPolyElement.mul_term  s    66;;ff'''<<&&vv**XYX_X_XacXaDTG</?XacuuU| ds   <B(c           	        U R                   R                  nU(       d  [        S5      eU (       a  XR                  :X  a  U $ UR                  (       a8  UR
                  nU R                  5        VVs/ s H  u  pEXC" XQ5      4PM     nnnO3U R                  5        VVs/ s H  u  pEXQ-  (       a  M  XEU-  4PM     nnnU R                  U5      $ s  snnf s  snnf rI  )r8   r4   rK  r   ri  r^  rU  rO  )ry   r  r4   r^  r   r   r^  s          r7   rM  PolyElement.quo_ground  s    #$9::AOH??**CABPuc%m,EPE>?kkm`mleTYT])uqj)mE`uuU|	 Q`s   1CC0
Cc                   Uu  p#U(       d  [        S5      eU (       d  U R                  R                  $ X R                  R                  :X  a  U R	                  U5      $ U R                  5       nU R                  5        Vs/ s H
  oT" XQ5      PM     nnU R                  U Vs/ s H	  oUc  M  UPM     sn5      $ s  snf s  snf rI  )rK  r8   r   r   rM  rq  rU  rO  )ry   r}  r   r   rn  tr^  s          r7   quo_termPolyElement.quo_term  s    #$9::66;;ff'''<<&&;;=-.[[]<](1#]<uu%:%Qq%:;; =:s    B9"B>,B>c                j   U R                   R                  R                  (       a>  / nU R                  5        H'  u  p4XA-  nXAS-  :  a  XA-
  nUR	                  X445        M)     O(U R                  5        VVs/ s H  u  p4X4U-  4PM     nnnU R                  U5      nUR                  5         U$ s  snnf )Nr  )r8   r4   is_ZZrU  r   rO  ru  )ry   r-  r^  r   r   r   s         r7   trunc_groundPolyElement.trunc_ground  s    66==E !	6>!IEe^, !. >?[[]L]\Uuai(]ELuuU|	 Ms   7B/c                    U nUR                  5       nUR                  5       nUR                  R                  R                  X45      nUR	                  U5      nUR	                  U5      nXRU4$ rZ   )r  r8   r4   r   rM  )r   r  ry   fcgcr   s         r7   extract_groundPolyElement.extract_ground  s[    YY[YY[ffmm'LLLLqyr9   c                    U (       d   U R                   R                  R                  $ U R                   R                  R                  nU" U R	                  5        Vs/ s H
  o2" U5      PM     sn5      $ s  snf rZ   )r8   r4   r   absr  )ry   	norm_func
ground_absr   s       r7   _normPolyElement._norm  sT    66==%%%**JallnNnUz%0nNOONs   A4c                ,    U R                  [        5      $ rZ   )r  rx   r  s    r7   max_normPolyElement.max_norm      wws|r9   c                ,    U R                  [        5      $ rZ   )r  rD   r  s    r7   l1_normPolyElement.l1_norm  r  r9   c                \   U R                   nU /[        U5      -   nS/UR                  -  nU H>  nUR                  5        H'  n[	        U5       H  u  px[        XG   U5      XG'   M     M)     M@     [	        U5       H  u  pyU	(       a  M  SXG'   M     [        U5      n[        S U 5       5      (       a  XC4$ / n
U Hg  nUR                  nUR                  5        H3  u  p[        X5       VVs/ s H	  u  p~X~-  PM     nnnX[        U5      '   M5     U
R                  U5        Mi     XJ4$ s  snnf )Nr   r   c              3  *   #    U  H	  oS :H  v   M     g7fr  rX   )r^   rq   s     r7   r`   &PolyElement.deflate.<locals>.<genexpr>0  s     !q!Avqs   )r8   rB   r   r  r  r   rz   re   r   rU  rG   r   )ry   r  r8   rT   Jr-  r   r   rR   rq   HhIr   rE  Ns                   r7   deflatePolyElement.deflate  s   vvd1gC

NA%e,DAa=AD - ( 
 aLDA1 ! !H!q!!!8OA		AKKM),Q4af4#%( * HHQK  t 5s   ,D(
c                    U R                   R                  nU R                  5        H3  u  p4[        X15       VVs/ s H	  u  pVXV-  PM     nnnXB[	        U5      '   M5     U$ s  snnf rZ   )r8   r   rU  rG   rz   )ry   r&  r   r)  r   r   rE  r*  s           r7   inflatePolyElement.inflate@  sT    vv{{HA"%a)-)$!!#)A-"qN &  .s   A c                f   U nUR                   R                  nUR                  (       d5  UR                  5       u  pBUR                  5       u  pQUR	                  XE5      nX!-  R                  UR                  U5      5      nUR                  (       d  UR                  W5      $ UR                  5       $ rZ   )	r8   r4   ri  r  r   r^  r   r  r  )r   r  ry   r4   r  r  rS   r(  s           r7   r   PolyElement.lcmI  s|    KKMEBKKMEB

2"ASIIaeeAh<<?"779r9   c                *    U R                  U5      S   $ r  )	cofactorsry   r  s     r7   r   PolyElement.gcdY  s    {{1~a  r9   c                "   U (       d!  U(       d  U R                   R                  nX"U4$ U (       d  U R                  U5      u  p4nX4U4$ U(       d  UR                  U 5      u  p5nX4U4$ [        U 5      S:X  a  U R	                  U5      u  p4nX4U4$ [        U5      S:X  a  UR	                  U 5      u  p5nX4U4$ U R                  U5      u  nu  pU R                  U5      u  p4nUR                  U5      UR                  U5      UR                  U5      4$ r   )r8   r   	_gcd_zeror{   
_gcd_monomr+  _gcdr.  )ry   r  r   r(  cffcfgr&  s          r7   r3  PolyElement.cofactors\  s    66;;Dt##++a.KAC3;++a.KAC3;Vq[,,q/KAC3;Vq[,,q/KAC3;IIaL	6AffQi		!ckk!nckk!n==r9   c                    U R                   R                  U R                   R                  p2UR                  (       a  XU4$ U* X2* 4$ rZ   )r8   r   r   r  )ry   r  r   r   s       r7   r7  PolyElement._gcd_zeror  s:    FFJJTC<2tT>!r9   c                2   U R                   nUR                  R                  nUR                  R                  nUR                  nUR
                  n[        U R                  5       5      S   u  pxXxpUR                  5        H  u  pU" X5      n	U" X5      n
M     U R                  X4/5      nU R                  U" Xy5      U" X5      4/5      nU R                  UR                  5        VVs/ s H  u  pU" X5      U" X5      4PM     snn5      nXU4$ s  snnf r  )	r8   r4   r   r^  r   r   rB   rU  rO  )ry   r  r8   
ground_gcd
ground_quor   r   mfcf_mgcd_cgcdr  r  r(  r:  r;  s                   r7   r8  PolyElement._gcd_monomy  s    vv[[__
[[__
((**akkm$Q'ukkmFB +Eu)E $ EEE>"#eemB.
20EFGHeeUVU`U`UbcUb62mB.
20EFUbcds{ ds   +D
c                    U R                   nUR                  R                  (       a  U R                  U5      $ UR                  R                  (       a  U R                  U5      $ UR                  X5      $ rZ   )r8   r4   is_QQ_gcd_QQr  _gcd_ZZdmp_inner_gcd)ry   r  r8   s      r7   r9  PolyElement._gcd  sR    vv;;99Q<[[99Q<%%a++r9   c                    [        X5      $ rZ   r   r4  s     r7   rJ  PolyElement._gcd_ZZ  s    a|r9   c                d   U nUR                   nUR                  UR                  R                  5       S9nUR	                  5       u  pRUR	                  5       u  paUR                  U5      nUR                  U5      nUR                  U5      u  pxn	UR                  U5      nUR                  UR                  5       pzUR                  U5      R                  UR                  R                  X5      5      nU	R                  U5      R                  UR                  R                  X5      5      n	XxU	4$ )Nr  )r8   r   r4   rk  rq  r_  rJ  r  r  r  r^  )r   r  ry   r8   r]  rC  r  r(  r:  r;  rS   s              r7   rI  PolyElement._gcd_QQ  s    vv::T[[%9%9%;:<  JJx JJx iilJJtttQWWY1ll4 ++DKKOOA,BCll4 ++DKKOOA,BCs{r9   c                @   U nUR                   nU(       d  X#R                  4$ UR                  nUR                  (       a  UR                  (       d  UR                  U5      u  pVnOUR                  UR                  5       S9nUR                  5       u  pUR                  5       u  pUR                  U5      nUR                  U5      nUR                  U5      u  pVnUR                  R                  X5      u  pZn	UR                  U5      nUR                  U5      nUR                  U
5      nUR                  U	5      nUR                  5       nXR                  :X  a  XgpvXg4$ XR                  * :X  a  U* U* pvXg4$ UR                  U5      nUR                  U5      nXg4$ )z
Cancel common factors in a rational function ``f/g``.

Examples
========

>>> from sympy.polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)

>>> (2*x**2 - 2).cancel(x**2 - 2*x + 1)
(2*x + 2, x - 1)

r  )r8   r   r4   ri  rj  r3  r   rk  rq  r_  r  canonical_unit)r   r  ry   r8   r4   r  r-  r  r]  cqcpus               r7   cancelPolyElement.cancel  sf    vvhh;F$9$9kk!nGA!zz):z;HNN$EBNN$EB

8$A

8$Akk!nGA! 11"9IA2

4 A

4 AR AR A
 

?q t ::+2rq
 t QAQAtr9   c                d    U R                   R                  nUR                  U R                  5      $ rZ   )r8   r4   rR  r  )ry   r4   s     r7   rR  PolyElement.canonical_unit  s$    $$QTT**r9   c                   U R                   nUR                  U5      nUR                  U5      nUR                  nU R	                  5        H9  u  pgXc   (       d  M  UR                  Xd5      nUR                  XvU   -  5      XX'   M;     U$ )zComputes partial derivative in ``x``.

Examples
========

>>> from sympy.polys.rings import ring
>>> from sympy.polys.domains import ZZ

>>> _, x, y = ring("x,y", ZZ)
>>> p = x + x**2*y**3
>>> p.diff(x)
2*x*y**3 + 1

)r8   r
  r   r   rU  r   r   )	ry   r  r8   r   rR   r  r   r   es	            r7   diffPolyElement.diff  sy     vvJJqM"II;;=KDww&&t/u!W}5 ) r9   c                ,   S[        U5      s=:  a  U R                  R                  ::  a;  O  O8U R                  [	        [        U R                  R                  U5      5      5      $ [        SU R                  R                  < S[        U5      < 35      e)Nr   z expected at least 1 and at most z values, got )r{   r8   r   evaluaterB   rG   r2   r   )ry   rE   s     r7   rJ  PolyElement.__call__ 	  sb    s6{*affll*::d3qvv{{F#;<==TUTZTZT`T`beflbmnoor9   c                   U n[        U[        5      (       ab  Uc_  US   USS  su  pBnUR                  XB5      nU(       d  U$ U VVs/ s H  u  pRUR                  U5      U4PM     nnnUR                  U5      $ UR                  nUR                  U5      nUR                  R                  U5      nUR                  S:X  a<  UR                  R                  nUR                  5        H  u  u  pXX)-  -  -  nM     U$ UR                  U5      R                  nUR                  5        HF  u  pX   US U XS-   S  -   pXU	-  -  n
X;   a  XU   -   n
U
(       a  XU'   M5  X	 M9  U
(       d  MB  XU'   MH     U$ s  snnf )Nr   r   )r[   rB   r_  r  r8   r
  r4   r   r   r   rU  )r   r  rp   ry   XYr8   r   resultrB  r   r   r   s                r7   r_  PolyElement.evaluate	  sg   a19!aeIFQA

1 A3461!qvvay!n16zz!}$vvJJqMKK"::?[[%%F {{}*$  - M99Q<$$D ! 8U2AYst%<5d
=!K/E&+U Ku&+U !. KA 7s   E5c                n   U n[        U[        5      (       a!  Uc  U H  u  pBUR                  XB5      nM     U$ UR                  nUR	                  U5      nUR
                  R                  U5      nUR                  S:X  aK  UR
                  R                  nUR                  5        H  u  u  pXyX(-  -  -  nM     UR                  U5      $ UR                  n
UR                  5        HI  u  pX   US U S-   XS-   S  -   pXU-  -  n	X;   a  XU   -   n	U	(       a  XU'   M8  X	 M<  U	(       d  ME  XU'   MK     U
$ )Nr   rm   )r[   rB   subsr8   r
  r4   r   r   r   rU  r   )r   r  rp   ry   rb  r8   r   rd  rB  r   r   r   s               r7   rg  PolyElement.subs2	  s'   a19FF1L HvvJJqMKK"::?[[%%F {{}*$  - ??6**99D ! 8U2AY%5cd%C5d
=!K/E&+U Ku&+U !. Kr9   c                  ^^^ U R                  5       nUR                  nUR                  nU(       d  XR                  / 4$ [	        U5       Vs/ s H  oBR                  US-   5      PM     snm0 mUU4S jn[        [	        US-
  5      5      n[        [	        USS5      5      nUR                  nU(       a  Su  pn[        UR                  5       5       HM  u  nu  mn[        U4S jU 5       5      (       d  M%  [        S [        UT5       5       5      nX:  d  MH  UTUpn	MO     U	S:w  a  XsmnOO~/ n[        TTSS S	-   5       H  u  nnUR                  UU-
  5        M     XR                  [        U5      U5      -  nUn[        U5       H  u  pCUU" XC5      -  nM     UU-  nU(       a  M  [        [        UR                  T5      5      nXU4$ s  snf )
a  
Rewrite *self* in terms of elementary symmetric polynomials.

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

If this :py:class:`~.PolyElement` belongs to a ring of $n$ variables,
we can try to write it as a function of the elementary symmetric
polynomials on $n$ variables. We compute a symmetric part, and a
remainder for any part we were not able to symmetrize.

Examples
========

>>> from sympy.polys.rings import ring
>>> from sympy.polys.domains import ZZ
>>> R, x, y = ring("x,y", ZZ)

>>> f = x**2 + y**2
>>> f.symmetrize()
(x**2 - 2*y, 0, [(x, x + y), (y, x*y)])

>>> f = x**2 - y**2
>>> f.symmetrize()
(x**2 - 2*y, -2*y**2, [(x, x + y), (y, x*y)])

Returns
=======

Triple ``(p, r, m)``
    ``p`` is a :py:class:`~.PolyElement` that represents our attempt
    to express *self* as a function of elementary symmetric
    polynomials. Each variable in ``p`` stands for one of the
    elementary symmetric polynomials. The correspondence is given
    by ``m``.

    ``r`` is the remainder.

    ``m`` is a list of pairs, giving the mapping from variables in
    ``p`` to elementary symmetric polynomials.

    The triple satisfies the equation ``p.compose(m) + r == self``.
    If the remainder ``r`` is zero, *self* is symmetric. If it is
    nonzero, we were not able to represent *self* as symmetric.

See Also
========

sympy.polys.polyfuncs.symmetrize

References
==========

.. [1] Lauer, E. Algorithms for symmetrical polynomials, Proc. 1976
    ACM Symp. on Symbolic and Algebraic Computing, NY 242-247.
    https://dl.acm.org/doi/pdf/10.1145/800205.806342

r   c                6   > X4T;  a  TU    U-  TX4'   TX4   $ rZ   rX   )r   rB  poly_powersrT   s     r7   get_poly_power.PolyElement.symmetrize.<locals>.get_poly_power	  s.    v[(&+AhkQF#v&&r9   r   r	  )r	  NNc              3  @   >#    U  H  nTU   TUS -      :  v   M     g7fr  rX   )r^   r   r   s     r7   r`   )PolyElement.symmetrize.<locals>.<genexpr>	  s"     AAuQx5Q</rA  c              3  .   #    U  H  u  pX-  v   M     g 7frZ   rX   )r^   rB  rR   s      r7   r`   ro  	  s      E1D1Ds   Nrm   )r   r8   r   r   r   rC  rB   r  r^  re   rx   rG   r   r   rz   r2   )r   ry   r8   rB  r   rl  r  weights	symmetric_height_monom_coeffr   height	exponentsr  m2productr  r   rk  rT   s                      @@@r7   
symmetrizePolyElement.symmetrizeY	  s   v IIKvvJJii##388<8a$$QqS)8<	'
 uQU|$uQ2'II	&4#GV%.qwwy%9!>E5AAAA  EWe1D EEF'28% &: "}%uIeU12Y%56B  b) 7 uY'7??IG!),>!// -LA1 a4 s499e,-W$$S =s   Gc                  ^ U R                   nUR                  n[        [        UR                  [        UR                  5      5      5      mUb  X4/nO^[        U[        5      (       a  [        U5      nO=[        U[        5      (       a  [        UR                  5       U4S jS9nO[        S5      e[        U5       H   u  nu  pTU   UR                  U5      4XV'   M"     U R                  5        H`  u  p[        U5      nUR                  n
U H  u  pX   SsoU'   U(       d  M  XU-  -  n
M      U
R!                  [#        U5      U	45      n
XJ-  nMb     U$ )Nc                   > TU S      $ r  rX   )ro  gens_maps    r7   rr   %PolyElement.compose.<locals>.<lambda>	  s    x!~r9   rv   z9expected a generator, value pair a sequence of such pairsr   )r8   r   rF   rG   r2   r   r   r[   rB   r  rH   r   r  r   rU  r   r  rz   )ry   r  rp   r8   r   replacementsro  r  r   r   subpolyr   rB  r~  s                @r7   r9  PolyElement.compose	  s+   vvyyDIIuTZZ'89:=F8L!T""#AwAt$$%aggi5MN !\]]"<0IAv'{DMM!,<=LO 1 KKMLEKEhhG$#h81!tOG %
 &&ee'<=GOD * r9   c                   U nUR                   R                  U5      nUR                  5        VVs/ s H  u  pVXT   U:X  d  M  XV4PM     nnnU(       d  UR                   R                  $ [	        U6 u  pU Vs/ s H  oUSU S-   XTS-   S -   PM     nnUR                   R                  [        [	        X5      5      5      $ s  snnf s  snf )am  
Coefficient of ``self`` with respect to ``x**deg``.

Treating ``self`` as a univariate polynomial in ``x`` this finds the
coefficient of ``x**deg`` as a polynomial in the other generators.

Parameters
==========

x : generator or generator index
    The generator or generator index to compute the expression for.
deg : int
    The degree of the monomial to compute the expression for.

Returns
=======

:py:class:`~.PolyElement`
    The coefficient of ``x**deg`` as a polynomial in the same ring.

Examples
========

>>> from sympy.polys import ring, ZZ
>>> R, x, y, z = ring("x, y, z", ZZ)

>>> p = 2*x**4 + 3*y**4 + 10*z**2 + 10*x*z**2
>>> deg = 2
>>> p.coeff_wrt(2, deg) # Using the generator index
10*x + 10
>>> p.coeff_wrt(z, deg) # Using the generator
10*x + 10
>>> p.coeff(z**2) # shows the difference between coeff and coeff_wrt
10

See Also
========

coeff, coeffs

Nrm   r   )r8   r
  rU  r   rG   rI   rF   )
r   r  degr-  r   rR   rS   r^  r  rO   s
             r7   	coeff_wrtPolyElement.coeff_wrt	  s    T FFLLO$%KKMAMDAQTS[!MA66;;e4:;FqBQ%$,q56*F;vvS%8 9:: B <s   C C 8Cc                   U nUR                   R                  U5      nUR                  U5      nUR                  U5      nUS:  a  [        S5      eX4pvXE:  a  U$ XE-
  S-   nUR	                  X%5      n	UR                   R
                  U   n
 UR	                  X'5      nXu-
  US-
  pXi-  nX-  X-  -  nX-
  nUR                  U5      nXu:  a  OMC  X-  nXo-  $ )af  
Pseudo-remainder of the polynomial ``self`` with respect to ``g``.

The pseudo-quotient ``q`` and pseudo-remainder ``r`` with respect to
``z`` when dividing ``f`` by ``g`` satisfy ``m*f = g*q + r``,
where ``deg(r,z) < deg(g,z)`` and
``m = LC(g,z)**(deg(f,z) - deg(g,z)+1)``.

See :meth:`pdiv` for explanation of pseudo-division.


Parameters
==========

g : :py:class:`~.PolyElement`
    The polynomial to divide ``self`` by.
x : generator or generator index, optional
    The main variable of the polynomials and default is first generator.

Returns
=======

:py:class:`~.PolyElement`
    The pseudo-remainder polynomial.

Raises
======

ZeroDivisionError : If ``g`` is the zero polynomial.

Examples
========

>>> from sympy.polys import ring, ZZ
>>> R, x, y = ring("x, y", ZZ)

>>> f = x**2 + x*y
>>> g = 2*x + 2
>>> f.prem(g) # first generator is chosen by default if it is not given
-4*y + 4
>>> f.rem(g) # shows the differnce between prem and rem
x**2 + x*y
>>> f.prem(g, y) # generator is given
0
>>> f.prem(g, 1) # generator index is given
0

See Also
========

pdiv, pquo, pexquo, sympy.polys.domains.ring.Ring.rem

r   rJ  r   r8   r
  r  rK  r  r2   )r   r  r  ry   dfdgry  drr*  lc_gxplc_rrE  Rr  rS   s                   r7   premPolyElement.prem
  s    l FFLLOXXa[XXa[6#$9::27HGaK{{1!VV[[^;;q%D7AEqA25 AA!Bw  Iur9   c                   U nUR                   R                  U5      nUR                  U5      nUR                  U5      nUS:  a  [        S5      eX#UpnXE:  a  Xg4$ XE-
  S-   n	UR	                  X%5      n
UR                   R
                  U   n UR	                  X(5      nX-
  U	S-
  pXj-  nXX-  -  -   nXz-  nX-  X-  -  nUU-
  nUR                  U5      nX:  a  OMQ  X-  nUU-  nUU-  nXg4$ )a	  
Computes the pseudo-division of the polynomial ``self`` with respect to ``g``.

The pseudo-division algorithm is used to find the pseudo-quotient ``q``
and pseudo-remainder ``r`` such that ``m*f = g*q + r``, where ``m``
represents the multiplier and ``f`` is the dividend polynomial.

The pseudo-quotient ``q`` and pseudo-remainder ``r`` are polynomials in
the variable ``x``, with the degree of ``r`` with respect to ``x``
being strictly less than the degree of ``g`` with respect to ``x``.

The multiplier ``m`` is defined as
``LC(g, x) ^ (deg(f, x) - deg(g, x) + 1)``,
where ``LC(g, x)`` represents the leading coefficient of ``g``.

It is important to note that in the context of the ``prem`` method,
multivariate polynomials in a ring, such as ``R[x,y,z]``, are treated
as univariate polynomials with coefficients that are polynomials,
such as ``R[x,y][z]``. When dividing ``f`` by ``g`` with respect to the
variable ``z``, the pseudo-quotient ``q`` and pseudo-remainder ``r``
satisfy ``m*f = g*q + r``, where ``deg(r, z) < deg(g, z)``
and ``m = LC(g, z)^(deg(f, z) - deg(g, z) + 1)``.

In this function, the pseudo-remainder ``r`` can be obtained using the
``prem`` method, the pseudo-quotient ``q`` can
be obtained using the ``pquo`` method, and
the function ``pdiv`` itself returns a tuple ``(q, r)``.


Parameters
==========

g : :py:class:`~.PolyElement`
    The polynomial to divide ``self`` by.
x : generator or generator index, optional
    The main variable of the polynomials and default is first generator.

Returns
=======

:py:class:`~.PolyElement`
    The pseudo-division polynomial (tuple of ``q`` and ``r``).

Raises
======

ZeroDivisionError : If ``g`` is the zero polynomial.

Examples
========

>>> from sympy.polys import ring, ZZ
>>> R, x, y = ring("x, y", ZZ)

>>> f = x**2 + x*y
>>> g = 2*x + 2
>>> f.pdiv(g) # first generator is chosen by default if it is not given
(2*x + 2*y - 2, -4*y + 4)
>>> f.div(g) # shows the difference between pdiv and div
(0, x**2 + x*y)
>>> f.pdiv(g, y) # generator is given
(2*x**3 + 2*x**2*y + 6*x**2 + 2*x*y + 8*x + 4, 0)
>>> f.pdiv(g, 1) # generator index is given
(2*x**3 + 2*x**2*y + 6*x**2 + 2*x*y + 8*x + 4, 0)

See Also
========

prem
    Computes only the pseudo-remainder more efficiently than
    `f.pdiv(g)[1]`.
pquo
    Returns only the pseudo-quotient.
pexquo
    Returns only an exact pseudo-quotient having no remainder.
div
    Returns quotient and remainder of f and g polynomials.

r   rJ  r   r  )r   r  r  ry   r  r  r  ry  r  r*  r  r  r  rE  Qr  r  rS   s                     r7   pdivPolyElement.pdivv
  s   ` FFLLOXXa[XXa[6#$9::b74KGaK{{1!VV[[^;;q%D7AEqA25L AA25 AAA!Bw% ( GEEtr9   c                .    U nUR                  X5      S   $ )a  
Polynomial pseudo-quotient in multivariate polynomial ring.

Examples
========
>>> from sympy.polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)

>>> f = x**2 + x*y
>>> g = 2*x + 2*y
>>> h = 2*x + 2
>>> f.pquo(g)
2*x
>>> f.quo(g) # shows the difference between pquo and quo
0
>>> f.pquo(h)
2*x + 2*y - 2
>>> f.quo(h) # shows the difference between pquo and quo
0

See Also
========

prem, pdiv, pexquo, sympy.polys.domains.ring.Ring.quo

r   )r  )r   r  r  ry   s       r7   pquoPolyElement.pquo
  s    6 vva|Ar9   c                h    U nUR                  X5      u  pEUR                  (       a  U$ [        X15      e)a;  
Polynomial exact pseudo-quotient in multivariate polynomial ring.

Examples
========
>>> from sympy.polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)

>>> f = x**2 + x*y
>>> g = 2*x + 2*y
>>> h = 2*x + 2
>>> f.pexquo(g)
2*x
>>> f.exquo(g) # shows the differnce between pexquo and exquo
Traceback (most recent call last):
...
ExactQuotientFailed: 2*x + 2*y does not divide x**2 + x*y
>>> f.pexquo(h)
Traceback (most recent call last):
...
ExactQuotientFailed: 2*x + 2 does not divide x**2 + x*y

See Also
========

prem, pdiv, pquo, sympy.polys.domains.ring.Ring.exquo

)r  r  r"   )r   r  r  ry   r  ry  s         r7   pexquoPolyElement.pexquo  s/    : vva|99H%a++r9   c                   U nUR                   R                  U5      nUR                  U5      nUR                  U5      nXE:  a  XpXTpTUS:X  a  SS/$ US:X  a  US/$ X1/nXE-
  nSUS-   -  nUR                  X5      n	X-  n	UR	                  X%5      n
X-  nSU/nU* nU	(       a  U	R                  U5      nUR                  U	5        XXU-
  4u  p1pWU
* X-  -  nUR                  X5      n	U	R                  U5      n	UR	                  X-5      n
US:  a  U
* U-  nXS-
  -  nUR                  U5      nOU
* nUR                  U* 5        U	(       a  M  U$ )a  
Computes the subresultant PRS of two polynomials ``self`` and ``g``.

Parameters
==========

g : :py:class:`~.PolyElement`
    The second polynomial.
x : generator or generator index
    The variable with respect to which the subresultant sequence is computed.

Returns
=======

R : list
    Returns a list polynomials representing the subresultant PRS.

Examples
========

>>> from sympy.polys import ring, ZZ
>>> R, x, y = ring("x, y", ZZ)

>>> f = x**2*y + x*y
>>> g = x + y
>>> f.subresultants(g) # first generator is chosen by default if not given
[x**2*y + x*y, x + y, y**3 - y**2]
>>> f.subresultants(g, 0) # generator index is given
[x**2*y + x*y, x + y, y**3 - y**2]
>>> f.subresultants(g, y) # generator is given
[x**2*y + x*y, x + y, x**3 + x**2]

r   r   r	  )r8   r
  r  r  r  r   r  )r   r  r  ry   rB  rR   r  drq   r(  lcrS   Sro  r-  r  s                   r7   subresultantsPolyElement.subresultants7  si   D FFLLOHHQKHHQK5qq6q6M6q6MFEQUO FF1LE [[GFBAHHQKqa%JA!afAqA
AQ"B1uSQJa%LGGAJCHHaRL' a* r9   c                8    U R                   R                  X5      $ rZ   )r8   dmp_half_gcdexr4  s     r7   
half_gcdexPolyElement.half_gcdex  s    vv$$Q**r9   c                8    U R                   R                  X5      $ rZ   )r8   	dmp_gcdexr4  s     r7   gcdexPolyElement.gcdex      vv%%r9   c                8    U R                   R                  X5      $ rZ   )r8   dmp_resultantr4  s     r7   	resultantPolyElement.resultant  s    vv##A))r9   c                8    U R                   R                  U 5      $ rZ   )r8   dmp_discriminantr  s    r7   discriminantPolyElement.discriminant  s    vv&&q))r9   c                    U R                   R                  (       a  U R                   R                  U 5      $ [        S5      e)Nzpolynomial decomposition)r8   r#  dup_decomposer#   r  s    r7   	decomposePolyElement.decompose  s0    6666''**-.HIIr9   c                    U R                   R                  (       a  U R                   R                  X5      $ [        S5      e)Nzshift: use shift_list instead)r8   r#  	dup_shiftr#   ry   rp   s     r7   shiftPolyElement.shift  s0    6666##A))-.MNNr9   c                8    U R                   R                  X5      $ rZ   )r8   	dmp_shiftr  s     r7   
shift_listPolyElement.shift_list  r  r9   c                    U R                   R                  (       a  U R                   R                  U 5      $ [        S5      e)Nzsturm sequence)r8   r#  	dup_sturmr#   r  s    r7   sturmPolyElement.sturm  s0    6666##A&&-.>??r9   c                8    U R                   R                  U 5      $ rZ   )r8   dmp_gff_listr  s    r7   gff_listPolyElement.gff_list      vv""1%%r9   c                8    U R                   R                  U 5      $ rZ   )r8   dmp_normr  s    r7   normPolyElement.norm  s    vvq!!r9   c                8    U R                   R                  U 5      $ rZ   )r8   dmp_sqf_normr  s    r7   sqf_normPolyElement.sqf_norm  r  r9   c                8    U R                   R                  U 5      $ rZ   )r8   dmp_sqf_partr  s    r7   sqf_partPolyElement.sqf_part  r  r9   c                4    U R                   R                  XS9$ )N)re   )r8   dmp_sqf_list)ry   re   s     r7   sqf_listPolyElement.sqf_list  s    vv""1"..r9   c                8    U R                   R                  U 5      $ rZ   )r8   dmp_factor_listr  s    r7   factor_listPolyElement.factor_list  s    vv%%a((r9   r   rZ   )F)r   rE  rF  rG  rH  rO  rR  r   r   r   r   r_  rc  rb  rq  ru  r   r   r  r  r  r  r  r  r  r  r  r  r3  r  r  r\   rI  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&  r6  r5  r4  r3  rP  rL  rY  rX  r`  r_  __floordiv____rfloordiv__rq  r   rW  r^  r  rt  ru  r  r  r  r  r   r  r   r  r  r  r  r  r  r  rO   r  r^  r  r  rU  r  r  r  rB  r  r  r  r  r  r  rM  r  r  rN  r  r  r  r!  r+  r.  r   r   r3  r7  r8  r9  rJ  rI  rV  rR  r\  rJ  r_  rg  rz  r9  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rK  rX   r9   r7   rl   rl   <  sF   ?$%3 E	8>	=M"44G0)"	2*>"H.` + + M M = =   5 5 5 5 8 8 8 8     * * 1 1 @ @ @ @ # #
 + +
 G GR4l(4l60d:.(` :"H:,%,%2 L MBJX+Z,*X#J= 
?= 
?(5#BJ5 4 4  * 1 1(	P;4;474#!"#!"!F	(
&

 <$ J
PB !>," ,*6p+2p*X%Nk%Z@3;jYv||<#,JXz+&**JO&@&"&&/)r9   rl   N)QrH  
__future__r   typingr   operatorr   r   r   r   r	   r
   	functoolsr   typesr   sympy.core.exprr   sympy.core.intfuncr   sympy.core.symbolr   r   rd   sympy.core.sympifyr   r   sympy.ntheory.multinomialr   sympy.polys.compatibilityr   sympy.polys.constructorr   sympy.polys.densebasicr   r   r   !sympy.polys.domains.domainelementr   "sympy.polys.domains.polynomialringr   sympy.polys.heuristicgcdr   sympy.polys.monomialsr   sympy.polys.orderingsr   sympy.polys.polyerrorsr    r!   r"   r#   sympy.polys.polyoptionsr$   r|   r%   r~   r&   sympy.polys.polyutilsr'   r(   r)   sympy.printing.defaultsr*   sympy.utilitiesr+   r,   sympy.utilities.iterablesr-   sympy.utilities.magicr.   r8   r;   r?   rU   rg   rh   __annotations__r1   rF   rl   rX   r9   r7   <module>r     s     "  - -     # 9 3 > , 4 C C ; = + - %6 6G G= = 3 + 1 ) # ! !< !$  < !$  < 2 2h@ !^  u upI&)-+t I&)r9   