
    gF                   4   U d Z ddlmZ ddlmZ ddlmZmZmZm	Z	m
Z
mZ ddlmZ ddlmZ ddlmZ ddlmZ dd	lmZmZ dd
lmZmZ ddlmZ ddlmZ ddlm Z  ddl!m"Z"m#Z#m$Z$ ddl%m&Z& ddl'm(Z( ddl)m*Z* ddl+m,Z, ddl-m.Z. ddl/m0Z0m1Z1m2Z2m3Z3 ddl4m5Z6m7Z8m9Z9 ddl:m;Z;m<Z<m=Z= ddl>m?Z? ddl@mAZAmBZB ddlCmDZD ddlEmFZF eAe.fd            ZGeAe.fd            ZHeAe.fd            ZIeAd             ZJd ZKi ZLd eMd!<    G d" d#e?e          ZN G d$ d%e&e?eeO          ZPd&S )'zSparse polynomial rings.     )annotations)Any)addmulltlegtge)reduce)GeneratorType)Expr)igcd)Symbolsymbols)CantSympifysympify)multinomial_coefficients)IPolys)construct_domain)ninfdmp_to_dictdmp_from_dict)DomainElementPolynomialRingheugcd)MonomialOps)lex)CoercionFailedGeneratorsErrorExactQuotientFailedMultivariatePolynomialError)DomainOrderbuild_options)expr_from_dict_dict_reorder_parallel_dict_from_expr)DefaultPrinting)publicsubsets)is_sequence)pollutec                :    t          | ||          }|f|j        z   S )a  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       M/var/www/html/ai-engine/env/lib/python3.11/site-packages/sympy/polys/rings.pyringr8   #   s$    8 Wfe,,E8ej      c                6    t          | ||          }||j        fS )a  Construct a polynomial ring returning ``(ring, (x_1, ..., x_n))``.

    Parameters
    ==========

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

    Examples
    ========

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

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

    r0   r3   s       r7   xringr;   B   s"    8 Wfe,,E5:r9   c                p    t          | ||          }t          d |j        D             |j                   |S )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'>

    c                    g | ]	}|j         
S  )name).0syms     r7   
<listcomp>zvring.<locals>.<listcomp>}   s    1113ch111r9   )r1   r.   r   r2   r3   s       r7   vringrC   a   s=    6 Wfe,,E11%-1115:>>>Lr9   c                (  
 d}t          |           s| gd}} t          t          t          |                     } t	          ||          }t          | |          \  }}|j        ^t          d |D             g           }t          ||          \  |_        }t          t          ||                    

fd|D             }t          |j        |j        |j                  }t          t          |j        |                    }	|r
||	d         fS ||	fS )ad  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'>

    FTNc                P    g | ]#}t          |                                          $S r>   listvalues)r@   reps     r7   rB   zsring.<locals>.<listcomp>   s(    ;;;ctCJJLL));;;r9   )optc                P    g | ]"}fd |                                 D             #S )c                (    i | ]\  }}||         S r>   r>   )r@   mc	coeff_maps      r7   
<dictcomp>z$sring.<locals>.<listcomp>.<dictcomp>   s#    999TQIaL999r9   )items)r@   rI   rO   s     r7   rB   zsring.<locals>.<listcomp>   s6    JJJc9999SYY[[999JJJr9   r   )r-   rG   mapr   r&   r)   r4   sumr   dictzipr1   r2   r5   	from_dict)exprsr   optionssinglerJ   repscoeffs
coeffs_domr6   polysrO   s             @r7   sringr^      s    4 Fu &vWe$$%%E

)
)C )44ID#
z;;T;;;R@@!1&c!B!B!B
JVZ0011	JJJJTJJJSXsz3955EU_d++,,E uQx  u~r9   c                H   t          | t                    r| rt          | d          ndS t          | t                    r| fS t	          |           rCt          d | D                       rt          |           S t          d | D                       r| S t          d          )NT)seqr>   c              3  @   K   | ]}t          |t                    V  d S N)
isinstancestrr@   ss     r7   	<genexpr>z!_parse_symbols.<locals>.<genexpr>   s,      33az!S!!333333r9   c              3  @   K   | ]}t          |t                    V  d S rb   )rc   r   re   s     r7   rg   z!_parse_symbols.<locals>.<genexpr>   s,      66At$$666666r9   zbexpected a string, Symbol or expression or a non-empty sequence of strings, Symbols or expressions)rc   rd   _symbolsr   r-   allr!   r   s    r7   _parse_symbolsrl      s    '3 .5=xT****2=	GT	"	" z	W		 33733333 	G$$$66g66666 	N
~

r9   zdict[Any, Any]_ring_cachec                  .   e Zd ZdZefdZd Zd Zd Zd Z	d Z
d Zd%d
Zd Zed             Zed             Zd&dZd Zd Zd ZeZd&dZd&dZd Zd Zd Zd Zd Zd Zd Zd Zd Z ed             Z!ed             Z"d Z#d  Z$d! Z%d" Z&d# Z'd$ Z(d	S )'r1   z*Multivariate distributed polynomial ring. c                   t          t          |                    }t          |          }t          j        |          }t          j                  | j        |||f}t                              |          }|v|j	        r3t          |          t          |j                  z  rt          d          t                              |           }||_        t!          |          |_        t%          dt&          fd|i          |_        ||_        ||_        ||_        |_        d|z  |_        |                                |_        t          |j                  |_        |j        |j        fg|_        |rt=          |          }|                                |_         |!                                |_"        |#                                |_$        |%                                |_&        |'                                |_(        |)                                |_*        |+                                |_,        n5d }||_         ||_"        d |_$        ||_&        ||_(        ||_*        ||_,        tZ          u rt\          |_/        n
fd|_/        ta          |j        |j                  D ]B\  }	}
tc          |	td                    r(|	j3        }ti          ||          stk          |||
           C|t          |<   |S )Nz7polynomial ring and it's ground domain share generatorsPolyElementr8   r   c                    dS Nr>   r>   )abs     r7   <lambda>z"PolyRing.__new__.<locals>.<lambda>   s    r r9   c                    dS rs   r>   )rt   ru   rN   s      r7   rv   z"PolyRing.__new__.<locals>.<lambda>   s    b r9   c                &    t          |           S )Nkey)max)fr5   s    r7   rv   z"PolyRing.__new__.<locals>.<lambda>   s    S->->-> r9   )6tuplerl   len	DomainOpt
preprocessOrderOpt__name__rm   getis_Compositesetr   r!   object__new___hash_tuplehash_hashtyperp   dtypengensr4   r5   
zero_monom_gensr2   	_gens_setone_oner   r   monomial_mulpowmonomial_powmulpowmonomial_mulpowldivmonomial_ldivdivmonomial_divlcmmonomial_lcmgcdmonomial_gcdr   r{   leading_expvrU   rc   r   r?   hasattrsetattr)clsr   r4   r5   r   r   objcodegenmonunitsymbol	generatorr?   s      `        r7   r   zPolyRing.__new__   s   w//00G%f--#E**|WeVUCook**;" as7||c&.6I6I'I a%&_```..%%C)CO[))CI][NVSMJJCI!CKCICJCI!%ZCNyy{{CHMMCM45CH +%e,,#*;;== #*;;== &-nn&6&6#$+LLNN!#*;;== #*;;== #*;;==  )/#* #* &8&8#$+!#* #* #*  ||#&  #>#>#>#> %(ch%?%? 6 6!	ff-- 6!;D"3-- 6T9555'*K$
r9   c                    | j         j        }g }t          | j                  D ]8}|                     |          }| j        }|||<   |                    |           9t          |          S )z(Return a list of polynomial generators. )r4   r   ranger   monomial_basiszeroappendr}   )selfr   r   iexpvpolys         r7   r   zPolyRing._gens  sm    kotz"" 	 	A&&q))D9DDJLLU||r9   c                *    | j         | j        | j        fS rb   )r   r4   r5   r   s    r7   __getnewargs__zPolyRing.__getnewargs__  s    dk4:66r9   c                x    | j                                         }|d= |D ]}|                    d          r||= |S )Nr   	monomial_)__dict__copy
startswith)r   staterz   s      r7   __getstate__zPolyRing.__getstate__  sM    ""$$.! 	 	C~~k** #Jr9   c                    | j         S rb   )r   r   s    r7   __hash__zPolyRing.__hash__   s
    zr9   c                    t          |t                    o5| j        | j        | j        | j        f|j        |j        |j        |j        fk    S rb   )rc   r1   r   r4   r   r5   r   others     r7   __eq__zPolyRing.__eq__#  sI    %** D\4;
