U
    ZÊ¹jî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   úP/var/www/html/bwave/python/venv/lib/python3.8/site-packages/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)
Zexprsr   ÚoptionsZsinglerC   ZrepsÚcoeffsZ
coeffs_domr4   Úpolysr5   rG   r6   Úsring€   s     

rR   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 rT   )rU   r   rW   r5   r5   r6   rY   ½   s     zbexpected a string, Symbol or expression or a non-empty sequence of strings, Symbols or expressions)rU   rV   Ú_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 ra   r5   )rb   rc   rF   r5   r5   r6   rd   ñ   re   c                   s   t | ˆ d�S )N©Úkey)Úmax©Úf©r3   r5   r6   rd   û   re   )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   rh   Úleading_expvrM   rU   r   r9   ÚhasattrÚsetattr)Úclsr   r2   r3   r|   rw   ÚobjZcodegenZmonunitÚsymbolÚ	generatorr9   r5   rk   r6   rv   Ç   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Úappendrl   )Úselfr€   r~   ÚiÚexpvÚpolyr5   r5   r6   r~     s    
zPolyRing._gensc                 C  s   | j | j| jfS rT   )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—   Ústaterg   r5   r5   r6   Ú__getstate__  s    

zPolyRing.__getstate__c                 C  s   | j S rT   )ry   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 rT   )rU   r/   r   r2   r|   r3   ©r—   Úotherr5   r5   r6   Ú__eq__#  s
    
ÿÿzPolyRing.__eq__c                 C  s
   | |k S rT   r5   r£   r5   r5   r6   Ú__ne__(  s    zPolyRing.__ne__Nc                 C  s    |   |p| j|p| j|p| j¡S rT   )Ú	__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|   rl   )r—   r˜   Zbasisr5   r5   r6   r”   .  s    zPolyRing.monomial_basisc                 C  s   |   ¡ S rT   )r{   r›   r5   r5   r6   r•   4  s    zPolyRing.zeroc                 C  s   |   | j¡S rT   )r{   r�   r›   r5   r5   r6   r€   8  s    zPolyRing.onec                 C  s   | j  ||¡S rT   )r2   Úconvert©r—   ÚelementÚorig_domainr5   r5   r6   Ú
domain_new<  s    zPolyRing.domain_newc                 C  s   |   | j|¡S rT   )Úterm_newr}   )r—   Úcoeffr5   r5   r6   Ú
ground_new?  s    zPolyRing.ground_newc                 C  s    |   |¡}| j}|r|||< |S rT   )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)rU   r_   r7   r2   r   r±   ÚNotImplementedErrorrV   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 rT   )r®   r•   rI   )r—   r¬   r­   r®   rš   r²   r°   r5   r5   r6   rN   a  s    

zPolyRing.from_dictc                 C  s   |   t|ƒ|¡S rT   )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»   )rr   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|   rU   r½   r¶   r{   r0   ÚindexrV   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˜   rX   ©Úindicesr5   r6   r<   µ  s      z!PolyRing.drop.<locals>.<listcomp>r\   N)rt   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—   rg   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   rs   r�   r¨   r¶   r›   r5   r5   r6   Ú	to_groundÄ  s    zPolyRing.to_groundc                 C  s   t | ƒS rT   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»   ©rm   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—   Z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)rt   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©rt   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 rT   )r½   ©r:   r˜   ©rX   r5   r6   rY   7  s     z*PolyRing.symmetric_poly.<locals>.<genexpr>N)r|   r¶   r0   r€   r•   r+   r“   r½   rl   r¯   r2   )r—   Únrš   r²   r5   rã   r6   Úsymmetric_poly+  s    zPolyRing.symmetric_poly)NNN)N)N)N))rq   Ú
__module__Ú__qualname__Ú__doc__r   rv   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 rT   )r§   )r—   Úinitr5   r5   r6   Únew?  s    zPolyElement.newc                 C  s
   | j  ¡ S rT   )r7   rÑ   r›   r5   r5   r6   ÚparentB  s    zPolyElement.parentc                 C  s   | j t|  ¡ ƒfS rT   )r7   r?   Ú	itertermsr›   r5   r5   r6   rœ   E  s    zPolyElement.__getnewargs__Nc                 C  s.   | j }|d kr*t| jt|  ¡ ƒfƒ | _ }|S rT   )ry   rx   r7   Ú	frozensetrI   )r—   ry   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 rT   )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   rm   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)rU   r_   r7   rL   r¥   rm   rr   r}   ©Úp1Úp2r5   r5   r6   r¥      s    zPolyElement.__eq__c                 C  s
   | |k S rT   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   rU   r{   rt   Úkeysr2   Úalmosteqrm   rª   r   Úconst)r  r  Z	tolerancer7   r  rø   r5   r5   r6   r  ½  s     zPolyElement.almosteqc                 C  s   t | ƒ|  ¡ fS rT   )rm   rñ   r›   r5   r5   r6   Úsort_keyÕ  s    zPolyElement.sort_keyc                 C  s(   t || jjƒr ||  ¡ | ¡ ƒS tS d S rT   )rU   r7   r{   r	  ÚNotImplemented)r  r  Úopr5   r5   r6   Ú_cmpØ  s    zPolyElement._cmpc                 C  s   |   |t¡S rT   )r  r   r  r5   r5   r6   Ú__lt__Þ  s    zPolyElement.__lt__c                 C  s   |   |t¡S rT   )r  r   r  r5   r5   r6   Ú__le__à  s    zPolyElement.__le__c                 C  s   |   |t¡S rT   )r  r   r  r5   r5   r6   Ú__gt__â  s    zPolyElement.__gt__c                 C  s   |   |t¡S rT   )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?   rl   )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 rT   )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   rV   &  sT    





