o
    §ƒðj@P ã                   @  sö  d 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 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/m0Z0m1Z1 ddl2m3Z3m4Z4m5Z5m6Z6 ddl7m&Z8m9Z:m;Z; ddl<m=Z=m>Z>m?Z? ddl@mAZA ddlBmCZCmDZD ddlEmFZF ddlGmHZH eCe0fd-dd„ƒZIeCe0fd d!„ƒZJeCe0fd"d#„ƒZKeCd$d%„ ƒZLd&d'„ ZMG d(d)„ d)eAeƒZNG d*d+„ d+e(eAeeOƒZPd,S ).zSparse polynomial rings. é    )Úannotations)ÚaddÚmulÚltÚleÚgtÚge)Úreduce)ÚGeneratorType)Úcacheit)ÚExpr)Úigcd)ÚSymbolÚsymbols)ÚCantSympifyÚsympify)Úmultinomial_coefficients)ÚIPolys)Úconstruct_domain)ÚninfÚdmp_to_dictÚdmp_from_dict)ÚDomain)ÚDomainElement©ÚPolynomialRing©Úheugcd)ÚMonomialOps)ÚlexÚMonomialOrder)ÚCoercionFailedÚGeneratorsErrorÚExactQuotientFailedÚMultivariatePolynomialError)r   ÚOrderÚbuild_options)Úexpr_from_dictÚ_dict_reorderÚ_parallel_dict_from_expr)ÚDefaultPrinting)ÚpublicÚsubsets)Úis_sequence)ÚpolluteÚorderúMonomialOrder | strc                 C  s   t | ||ƒ}|f|j 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   Údomainr/   Ú_ring© r7   ú“/tmp/claude-1000/-var-www-html-academy/3f42efd1-c2b7-4d08-9b05-30d86bb35479/scratchpad/piper/venv/lib/python3.10/site-packages/sympy/polys/rings.pyÚring$   s   r9   c                 C  s   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'>

    r1   r4   r7   r7   r8   ÚxringC   s   
r:   c                 C  s(   t | ||ƒ}td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                 S  s   g | ]}|j ‘qS r7   )Úname)Ú.0Úsymr7   r7   r8   Ú
<listcomp>~   ó    zvring.<locals>.<listcomp>)r2   r.   r   r3   r4   r7   r7   r8   Úvringb   s   r@   c           
        sÈ   d}t | ƒs| gd} }ttt| ƒƒ} t||ƒ}t| |ƒ\}}|jdu rGtdd„ |D ƒg ƒ}t||d�\|_}t	t
||ƒƒ‰ ‡ fd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                 S  s   g | ]}t | ¡ ƒ‘qS r7   ©ÚlistÚvalues©r<   Úrepr7   r7   r8   r>   §   ó    zsring.<locals>.<listcomp>)Úoptc                   s"   g | ]}‡ fd d„|  ¡ D ƒ‘qS )c                   s   i | ]	\}}|ˆ | “qS r7   r7   ©r<   ÚmÚc©Ú	coeff_mapr7   r8   Ú
<dictcomp>¬   ó    z$sring.<locals>.<listcomp>.<dictcomp>)ÚitemsrD   rK   r7   r8   r>   ¬   ó   " r   )r-   rB   Úmapr   r&   r)   r5   Úsumr   ÚdictÚzipr2   r3   r/   Ú	from_dict)
Úexprsr   ÚoptionsÚsinglerG   ÚrepsÚcoeffsÚ
coeffs_domr6   Úpolysr7   rK   r8   Úsring�   s    

r]   c                 C  sn   t | tƒr| rt| dd�S dS t | tƒr| fS t| ƒr3tdd„ | D ƒƒr(t| ƒS tdd„ | D ƒƒr3| S tdƒ‚)NT)Úseqr7   c                 s  ó   � | ]}t |tƒV  qd S ©N)Ú
isinstanceÚstr©r<   Úsr7   r7   r8   Ú	<genexpr>¼   ó   € z!_parse_symbols.<locals>.<genexpr>c                 s  r_   r`   )ra   r   rc   r7   r7   r8   re   ¾   rf   zbexpected a string, Symbol or expression or a non-empty sequence of strings, Symbols or expressions)ra   rb   Ú_symbolsr   r-   Úallr"   ©r   r7   r7   r8   Ú_parse_symbols¶   s   

rj   c                   @  s~  e Zd ZU dZded< ded< ded< ded	< d
ed< efdd„Zdd„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ ZdUdd„Zedd„ ƒZdd „ Zed!d"„ ƒZed#d$„ ƒZd%d&„ ZdVd'd(„Zd)d*„ Zd+d,„ Zd-d.„ ZeZdVd/d0„ZdVd1d2„Zd3d4„ Zd5d6„ Zd7d8„ Zd9d:„ Zd;d<„ Z d=d>„ Z!d?d@„ Z"dAdB„ Z#dCdD„ Z$edEdF„ ƒZ%edGdH„ ƒZ&dIdJ„ Z'dKdL„ Z(dMdN„ Z)dOdP„ Z*dQdR„ Z+dSdT„ Z,dS )Wr2   z*Multivariate distributed polynomial ring. ztuple[PolyElement, ...]r3   ztuple[Expr, ...]r   ÚintÚngensr   r5   r    r/   c                   s²  t t|ƒƒ}t|ƒ}t |¡}t ˆ ¡‰ | j|||ˆ f}|jr,t|ƒt|j	ƒ@ r,t
dƒ‚t | ¡}||_t|ƒ|_||_	||_||_ˆ |_t|dƒj|_d| |_| ¡ |_t|jƒ|_|j|jfg|_|rŽt|ƒ}| ¡ |_| ¡ |_ | !¡ |_"| #¡ |_$| %¡ |_&| '¡ |_(| )¡ |_*ndd„ }||_||_ dd„ |_"||_$||_&||_(||_*ˆ t+u r±t,|_-n‡ fdd„|_-t.|j	|jƒD ]\}	}
t/|	t0ƒrÖ|	j1}t2||ƒsÖt3|||
ƒ q¿|S )Nz7polynomial ring and it's ground domain share generatorsr7   ©r   c                 S  ó   dS ©Nr7   r7   )ÚaÚbr7   r7   r8   Ú<lambda>ó   ó    z"PolyRing.__new__.<locals>.<lambda>c                 S  rn   ro   r7   )rp   rq   rJ   r7   r7   r8   rr   ö   rs   c                   s   t | ˆ d�S )N©Úkey)Úmax©Úf©r/   r7   r8   rr      ó    )4Útuplerj   ÚlenÚ	DomainOptÚ
preprocessÚOrderOptÚ__name__Úis_CompositeÚsetr   r"   ÚobjectÚ__new__Ú_hash_tupleÚhashÚ_hashrl   r5   r/   ÚPolyElementÚnewÚdtypeÚ
zero_monomÚ_gensr3   Ú	_gens_setÚoneÚ_oner   r   Úmonomial_mulÚpowÚmonomial_powÚmulpowÚmonomial_mulpowÚldivÚmonomial_ldivÚdivÚmonomial_divÚlcmÚmonomial_lcmÚgcdÚmonomial_gcdr   rv   Úleading_expvrT   ra   r   r;   ÚhasattrÚsetattr)Úclsr   r5   r/   rl   r…   ÚobjÚcodegenÚmonunitÚsymbolÚ	generatorr;   r7   ry   r8   r„   Í   s\   














€zPolyRing.__new__c                 C  sF   | j j}g }t| jƒD ]}|  |¡}| j}|||< | |¡ qt|ƒS )z(Return a list of polynomial generators. )r5   rŽ   Úrangerl   Úmonomial_basisÚzeroÚappendr{   )ÚselfrŽ   rŒ   ÚiÚexpvÚpolyr7   r7   r8   rŒ     s   
zPolyRing._gensc                 C  s   | j | j| jfS r`   )r   r5   r/   ©rª   r7   r7   r8   Ú__getnewargs__  ó   zPolyRing.__getnewargs__c                 C  s.   | j  ¡ }|d= |D ]
}| d¡r||= q
|S )Nr�   Ú	monomial_)Ú__dict__ÚcopyÚ
startswith)rª   Ústateru   r7   r7   r8   Ú__getstate__  s   

€zPolyRing.__getstate__c                 C  s   | j S r`   )r‡   r®   r7   r7   r8   Ú__hash__#  s   zPolyRing.__hash__c                 C  s2   t |tƒo| j| j| j| jf|j|j|j|jfkS r`   )ra   r2   r   r5   rl   r/   ©rª   Úotherr7   r7   r8   Ú__eq__&  s
   
ÿÿzPolyRing.__eq__c                 C  ó
   | |k S r`   r7   r¸   r7   r7   r8   Ú__ne__+  ó   
zPolyRing.__ne__Nc                 C  s(   |d urt |tƒrt|ƒ}|  |||¡S r`   )ra   rB   r{   Ú_clone©rª   r   r5   r/   r7   r7   r8   Úclone.  s   zPolyRing.clonec                 C  s    |   |p| j|p
| j|p| j¡S r`   )Ú	__class__r   r5   r/   r¿   r7   r7   r8   r¾   4  s    zPolyRing._clonec                 C  s   dg| j  }d||< t|ƒS )zReturn the ith-basis element. r   é   )rl   r{   )rª   r«   Úbasisr7   r7   r8   r§   8  s   zPolyRing.monomial_basisc                 C  s
   |   g ¡S r`   )rŠ   r®   r7   r7   r8   r¨   >  s   