DJ?]EL%+u{CD	Dr9   c                    | |k     S rb   r>   r   s     r7   __ne__zPolyRing.__ne__(  s    5=  r9   Nc                Z    |                      |p| j        |p| j        |p| j                  S rb   )	__class__r   r4   r5   )r   r   r4   r5   s       r7   clonezPolyRing.clone+  s/    ~~g5v7LeNaW[Wabbbr9   c                @    dg| j         z  }d||<   t          |          S )zReturn the ith-basis element. r      )r   r}   )r   r   basiss      r7   r   zPolyRing.monomial_basis.  s$    DJaU||r9   c                *    |                                  S rb   )r   r   s    r7   r   zPolyRing.zero4  s    zz||r9   c                6    |                      | j                  S rb   )r   r   r   s    r7   r   zPolyRing.one8  s    zz$)$$$r9   c                8    | j                             ||          S rb   )r4   convertr   elementorig_domains      r7   
domain_newzPolyRing.domain_new<  s    {""7K888r9   c                8    |                      | j        |          S rb   )term_newr   )r   coeffs     r7   
ground_newzPolyRing.ground_new?  s    }}T_e444r9   c                L    |                      |          }| j        }|r|||<   |S rb   )r   r   )r   monomr   r   s       r7   r   zPolyRing.term_newB  s0    &&y 	 DKr9   c                   t          |t                    r`| |j        k    r|S t          | j        t                    r*| j        j        |j        k    r|                     |          S t          d          t          |t                    rt          d          t          |t                    r| 	                    |          S t          |t                    r;	 |                     |          S # t          $ r |                     |          cY S w xY wt          |t                    r|                     |          S |                     |          S )N
conversionparsing)rc   rp   r8   r4   r   r   NotImplementedErrorrd   rT   rV   rG   
from_terms
ValueError	from_listr   	from_exprr   r   s     r7   ring_newzPolyRing.ring_newI  sC   g{++ 	,w|##DK88 8T[=MQXQ]=]=]w///),777%% 	,%i000&& 
	,>>'***&& 	,/w/// / / /~~g...../&& 	,>>'***??7+++s   C/ /DDc                |    | j         }| j        }|                                D ]\  }} |||          }|r|||<   |S rb   )r   r   rQ   )r   r   r   r   r   r   r   s          r7   rV   zPolyRing.from_dicta  sS    _
y#MMOO 	$ 	$LE5Juk22E $#Ur9   c                H    |                      t          |          |          S rb   )rV   rT   r   s      r7   r   zPolyRing.from_termsl  s    ~~d7mm[999r9   c                d    |                      t          || j        dz
  | j                            S Nr   )rV   r   r   r4   r   s     r7   r   zPolyRing.from_listo  s(    ~~k'4:a<MMNNNr9   c                X      j          fd t          |                    S )Nc           	                             |           }||S | j        r5t          t          t	          t          | j                                      S | j        r5t          t          t	          t          | j                                      S | 	                                \  }}|j
        r!|dk    r |          t          |          z  S                                         |                     S r   )r   is_Addr   r   rG   rR   argsis_Mulr   as_base_exp
is_Integerintr   r   )exprr   baseexp_rebuildr4   mappingr   s       r7   r   z(PolyRing._rebuild_expr.<locals>._rebuildu  s    D))I$   Ac4Hdi(@(@#A#ABBB 	Ac4Hdi(@(@#A#ABBB !,,..	c> AcAgg#8D>>3s8833??6>>$+?+?@@@r9   )r4   r   )r   r   r   r   r4   s   ` `@@r7   _rebuild_exprzPolyRing._rebuild_exprr  sU    	A 	A 	A 	A 	A 	A 	A 	A$ x&&&r9   c                   t          t          t          | j        | j                                      }	 |                     ||          }|                     |          S # t          $ r t          d| d|          w xY w)Nz6expected an expression convertible to a polynomial in z, got )	rT   rG   rU   r   r2   r   r   r    r   )r   r   r   r   s       r7   r   zPolyRing.from_expr  s    tCdi8899::	'%%dG44D ==&&&  	p 	p 	p*cgcgcgimimnooo	ps   A! ! Bc                8   || j         rd}nd}nt          |t                    r?|}d|k    r|| j         k     rn| j          |k    r|dk    r| dz
  }nt          d|z            t          || j                  r<	 | j                            |          }n# t          $ r t          d|z            w xY wt          |t                    r<	 | j                            |          }n2# t          $ r t          d|z            w xY wt          d|z            |S )z+Compute index of ``gen`` in ``self.gens``. Nr   r   zinvalid generator index: %szinvalid generator: %szEexpected a polynomial generator, an integer, a string or None, got %s)	r   rc   r   r   r   r2   indexrd   r   )r   genr   s      r7   r   zPolyRing.index  sg   ;z S!! 	lAAvv!dj..*!!a2ggBF !>!DEEETZ(( 	l@IOOC(( @ @ @ !83!>???@S!! 	l@L&&s++ @ @ @ !83!>???@ dgjjkkks   <B B4C( (Dc                    t          t          | j        |                    fdt          | j                  D             }|s| j        S |                     |          S )z,Remove specified generators from this ring. c                "    g | ]\  }}|v	|S r>   r>   r@   r   rf   indicess      r7   rB   z!PolyRing.drop.<locals>.<listcomp>  s'    OOO$!QQg=M=MA=M=M=Mr9   rk   )r   rR   r   	enumerater   r4   r   r   r2   r   r   s      @r7   dropzPolyRing.drop  sc    c$*d++,,OOOO)DL"9"9OOO 	/;::g:...r9   c                Z    | j         |         }|s| j        S |                     |          S )Nrk   )r   r4   r   )r   rz   r   s      r7   __getitem__zPolyRing.__getitem__  s2    ,s# 	/;::g:...r9   c                    | j         j        st          | j         d          r |                     | j         j                   S t	          d| j         z            )Nr4   r4   z%s is not a composite domain)r4   r   r   r   r   r   s    r7   	to_groundzPolyRing.to_ground  sS    ;# 	Kwt{H'E'E 	K::T[%7:888;dkIJJJr9   c                     t          |           S rb   r   r   s    r7   	to_domainzPolyRing.to_domain  s    d###r9   c                F    ddl m}  || j        | j        | j                  S )Nr   )	FracField)sympy.polys.fieldsr  r   r4   r5   )r   r  s     r7   to_fieldzPolyRing.to_field  s.    000000yt{DJ???r9   c                2    t          | j                  dk    S r   r~   r2   r   s    r7   is_univariatezPolyRing.is_univariate  s    49~~""r9   c                2    t          | j                  dk    S r   r  r   s    r7   is_multivariatezPolyRing.is_multivariate  s    49~~!!r9   c                p    | j         }|D ]+}t          |t                    r| | j        | z  }&||z  },|S )aw  
        Add a sequence of polynomials or containers of polynomials.

        Examples
        ========

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

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

        include)r   r-   r   r   r   objspr   s       r7   r   zPolyRing.add  sS    " I 	 	C3666 XTXs^#Sr9   c                p    | j         }|D ]+}t          |t                    r| | j        | z  }&||z  },|S )a  
        Multiply a sequence of polynomials or containers of polynomials.

        Examples
        ========

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

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

        r  )r   r-   r   r   r  s       r7   r   zPolyRing.mul  sS    " H 	 	C3666 XTXs^#Sr9   c                   t          t          | j        |                    fdt          | j                  D             }fdt          | j                  D             }|s| S |                     | | j        |           S )zd
        Remove specified generators from the ring and inject them into
        its domain.
        c                "    g | ]\  }}|v	|S r>   r>   r   s      r7   rB   z+PolyRing.drop_to_ground.<locals>.<listcomp>  s'    MMMAAW<L<L1<L<L<Lr9   c                "    g | ]\  }}|v	|S r>   r>   )r@   r   r   r   s      r7   rB   z+PolyRing.drop_to_ground.<locals>.<listcomp>  s'    KKK3!7:J:J:J:J:Jr9   r   r4   )r   rR   r   r   r   r2   r   r   r   s      @r7   drop_to_groundzPolyRing.drop_to_ground  s    
 c$*d++,,MMMM4<!8!8MMMKKKK)DI"6"6KKK 	HK::gidi6F:GGGr9   c                    | |k    r\t          | j                                      t          |j                            }|                     t	          |                    S | S )z+Add the generators of ``other`` to ``self``rk   r   r   unionr   rG   )r   r   symss      r7   composezPolyRing.compose  sQ    5==t|$$**3u}+=+=>>D::d4jj:111Kr9   c                    t          | j                                      t          |                    }|                     t	          |                    S )z9Add the elements of ``symbols`` as generators to ``self``rk   r  )r   r   r  s      r7   add_genszPolyRing.add_gens&  s?    4<  &&s7||44zz$t**z---r9   c                   |dk     s|| j         k    rt          d|d| j                  |s| j        S | j        }t          t          | j                   t          |                    D ]Rt          fdt          | j                   D                       }|| 	                    || j
        j                  z  }S|S )zo
        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  :   K   | ]}t          |v           V  d S rb   )r   )r@   r   rf   s     r7   rg   z*PolyRing.symmetric_poly.<locals>.<genexpr>7  s-      EEac!q&kkEEEEEEr9   )r   r   r2   r   r   r,   r   r   r}   r   r4   )r   nr   r   rf   s       @r7   symmetric_polyzPolyRing.symmetric_poly+  s    
 q55A
NN*Z[Z[Z[]a]f]fghhh 	8O9DU4:..A77 > >EEEE53D3DEEEEEeT[_===Kr9   )NNNrb   ))r   
__module____qualname____doc__r   r   r   r   r   r   r   r   r   r   propertyr   r   r   r   r   r   __call__rV   r   r   r   r   r   r   r  r  r  r
  r  r  r   r   r  r   r"  r&  r>   r9   r7   r1   r1      s       44,/ ? ? ? ?B	 	 	7 7 7    D D D
! ! !c c c c     X % % X%9 9 9 95 5 5  , , ,, H	 	 	 	: : : :O O O' ' '.' ' '  >/ / // / /K K K$ $ $@ @ @ # # X# " " X"  6  6H H H  . . .
    r9   r1   c                     e Zd ZdZd Zd Zd ZdZd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd ZddZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zed             Z ed             Z!ed             Z"ed              Z#ed!             Z$ed"             Z%ed#             Z&ed$             Z'ed%             Z(ed&             Z)ed'             Z*ed(             Z+ed)             Z,ed*             Z-ed+             Z.ed,             Z/ed-             Z0d. Z1d/ Z2d0 Z3d1 Z4d2 Z5d3 Z6d4 Z7d5 Z8d6 Z9d7 Z:d8 Z;d9 Z<d: Z=d; Z>d< Z?d= Z@d> ZAd? ZBeAZCeBZDd@ ZEdA ZFdB ZGdC ZHdD ZIdE ZJdF ZKddGZLdH ZMddIZNdJ ZOdK ZPdL ZQdM ZRdN ZSedO             ZTedP             ZUdQ ZVedR             ZWdS ZXdT ZYddUZZddVZ[ddWZ\dX Z]dY Z^dZ Z_d[ Z`d\ Zad] Zbd^ Zcd_ Zdd` Zeda Zfdb Zgdc Zhdd Zide Zjdf Zkdg ZlelZmdh Zndi Zodj Zpdk Zqdl Zrdm Zsdn Ztdo Zudp Zvdq Zwdr Zxds Zydt Zzdu Z{dv Z|dw Z}dx Z~dy ZddzZdd{Zd| Zdd}Zd~ ZddZddZddZddZddZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZddZd ZdS )rp   z5Element of multivariate distributed polynomial ring. c                ,    |                      |          S rb   )r   )r   inits     r7   newzPolyElement.new?  s    ~~d###r9   c                4    | j                                         S rb   )r8   r  r   s    r7   parentzPolyElement.parentB  s    y""$$$r9   c                R    | j         t          |                                           fS rb   )r8   rG   	itertermsr   s    r7   r   zPolyElement.__getnewargs__E  s!    	4 0 01122r9   Nc                    | j         }|<t          | j        t          |                                           f          x| _         }|S rb   )r   r   r8   	frozensetrQ   )r   r   s     r7   r   zPolyElement.__hash__J  s@     
=!%ty)DJJLL2I2I&J!K!KKDJr9   c                ,    |                      |           S )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    r7   r   zPolyElement.copyU  s    4 xx~~r9   c           	     .   | j         |k    r| S | j         j        |j        k    rTt          t          t	          | | j         j        |j                             }|                    || j         j                  S |                    | | j         j                  S rb   )r8   r   rG   rU   r(   r   r4   rV   )r   new_ringtermss      r7   set_ringzPolyElement.set_ringq  s    9  KY("222mD$)2CXEUVVWXXE&&udi.>???%%dDI,<===r9   c                    |s| j         j        }nIt          |          | j         j        k    r,t	          d| j         j        dt          |                    t          |                                 g|R  S )Nz"Wrong number of symbols, expected z got )r8   r   r~   r   r   r'   as_expr_dict)r   r   s     r7   as_exprzPolyElement.as_exprz  s}     	i'GG\\TY_,,*#g,,,0  
 d//11<G<<<<r9   c                f    | j         j        j        fd|                                 D             S )Nc                .    i | ]\  }}| |          S r>   r>   )r@   r   r   to_sympys      r7   rP   z,PolyElement.as_expr_dict.<locals>.<dictcomp>  s'    LLL<5%xxLLLr9   )r8   r4   r@  r3  )r   r@  s    @r7   r<  zPolyElement.as_expr_dict  s4    9#,LLLL4>>;K;KLLLLr9   c                b   | j         j        }|j        r|j        s	|j        | fS |                                }|j        |j        }|j        }|                                 D ]} | ||                    | 	                    fd| 
                                D                       }|fS )Nc                $    g | ]\  }}||z  fS r>   r>   )r@   kvcommons      r7   rB   z,PolyElement.clear_denoms.<locals>.<listcomp>  s%    BBBDAq1ah-BBBr9   )r8   r4   is_Fieldhas_assoc_Ringr   get_ringr   denomrH   r/  rQ   )r   r4   ground_ringr   rI  r   r   rE  s          @r7   clear_denomszPolyElement.clear_denoms  s    ! 	$f&; 	$:t##oo''o[[]] 	/ 	/ESu..FFxxBBBBDJJLLBBBCCt|r9   c                ^    t          |                                           D ]
\  }}|s| |= dS )z+Eliminate monomials with zero coefficient. NrG   rQ   )r   rC  rD  s      r7   
strip_zerozPolyElement.strip_zero  s?    && 	 	DAq G	 	r9   c                    |s|  S t          |t                    r+|j        | j        k    rt                              | |          S t          |           dk    rdS |                     | j        j                  |k    S )aP  Equality 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)rc   rp   r8   rT   r   r~   r   r   p1p2s     r7   r   zPolyElement.__eq__  sw    "  	46MK(( 	4RW-?-?;;r2&&&WWq[[566"',--33r9   c                    | |k     S rb   r>   rP  s     r7   r   zPolyElement.__ne__  s    8|r9   c                &   | j         }t          ||j                  rt          |                                           t          |                                          k    rdS |j        j        }|                                 D ]} || |         ||         |          s dS dS t          |           dk    rdS 	 |j                            |          }|j                            | 	                                ||          S # t          $ r Y dS w xY w)z+Approximate equality test for polynomials. FTr   )r8   rc   r   r   keysr4   almosteqr~   r   constr    )rQ  rR  	tolerancer8   rV  rC  s         r7   rV  zPolyElement.almosteq  s   wb$*%% 	G27799~~RWWYY//u{+HWWYY ! !x1r!ui88 ! 55!4WWq[[5G[((,, {++BHHJJIFFF "   uus   :D 
DDc                H    t          |           |                                 fS rb   )r~   r9  r   s    r7   sort_keyzPolyElement.sort_key  s    D		4::<<((r9   c                    t          || j        j                  r0 ||                                 |                                          S t          S rb   )rc   r8   r   rZ  NotImplemented)rQ  rR  ops      r7   _cmpzPolyElement._cmp  s@    b"'-(( 	"2bkkmmR[[]]333!!r9   c                8    |                      |t                    S rb   )r^  r   rP  s     r7   __lt__zPolyElement.__lt__      wwr2r9   c                8    |                      |t                    S rb   )r^  r   rP  s     r7   __le__zPolyElement.__le__  ra  r9   c                8    |                      |t                    S rb   )r^  r	   rP  s     r7   __gt__zPolyElement.__gt__  ra  r9   c                8    |                      |t                    S rb   )r^  r
   rP  s     r7   __ge__zPolyElement.__ge__  ra  r9   c                    | j         }|                    |          }|j        dk    r	||j        fS t	          |j                  }||= ||                    |          fS )Nr   rk   )r8   r   r   r4   rG   r   r   r   r   r8   r   r   s        r7   _dropzPolyElement._drop  s^    yJJsOO:??dk>!4<((G
djjj1111r9   c                x   |                      |          \  }}| j        j        dk    r.| j        r|                     d          S t          d|z            |j        }|                                 D ]G\  }}||         dk    r%t          |          }||= ||t          |          <   6t          d|z            |S )Nr   zCannot drop %sr   )
rj  r8   r   	is_groundr   r   r   rQ   rG   r}   )r   r   r   r8   r   rC  rD  Ks           r7   r   zPolyElement.drop  s    **S//49?a~ 9zz!}}$ !1C!78889D

 = =1Q4199QA!%&DqNN$%5%;<<<Kr9   c                    | j         }|                    |          }t          |j                  }||= ||                    |||                   fS )Nr  )r8   r   rG   r   r   ri  s        r7   _drop_to_groundzPolyElement._drop_to_ground  sM    yJJsOOt|$$AJ$**WT!W*====r9   c                   | j         j        dk    rt          d          |                     |          \  }}|j        }|j        j        d         }|                                 D ]o\  }}|d |         ||dz   d          z   }||vr"|||         z                      |          ||<   C||xx         |||         z                      |          z  cc<   p|S )Nr   z$Cannot drop only generator to groundr   )	r8   r   r   ro  r   r4   r2   r3  
mul_ground)r   r   r   r8   r   r   r   mons           r7   r  zPolyElement.drop_to_ground  s    9?aCDDD&&s++4ykq! NN,, 	? 	?LE5)eAaCDDk)C$ %(]66u==S		S			c58m77>>>				r9   c                R    t          | | j        j        dz
  | j        j                  S r   )r   r8   r   r4   r   s    r7   to_densezPolyElement.to_dense   s"    T49?1#4di6FGGGr9   c                     t          |           S rb   )rT   r   s    r7   to_dictzPolyElement.to_dict#  s    Dzzr9   c                   | s$|                     | j        j        j                  S |d         }|d         }| j        }|j        }|j        }	|j        }
g }|                                 D ]\  }}|j                            |          }|rdnd}|	                    |           ||
k    r7|                     |          }|r|
                    d          r
|dd          }n5|r| }|| j        j        j        k    r|                    ||d          }nd	}g }t          |	          D ]}||         }|s|                    ||         |d          }|dk    rO|t          |          k    s|d
k     r|                    ||d          }n|}|	                    |||fz             |	                    d|z             |r|g|z   }|	                    |                    |                     |d
         dv r1|                    d
          }|dk    r|                    d
d           d	                    |          S )NMulAtom -  + -r   T)strict r   Fz%s)r{  rz  )_printr8   r4   r   r   r   r   r9  is_negativer   r   r   parenthesizer   r   joinpopinsert)r   printer
precedenceexp_pattern
mul_symbolprec_mul	prec_atomr8   r   r   zmsexpvsr   r   negativesignscoeffsexpvr   r   r   sexpheads                          r7   rd   zPolyElement.str&  su    	9>>$)"2"7888e$v&	y,
_::<< 	2 	2KD%{..u55H$/55%DMM$rzz .. ( 1 1# 6 6 (#ABBZF #"FEDI,000$11%$1OOFFFE5\\ 0 01g  --gaj)D-QQ!88c#hh#''&33C53QQ"LL~!=>>>>LL//// )5(MM*//%001111!9&&::a==Du}}a%%%wwvr9   c                    | | j         j        v S rb   )r8   r   r   s    r7   is_generatorzPolyElement.is_generatorV  s    ty***r9   c                J    |  p t          |           dk    o| j        j        | v S r   )r~   r8   r   r   s    r7   rl  zPolyElement.is_groundZ  s(    xLCIINKty/Ct/KLr9   c                D    |  pt          |           dk    o
| j        dk    S r   )r~   LCr   s    r7   is_monomialzPolyElement.is_monomial^  s$    x<CIIN;tw!|<r9   c                (    t          |           dk    S r   )r~   r   s    r7   is_termzPolyElement.is_termb  s    4yyA~r9   c                J    | j         j                            | j                  S rb   )r8   r4   r  r  r   s    r7   r  zPolyElement.is_negativef      y++DG444r9   c                J    | j         j                            | j                  S rb   )r8   r4   is_positiver  r   s    r7   r  zPolyElement.is_positivej  r  r9   c                J    | j         j                            | j                  S rb   )r8   r4   is_nonnegativer  r   s    r7   r  zPolyElement.is_nonnegativen      y..tw777r9   c                J    | j         j                            | j                  S rb   )r8   r4   is_nonpositiver  r   s    r7   r  zPolyElement.is_nonpositiver  r  r9   c                    |  S rb   r>   r|   s    r7   is_zerozPolyElement.is_zerov  s	    ur9   c                "    | | j         j        k    S rb   )r8   r   r  s    r7   is_onezPolyElement.is_onez  s    AFJr9   c                J    | j         j                            | j                  S rb   )r8   r4   r  r  r  s    r7   is_moniczPolyElement.is_monic~  s    v}##AD)))r9   c                d    | j         j                            |                                           S rb   )r8   r4   r  contentr  s    r7   is_primitivezPolyElement.is_primitive  s"    v}##AIIKK000r9   c                X    t          d |                                 D                       S )Nc              3  <   K   | ]}t          |          d k    V  dS r   NrS   r@   r   s     r7   rg   z(PolyElement.is_linear.<locals>.<genexpr>  ,      ??u3u::???????r9   rj   
itermonomsr  s    r7   	is_linearzPolyElement.is_linear  '    ????????r9   c                X    t          d |                                 D                       S )Nc              3  <   K   | ]}t          |          d k    V  dS )   Nr  r  s     r7   rg   z+PolyElement.is_quadratic.<locals>.<genexpr>  r  r9   r  r  s    r7   is_quadraticzPolyElement.is_quadratic  r  r9   c                R    | j         j        sdS | j                             |           S NT)r8   r   	dmp_sqf_pr  s    r7   is_squarefreezPolyElement.is_squarefree  s)    v| 	4v"""r9   c                R    | j         j        sdS | j                             |           S r  )r8   r   dmp_irreducible_pr  s    r7   is_irreduciblezPolyElement.is_irreducible  s)    v| 	4v''***r9   c                l    | j         j        r| j                             |           S t          d          )Nzcyclotomic polynomial)r8   r  dup_cyclotomic_pr#   r  s    r7   is_cyclotomiczPolyElement.is_cyclotomic  s5    6 	G6**1----.EFFFr9   c                d    |                      d |                                 D                       S )Nc                    g | ]
\  }}|| fS r>   r>   )r@   r   r   s      r7   rB   z'PolyElement.__neg__.<locals>.<listcomp>  s"    PPPleU55&/PPPr9   )r/  r3  r   s    r7   __neg__zPolyElement.__neg__  s-    xxPPdnn>N>NPPPQQQr9   c                    | S rb   r>   r   s    r7   __pos__zPolyElement.__pos__  s    r9   c                `   |s|                                  S | j        }t          ||j                  r]|                                  }|j        }|j        j        }|                                D ]\  }} |||          |z   }|r|||<   ||=  |S t          |t                    rt          |j        t                    r|j        j        |j        k    rnPt          |j        j        t                    r*|j        j        j        |k    r|
                    |           S t          S 	 |                    |          }|                                  }|s|S |j        }	|	|                                 vr|||	<   n!|||	          k    r||	= n||	xx         |z  cc<   |S # t          $ r
 t          cY S w xY w)a  Add two polynomials.

        Examples
        ========

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

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

        )r   r8   rc   r   r   r4   r   rQ   rp   r   __radd__r\  r   r   rU  r    )