zPolyElement.strc                 C  s   | | j jkS rT   )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»   )rm   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»   )rm   ÚLCr›   r5   r5   r6   Úis_monomial^  s    zPolyElement.is_monomialc                 C  s   t | ƒdkS r»   )rm   r›   r5   r5   r6   Úis_termb  s    zPolyElement.is_termc                 C  s   | j j | j¡S rT   )r7   r2   r  r*  r›   r5   r5   r6   r  f  s    zPolyElement.is_negativec                 C  s   | j j | j¡S rT   )r7   r2   Úis_positiver*  r›   r5   r5   r6   r-  j  s    zPolyElement.is_positivec                 C  s   | j j | j¡S rT   )r7   r2   Úis_nonnegativer*  r›   r5   r5   r6   r.  n  s    zPolyElement.is_nonnegativec                 C  s   | j j | j¡S rT   )r7   r2   Úis_nonpositiver*  r›   r5   r5   r6   r/  r  s    zPolyElement.is_nonpositivec                 C  s   |  S rT   r5   ri   r5   r5   r6   Úis_zerov  s    zPolyElement.is_zeroc                 C  s   | | j jkS rT   )r7   r€   ri   r5   r5   r6   Úis_onez  s    zPolyElement.is_onec                 C  s   | j j | j¡S rT   )r7   r2   r1  r*  ri   r5   r5   r6   Úis_monic~  s    zPolyElement.is_monicc                 C  s   | j j |  ¡ ¡S rT   )r7   r2   r1  Úcontentri   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   rY   ˆ  s     z(PolyElement.is_linear.<locals>.<genexpr>©r[   Ú
itermonomsri   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 )é   Nr6  r7  r5   r5   r6   rY   Œ  s     z+PolyElement.is_quadratic.<locals>.<genexpr>r8  ri   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_pri   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_pri   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"   ri   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 rT   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   rU   r{   rr   r2   r•   rI   r_   r   Ú__radd__r
  r®   r   r}   r  )
