
    \h@P                      S 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  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/J0r0J1r1  SSK2J3r3J4r4J5r5J6r6  SSK7J&r8J9r:J;r;  SSK<J=r=J>r>J?r?  SSK@JArA  SSKBJCrCJDrD  SSKEJFrF  SSKGJHrH  \C\04S&S jj5       rI\C\04S j5       rJ\C\04S j5       rK\CS 5       rLS  rM " S! S"\A\5      rN " S# S$\(\A\\O5      rPg%)'zSparse polynomial rings.     )annotations)addmulltlegtge)reduce)GeneratorType)cacheit)Expr)igcd)Symbolsymbols)CantSympifysympify)multinomial_coefficients)IPolys)construct_domain)ninfdmp_to_dictdmp_from_dict)Domain)DomainElementPolynomialRingheugcd)MonomialOps)lexMonomialOrder)CoercionFailedGeneratorsErrorExactQuotientFailedMultivariatePolynomialError)r   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       I/var/www/auris/envauris/lib/python3.13/site-packages/sympy/polys/rings.pyringr9   $   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'>

r1   r4   s       r8   xringr<   C   s    8 We,E::r:   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'>

)r2   r/   r   namer3   )r   r5   r6   r7   syms        r8   vringr@   b   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*   r5   sumvaluesr   dictzipitemsr2   r3   r6   	from_dict)exprsr   optionssinglerB   repsrepcoeffs
coeffs_dom	coeff_mapmcr7   polyss                 r8   sringrV      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     r8   	<genexpr>!_parse_symbols.<locals>.<genexpr>   s     37az!S!!7   c              3  B   #    U  H  n[        U[        5      v   M     g 7fr[   )r\   r   r^   s     r8   ra   rb      s     6gAt$$grc   zbexpected a string, Symbol or expression or a non-empty sequence of strings, Symbols or expressions)r\   r]   _symbolsr   r.   allr#   r   s    r8   _parse_symbolsrh      s    '3.5xT*=2=	GT	"	"z	W		37333G$$6g666N
~
r:   c                  p   \ rS rSr% SrS\S'   S\S'   S\S'   S	\S
'   S\S'   \4S jrS rS r	S r
S rS rS rS3S jr\S 5       rS r\S 5       r\S 5       rS rS4S jrS rS rS r\rS4S jrS4S  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+S0 r,S1 r-S2r.g)5r2      z*Multivariate distributed polynomial ring. ztuple[PolyElement, ...]r3   ztuple[Expr, ...]r   intngensr   r5   r!   r6   c                l  ^ [        [        U5      5      n[        U5      n[        R                  " U5      n[
        R                  " T5      mU R                  XUT4nUR                  (       a1  [        U5      [        UR                  5      -  (       a  [        S5      e[        R                  U 5      nXVl        [        U5      Ul        Xl	        XFl        X&l        TUl        ['        US5      R(                  Ul        SU-  Ul        UR/                  5       Ul        [        UR0                  5      Ul        UR,                  UR4                  4/Ul        U(       a  [9        U5      nUR;                  5       Ul        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*        O/S nXl        Xl         S Ul"        Xl$        Xl&        Xl(        Xl*        T[V        L a  [X        Ul-        OU4S jUl-        []        UR                  UR0                  5       HF  u  p[_        U	[`        5      (       d  M  U	Rb                  n[e        Xk5      (       a  M:  [g        XkU
5        MH     U$ )Nz7polynomial ring and it's ground domain share generatorsrY   r   c                    gNrY   rY   )abs     r8   <lambda>"PolyRing.__new__.<locals>.<lambda>   s    2r:   c                    grp   rY   )rq   rr   rT   s      r8   rs   rt      s    "r:   c                   > [        U TS9$ )Nkey)max)fr6   s    r8   rs   rt      s    QE):r:   )4tuplerh   len	DomainOpt
preprocessOrderOpt__name__is_Compositesetr   r#   object__new___hash_tuplehash_hashrl   r5   r6   PolyElementnewdtype
zero_monom_gensr3   	_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    ry   leading_expvrH   r\   r   r>   hasattrsetattr)clsr   r5   r6   rl   r   objcodegenmonunitsymbol	generatorr>   s      `        r8   r   PolyRing.__new__   s   w/0G%%f-##E*||WVUC3w<#fnn2E#E!"[\\nnS!%%		
	R(,,	e99;CHH^^VZZ01!%(G&{{}C&{{}C").."2C 'C&{{}C&{{}C&{{}C%G&&"4C '&&& C<"C:C!$S[[#((!;F&&)){{s))Cy1 "< 
r:   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. )r5   r   rangerl   monomial_basiszeroappendr{   )selfr   r   iexpvpolys         r8   r   PolyRing._gens  s_    kkootzz"A&&q)D99DJLL	 #
 U|r:   c                H    U R                   U R                  U R                  4$ r[   )r   r5   r6   r   s    r8   __getnewargs__PolyRing.__getnewargs__  s    dkk4::66r:   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   staterx   s      r8   __getstate__PolyRing.__getstate__  sA    ""$.!C~~k**J  r:   c                    U R                   $ r[   )r   r   s    r8   __hash__PolyRing.__hash__#  s    zzr:   c                    [        U[        5      =(       a]    U R                  U R                  U R                  U R
                  4UR                  UR                  UR                  UR
                  4:H  $ r[   )r\   r2   r   r5   rl   r6   r   others     r8   __eq__PolyRing.__eq__&  sV    %* D\\4;;

DJJ?]]ELL%++u{{CD	Dr:   c                    X:X  + $ r[   rY   r   s     r8   __ne__PolyRing.__ne__+  s      r:   Nc                l    Ub   [        U[        5      (       a  [        U5      nU R                  XU5      $ r[   )r\   rC   r{   _cloner   r   r5   r6   s       r8   clonePolyRing.clone.  s.    :gt#<#<GnG{{7E22r:   c                    U R                  U=(       d    U R                  U=(       d    U R                  U=(       d    U R                  5      $ r[   )	__class__r   r5   r6   r   s       r8   r   PolyRing._clone4  s3    ~~g5v7LeNaW[WaWabbr:   c                @    S/U R                   -  nSX!'   [        U5      $ )zReturn the ith-basis element. r      )rl   r{   )r   r   basiss      r8   r   PolyRing.monomial_basis8  s"    DJJU|r:   c                $    U R                  / 5      $ r[   )r   r   s    r8   r   PolyRing.zero>  s    zz"~r:   c                8    U R                  U R                  5      $ r[   )r   r   r   s    r8   r   PolyRing.oneB  s    zz$))$$r:   c                N    [        U[        5      =(       a    UR                  U :H  $ )zATrue if ``element`` is an element of this ring. False otherwise. )r\   r   r9   r   elements     r8   
is_elementPolyRing.is_elementF  s    ';/HGLLD4HHr:   c                8    U R                   R                  X5      $ r[   )r5   convertr   r   orig_domains      r8   
domain_newPolyRing.domain_newJ  s    {{""788r:   c                :    U R                  U R                  U5      $ r[   )term_newr   )r   coeffs     r8   
ground_newPolyRing.ground_newM  s    }}T__e44r:   c                V    U R                  U5      nU R                  nU(       a  X#U'   U$ r[   )r   r   )r   monomr   r   s       r8   r   PolyRing.term_newP  s(    &yyKr:   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\   r   r9   r5   r   r   NotImplementedErrorr]   rG   rJ   rC   
from_terms
ValueError	from_listr   	from_exprr   s     r8   ring_newPolyRing.ring_newW  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$ r[   )r   r   rI   )r   r   r   r   r   r   r   s          r8   rJ   PolyRing.from_dicto  sC    __
yy#MMOLEu2Eu#U ,
 r:   c                8    U R                  [        U5      U5      $ r[   )rJ   rG   r   s      r8   r   PolyRing.from_termsz  s    ~~d7m[99r:   c                f    U R                  [        XR                  S-
  U R                  5      5      $ Nr   )rJ   r   rl   r5   r   s     r8   r   PolyRing.from_list}  s$    ~~k'::a<MNNr:   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   )getis_Addr
   r   rC   rD   argsis_Mulr   as_base_exp
is_Integerrk   r   r   )exprr   baseexp_rebuildr5   mappingr   s       r8   r  (PolyRing._rebuild_expr.<locals>._rebuild  s    D)I$  c4Hdii(@#ABBc4Hdii(@#ABB !,,.	>>cAg#D>3s833??6>>$+?@@r:   )r5   r   )r   r  r  r  r5   s   ` `@@r8   _rebuild_exprPolyRing._rebuild_expr  s)    	A 	A$ &&r:   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 )	rG   rC   rH   r   r3   r
  r   r"   r   )r   r  r  r   s       r8   r   PolyRing.from_expr  sk    tCdii89:	'%%d4D ==&&  	pcgimnoo	ps   A A4c                N   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U R	                  U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)	rl   r\   rk   r   r   r3   indexr]   r   )r   genr   s      r8   r  PolyRing.index  sI   ;zz2 / . - S!!AAv!jj.$ # **!a2gBF   !!>!DEE__S!!@IIOOC(  S!!@LL&&s+  dgjjkk  @ !83!>??@
  @ !83!>??@s   C/ D /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. rg   )r   rD   r  	enumerater   r5   r   )r   r3   indicesr   r`   r   s         r8   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$ )Nrg   )r   r5   r   )r   rx   r   s      r8   __getitem__PolyRing.__getitem__  s.    ,,s#;;::g:..r:   c                    U R                   R                  (       d  [        U R                   S5      (       a#  U R                  U R                   R                   S9$ [	        SU R                   -  5      e)Nr5   r5   z%s is not a composite domain)r5   r   r   r   r   r   s    r8   	to_groundPolyRing.to_ground  sO    ;;##wt{{H'E'E::T[[%7%7:88;dkkIJJr:   c                    [        U 5      $ r[   r   r   s    r8   	to_domainPolyRing.to_domain  s    d##r:   c                ^    SSK Jn  U" U R                  U R                  U R                  5      $ )Nr   )	FracField)sympy.polys.fieldsr#  r   r5   r6   )r   r#  s     r8   to_fieldPolyRing.to_field  s     0t{{DJJ??r:   c                2    [        U R                  5      S:H  $ r   r|   r3   r   s    r8   is_univariatePolyRing.is_univariate  s    499~""r:   c                2    [        U R                  5      S:  $ r   r(  r   s    r8   is_multivariatePolyRing.is_multivariate  s    499~!!r:   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       r8   r   PolyRing.add  s?    " IIC36XXs^#	  r:   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   r1  s       r8   r   PolyRing.mul  s?    " HHC36XXs^#	  r:   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   r5   )r   rD   r  r  r   r3   r   r  )r   r3   r  r   r`   r   r  s          r8   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``rg   r   r   unionr   rC   )r   r   symss      r8   composePolyRing.compose,  sC    =t||$**3u}}+=>D::d4j:11Kr:   c                    [        U R                  5      R                  [        U5      5      nU R                  [	        U5      S9$ )z9Add the elements of ``symbols`` as generators to ``self``rg   r<  )r   r   r>  s      r8   add_gensPolyRing.add_gens4  s4    4<< &&s7|4zz$t*z--r:   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r[   )rk   )r_   r   r`   s     r8   ra   *PolyRing.symmetric_poly.<locals>.<genexpr>E  s     E3Dac!q&kk3D   )rl   r   r3   r   r   r-   r   rk   r{   r   r5   )r   nr   r   r`   s       @r8   symmetric_polyPolyRing.symmetric_poly9  s    
 q5A

NZ[]a]f]fghh88O99DU4::.A7E53DEEe[[__== 8 Kr:   rY   )NNNr[   )/r   
__module____qualname____firstlineno____doc____annotations__r    r   r   r   r   r   r   r   r   r   r   r   propertyr   r   r   r   r   r   r   __call__rJ   r   r   r
  r   r  r  r  r  r   r%  r)  r,  r   r   r9  r?  rB  rI  __static_attributes__rY   r:   r8   r2   r2      s3   4
!!JN,/ <|	7D
!3 c c   % %I95,, H	:O'.'>//K$@ # # " "66H.
r:   r2   c                    ^  \ rS rSrSrU 4S 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 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       r0\"S. 5       r1\"S/ 5       r2\"S0 5       r3S1 r4S2 r5S3 r6S4 r7S5 r8S6 r9S7 r:S8 r;S9 r<S: r=S; r>S< r?S= r@S> rAS? rBS@ rCSA rDSB rESC rFSD rGSE rHSF rISG rJSH rKSI rLSJ rMSK rNSSL jrOSM rPSSN jrQSO rRSP rSSQ rTSR rUSS rV\"ST 5       rW\"SU 5       rXSV rY\"SW 5       rZSX r[SY r\SSZ jr]SS[ jr^SS\ jr_S] r`S^ raS_ rbS` rcSa rdSb reSc rfSd rgSe rhSf riSg rjSh rkSi rlSj rmSk rnSl ro\orpSm rqSn rrSo rsSp rtSq ruSr rvSs rwSt rxSu rySv rzSw r{Sx r|Sy r}Sz r~S{ rS| rS} rS~ 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 rSrU =r$ )r   iJ  z5Element of multivariate distributed polynomial ring. c                0   > [         TU ]  U5        Xl        g r[   )super__init__r9   )r   r9   initr   s      r8   rV  PolyElement.__init__M  s    	r:   c                   [        U [        5      (       d   e[        U R                  [        5      (       d   eU R                  R                  n[        U[
        5      (       d   eU R                  5        H[  u  p#UR                  U5      (       d   e[        U5      U R                  R                  :X  d   e[        S U 5       5      (       a  M[   e   g )Nc              3  Z   #    U  H!  n[        U[        5      =(       a    US :  v   M#     g7f)r   N)r\   rk   )r_   r  s     r8   ra   %PolyElement._check.<locals>.<genexpr>[  s#     JESz#s+8q8Es   )+)r\   r   r9   r2   r5   r   rI   of_typer|   rl   rf   )r   domr   r   s       r8   _checkPolyElement._checkS  s    $,,,,$))X....ii#v&&&& JJLLE;;u%%%%u:000JEJJJJJ )r:   c                :    U R                  U R                  U5      $ r[   )r   r9   )r   rW  s     r8   r   PolyElement.new]  s    ~~dii..r:   c                6    U R                   R                  5       $ r[   )r9   r   r   s    r8   parentPolyElement.parent`  s    yy""$$r:   c                L    U R                   [        U R                  5       5      4$ r[   )r9   rC   	itertermsr   s    r8   r   PolyElement.__getnewargs__c  s    		4 0122r:   Nc                    U R                   nUc5  [        U R                  [        U R	                  5       5      45      =U l         nU$ r[   )r   r   r9   	frozensetrI   )r   r   s     r8   r   PolyElement.__hash__h  s<     

=!%tyy)DJJL2I&J!KKDJr:   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

)r   r   s    r8   r   PolyElement.copys  s    4 xx~r:   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      $ r[   )r9   r   rC   rH   r)   r   r5   rJ   )r   new_ringtermss      r8   set_ringPolyElement.set_ring  s    99 KYY("2"22mD))2C2CXEUEUVWXE&&uii.>.>??%%dII,<,<==r:   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 )r9   r   r|   rl   r   r(   as_expr_dict)r   r   s     r8   as_exprPolyElement.as_expr  sf    ii''G\TYY__,#g,0 
 d//1<G<<r:   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 r[   )r9   r5   to_sympyrf  )r   rw  r   r   s       r8   rs  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 r[   )r9   r5   is_Fieldhas_assoc_Ringr   get_ringr   denomrF   r   rI   )
r   r5   ground_ringcommonr   r}  r   kvr   s
             r8   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rC   rI   )r   r  r  s      r8   
strip_zeroPolyElement.strip_zero  s#    &DA1G 'r:   c                    U(       d  U (       + $ U R                   R                  U5      (       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)r9   r   rG   r   r|   r   r   p1p2s     r8   r   PolyElement.__eq__  s^    " 6MWW##;;r&&Wq[66"'',,-33r:   c                    X:X  + $ r[   rY   r  s     r8   r   PolyElement.__ne__  s
    |r:   c                   U R                   nUR                  U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   )
r9   r   r   keysr5   almosteqr|   r   constr"   )r  r  	tolerancer9   r  r  s         r8   r  PolyElement.almosteq  s    ww??22779~RWWY/{{++HWWYrui88   Wq[G[[((, {{++BHHJFF " s   ,C1 1
C>=C>c                8    [        U 5      U R                  5       4$ r[   )r|   ro  r   s    r8   sort_keyPolyElement.sort_key  s    D	4::<((r:   c                    U R                   R                  U5      (       a%  U" U R                  5       UR                  5       5      $ [        $ r[   )r9   r   r  NotImplemented)r  r  ops      r8   _cmpPolyElement._cmp  s6    77b!!bkkmR[[]33!!r:   c                .    U R                  U[        5      $ r[   )r  r   r  s     r8   __lt__PolyElement.__lt__      wwr2r:   c                .    U R                  U[        5      $ r[   )r  r   r  s     r8   __le__PolyElement.__le__  r  r:   c                .    U R                  U[        5      $ r[   )r  r   r  s     r8   __gt__PolyElement.__gt__   r  r:   c                .    U R                  U[        5      $ r[   )r  r	   r  s     r8   __ge__PolyElement.__ge__  r  r:   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   rg   )r9   r  rl   r5   rC   r   r   r   r  r9   r   r   s        r8   _dropPolyElement._drop  sV    yyJJsO::?kk>!4<<(G
jjj111r:   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  r9   rl   	is_groundr   r   r   rI   rC   r{   )r   r  r   r9   r   r  r  Ks           r8   r  PolyElement.drop  s    **S/99??a~~zz!}$ !1C!78899D

419QA%&qN$%5%;<< % Kr:   c                    U R                   nUR                  U5      n[        UR                  5      nXC	 X2R	                  XBU   S94$ )Nr8  )r9   r  rC   r   r   r  s        r8   _drop_to_groundPolyElement._drop_to_ground%  sC    yyJJsOt||$J**W!W*===r:   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   )	r9   rl   r   r  r   r5   r3   rf  
mul_ground)r   r  r   r9   r   r   r   mons           r8   r9  PolyElement.drop_to_ground-  s    99??aCDD&&s+yykkq! NN,LE)eaCDk)C (]66u=		c8m77>>	 - r:   c                p    [        X R                  R                  S-
  U R                  R                  5      $ r   )r   r9   rl   r5   r   s    r8   to_densePolyElement.to_dense>  s&    T99??1#4dii6F6FGGr:   c                    [        U 5      $ r[   )rG   r   s    r8   to_dictPolyElement.to_dictA  s    Dzr:   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  )_printr9   r5   r   r   rl   r   ro  is_negativer   r   r   parenthesizer   rk   joinpopinsert)r   printer
precedenceexp_pattern
mul_symbolprec_mul	prec_atomr9   r   rl   zmsexpvsr   r   negativesignscoeffsexpvr   r  r   sexpheads                          r8   r]   PolyElement.strD  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r:   c                2    X R                   R                  ;   $ r[   )r9   r   r   s    r8   is_generatorPolyElement.is_generatort  s    yy****r:   c                z    U (       + =(       d.    [        U 5      S:H  =(       a    U R                  R                  U ;   $ r   )r|   r9   r   r   s    r8   r  PolyElement.is_groundx  s+    xLCINKtyy/C/Ct/KLr:   c                f    U (       + =(       d$    [        U 5      S:H  =(       a    U R                  S:H  $ r   )r|   LCr   s    r8   is_monomialPolyElement.is_monomial|  s$    x<CIN;tww!|<r:   c                    [        U 5      S:*  $ r   )r|   r   s    r8   is_termPolyElement.is_term  s    4yA~r:   c                `    U R                   R                  R                  U R                  5      $ r[   )r9   r5   r  r  r   s    r8   r  PolyElement.is_negative  !    yy++DGG44r:   c                `    U R                   R                  R                  U R                  5      $ r[   )r9   r5   is_positiver  r   s    r8   r  PolyElement.is_positive  r  r:   c                `    U R                   R                  R                  U R                  5      $ r[   )r9   r5   is_nonnegativer  r   s    r8   r  PolyElement.is_nonnegative  !    yy..tww77r:   c                `    U R                   R                  R                  U R                  5      $ r[   )r9   r5   is_nonpositiver  r   s    r8   r  PolyElement.is_nonpositive  r  r:   c                    U (       + $ r[   rY   rz   s    r8   is_zeroPolyElement.is_zero  s	    ur:   c                2    X R                   R                  :H  $ r[   )r9   r   r  s    r8   is_onePolyElement.is_one  s    FFJJr:   c                `    U R                   R                  R                  U R                  5      $ r[   )r9   r5   r  r  r  s    r8   is_monicPolyElement.is_monic  s    vv}}##ADD))r:   c                h    U R                   R                  R                  U R                  5       5      $ r[   )r9   r5   r  contentr  s    r8   is_primitivePolyElement.is_primitive  s!    vv}}##AIIK00r:   c                B    [        S U R                  5        5       5      $ )Nc              3  >   #    U  H  n[        U5      S :*  v   M     g7fr   NrE   r_   r   s     r8   ra   (PolyElement.is_linear.<locals>.<genexpr>       ?u3u:?   rf   
itermonomsr  s    r8   	is_linearPolyElement.is_linear      ????r:   c                B    [        S U R                  5        5       5      $ )Nc              3  >   #    U  H  n[        U5      S :*  v   M     g7f)   Nr  r  s     r8   ra   +PolyElement.is_quadratic.<locals>.<genexpr>  r	  r
  r  r  s    r8   is_quadraticPolyElement.is_quadratic  r  r:   c                p    U R                   R                  (       d  gU R                   R                  U 5      $ NT)r9   rl   	dmp_sqf_pr  s    r8   is_squarefreePolyElement.is_squarefree  s%    vv||vv""r:   c                p    U R                   R                  (       d  gU R                   R                  U 5      $ r  )r9   rl   dmp_irreducible_pr  s    r8   is_irreduciblePolyElement.is_irreducible  s%    vv||vv''**r:   c                    U R                   R                  (       a  U R                   R                  U 5      $ [        S5      e)Nzcyclotomic polynomial)r9   r)  dup_cyclotomic_pr%   r  s    r8   is_cyclotomicPolyElement.is_cyclotomic  s0    6666**1---.EFFr:   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 r[   )r   rf  )r   r   r   s      r8   __neg__PolyElement.__neg__  s2    xxdnn>NP>Nle5&/>NPQQPs   7
c                    U $ r[   rY   r   s    r8   __pos__PolyElement.__pos__  s    r:   c                   U(       d  U R                  5       $ U R                  nUR                  U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   r9   r   r   r5   r   rI   r\   r   r   __radd__r  r   r   r  r"   )
r  r  r9   r3  r   r   r  r  cp2r  s
             r8   __add__PolyElement.__add__  s    779ww??2	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r[   )r   r9   r   r   r  r"   r  )r  rH  r3  r9   r  s        r8   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UR                  U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   r9   r   r   r5   r   rI   r\   r   r   __rsub__r  r   r   r  r"   )	r  r  r9   r3  r   r   r  r  r  s	            r8   __sub__PolyElement.__sub__  s~     779ww??2	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

)r9   r   r   r"   r  )r  rH  r9   r3  r   s        r8   r1  PolyElement.__rsub__E  sc     ww
	"A 		A8) FAH  	"!!	"s   A AAc                   U R                   nUR                  nU (       a  U(       d  U$ UR                  U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

)r9   r   r   r   r5   r   rC   rI   r  r\   r   r   __rmul__r  r   r"   )r  r  r9   r3  r   r   r   p2itexp1v1exp2v2r  r  s                 r8   __mul__PolyElement.__mul__a  sy     wwIIH__R  %%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

)r9   r   r   rI   r"   r  )r  r  r3  r9  r:  r  s         r8   r7  PolyElement.__rmul__  sw     GGLLH		""2&B HHJE1dG ' H  	"!!	"s   A( (A;:A;c                   [        U[        5      (       d  [        SU-  5      eUS:  a  [        SU-  5      e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#exponent must be an integer, got %sr   z/exponent must be a non-negative integer, got %sz0**0r   zNegative exponentr        )r\   rk   	TypeErrorr   r9   r   r|   rC   rI   r   r5   r   r   square_pow_multinomial_pow_generic)r   rH  r9   r   r   r3  s         r8   __pow__PolyElement.__pow__  sT    !S!!AAEFFUNQRRSSyyxx ((Y!^

-a0LE		A'16$##E-. H 27##E-.H Fq5011!V99;!V;;= !V%%Y!^((++$$Q''r:   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  )r9   r   rE  )r   rH  r3  rT   s       r8   rG  PolyElement._pow_generic  sV    IIMM1uCQ
  
AQA r:   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$ r[   )r   r|   rI   r9   r   r   r5   r   rH   r{   r   )r   rH  multinomialsr   r   ro  r   r   multinomialmultinomial_coeffproduct_monomproduct_coeffr  r   r   s                  r8   rF  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# /;& r:   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  )r9   r   r   rC   r  r5   r   r   r|   imul_numrI   r  )r   r9   r3  r   r  r   r   r   k1pkjk2r  r  r  s                  r8   rE  PolyElement.square  s     yyIIeeDIIK {{((s4y!ABB1XW"2*S""X+5  " JJqMeeJJLDAa#BMAqD(AE ! 	
r:   c                   U R                   nU(       d  [        S5      eUR                  U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)r9   ZeroDivisionErrorr   r   r\   r   r5   r   __rdivmod__r  r   
quo_ground
rem_groundr"   r  r  r9   s      r8   
__divmod__PolyElement.__divmod__:  s    ww#$9::__R  66":K(($++~664;;;K;Krww;VBGGNNN;;@S@SW[@[~~b))%%	:$B MM"%r}}R'899  	"!!	"s   D7 7E
	E
c                    U R                   n UR                  U5      nUR                  U 5      $ ! [         a	    [        s $ f = fr[   )r9   r   r   r"   r  ra  s      r8   r^  PolyElement.__rdivmod__P  E    ww	$B 66":  	"!!	"   0 AAc                x   U R                   nU(       d  [        S5      eUR                  U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r[  )r9   r]  r   remr\   r   r5   r   __rmod__r  r   r`  r"   ra  s      r8   __mod__PolyElement.__mod__Y  s    ww#$9::__R  66":K(($++~664;;;K;Krww;VBGGNNN;;@S@SW[@[{{2&%%	%$B ==$$  	"!!	"   D& &D98D9c                    U R                   n UR                  U5      nUR                  U 5      $ ! [         a	    [        s $ f = fr[   )r9   r   ri  r"   r  ra  s      r8   rj  PolyElement.__rmod__o  rf  rg  c                x   U R                   nU(       d  [        S5      eUR                  U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r[  )r9   r]  r   quor\   r   r5   r   __rtruediv__r  r   r_  r"   ra  s      r8   __floordiv__PolyElement.__floordiv__x  s    ww#$9::__R  66":K(($++~664;;;K;Krww;VBGGNNN;;@S@SW[@[r**%%	%$B ==$$  	"!!	"rm  c                    U R                   n UR                  U5      nUR                  U 5      $ ! [         a	    [        s $ f = fr[   )r9   r   rq  r"   r  ra  s      r8   __rfloordiv__PolyElement.__rfloordiv__  rf  rg  c                x   U R                   nU(       d  [        S5      eUR                  U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r[  )r9   r]  r   exquor\   r   r5   r   rr  r  r   r_  r"   ra  s      r8   __truediv__PolyElement.__truediv__  s    ww#$9::__R  88B<K(($++~664;;;K;Krww;VBGGNNN;;@S@SW[@[r**%%	%$B ==$$  	"!!	"rm  c                    U R                   n UR                  U5      nUR                  U 5      $ ! [         a	    [        s $ f = fr[   )r9   r   ry  r"   r  ra  s      r8   rr  PolyElement.__rtruediv__  sE    ww	 $B 88B<  	"!!	"rg  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 r[   rY   
	a_lm_a_lc	b_lm_b_lca_lma_lcb_lmb_lcr   
domain_quor   r  s
          r8   term_div'PolyElement._term_div.<locals>.term_div  s@    &
&
2: E(4E$ *T"888r:   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 r[   rY   r  s
          r8   r  r    sC    &
&
2: E(4E *T"888r:   )r9   r   r5   rq  r   rz  )r   r5   r  r  r   r  s      @@@r8   	_term_divPolyElement._term_div  sX    YY!!!!ZZ
yy--??
 0 
  r:   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

FTr\  z"self and f must have the same ringr   r   )r9   r\   r   rf   r]  r   r   r|   r   r   r  r   _iadd_monom_iadd_poly_monomr   )r   fvr9   
ret_singlerz   r`   r   qvr3  rr  fxexpvsdivoccurredr   termexpv1rT   s                     r8   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$ r[  )r\   r   rf   r]  r9   r5   r   r   r  LTr   r   rf  r   )r   Grz   r9   r5   r   r   r  r  ltfr   gtqrS   rT   mgcgm1c1ltmltcs                        r8   ri  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 r:   c                *    U R                  U5      S   $ Nr   )r   )rz   r  s     r8   rq  PolyElement.quoP  s    uuQx{r:   c                P    U R                  U5      u  p#U(       d  U$ [        X5      er[   )r   r$   )rz   r  qr  s       r8   ry  PolyElement.exquoS  s$    uuQxH%a++r:   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

)r9   r   r   r   )r   mccpselfr   r   rT   s         r8   r  PolyElement._iadd_monom[  sr    8 99&&&YY[FFJJt9 4L  JA t  Lr:   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

)r9   r   r   r   r5   r   r   rI   )r   r  r  r  rS   rT   r   r   r   r  r  kar   s                r8   r  PolyElement._iadd_poly_monom  s    * """Bffww~~""ww++HHJDAa#BMAC'E2F  	r:   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r[   rY   r_   r   r   s     r8   ra   %PolyElement.degree.<locals>.<genexpr>       <^EQx^   )r9   r  r   ry   r  rz   xr   s     @r8   degreePolyElement.degree  ?     FFLLOKU<Q\\^<<<r:   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   r9   rl   r{   rD   ry   rC   rH   r  r  s    r8   degreesPolyElement.degrees  >     7166<<''S$sALLN';"<=>>r:   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r[   rY   r  s     r8   ra   *PolyElement.tail_degree.<locals>.<genexpr>  r  r  )r9   r  r   minr  r  s     @r8   tail_degreePolyElement.tail_degree  r  r:   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   r9   rl   r{   rD   r  rC   rH   r  r  s    r8   tail_degreesPolyElement.tail_degrees  r  r:   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)r9   r   r   s    r8   r   PolyElement.leading_expv  s     99))$//r:   c                `    U R                  XR                  R                  R                  5      $ r[   )r   r9   r5   r   r   r   s     r8   
_get_coeffPolyElement._get_coeff  s!    xxii..3344r:   c                z   US:X  a%  U R                  U R                  R                  5      $ U R                  R                  U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  r9   r   r   rC   rf  r|   r5   r   r   )r   r   ro  r   r   s        r8   r   PolyElement.coeff  s    4 a<??499#7#788YY!!'****,-E5zQ$QxII,,000??5116@AAr:   c                L    U R                  U R                  R                  5      $ )z"Returns the constant coefficient. )r  r9   r   r   s    r8   r  PolyElement.const   s    tyy3344r:   c                @    U R                  U R                  5       5      $ r[   )r  r   r   s    r8   r  PolyElement.LC$  s    t00233r:   c                X    U R                  5       nUc  U R                  R                  $ U$ r[   )r   r9   r   r  s     r8   LMPolyElement.LM(  s*      "<99'''Kr:   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

)r9   r   r   r5   r   r   r3  r   s      r8   leading_monomPolyElement.leading_monom0  s>     IINN  "ii&&**AGr:   c                    U R                  5       nUc6  U R                  R                  U R                  R                  R                  4$ XR                  U5      4$ r[   )r   r9   r   r5   r   r  r  s     r8   r  PolyElement.LTE  sL      "<II(($))*:*:*?*?@@//$/00r:   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

)r9   r   r   r  s      r8   leading_termPolyElement.leading_termM  s3     IINN  "jAGr:   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  rY   )r   s    r8   rs   %PolyElement._sorted.<locals>.<lambda>h  s    qr:   T)rx   reversec                   > T" U S   5      $ r  rY   )r   r6   s    r8   rs   r  j  s    uQxr:   )r9   r6   r   r~   r    sorted)r   rX   r6   s     `r8   _sortedPolyElement._sorteda  sL    =IIOOE''.EC<##94HH##@$OOr:   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]

ro  )r   r6   _r   s       r8   rP   PolyElement.coeffsl  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   r6   r   r  s       r8   monomsPolyElement.monoms  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  rC   rI   )r   r6   s     r8   ro  PolyElement.terms  s     0 ||D.66r:   c                4    [        U R                  5       5      $ )z,Iterator over coefficients of a polynomial. )iterrF   r   s    r8   
itercoeffsPolyElement.itercoeffs      DKKM""r:   c                4    [        U R                  5       5      $ )z)Iterator over monomials of a polynomial. )r  r  r   s    r8   r  PolyElement.itermonoms      DIIK  r:   c                4    [        U R                  5       5      $ )z%Iterator over terms of a polynomial. )r  rI   r   s    r8   rf  PolyElement.iterterms      DJJL!!r:   c                4    [        U R                  5       5      $ )z+Unordered list of polynomial coefficients. )rC   rF   r   s    r8   
listcoeffsPolyElement.listcoeffs  r  r:   c                4    [        U R                  5       5      $ )z(Unordered list of polynomial monomials. )rC   r  r   s    r8   
listmonomsPolyElement.listmonoms  r  r:   c                4    [        U R                  5       5      $ )z$Unordered list of polynomial terms. r  r   s    r8   	listtermsPolyElement.listterms  r   r:   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)r9   r   clear)r3  rT   r  s      r8   rT  PolyElement.imul_num  sD    4    3JGGICFaKF r:   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. )r9   r5   r   r   r  )rz   r5   contr   r   s        r8   r   PolyElement.content  sB    {{jj\\^Et#D $ r:   c                    U R                  5       nXR                  R                  R                  :X  a  X4$ XR	                  U5      4$ )z,Returns content and a primitive polynomial. )r   r9   r5   r   r_  )rz   r  s     r8   	primitivePolyElement.primitive   s;    yy{66==%%%9\\$'''r:   c                J    U (       d  U $ U R                  U R                  5      $ )z5Divides all coefficients by the leading coefficient. )r_  r  r  s    r8   monicPolyElement.monic  s    H<<%%r:   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 r[   )r9   r   rf  r   )rz   r  r   r   ro  s        r8   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 r[   )r9   r   rI   r   )rz   r   r   f_monomf_coeffro  s         r8   	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 r[   )r9   r   r   r  r   rI   r   )rz   r  r   r   r   r  r  ro  s           r8   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 r[  )r9   r5   r]  r   rz  rq  rf  r   )rz   r  r5   rq  r   r   ro  s          r8   r_  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 r[  )r]  r9   r   r   r_  r  rf  r   )rz   r  r   r   r  tro  s          r8   quo_termPolyElement.quo_term6  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  )r9   r5   is_ZZrf  r   r   r  )rz   r3  ro  r   r   r   s         r8   trunc_groundPolyElement.trunc_groundE  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$ r[   )r   r9   r5   r   r_  )r   r  rz   fcgcr   s         r8   extract_groundPolyElement.extract_groundY  s[    YY[YY[ffmm'LLLLqyr:   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 r[   )r9   r5   r   absr  )rz   	norm_func
ground_absr   s       r8   _normPolyElement._norme  sT    66==%%%**JallnNnUz%0nNOONs   A4c                ,    U R                  [        5      $ r[   )r3  ry   r  s    r8   max_normPolyElement.max_norml      wws|r:   c                ,    U R                  [        5      $ r[   )r3  rE   r  s    r8   l1_normPolyElement.l1_normo  r8  r:   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  rY   )r_   rr   s     r8   ra   &PolyElement.deflate.<locals>.<genexpr>  s     !q!Avqs   )r9   rC   rl   r  r  r   r{   rf   r   rf  rH   r   )rz   r  r9   rU   Jr3  r   r   rS   rr   HhIr   rW  Ns                   r8   deflatePolyElement.deflater  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 r[   )r9   r   rf  rH   r{   )rz   r?  r   rB  r   r   rW  rC  s           r8   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       $ r[   )	r9   r5   rz  r  r   rq  r   r  r  )r   r  rz   r5   r+  r,  rT   rA  s           r8   r   PolyElement.lcm  s|    KKMEBKKMEB

2"ASIIaeeAh<<?"779r:   c                *    U R                  U5      S   $ r  )	cofactorsrz   r  s     r8   r   PolyElement.gcd  s    {{1~a  r:   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   )r9   r   	_gcd_zeror|   
_gcd_monomrD  _gcdrG  )rz   r  r   rA  cffcfgr?  s          r8   rL  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==r:   c                    U R                   R                  U R                   R                  p2UR                  (       a  XU4$ U* X2* 4$ r[   )r9   r   r   r  )rz   r  r   r   s       r8   rP  PolyElement._gcd_zero  s:    FFJJTC<2tT>!r:   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  )	r9   r5   r   rq  r   r   rC   rf  r   )rz   r  r9   
ground_gcd
ground_quor   r   mfcf_mgcd_cgcdr  r  rA  rS  rT  s                   r8   rQ  PolyElement._gcd_monom  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      $ r[   )r9   r5   is_QQ_gcd_QQr'  _gcd_ZZdmp_inner_gcd)rz   r  r9   s      r8   rR  PolyElement._gcd  sR    vv;;99Q<[[99Q<%%a++r:   c                    [        X5      $ r[   r   rM  s     r8   rc  PolyElement._gcd_ZZ  s    a|r:   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  )r9   r   r5   r|  r  rp  rc  r  r  r  rq  )r   r  rz   r9   rn  r\  r  rA  rS  rT  rT   s              r8   rb  PolyElement._gcd_QQ  s    vv::T[[%9%9%;:<  JJx JJx iilJJtttQWWY1ll4 ++DKKOOA,BCll4 ++DKKOOA,BCs{r:   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   Xg4$ 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  )r9   r   r5   rz  r{  rL  r   r|  r  rp  r  canonical_unit)r   r  rz   r9   r5   r  r3  r  rn  cqcpus               r8   cancelPolyElement.cancel  sd    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
 

? t ::+2rq
 t QAQAtr:   c                d    U R                   R                  nUR                  U R                  5      $ r[   )r9   r5   rk  r  )rz   r5   s     r8   rk  PolyElement.canonical_unit6	  s$    $$QTT**r:   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

)r9   r  r   r   rf  r   r   )	rz   r  r9   r   rS   r  r   r   es	            r8   diffPolyElement.diff:	  sy     vvJJqM"II;;=KDww&&t/u!W}5 ) r:   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|   r9   rl   evaluaterC   rH   r3   r   )rz   rF   s     r8   rQ  PolyElement.__call__S	  sb    s6{*affll*::d3qvv{{F#;<==TUTZTZT`T`beflbmnoor:   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\   rC   rx  r  r9   r  r5   r   rl   r   rf  )r   r  rq   rz   XYr9   r   resultrH  r   r   r   s                r8   rx  PolyElement.evaluateY	  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   rn   )r\   rC   subsr9   r  r5   r   rl   r   rf  r   )r   r  rq   rz   r{  r9   r   r}  rH  r   r   r   s               r8   r  PolyElement.subs	  s'   a19FF1L HvvJJqMKK"::?[[%%F {{}*$  - ??6**99D ! 8U2AY%5cd%C5d
=!K/E&+U Ku&+U !. Kr:   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   $ r[   rY   )r   rH  poly_powersrU   s     r8   get_poly_power.PolyElement.symmetrize.<locals>.get_poly_power	  s.    v[(&+AhkQF#v&&r:   r   r  )r  NNc              3  @   >#    U  H  nTU   TUS -      :  v   M     g7fr  rY   )r_   r   r   s     r8   ra   )PolyElement.symmetrize.<locals>.<genexpr>	  s"     AAuQx5Q</rG  c              3  .   #    U  H  u  pX-  v   M     g 7fr[   rY   )r_   rH  rS   s      r8   ra   r   
  s      E1D1Ds   Nrn   )r   r9   rl   r   r   rI  rC   r  ro  rf   ry   rH   r   r   r{   r3   )r   rz   r9   rH  r   r  r  weights	symmetric_height_monom_coeffr   height	exponentsr  m2productr  r   r  rU   s                      @@@r8   
symmetrizePolyElement.symmetrize	  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  rY   )r  gens_maps    r8   rs   %PolyElement.compose.<locals>.<lambda>$
  s    x!~r:   rw   z9expected a generator, value pair a sequence of such pairsr   )r9   r   rG   rH   r3   r   rl   r\   rC   r  rI   r   r  r   rf  r   r  r{   )rz   r  rq   r9   r   replacementsr  r  r   r   subpolyr   rH  r  s                @r8   r?  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 * r:   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

Nrn   r   )r9   r  rf  r   rH   rJ   rG   )
r   r  degr3  r   rS   rT   ro  r  rP   s
             r8   	coeff_wrtPolyElement.coeff_wrt9
  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-  $ )ag  
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 difference 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   r\  r   r9   r  r  r]  r  r3   )r   r  r  rz   dfdgr  drrC  lc_gxplc_rrW  Rr  rT   s                   r8   premPolyElement.premn
  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r:   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   r\  r   r  )r   r  r  rz   r  r  r  r  r  rC  r  r  r  rW  Qr  r  rT   s                     r8   pdivPolyElement.pdiv
  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r:   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  rz   s       r8   pquoPolyElement.pquoG  s    6 vva|Ar:   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 difference 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  rz   r  r  s         r8   pexquoPolyElement.pexquoe  s/    : vva|99H%a++r:   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  )r9   r  r  r  r  r   ry  )r   r  r  rz   rH  rS   r  drr   rA  lcrT   Sr  r3  r  s                   r8   subresultantsPolyElement.subresultants  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* r:   c                8    U R                   R                  X5      $ r[   )r9   dmp_half_gcdexrM  s     r8   
half_gcdexPolyElement.half_gcdex  s    vv$$Q**r:   c                8    U R                   R                  X5      $ r[   )r9   	dmp_gcdexrM  s     r8   gcdexPolyElement.gcdex      vv%%r:   c                8    U R                   R                  X5      $ r[   )r9   dmp_resultantrM  s     r8   	resultantPolyElement.resultant  s    vv##A))r:   c                8    U R                   R                  U 5      $ r[   )r9   dmp_discriminantr  s    r8   discriminantPolyElement.discriminant  s    vv&&q))r:   c                    U R                   R                  (       a  U R                   R                  U 5      $ [        S5      e)Nzpolynomial decomposition)r9   r)  dup_decomposer%   r  s    r8   	decomposePolyElement.decompose  s0    6666''**-.HIIr:   c                    U R                   R                  (       a  U R                   R                  X5      $ [        S5      e)Nzshift: use shift_list instead)r9   r)  	dup_shiftr%   rz   rq   s     r8   shiftPolyElement.shift  s0    6666##A))-.MNNr:   c                8    U R                   R                  X5      $ r[   )r9   	dmp_shiftr  s     r8   
shift_listPolyElement.shift_list  r  r:   c                    U R                   R                  (       a  U R                   R                  U 5      $ [        S5      e)Nzsturm sequence)r9   r)  	dup_sturmr%   r  s    r8   sturmPolyElement.sturm  s0    6666##A&&-.>??r:   c                8    U R                   R                  U 5      $ r[   )r9   dmp_gff_listr  s    r8   gff_listPolyElement.gff_list      vv""1%%r:   c                8    U R                   R                  U 5      $ r[   )r9   dmp_normr  s    r8   normPolyElement.norm  s    vvq!!r:   c                8    U R                   R                  U 5      $ r[   )r9   dmp_sqf_normr  s    r8   sqf_normPolyElement.sqf_norm  r  r:   c                8    U R                   R                  U 5      $ r[   )r9   dmp_sqf_partr  s    r8   sqf_partPolyElement.sqf_part  r  r:   c                4    U R                   R                  XS9$ )N)rf   )r9   dmp_sqf_list)rz   rf   s     r8   sqf_listPolyElement.sqf_list  s    vv""1"..r:   c                8    U R                   R                  U 5      $ r[   )r9   dmp_factor_listr  s    r8   factor_listPolyElement.factor_list  s    vv%%a((r:   )r   r9   r[   )F)r   rK  rL  rM  rN  rV  r^  r   rc  r   r   r   r   rp  rt  rs  r  r  r   r   r  r  r  r  r  r  r  r  r  r  r9  r  r  r]   rP  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r!  r$  r'  r,  r*  r2  r1  r=  r7  rH  rG  rF  rE  rb  r^  rk  rj  rs  rv  rz  rr  r  r   ri  rq  ry  r  r  r  r  r  r  r   r  r   r  r  r  r  r  r  r  rP   r  ro  r  r  rf  r  r  r  rT  r   r  r  r  r  r  r_  r$  r(  r`  r-  r3  r6  r:  rD  rG  r   r   rL  rP  rQ  rR  rc  rb  ro  rk  ru  rQ  rx  r  r  r?  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rR  __classcell__)r   s   @r8   r   r   J  sU   ?K/%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82h:4(l :#J:,%,%,%, 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&@&"&&/) )r:   r   N)r6   zMonomialOrder | str)QrN  
__future__r   operatorr   r   r   r   r   r	   	functoolsr
   typesr   sympy.core.cacher   sympy.core.exprr   sympy.core.intfuncr   sympy.core.symbolr   r   re   sympy.core.sympifyr   r   sympy.ntheory.multinomialr   sympy.polys.compatibilityr   sympy.polys.constructorr   sympy.polys.densebasicr   r   r   sympy.polys.domains.domainr   !sympy.polys.domains.domainelementr   "sympy.polys.domains.polynomialringr   sympy.polys.heuristicgcdr   sympy.polys.monomialsr   sympy.polys.orderingsr    r!   sympy.polys.polyerrorsr"   r#   r$   r%   sympy.polys.polyoptionsr}   r&   r   r'   sympy.polys.polyutilsr(   r)   r*   sympy.printing.defaultsr+   sympy.utilitiesr,   r-   sympy.utilities.iterablesr.   sympy.utilities.magicr/   r9   r<   r@   rV   rh   r2   rG   r   rY   r:   r8   <module>r     s     " - -   $   # 9 3 > , 4 C C - ; = + - 46 6G G= = 3 + 1 )58 ! !< !$  < !$  < 2 2h@C CLN')-+t N')r:   