rQ  rR  r8   r  r   r   rC  rD  cp2r  s
             r7   __add__zPolyElement.__add__  s     	7799wb$*%% 	&		A%C;#D

  1C4LL1$ AaDD!HK(( 	&$+~66 &4;;Krw;V;VBGNN;; &@SW[@[@[{{2&%%	//"%%C 		A B"""!B%<<"bEEESLEEEH  	" 	" 	"!!!!	"s   &F F-,F-c                &   |                                  }|s|S | j        }	 |                    |          }|j        }||                                 vr|||<   n!|||          k    r||= n||xx         |z  cc<   |S # t
          $ r
 t          cY S w xY wrb   )r   r8   r   r   rU  r    r\  )rQ  r%  r  r8   r  s        r7   r  zPolyElement.__radd__  s    GGII 	Hw	""A B"""2;;"bEEEQJEEEH  	" 	" 	"!!!!	"s   A< <BBc                X   |s|                                  S | j        }t          ||j                  r]|                                  }|j        }|j        j        }|                                D ]\  }} |||          |z
  }|r|||<   ||=  |S t          |t                    rt          |j        t                    r|j        j        |j        k    rnPt          |j        j        t                    r*|j        j        j        |k    r|
                    |           S t          S 	 |                    |          }|                                  }|j        }||                                 vr| ||<   n |||         k    r||= n||xx         |z  cc<   |S # t          $ r
 t          cY S w xY w)a.  Subtract polynomial p2 from p1.

        Examples
        ========

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

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

        )r   r8   rc   r   r   r4   r   rQ   rp   r   __rsub__r\  r   r   rU  r    )	rQ  rR  r8   r  r   r   rC  rD  r  s	            r7   __sub__zPolyElement.__sub__  s      	7799wb$*%% 	&		A%C;#D

  1C4LL1$ AaDD!HK(( 	&$+~66 &4;;Krw;V;VBGNN;; &@SW[@[@[{{2&%%	$$B 		AB"""2;;"bEEERKEEEH  	" 	" 	"!!!!	"s   &F F)(F)c                    | j         }	 |                    |          }|j        }| D ]}| |          ||<   ||z  }|S # t          $ r
 t          cY S w xY w)a#  n - p1 with n convertible to the coefficient domain.

        Examples
        ========

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

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

        )r8   r   r   r    r\  )rQ  r%  r8   r  r   s        r7   r  zPolyElement.__rsub__'  s     w		""A 	A $ $d8)$FAH  	" 	" 	"!!!!	"s   = AAc                P   | j         }|j        }| r|s|S t          ||j                  r|j        }|j        j        }|j        }t          |                                          }|                                 D ].\  }}	|D ]&\  }
} |||
          } |||          |	|z  z   ||<   '/|	                                 |S t          |t                    rt          |j        t                    r|j        j         |j         k    rnPt          |j         j        t                    r*|j         j        j         |k    r|                    |           S t          S 	 |                    |          }|                                 D ]\  }}	|	|z  }|r|||<   |S # t          $ r
 t          cY S w xY w)a!  Multiply two polynomials.

        Examples
        ========

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

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

        )r8   r   rc   r   r   r4   r   rG   rQ   rN  rp   r   __rmul__r\  r   r    )rQ  rR  r8   r  r   r   r   p2itexp1v1exp2v2r   rD  s                 r7   __mul__zPolyElement.__mul__B  s     wI 	& 	&HDJ'' 	&%C;#D,L