r  r  r7   rÚ   rr   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 rT   )rž   r7   r®   r   r
  r}   r  )r  rä   rÚ   r7   r%  r5   r5   r6   rC  Ý  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   rU   r{   rr   r2   r•   rI   r_   r   Ú__rsub__r
  r®   r   r}   r  )	r  r  r7   rÚ   rr   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   rE  '  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•   rU   r{   rr   r2   r‚   r?   rI   r  r_   r   Ú__rmul__r
  r®   r   )r  r  r7   rÚ   rr   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Ú   rH  rI  rù   r5   r5   r6   rG  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¶   rm   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€   rM  )r—   rä   rÚ   rF   r5   r5   r6   rO  Á  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 rT   )r   rm   rI   r7   r…   r}   r2   r•   rM   rl   rr   )r—   rä   Zmultinomialsr…   r}   rñ   r•   rš   ZmultinomialZmultinomial_coeffZproduct_monomZproduct_coeffrÀ   r²   r°   r5   r5   r6   rN  Ñ  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•   rr   r?   r  r2   r‚   r“   rm   Úimul_numrI   r  )r—   r7   rÚ   rr   r  r•   r‚   r˜   Zk1ÚpkÚjZk2rÀ   rø   rù   r5   r5   r6   rM  î  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   ÚZeroDivisionErrorrU   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 rT   ©r
  r  r5   r5   r6   rW  (  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 rT  )r7   rV  rU   r{   Úremr_   r2   r   Ú__rmod__r
  r®   r   rY  rZ  r5   r5   r6   Ú__mod__+  s     




zPolyElement.__mod__c                 C  s   t S rT   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 )NrU  rÅ   )r7   rV  rU   r{   r+  Úquor_   r2   r   Ú__rtruediv__r
  r®   r   rX  rZ  r5   r5   r6   Ú__truediv__D  s$    



zPolyElement.__truediv__c                 C  s   t S rT   r\  r  r5   r5   r6   ra  ]  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 rT   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 rT   r5   rc  rd  r5   r6   re  x  s    
)r7   r}   r2   r`  rˆ   rü   )r—   r2   re  r5   rd  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

        FTrU  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   rU   r_   r[   rV  r•   r¶   rm   r“   rž   rf  rŒ   Ú_iadd_monomÚ_iadd_poly_monomr}   )r—   ZfvZ
ret_singlerj   rX   ZqvrÚ   Úrre  Zexpvsr˜   Zdivoccurredr™   ÚtermZexpv1rF   r5   rg  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 rT  )rU   r_   r[   rV  r7   r2   r•   r‚   rf  ÚLTrž   rr   rî   rŒ   )r—   ÚGrj   r7   r2   r•   r‚   rj  re  Zltfrr   ÚgZtqrE   rF   ÚmgÚcgÚm1Úc1ZltmZltcr5   r5   r6   r]  Ò  sL    



zPolyElement.remc                 C  s   |   |¡d S ©Nr   )r‡   )rj   rm  r5   r5   r6   r`  ÿ  s    zPolyElement.quoc                 C  s$   |   |¡\}}|s|S t| |ƒ‚d S rT   )r‡   r!   )rj   rm  Úqrj  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ž   rr   )r—   ÚmcZcpselfr™   r°   rF   r5   r5   r6   rh  
  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ž   rr   r2   r•   r‚   rI   )r—   r  rv  r  rE   rF   rr   r•   r‚   rø   rù   Úkar°   r5   r5   r6   ri  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 rT   r5   r7  ©r˜   r5   r6   rY   i  s     z%PolyElement.degree.<locals>.<genexpr>N)r7   rÆ   r   rh   r9  ©rj   Úxr5   rx  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|   rl   rJ   rh   r?   rM   r9  ri   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 rT   r5   r7  rx  r5   r6   rY   …  s     z*PolyElement.tail_degree.<locals>.<genexpr>N)r7   rÆ   r   Úminr9  ry  r5   rx  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|   rl   rJ   r}  r?   rM   r9  ri   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 rT   )rr   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}   rU   r{   r?   rî   rm   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 rT   )r�  rŒ   r›   r5   r5   r6   r*  Ó  s    zPolyElement.LCc                 C  s    |   ¡ }|d kr| jjS |S d S rT   )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 rT   )rŒ   r7   r}   r2   r•   r�  r€  r5   r5   r6   rl  ô  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 rs  r5   ©r²   r5   r5   r6   rd     re   z%PolyElement._sorted.<locals>.<lambda>T)rg   Úreversec                   s   ˆ | d ƒS rs  r5   r†  rk   r5   r6   rd     re   )r7   r3   rp   ro   r   Úsorted)r—   rS   r3   r5   rk   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   rP     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   r9  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   rQ  �  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�  )rj   r2   ÚcontrŠ   r°   r5   r5   r6   r3  ¤  s    zPolyElement.contentc                 C  s   |   ¡ }||  |¡fS )z,Returns content and a primitive polynomial. )r3  rX  )rj   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)rX  r*  ri   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õ   ©rz  r5   r6   r<   ¿  s     z*PolyElement.mul_ground.<locals>.<listcomp>)r7   r•   rî   rì   )rj   rz  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ì   )rj   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ì   )rj   rk  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 )NrU  c                   s   g | ]\}}|ˆ |ˆƒf‘qS r5   r5   rõ   ©r`  rz  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   rV  r€   rü   r`  rî   rì   )rj   rz  r2   rñ   r5   r�  r6   rX  Ó  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 )NrU  c                   s   g | ]}ˆ|ˆ ƒ‘qS r5   r5   ©r:   Út©rk  re  r5   r6   r<   ï  s     z(PolyElement.quo_term.<locals>.<listcomp>c                 S  s   g | ]}|d k	r|‘qS rT   r5   rž  r5   r5   r6   r<   ð  s      )rV  r7   r•   r}   rX  rf  rî   rì   )rj   rk  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  )rj   rÚ   rñ   r²   r°   rš   r5   r¢  r6   Útrunc_groundò  s    