zPolyRing.zeroc                 C  s   |   | j¡S r`   )rŠ   r�   r®   r7   r7   r8   rŽ   B  ó   zPolyRing.onec                 C  s   t |tƒo	|j| kS )zATrue if ``element`` is an element of this ring. False otherwise. )ra   rˆ   r9   ©rª   Úelementr7   r7   r8   Ú
is_elementF  s   zPolyRing.is_elementc                 C  s   | j  ||¡S r`   )r5   Úconvert©rª   rÆ   Úorig_domainr7   r7   r8   Ú
domain_newJ  ó   zPolyRing.domain_newc                 C  ó   |   | j|¡S r`   )Úterm_newr‹   )rª   Úcoeffr7   r7   r8   Ú
ground_newM  rÌ   zPolyRing.ground_newc                 C  s    |   |¡}| j}|r|||< |S r`   )rË   r¨   )rª   ÚmonomrÏ   r­   r7   r7   r8   rÎ   P  s
   
zPolyRing.term_newc                 C  s¼   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ƒr5|  	|¡S t |t
ƒrOz|  |¡W S  tyN   |  |¡ Y S w t |tƒrY|  |¡S |  |¡S )NÚ
conversionÚparsing)ra   rˆ   r9   r5   r   rÐ   ÚNotImplementedErrorrb   rS   rU   rB   Ú
from_termsÚ
ValueErrorÚ	from_listr   Ú	from_exprrÅ   r7   r7   r8   Úring_newW  s&   






ÿ


zPolyRing.ring_newc                 C  s8   | j }| j}| ¡ D ]\}}|||ƒ}|r|||< q
|S r`   )rË   r¨   rO   )rª   rÆ   rÊ   rË   r­   rÑ   rÏ   r7   r7   r8   rU   o  s   
€zPolyRing.from_dictc                 C  s   |   t|ƒ|¡S r`   )rU   rS   rÉ   r7   r7   r8   rÕ   z  r°   zPolyRing.from_termsc                 C  s   |   t|| jd | jƒ¡S ©NrÂ   )rU   r   rl   r5   rÅ   r7   r7   r8   r×   }  s   zPolyRing.from_listc                   s$   ˆj ‰‡ ‡‡‡fdd„‰ ˆ t|ƒƒS )Nc                   sˆ   ˆ  | ¡}|d ur|S | jrttttˆ | jƒƒƒS | jr'ttttˆ | jƒƒƒS |  	¡ \}}|j
r<|dkr<ˆ |ƒt|ƒ S ˆ ˆ | ¡¡S rÚ   )ÚgetÚis_Addr	   r   rB   rQ   ÚargsÚis_Mulr   Úas_base_expÚ
is_Integerrk   rÐ   rÈ   )Úexprr¥   ÚbaseÚexp©Ú_rebuildr5   Úmappingrª   r7   r8   rå   ƒ  s   
z(PolyRing._rebuild_expr.<locals>._rebuild)r5   r   )rª   rá   ræ   r7   rä   r8   Ú_rebuild_expr€  s   zPolyRing._rebuild_exprc                 C  sP   t tt| j| jƒƒƒ}z|  ||¡}W n ty"   td| |f ƒ‚w |  |¡S )Nz@expected an expression convertible to a polynomial in %s, got %s)	rS   rB   rT   r   r3   rç   r!   rÖ   rÙ   )rª   rá   ræ   r­   r7   r7   r8   rØ   —  s   ÿ
zPolyRing.from_exprc                 C  sî   |du r| j rd}|S d}|S t|tƒr9|}d|kr"|| j k r"	 |S | j  |kr3|dkr3| d }|S td| ƒ‚|  |¡rUz	| j |¡}W |S  tyT   td| ƒ‚w t|tƒrqz	| j |¡}W |S  typ   td| ƒ‚w td| ƒ‚)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)	rl   ra   rk   rÖ   rÇ   r3   Úindexrb   r   )rª   Úgenr«   r7   r7   r8   ré   ¡  s<   é
êï
ò
öÿ
ûÿzPolyRing.indexc                   s>   t t| j|ƒƒ‰ ‡ fdd„t| jƒD ƒ}|s| jS | j|d�S )z,Remove specified generators from this ring. c                   ó   g | ]
\}}|ˆ vr|‘qS r7   r7   ©r<   r«   rd   ©Úindicesr7   r8   r>   Ã  ó    z!PolyRing.drop.<locals>.<listcomp>ri   )r‚   rQ   ré   Ú	enumerater   r5   rÀ   ©rª   r3   r   r7   rí   r8   ÚdropÀ  s
   zPolyRing.dropc                 C  s    | j | }|s
| jS | j|d�S )Nri   )r   r5   rÀ   )rª   ru   r   r7   r7   r8   Ú__getitem__Ê  s   
zPolyRing.__getitem__c                 C  s2   | j js
t| j dƒr| j| j j d�S td| j  ƒ‚)Nr5   ©r5   z%s is not a composite domain)r5   r�   rž   rÀ   rÖ   r®   r7   r7   r8   Ú	to_groundÒ  s   zPolyRing.to_groundc                 C  ó   t | ƒS r`   r   r®   r7   r7   r8   Ú	to_domainÙ  ó   zPolyRing.to_domainc                 C  s   ddl m} || j| j| jƒS )Nr   )Ú	FracField)Úsympy.polys.fieldsrù   r   r5   r/   )rª   rù   r7   r7   r8   Úto_fieldÜ  s   zPolyRing.to_fieldc                 C  s   t | jƒdkS rÚ   ©r|   r3   r®   r7   r7   r8   Úis_univariateà  ó   zPolyRing.is_univariatec                 C  s   t | jƒdkS rÚ   rü   r®   r7   r7   r8   Úis_multivariateä  rþ   zPolyRing.is_multivariatec                 G  s8   | j }|D ]}t|td�r|| j|Ž 7 }q||7 }q|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¡   r7   r7   r8   r   è  ó   
zPolyRing.addc                 G  s8   | j }|D ]}t|td�r|| j|Ž 9 }q||9 }q|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  r7   r7   r8   r     r  zPolyRing.mulc                   s\   t t| j|ƒƒ‰ ‡ fdd„t| jƒD ƒ}‡ fdd„t| jƒD ƒ}|s$| S | j|| j|Ž d�S )zd
        Remove specified generators from the ring and inject them into
        its domain.
        c                   rë   r7   r7   rì   rí   r7   r8   r>   $  rï   z+PolyRing.drop_to_ground.<locals>.<listcomp>c                   rë   r7   r7   )r<   r«   rê   rí   r7   r8   r>   %  rï   ©r   r5   )r‚   rQ   ré   rð   r   r3   rÀ   rò   rñ   r7   rí   r8   Údrop_to_ground  s   zPolyRing.drop_to_groundc                 C  s2   | |krt | jƒ t |jƒ¡}| jt|ƒd�S | S )z+Add the generators of ``other`` to ``self``ri   ©r‚   r   ÚunionrÀ   rB   )rª   r¹   Úsymsr7   r7   r8   Úcompose,  s   zPolyRing.composec                 C  s$   t | jƒ t |ƒ¡}| jt|ƒd�S )z9Add the elements of ``symbols`` as generators to ``self``ri   r  )rª   r   r
  r7   r7   r8   Úadd_gens4  s   zPolyRing.add_gensc                   s‚   |dk s	|| j krtd|| jf ƒ‚|s| jS | j}tt| j ƒt|ƒƒD ]‰ t‡ fdd„t| j ƒD ƒƒ}||  	|| j
j¡7 }q$|S )zo
        Return the elementary symmetric polynomial of degree *n* over
        this ring's generators.
        r   z7Cannot generate symmetric polynomial of order %s for %sc                 3  s   � | ]	}t |ˆ v ƒV  qd S r`   )rk   ©r<   r«   ©rd   r7   r8   re   E  ó   € z*PolyRing.symmetric_poly.<locals>.<genexpr>)rl   rÖ   r3   rŽ   r¨   r,   r¦   rk   r{   rÎ   r5   )rª   Únr­   rÑ   r7   r  r8   Úsymmetric_poly9  s   zPolyRing.symmetric_poly)NNNr`   )-r€   Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r   r„   rŒ   r¯   r¶   r·   rº   r¼   rÀ   r   r¾   r§   Úpropertyr¨   rŽ   rÇ   rË   rÐ   rÎ   rÙ   Ú__call__rU   rÕ   r×   rç   rØ   ré   rò   ró   rõ   r÷   rû   rý   rÿ   r   r   r  r  r  r  r7   r7   r7   r8   r2   Ä   sb   
 >











r2   c                      s–  e Zd ZdZ‡ fdd„Zdd„ Zdd„ Zdd	„ Zd
d„ ZdZ	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Z�d*dd „Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7d8„ Zd9d:„ Z e!d;d<„ ƒZ"e!d=d>„ ƒZ#e!d?d@„ ƒZ$e!dAdB„ ƒZ%e!dCdD„ ƒZ&e!dEdF„ ƒZ'e!dGdH„ ƒZ(e!dIdJ„ ƒZ)e!dKdL„ ƒZ*e!dMdN„ ƒZ+e!dOdP„ ƒZ,e!dQdR„ ƒZ-e!dSdT„ ƒZ.e!dUdV„ ƒZ/e!dWdX„ ƒZ0e!dYdZ„ ƒZ1e!d[d\„ ƒZ2d]d^„ Z3d_d`„ Z4dadb„ Z5dcdd„ Z6dedf„ Z7dgdh„ Z8didj„ Z9dkdl„ Z:dmdn„ Z;dodp„ Z<dqdr„ Z=dsdt„ Z>dudv„ Z?dwdx„ Z@dydz„ ZAd{d|„ ZBd}d~„ ZCdd€„ ZDd�d‚„ ZEdƒd„„ ZFd…d†„ ZGd‡dˆ„ ZHd‰dŠ„ ZId‹dŒ„ ZJd�dŽ„ ZKd�d�„ ZLd‘d’„ ZM�d*d“d”„ZNd•d–„ ZO�d*d—d˜„ZPd™dš„ ZQd›dœ„ ZRd�dž„ ZSdŸd „ ZTd¡d¢„ ZUe!d£d¤„ ƒZVe!d¥d¦„ ƒZWd§d¨„ ZXe!d©dª„ ƒZYd«d¬„ ZZd­d®„ Z[�d*d¯d°„Z\�d*d±d²„Z]�d*d³d´„Z^dµd¶„ Z_d·d¸„ Z`d¹dº„ Zad»d¼„ Zbd½d¾„ Zcd¿dÀ„ ZddÁdÂ„ ZedÃdÄ„ ZfdÅdÆ„ ZgdÇdÈ„ ZhdÉdÊ„ ZidËdÌ„ ZjdÍdÎ„ ZkdÏdÐ„ ZldÑdÒ„ ZmdÓdÔ„ ZnenZodÕdÖ„ Zpd×dØ„ ZqdÙdÚ„ ZrdÛdÜ„ ZsdÝdÞ„ Ztdßdà„ Zudádâ„ Zvdãdä„ Zwdådæ„ Zxdçdè„ Zydédê„ Zzdëdì„ Z{dídî„ Z|dïdð„ Z}dñdò„ Z~dódô„ Zdõdö„ Z€d÷dø„ Z��d*dùdú„Z‚�d*dûdü„Zƒdýdþ„ Z„�d*dÿ�d „Z…�d�d„ Z†�d*�d�d„Z‡�d*�d�d„Zˆ�d*�d�d„Z‰�d*�d	�d
„ZŠ�d*�d�d„Z‹�d�d„ ZŒ�d�d„ Z��d�d„ ZŽ�d�d„ Z��d�d„ Z��d�d„ Z‘�d�d„ Z’�d�d„ Z“�d�d„ Z”�d�d „ Z•�d!�d"„ Z–�d#�d$„ Z—�d+�d&�d'„Z˜�d(�d)„ Z™‡  ZšS (,  rˆ   z5Element of multivariate distributed polynomial ring. c                   s   t ƒ  |¡ || _d S r`   )ÚsuperÚ__init__r9   )rª   r9   Úinit©rÁ   r7   r8   r  M  s   
zPolyElement.__init__c                 C  s‚   t | tƒsJ ‚t | jtƒsJ ‚| jj}t |tƒsJ ‚|  ¡ D ] \}}| |¡s)J ‚t|ƒ| jj	ks3J ‚t
dd„ |D ƒƒs>J ‚qd S )Nc                 s  s"   � | ]}t |tƒo|d kV  qdS )r   N)ra   rk   )r<   rã   r7   r7   r8   re   [  s   €  z%PolyElement._check.<locals>.<genexpr>)ra   rˆ   r9   r2   r5   r   rO   Úof_typer|   rl   rh   )rª   ÚdomrÑ   rÏ   r7   r7   r8   Ú_checkS  s   ýzPolyElement._checkc                 C  rÍ   r`   )rÁ   r9   )rª   r  r7   r7   r8   r‰   ]  rÌ   zPolyElement.newc                 C  s
   | j  ¡ S r`   )r9   r÷   r®   r7   r7   r8   Úparent`  r½   zPolyElement.parentc                 C  s   | j t|  ¡ ƒfS r`   )r9   rB   Ú	itertermsr®   r7   r7   r8   r¯   c  ó   zPolyElement.__getnewargs__Nc                 C  s.   | j }|d u rt| jt|  ¡ ƒfƒ | _ }|S r`   )r‡   r†   r9   Ú	frozensetrO   )rª   r‡   r7   r7   r8   r·   h  s   zPolyElement.__hash__c                 C  s
   |   | ¡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®   r7   r7   r8   r³   s  s   