##DHHJJ 4 4b $ 4 4HD"&,tT22C Sd^^be3AcFF4 LLNNNHK(( 	&$+~66 &4;;Krw;V;VBGNN;; &@SW[@[@[{{2&%%		$$B HHJJ    brE  AdGH  	" 	" 	"!!!!	"s   F F%$F%c                    | j         j        }|s|S 	 |j                             |          }|                                 D ]\  }}||z  }|r|||<   |S # t          $ r
 t
          cY S w xY w)a  p2 * p1 with p2 in the coefficient domain of p1.

        Examples
        ========

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

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

        )r8   r   r   rQ   r    r\  )rQ  rR  r  r  r  rD  s         r7   r  zPolyElement.__rmul__t  s     GL 	H		""2&&B HHJJ    brE  AdGH  	" 	" 	"!!!!	"s   A A('A(c                   | j         }|s| r|j        S t          d          t          |           dk    ryt	          |                                           d         \  }}|j        }||j        j        k    r|||                    ||          <   n||z  ||                    ||          <   |S t          |          }|dk     rt          d          |dk    r| 
                                S |dk    r|                                 S |dk    r| |                                 z  S t          |           dk    r|                     |          S |                     |          S )a(  raise polynomial to power `n`

        Examples
        ========

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

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

        z0**0r   r   zNegative exponentr        )r8   r   r   r~   rG   rQ   r   r4   r   r   r   square_pow_multinomial_pow_generic)r   r%  r8   r   r   r  s         r7   __pow__zPolyElement.__pow__  sY    y 	 )x (((YY!^^

--a0LE5	A''16$##E1--..16$##E1--.H FFq550111!VV99;;!VV;;== !VV%%YY!^^((+++$$Q'''r9   c                |    | j         j        }| }	 |dz  r||z  }|dz  }|sn|                                }|dz  },|S )NTr   r  )r8   r   r  )r   r%  r  rN   s       r7   r  zPolyElement._pow_generic  s`    IM	1u aCQ 

AQA	 r9   c                   t          t          |           |                                          }| j        j        }| j        j        }|                                 }| j        j        j        }| j        j        }|D ]r\  }}	|}
|	}t          ||          D ]\  }\  }}|r ||
||          }
|||z  z  } t          |
          }|}|
                    ||          |z   }|r|||<   k||v r||= s|S rb   )r   r~   rQ   r8   r   r   r4   r   rU   r}   r   )r   r%  multinomialsr   r   r9  r   r   multinomialmultinomial_coeffproduct_monomproduct_coeffr   r   r   s                  r7   r  zPolyElement._pow_multinomial  s   /D		1==CCEE)3Y)


y$y~.: 	  	 *K*&M-M'*;'>'> 0 0#^eU 0$3OM5#$N$NM!UCZ/M-((E!EHHUD))E1E  #U$Kr9   c                N   | j         }|j        }|j        }t          |                                           }|j        j        }|j        }t          t          |                    D ]S}||         }| |         }	t          |          D ]1}
||
         } |||          } |||          |	| |         z  z   ||<   2T|	                    d          }|j        }| 
                                D ]&\  }} |||          } |||          |dz  z   ||<   '|                                 |S )a  square of a polynomial

        Examples
        ========

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

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

        r  )r8   r   r   rG   rU  r4   r   r   r~   imul_numrQ   rN  )r   r8   r  r   rU  r   r   r   k1pkjk2r   rC  rD  s                  r7   r  zPolyElement.square  s9    yIeDIIKK  {(s4yy!! 	6 	6AaBbB1XX 6 6!W"l2r**S$"T"X+5#6 JJqMMeJJLL 	) 	)DAqa##BCDMMAqD(AbEE	r9   c                ^   | j         }|st          d          t          ||j                  r|                     |          S t          |t
                    rt          |j        t                    r|j        j         |j         k    rnPt          |j         j        t                    r*|j         j        j         |k    r|                    |           S t          S 	 |
                    |          }|                     |          |                     |          fS # t          $ r
 t          cY S w xY wNpolynomial division)r8   ZeroDivisionErrorrc   r   r   rp   r4   r   __rdivmod__r\  r   