zPolyElement.trunc_groundc                 C  sB   | }|  ¡ }|  ¡ }|jj ||¡}| |¡}| |¡}|||fS rT   )r3  r7   r2   rŠ   rX  )r—   rn  rj   Ú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�  )rj   Z	norm_funcr5   r¨  r6   Ú_norm  s    

zPolyElement._normc                 C  s
   |   t¡S rT   )rª  rh   ri   r5   r5   r6   Úmax_norm  s    zPolyElement.max_normc                 C  s
   |   t¡S rT   )rª  rK   ri   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 r5  r5   )r:   rc   r5   r5   r6   rY   0  s     z&PolyElement.deflate.<locals>.<genexpr>c                 S  s   g | ]\}}|| ‘qS r5   r5   ©r:   r˜   rS  r5   r5   r6   r<   9  s     z'PolyElement.deflate.<locals>.<listcomp>)r7   r?   r|   r9  rË   r   rl   r[   r•   rî   rM   r–   )rj   rm  r7   rQ   ÚJrÚ   r²   r˜   rE   rc   Ú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   rl   )rj   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 rT   )	r7   r2   rü   r•  r‰   r`  rŠ   r  r–  )r—   rn  rj   r2   r¥  r¦  rF   r°  r5   r5   r6   r‰   I  s    
zPolyElement.lcmc                 C  s   |   |¡d S rs  )Ú	cofactors©rj   rn  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_zerorm   Ú
_gcd_monomr³  Ú_gcdr´  )rj   rn  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 rT   )r7   r€   r•   r.  )rj   rn  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:   ro  rp  ©Z_cgcdZ_mgcdZ
ground_quor†   r5   r6   r<   †  s     z*PolyElement._gcd_monom.<locals>.<listcomp>)	r7   r2   rŠ   r`  r‹   r†   r?   rî   rì   )rj   rn  r7   Z
ground_gcdr‹   ÚmfÚcfro  rp  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 rT   )r7   r2   Zis_QQÚ_gcd_QQr£  Ú_gcd_ZZZdmp_inner_gcd)rj   rn  r7   r5   r5   r6   r¹  ‰  s    

zPolyElement._gcdc                 C  s
   t | |ƒS rT   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  r`  )r—   rn  rj   r7   rð   r¾  rp  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—   rn  rj   r7   r2   rŠ  rÚ   rt  rð   ZcqÚcpÚur5   r5   r6   Úcancel«  s4    