zPolyElement.copyc                 C  sV   | j |kr| S | j j|jkr#ttt| | j j|jƒŽ ƒ}| || j j¡S | | | j j¡S r`   )r9   r   rB   rT   r(   rÕ   r5   rU   )rª   Únew_ringÚtermsr7   r7   r8   Úset_ring�  s   
zPolyElement.set_ringc                 G  sJ   |s| j j}nt|ƒ| j jkrtd| j jt|ƒf ƒ‚t|  ¡ g|¢R Ž S )Nz+Wrong number of symbols, expected %s got %s)r9   r   r|   rl   rÖ   r'   Úas_expr_dict)rª   r   r7   r7   r8   Úas_expr˜  s   
ÿÿzPolyElement.as_exprc                   s    | j jj‰ ‡ fdd„|  ¡ D ƒS )Nc                   s   i | ]	\}}|ˆ |ƒ“qS r7   r7   ©r<   rÑ   rÏ   ©Úto_sympyr7   r8   rM   ¥  rN   z,PolyElement.as_expr_dict.<locals>.<dictcomp>)r9   r5   r*  r   r®   r7   r)  r8   r&  £  s   
zPolyElement.as_expr_dictc                   sx   | j j}|jr
|js|j| fS | ¡ }|j‰ |j}|j}|  ¡ D ]	}|ˆ ||ƒƒ‰ q |  	‡ fdd„|  
¡ D ƒ¡}ˆ |fS )Nc                   ó   g | ]
\}}||ˆ  f‘qS r7   r7   )r<   ÚkÚv©Úcommonr7   r8   r>   µ  rï   z,PolyElement.clear_denoms.<locals>.<listcomp>)r9   r5   Úis_FieldÚhas_assoc_RingrŽ   Úget_ringr™   ÚdenomrC   r‰   rO   )rª   r5   Úground_ringr™   r3  rÏ   r­   r7   r.  r8   Úclear_denoms§  s   
zPolyElement.clear_denomsc                 C  s$   t |  ¡ ƒD ]	\}}|s| |= qdS )z+Eliminate monomials with zero coefficient. N©rB   rO   )rª   r,  r-  r7   r7   r8   Ú
strip_zero¸  s
   €þzPolyElement.strip_zeroc                 C  sD   |s|  S | j  |¡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)r9   rÇ   rS   rº   r|   rÛ   r‹   ©Úp1Úp2r7   r7   r8   rº   ¾  s   zPolyElement.__eq__c                 C  r»   r`   r7   r8  r7   r7   r8   r¼   Ø  r½   zPolyElement.__ne__c                 C  sª   | j }| |¡r0t|  ¡ ƒt| ¡ ƒkrdS |jj}|  ¡ D ]}|| | || |ƒs- dS qdS t| ƒdkr8dS z|j |¡}W n
 tyJ   Y dS w |j |  	¡ ||¡S )z+Approximate equality test for polynomials. FTrÂ   )
r9   rÇ   r‚   Úkeysr5   Úalmosteqr|   rÈ   r!   Úconst)r9  r:  Ú	tolerancer9   r<  r,  r7   r7   r8   r<  Û  s$   
ÿÿzPolyElement.almosteqc                 C  s   t | ƒ|  ¡ fS r`   )r|   r$  r®   r7   r7   r8   Úsort_keyó  r°   zPolyElement.sort_keyc                 C  s"   | j  |¡r||  ¡ | ¡ ƒS tS r`   )r9   rÇ   r?  ÚNotImplemented)r9  r:  Úopr7   r7   r8   Ú_cmpö  s   zPolyElement._cmpc                 C  ó   |   |t¡S r`   )rB  r   r8  r7   r7   r8   Ú__lt__ü  ó   zPolyElement.__lt__c                 C  rC  r`   )rB  r   r8  r7   r7   r8   Ú__le__þ  rE  zPolyElement.__le__c                 C  rC  r`   )rB  r   r8  r7   r7   r8   Ú__gt__   rE  zPolyElement.__gt__c                 C  rC  r`   )rB  r   r8  r7   r7   r8   Ú__ge__  rE  zPolyElement.__ge__c                 C  sD   | j }| |¡}|jdkr||jfS t|jƒ}||= ||j|d�fS )NrÂ   ri   )r9   ré   rl   r5   rB   r   rÀ   ©rª   rê   r9   r«   r   r7   r7   r8   Ú_drop  s   



zPolyElement._dropc                 C  s„   |   |¡\}}| jjdkr| jr|  d¡S td| ƒ‚|j}|  ¡ D ]\}}|| dkr:t|ƒ}||= ||t	|ƒ< q"td| ƒ‚|S )NrÂ   zCannot drop %sr   )
rJ  r9   rl   Ú	is_groundrÏ   rÖ   r¨   rO   rB   r{   )rª   rê   r«   r9   r­   r,  r-  ÚKr7   r7   r8   rò     s   
zPolyElement.dropc                 C  s6   | j }| |¡}t|jƒ}||= ||j||| d�fS )Nr  )r9   ré   rB   r   rÀ   rI  r7   r7   r8   Ú_drop_to_ground%  s
   

