U
     ‹ÑhîF ã                   @  sò  U d Z ddlmZ ddlmZ ddlmZmZmZm	Z	m
Z
mZ ddlmZ ddlmZ ddlmZ ddlmZ dd	lmZmZ dd
lmZmZ ddlmZ ddlmZ ddlm Z  ddl!m"Z"m#Z#m$Z$ ddl%m&Z& ddl'm(Z( ddl)m*Z* ddl+m,Z, ddl-m.Z. ddl/m0Z0m1Z1m2Z2m3Z3 ddl4m5Z6m7Z8m9Z9 ddl:m;Z;m<Z<m=Z= ddl>m?Z? ddl@mAZAmBZB ddlCmDZD ddlEmFZF eAe.fdd„ƒZGeAe.fdd„ƒZHeAe.fdd „ƒZIeAd!d"„ ƒZJd#d$„ ZKi ZLd%eMd&< G d'd(„ d(e?eƒZNG d)d*„ d*e&e?eeOƒZPd+S ),zSparse polynomial rings. é    )Úannotations)ÚAny)ÚaddÚmulÚltÚleÚgtÚge)Úreduce)ÚGeneratorType)ÚExpr)Úigcd)ÚSymbolÚsymbols)ÚCantSympifyÚsympify)Úmultinomial_coefficients)ÚIPolys)Úconstruct_domain)ÚninfÚdmp_to_dictÚdmp_from_dict)ÚDomainElement©ÚPolynomialRing©Úheugcd)ÚMonomialOps)Úlex)ÚCoercionFailedÚGeneratorsErrorÚExactQuotientFailedÚMultivariatePolynomialError)ÚDomainÚOrderÚbuild_options)Úexpr_from_dictÚ_dict_reorderÚ_parallel_dict_from_expr)ÚDefaultPrinting)ÚpublicÚsubsets)Úis_sequence)Úpollutec                 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   ÚdomainÚorderÚ_ring© r5   ú?/tmp/user/2202/pip-unpacked-wheel-qe3242ng/sympy/polys/rings.pyÚring#   s    r7   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'>

    r.   r1   r5   r5   r6   ÚxringB   s    r8   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 r5   )Úname)Ú.0Úsymr5   r5   r6   Ú
<listcomp>}   s     zvring.<locals>.<listcomp>)r/   r-   r   r0   r1   r5   r5   r6   Úvringa   s    r=   c           
        sÌ   d}t | ƒs| gd } }ttt| ƒƒ} t||ƒ}t| |ƒ\}}|jdkrŽt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 d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 r5   ©ÚlistÚvalues©r:   Úrepr5   r5   r6   r<   ¦   s     zsring.<locals>.<listcomp>)Úoptc                   s"   g | ]}‡ fd d„|  ¡ D ƒ‘qS )c                   s   i | ]\}}|ˆ | “qS r5   r5   ©r:   ÚmÚc©Z	coeff_mapr5   r6   Ú
<dictcomp>«   s      z$sring.<locals>.<listcomp>.<dictcomp>)ÚitemsrA   rG   r5   r6   r<   «   s     r   )r,   r?   Úmapr   r%   r(   r2   Úsumr   ÚdictÚzipr/   r0   r3   Ú	from_dict)
Úexprsr   ÚoptionsZsinglerC   ZrepsÚcoeffsZ
coeffs_domr4   Úpolysr5   rG   r6   Úsring€   s     

rS   c                 C  sr   t | tƒr| rt| dd�S dS t | tƒr.| fS t| ƒrftdd„ | D ƒƒrPt| ƒS tdd„ | D ƒƒrf| S tdƒ‚d S )NT)Úseqr5   c                 s  s   | ]}t |tƒV  qd S ©N)Ú
isinstanceÚstr©r:   Úsr5   r5   r6   Ú	<genexpr>»   s     z!_parse_symbols.<locals>.<genexpr>c                 s  s   | ]}t |tƒV  qd S rU   )rV   r   rX   r5   r5   r6   rZ   ½   s     zbexpected a string, Symbol or expression or a non-empty sequence of strings, Symbols or expressions)rV   rW   Ú_symbolsr   r,   Úallr    ©r   r5   r5   r6   Ú_parse_symbolsµ   s    

r^   zdict[Any, Any]Ú_ring_cachec                   @  s@  e Zd ZdZefdd„Zdd„ Zdd„ Zdd	„ Zd
d„ Z	dd„ Z
dd„ ZdGdd„Zdd„ Zedd„ ƒZedd„ ƒZdHdd„Zdd„ Zdd„ Zdd „ ZeZdId!d"„ZdJd#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 ed7d8„ ƒZ!ed9d:„ ƒZ"d;d<„ Z#d=d>„ Z$d?d@„ Z%dAdB„ Z&dCdD„ Z'dEdF„ Z(dS )Kr/   z*Multivariate distributed polynomial ring. c                   sÞ  t t|ƒƒ}t|ƒ}t |¡}t ˆ ¡‰ | j|||ˆ f}t |¡}|d k�rÚ|j	rlt
|ƒt
|jƒ@ rltdƒ‚t | ¡}||_t|ƒ|_tdtfd|iƒ|_||_||_||_ˆ |_d| |_| ¡ |_t
|jƒ|_|j|jfg|_|�r8t|ƒ}| ¡ |_ | !¡ |_"| #¡ |_$| %¡ |_&| '¡ |_(| )¡ |_*| +¡ |_,n6dd„ }||_ ||_"dd„ |_$||_&||_(||_*||_,ˆ t-k�r€t.|_/n‡ fdd„|_/t0|j|jƒD ]4\}	}
t1|	t2ƒ�rœ|	j3}t4||ƒ�sœt5|||
ƒ �qœ|t|< |S )	Nz7polynomial ring and it's ground domain share generatorsÚPolyElementr7   ©r   c                 S  s   dS ©Nr5   r5   )ÚaÚbr5   r5   r6   Ú<lambda>î   ó    z"PolyRing.__new__.<locals>.<lambda>c                 S  s   dS rb   r5   )rc   rd   rF   r5   r5   r6   re   ñ   rf   c                   s   t | ˆ d�S )N©Úkey)Úmax©Úf©r3   r5   r6   re   û   rf   )6Útupler^   ÚlenÚ	DomainOptÚ
preprocessÚOrderOptÚ__name__r_   ÚgetÚis_CompositeÚsetr   r    ÚobjectÚ__new__Ú_hash_tupleÚhashÚ_hashÚtyper`   ÚdtypeÚngensr2   r3   Ú
zero_monomÚ_gensr0   Ú	_gens_setÚoneÚ_oner   r   Úmonomial_mulÚpowÚmonomial_powZmulpowÚmonomial_mulpowZldivÚmonomial_ldivÚdivÚmonomial_divÚlcmZmonomial_lcmÚgcdÚmonomial_gcdr   ri   Úleading_expvrM   rV   r   r9   ÚhasattrÚsetattr)Úclsr   r2   r3   r}   rx   ÚobjZcodegenZmonunitÚsymbolÚ	generatorr9   r5   rl   r6   rw   Ç   s`    















zPolyRing.__new__c                 C  sF   | j j}g }t| jƒD ]&}|  |¡}| j}|||< | |¡ qt|ƒS )z(Return a list of polynomial generators. )r2   r�   Úranger}   Úmonomial_basisÚzeroÚappendrm   )Úselfr�   r   ÚiÚexpvÚpolyr5   r5   r6   r     s    
zPolyRing._gensc                 C  s   | j | j| jfS rU   )r   r2   r3   ©r˜   r5   r5   r6   Ú__getnewargs__  s    zPolyRing.__getnewargs__c                 C  s.   | j  ¡ }|d= |D ]}| d¡r||= q|S )Nr�   Z	monomial_)Ú__dict__ÚcopyÚ
startswith)r˜   Ústaterh   r5   r5   r6   Ú__getstate__  s    

zPolyRing.__getstate__c                 C  s   | j S rU   )rz   rœ   r5   r5   r6   Ú__hash__   s    zPolyRing.__hash__c                 C  s2   t |tƒo0| j| j| j| jf|j|j|j|jfkS rU   )rV   r/   r   r2   r}   r3   ©r˜   Úotherr5   r5   r6   Ú__eq__#  s
    
ÿÿzPolyRing.__eq__c                 C  s
   | |k S rU   r5   r¤   r5   r5   r6   Ú__ne__(  s    zPolyRing.__ne__Nc                 C  s    |   |p| j|p| j|p| j¡S rU   )Ú	__class__r   r2   r3   )r˜   r   r2   r3   r5   r5   r6   Úclone+  s    zPolyRing.clonec                 C  s   dg| j  }d||< t|ƒS )zReturn the ith-basis element. r   é   )r}   rm   )r˜   r™   Zbasisr5   r5   r6   r•   .  s    zPolyRing.monomial_basisc                 C  s   |   ¡ S rU   )r|   rœ   r5   r5   r6   r–   4  s    zPolyRing.zeroc                 C  s   |   | j¡S rU   )r|   r‚   rœ   r5   r5   r6   r�   8  s    zPolyRing.onec                 C  s   | j  ||¡S rU   )r2   Úconvert©r˜   ÚelementÚorig_domainr5   r5   r6   Ú