quo_ground
rem_groundr    rQ  rR  r8   s      r7   
__divmod__zPolyElement.__divmod__  s"   w 
	&#$9:::DJ'' 	&66"::K(( 	&$+~66 &4;;Krw;V;VBGNN;; &@SW[@[@[~~b)))%%	:$$B MM"%%r}}R'8'899  	" 	" 	"!!!!	"s   D D,+D,c                    t           S rb   r\  rP  s     r7   r  zPolyElement.__rdivmod__(      r9   c                4   | j         }|st          d          t          ||j                  r|                     |          S t          |t
                    rt          |j        t                    r|j        j         |j         k    rnPt          |j         j        t                    r*|j         j        j         |k    r|                    |           S t          S 	 |
                    |          }|                     |          S # t          $ r
 t          cY S w xY wr  )r8   r  rc   r   remrp   r4   r   __rmod__r\  r   r  r    r  s      r7   __mod__zPolyElement.__mod__+  s   w 
	&#$9:::DJ'' 	&66"::K(( 	&$+~66 &4;;Krw;V;VBGNN;; &@SW[@[@[{{2&%%	%$$B ==$$$  	" 	" 	"!!!!	"s   D DDc                    t           S rb   r  rP  s     r7   r  zPolyElement.__rmod__A  r  r9   c                R   | j         }|st          d          t          ||j                  r$|j        r| |dz  z  S |                     |          S t          |t                    rt          |j        t                    r|j        j         |j         k    rnPt          |j         j        t                    r*|j         j        j         |k    r|	                    |           S t          S 	 |                    |          }|                     |          S # t          $ r
 t          cY S w xY w)Nr  r   )r8   r  rc   r   r  quorp   r4   r   __rtruediv__r\  r   r  r    r  s      r7   __truediv__zPolyElement.__truediv__D  s)   w 	&#$9:::DJ'' 	&~ "28}$vvbzz!K(( 	&$+~66 &4;;Krw;V;VBGNN;; &@SW[@[@[r***%%	%$$B ==$$$  	" 	" 	"!!!!	"s   (D D&%D&c                    t           S rb   r  rP  s     r7   r  zPolyElement.__rtruediv__]  r  r9   c                    | j         j        | j         j        }|j        | j         j        |j        rfd}nfd}|S )Nc                f    | \  }}|\  }}|	k    r|}n ||          }|| ||          fS d S rb   r>   
	a_lm_a_lc	b_lm_b_lca_lma_lcb_lmb_lcr   
domain_quor   r  s
          r7   term_divz'PolyElement._term_div.<locals>.term_divl  sX    &
d&
d2:: EE(Lt44E$ **T4"8"8884r9   c                p    | \  }}|\  }}|	k    r|}n ||          }|||z  s| ||          fS d S rb   r>   r	  s
          r7   r  z'PolyElement._term_div.<locals>.term_divx  s_    &
d&
d2:: EE(Lt44E **T4"8"8884r9   )r8   r   r4   r  r   rF  )r   r4   r  r  r   r  s      @@@r7   	_term_divzPolyElement._term_dive  s    Y!!Z
y-? 	 
  
  
  
  
  
  
  
 
  
  
  
  
  
  
  r9   c                   | j         d}t          |t                    rd}|g}t          |          st	          d          | s|rj        j        fS g j        fS |D ]}|j         k    rt          d          t          |          }fdt          |          D             }| 	                                }j        }| 
                                }d |D             }	|rd}
d}|
|k     r|dk    r|                                } ||||         f|	|
         ||
         |	|
                  f          }|G|\  }}||
                             ||f          ||
<   |                    ||
         || f          }d	}n|
d	z  }
|
|k     r|dk    |s4|                                }|                    |||         f          }||= ||j        k    r||z  }|r|s	j        |fS |d         |fS ||fS )
aU  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 ringc                    g | ]	}j         
S r>   )r   r@   r   r8   s     r7   rB   z#PolyElement.div.<locals>.<listcomp>  s    ***Adi***r9   c                6    g | ]}|                                 S r>   )r   )r@   fxs     r7   rB   z#PolyElement.div.<locals>.<listcomp>  s"    000r""000r9   r   Nr   )r8   rc   rp   rj   r  r   r   r~   r   r   r  r   _iadd_monom_iadd_poly_monomr   )r   fv
ret_singler|   rf   qvr  rr  expvsr   divoccurredr   termexpv1rN   r8   s                   @r7   r   zPolyElement.div  sh   8 y
b+&& 	JB2ww 	;#$9::: 	% %y$)++49}$ 	G 	GAv~~ !EFFF GG****q***IIKKI>>##00R000 	AKa%%K1,,~~''xqw%(BqE%(O1LMM##HE1qE--uaj99BqE**2a551"+>>A"#KKFA a%%K1,,  ((MM44/22dG!  	" 4?""FA 	  y!|#!uaxq5Lr9   c                   | }t          |t                    r|g}t          |          st          d          |j        }|j        }|j        }|j        }|j        }|                                }|j	        }	|
                                }|j        }
|r|D ]} ||	|j	                  }|j|\  }}|                                D ].\  }} |||          } |
||          ||z  z
  }|s||= )|||<   /|                                }|
|||         f}	 nC|	\  }}||v r||xx         |z  cc<   n|||<   ||= |                                }|
|||         f}	||S r  )rc   rp   rj   r  r8   r4   r   r   r  LTr   r   r3  r   )r   Gr|   r8   r4   r   r   r  r  ltfr   gtqrM   rN   mgcgm1c1ltmltcs                        r7   r  zPolyElement.rem  s   a%% 	A1vv 	;#$9:::v{(I;;==dFFHHe 	& & &Xc14((>DAq"#++-- ' 'B)\"a00 ST]]QrT1! ' !"$&AbEE..**C!1S6kE " S!88cFFFcMFFFF AcFcFnn&&?qv+C5  	&8 r9   c                8    |                      |          d         S Nr   )r   )r|   r%  s     r7   r  zPolyElement.quo  s    uuQxx{r9   c                Z    |                      |          \  }}|s|S t          | |          rb   )r   r"   )r|   r%  qr  s       r7   exquozPolyElement.exquo  s2    uuQxx1 	,H%a+++r9   c                    | | j         j        v r|                                 }n| }|\  }}|                    |          }||||<   n||z  }|r|||<   n||= |S )a  add to self the monomial coeff*x0**i0*x1**i1*...
        unless self is a generator -- then just return the sum of the two.

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

        Examples
        ========

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

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

        )r8   r   r   r   )r   mccpselfr   r   rN   s         r7   r  zPolyElement._iadd_monom
  sz    8 49&&&YY[[FFFeJJt9 F4LLJA ! t4Lr9   c                &   | }||j         j        v r|                                }|\  }}|j        }|j         j        j        }|j         j        }|                                D ].\  }	}
 ||	|          } |||          |