zPolyElement._drop_to_groundc                 C  s¤   | j jdkr
tdƒ‚|  |¡\}}|j}|jjd }|  ¡ D ]1\}}|d |… ||d d …  }||vr@|||   |¡||< q||  |||   |¡7  < q|S )NrÂ   z$Cannot drop only generator to groundr   )	r9   rl   rÖ   rM  r¨   r5   r3   r   Ú
mul_ground)rª   rê   r«   r9   r­   rÑ   rÏ   Úmonr7   r7   r8   r  -  s    zPolyElement.drop_to_groundc                 C  s   t | | jjd | jjƒS rÚ   )r   r9   rl   r5   r®   r7   r7   r8   Úto_dense>  ó   zPolyElement.to_densec                 C  rö   r`   )rS   r®   r7   r7   r8   Úto_dictA  rø   zPolyElement.to_dictc                 C  sª  | s
|  | jjj¡S |d }|d }| j}|j}|j}	|j}
g }|  ¡ D ]–\}}|j |¡}|r2dnd}| 	|¡ ||
krP|  |¡}|rO| 
d¡rO|dd … }n|rU| }|| jjjkre|j||dd�}nd	}g }t|	ƒD ]=}|| }|svqm|j|| |dd�}|dkr£|t|ƒksŽ|d
k r—|j||dd�}n|}| 	|||f ¡ qm| 	d| ¡ qm|r²|g| }| 	| |¡¡ q$|d
 dv rÐ| d
¡}|dkrÐ| d
d¡ d	 |¡S )NÚMulÚAtomú - ú + ú-rÂ   T)ÚstrictÚ r   Fz%s)rV  rU  )Ú_printr9   r5   r¨   r   rl   r‹   r$  Úis_negativer©   r´   rŽ   Úparenthesizer¦   rk   ÚjoinÚpopÚinsert)rª   ÚprinterÚ
precedenceÚexp_patternÚ
mul_symbolÚprec_mulÚ	prec_atomr9   r   rl   ÚzmÚsexpvsr¬   rÏ   ÚnegativeÚsignÚscoeffÚsexpvr«   rã   r¤   ÚsexpÚheadr7   r7   r8   rb   D  sV   

€


zPolyElement.strc                 C  s   | | j jv S r`   )r9   r�   r®   r7   r7   r8   Úis_generatort  rÄ   zPolyElement.is_generatorc                 C  s   |  pt | ƒdko| jj| v S rÚ   )r|   r9   r‹   r®   r7   r7   r8   rK  x  s   zPolyElement.is_groundc                 C  s   |  pt | ƒdko| jdkS rÚ   )r|   ÚLCr®   r7   r7   r8   Úis_monomial|  s   zPolyElement.is_monomialc                 C  s   t | ƒdkS rÚ   )r|   r®   r7   r7   r8   Úis_term€  rÄ   zPolyElement.is_termc                 C  ó   | j j | j¡S r`   )r9   r5   r[  ro  r®   r7   r7   r8   r[  „  ó   zPolyElement.is_negativec                 C  rr  r`   )r9   r5   Úis_positivero  r®   r7   r7   r8   rt  ˆ  rs  zPolyElement.is_positivec                 C  rr  r`   )r9   r5   Úis_nonnegativero  r®   r7   r7   r8   ru  Œ  rs  zPolyElement.is_nonnegativec                 C  rr  r`   )r9   r5   Úis_nonpositivero  r®   r7   r7   r8   rv  �  rs  zPolyElement.is_nonpositivec                 C  s   |  S r`   r7   rw   r7   r7   r8   Úis_zero”  s   zPolyElement.is_zeroc                 C  s   | | j jkS r`   )r9   rŽ   rw   r7   r7   r8   Úis_one˜  rÄ   zPolyElement.is_onec                 C  rr  r`   )r9   r5   rx  ro  rw   r7   r7   r8   Úis_monicœ  rs  zPolyElement.is_monicc                 C  s   | j j |  ¡ ¡S r`   )r9   r5   rx  Úcontentrw   r7   r7   r8   Úis_primitive   s   zPolyElement.is_primitivec                 C  ó   t dd„ |  ¡ D ƒƒS )Nc                 s  ó   � | ]	}t |ƒd kV  qdS ©rÂ   N©rR   ©r<   rÑ   r7   r7   r8   re   ¦  r  z(PolyElement.is_linear.<locals>.<genexpr>©rh   Ú
itermonomsrw   r7   r7   r8   Ú	is_linear¤  ó   zPolyElement.is_linearc                 C  r|  )Nc                 s  r}  )é   Nr  r€  r7   r7   r8   re   ª  r  z+PolyElement.is_quadratic.<locals>.<genexpr>r�  rw   r7   r7   r8   Úis_quadratic¨  r„  zPolyElement.is_quadraticc                 C  ó   | j jsdS | j  | ¡S ©NT)r9   rl   Ú	dmp_sqf_prw   r7   r7   r8   Úis_squarefree¬  ó   zPolyElement.is_squarefreec                 C  r‡  rˆ  )r9   rl   Údmp_irreducible_prw   r7   r7   r8   Úis_irreducible²  r‹  zPolyElement.is_irreduciblec                 C  ó   | j jr
| j  | ¡S tdƒ‚)Nzcyclotomic polynomial)r9   rý   Údup_cyclotomic_pr$   rw   r7   r7   r8   Úis_cyclotomic¸  s   zPolyElement.is_cyclotomicc                 C  s   |   dd„ |  ¡ D ƒ¡S )Nc                 S  s   g | ]	\}}|| f‘qS r7   r7   r(  r7   r7   r8   r>   À  rN   z'PolyElement.__neg__.<locals>.<listcomp>)r‰   r   r®   r7   r7   r8   Ú__neg__¿  rQ  zPolyElement.__neg__c                 C  s   | S r`   r7   r®   r7   r7   r8   Ú__pos__Â  s   zPolyElement.__pos__c           
      C  s:  |s|   ¡ S | j}| |¡r5|   ¡ }|j}|jj}| ¡ D ]\}}|||ƒ| }|r/|||< q||= q|S t|tƒr]t|jt	ƒrH|jj|jkrHnt|jjt	ƒr[|jjj|kr[| 
| ¡S tS z| |¡}W n tyo   t Y S w |   ¡ }|sx|S |j}	|	|  ¡ vr‡|||	< |S |||	  kr“||	= |S ||	  |7  < |S )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³   r9   rÇ   rÛ   r5   r¨   rO   ra   rˆ   r   Ú__radd__r@  rË   r!   r‹   r;  )
r9  r:  r9   r  rÛ   r¨   r,  r-  Úcp2rf  r7   r7   r8   Ú__add__Å  sH   



ÿüÿzPolyElement.__add__c                 C  s†   |   ¡ }|s|S | j}z| |¡}W n ty   t Y S w |j}||  ¡ vr-|||< |S |||  kr9||= |S ||  |7  < |S r`   )r³   r9   rË   r!   r@  r‹   r;  )r9  r  r  r9   rf  r7   r7   r8   r“  û  s$   ÿüÿzPolyElement.__radd__c           	      C  s2  |s|   ¡ S | j}| |¡r5|   ¡ }|j}|jj}| ¡ D ]\}}|||ƒ| }|r/|||< q||= q|S t|tƒr]t|jt	ƒrH|jj|jkrHnt|jjt	ƒr[|jjj|kr[| 
| ¡S tS z| |¡}W n tyo   t Y S w |   ¡ }|j}||  ¡ vr„| ||< |S ||| kr�||= |S ||  |8  < |S )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³   r9   rÇ   rÛ   r5   r¨   rO   ra   rˆ   r   Ú__rsub__r@  rË   r!   r‹   r;  )	r9  r:  r9   r  rÛ   r¨   r,  r-  rf  r7   r7   r8   Ú__sub__  sD   



ÿ
üÿzPolyElement.__sub__c                 C  sV   | j }z| |¡}W n ty   t Y S w |j}| D ]	}| |  ||< q||7 }|S )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

        )r9   rË   r!   r@  r¨   )r9  r  r9   r  r¬   r7   r7   r8   r–  E  s   ÿzPolyElement.__rsub__c                 C  s.  | j }|j}| r
|s|S | |¡rG|j}|jj}|j}t| ¡ ƒ}|  ¡ D ]\}}	|D ]\}
}|||
ƒ}|||ƒ|	|  ||< q+q%| ¡  |S t	|t
ƒrot	|jtƒrZ|jj |j krZnt	|j jtƒrm|j jj |krm| | ¡S tS z| |¡}W n ty�   t Y S w |  ¡ D ]\}}	|	| }|r”|||< q†|S )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

        )r9   r¨   rÇ   rÛ   r5   r�   rB   rO   r7  ra   rˆ   r   Ú__rmul__r@  rË   r!   )r9  r:  r9   r  rÛ   r¨   r�   Úp2itÚexp1Úv1Úexp2Úv2rã   r-  r7   r7   r8   Ú__mul__a  sB   

þ

ÿ€zPolyElement.__mul__c                 C  sb   | j j}|s|S z|j  |¡}W n ty   t Y S w |  ¡ D ]\}}|| }|r.|||< q |S )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

        )r9   r¨   rË   r!   r@  rO   )r9  r:  r  rš  r›  r-  r7   r7   r8   r˜  •  s   ÿ€zPolyElement.__rmul__c                 C  s  t |tƒstd| ƒ‚|dk rtd| ƒ‚| j}|s#| r|jS tdƒ‚t| ƒdkrRt|  ¡ ƒd \}}|j	}||j
jkrF||| ||¡< |S || || ||¡< |S t|ƒ}|dk r^tdƒ‚|dkrf|  ¡ S |dkrn|  ¡ S |dkrx| |  ¡  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#exponent must be an integer, got %sr   z/exponent must be a non-negative integer, got %sz0**0rÂ   zNegative exponentr…  é   é   )ra   rk   Ú	TypeErrorrÖ   r9   rŽ   r|   rB   rO   r¨   r5   r’   r³   ÚsquareÚ_pow_multinomialÚ_pow_generic)rª   r  r9   rÑ   rÏ   r  r7   r7   r8   Ú__pow__²  s:   
þ

zPolyElement.__pow__c                 C  sB   | j j}| }	 |d@ r|| }|d8 }|s	 |S | ¡ }|d }q)NTrÂ   r…  )r9   rŽ   r¢  )rª   r  r  rJ   r7   r7   r8   r¤  è  s   ýøzPolyElement._pow_genericc                 C  sÂ   t t| ƒ|ƒ ¡ }| jj}| jj}|  ¡ }| jjj}| jj}|D ]>\}}	|}
|	}t||ƒD ]\}\}}|rA||
||ƒ}
||| 9 }q-t	|
ƒ}|}| 
||¡| }|rW|||< q ||v r^||= q |S r`   )r   r|   rO   r9   r”   r‹   r5   r¨   rT   r{   rÛ   )rª   r  Úmultinomialsr”   r‹   r$  r¨   r­   ÚmultinomialÚmultinomial_coeffÚproduct_monomÚproduct_coeffrã   rÑ   rÏ   r7   r7   r8   r£  ø  s.   
€
€zPolyElement._pow_multinomialc                 C  sÖ   | j }|j}|j}t|  ¡ ƒ}|jj}|j}tt|ƒƒD ]'}|| }| | }	t|ƒD ]}
||
 }|||ƒ}|||ƒ|	| |   ||< q*q| 	d¡}|j}|  