domain_new<  s    zPolyRing.domain_newc                 C  s   |   | j|¡S rU   )Úterm_newr~   )r˜   Úcoeffr5   r5   r6   Ú
ground_new?  s    zPolyRing.ground_newc                 C  s    |   |¡}| j}|r|||< |S rU   )r¯   r–   )r˜   Úmonomr±   r›   r5   r5   r6   r°   B  s
    
zPolyRing.term_newc                 C  sÈ   t |tƒrF| |jkr|S t | jtƒr<| jj|jkr<|  |¡S tdƒ‚n~t |tƒrZtdƒ‚njt |tƒrn|  	|¡S t |t
ƒr¦z|  |¡W S  tk
r¢   |  |¡ Y S X nt |tƒrº|  |¡S |  |¡S d S )NÚ
conversionZparsing)rV   r`   r7   r2   r   r²   ÚNotImplementedErrorrW   rL   rN   r?   Ú
from_termsÚ
ValueErrorÚ	from_listr   Ú	from_expr©r˜   r­   r5   r5   r6   Úring_newI  s$    










zPolyRing.ring_newc                 C  s8   | j }| j}| ¡ D ]\}}|||ƒ}|r|||< q|S rU   )r¯   r–   rI   )r˜   r­   r®   r¯   r›   r³   r±   r5   r5   r6   rN   a  s    

zPolyRing.from_dictc                 C  s   |   t|ƒ|¡S rU   )rN   rL   r¬   r5   r5   r6   r¶   l  s    zPolyRing.from_termsc                 C  s   |   t|| jd | jƒ¡S ©Nrª   )rN   r   r}   r2   rº   r5   r5   r6   r¸   o  s    zPolyRing.from_listc                   s$   ˆj ‰‡ ‡‡‡fdd„‰ ˆ t|ƒƒS )Nc                   sŒ   ˆ  | ¡}|d k	r|S | jr2ttttˆ | jƒƒƒS | jrNttttˆ | jƒƒƒS |  	¡ \}}|j
rx|dkrxˆ |ƒt|ƒ S ˆ ˆ | ¡¡S d S r¼   )rs   Zis_Addr
   r   r?   rJ   ÚargsZis_Mulr   Zas_base_expZ
is_IntegerÚintr²   r«   )Úexprr“   ÚbaseÚexp©Ú_rebuildr2   Úmappingr˜   r5   r6   rÃ   u  s    
z(PolyRing._rebuild_expr.<locals>._rebuild)r2   r   )r˜   r¿   rÄ   r5   rÂ   r6   Ú_rebuild_exprr  s    zPolyRing._rebuild_exprc                 C  sZ   t tt| j| jƒƒƒ}z|  ||¡}W n$ tk
rJ   td| |f ƒ‚Y nX |  |¡S d S )Nz@expected an expression convertible to a polynomial in %s, got %s)	rL   r?   rM   r   r0   rÅ   r   r·   r»   )r˜   r¿   rÄ   r›   r5   r5   r6   r¹   ‰  s    zPolyRing.from_exprc                 C  sø   |dkr| j rd}qôd}nÚt|tƒrj|}d|kr<|| j k r<qô| j  |kr\|dkr\| d }qôtd| ƒ‚nŠt|| jƒrªz| j |¡}W qô tk
r¦   td| ƒ‚Y qôX nJt|tƒrèz| j |¡}W qô tk
rä   td| ƒ‚Y qôX ntd| ƒ‚|S )z+Compute index of ``gen`` in ``self.gens``. Nr   éÿÿÿÿrª   zinvalid generator index: %szinvalid generator: %szEexpected a polynomial generator, an integer, a string or None, got %s)	r}   rV   r¾   r·   r|   r0   ÚindexrW   r   )r˜   Úgenr™   r5   r5   r6   rÇ   “  s.    

zPolyRing.indexc                   sB   t t| j|ƒƒ‰ ‡ fdd„t| jƒD ƒ}|s2| jS | j|d�S dS )z,Remove specified generators from this ring. c                   s   g | ]\}}|ˆ kr|‘qS r5   r5   ©r:   r™   rY   ©Úindicesr5   r6   r<   µ  s      z!PolyRing.drop.<locals>.<listcomp>r]   N)ru   rJ   rÇ   Ú	enumerater   r2   r©   ©r˜   r0   r   r5   rÊ   r6   Údrop²  s
    zPolyRing.dropc                 C  s$   | j | }|s| jS | j|d�S d S )Nr]   )r   r2   r©   )r˜   rh   r   r5   r5   r6   Ú__getitem__¼  s    
zPolyRing.__getitem__c                 C  s6   | j jst| j dƒr$| j| j j d�S td| j  ƒ‚d S )Nr2   ©r2   z%s is not a composite domain)r2   rt   rŽ   r©   r·   rœ   r5   r5   r6   Ú	to_groundÄ  s    zPolyRing.to_groundc                 C  s   t | ƒS rU   r   rœ   r5   r5   r6   Ú	to_domainË  s    zPolyRing.to_domainc                 C  s   ddl m} || j| j| jƒS )Nr   )Ú	FracField)Zsympy.polys.fieldsrÓ   r   r2   r3   )r˜   rÓ   r5   r5   r6   Úto_fieldÎ  s    zPolyRing.to_fieldc                 C  s   t | jƒdkS r¼   ©rn   r0   rœ   r5   r5   r6   Úis_univariateÒ  s    zPolyRing.is_univariatec                 C  s   t | jƒdkS r¼   rÕ   rœ   r5   r5   r6   Úis_multivariateÖ  s    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‘   r5   r5   r6   r   Ú  s    
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Ú   r5   r5   r6   r   õ  s    
zPolyRing.mulc                   s`   t t| j|ƒƒ‰ ‡ fdd„t| jƒD ƒ}‡ fdd„t| jƒD ƒ}|sH| S | j|| j|Ž d�S dS )zd
        Remove specified generators from the ring and inject them into
        its domain.
        c                   s   g | ]\}}|ˆ kr|‘qS r5   r5   rÉ   rÊ   r5   r6   r<     s      z+PolyRing.drop_to_ground.<locals>.<listcomp>c                   s   g | ]\}}|ˆ kr|‘qS r5   r5   )r:   r™   rÈ   rÊ   r5   r6   r<     s      ©r   r2   N)ru   rJ   rÇ   rÌ   r   r0   r©   rÎ   rÍ   r5   rÊ   r6   Údrop_to_ground  s    zPolyRing.drop_to_groundc                 C  s6   | |kr.t | jƒ t |jƒ¡}| jt|ƒd�S | S dS )z+Add the generators of ``other`` to ``self``r]   N©ru   r   Úunionr©   r?   )r˜   r¥   Úsymsr5   r5   r6   Úcompose  s    zPolyRing.composec                 C  s$   t | jƒ t |ƒ¡}| jt|ƒd�S )z9Add the elements of ``symbols`` as generators to ``self``r]   rß   )r˜   r   rá   r5   r5   r6   Úadd_gens&  s    zPolyRing.add_gensc                   sˆ   |dk s|| j kr&td|| jf ƒ‚n^|s0| jS | j}tt| j ƒt|ƒƒD ]4‰ t‡ fdd„t| j ƒD ƒƒ}||  	|| j
j¡7 }qJ|S d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 |ˆ kƒV  qd S rU   )r¾   ©r:   r™   ©rY   r5   r6   rZ   7  s     z*PolyRing.symmetric_poly.<locals>.<genexpr>N)r}   r·   r0   r�   r–   r+   r”   r¾   rm   r°   r2   )r˜   Únr›   r³   r5   rå   r6   Úsymmetric_poly+  s    zPolyRing.symmetric_poly)NNN)N)N)N))rr   Ú
__module__Ú__qualname__Ú__doc__r   rw   r   r�   r¢   r£   r¦   r§   r©   r•   Úpropertyr–   r�   r¯   r²   r°   r»   Ú__call__rN   r¶   r¸   rÅ   r¹   rÇ   rÎ   rÏ   rÑ   rÒ   rÔ   rÖ   r×   r   r   rÞ   râ   rã   rç   r5   r5   r5   r6   r/   Ä   sP   A










