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   úb/var/www/html/academy/tools/voices/clone/sv-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©Z	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_   )r`   r   rb   r7   r7   r8   rd   ¾   re   zbexpected a string, Symbol or expression or a non-empty sequence of strings, Symbols or expressions)r`   ra   Ú_symbolsr   r-   Úallr"   ©r   r7   r7   r8   Ú_parse_symbols¶   s   

ri   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  rm   rn   r7   )ro   rp   rJ   r7   r7   r8   rq   ö   rr   c                   s   t | ˆ d�S )N©Úkey)Úmax©Úf©r/   r7   r8   rq      ó    )4Útupleri   ÚlenÚ	DomainOptÚ
preprocessÚOrderOptÚ__name__Úis_CompositeÚsetr   r"   ÚobjectÚ__new__Ú_hash_tupleÚhashÚ_hashrk   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   ru   Úleading_expvrS   r`   r   r;   ÚhasattrÚsetattr)Úclsr   r5   r/   rk   r„   ÚobjÚcodegenZmonunitÚsymbolÚ	generatorr;   r7   rx   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�   Úrangerk   Úmonomial_basisÚzeroÚappendrz   )Ú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œ   Z	monomial_)Ú__dict__ÚcopyÚ
startswith)r¨   Ústatert   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_   )r`   r2   r   r5   rk   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_   )r`   rB   rz   Ú_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   é   )rk   rz   )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. )r`   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)r`   r‡   r9   r5   r   rÍ   ÚNotImplementedErrorra   rR   rT   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¦   rN   )r¨   rÃ   rÇ   rÈ   r«   rÎ   rÌ   r7   r7   r8   rT   o  s   
€zPolyRing.from_dictc                 C  s   |   t|ƒ|¡S r_   )rT   rR   rÆ   r7   r7   r8   rÒ   z  r®   zPolyRing.from_termsc                 C  s   |   t|| jd | jƒ¡S ©Nr¿   )rT   r   rk   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   rP   ÚargsÚis_Mulr   Úas_base_expÚ
is_Integerrj   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)	rR   rB   rS   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)	rk   r`   rj   rÓ   rÄ   r3   Úindexra   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©   rc   ©Úindicesr7   r8   r>   Ã  ó    z!PolyRing.drop.<locals>.<listcomp>rh   )r�   rP   ræ   Ú	enumerater   r5   r½   ©r¨   r3   r   r7   rê   r8   ÚdropÀ  s
   zPolyRing.dropc                 C  s    | j | }|s
| jS | j|d�S )Nrh   )r   r5   r½   )r¨   rt   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�   rP   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``rh   ©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``rh   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_   )rj   ©r<   r©   ©rc   r7   r8   rd   E  ó   € z*PolyRing.symmetric_poly.<locals>.<genexpr>)rk   rÓ   r3   r�   r¦   r,   r¤   rj   rz   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__rT   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)r`   rj   )r<   rà   r7   r7   r8   rd   [  s   €  z%PolyElement._check.<locals>.<genexpr>)r`   r‡   r9   r2   r5   r   rN   Úof_typer{   rk   rg   )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   Ú	frozensetrN   )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   rS   r(   rÒ   r5   rT   )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{   rk   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   rL   ¥  rM   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ˆ   rN   )r¨   r5   Zground_ringr˜   r0  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   rN   )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Ä   rR   r·   r{   rØ   rŠ   ©Úp1Úp2r7   r7   r8   r·   ¾  s   zPolyElement.__eq__c                 C  r¸   r_   r7   r4  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)r5  r6  Ú	tolerancer9   r8  r)  r7   r7   r8   r8  Û  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)r5  r6  Úopr7   r7   r8   Ú_cmpö  s   zPolyElement._cmpc                 C  ó   |   |t¡S r_   )r>  r   r4  r7   r7   r8   Ú__lt__ü  ó   zPolyElement.__lt__c                 C  r?  r_   )r>  r   r4  r7   r7   r8   Ú__le__þ  rA  zPolyElement.__le__c                 C  r?  r_   )r>  r   r4  r7   r7   r8   Ú__gt__   rA  zPolyElement.__gt__c                 C  r?  r_   )r>  r   r4  r7   r7   r8   Ú__ge__  rA  zPolyElement.__ge__c                 C  sD   | j }| |¡}|jdkr||jfS t|jƒ}||= ||j|d�fS )Nr¿   rh   )r9   ræ   rk   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   )
rF  r9   rk   Ú	is_groundrÌ   rÓ   r¦   rN   rB   rz   )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½   rE  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   rk   rÓ   rI  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   rk   r5   r¬   r7   r7   r8   Úto_dense>  ó   zPolyElement.to_densec                 C  ró   r_   )rR   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)rR  rQ  )Ú_printr9   r5   r¦   r   rk   rŠ   r!  Úis_negativer§   r±   r�   Úparenthesizer¤   rj   ÚjoinÚpopÚinsert)r¨   ÚprinterÚ
precedenceZexp_patternZ
mul_symbolZprec_mulZ	prec_atomr9   r   rk   ÚzmZsexpvsrª   rÌ   ÚnegativeÚsignZscoeffZsexpvr©   rà   r¢   ÚsexpÚheadr7   r7   r8   ra   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   rG  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   rW  rd  r¬   r7   r7   r8   rW  „  ó   zPolyElement.is_negativec                 C  rg  r_   )r9   r5   Úis_positiverd  r¬   r7   r7   r8   ri  ˆ  rh  zPolyElement.is_positivec                 C  rg  r_   )r9   r5   Úis_nonnegativerd  r¬   r7   r7   r8   rj  Œ  rh  zPolyElement.is_nonnegativec                 C  rg  r_   )r9   r5   Úis_nonpositiverd  r¬   r7   r7   r8   rk  �  rh  zPolyElement.is_nonpositivec                 C  s   |  S r_   r7   rv   r7   r7   r8   Úis_zero”  s   zPolyElement.is_zeroc                 C  s   | | j jkS r_   )r9   r�   rv   r7   r7   r8   Úis_one˜  rÁ   zPolyElement.is_onec                 C  rg  r_   )r9   r5   rm  rd  rv   r7   r7   r8   Úis_monicœ  rh  zPolyElement.is_monicc                 C  s   | j j |  ¡ ¡S r_   )r9   r5   rm  Úcontentrv   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©rQ   ©r<   rÎ   r7   r7   r8   rd   ¦  r  z(PolyElement.is_linear.<locals>.<genexpr>©rg   Ú
itermonomsrv   r7   r7   r8   Ú	is_linear¤  ó   zPolyElement.is_linearc                 C  rq  )Nc                 s  rr  )é   Nrt  ru  r7   r7   r8   rd   ª  r  z+PolyElement.is_quadratic.<locals>.<genexpr>rv  rv   r7   r7   r8   Úis_quadratic¨  ry  zPolyElement.is_quadraticc                 C  ó   | j jsdS | j  | ¡S ©NT)r9   rk   Ú	dmp_sqf_prv   r7   r7   r8   Úis_squarefree¬  ó   zPolyElement.is_squarefreec                 C  r|  r}  )r9   rk   Údmp_irreducible_prv   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$   rv   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>   À  rM   z'PolyElement.__neg__.<locals>.<listcomp>)rˆ   r  r¬   r7   r7   r8   Ú__neg__¿  rM  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¦   rN   r`   r‡   r   Ú__radd__r<  rÈ   r!   rŠ   r7  )
r5  r6  r9   r  rØ   r¦   r)  r*  Úcp2r^  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Š   r7  )r5  r  r  r9   r^  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¦   rN   r`   r‡   r   Ú__rsub__r<  rÈ   r!   rŠ   r7  )	r5  r6  r9   r  rØ   r¦   r)  r*  r^  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¦   )r5  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   rN   r3  r`   r‡   r   Ú__rmul__r<  rÈ   r!   )r5  r6  r9   r  rØ   r¦   r�   Z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<  rN   )r5  r6  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 exponentrz  é   é   )r`   rj   Ú	TypeErrorrÓ   r9   r�   r{   rB   rN   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¿   rz  )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{   rN   r9   r“   rŠ   r5   r¦   rS   rz   rØ   )r¨   r  Zmultinomialsr“   rŠ   r!  r¦   r«   ÚmultinomialZmultinomial_coeffZproduct_monomZ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

        rz  )r9   r¦   rØ   rB   r7  r5   r�   r¤   r{   Úimul_numrN   r3  )r¨   r9   r  rØ   r7  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–   r`   r‡   r5   r   Ú__rdivmod__r<  rÈ   r!   Ú