¡ D ]\}}|||ƒ}|||ƒ|d  ||< qP| ¡  |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…  )r9   r¨   rÛ   rB   r;  r5   r�   r¦   r|   Úimul_numrO   r7  )rª   r9   r  rÛ   r;  r¨   r�   r«   Úk1ÚpkÚjÚk2rã   r,  r-  r7   r7   r8   r¢    s*   
ý

zPolyElement.squarec                 C  s°   | j }|s	tdƒ‚| |¡r|  |¡S t|tƒr;t|jtƒr&|jj |j kr&nt|j jtƒr9|j jj |kr9| | ¡S t	S z| 
|¡}W n tyM   t	 Y S w |  |¡|  |¡fS ©Núpolynomial division)r9   ÚZeroDivisionErrorrÇ   r—   ra   rˆ   r5   r   Ú__rdivmod__r@  rË   r!   Ú
quo_groundÚ
rem_ground©r9  r:  r9   r7   r7   r8   Ú
__divmod__:  s"   



ÿzPolyElement.__divmod__c                 C  ó6   | j }z| |¡}W n ty   t Y S w | | ¡S r`   )r9   rÐ   r!   r@  r—   r¶  r7   r7   r8   r³  P  ó   ÿ
zPolyElement.__rdivmod__c                 C  ó¦   | j }|s	tdƒ‚| |¡r|  |¡S t|tƒr;t|jtƒr&|jj |j kr&nt|j jtƒr9|j jj |kr9| | ¡S t	S z| 
|¡}W n tyM   t	 Y S w |  |¡S r°  )r9   r²  rÇ   Úremra   rˆ   r5   r   Ú__rmod__r@  rË   r!   rµ  r¶  r7   r7   r8   Ú__mod__Y  ó"   



ÿ
zPolyElement.__mod__c                 C  r¸  r`   )r9   rÐ   r!   r@  r»  r¶  r7   r7   r8   r¼  o  r¹  zPolyElement.__rmod__c                 C  rº  r°  )r9   r²  rÇ   Úquora   rˆ   r5   r   Ú__rtruediv__r@  rË   r!   r´  r¶  r7   r7   r8   Ú__floordiv__x  r¾  zPolyElement.__floordiv__c                 C  r¸  r`   )r9   rÐ   r!   r@  r¿  r¶  r7   r7   r8   Ú__rfloordiv__Ž  r¹  zPolyElement.__rfloordiv__c                 C  rº  r°  )r9   r²  rÇ   Úexquora   rˆ   r5   r   rÀ  r@  rË   r!   r´  r¶  r7   r7   r8   Ú__truediv__—  r¾  zPolyElement.__truediv__c                 C  r¸  r`   )r9   rÐ   r!   r@  rÃ  r¶  r7   r7   r8   rÀ  ­  r¹  zPolyElement.__rtruediv__c                   sL   | j j‰| j j}|j‰ | j j‰|jr‡ ‡‡fdd„}|S ‡ ‡‡fdd„}|S )Nc                   sB   | \}}|\}}|ˆkr|}nˆ||ƒ}|d ur|ˆ ||ƒfS d S r`   r7   ©Ú	a_lm_a_lcÚ	b_lm_b_lcÚa_lmÚa_lcÚb_lmÚb_lcrÑ   ©Ú
domain_quor˜   rf  r7   r8   Úterm_div½  s   
z'PolyElement._term_div.<locals>.term_divc                   sJ   | \}}|\}}|ˆkr|}nˆ||ƒ}|d u s#|| s#|ˆ ||ƒfS d S r`   r7   rÅ  rÌ  r7   r8   rÎ  É  s   
)r9   r‹   r5   r¿  r˜   r0  )rª   r5   rÎ  r7   rÌ  r8   Ú	_term_div¶  s   ôzPolyElement._term_divc                   s®  | j ‰ d}t|tƒrd}|g}t|ƒstdƒ‚| s&|r!ˆ jˆ jfS g ˆ jfS |D ]}|j ˆ kr3tdƒ‚q(t|ƒ}‡ fdd„t|ƒD ƒ}|  	¡ }ˆ j}|  
¡ }dd„ |D ƒ}	|r»d}
d}|
|k r§|dkr§| ¡ }|||| f|	|
 ||
 |	|
  fƒ}|d	ur›|\}}||
  ||f¡||
< | ||
 || f¡}d
}n|
d
7 }
|
|k r§|dksc|s¹| ¡ }| ||| f¡}||= |sW|ˆ jkrÄ||7 }|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                   s   g | ]}ˆ j ‘qS r7   )r¨   r  ©r9   r7   r8   r>     r?   z#PolyElement.div.<locals>.<listcomp>c                 S  s   g | ]}|  ¡ ‘qS r7   )r�   )r<   Úfxr7   r7   r8   r>     ó    r   NrÂ   )r9   ra   rˆ   rh   r²  r¨   rÖ   r|   r¦   r³   rÏ  r�   Ú_iadd_monomÚ_iadd_poly_monomr‹   )rª   ÚfvÚ
ret_singlerx   rd   Úqvr  ÚrrÎ  Úexpvsr«   Údivoccurredr¬   ÚtermÚexpv1rJ   r7   rÐ  r8   r—   ×  s\   


ÿ&÷
ð

zPolyElement.divc                 C  s>  | }t |tƒr
|g}t|ƒstdƒ‚|j}|j}|j}|j}|j}| ¡ }|j	}	| 
¡ }|j}
|r�|D ]A}||	|j	ƒ}|d urt|\}}| ¡ D ]\}}|||ƒ}|
||ƒ||  }|s_||= qG|||< qG| ¡ }|d urr||| f}	 n'q3|	\}}||v r†||  |7  < n|||< ||= | ¡ }|d ur›||| f}	|s1|S r°  )ra   rˆ   rh   r²  r9   r5   r¨   r�   rÏ  ÚLTr³   rÛ   r   r�   )rª   ÚGrx   r9   r5   r¨   r�   rØ  rÎ  ÚltfrÛ   ÚgÚtqrI   rJ   ÚmgÚcgÚm1Úc1ÚltmÚltcr7   r7   r8   r»  #  sP   


óæzPolyElement.remc                 C  ó   |   |¡d S ©Nr   )r—   )rx   rÞ  r7   r7   r8   r¿  P  rÌ   zPolyElement.quoc                 C  s    |   |¡\}}|s|S t| |ƒ‚r`   )r—   r#   )rx   rÞ  ÚqrØ  r7   r7   r8   rÃ  S  s   
zPolyElement.exquoc                 C  sb   | | j jv r|  ¡ }n| }|\}}| |¡}|du r |||< |S ||7 }|r,|||< |S ||= |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

        N)r9   r�   r³   rÛ   )rª   ÚmcÚcpselfr¬   rÏ   rJ   r7   r7   r8   rÓ  [  s   

ûÿzPolyElement._iadd_monomc                 C  s~   | }||j jv r| ¡ }|\}}|j}|j jj}|j j}| ¡ D ]\}	}
||	|ƒ}|||ƒ|
|  }|r9|||< q ||= q |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

        )r9   r�   r³   rÛ   r5   r¨   r�   rO   )rª   r:  rë  r9  rI   rJ   rÛ   r¨   r�   r,  r-  ÚkarÏ   r7   r7   r8   rÔ  ‡  s   


zPolyElement._iadd_poly_monomc                   ó:   | j  |¡‰ | s
tS ˆ dk rdS t‡ fd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  ó   � | ]}|ˆ  V  qd S r`   r7   r€  ©r«   r7   r8   re   º  ó   € z%PolyElement.degree.<locals>.<genexpr>)r9   ré   r   rv   r‚  ©rx   Úxr7   rð  r8   Údegree¬  ó   zPolyElement.degreec                 C  ó,   | s	t f| jj 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   r9   rl   r{   rQ   rv   rB   rT   r‚  rw   r7   r7   r8   Údegrees¼  ó   zPolyElement.degreesc                   rî  )z�
        The tail degree in ``x`` or the main variable.

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

        r   c                 3  rï  r`   r7   r€  rð  r7   r8   re   Ö  rñ  z*PolyElement.tail_degree.<locals>.<genexpr>)r9   ré   r   Úminr‚  rò  r7   rð  r8   Útail_degreeÈ  rõ  zPolyElement.tail_degreec                 C  rö  )z�
        A tuple containing tail degrees in all variables.

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

        )	r   r9   rl   r{   rQ   rù  rB   rT   r‚  rw   r7   r7   r8   Útail_degreesØ  rø  zPolyElement.tail_degreesc                 C  s   | 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)r9   r�   r®   r7   r7   r8   r�   ä  s   zPolyElement.leading_expvc                 C  s   |   || jjj¡S r`   )rÛ   r9   r5   r¨   ©rª   r¬   r7   r7   r8   Ú
_get_coeffø  r!  zPolyElement._get_coeffc                 C  sj   |dkr|   | jj¡S | j |¡r/t| ¡ ƒ}t|ƒdkr/|d \}}|| jjjkr/|   |¡S t	d| ƒ‚)a  
        Returns the coefficient that stands next to the given monomial.

        Parameters
        ==========

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

        Examples
        ========

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

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

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

        rÂ   r   zexpected a monomial, got %s)