r/   c                   @  sf  e Zd Z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+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zed7d8„ ƒZ e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„ ƒZ0dYdZ„ Z1d[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|„ ZBeAZCeBZDd}d~„ ZEdd€„ ZFd�d‚„ ZGdƒd„„ ZHd…d†„ ZId‡dˆ„ ZJd‰dŠ„ ZK�d#d‹dŒ„ZLd�dŽ„ ZM�d$d�d�„ZNd‘d’„ ZOd“d”„ ZPd•d–„ ZQd—d˜„ ZRd™dš„ ZSed›dœ„ ƒZTed�dž„ ƒZUdŸd „ ZVed¡d¢„ ƒZWd£d¤„ ZXd¥d¦„ ZY�d%d§d¨„ZZ�d&d©dª„Z[�d'd«d¬„Z\d­d®„ Z]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Ì„ ZlelZmdÍdÎ„ ZndÏdÐ„ ZodÑ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ñ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•�d0�d�d„Z–�d �d!„ Z—dS (1  r`   z5Element of multivariate distributed polynomial ring. c                 C  s
   |   |¡S rU   )r¨   )r˜   Úinitr5   r5   r6   Únew?  s    zPolyElement.newc                 C  s
   | j  ¡ S rU   )r7   rÒ   rœ   r5   r5   r6   ÚparentB  s    zPolyElement.parentc                 C  s   | j t|  ¡ ƒfS rU   )r7   r?   Ú	itertermsrœ   r5   r5   r6   r�   E  s    zPolyElement.__getnewargs__Nc                 C  s.   | j }|d kr*t| jt|  ¡ ƒfƒ | _ }|S rU   )rz   ry   r7   Ú	frozensetrI   )r˜   rz   r5   r5   r6   r£   J  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œ   r5   r5   r6   rŸ   U  s    zPolyElement.copyc                 C  sZ   | j |kr| S | j j|jkrFttt| | j j|jƒŽ ƒ}| || j j¡S | | | j j¡S d S rU   )r7   r   r?   rM   r'   r¶   r2   rN   )r˜   Únew_ringÚtermsr5   r5   r6   Úset_ringq  s    
zPolyElement.set_ringc                 G  sH   |s| j j}n(t|ƒ| j jkr6td| j jt|ƒf ƒ‚t|  ¡ f|žŽ S )Nz+Wrong number of symbols, expected %s got %s)r7   r   rn   r}   r·   r&   Úas_expr_dict)r˜   r   r5   r5   r6   Úas_exprz  s    
ÿÿzPolyElement.as_exprc                   s    | j jj‰ ‡ fdd„|  ¡ D ƒS )Nc                   s   i | ]\}}|ˆ |ƒ“qS r5   r5   ©r:   r³   r±   ©Úto_sympyr5   r6   rH   ‡  s      z,PolyElement.as_expr_dict.<locals>.<dictcomp>)r7   r2   rù   rð   rœ   r5   rø   r6   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                   s   g | ]\}}||ˆ  f‘qS r5   r5   )r:   ÚkÚv©Úcommonr5   r6   r<   —  s     z,PolyElement.clear_denoms.<locals>.<listcomp>)r7   r2   Úis_FieldÚhas_assoc_Ringr�   Úget_ringrŠ   Údenomr@   rî   rI   )r˜   r2   Zground_ringrŠ   r  r±   r›   r5   rü   r6   Úclear_denoms‰  s    
zPolyElement.clear_denomsc                 C  s$   t |  ¡ ƒD ]\}}|s| |= qdS )z+Eliminate monomials with zero coefficient. N©r?   rI   )r˜   rú   rû   r5   r5   r6   Ú
strip_zeroš  s    zPolyElement.strip_zeroc                 C  sR   |s
|  S t |tƒr,|j| jkr,t | |¡S t| ƒdkr<dS |  | jj¡|kS d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ª   FN)rV   r`   r7   rL   r¦   rn   rs   r~   ©Úp1Úp2r5   r5   r6   r¦      s    zPolyElement.__eq__c                 C  s
   | |k S rU   r5   r  r5   r5   r6   r§   º  s    zPolyElement.__ne__c                 C  s²   | j }t||jƒrbt|  ¡ ƒt| ¡ ƒkr.dS |jj}|  ¡ D ]}|| | || |ƒs> dS q>dS t| ƒdkrrdS z|j |¡}W n t	k
r˜   Y dS X |j |  
¡ ||¡S dS )z+Approximate equality test for polynomials. FTrª   N)r7   rV   r|   ru   Úkeysr2   Úalmosteqrn   r«   r   Úconst)r  r  Z	tolerancer7   r	  rú   r5   r5   r6   r	  ½  s     zPolyElement.almosteqc                 C  s   t | ƒ|  ¡ fS rU   )rn   ró   rœ   r5   r5   r6   Úsort_keyÕ  s    zPolyElement.sort_keyc                 C  s(   t || jjƒr ||  ¡ | ¡ ƒS tS d S rU   )rV   r7   r|   r  ÚNotImplemented)r  r  Úopr5   r5   r6   Ú_cmpØ  s    zPolyElement._cmpc                 C  s   |   |t¡S rU   )r  r   r  r5   r5   r6   Ú__lt__Þ  s    zPolyElement.__lt__c                 C  s   |   |t¡S rU   )r  r   r  r5   r5   r6   Ú__le__à  s    zPolyElement.__le__c                 C  s   |   |t¡S rU   )r  r   r  r5   r5   r6   Ú__gt__â  s    zPolyElement.__gt__c                 C  s   |   |t¡S rU   )r  r	   r  r5   r5   r6   Ú__ge__ä  s    zPolyElement.__ge__c                 C  sH   | j }| |¡}|jdkr$||jfS t|jƒ}||= ||j|d�fS d S )Nrª   r]   )r7   rÇ   r}   r2   r?   r   r©   ©r˜   rÈ   r7   r™   r   r5   r5   r6   Ú_dropç  s    



zPolyElement._dropc                 C  sŒ   |   |¡\}}| jjdkr8| jr*|  d¡S td| ƒ‚nP|j}|  ¡ D ]<\}}|| dkrvt|ƒ}||= ||t	|ƒ< qFtd| ƒ‚qF|S d S )Nrª   zCannot drop %sr   )
r  r7   r}   Ú	is_groundr±   r·   r–   rI   r?   rm   )r˜   rÈ   r™   r7   r›   rú   rû   ÚKr5   r5   r6   rÎ   ò  s    
zPolyElement.dropc                 C  s6   | j }| |¡}t|jƒ}||= ||j||| d�fS )NrÝ   )r7   rÇ   r?   r   r©   r  r5   r5   r6   Ú_drop_to_ground  s
    

zPolyElement._drop_to_groundc                 C  s¤   | j jdkrtdƒ‚|  |¡\}}|j}|jjd }|  ¡ D ]b\}}|d |… ||d d …  }||kr€|||   |¡||< q<||  |||   |¡7  < q<|S )Nrª   z$Cannot drop only generator to groundr   )	r7   r}   r·   r  r–   r2   r0   rð   Ú
mul_ground)r˜   rÈ   r™   r7   r›   r³   r±   Úmonr5   r5   r6   rÞ     s     zPolyElement.drop_to_groundc                 C  s   t | | jjd | jjƒS r¼   )r   r7   r}   r2   rœ   r5   r5   r6   Úto_dense   s    zPolyElement.to_densec                 C  s   t | ƒS rU   )rL   rœ   r5   r5   r6   Úto_dict#  s    zPolyElement.to_dictc                 C  s¸  | s|  | jjj¡S |d }|d }| j}|j}|j}	|j}
g }|  ¡ D �]4\}}|j |¡}|rfdnd}| 	|¡ ||
kr¢|  |¡}|rÐ| 
d¡rÐ|dd … }n.|r¬| }|| jjjkrÌ|j||dd�}nd	}g }t|	ƒD ]€}|| }|sîqÜ|j|| |dd�}|dk�rN|t|ƒk�s$|d
k �r6|j||dd�}n|}| 	|||f ¡ qÜ| 	d| ¡ qÜ|�rn|g| }| 	| |¡¡ qH|d
 dk�r®| d
¡}|dk�r®| d
d¡ d	 |¡S )NZMulZAtomú - ú + ú-rª   T)ÚstrictÚ r   Fz%s)r  r  )Z_printr7   r2   r–   r   r}   r~   ró   Úis_negativer—   r    r�   Zparenthesizer”   r¾   ÚjoinÚpopÚinsert)r˜   ÚprinterÚ
precedenceZexp_patternZ
mul_symbolZprec_mulZ	prec_atomr7   r   r}   ÚzmZsexpvsrš   r±   ÚnegativeÚsignZscoeffZsexpvr™   rÁ   r’   ZsexpÚheadr5   r5   r6   rW   &  sT    





zPolyElement.strc                 C  s   | | j jkS rU   )r7   r€   rœ   r5   r5   r6   Úis_generatorV  s    zPolyElement.is_generatorc                 C  s   |  pt | ƒdko| jj| kS r¼   )rn   r7   r~   rœ   r5   r5   r6   r  Z  s    zPolyElement.is_groundc                 C  s   |  pt | ƒdko| jdkS r¼   )rn   ÚLCrœ   r5   r5   r6   Úis_monomial^  s    zPolyElement.is_monomialc                 C  s   t | ƒdkS r¼   )rn   rœ   r5   r5   r6   Úis_termb  s    zPolyElement.is_termc                 C  s   | j j | j¡S rU   )r7   r2   r!  r,  rœ   r5   r5   r6   r!  f  s    zPolyElement.is_negativec                 C  s   | j j | j¡S rU   )r7   r2   Úis_positiver,  rœ   r5   r5   r6   r/  j  s    zPolyElement.is_positivec                 C  s   | j j | j¡S rU   )r7   r2   Úis_nonnegativer,  rœ   r5   r5   r6   r0  n  s    zPolyElement.is_nonnegativec                 C  s   | j j | j¡S rU   )r7   r2   Úis_nonpositiver,  rœ   r5   r5   r6   r1  r  s    zPolyElement.is_nonpositivec                 C  s   |  S rU   r5   rj   r5   r5   r6   Úis_zerov  s    zPolyElement.is_zeroc                 C  s   | | j jkS rU   )r7   r�   rj   r5   r5   r6   Úis_onez  s    zPolyElement.is_onec                 C  s   | j j | j¡S rU   )r7   r2   r3  r,  rj   r5   r5   r6   Úis_monic~  s    zPolyElement.is_monicc                 C  s   | j j |  ¡ ¡S rU   )r7   r2   r3  Úcontentrj   r5   r5   r6   Úis_primitive‚  s    zPolyElement.is_primitivec                 C  s   t dd„ |  ¡ D ƒƒS )Nc                 s  s   | ]}t |ƒd kV  qdS ©rª   N©rK   ©r:   r³   r5   r5   r6   rZ   ˆ  s     z(PolyElement.is_linear.<locals>.<genexpr>©r\   Ú
itermonomsrj   r5   r5   r6   Ú	is_linear†  s    zPolyElement.is_linearc                 C  s   t dd„ |  ¡ D ƒƒS )Nc                 s  s   | ]}t |ƒd kV  qdS )é   Nr8  r9  r5   r5   r6   rZ   Œ  s     z+PolyElement.is_quadratic.<locals>.<genexpr>r:  rj   r5   r5   r6   Úis_quadraticŠ  s    zPolyElement.is_quadraticc                 C  s   | j jsdS | j  | ¡S ©NT)r7   r}   Z	dmp_sqf_prj   r5   r5   r6   Úis_squarefreeŽ  s    zPolyElement.is_squarefreec                 C  s   | j jsdS | j  | ¡S r?  )r7   r}   Zdmp_irreducible_prj   r5   r5   r6   Úis_irreducible”  s    zPolyElement.is_irreduciblec                 C  s    | j jr| j  | ¡S tdƒ‚d S )Nzcyclotomic polynomial)r7   rÖ   Zdup_cyclotomic_pr"   rj   r5   r5   r6   Úis_cyclotomicš  s    zPolyElement.is_cyclotomicc                 C  s   |   dd„ |  ¡ D ƒ¡S )Nc                 S  s   g | ]\}}|| f‘qS r5   r5   r÷   r5   r5   r6   r<   ¢  s     z'PolyElement.__neg__.<locals>.<listcomp>)rî   rð   rœ   r5   r5   r6   Ú__neg__¡  s    zPolyElement.__neg__c                 C  s   | S rU   r5   rœ   r5   r5   r6   Ú__pos__¤  s    zPolyElement.__pos__c           
      C  sB  |s|   ¡ S | j}t||jƒrl|   ¡ }|j}|jj}| ¡ D ]*\}}|||ƒ| }|r`|||< q<||= q<|S t|tƒr¼t|jt	ƒr’|jj|jkr’n*t|jjt	ƒr¸|jjj|kr¸| 