quo_groundÚ
rem_ground©r5  r6  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Ä   Úremr`   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Ä   Úquor`   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Ä   Úexquor`   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   ©Z	a_lm_a_lcZ	b_lm_b_lcÚa_lmÚa_lcÚb_lmÚb_lcrÎ   ©Z
domain_quor—   r^  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—   r-  )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   r`   r‡   rg   r¢  r¦   rÓ   r{   r¤   r°   r¼  rœ   Ú_iadd_monomÚ_iadd_poly_monomrŠ   )r¨   ÚfvZ
ret_singlerw   rc   Zqvr  Úrr»  Zexpvsr©   Zdivoccurredrª   ÚtermZ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   )r`   r‡   rg   r¢  r9   r5   r¦   r�   r¼  ÚLTr°   rØ   r  rœ   )r¨   ÚGrw   r9   r5   r¦   r�   rÃ  r»  ÚltfrØ   ÚgÚtqrI   rJ   ÚmgÚcgÚm1Úc1ÚltmZltcr7   r7   r8   r«  #  sP   


óæzPolyElement.remc                 C  ó   |   |¡d S ©Nr   )r–   )rw   rÆ  r7   r7   r8   r¯  P  rÉ   zPolyElement.quoc                 C  s    |   |¡\}}|s|S t| |ƒ‚r_   )r–   r#   )rw   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¨   ÚmcZ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�   rN   )r¨   r6  rÒ  r5  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   ru  ©r©   r7   r8   rd   º  ó   € z%PolyElement.degree.<locals>.<genexpr>)r9   ræ   r   ru   rw  ©rw   Ú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   rk   rz   rP   ru   rB   rS   rw  rv   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   ru  rÖ  r7   r8   rd   Ö  r×  z*PolyElement.tail_degree.<locals>.<genexpr>)r9   ræ   r   Úminrw  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   rk   rz   rP   rß  rB   rS   rw  rv   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   r9     rû   zPolyElement.constc                 C  s   |   |  ¡ ¡S r_   )rã  rœ   r¬   r7   r7   r8   rd  $  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   rq   h  s    z%PolyElement._sorted.<locals>.<lambda>T)rt   Úreversec                   s   ˆ | d ƒS rÐ  r7   rè  rx   r7   r8   rq   j  ry   )r9   r/   r~   r}   r   Úsorted)r¨   r]   r/   r7   rx   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   rY   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   rN   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ó  r7  r¬   r7   r7   r8   rw  ¾  rÁ   zPolyElement.itermonomsc                 C  rò  )z%Iterator over terms of a polynomial. )ró  rN   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   r7  r¬   r7   r7   r8   Ú
listmonomsÊ  rÁ   zPolyElement.listmonomsc                 C  rò  )z$Unordered list of polynomial terms. r2  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ô  )rw   r5   Úcontrš   rÌ   r7   r7   r8   ro  õ  s   zPolyElement.contentc                 C  s,   |   ¡ }|| jjjkr|| fS ||  |¡fS )z,Returns content and a primitive polynomial. )ro  r9   r5   r¦   r¤  )rw   rù  r7   r7   r8   Ú	primitive   s   zPolyElement.primitivec                 C  s   | s| S |   | j¡S )z5Divides all coefficients by the leading coefficient. )r¤  rd  rv   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ˆ   )rw   rÙ  r!  r7   rü  r8   rJ    s   
zPolyElement.mul_groundc                   s*   | j j‰‡ ‡fdd„|  ¡ D ƒ}|  |¡S )Nc                   s   g | ]\}}ˆ|ˆ ƒ|f‘qS r7   r7   ©r<   Úf_monomZf_coeff©rÎ   r�   r7   r8   r>     ó    z)PolyElement.mul_monom.<locals>.<listcomp>)r9   r�   rN   rˆ   )rw   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>   #  rO   z(PolyElement.mul_term.<locals>.<listcomp>)r9   r¦   rŠ   rJ  r�   rN   rˆ   )rw   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�   r-  r¯  r  rˆ   )rw   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ˆ   )rw   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 )Nrz  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ˆ   r3  )rw   r  r!  rÎ   rÌ   r«   r7   r
  r8   Útrunc_groundE  s   
ú
zPolyElement.trunc_groundc                 C  sB   | }|  ¡ }|  ¡ }|jj ||¡}| |¡}| |¡}|||fS r_   )ro  r9   r5   rš   r¤  )r¨   rÈ  rw   Ú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Ì   ©Z
ground_absr7   r8   r>   j  r¿  z%PolyElement._norm.<locals>.<listcomp>)r9   r5   r¦   Úabsrô  )rw   Z	norm_funcr7   r  r8   Ú_norme  s   

zPolyElement._normc                 C  ó
   |   t¡S r_   )r  ru   rv   r7   r7   r8   Úmax_norml  rº   zPolyElement.max_normc                 C  r  r_   )r  rQ   rv   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 rs  r7   )r<   rp   r7   r7   r8   rd   ƒ  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   rk   rw  rí   r   rz   rg   r¦   r  rS   r§   )rw   rÆ  r9   r[   ÚJr  rÎ   r©   rI   rp   Ú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   r  r7   r7   r8   r>   —  rF   z'PolyElement.inflate.<locals>.<listcomp>)r9   r¦   r  rS   rz   )rw   r  r«   r  rÌ   r  r7   r7   r8   Úinflate“  s
   zPolyElement.inflatec                 C  sb   | }|j j}|js| ¡ \}}| ¡ \}}| ||¡}||  | |¡¡}|js-| |¡S | ¡ S r_   )	r9   r5   r-  rú  r˜   r¯  rš   rJ  rû  )r¨   rÈ  rw   r5   r  r  rJ   r  r7   r7   r8   r˜   œ  s   
zPolyElement.lcmc                 C  rÏ  rÐ  )Ú	cofactors©rw   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_monomr  Ú_gcdr  )rw   rÈ  r¦   r  ÚcffÚcfgr  r7   r7   r8   r  ¯  s$   




zPolyElement.cofactorsc                 C  s0   | j j| j j}}|jr|||fS | || fS r_   )r9   r�   r¦   rj  )rw   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Ë  ©Z_cgcdZ_mgcdZ
ground_quor•   r7   r8   r>   Ù  r  z*PolyElement._gcd_monom.<locals>.<listcomp>)	r9   r5   rš   r¯  r›   r•   rB   r  rˆ   )rw   rÈ  r9   Z
ground_gcdr›   ÚmfÚcfrÊ  rË  r  r#  r$  r7   r%  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)rw   rÈ  r9   r7   r7   r8   r"  Ü  s   

zPolyElement._gcdc                 C  s
   t | |ƒS r_   r   r  r7   r7   r8   r*  æ  rº   zPolyElement._gcd_ZZc                 C  s°   | }|j }|j|j ¡ d�}| ¡ \}}| ¡ \}}| |¡}| |¡}| |¡\}}}	| |¡}|j| ¡ }
}| |¡ 	|j 
|
|¡¡}|	 |¡ 	|j 
|
|¡¡}	|||	fS )Nrñ   )r9   r½   r5   r/  r1  r"  r*  rd  rû  rJ  r¯  )r¨   rÈ  rw   r9   r   r'  rË  r  r#  r$  rJ   r7   r7   r8   r)  é  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   r-  r.  r  r½   r/  r1  r"  rJ  Úcanonical_unit)r¨   rÈ  rw   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   r,  rd  )rw   r5   r7   r7   r8   r,  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È   )	rw   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   rk   ÚevaluaterB   rS   r3   rÓ   )rw   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<   ÚYro   ©ÚXr7   r8   r>   c	  r   z(PolyElement.evaluate.<locals>.<listcomp>)r`   rB   r3  r9   ræ   r5   rÅ   rk   r¦   r  rï   )r¨   rÙ  ro   rw   r9   r©   Úresultr  rÌ   r«   rÎ   r7   r5  r8   r3  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¿   rl   )r`   rB   Úsubsr9   ræ   r5   rÅ   rk   r¦   r  rÍ   )r¨   rÙ  ro   rw   r6  r9   r©   r7  r  rÌ   r«   rÎ   r7   r7   r8   r8  …	  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>   î	  rM   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 rs  r7   r
  rè  r7   r8   rd   ÿ	  s   €" z)PolyElement.symmetrize.<locals>.<genexpr>c                 s  s   � | ]	\}}|| V  qd S r_   r7   )r<   r  rI   r7   r7   r8   rd    
  r  Nrl   )r°   r9   rk   r¦   r¤   rB   rí   r!  rg   ru   rS   r§   rË   rz   r3   )r¨   rw   r  r:  rë   ÚweightsÚ	symmetricÚ_heightZ_monomÚ_coeffr©   rÌ   ÚheightÚ	exponentsrÌ  Úm2Úproductrã   r7   )rÎ   r9  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)  ©Zgens_mapr7   r8   rq   $
  ry   z%PolyElement.compose.<locals>.<lambda>rs   z9expected a generator, value pair a sequence of such pairsr   )r9   r¦   rR   rS   r3   r¤   rk   r`   rB   rê  rN   rÓ   rí   rÖ   r  r�   r  rz   )rw   rÙ  ro   r9   r«   Úreplacementsr)  rÈ  rÎ   rÌ   Zsubpolyr©   r  r7   rD  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 )Nrl   r¿   r7   )r<   rI   rÖ  r7   r8   r>   k
  s   , )r9   ræ   r  r¦   rS   rT   rR   )r¨   rÙ  rG  r  r!  rñ  rY   r7   rF  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¢  rH  r3   )r¨   rÈ  rÙ  rw   ÚdfÚdgrÃ  Údrr  Ú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¿   rI  )r¨   rÈ  rÙ  rw   rJ  rK  rÑ  rÃ  rL  r  rM  rN  rO  rž  ÚQrP  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   )rS  )r¨   rÈ  rÙ  rw   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

        )rS  rl  r#   )r¨   rÈ  rÙ  rw   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Ú  rQ  rH  r§   r³  )r¨   rÈ  rÙ  rw   r  rI   rP  Údrp   r  Ú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  rZ  r_   )r9   Ú	dmp_gcdexr  r7   r7   r8   Úgcdexê  rÉ   zPolyElement.gcdexc                 C  rZ  r_   )r9   Údmp_resultantr  r7   r7   r8   Ú	resultantí  rÉ   zPolyElement.resultantc                 C  ó   | j  | ¡S r_   )r9   Údmp_discriminantrv   r7   r7   r8   Údiscriminantð  rA  zPolyElement.discriminantc                 C  rƒ  )Nzpolynomial decomposition)r9   rú   Údup_decomposer$   rv   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$   ©rw   ro   r7   r7   r8   Úshiftù  s   zPolyElement.shiftc                 C  rZ  r_   )r9   Ú	dmp_shiftrh  r7   r7   r8   Ú