|z  z   }|r|||<   +||= /|S )aE  add to self the product of (p)*(coeff*x0**i0*x1**i1*...)
        unless self is a generator -- then just return the sum of the two.

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

        Examples
        ========

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

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

        )r8   r   r   r   r4   r   r   rQ   )r   rR  r5  rQ  rM   rN   r   r   r   rC  rD  kar   s                r7   r  zPolyElement._iadd_poly_monom6  s    * """BAfw~"w+HHJJ 	 	DAqa##BCDMMAaC'E 2rFF	r9   c                    | j                             |          | st          S dk     rdS t          fd|                                 D                       S )z
        The leading degree in ``x`` or the main variable.

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

        r   c              3  (   K   | ]}|         V  d S rb   r>   r@   r   r   s     r7   rg   z%PolyElement.degree.<locals>.<genexpr>i  '      <<EuQx<<<<<<r9   )r8   r   r   r{   r  r|   xr   s     @r7   degreezPolyElement.degree[  \     FLLOO 	=KUU1<<<<Q\\^^<<<<<<r9   c                    | st           f| j        j        z  S t          t	          t
          t          t          |                                                                S )z
        A tuple containing leading degrees in all variables.

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

        )	r   r8   r   r}   rR   r{   rG   rU   r  r  s    r7   degreeszPolyElement.degreesk  J      	?716<''S$sALLNN';"<"<==>>>r9   c                    | j                             |          | st          S dk     rdS t          fd|                                 D                       S )z
        The tail degree in ``x`` or the main variable.

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

        r   c              3  (   K   | ]}|         V  d S rb   r>   r;  s     r7   rg   z*PolyElement.tail_degree.<locals>.<genexpr>  r<  r9   )r8   r   r   minr  r=  s     @r7   tail_degreezPolyElement.tail_degreew  r@  r9   c                    | st           f| j        j        z  S t          t	          t
          t          t          |                                                                S )z
        A tuple containing tail degrees in all variables.

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

        )	r   r8   r   r}   rR   rF  rG   rU   r  r  s    r7   tail_degreeszPolyElement.tail_degrees  rC  r9   c                >    | r| j                             |           S dS )aT  Leading monomial tuple according to the monomial ordering.

        Examples
        ========

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

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

        N)r8   r   r   s    r7   r   zPolyElement.leading_expv  s'      	9))$///4r9   c                L    |                      || j        j        j                  S rb   )r   r8   r4   r   r   r   s     r7   
_get_coeffzPolyElement._get_coeff  s    xxdi.3444r9   c                v   |dk    r|                      | j        j                  S t          || j        j                  rit          |                                          }t          |          dk    r5|d         \  }}|| j        j        j	        k    r|                      |          S t          d|z            )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)rM  r8   r   rc   r   rG   r3  r~   r4   r   r   )r   r   r9  r   r   s        r7   r   zPolyElement.coeff  s    4 a<<??49#788811 	2**,,--E5zzQ$QxuDI,000??51116@AAAr9   c                @    |                      | j        j                  S )z"Returns the constant coefficient. )rM  r8   r   r   s    r7   rW  zPolyElement.const  s    ty3444r9   c                P    |                      |                                           S rb   )rM  r   r   s    r7   r  zPolyElement.LC  s     t0022333r9   c                J    |                                  }|| j        j        S |S rb   )r   r8   r   rL  s     r7   LMzPolyElement.LM  s(      ""<9''Kr9   c                r    | j         j        }|                                 }|r| j         j        j        ||<   |S )a  
        Leading monomial as a polynomial element.

        Examples
        ========

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

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

        )r8   r   r   r4   r   r   r  r   s      r7   leading_monomzPolyElement.leading_monom  s<     IN  "" 	+i&*AdGr9   c                    |                                  }|| j        j        | j        j        j        fS ||                     |          fS rb   )r   r8   r   r4   r   rM  rL  s     r7   r$  zPolyElement.LT  sG      ""<I($)*:*?@@$//$//00r9   c                `    | j         j        }|                                 }|| |         ||<   |S )a  Leading term as a polynomial element.

        Examples
        ========

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

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

        )r8   r   r   rT  s      r7   leading_termzPolyElement.leading_term  s6     IN  ""4jAdGr9   c                    | j         j        nt          j                  t          u rt          |d d          S t          |fdd          S )Nc                    | d         S r0  r>   )r   s    r7   rv   z%PolyElement._sorted.<locals>.<lambda>  s
    q r9   T)rz   reversec                &     | d                   S r0  r>   )r   r5   s    r7   rv   z%PolyElement._sorted.<locals>.<lambda>  s    uQx r9   )r8   r5   r   r   r   sorted)r   r`   r5   s     `r7   _sortedzPolyElement._sorted  sd    =IOEE'..EC<<##9#94HHHH##@#@#@#@$OOOOr9   c                @    d |                      |          D             S )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]

        c                    g | ]\  }}|S r>   r>   )r@   _r   s      r7   rB   z&PolyElement.coeffs.<locals>.<listcomp>3  s    :::81e:::r9   r9  r   r5   s     r7   r[   zPolyElement.coeffs  $    0 ;:tzz%'8'8::::r9   c                @    d |                      |          D             S )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)]

        c                    g | ]\  }}|S r>   r>   )r@   r   ra  s      r7   rB   z&PolyElement.monoms.<locals>.<listcomp>M  s    :::85!:::r9   rb  rc  s     r7   monomszPolyElement.monoms5  rd  r9   c                l    |                      t          |                                           |          S )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^  rG   rQ   rc  s     r7   r9  zPolyElement.termsO  s(    0 ||D..666r9   c                D    t          |                                           S )z,Iterator over coefficients of a polynomial. )iterrH   r   s    r7   
itercoeffszPolyElement.itercoeffsi      DKKMM"""r9   c                D    t          |                                           S )z)Iterator over monomials of a polynomial. )rj  rU  r   s    r7   r  zPolyElement.itermonomsm      DIIKK   r9   c                D    t          |                                           S )z%Iterator over terms of a polynomial. )rj  rQ   r   s    r7   r3  zPolyElement.itertermsq      DJJLL!!!r9   c                D    t          |                                           S )z+Unordered list of polynomial coefficients. rF   r   s    r7   
listcoeffszPolyElement.listcoeffsu  rl  r9   c                D    t          |                                           S )z(Unordered list of polynomial monomials. )rG   rU  r   s    r7   
listmonomszPolyElement.listmonomsy  rn  r9   c                D    t          |                                           S )z$Unordered list of polynomial terms. rM  r   s    r7   	listtermszPolyElement.listterms}  rp  r9   c                    | | j         j        v r| |z  S |s|                                  dS | D ]}| |xx         |z  cc<   | S )a:  multiply inplace the polynomial p by an element in the
        coefficient ring, provided p is not one of the generators;
        else multiply not inplace

        Examples
        ========

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

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

        N)r8   r   clear)r  rN   r   s      r7   r  zPolyElement.imul_num  sb    4    Q3J 	GGIIIF 	 	CcFFFaKFFFFr9   c                    | j         j        }|j        }|j        }|                                 D ]} |||          }|S )z*Returns GCD of polynomial's coefficients. )r8   r4   r   r   rk  )r|   r4   contr   r   s        r7   r  zPolyElement.content  sH    {j\\^^ 	$ 	$E3tU##DDr9   c                X    |                                  }||                     |          fS )z,Returns content and a primitive polynomial. )r  r  )r|   rz  s     r7   	primitivezPolyElement.primitive  s&    yy{{Q\\$''''r9   c                >    | s| S |                      | j                  S )z5Divides all coefficients by the leading coefficient. )r  r  r  s    r7   moniczPolyElement.monic  s#     	&H<<%%%r9   c                    s| j         j        S fd|                                 D             }|                     |          S )Nc                $    g | ]\  }}||z  fS r>   r>   r@   r   r   r>  s      r7   rB   z*PolyElement.mul_ground.<locals>.<listcomp>  s&    FFF|ue5%'"FFFr9   )r8   r   r3  r/  )r|   r>  r9  s    ` r7   rq  zPolyElement.mul_ground  sF     	6;FFFFq{{}}FFFuuU||r9   c                    | j         j        fd|                                 D             }|                     |          S )Nc                2    g | ]\  }} |          |fS r>   r>   )r@   f_monomf_coeffr   r   s      r7   rB   z)PolyElement.mul_monom.<locals>.<listcomp>  s/    ]]]>Ngw<<//9]]]r9   )r8   r   rQ   r/  )r|   r   r9  r   s    ` @r7   	mul_monomzPolyElement.mul_monom  sG    v*]]]]]RSRYRYR[R[]]]uuU||r9   c                   |\  | rs| j         j        S | j         j        k    r|                               S | j         j        fd|                                 D             }|                     |          S )Nc                8    g | ]\  }} |          |z  fS r>   r>   )r@   r  r  r   r   r   s      r7   rB   z(PolyElement.mul_term.<locals>.<listcomp>  s3    cccDTGW<<//?cccr9   )r8   r   r   rq  r   rQ   r/  )r|   r!  r9  r   r   r   s      @@@r7   mul_termzPolyElement.mul_term  s    u 	' 	'6;af'''<<&&&v*ccccccXYX_X_XaXacccuuU||r9   c                (   | j         j        }st          d          | r|j        k    r| S |j        r)|j        fd|                                 D             }n fd|                                 D             }|                     |          S )Nr  c                2    g | ]\  }}| |          fS r>   r>   )r@   r   r   r  r>  s      r7   rB   z*PolyElement.quo_ground.<locals>.<listcomp>  s,    PPPucc%mm,PPPr9   c                .    g | ]\  }}|z  