| ¡S tS z| |¡}W n tk
râ   t Y S X |   ¡ }|sô|S |j}	|	|  ¡ k�r|||	< n(|||	  k�r*||	= n||	  |7  < |S d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

        N)rŸ   r7   rV   r|   rs   r2   r–   rI   r`   r   Ú__radd__r  r¯   r   r~   r  )
r  r  r7   rÜ   rs   r–   rú   rû   Zcp2r'  r5   r5   r6   Ú__add__§  sB    




zPolyElement.__add__c                 C  sˆ   |   ¡ }|s|S | j}z| |¡}W n tk
r<   t Y S X |j}||  ¡ krZ|||< n&|||  krp||= n||  |7  < |S d S rU   )rŸ   r7   r¯   r   r  r~   r  )r  ræ   rÜ   r7   r'  r5   r5   r6   rE  Ý  s    

zPolyElement.__radd__c           	      C  s:  |s|   ¡ S | j}t||jƒrl|   ¡ }|j}|jj}| ¡ D ]*\}}|||ƒ| }|r`|||< q<||= q<|S t|tƒr¼t|jt	ƒr’|jj|jkr’n*t|jjt	ƒr¸|jjj|kr¸| 
| ¡S tS z| |¡}W n tk
râ   t Y S X |   ¡ }|j}||  ¡ k�r| ||< n&||| k�r"||= n||  |8  < |S d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

        N)rŸ   r7   rV   r|   rs   r2   r–   rI   r`   r   Ú__rsub__r  r¯   r   r~   r  )	r  r  r7   rÜ   rs   r–   rú   rû   r'  r5   r5   r6   Ú__sub__ñ  s>    



zPolyElement.__sub__c                 C  s\   | j }z| |¡}W n tk
r,   t Y S X |j}| D ]}| |  ||< q8||7 }|S d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

        N)r7   r¯   r   r  r–   )r  ræ   r7   rÜ   rš   r5   r5   r6   rG  '  s    
zPolyElement.__rsub__c                 C  s<  | j }|j}| r|s|S t||jƒr�|j}|jj}|j}t| ¡ ƒ}|  ¡ D ]6\}}	|D ](\}
}|||
ƒ}|||ƒ|	|  ||< qXqL| 	¡  |S t|t
ƒràt|jtƒr¶|jj |j kr¶n*t|j jtƒrÜ|j jj |krÜ| | ¡S tS z| |¡}W n tk
�r   t Y S X |  ¡ D ] \}}	|	| }|�r|||< �q|S d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

        N)r7   r–   rV   r|   rs   r2   rƒ   r?   rI   r  r`   r   Ú__rmul__r  r¯   r   )r  r  r7   rÜ   rs   r–   rƒ   Zp2itÚexp1Úv1Zexp2Zv2rÁ   rû   r5   r5   r6   Ú__mul__B  s<    



zPolyElement.__mul__c                 C  sh   | j j}|s|S z|j  |¡}W n tk
r8   t Y S X |  ¡ D ]\}}|| }|rB|||< qB|S d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

        N)r7   r–   r¯   r   r  rI   )r  r  rÜ   rJ  rK  rû   r5   r5   r6   rI  t  s    

zPolyElement.__rmul__c                 C  sì   | j }|s| r|jS tdƒ‚n\t| ƒdkrzt|  ¡ ƒd \}}|j}||jjkrb||| ||¡< n|| || ||¡< |S t	|ƒ}|dk r”tdƒ‚nT|dkr¤|  
¡ S |dkr´|  ¡ S |dkrÈ| |  ¡  S t| ƒdkrÞ|  |¡S |  |¡S dS )	a(  raise polynomial to power `n`

        Examples
        ========

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

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

        z0**0rª   r   zNegative exponentr=  é   é   N)r7   r�   r·   rn   r?   rI   r–   r2   r…   r¾   rŸ   ÚsquareÚ_pow_multinomialÚ_pow_generic)r˜   ræ   r7   r³   r±   rÜ   r5   r5   r6   Ú__pow__‘  s0    


zPolyElement.__pow__c                 C  s@   | j j}| }|d@ r*|| }|d8 }|s*q<| ¡ }|d }q|S )Nrª   r=  )r7   r�   rO  )r˜   ræ   rÜ   rF   r5   r5   r6   rQ  Á  s    
zPolyElement._pow_genericc                 C  sÂ   t t| ƒ|ƒ ¡ }| jj}| jj}|  ¡ }| jjj}| jj}|D ]|\}}	|}
|	}t||ƒD ](\}\}}|rZ||
||ƒ}
||| 9 }qZt	|
ƒ}|}| 
||¡| }|r®|||< q@||kr@||= q@|S rU   )r   rn   rI   r7   r†   r~   r2   r–   rM   rm   rs   )r˜   ræ   Zmultinomialsr†   r~   ró   r–   r›   ZmultinomialZmultinomial_coeffZproduct_monomZproduct_coeffrÁ   r³   r±   r5   r5   r6   rP  Ñ  s*    

zPolyElement._pow_multinomialc                 C  sÖ   | j }|j}|j}t|  ¡ ƒ}|jj}|j}tt|ƒƒD ]N}|| }| | }	t|ƒD ]0}
||
 }|||ƒ}|||ƒ|	| |   ||< qTq8| 	d¡}|j}|  