zPolyElement.cancelc                 C  s   | j j}| | j¡S rT   )r7   r2   rÁ  r*  )rj   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®   )	rj   rz  r7   r˜   rE   rn  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)rm   r7   r|   Úevaluater?   rM   r0   r¶   )rj   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:   ÚYrb   ©ÚXr5   r6   r<   	  s     z(PolyElement.evaluate.<locals>.<listcomp>)rU   r?   rÇ  r7   rÆ   r2   rª   r|   r•   rî   rÍ   )r—   rz  rb   rj   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©   r`   )rU   r?   Úsubsr7   rÆ   r2   rª   r|   r•   rî   r±   )r—   rz  rb   rj   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â   rg  r5   r6   r<   ›	  s     z*PolyElement.symmetrize.<locals>.<listcomp>c                   s,   | |fˆ kr ˆ|  | ˆ | |f< ˆ | |f S rT   r5   )r˜   rä   )Úpoly_powersrQ   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 r5  r5   râ   r†  r5   r6   rY   ¬	  s     z)PolyElement.symmetrize.<locals>.<genexpr>c                 s  s   | ]\}}|| V  qd S rT   r5   )r:   rä   rE   r5   r5   r6   rY   ­	  s     Nr`   )rž   r7   r|   r•   r“   r?   rË   rñ   r[   rh   rM   r–   r¯   rl   r0   )r—   rj   rä   rÎ  rÊ   ÚweightsZ	symmetricÚ_heightZ_monomZ_coeffr˜   r°   ÚheightZ	exponentsrq  Úm2ÚproductrÃ   r5   )r²   rÍ  rQ   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 rs  r5   )rø   ©Zgens_mapr5   r6   rd   Ñ	  re   z%PolyElement.compose.<locals>.<lambda>rf   z9expected a generator, value pair a sequence of such pairsr   )r7   r•   rL   rM   r0   r“   r|   rU   r?   rˆ  rI   r¶   rË   rº   rî   r€   rœ  rl   )rj   rz  rb   r7   rš   Zreplacementsrø   rn  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 )Nr`   r©   r5   )r:   rE   rx  r5   r6   r<   
  s     )r7   rÆ   rî   r•   rM   rN   rL   )r—   rz  r×  rÚ   rñ   r�  rP   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   rU  r©   ©r7   rÆ   r{  rV  rØ  r0   )r—   rn  rz  rj   ÚdfÚdgrj  Údrr²  Úlc_gÚxpÚlc_rrS  ÚRrm  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   rU  r©   rÙ  )r—   rn  rz  rj   rÚ  rÛ  rt  rj  rÜ  r²  rÝ  rÞ  rß  rS  ÚQrà  rm  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—   rn  rz  rj   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ã  r0  r!   )r—   rn  rz  rj   rt  rj  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–   ru  )r—   rn  rz  rj   rä   rE   rà  Údrc   r°  ÚlcrF   ÚSrø   rÚ   rt  r5   r5   r6   Úsubresultants7  sF    "








zPolyElement.subresultantsc                 C  s   | j  | |¡S rT   )r7   Zdmp_half_gcdexr¶  r5   r5   r6   Ú
half_gcdex”  s    zPolyElement.half_gcdexc                 C  s   | j  | |¡S rT   )r7   Z	dmp_gcdexr¶  r5   r5   r6   Úgcdex—  s    zPolyElement.gcdexc                 C  s   | j  | |¡S rT   )r7   Zdmp_resultantr¶  r5   r5   r6   Ú	resultantš  s    zPolyElement.resultantc                 C  s   | j  | ¡S rT   )r7   Zdmp_discriminantri   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"   ri   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"   ©rj   rb   r5   r5   r6   Úshift¦  s    zPolyElement.shiftc                 C  s   | j  | |¡S rT   )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"   ri   r5   r5   r6   Ústurm¯  s    zPolyElement.sturmc                 C  s   | j  | ¡S rT   )r7   Zdmp_gff_listri   r5   r5   r6   Úgff_listµ  s    zPolyElement.gff_listc                 C  s   | j  | ¡S rT   )r7   Zdmp_normri   r5   r5   r6   Únorm¸  s    zPolyElement.normc                 C  s   | j  | ¡S rT   )r7   Zdmp_sqf_normri   r5   r5   r6   Úsqf_norm»  s    zPolyElement.sqf_normc                 C  s   | j  | ¡S rT   )r7   Zdmp_sqf_partri   r5   r5   r6   Úsqf_part¾  s    zPolyElement.sqf_partFc                 C  s   | j j| |d�S )N)r[   )r7   Zdmp_sqf_list)rj   r[   r5   r5   r6   Úsqf_listÁ  s    zPolyElement.sqf_listc                 C  s   | j  | ¡S rT   )r7   Zdmp_factor_listri   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)˜rq   ræ   rç   rè   rì   rí   rœ   ry   r¢   rž   rò   rô   ró   r   r  r¥   r¦   r  r	  r  r  r  r  r  r  rÍ   r  rÜ   r  r  rV   ré   r)  r  r+  r,  r  r-  r.  r/  r0  r1  r2  r4  r:  r<  r>  r?  r@  rA  rB  rD  rC  rF  rE  rJ  rG  rP  rO  rN  rM  r[  rW  r_  r^  rb  ra  Ú__floordiv__Ú__rfloordiv__rf  r‡   r]  r`  ru  rh  ri  r{  r|  r~  r  rŒ   r�  r°   r  r*  r‚  r„  rl  r…  r‰  rP   r�  rñ   r�  r9  rî   r�  r‘  r’  rQ  r3  r•  r–  r  rš  rœ  rX  r¡  r¤  rY  r§  rª  r«  r¬  r³  r´  r‰   rŠ   rµ  r·  r¸  r¹  rÀ  r¿  rÄ  rÁ  rÆ  rê   rÇ  rÌ  rÔ  rà   rØ  rá  rã  rä  rå  ré  rê  rë  rì  rí  rî  rð  rñ  rò  ró  rô  rõ  rö  r÷  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   rZ   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#   rn   r$   rp   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=   rR   r]   r^   Ú__annotations__r/   rL   r_   r5   r5   r5   r6   Ú<module>   sN    
4  z