||z  fS r>   r>   r  s      r7   rB   z*PolyElement.quo_ground.<locals>.<listcomp>  s2    ```leUTY\]T]`ueqj)```r9   )r8   r4   r  r   rF  r  r3  r/  )r|   r>  r4   r9  r  s    `  @r7   r  zPolyElement.quo_ground  s     	;#$9::: 	AOOH? 	a*CPPPPPPPPEE````akkmm```EuuU||r9   c                @   \  }}|st          d          | s| j        j        S || j        j        k    r|                     |          S |                                 fd|                                 D             }|                     d |D                       S )Nr  c                (    g | ]} |          S r>   r>   )r@   tr!  r  s     r7   rB   z(PolyElement.quo_term.<locals>.<listcomp>  s%    <<<((1d##<<<r9   c                    g | ]}||S rb   r>   )r@   r  s     r7   rB   z(PolyElement.quo_term.<locals>.<listcomp>  s    :::Q1=q===r9   )r  r8   r   r   r  r  r3  r/  )r|   r!  r   r   r9  r  s    `   @r7   quo_termzPolyElement.quo_term  s    u 	'#$9::: 	'6;af'''<<&&&;;==<<<<<Q[[]]<<<uu::%:::;;;r9   c                J   | j         j        j        rGg }|                                 D ]/\  }}|z  }|dz  k    r|z
  }|                    ||f           0n fd|                                 D             }|                     |          }|                                 |S )Nr  c                $    g | ]\  }}||z  fS r>   r>   )r@   r   r   r  s      r7   rB   z,PolyElement.trunc_ground.<locals>.<listcomp>  s&    LLL\UEueai(LLLr9   )r8   r4   is_ZZr3  r   r/  rN  )r|   r  r9  r   r   r   s    `    r7   trunc_groundzPolyElement.trunc_ground  s    6= 	ME ! - -u	16>>!AIEeU^,,,,- MLLLQ[[]]LLLEuuU||r9   c                    | }|                                 }|                                 }|j        j                            ||          }|                    |          }|                    |          }|||fS rb   )r  r8   r4   r   r  )r   r'  r|   fcgcr   s         r7   extract_groundzPolyElement.extract_ground  sh    YY[[YY[[fmB''LLLLAqyr9   c                    | s| j         j        j        S | j         j        j         |fd|                                 D                       S )Nc                &    g | ]} |          S r>   r>   )r@   r   
ground_abss     r7   rB   z%PolyElement._norm.<locals>.<listcomp>  s#    NNNUzz%00NNNr9   )r8   r4   r   absrk  )r|   	norm_funcr  s     @r7   _normzPolyElement._norm  sR     	P6=%%*J9NNNNallnnNNNOOOr9   c                6    |                      t                    S rb   )r  r{   r  s    r7   max_normzPolyElement.max_norm      wws||r9   c                6    |                      t                    S rb   )r  rS   r  s    r7   l1_normzPolyElement.l1_norm  r  r9   c                J   | j         }| gt          |          z   }dg|j        z  }|D ]G}|                                D ]0}t	          |          D ]\  }}t          ||         |          ||<   1Ht	          |          D ]\  }}	|	sd||<   t          |          }t          d |D                       r||fS g }
|D ]d}|j        }|	                                D ]1\  }}d t          ||          D             }||t          |          <   2|
                    |           e||
fS )Nr   r   c              3  "   K   | ]
}|d k    V  dS r  r>   )r@   ru   s     r7   rg   z&PolyElement.deflate.<locals>.<genexpr>0  s&      !!!qAv!!!!!!r9   c                    g | ]
\  }}||z  S r>   r>   r@   r   r  s      r7   rB   z'PolyElement.deflate.<locals>.<listcomp>9  s     444Aa1f444r9   )r8   rG   r   r  r   r   r}   rj   r   r3  rU   r   )r|   r%  r8   r]   Jr  r   r   rM   ru   HhIr   Ns                  r7   deflatezPolyElement.deflate  se   vd1ggC
N 	) 	)A ) )%e,, ) )DAq!a==AaDD)) aLL 	 	DAq !!HH!!q!!!!! 	e8O 	 	A	AKKMM $ $544Q444#%((HHQKKKK!tr9   c                    | j         j        }|                                 D ]1\  }}d t          ||          D             }||t	          |          <   2|S )Nc                    g | ]
\  }}||z  S r>   r>   r  s      r7   rB   z'PolyElement.inflate.<locals>.<listcomp>D  s     ---$!Q!A#---r9   )r8   r   r3  rU   r}   )r|   r  r   r  r   r  s         r7   inflatezPolyElement.inflate@  sW    v{ 	# 	#HAu--#a))---A"DqNNr9   c                j   | }|j         j        }|j        sD|                                \  }}|                                \  }}|                    ||          }||z                      |                    |                    }|j        s|                    |          S |                                S rb   )	r8   r4   rF  r|  r   r  r   rq  r~  )r   r'  r|   r4   r  r  rN   r  s           r7   r   zPolyElement.lcmI  s     	#KKMMEBKKMMEB

2r""AqSIIaeeAhh 	<<??"7799r9   c                8    |                      |          d         S r0  )	cofactorsr|   r'  s     r7   r   zPolyElement.gcdY  s    {{1~~a  r9   c                T   | s|s| j         j        }|||fS | s|                     |          \  }}}|||fS |s|                    |           \  }}}|||fS t          |           dk    r|                     |          \  }}}|||fS t          |          dk    r|                    |           \  }}}|||fS |                     |          \  }\  } }|                     |          \  }}}|                    |          |                    |          |                    |          fS r   )r8   r   	_gcd_zeror~   
_gcd_monomr  _gcdr  )r|   r'  r   r  cffcfgr  s          r7   r  zPolyElement.cofactors\  s0    	 	6;Dt## 	++a..KAsCc3; 	++a..KAsCc3;VVq[[,,q//KAsCc3;VVq[[,,q//KAsCc3;IIaLL	6AqffQii3		!ckk!nnckk!nn==r9   c                X    | j         j        | j         j        }}|j        r|||fS | || fS rb   )r8   r   r   r  )r|   r'  r   r   s       r7   r  zPolyElement._gcd_zeror  s:    FJT 	"dC<2tcT>!r9   c                $   | j         }|j        j        }|j        j        |j        }|j        t          |                                           d         \  }}||c|                                D ]\  }} ||           ||          |                     fg          }	|                      |           |          fg          }
|                     fd|                                D                       }|	|
|fS )Nr   c                F    g | ]\  }} |           |          fS r>   r>   )r@   r)  r*  _cgcd_mgcd
ground_quor   s      r7   rB   z*PolyElement._gcd_monom.<locals>.<listcomp>  s:    ccc62rmmB..

2u0E0EFcccr9   )	r8   r4   r   r  r   r   rG   r3  r/  )r|   r'  r8   
ground_gcdr   mfcfr)  r*  r  r  r  r  r  r  r   s               @@@@r7   r  zPolyElement._gcd_monomy  s(   v[_
[_
(*akkmm$$Q'B2ukkmm 	* 	*FB L++EJub))EEEEE5>"##eemmB..

2u0E0EFGHHeecccccccUVU`U`UbUbcccdd#s{r9   c                    | j         }|j        j        r|                     |          S |j        j        r|                     |          S |                    | |          S rb   )r8   r4   is_QQ_gcd_QQr  _gcd_ZZdmp_inner_gcd)r|   r'  r8   s      r7   r  zPolyElement._gcd  sY    v; 	,99Q<<[ 	,99Q<<%%a+++r9   c                "    t          | |          S rb   r   r  s     r7   r  zPolyElement._gcd_ZZ  s    a||r9   c                   | }|j         }|                    |j                                                  }|                                \  }}|                                \  }}|                    |          }|                    |          }|                    |          \  }}}	|                    |          }|j        |                                }}
|                    |          	                    |j        
                    |
|                    }|	                    |          	                    |j        
                    |
|                    }	|||	fS )Nr  )r8   r   r4   rH  rK  r:  r  r  r~  rq  r  )r   r'  r|   r8   r8  r  r*  r  r  r  rN   s              r7   r  zPolyElement._gcd_QQ  s   v::T[%9%9%;%;:<<  A  AJJx  JJx  iill3JJttQWWYY1ll4  ++DKOOAr,B,BCCll4  ++DKOOAr,B,BCC#s{r9   c                l   | }|j         }|s	||j        fS |j        }|j        r|j        s|                    |          \  }}}n|                    |                                          }|                                \  }	}|                                \  }
}|	                    |          }|	                    |          }|                    |          \  }}}|j                            |
|	          \  }}
}	|	                    |          }|	                    |          }|
                    |
          }|
                    |	          }|                                }||j        k    r||}}n=||j         k    r| | }}n*|
                    |          }|
                    |          }||fS )a  
        Cancel common factors in a rational function ``f/g``.

        Examples
        ========

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

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

        r  )r8   r   r4   rF  rG  r  r   rH  rK  r:  rq  canonical_unit)r   r'  r|   r8   r4   ra  r  r2  r8  cqcpus               r7   cancelzPolyElement.cancel  s    v 	dh; 	!F$9 	!kk!nnGAq!!zz):):z;;HNN$$EBNN$$EB

8$$A

8$$Akk!nnGAq! 11"b99IAr2

4  A

4  AR  AR  A
 
??aqAA6:+2rqAAQAQA!tr9   c                N    | j         j        }|                    | j                  S rb   )r8   r4   r  r  )r|   r4   s     r7   r  zPolyElement.canonical_unit  s!    $$QT***r9   c                (   | j         }|                    |          }|                    |          }|j        }|                                 D ]D\  }}||         r7|                    ||          }|                    |||         z            ||<   E|S )a!  Computes partial derivative in ``x``.

        Examples
        ========

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

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

        )r8   r   r   r   r3  r   r   )	r|   r>  r8   r   rM   r'  r   r   es	            r7   diffzPolyElement.diff  s     vJJqMM""I;;== 	6 	6KD%Aw 6&&tQ//uT!W}55!r9   c                   dt          |          cxk     r| j        j        k    r=n n:|                     t	          t          | j        j        |                              S t          d| j        j        dt          |                    )Nr   z expected at least 1 and at most z values, got )r~   r8   r   evaluaterG   rU   r2   r   )r|   rH   s     r7   r+  zPolyElement.__call__ 	  s    s6{{****afl*****::d3qv{F#;#;<<===*TUTZT`T`T`beflbmbmbmnooor9   c                   | }t          |t                    rU|S|d         |dd          c\  }}|                    |          }|s|S fd|D             }|                    |          S |j        }|                    |          }|j                            |          }|j        dk    r5|j        j        }|	                                D ]\  \  }}||||z  z  z  }|S |
                    |          j        }	|	                                D ]O\  }
}|
|         |
d |         |
|dz   d          z   }
}|||z  z  }|
|	v r||	|
         z   }|r||	|
<   D|	|
= H|r||	|
<   P|	S )Nr   r   c                D    g | ]\  }}|                               |fS r>   )r   )r@   Yrt   Xs      r7   rB   z(PolyElement.evaluate.<locals>.<listcomp>	  s+    666!Qqvvayy!n666r9   )rc   rG   r  r8   r   r4   r   r   r   r3  r   )r   r>  rt   r|   r8   r   resultr%  r   r   r   r  s              @r7   r  zPolyElement.evaluate	  s   a 	%19!aeIFQA

1a  A %66661666zz!}}$vJJqMMK"":??[%F {{}} % %e%1*$M99Q<<$D ! , ,u 8U2A2Yqstt%<5ad
D==!DK/E (&+U KK ,&+UKr9   c                f   | }t          |t                    r"| |D ]\  }}|                    ||          }|S |j        }|                    |          }|j                            |          }|j        dk    rH|j        j        }|	                                D ]\  \  }}	||	||z  z  z  }|
                    |          S |j        }
|	                                D ]R\  }}	||         |d |         dz   ||dz   d          z   }}|	||z  z  }	||
v r|	|
|         z   }	|	r|	|
|<   G|
|= K|	r|	|
|<   S|
S )Nr   rq   )rc   rG   subsr8   r   r4   r   r   r   r3  r   )r   r>  rt   r|   r  r8   r   r  r%  r   r   r   s               r7   r  zPolyElement.subs2	  so   a 	19 ! !1FF1aLLHvJJqMMK"":??[%F {{}} % %e%1*$??6***9D ! , ,u 8U2A2Y%5acdd%C5ad
D==!DK/E (&+U KK ,&+UKr9   c                   |                                  }|j        j        }|s
|j        g fS fdt	          |          D             i fd}t          t	          |dz
                      }t          t	          |dd                    }j        }|rd\  }}}	t          |                                          D ]V\  }
\  }t          fd|D                       r3t          d t          |          D                       }||k    r||}	}}W|dk    r||	c}nng }t          dd	         d
z             D ]\  }}|                    ||z
             |                    t          |          |          z  }|}t          |          D ]\  }
}| ||
|          z  }||z  }|t          t          j                            }|||fS )aX  
        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

        c                @    g | ]}                     |d z             S )r   )r&  r  s     r7   rB   z*PolyElement.symmetrize.<locals>.<listcomp>	  s+    <<<a$$QqS))<<<r9   c                D    | |fvr|          |z  | |f<   | |f         S rb   r>   )r   r%  poly_powersr]   s     r7   get_poly_powerz.PolyElement.symmetrize.<locals>.get_poly_power	  s7    1v[((&+AhkQF#1v&&r9   r   r   r   )r   NNc              3  B   K   | ]}|         |d z            k    V  dS r  r>   )r@   r   r   s     r7   rg   z)PolyElement.symmetrize.<locals>.<genexpr>	  s4      AAAuQx5Q</AAAAAAr9   c              3  &   K   | ]\  }}||z  V  d S rb   r>   )r@   r%  rM   s      r7   rg   z)PolyElement.symmetrize.<locals>.<genexpr>	  s*       E EA1 E E E E E Er9   Nrq   )r   r8   r   r   r   rG   r   r9  rj   r{   rU   r   r   r}   r2   )r   r|   r%  r  r   weights	symmetric_height_monom_coeffr   r   height	exponentsr+  m2productr   r   r  r]   r8   s                     @@@@r7   
symmetrizezPolyElement.symmetrizeY	  sM   v IIKKvJ 	$di##<<<<588<<<	' 	' 	' 	' 	' 	'
 uQU||$$uQ2''I	 	&4#GVV%.qwwyy%9%9 G G!>E5AAAAAAAAA G  E EWe1D1D E E EEEF''28%"}}%vuuIeU122Y%566 * *B  b))))uY'7'7???IG!),, 0 01>>!Q///LA1  	4 s49e,,--!W$$r9   c                   | j         }|j        }t          t          |j        t          |j                                      |||fg}npt          |t                    rt          |          }nKt          |t                    r't          |
                                fd          }nt          d          t          |          D ](\  }\  }}|         |                    |          f||<   )|                                 D ]d\  }}	t          |          }|j        }