¡ D ](\}}|||ƒ}|||ƒ|d  ||< q | ¡  |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=  )r7   r–   rs   r?   r  r2   rƒ   r”   rn   Úimul_numrI   r  )r˜   r7   rÜ   rs   r  r–   rƒ   r™   Zk1ÚpkÚjZk2rÁ   rú   rû   r5   r5   r6   rO  î  s(    


zPolyElement.squarec                 C  sº   | j }|stdƒ‚nft||jƒr*|  |¡S t|tƒrzt|jtƒrP|jj |j krPn*t|j jtƒrv|j jj |krv| | ¡S t	S z| 
|¡}W n tk
r    t	 Y S X |  |¡|  |¡fS d S ©Núpolynomial division)r7   ÚZeroDivisionErrorrV   r|   rˆ   r`   r2   r   Ú__rdivmod__r  r¯   r   Ú
quo_groundÚ
rem_ground©r  r  r7   r5   r5   r6   Ú
__divmod__  s     




zPolyElement.__divmod__c                 C  s   t S rU   ©r  r  r5   r5   r6   rY  (  s    zPolyElement.__rdivmod__c                 C  s°   | j }|stdƒ‚nft||jƒr*|  |¡S t|tƒrzt|jtƒrP|jj |j krPn*t|j jtƒrv|j jj |krv| | ¡S t	S z| 
|¡}W n tk
r    t	 Y S X |  |¡S d S rV  )r7   rX  rV   r|   Úremr`   r2   r   Ú__rmod__r  r¯   r   r[  r\  r5   r5   r6   Ú__mod__+  s     




zPolyElement.__mod__c                 C  s   t S rU   r^  r  r5   r5   r6   r`  A  s    zPolyElement.__rmod__c                 C  sÄ   | j }|stdƒ‚nzt||jƒr>|jr2| |d  S |  |¡S nPt|tƒrŽt|jtƒrd|jj |j krdn*t|j jtƒrŠ|j jj |krŠ| 	| ¡S t
S z| |¡}W n tk
r´   t
 Y S X |  |¡S d S )NrW  rÆ   )r7   rX  rV   r|   r-  Úquor`   r2   r   Ú__rtruediv__r  r¯   r   rZ  r\  r5   r5   r6   Ú__truediv__D  s$    



zPolyElement.__truediv__c                 C  s   t S rU   r^  r  r5   r5   r6   rc  ]  s    zPolyElement.__rtruediv__c                   sJ   | j j‰| j j}|j‰ | j j‰|jr6‡ ‡‡fdd„}n‡ ‡‡fdd„}|S )Nc                   sF   | \}}|\}}|ˆkr|}n
ˆ||ƒ}|d k	r>|ˆ ||ƒfS d S d S rU   r5   ©Z	a_lm_a_lcZ	b_lm_b_lcZa_lmZa_lcZb_lmZb_lcr³   ©Z
domain_quor‰   r'  r5   r6   Úterm_divl  s    
z'PolyElement._term_div.<locals>.term_divc                   sN   | \}}|\}}|ˆkr|}n
ˆ||ƒ}|d ksF|| sF|ˆ ||ƒfS d S d S rU   r5   re  rf  r5   r6   rg  x  s    
)r7   r~   r2   rb  r‰   rþ   )r˜   r2   rg  r5   rf  r6   Ú	_term_dive  s    zPolyElement._term_divc                   s²  | j ‰ d}t|tƒrd}|g}t|ƒs.tdƒ‚| sL|rBˆ jˆ jfS g ˆ jfS |D ]}|j ˆ krPtdƒ‚qPt|ƒ}‡ fdd„t|ƒD ƒ}|  	¡ }ˆ j}|  
¡ }dd„ |D ƒ}	|�rnd}
d}|
|k �rH|dk�rH| ¡ }|||| f|	|
 ||
 |	|
  fƒ}|d	k	�r>|\}}||
  ||f¡||
< | ||
 || f¡}d
}q¸|
d
7 }
q¸|sª| ¡ }| ||| f¡}||= qª|ˆ jk�r‚||7 }|�r¦|�s˜ˆ j|fS |d |fS n||fS d	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

        FTrW  z"self and f must have the same ringc                   s   g | ]
}ˆ j ‘qS r5   )r–   rä   ©r7   r5   r6   r<   ²  s     z#PolyElement.div.<locals>.<listcomp>c                 S  s   g | ]}|  ¡ ‘qS r5   )r�   )r:   Zfxr5   r5   r6   r<   ¶  s     r   Nrª   )r7   rV   r`   r\   rX  r–   r·   rn   r”   rŸ   rh  r�   Ú_iadd_monomÚ_iadd_poly_monomr~   )r˜   ZfvZ
ret_singlerk   rY   ZqvrÜ   Úrrg  Zexpvsr™   Zdivoccurredrš   ÚtermZexpv1rF   r5   ri  r6   rˆ   †  sV    



&


zPolyElement.divc                 C  s@  | }t |tƒr|g}t|ƒs$tdƒ‚|j}|j}|j}|j}|j}| ¡ }|j	}	| 
¡ }|j}
|�r<|D ]‚}||	|j	ƒ}|d k	rh|\}}| ¡ D ]8\}}|||ƒ}|
||ƒ||  }|sÀ||= q�|||< q�| ¡ }|d k	ræ||| f}	 q^qh|	\}}||k�r||  |7  < n|||< ||= | ¡ }|d k	r^||| f}	q^|S rV  )rV   r`   r\   rX  r7   r2   r–   rƒ   rh  ÚLTrŸ   rs   rð   r�   )r˜   ÚGrk   r7   r2   r–   rƒ   rl  rg  Zltfrs   ÚgZtqrE   rF   ÚmgÚcgÚm1Zc1ZltmZltcr5   r5   r6   r_  Ò  sL    



zPolyElement.remc                 C  s   |   |¡d S ©Nr   )rˆ   )rk   ro  r5   r5   r6   rb  ÿ  s    zPolyElement.quoc                 C  s$   |   |¡\}}|s|S t| |ƒ‚d S rU   )rˆ   r!   )rk   ro  Úqrl  r5   r5   r6   Úexquo  s    zPolyElement.exquoc                 C  s^   | | j jkr|  ¡ }n| }|\}}| |¡}|dkr>|||< n||7 }|rT|||< n||= |S )a�  add to self the monomial coeff*x0**i0*x1**i1*...
        unless self is a generator -- then just return the sum of the two.

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

        Examples
        ========

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

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

        N)r7   r€   rŸ   rs   )r˜   ÚmcZcpselfrš   r±   rF   r5   r5   r6   rj  
  s    



zPolyElement._iadd_monomc                 C  s~   | }||j jkr| ¡ }|\}}|j}|j jj}|j j}| ¡ D ]8\}	}
||	|ƒ}|||ƒ|
|  }|rr|||< 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

        )r7   r€   rŸ   rs   r2   r–   rƒ   rI   )r˜   r  rw  r  rE   rF   rs   r–   rƒ   rú   rû   Úkar±   r5   r5   r6   rk  6  s    


zPolyElement._iadd_poly_monomc                   s>   | j  |¡‰ | stS ˆ dk r dS t‡ fdd„|  ¡ D ƒƒS 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  s   | ]}|ˆ  V  qd S rU   r5   r9  ©r™   r5   r6   rZ   i  s     z%PolyElement.degree.<locals>.<genexpr>N)r7   rÇ   r   ri   r;  ©rk   Úxr5   ry  r6   Údegree[  s    zPolyElement.degreec                 C  s0   | st f| jj S ttttt|  ¡ Ž ƒƒƒS dS )z“
        A tuple containing leading degrees in all variables.

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

        N)	r   r7   r}   rm   rJ   ri   r?   rM   r;  rj   r5   r5   r6   Údegreesk  s    zPolyElement.degreesc                   s>   | j  |¡‰ | stS ˆ dk r dS t‡ fdd„|  ¡ D ƒƒS dS )z�
        The tail degree in ``x`` or the main variable.

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

        r   c                 3  s   | ]}|ˆ  V  qd S rU   r5   r9  ry  r5   r6   rZ   …  s     z*PolyElement.tail_degree.<locals>.<genexpr>N)r7   rÇ   r   Úminr;  rz  r5   ry  r6   Útail_degreew  s    zPolyElement.tail_degreec                 C  s0   | st f| jj S ttttt|  ¡ Ž ƒƒƒS dS )z�
        A tuple containing tail degrees in all variables.

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

        N)	r   r7   r}   rm   rJ   r~  r?   rM   r;  rj   r5   r5   r6   Útail_degrees‡  s    zPolyElement.tail_degreesc                 C  s   | r| j  | ¡S d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)r7   r�   rœ   r5   r5   r6   r�   “  s    zPolyElement.leading_expvc                 C  s   |   || jjj¡S rU   )rs   r7   r2   r–   ©r˜   rš   r5   r5   r6   Ú
_get_coeff§  s    zPolyElement._get_coeffc                 C  sp   |dkr|   | jj¡S t|| jjƒr`t| ¡ ƒ}t|ƒdkr`|d \}}|| jjj	kr`|   |¡S t
d| ƒ‚dS )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 %sN)r‚  r7   r~   rV   r|   r?   rð   rn   r2   r�   r·   )r˜   r­   ró   r³   r±   r5   r5   r6   r±   ª  s    
zPolyElement.coeffc                 C  s   |   | jj¡S )z"Returns the constant coefficient. )r‚  r7   r~   rœ   r5   r5   r6   r
  Ï  s    zPolyElement.constc                 C  s   |   |  ¡ ¡S rU   )r‚  r�   rœ   r5   r5   r6   r,  Ó  s    zPolyElement.LCc                 C  s    |   ¡ }|d kr| jjS |S d S rU   )r�   r7   r~   r�  r5   r5   r6   Ú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

        )r7   r–   r�   r2   r�   ©r˜   rÜ   rš   r5   r5   r6   Úleading_monomß  s
    zPolyElement.leading_monomc                 C  s4   |   ¡ }|d kr"| jj| jjjfS ||  |¡fS d S rU   )r�   r7   r~   r2   r–   r‚  r�  r5   r5   r6   rn  ô  s    zPolyElement.LTc                 C  s(   | j j}|  ¡ }|dk	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)r7   r–   r�   r„  r5   r5   r6   Úleading_termü  s
    zPolyElement.leading_termc                   sP   ˆ d kr| j j‰ n