rý  r9   r‹   rÇ   rB   r   r|   r5   rŽ   rÖ   )rª   rÆ   r$  rÑ   rÏ   r7   r7   r8   rÏ   û  s   
zPolyElement.coeffc                 C  s   |   | jj¡S )z"Returns the constant coefficient. )rý  r9   r‹   r®   r7   r7   r8   r=     rþ   zPolyElement.constc                 C  s   |   |  ¡ ¡S r`   )rý  r�   r®   r7   r7   r8   ro  $  rþ   zPolyElement.LCc                 C  s   |   ¡ }|d u r| jjS |S r`   )r�   r9   r‹   rü  r7   r7   r8   ÚLM(  s   zPolyElement.LMc                 C  s&   | 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

        )r9   r¨   r�   r5   rŽ   ©rª   r  r¬   r7   r7   r8   Úleading_monom0  s
   zPolyElement.leading_monomc                 C  s0   |   ¡ }|d u r| jj| jjjfS ||  |¡fS r`   )r�   r9   r‹   r5   r¨   rý  rü  r7   r7   r8   rÝ  E  s   zPolyElement.LTc                 C  s(   | j j}|  ¡ }|dur| | ||< |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

        N)r9   r¨   r�   rÿ  r7   r7   r8   Úleading_termM  s
   zPolyElement.leading_termc                   sL   ˆ d u r	| j j‰ nt ˆ ¡‰ ˆ tu rt|dd„ dd�S t|‡ fdd„dd�S )Nc                 S  s   | d S ré  r7   ©rÑ   r7   r7   r8   rr   h  s    z%PolyElement._sorted.<locals>.<lambda>T)ru   Úreversec                   s   ˆ | d ƒS ré  r7   r  ry   r7   r8   rr   j  rz   )r9   r/   r   r~   r   Úsorted)rª   r^   r/   r7   ry   r8   Ú_sorteda  s   

zPolyElement._sortedc                 C  ó   d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                 S  s   g | ]\}}|‘qS r7   r7   )r<   Ú_rÏ   r7   r7   r8   r>   „  rÒ  z&PolyElement.coeffs.<locals>.<listcomp>©r$  ©rª   r/   r7   r7   r8   rZ   l  ó   zPolyElement.coeffsc                 C  r  )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                 S  s   g | ]\}}|‘qS r7   r7   )r<   rÑ   r  r7   r7   r8   r>   ž  rÒ  z&PolyElement.monoms.<locals>.<listcomp>r  r	  r7   r7   r8   Úmonoms†  r
  zPolyElement.monomsc                 C  s   |   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  rB   rO   r	  r7   r7   r8   r$     r
  zPolyElement.termsc                 C  ó   t |  ¡ ƒS )z,Iterator over coefficients of a polynomial. )ÚiterrC   r®   r7   r7   r8   Ú
itercoeffsº  rÄ   zPolyElement.itercoeffsc                 C  r  )z)Iterator over monomials of a polynomial. )r  r;  r®   r7   r7   r8   r‚  ¾  rÄ   zPolyElement.itermonomsc                 C  r  )z%Iterator over terms of a polynomial. )r  rO   r®   r7   r7   r8   r   Â  rÄ   zPolyElement.itertermsc                 C  r  )z+Unordered list of polynomial coefficients. rA   r®   r7   r7   r8   Ú
listcoeffsÆ  rÄ   zPolyElement.listcoeffsc                 C  r  )z(Unordered list of polynomial monomials. )rB   r;  r®   r7   r7   r8   Ú
listmonomsÊ  rÄ   zPolyElement.listmonomsc                 C  r  )z$Unordered list of polynomial terms. r6  r®   r7   r7   r8   Ú	listtermsÎ  rÄ   zPolyElement.listtermsc                 C  sB   | | j jv r
| | S |s|  ¡  dS | D ]
}| |  |9  < q| 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)r9   r�   Úclear)r  rJ   rã   r7   r7   r8   r«  Ò  s   zPolyElement.imul_numc                 C  s0   | j j}|j}|j}|  ¡ D ]}|||ƒ}q|S )z*Returns GCD of polynomial's coefficients. )r9   r5   r¨   r›   r  )rx   r5   Úcontr›   rÏ   r7   r7   r8   rz  õ  s   zPolyElement.contentc                 C  s,   |   ¡ }|| jjjkr|| fS ||  |¡fS )z,Returns content and a primitive polynomial. )rz  r9   r5   r¨   r´  )rx   r  r7   r7   r8   Ú	primitive   s   zPolyElement.primitivec                 C  s   | s| S |   | j¡S )z5Divides all coefficients by the leading coefficient. )r´  ro  rw   r7   r7   r8   Úmonic  s   zPolyElement.monicc                   s,   ˆ s| j jS ‡ fdd„|  ¡ D ƒ}|  |¡S )Nc                   r+  r7   r7   r(  ©ró  r7   r8   r>     rï   z*PolyElement.mul_ground.<locals>.<listcomp>)r9   r¨   r   r‰   )rx   ró  r$  r7   r  r8   rN    s   
zPolyElement.mul_groundc                   s*   | j j‰‡ ‡fdd„|  ¡ D ƒ}|  |¡S )Nc                   s   g | ]\}}ˆ|ˆ ƒ|f‘qS r7   r7   ©r<   Úf_monomÚf_coeff©rÑ   r�   r7   r8   r>     ó    z)PolyElement.mul_monom.<locals>.<listcomp>)r9   r�   rO   r‰   )rx   rÑ   r$  r7   r  r8   Ú	mul_monom  s   
zPolyElement.mul_monomc                   sZ   |\‰‰ | rˆ s| j jS ˆ| j jkr|  ˆ ¡S | j j‰‡ ‡‡fdd„|  ¡ D ƒ}|  |¡S )Nc                   s"   g | ]\}}ˆ|ˆƒ|ˆ  f‘qS r7   r7   r  ©rÏ   rÑ   r�   r7   r8   r>   #  rP   z(PolyElement.mul_term.<locals>.<listcomp>)r9   r¨   r‹   rN  r�   rO   r‰   )rx   rÛ  r$  r7   r  r8   Úmul_term  s   

zPolyElement.mul_termc                   sl   | j j}ˆs
tdƒ‚| rˆ|jkr| S |jr&|j‰ ‡ ‡fdd„|  ¡ D ƒ}n‡fdd„|  ¡ D ƒ}|  |¡S )Nr±  c                   s   g | ]\}}|ˆ |ˆƒf‘qS r7   r7   r(  ©r¿  ró  r7   r8   r>   0  r  z*PolyElement.quo_ground.<locals>.<listcomp>c                   s$   g | ]\}}|ˆ  s||ˆ  f‘qS r7   r7   r(  r  r7   r8   r>   2  ó   $ )r9   r5   r²  rŽ   r0  r¿  r   r‰   )rx   ró  r5   r$  r7   r  r8   r´  &  s   
zPolyElement.quo_groundc                   sj   ˆ \}}|s
t dƒ‚| s| jjS || jjkr|  |¡S |  ¡ ‰‡ ‡fdd„|  ¡ D ƒ}|  dd„ |D ƒ¡S )Nr±  c                   s   g | ]}ˆ|ˆ ƒ‘qS r7   r7   ©r<   Út©rÛ  rÎ  r7   r8   r>   B  s    z(PolyElement.quo_term.<locals>.<listcomp>c                 S  s   g | ]}|d ur|‘qS r`   r7   r!  r7   r7   r8   r>   C  rF   )r²  r9   r¨   r‹   r´  rÏ  r   r‰   )rx   rÛ  rÑ   rÏ   r$  r7   r#  r8   Úquo_term6  s   
zPolyElement.quo_termc                   sx   | j jjr&g }|  ¡ D ]\}}|ˆ  }|ˆ d kr|ˆ  }| ||f¡ qn‡ fdd„|  ¡ D ƒ}|  |¡}| ¡  |S )Nr…  c                   s   g | ]
\}}||ˆ  f‘qS r7   r7   r(  ©r  r7   r8   r>   Q  rï   z,PolyElement.trunc_ground.<locals>.<listcomp>)r9   r5   Úis_ZZr   r©   r‰   r7  )rx   r  r$  rÑ   rÏ   r­   r7   r%  r8   Útrunc_groundE  s   
ú
zPolyElement.trunc_groundc                 C  sB   | }|  ¡ }|  ¡ }|jj ||¡}| |¡}| |¡}|||fS r`   )rz  r9   r5   r›   r´  )rª   rà  rx   ÚfcÚgcr›   r7   r7   r8   Úextract_groundY  s   


zPolyElement.extract_groundc                   s2   | s| j jjS | j jj‰ |‡ fdd„|  ¡ D ƒƒS )Nc                   s   g | ]}ˆ |ƒ‘qS r7   r7   )r<   rÏ   ©Ú
ground_absr7   r8   r>   j  rÒ  z%PolyElement._norm.<locals>.<listcomp>)r9   r5   r¨   Úabsr  )rx   Ú	norm_funcr7   r+  r8   Ú_norme  s   

zPolyElement._normc                 C  ó
   |   t¡S r`   )r/  rv   rw   r7   r7   r8   Úmax_norml  r½   zPolyElement.max_normc                 C  r0  r`   )r/  rR   rw   r7   r7   r8   Úl1_normo  r½   zPolyElement.l1_normc                 G  sô   | j }| gt|ƒ }dg|j }|D ]}| ¡ D ]}t|ƒD ]\}}t|| |ƒ||< qqqt|ƒD ]
\}}	|	s<d||< q2t|ƒ}tdd„ |D ƒƒrN||fS g }
|D ]#}|j}| 	¡ D ]\}}dd„ t
||ƒD ƒ}||t|ƒ< q[|
 |¡ qR||
fS )Nr   rÂ   c                 s  s   � | ]}|d kV  qdS r~  r7   )r<   rq   r7   r7   r8   re   ƒ  rñ  z&PolyElement.deflate.<locals>.<genexpr>c                 S  s   g | ]\}}|| ‘qS r7   r7   ©r<   r«   r®  r7   r7   r8   r>   Œ  rF   z'PolyElement.deflate.<locals>.<listcomp>)r9   rB   rl   r‚  rð   r   r{   rh   r¨   r   rT   r©   )rx   rÞ  r9   r\   ÚJr  rÑ   r«   rI   rq   ÚHÚhÚIrÏ   ÚNr7   r7   r8   Údeflater  s0   ÿÿ€zPolyElement.deflatec                 C  s>   | j j}|  ¡ D ]\}}dd„ t||ƒD ƒ}||t|ƒ< q|S )Nc                 S  s   g | ]\}}|| ‘qS r7   r7   r3  r7   r7   r8   r>   —  rF   z'PolyElement.inflate.<locals>.<listcomp>)r9   r¨   r   rT   r{   )rx   r4  r­   r7  rÏ   r8  r7   r7   r8   Úinflate“  s
   zPolyElement.inflatec                 C  sb   | }|j j}|js| ¡ \}}| ¡ \}}| ||¡}||  | |¡¡}|js-| |¡S | ¡ S r`   )	r9   r5   r0  r  r™   r¿  r›   rN  r  )rª   rà  rx   r5   r(  r)  rJ   r6  r7   r7   r8   r™   œ  s   