|D ]\  }}||         dc}||<   |r|
||z  z  }
|
                    t#          |          |	f          }
||
z  }e|S )Nc                     | d                  S r0  r>   )rC  gens_maps    r7   rv   z%PolyElement.compose.<locals>.<lambda>	  s    x!~ r9   ry   z9expected a generator, value pair a sequence of such pairsr   )r8   r   rT   rU   r2   r   r   rc   rG   r]  rQ   r   r   r   r3  r   r  r}   )r|   r>  rt   r8   r   replacementsrC  r'  r   r   subpolyr   r%  r  s                @r7   r   zPolyElement.compose	  s   vyDIuTZ'8'899::=F8LL!T"" ^#AwwAt$$ ^%aggii5M5M5M5MNNN !\]]]"<00 	> 	>IAv1'{DMM!,<,<=LOOKKMM 
	 
	LE5KKEhG$ $ $1#Ah58 $q!tOG&&ee'<==GGODDr9   c                :   | }|j                             |          fd|                                D             }|s|j         j        S t	          | \  }}fd|D             }|j                             t          t	          ||                              S )aU  
        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

        c                6    g | ]\  }}|         k    ||fS r>   r>   )r@   rM   rN   degr   s      r7   rB   z)PolyElement.coeff_wrt.<locals>.<listcomp>
  s*    AAADAqQqTS[[!Q[[[r9   c                F    g | ]}|d          dz   |dz   d          z   S )Nrq   r   r>   )r@   rM   r   s     r7   rB   z)PolyElement.coeff_wrt.<locals>.<listcomp>
  s6    ;;;q!BQB%$,1q566*;;;r9   )r8   r   r3  r   rU   rV   rT   )r   r>  r  r  r9  rg  r[   r   s     `    @r7   	coeff_wrtzPolyElement.coeff_wrt	  s    T FLLOOAAAAAAKKMMAAA 	6;e;;;;F;;;vS%8%8 9 9:::r9   c                   | }|j                             |          }|                    |          }|                    |          }|dk     rt          d          ||}}||k     r|S ||z
  dz   }|                    ||          }	|j         j        |         }
	 |                    ||          }||z
  |dz
  }}||	z  }||z  |
|z  z  }||z
  }|                    |          }||k     rnR|	|z  }||z  S )a  
        Pseudo-remainder of the polynomial ``self`` with respect to ``g``.

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

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


        Parameters
        ==========

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

        Returns
        =======

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

        Raises
        ======

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

        Examples
        ========

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

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

        See Also
        ========

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

        r   r  r   r8   r   r?  r  r  r2   )r   r'  r>  r|   dfdgr  drr  lc_gxplc_rr  Rr%  rN   s                   r7   premzPolyElement.prem
  s   l FLLOOXXa[[XXa[[66#$9:::2277HGaK{{1b!!V[^	;;q"%%D7AEqADAD2q5 AAA!BBww	 AI1ur9   c                $   | }|j                             |          }|                    |          }|                    |          }|dk     rt          d          |||}}}||k     r||fS ||z
  dz   }	|                    ||          }
|j         j        |         }	 |                    ||          }||z
  |	dz
  }	}||
z  }||||z  z  z   }||
z  }||z  ||z  z  }||z
  }|                    |          }||k     rnb|
|	z  }||z  }||z  }||fS )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>  r|   r  r  r2  r  r  r  r  r   r  r  Qr  r%  rN   s                     r7   pdivzPolyElement.pdivv
  sK   ` FLLOOXXa[[XXa[[66#$9:::ab177a4KGaK{{1b!!V[^	;;q"%%D7AEqADAT2q5L ADAD2q5 AAA!BBww%	( !GEE!tr9   c                >    | }|                     ||          d         S )aW  
        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>  r|   s       r7   pquozPolyElement.pquo
  s    6 vva||Ar9   c                j    | }|                     ||          \  }}|j        r|S t          ||          )a  
        Polynomial exact pseudo-quotient in multivariate polynomial ring.

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

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

        See Also
        ========

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

        )r  r  r"   )r   r'  r>  r|   r2  r  s         r7   pexquozPolyElement.pexquo  s=    : vva||19 	,H%a+++r9   c                   | }|j                             |          }|                    |          }|                    |          }||k     r||}}||}}|dk    rddgS |dk    r|dgS ||g}||z
  }d|dz   z  }|                    ||          }	|	|z  }	|                    ||          }
|
|z  }d|g}| }|	r|	                    |          }|                    |	           ||	|||z
  f\  }}}}|
 ||z  z  }|                    ||          }	|	                    |          }	|                    ||          }
|dk    r$|
 |z  }||dz
  z  }|                    |          }n|
 }|                    |            |	|S )a  
        Computes the subresultant PRS of two polynomials ``self`` and ``g``.

        Parameters
        ==========

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

        Returns
        =======

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

        Examples
        ========

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

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

        r   r   r   )r8   r   r?  r  r  r   r3  )r   r'  r>  r|   r%  rM   r  dru   r  lcrN   SrC  r  r2  s                   r7   subresultantszPolyElement.subresultants7  s   D FLLOOHHQKKHHQKKq55aqAaqA66q6M66q6MFEQUO FF1aLLE [[A!GFB 	AHHQKKKAq!a%JAq!Qa1fAq!A

AQ""B1uuSQJ!a%LGGAJJCHHaRLLL'  	* r9   c                8    | j                             | |          S rb   )r8   dmp_half_gcdexr  s     r7   
half_gcdexzPolyElement.half_gcdex  s    v$$Q***r9   c                8    | j                             | |          S rb   )r8   	dmp_gcdexr  s     r7   gcdexzPolyElement.gcdex      v1%%%r9   c                8    | j                             | |          S rb   )r8   dmp_resultantr  s     r7   	resultantzPolyElement.resultant  s    v##Aq)))r9   c                6    | j                             |           S rb   )r8   dmp_discriminantr  s    r7   discriminantzPolyElement.discriminant  s    v&&q)))r9   c                l    | j         j        r| j                             |           S t          d          )Nzpolynomial decomposition)r8   r  dup_decomposer#   r  s    r7   	decomposezPolyElement.decompose  s5    6 	J6''***-.HIIIr9   c                n    | j         j        r| j                             | |          S t          d          )Nzshift: use shift_list instead)r8   r  	dup_shiftr#   r|   rt   s     r7   shiftzPolyElement.shift  s7    6 	O6##Aq)))-.MNNNr9   c                8    | j                             | |          S rb   )r8   	dmp_shiftr"  s     r7   
shift_listzPolyElement.shift_list  r  r9   c                l    | j         j        r| j                             |           S t          d          )Nzsturm sequence)r8   r  	dup_sturmr#   r  s    r7   sturmzPolyElement.sturm  s5    6 	@6##A&&&-.>???r9   c                6    | j                             |           S rb   )r8   dmp_gff_listr  s    r7   gff_listzPolyElement.gff_list      v""1%%%r9   c                6    | j                             |           S rb   )r8   dmp_normr  s    r7   normzPolyElement.norm  s    vq!!!r9   c                6    | j                             |           S rb   )r8   dmp_sqf_normr  s    r7   sqf_normzPolyElement.sqf_norm  r-  r9   c                6    | j                             |           S rb   )r8   dmp_sqf_partr  s    r7   sqf_partzPolyElement.sqf_part  r-  r9   Fc                :    | j                             | |          S )N)rj   )r8   dmp_sqf_list)r|   rj   s     r7   sqf_listzPolyElement.sqf_list  s    v""1#"...r9   c                6    | j                             |           S rb   )r8   dmp_factor_listr  s    r7   factor_listzPolyElement.factor_list  s    v%%a(((r9   rb   )F)r   r'  r(  r)  r/  r1  r   r   r   r   r:  r=  r<  rK  rN  r   r   rV  rZ  r^  r`  rc  re  rg  rj  r   ro  r  rt  rv  rd   r*  r  rl  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  __floordiv____rfloordiv__r  r   r  r  r3  r  r  r?  rB  rG  rI  r   rM  r   rW  r  rR  rU  r$  rX  r^  r[   rg  r9  rk  r  r3  rr  rt  rv  r  r  r|  r~  rq  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r  r  r  r  r  r  r  r  r  r+  r  r  r  r   r  r  r  r  r
  r  r  r  r  r  r  r#  r&  r)  r,  r0  r3  r6  r9  r<  r>   r9   r7   rp   rp   <  s(
       ??$ $ $% % %3 3 3 E	 	 	  8> > >	= 	= 	=M M M  "  4 4 44  G G G G0) ) )" " "        	2 	2 	2  *> > >  "H H H  . . .` + + X+ M M XM = = X=   X 5 5 X5 5 5 X5 8 8 X8 8 8 X8   X   X * * X* 1 1 X1 @ @ X@ @ @ X@ # # X#
 + + X+
 G G XGR R R  4 4 4l  (4 4 4l  60 0 0d  :.( .( .(`     :" " "H: : :,  % % %,  % % %2   L M  BJ J JX+ + +Z  , , ,* * *X# # #J= = = = 
? 
? 
?= = = = 
? 
? 
?  (5 5 5#B #B #BJ5 5 5 4 4 X4   X  * 1 1 X1  (	P 	P 	P; ; ; ;4; ; ; ;47 7 7 74# # #! ! !" " "# # #! ! !" " "! ! !F	 	 	( ( (
& & &    

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