t ˆ ¡‰ ˆ tkr6t|dd„ dd�S t|‡ fdd„dd�S d S )Nc                 S  s   | d S rt  r5   ©r³   r5   r5   r6   re     rf   z%PolyElement._sorted.<locals>.<lambda>T)rh   Úreversec                   s   ˆ | d ƒS rt  r5   r‡  rl   r5   r6   re     rf   )r7   r3   rq   rp   r   Úsorted)r˜   rT   r3   r5   rl   r6   Ú_sorted  s    

zPolyElement._sortedc                 C  s   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 r5   r5   )r:   Ú_r±   r5   r5   r6   r<   3  s     z&PolyElement.coeffs.<locals>.<listcomp>©ró   ©r˜   r3   r5   r5   r6   rQ     s    zPolyElement.coeffsc                 C  s   dd„ |   |¡D ƒS )a
  Ordered list of polynomial monomials.

        Parameters
        ==========

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

        Examples
        ========

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

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

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

        c                 S  s   g | ]\}}|‘qS r5   r5   )r:   r³   r‹  r5   r5   r6   r<   M  s     z&PolyElement.monoms.<locals>.<listcomp>rŒ  r�  r5   r5   r6   Úmonoms5  s    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Š  r?   rI   r�  r5   r5   r6   ró   O  s    zPolyElement.termsc                 C  s   t |  ¡ ƒS )z,Iterator over coefficients of a polynomial. )Úiterr@   rœ   r5   r5   r6   Ú
itercoeffsi  s    zPolyElement.itercoeffsc                 C  s   t |  ¡ ƒS )z)Iterator over monomials of a polynomial. )r�  r  rœ   r5   r5   r6   r;  m  s    zPolyElement.itermonomsc                 C  s   t |  ¡ ƒS )z%Iterator over terms of a polynomial. )r�  rI   rœ   r5   r5   r6   rð   q  s    zPolyElement.itertermsc                 C  s   t |  ¡ ƒS )z+Unordered list of polynomial coefficients. r>   rœ   r5   r5   r6   Ú
listcoeffsu  s    zPolyElement.listcoeffsc                 C  s   t |  ¡ ƒS )z(Unordered list of polynomial monomials. )r?   r  rœ   r5   r5   r6   Ú
listmonomsy  s    zPolyElement.listmonomsc                 C  s   t |  ¡ ƒS )z$Unordered list of polynomial terms. r  rœ   r5   r5   r6   Ú	listterms}  s    zPolyElement.listtermsc                 C  sB   | | j jk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)r7   r€   Úclear)rÜ   rF   rÁ   r5   r5   r6   rS  �  s    zPolyElement.imul_numc                 C  s0   | j j}|j}|j}|  ¡ D ]}|||ƒ}q|S )z*Returns GCD of polynomial's coefficients. )r7   r2   r–   r‹   r�  )rk   r2   Úcontr‹   r±   r5   r5   r6   r5  ¤  s    zPolyElement.contentc                 C  s   |   ¡ }||  |¡fS )z,Returns content and a primitive polynomial. )r5  rZ  )rk   r•  r5   r5   r6   Ú	primitive¯  s    zPolyElement.primitivec                 C  s   | s| S |   | j¡S dS )z5Divides all coefficients by the leading coefficient. N)rZ  r,  rj   r5   r5   r6   Úmonic´  s    zPolyElement.monicc                   s,   ˆ s| j jS ‡ fdd„|  ¡ D ƒ}|  |¡S )Nc                   s   g | ]\}}||ˆ  f‘qS r5   r5   r÷   ©r{  r5   r6   r<   ¿  s     z*PolyElement.mul_ground.<locals>.<listcomp>)r7   r–   rð   rî   )rk   r{  ró   r5   r˜  r6   r  »  s    zPolyElement.mul_groundc                   s*   | j j‰‡ ‡fdd„|  ¡ D ƒ}|  |¡S )Nc                   s   g | ]\}}ˆ|ˆ ƒ|f‘qS r5   r5   ©r:   Zf_monomZf_coeff©r³   rƒ   r5   r6   r<   Ä  s     z)PolyElement.mul_monom.<locals>.<listcomp>)r7   rƒ   rI   rî   )rk   r³   ró   r5   rš  r6   Ú	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 r5   r5   r™  ©r±   r³   rƒ   r5   r6   r<   Ð  s     z(PolyElement.mul_term.<locals>.<listcomp>)r7   r–   r~   r  rƒ   rI   rî   )rk   rm  ró   r5   rœ  r6   Úmul_termÇ  s    
zPolyElement.mul_termc                   sl   | j j}ˆstdƒ‚| r"ˆ|jkr&| S |jrL|j‰ ‡ ‡fdd„|  ¡ D ƒ}n‡fdd„|  ¡ D ƒ}|  |¡S )NrW  c                   s   g | ]\}}|ˆ |ˆƒf‘qS r5   r5   r÷   ©rb  r{  r5   r6   r<   Ý  s     z*PolyElement.quo_ground.<locals>.<listcomp>c                   s$   g | ]\}}|ˆ  s||ˆ  f‘qS r5   r5   r÷   r˜  r5   r6   r<   ß  s      )r7   r2   rX  r�   rþ   rb  rð   rî   )rk   r{  r2   ró   r5   rž  r6   rZ  Ó  s    zPolyElement.quo_groundc                   sl   ˆ \}}|st dƒ‚n"| s"| jjS || jjkr8|  |¡S |  ¡ ‰‡ ‡fdd„|  ¡ D ƒ}|  dd„ |D ƒ¡S )NrW  c                   s   g | ]}ˆ|ˆ ƒ‘qS r5   r5   ©r:   Út©rm  rg  r5   r6   r<   ï  s     z(PolyElement.quo_term.<locals>.<listcomp>c                 S  s   g | ]}|d k	r|‘qS rU   r5   rŸ  r5   r5   r6   r<   ð  s      )rX  r7   r–   r~   rZ  rh  rð   rî   )rk   rm  r³   r±   ró   r5   r¡  r6   Úquo_termã  s    

zPolyElement.quo_termc                   sx   | j jjrLg }|  ¡ D ]2\}}|ˆ  }|ˆ d kr:|ˆ  }| ||f¡ qn‡ fdd„|  ¡ D ƒ}|  |¡}| ¡  |S )Nr=  c                   s   g | ]\}}||ˆ  f‘qS r5   r5   r÷   ©rÜ   r5   r6   r<   þ  s     z,PolyElement.trunc_ground.<locals>.<listcomp>)r7   r2   Úis_ZZrð   r—   rî   r  )rk   rÜ   ró   r³   r±   r›   r5   r£  r6   Útrunc_groundò  s    

zPolyElement.trunc_groundc                 C  sB   | }|  ¡ }|  ¡ }|jj ||¡}| |¡}| |¡}|||fS rU   )r5  r7   r2   r‹   rZ  )r˜   rp  rk   ÚfcÚgcr‹   r5   r5   r6   Úextract_ground  s    

zPolyElement.extract_groundc                   s6   | s| j jjS | j jj‰ |‡ fdd„|  ¡ D ƒƒS d S )Nc                   s   g | ]}ˆ |ƒ‘qS r5   r5   )r:   r±   ©Z
ground_absr5   r6   r<     s     z%PolyElement._norm.<locals>.<listcomp>)r7   r2   r–   Úabsr�  )rk   Z	norm_funcr5   r©  r6   Ú_norm  s    

zPolyElement._normc                 C  s
   |   t¡S rU   )r«  ri   rj   r5   r5   r6   Úmax_norm  s    zPolyElement.max_normc                 C  s
   |   t¡S rU   )r«  rK   rj   r5   r5   r6   Úl1_norm  s    zPolyElement.l1_normc                 G  sô   | j }| gt|ƒ }dg|j }|D ]6}| ¡ D ](}t|ƒD ]\}}t|| |ƒ||< q<q0q$t|ƒD ]\}}	|	sdd||< qdt|ƒ}tdd„ |D ƒƒrœ||fS g }
|D ]F}|j}| 	¡ D ](\}}dd„ t
||ƒD ƒ}||t|ƒ< q¶|
 |¡ q¤||
fS )Nr   rª   c                 s  s   | ]}|d kV  qdS r7  r5   )r:   rd   r5   r5   r6   rZ   0  s     z&PolyElement.deflate.<locals>.<genexpr>c                 S  s   g | ]\}}|| ‘qS r5   r5   ©r:   r™   rU  r5   r5   r6   r<   9  s     z'PolyElement.deflate.<locals>.<listcomp>)r7   r?   r}   r;  rÌ   r   rm   r\   r–   rð   rM   r—   )rk   ro  r7   rR   ÚJrÜ   r³   r™   rE   rd   ÚHÚhÚIr±   ÚNr5   r5   r6   Údeflate  s*    
zPolyElement.deflatec                 C  s>   | j j}|  ¡ D ](\}}dd„ t||ƒD ƒ}||t|ƒ< q|S )Nc                 S  s   g | ]\}}|| ‘qS r5   r5   r®  r5   r5   r6   r<   D  s     z'PolyElement.inflate.<locals>.<listcomp>)r7   r–   rð   rM   rm   )rk   r¯  r›   r²  r±   r³  r5   r5   r6   Úinflate@  s
    zPolyElement.inflatec                 C  sf   | }|j j}|js6| ¡ \}}| ¡ \}}| ||¡}||  | |¡¡}|jsZ| |¡S | ¡ S d S rU   )	r7   r2   rþ   r–  rŠ   rb  r‹   r  r—  )r˜   rp  rk   r2   r¦  r§  rF   r±  r5   r5   r6   rŠ   I  s    