zPolyElement.lcmc                 C  rè  ré  )Ú	cofactors©rx   rà  r7   r7   r8   r›   ¬  rÌ   zPolyElement.gcdc                 C  sà   | s|s| j j}|||fS | s|  |¡\}}}|||fS |s+| | ¡\}}}|||fS t| ƒdkr>|  |¡\}}}|||fS t|ƒdkrQ| | ¡\}}}|||fS |  |¡\}\} }|  |¡\}}}| |¡| |¡| |¡fS rÚ   )r9   r¨   Ú	_gcd_zeror|   Ú
_gcd_monomr9  Ú_gcdr:  )rx   rà  r¨   r6  ÚcffÚcfgr4  r7   r7   r8   r;  ¯  s$   




zPolyElement.cofactorsc                 C  s0   | j j| j j}}|jr|||fS | || fS r`   )r9   rŽ   r¨   ru  )rx   rà  rŽ   r¨   r7   r7   r8   r=  Å  s   
zPolyElement._gcd_zeroc                   s¾   | j }|jj}|jj‰|j}|j‰t|  ¡ ƒd \}}||‰‰ | ¡ D ]\}}|ˆ|ƒ‰|ˆ |ƒ‰ q$|  ˆˆ fg¡}	|  ˆ|ˆƒˆ|ˆ ƒfg¡}
|  ‡ ‡‡‡fdd„| ¡ D ƒ¡}|	|
|fS )Nr   c                   s$   g | ]\}}ˆ|ˆƒˆ|ˆ ƒf‘qS r7   r7   )r<   râ  rã  ©Ú_cgcdÚ_mgcdÚ
ground_quor–   r7   r8   r>   Ù  r   z*PolyElement._gcd_monom.<locals>.<listcomp>)	r9   r5   r›   r¿  rœ   r–   rB   r   r‰   )rx   rà  r9   Ú
ground_gcdrœ   ÚmfÚcfrâ  rã  r6  r@  rA  r7   rB  r8   r>  Ì  s   

"
zPolyElement._gcd_monomc                 C  s6   | j }|jjr|  |¡S |jjr|  |¡S | | |¡S r`   )r9   r5   Úis_QQÚ_gcd_QQr&  Ú_gcd_ZZÚdmp_inner_gcd)rx   rà  r9   r7   r7   r8   r?  Ü  s   

zPolyElement._gcdc                 C  s
   t | |ƒS r`   r   r<  r7   r7   r8   rK  æ  r½   zPolyElement._gcd_ZZc                 C  s°   | }|j }|j|j ¡ d�}| ¡ \}}| ¡ \}}| |¡}| |¡}| |¡\}}}	| |¡}|j| ¡ }
}| |¡ 	|j 
|
|¡¡}|	 |¡ 	|j 
|
|¡¡}	|||	fS )Nrô   )r9   rÀ   r5   r2  r5  r%  rK  ro  r  rN  r¿  )rª   rà  rx   r9   r#  rH  rã  r6  r@  rA  rJ   r7   r7   r8   rJ  é  s   



zPolyElement._gcd_QQc                 C  s  | }|j }|s||jfS |j}|jr|js| |¡\}}}nD|j| ¡ d�}| ¡ \}	}| ¡ \}
}| 	|¡}| 	|¡}| |¡\}}}|j |
|	¡\}}
}	| 	|¡}| 	|¡}| 
|
¡}| 
|	¡}| ¡ }||jkrp	 ||fS ||j kr�| | }}||fS | 
|¡}| 
|¡}||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ô   )r9   rŽ   r5   r0  r1  r;  rÀ   r2  r5  r%  rN  Úcanonical_unit)rª   rà  rx   r9   r5   r  r  rê  r#  ÚcqÚcpÚur7   r7   r8   Úcancelþ  s8   







ú
ý
zPolyElement.cancelc                 C  s   | j j}| | j¡S r`   )r9   r5   rM  ro  )rx   r5   r7   r7   r8   rM  6	  s   zPolyElement.canonical_unitc           	      C  s`   | j }| |¡}| |¡}|j}|  ¡ D ]\}}|| r-| ||¡}| |||  ¡||< q|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

        )r9   ré   r§   r¨   r   r–   rË   )	rx   ró  r9   r«   rI   rà  r¬   rÏ   Úer7   r7   r8   Údiff:	  s   

€zPolyElement.diffc                 G  sP   dt |ƒ  k r| jjkrn n|  tt| jj|ƒƒ¡S td| jjt |ƒf ƒ‚)Nr   z1expected at least 1 and at most %s values, got %s)r|   r9   rl   ÚevaluaterB   rT   r3   rÖ   )rx   rC   r7   r7   r8   r  S	  s    zPolyElement.__call__c                   s@  | }t |tƒr0|d u r0|d |dd … \‰ }}| ˆ |¡}|s"|S ‡ fdd„|D ƒ}| |¡S |j}| |¡}|j |¡}|jdkr[|jj}| 	¡ D ]\\}}||||  7 }qK|S | 
|¡j}	| 	¡ D ]8\}
}|
| |
d |… |
|d d …  }}
|||  }|
|	v r—||	|
  }|r“||	|
< qe|	|
= qe|r�||	|
< qe|	S )Nr   rÂ   c                   s   g | ]\}}|  ˆ ¡|f‘qS r7   )rò   )r<   ÚYrp   ©ÚXr7   r8   r>   c	  r  z(PolyElement.evaluate.<locals>.<listcomp>)ra   rB   rT  r9   ré   r5   rÈ   rl   r¨   r   rò   )rª   ró  rp   rx   r9   r«   Úresultr  rÏ   r­   rÑ   r7   rV  r8   rT  Y	  s:   


&
€zPolyElement.evaluatec                 C  s  | }t |tƒr|d u r|D ]
\}}| ||¡}q|S |j}| |¡}|j |¡}|jdkrH|jj}| 	¡ D ]\\}}	||	||  7 }q5| 
|¡S |j}
| 	¡ D ]:\}}	|| |d |… d ||d d …  }}|	||  }	||
v rƒ|	|
|  }	|	r|	|
|< qO|
|= qO|	r‰|	|
|< qO|
S )NrÂ   rm   )ra   rB   Úsubsr9   ré   r5   rÈ   rl   r¨   r   rÐ   )rª   ró  rp   rx   rW  r9   r«   rX  r  rÏ   r­   rÑ   r7   r7   r8   rY  …	  s4   


*
€zPolyElement.subsc                   s†  |   ¡ }|j‰ˆj}|s|ˆjg fS ‡fdd„t|ƒD ƒ‰i ‰‡‡fdd„}tt|d ƒƒ}tt|ddƒƒ}ˆj}|r¶d\}}}	t| ¡ ƒD ])\}
\‰ }t‡ fd	d
„|D ƒƒrot	dd
„ t
|ˆ ƒD ƒƒ}||kro|ˆ |}}}	qF|dkrz||	‰ }nn;g }t
ˆ ˆ dd… d ƒD ]\}}| || ¡ qˆ|ˆ t|ƒ|¡7 }|}t|ƒD ]\}
}|||
|ƒ9 }q¤||8 }|s;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                   s   g | ]	}ˆ   |d  ¡‘qS )rÂ   )r  r  rÐ  r7   r8   r>   î	  rN   z*PolyElement.symmetrize.<locals>.<listcomp>c                   s,   | |fˆ vrˆ|  | ˆ | |f< ˆ | |f S r`   r7   )r«   r  )Úpoly_powersr\   r7   r8   Úget_poly_powerñ	  s   z.PolyElement.symmetrize.<locals>.get_poly_powerrÂ   r   rè   )rè   NNc                 3  s$   � | ]}ˆ | ˆ |d   kV  qdS r~  r7   r  r  r7   r8   re   ÿ	  s   €" z)PolyElement.symmetrize.<locals>.<genexpr>c                 s  s   � | ]	\}}|| V  qd S r`   r7   )r<   r  rI   r7   r7   r8   re    
  r  Nrm   )r³   r9   rl   r¨   r¦   rB   rð   r$  rh   rv   rT   r©   rÎ   r{   r3   )rª   rx   r  r[  rî   ÚweightsÚ	symmetricÚ_heightÚ_monomÚ_coeffr«   rÏ   ÚheightÚ	exponentsrä  Úm2Úproductræ   r7   )rÑ   rZ  r\   r9   r8   Ú