shift_listÿ  rÉ   zPolyElement.shift_listc                 C  rƒ  )Nzsturm sequence)r9   rú   Ú	dup_sturmr$   rv   r7   r7   r8   Ústurm  rf  zPolyElement.sturmc                 C  ra  r_   )r9   Údmp_gff_listrv   r7   r7   r8   Úgff_list  rA  zPolyElement.gff_listc                 C  ra  r_   )r9   Údmp_normrv   r7   r7   r8   Únorm  rA  zPolyElement.normc                 C  ra  r_   )r9   Údmp_sqf_normrv   r7   r7   r8   Úsqf_norm  rA  zPolyElement.sqf_normc                 C  ra  r_   )r9   Údmp_sqf_partrv   r7   r7   r8   Úsqf_part  rA  zPolyElement.sqf_partFc                 C  s   | j j| |d�S )N)rg   )r9   Údmp_sqf_list)rw   rg   r7   r7   r8   Úsqf_list  r®   zPolyElement.sqf_listc                 C  ra  r_   )r9   Údmp_factor_listrv   r7   r7   r8   Úfactor_list  rA  zPolyElement.factor_listr_   )F)›r   r  r  r  r  r  rˆ   r  r­   r†   r´   r°   r"  r$  r#  r1  r3  r·   r¹   r8  r;  r>  r@  rB  rC  rD  rF  rï   rI  r  rL  rN  ra   r  rc  rG  re  rf  rW  ri  rj  rk  rl  rm  rn  rp  rx  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Ì   r9  rd  rä  ræ  rÅ  rç  rë  rY   rñ  r!  rô  rw  r  rõ  rö  r÷  r›  ro  rú  rû  rJ  r  r  r¤  r	  r  r¥  r  r  r  r  r  r  r˜   rš   r  r   r!  r"  r*  r)  r0  r,  r2  r  r3  r8  rC  r  rH  rQ  rS  rT  rU  rY  r\  r^  r`  rc  re  ri  rk  rm  ro  rq  rs  ru  rw  ry  Ú__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   Zsympy.core.intfuncr   Úsympy.core.symbolr   r   rf   Úsympy.core.sympifyr   r   Úsympy.ntheory.multinomialr   Zsympy.polys.compatibilityr   Úsympy.polys.constructorr   Úsympy.polys.densebasicr   r   r   Zsympy.polys.domains.domainr   Ú!sympy.polys.domains.domainelementr   Ú"sympy.polys.domains.polynomialringr   Z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)   Zsympy.printing.defaultsr*   Úsympy.utilitiesr+   r,   Úsympy.utilities.iterablesr-   Zsympy.utilities.magicr.   r9   r:   r@   r\   ri   r2   rR   r‡   r7   r7   r7   r8   Ú<module>   sR     
4   	