zPolyElement.lcmc                 C  s   |   |¡d S rt  )Ú	cofactors©rk   rp  r5   r5   r6   r‹   Y  s    zPolyElement.gcdc                 C  sà   | s|s| j j}|||fS | s8|  |¡\}}}|||fS |sV| | ¡\}}}|||fS t| ƒdkr||  |¡\}}}|||fS t|ƒdkr¢| | ¡\}}}|||fS |  |¡\}\} }|  |¡\}}}| |¡| |¡| |¡fS r¼   )r7   r–   Ú	_gcd_zerorn   Ú
_gcd_monomr´  Ú_gcdrµ  )rk   rp  r–   r±  ÚcffÚcfgr¯  r5   r5   r6   r¶  \  s$    




zPolyElement.cofactorsc                 C  s4   | j j| j j }}|jr"|||fS | || fS d S rU   )r7   r�   r–   r0  )rk   rp  r�   r–   r5   r5   r6   r¸  r  s    
zPolyElement._gcd_zeroc                   s¾   | j }|jj}|jj‰|j}|j‰t|  ¡ ƒd \}}|| ‰‰ | ¡ D ]\}}|ˆ|ƒ‰|ˆ |ƒ‰ qH|  ˆˆ fg¡}	|  ˆ|ˆƒˆ|ˆ ƒfg¡}
|  ‡ ‡‡‡fdd„| ¡ D ƒ¡}|	|
|fS )Nr   c                   s$   g | ]\}}ˆ|ˆƒˆ|ˆ ƒf‘qS r5   r5   )r:   rq  rr  ©Z_cgcdZ_mgcdZ
ground_quor‡   r5   r6   r<   †  s     z*PolyElement._gcd_monom.<locals>.<listcomp>)	r7   r2   r‹   rb  rŒ   r‡   r?   rð   rî   )rk   rp  r7   Z
ground_gcdrŒ   ZmfÚcfrq  rr  r±  r»  r¼  r5   r½  r6   r¹  y  s    

"zPolyElement._gcd_monomc                 C  s:   | j }|jjr|  |¡S |jjr*|  |¡S | | |¡S d S rU   )r7   r2   Zis_QQÚ_gcd_QQr¤  Ú_gcd_ZZZdmp_inner_gcd)rk   rp  r7   r5   r5   r6   rº  ‰  s    

zPolyElement._gcdc                 C  s
   t | |ƒS rU   r   r·  r5   r5   r6   rÀ  “  s    zPolyElement._gcd_ZZc                 C  s°   | }|j }|j|j ¡ d�}| ¡ \}}| ¡ \}}| |¡}| |¡}| |¡\}}}	| |¡}|j| ¡  }
}| |¡ 	|j 
|
|¡¡}|	 |¡ 	|j 
|
|¡¡}	|||	fS )NrÐ   )r7   r©   r2   r   r  rô   rÀ  r,  r—  r  rb  )r˜   rp  rk   r7   rò   r¾  rr  r±  r»  r¼  rF   r5   r5   r6   r¿  –  s    


zPolyElement._gcd_QQc                 C  s  | }|j }|s||jfS |j}|jr*|js<| |¡\}}}nˆ|j| ¡ d�}| ¡ \}	}| ¡ \}
}| 	|¡}| 	|¡}| |¡\}}}|j |
|	¡\}}
}	| 	|¡}| 	|¡}| 
|
¡}| 
|	¡}| ¡ }||jkrâ|| }}n2||j k�r | |  }}n| 
|¡}| 
|¡}||fS )a  
        Cancel common factors in a rational function ``f/g``.

        Examples
        ========

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

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

        rÐ   )r7   r�   r2   rþ   rÿ   r¶  r©   r   r  rô   r  Úcanonical_unit)r˜   rp  rk   r7   r2   r‹  rÜ   ru  rò   ZcqÚcpÚur5   r5   r6   Úcancel«  s4    









zPolyElement.cancelc                 C  s   | j j}| | j¡S rU   )r7   r2   rÁ  r,  )rk   r2   r5   r5   r6   rÁ  ã  s    zPolyElement.canonical_unitc           	      C  s`   | j }| |¡}| |¡}|j}|  ¡ D ]2\}}|| 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

        )r7   rÇ   r•   r–   rð   r‡   r¯   )	rk   r{  r7   r™   rE   rp  rš   r±   Úer5   r5   r6   Údiffç  s    

zPolyElement.diffc                 G  sT   dt |ƒ  k r| jjkr8n n|  tt| jj|ƒƒ¡S td| jjt |ƒf ƒ‚d S )Nr   z1expected at least 1 and at most %s values, got %s)rn   r7   r}   Úevaluater?   rM   r0   r·   )rk   r@   r5   r5   r6   rì    	  s     zPolyElement.__call__c                   sH  | }t |tƒr`|d kr`|d |dd …  \‰ }}| ˆ |¡}|sD|S ‡ fdd„|D ƒ}| |¡S |j}| |¡}|j |¡}|jdkr¶|jj}| 	¡ D ]\\}}||||  7 }q–|S | 
|¡j}	| 	¡ D ]t\}
}|
| |
d |… |
|d d …   }}
|||  }|
|	k�r2||	|
  }|�r*||	|
< n|	|
= qÊ|rÊ||	|
< qÊ|	S d S )Nr   rª   c                   s   g | ]\}}|  ˆ ¡|f‘qS r5   )rÎ   )r:   ÚYrc   ©ÚXr5   r6   r<   	  s     z(PolyElement.evaluate.<locals>.<listcomp>)rV   r?   rÇ  r7   rÇ   r2   r«   r}   r–   rð   rÎ   )r˜   r{  rc   rk   r7   r™   Úresultræ   r±   r›   r³   r5   rÉ  r6   rÇ  	  s8    


&


zPolyElement.evaluatec                 C  s   | }t |tƒr4|d kr4|D ]\}}| ||¡}q|S |j}| |¡}|j |¡}|jdkr�|jj}| 	¡ D ]\\}}	||	||  7 }qj| 
|¡S |j}
| 	¡ D ]x\}}	|| |d |… d ||d d …   }}|	||  }	||
k�r
|	|
|  }	|	�r|	|
|< n|
|= qž|	rž|	|
|< qž|
S d S )Nrª   ra   )rV   r?   Úsubsr7   rÇ   r2   r«   r}   r–   rð   r²   )r˜   r{  rc   rk   rÊ  r7   r™   rË  ræ   r±   r›   r³   r5   r5   r6   rÌ  2	  s2    


*


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}|�rrd\}}}	t| ¡ ƒD ]R\}
\‰ }t‡ fd	d
„|D ƒƒrŽt	dd
„ t
|ˆ ƒD ƒƒ}||krŽ|ˆ |  }}}	qŽ|dkrö||	 ‰ }n�qrg }t
ˆ ˆ dd… d ƒD ]\}}| || ¡ �q|ˆ t|ƒ|¡7 }|}t|ƒD ]\}
}|||
|ƒ9 }�qN||8 }qrt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ä   ri  r5   r6   r<   ›	  s     z*PolyElement.symmetrize.<locals>.<listcomp>c                   s,   | |fˆ kr ˆ|  | ˆ | |f< ˆ | |f S rU   r5   )r™   ræ   )Úpoly_powersrR   r5   r6   Úget_poly_powerž	  s    z.PolyElement.symmetrize.<locals>.get_poly_powerrª   r   rÆ   )rÆ   NNc                 3  s"   | ]}ˆ | ˆ |d   kV  qdS r7  r5   rä   r‡  r5   r6   rZ   ¬	  s     z)PolyElement.symmetrize.<locals>.<genexpr>c                 s  s   | ]\}}|| V  qd S rU   r5   )r:   ræ   rE   r5   r5   r6   rZ   ­	  s     Nra   )rŸ   r7   r}   r–   r”   r?   rÌ   ró   r\   ri   rM   r—   r°   rm   r0   )r˜   rk   ræ   rÎ  rË   ÚweightsZ	symmetricZ_heightZ_monomZ_coeffr™   r±   ÚheightZ	exponentsrs  Úm2ÚproductrÄ   r5   )r³   rÍ  rR   r7   r6   Ú
symmetrizeY	  s>    ;

zPolyElement.symmetrizec                   s  | j }|j}tt|jt|jƒƒƒ‰ |d k	r6||fg}n@t|tƒrJt|ƒ}n,t|tƒrnt	| 
¡ ‡ fdd„d�}ntdƒ‚t|ƒD ]"\}\}}ˆ | | |¡f||< q~|  ¡ D ]`\}}	t|ƒ}|j}
|D ]*\}}|| d }||< |rÄ|
|| 9 }
qÄ|
 t|ƒ|	f¡}