symmetrize¬	  sB   ;
€è
zPolyElement.symmetrizec                   s  | j }|j}tt|jt|jƒƒƒ‰ |d ur||fg}n t|tƒr%t|ƒ}nt|tƒr7t	| 
¡ ‡ fdd„d�}ntdƒ‚t|ƒD ]\}\}}ˆ | | |¡f||< q?|  ¡ D ]0\}}	t|ƒ}|j}
|D ]\}}|| d}||< |rw|
|| 9 }
qb|
 t|ƒ|	f¡}
||
7 }qU|S )Nc                   s   ˆ | d  S ré  r7   )r,  ©Úgens_mapr7   r8   rr   $
  rz   z%PolyElement.compose.<locals>.<lambda>rt   z9expected a generator, value pair a sequence of such pairsr   )r9   r¨   rS   rT   r3   r¦   rl   ra   rB   r  rO   rÖ   rð   rÙ   r   rŽ   r  r{   )rx   ró  rp   r9   r­   Úreplacementsr,  rà  rÑ   rÏ   Úsubpolyr«   r  r7   rf  r8   r  
  s.   


€
zPolyElement.composec                   sh   | }|j  |¡‰‡ ‡fdd„| ¡ D ƒ}|s|j jS t|Ž \}}‡fd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                   s$   g | ]\}}|ˆ ˆ kr||f‘qS r7   r7   rH   ©Údegr«   r7   r8   r>   e
  r   z)PolyElement.coeff_wrt.<locals>.<listcomp>c                   s,   g | ]}|d ˆ … d |ˆ d d …  ‘qS )Nrm   rÂ   r7   )r<   rI   rð  r7   r8   r>   k
  s   , )r9   ré   r   r¨   rT   rU   rS   )rª   ró  rk  r  r$  r  rZ   r7   rj  r8   Ú	coeff_wrt9
  s   *zPolyElement.coeff_wrtc                 C  sÔ   | }|j  |¡}| |¡}| |¡}|dk rtdƒ‚||}}||k r%|S || d }| ||¡}	|j j| }
	 | ||¡}|| |d }}||	 }|| |
|  }|| }| |¡}||k ranq8|	| }|| 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 difference between prem and rem
        x**2 + x*y
        >>> f.prem(g, y) # generator is given
        0
        >>> f.prem(g, 1) # generator index is given
        0

        See Also
        ========

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

        r   r±  rÂ   ©r9   ré   rô  r²  rl  r3   )rª   rà  ró  rx   ÚdfÚdgrØ  Údrr8  Úlc_gÚxpÚlc_rr®  ÚRrÞ  rJ   r7   r7   r8   Úpremn
  s0   6



ôzPolyElement.premc                 C  s  | }|j  |¡}| |¡}| |¡}|dk rtdƒ‚|||}}}||k r*||fS || d }	| ||¡}
|j j| }	 | ||¡}|| |	d }}	||
 }||||   }||
 }|| ||  }|| }| |¡}||k rrnq=|
|	 }|| }|| }||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Â   rm  )rª   rà  ró  rx   rn  ro  rê  rØ  rp  r8  rq  rr  rs  r®  ÚQrt  rÞ  rJ   r7   r7   r8   ÚpdivÉ
  s8   P


îzPolyElement.pdivc                 C  s   | }|  ||¡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   )rw  )rª   rà  ró  rx   r7   r7   r8   ÚpquoG  s   zPolyElement.pquoc                 C  s(   | }|  ||¡\}}|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 difference between pexquo and exquo
        Traceback (most recent call last):
        ...
        ExactQuotientFailed: 2*x + 2*y does not divide x**2 + x*y
        >>> f.pexquo(h)
        Traceback (most recent call last):
        ...
        ExactQuotientFailed: 2*x + 2 does not divide x**2 + x*y

        See Also
        ========

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

        )rw  rw  r#   )rª   rà  ró  rx   rê  rØ  r7   r7   r8   Úpexquoe  s
   
zPolyElement.pexquoc                 C  sV  | }|j  |¡}| |¡}| |¡}||k r ||}}||}}|dkr(ddgS |dkr0|dgS ||g}|| }d|d  }| ||¡}	|	| }	| ||¡}
|
| }d|g}| }|	r©|	 |¡}| |	¡ ||	||| f\}}}}|
 ||  }| ||¡}	|	 |¡}	| ||¡}
|dkrž|
 | }||d  }| |¡}n|
 }| | ¡ |	s[|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è   )r9   ré   rô  ru  rl  r©   rÃ  )rª   rà  ró  rx   r  rI   rt  Údrq   r6  ÚlcrJ   ÚSr,  r  rê  r7   r7   r8   ÚsubresultantsŠ  sH   "







ízPolyElement.subresultantsc                 C  ó   | j  | |¡S r`   )r9   Údmp_half_gcdexr<  r7   r7   r8   Ú
half_gcdexç  rÌ   zPolyElement.half_gcdexc                 C  r~  r`   )r9   Ú	dmp_gcdexr<  r7   r7   r8   Úgcdexê  rÌ   zPolyElement.gcdexc                 C  r~  r`   )r9   Údmp_resultantr<  r7   r7   r8   Ú	resultantí  rÌ   zPolyElement.resultantc                 C  ó   | j  | ¡S r`   )r9   Údmp_discriminantrw   r7   r7   r8   Údiscriminantð  rE  zPolyElement.discriminantc                 C  rŽ  )Nzpolynomial decomposition)r9   rý   Údup_decomposer$   rw   r7   r7   r8   Ú	decomposeó  ó   zPolyElement.decomposec                 C  s   | j jr| j  | |¡S tdƒ‚)Nzshift: use shift_list instead)r9   rý   Ú	dup_shiftr$   ©rx   rp   r7   r7   r8   Úshiftù  s   zPolyElement.shiftc                 C  r~  r`   )r9   Ú	dmp_shiftrŒ  r7   r7   r8   Ú
shift_listÿ  rÌ   zPolyElement.shift_listc                 C  rŽ  )Nzsturm sequence)r9   rý   Ú	dup_sturmr$   rw   r7   r7   r8   Ústurm  rŠ  zPolyElement.sturmc                 C  r…  r`   )r9   Údmp_gff_listrw   r7   r7   r8   Úgff_list  rE  zPolyElement.gff_listc                 C  r…  r`   )r9   Údmp_normrw   r7   r7   r8   Únorm  rE  zPolyElement.normc                 C  r…  r`   )r9   Údmp_sqf_normrw   r7   r7   r8   Úsqf_norm  rE  zPolyElement.sqf_normc                 C  r…  r`   )r9   Údmp_sqf_partrw   r7   r7   r8   Úsqf_part  rE  zPolyElement.sqf_partFc                 C  s   | j j| |d�S )N)rh   )r9   Údmp_sqf_list)rx   rh   r7   r7   r8   Úsqf_list  r°   zPolyElement.sqf_listc                 C  r…  r`   )r9   Údmp_factor_listrw   r7   r7   r8   Úfactor_list  rE  zPolyElement.factor_listr`   )F)›r€   r  r  r  r  r  r‰   r  r¯   r‡   r·   r³   r%  r'  r&  r5  r7  rº   r¼   r<  r?  rB  rD  rF  rG  rH  rJ  rò   rM  r  rP  rR  rb   r  rn  rK  rp  rq  r[  rt  ru  rv  rw  rx  ry  r{  rƒ  r†  rŠ  r�  r�  r‘  r’  r•  r“  r—  r–  rž  r˜  r¥  r¤  r£  r¢  r·  r³  r½  r¼  rÁ  rÂ  rÄ  rÀ  rÏ  r—   r»  r¿  rÃ  rÓ  rÔ  rô  r÷  rú  rû  r�   rý  rÏ   r=  ro  rþ  r   rÝ  r  r  rZ   r  r$  r  r‚  r   r  r  r  r«  rz  r  r  rN  r  r  r´  r$  r'  rµ  r*  r/  r1  r2  r9  r:  r™   r›   r;  r=  r>  r?  rK  rJ  rQ  rM  rS  r  rT  rY  re  r  rl  ru  rw  rx  ry  r}  r€  r‚  r„  r‡  r‰  r�  r�  r‘  r“  r•  r—  r™  r›  r�  Ú__classcell__r7   r7   r  r8   rˆ   J  sV   
	0
















6646%				!L-,%%


#!	
8,'m 5[~%]rˆ   N)r/   r0   )Qr  Ú
__future__r   Úoperatorr   r   r   r   r   r   Ú	functoolsr	   Útypesr
   Úsympy.core.cacher   Úsympy.core.exprr   Úsympy.core.intfuncr   Úsympy.core.symbolr   r   rg   Úsympy.core.sympifyr   r   Úsympy.ntheory.multinomialr   Úsympy.polys.compatibilityr   Úsympy.polys.constructorr   Úsympy.polys.densebasicr   r   r   Úsympy.polys.domains.domainr   Ú!sympy.polys.domains.domainelementr   Ú"sympy.polys.domains.polynomialringr   Úsympy.polys.heuristicgcdr   Úsympy.polys.monomialsr   Úsympy.polys.orderingsr   r    Úsympy.polys.polyerrorsr!   r"   r#   r$   Úsympy.polys.polyoptionsr}   r%   r   r&   Úsympy.polys.polyutilsr'   r(   r)   Úsympy.printing.defaultsr*   Úsympy.utilitiesr+   r,   Úsympy.utilities.iterablesr-   Úsympy.utilities.magicr.   r9   r:   r@   r]   rj   r2   rS   rˆ   r7   r7   r7   r8   Ú<module>   sR     
4   	