||
7 }qª|S )Nc                   s   ˆ | d  S rt  r5   )rú   ©Zgens_mapr5   r6   re   Ñ	  rf   z%PolyElement.compose.<locals>.<lambda>rg   z9expected a generator, value pair a sequence of such pairsr   )r7   r–   rL   rM   r0   r”   r}   rV   r?   r‰  rI   r·   rÌ   r»   rð   r�   r�  rm   )rk   r{  rc   r7   r›   Úreplacementsrú   rp  r³   r±   Zsubpolyr™   ræ   r5   rÔ  r6   râ   Æ	  s,    



zPolyElement.composec                   sh   | }|j  |¡‰‡ ‡fdd„| ¡ D ƒ}|s4|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 r5   r5   rD   ©Údegr™   r5   r6   r<   
  s      z)PolyElement.coeff_wrt.<locals>.<listcomp>c                   s,   g | ]$}|d ˆ … d |ˆ d d …  ‘qS )Nra   rª   r5   )r:   rE   ry  r5   r6   r<   
  s     )r7   rÇ   rð   r–   rM   rN   rL   )r˜   r{  r×  rÜ   ró   rŽ  rQ   r5   rÖ  r6   Ú	coeff_wrtæ	  s    *zPolyElement.coeff_wrtc                 C  sÒ   | }|j  |¡}| |¡}| |¡}|dk r4tdƒ‚|| }}||k rJ|S || d }| ||¡}	|j j| }
| ||¡}|| |d  }}||	 }|| |
|  }|| }| |¡}||k rnqÂqn|	| }|| S )aŽ  
        Pseudo-remainder of the polynomial ``self`` with respect to ``g``.

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

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


        Parameters
        ==========

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

        Returns
        =======

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

        Raises
        ======

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

        Examples
        ========

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

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

        See Also
        ========

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

        r   rW  rª   ©r7   rÇ   r|  rX  rØ  r0   )r˜   rp  r{  rk   ÚdfÚdgrl  Údrr³  Úlc_gÚxpÚlc_rrU  ÚRro  rF   r5   r5   r6   Úprem
  s,    6



zPolyElement.premc                 C  s  | }|j  |¡}| |¡}| |¡}|dk r4tdƒ‚|||  }}}||k rT||fS || d }	| ||¡}
|j j| }| ||¡}|| |	d  }}	||
 }||||   }||
 }|| ||  }|| }| |¡}||k rxqäqx|
|	 }|| }|| }||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   rW  rª   rÙ  )r˜   rp  r{  rk   rÚ  rÛ  ru  rl  rÜ  r³  rÝ  rÞ  rß  rU  ÚQrà  ro  rF   r5   r5   r6   Úpdivv
  s4    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   )rã  )r˜   rp  r{  rk   r5   r5   r6   Úpquoô
  s    zPolyElement.pquoc                 C  s,   | }|  ||¡\}}|jr|S t||ƒ‚dS )aë  
        Polynomial exact pseudo-quotient in multivariate polynomial ring.

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

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

        See Also
        ========

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

        N)rã  r2  r!   )r˜   rp  r{  rk   ru  rl  r5   r5   r6   Úpexquo  s
    zPolyElement.pexquoc                 C  sX  | }|j  |¡}| |¡}| |¡}||k r@|| }}|| }}|dkrPddgS |dkr`|dgS ||g}|| }d|d  }| ||¡}	|	| }	| ||¡}
|
| }d|g}| }|	�rT|	 |¡}| |	¡ ||	||| f\}}}}|
 ||  }| ||¡}	|	 |¡}	| ||¡}
|dk�r@|
 | }||d  }| |¡}n|
 }| | ¡ q²|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Æ   )r7   rÇ   r|  rá  rØ  r—   rv  )r˜   rp  r{  rk   ræ   rE   rà  Údrd   r±  ÚlcrF   ÚSrú   rÜ   ru  r5   r5   r6   Úsubresultants7  sF    "








zPolyElement.subresultantsc                 C  s   | j  | |¡S rU   )r7   Zdmp_half_gcdexr·  r5   r5   r6   Ú
half_gcdex”  s    zPolyElement.half_gcdexc                 C  s   | j  | |¡S rU   )r7   Z	dmp_gcdexr·  r5   r5   r6   Úgcdex—  s    zPolyElement.gcdexc                 C  s   | j  | |¡S rU   )r7   Zdmp_resultantr·  r5   r5   r6   Ú	resultantš  s    zPolyElement.resultantc                 C  s   | j  | ¡S rU   )r7   Zdmp_discriminantrj   r5   r5   r6   Údiscriminant�  s    zPolyElement.discriminantc                 C  s    | j jr| j  | ¡S tdƒ‚d S )Nzpolynomial decomposition)r7   rÖ   Zdup_decomposer"   rj   r5   r5   r6   Ú	decompose   s    zPolyElement.decomposec                 C  s"   | j jr| j  | |¡S tdƒ‚d S )Nzshift: use shift_list instead)r7   rÖ   Z	dup_shiftr"   ©rk   rc   r5   r5   r6   Úshift¦  s    zPolyElement.shiftc                 C  s   | j  | |¡S rU   )r7   Z	dmp_shiftrï  r5   r5   r6   Ú
shift_list¬  s    zPolyElement.shift_listc                 C  s    | j jr| j  | ¡S tdƒ‚d S )Nzsturm sequence)r7   rÖ   Z	dup_sturmr"   rj   r5   r5   r6   Ústurm¯  s    zPolyElement.sturmc                 C  s   | j  | ¡S rU   )r7   Zdmp_gff_listrj   r5   r5   r6   Úgff_listµ  s    zPolyElement.gff_listc                 C  s   | j  | ¡S rU   )r7   Zdmp_normrj   r5   r5   r6   Únorm¸  s    zPolyElement.normc                 C  s   | j  | ¡S rU   )r7   Zdmp_sqf_normrj   r5   r5   r6   Úsqf_norm»  s    zPolyElement.sqf_normc                 C  s   | j  | ¡S rU   )r7   Zdmp_sqf_partrj   r5   r5   r6   Úsqf_part¾  s    zPolyElement.sqf_partFc                 C  s   | j j| |d�S )N)r\   )r7   Zdmp_sqf_list)rk   r\   r5   r5   r6   Úsqf_listÁ  s    zPolyElement.sqf_listc                 C  s   | j  | ¡S rU   )r7   Zdmp_factor_listrj   r5   r5   r6   Úfactor_listÄ  s    zPolyElement.factor_list)N)N)N)N)N)N)N)N)N)N)N)N)N)N)F)˜rr   rè   ré   rê   rî   rï   r�   rz   r£   rŸ   rô   rö   rõ   r  r  r¦   r§   r	  r  r  r  r  r  r  r  rÎ   r  rÞ   r  r  rW   rë   r+  r  r-  r.  r!  r/  r0  r1  r2  r3  r4  r6  r<  r>  r@  rA  rB  rC  rD  rF  rE  rH  rG  rL  rI  rR  rQ  rP  rO  r]  rY  ra  r`  rd  rc  Ú__floordiv__Ú__rfloordiv__rh  rˆ   r_  rb  rv  rj  rk  r|  r}  r  r€  r�   r‚  r±   r
  r,  rƒ  r…  rn  r†  rŠ  rQ   rŽ  ró   r�  r;  rð   r‘  r’  r“  rS  r5  r–  r—  r  r›  r�  rZ  r¢  r¥  r[  r¨  r«  r¬  r­  r´  rµ  rŠ   r‹   r¶  r¸  r¹  rº  rÀ  r¿  rÄ  rÁ  rÆ  rì   rÇ  rÌ  rÓ  râ   rØ  rá  rã  rä  rå  ré  rê  rë  rì  rí  rî  rð  rñ  rò  ró  rô  rõ  rö  r÷  rø  r5   r5   r5   r6   r`   <  sP  	0
















6620$!L-,%%


#!	
8,'m 5[~%]r`   N)Qrê   Ú
__future__r   Útypingr   Úoperatorr   r   r   r   r   r	   Ú	functoolsr
   Útypesr   Zsympy.core.exprr   Zsympy.core.intfuncr   Zsympy.core.symbolr   r   r[   Zsympy.core.sympifyr   r   Zsympy.ntheory.multinomialr   Zsympy.polys.compatibilityr   Zsympy.polys.constructorr   Zsympy.polys.densebasicr   r   r   Z!sympy.polys.domains.domainelementr   Z"sympy.polys.domains.polynomialringr   Zsympy.polys.heuristicgcdr   Zsympy.polys.monomialsr   Zsympy.polys.orderingsr   Zsympy.polys.polyerrorsr   r    r!   r"   Zsympy.polys.polyoptionsr#   ro   r$   rq   r%   Zsympy.polys.polyutilsr&   r'   r(   Zsympy.printing.defaultsr)   Zsympy.utilitiesr*   r+   Zsympy.utilities.iterablesr,   Zsympy.utilities.magicr-   r7   r8   r=   rS   r^   r_   Ú__annotations__r/   rL   r`   r5   r5   r5   r6   Ú<module>   sN    
4  z