o
    #ôjO  ã                   @   sR   d Z ddlmZ ddlmZ ddlmZmZ ddlm	Z	 e	G dd„ deeƒƒZ
dS )	z1Implementation of :class:`PolynomialRing` class. é    )ÚRing)ÚCompositeDomain)ÚCoercionFailedÚGeneratorsError)Úpublicc                   @   sN  e Zd ZdZd ZZdZdZdLdd„Zdd„ Z	dd	„ Z
ed
d„ ƒZedd„ ƒZedd„ ƒZdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Z d4d5„ Z!d6d7„ Z"d8d9„ Z#d:d;„ Z$d<d=„ Z%d>d?„ Z&d@dA„ Z'dBdC„ Z(dDdE„ Z)dFdG„ Z*dHdI„ Z+dJdK„ Z,dS )MÚPolynomialRingz8A class for representing multivariate polynomial rings. TNc                 C   s˜   ddl m} t||ƒr|d u r|d u r|}n||||ƒ}|| _|j| _|j| _|j| _|j| _|j| _|rF|jj	rF|jj
rFt|ƒdkrFd| _| j| _d S )Nr   )ÚPolyRingé   T)Úsympy.polys.ringsr   Ú
isinstanceÚringÚdtypeÚgensÚngensÚsymbolsÚdomainÚis_FieldÚis_ExactÚlenÚis_PIDÚdom)ÚselfZdomain_or_ringr   Úorderr   r   © r   ús/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/sympy/polys/domains/polynomialring.pyÚ__init__   s   zPolynomialRing.__init__c                 C   ó   | j  |¡S ©N)r   Zring_new©r   Úelementr   r   r   Únew+   s   zPolynomialRing.newc                 C   r   )z%Check if ``a`` is of type ``dtype``. )r   Z
is_elementr   r   r   r   Úof_type.   ó   zPolynomialRing.of_typec                 C   ó   | j jS r   )r   Úzero©r   r   r   r   r$   2   ó   zPolynomialRing.zeroc                 C   r#   r   )r   Úoner%   r   r   r   r'   6   r&   zPolynomialRing.onec                 C   r#   r   )r   r   r%   r   r   r   r   :   r&   zPolynomialRing.orderc                 C   s$   t | jƒd d tt | jƒ¡ d S )NÚ[ú,Ú])Ústrr   ÚjoinÚmapr   r%   r   r   r   Ú__str__>   s   $zPolynomialRing.__str__c                 C   s   t | jj| j| j| jfƒS r   )ÚhashÚ	__class__Ú__name__r   r   r   r%   r   r   r   Ú__hash__A   s   zPolynomialRing.__hash__c                 C   s   t |tƒstS | j|jkS )z.Returns `True` if two domains are equivalent. )r   r   ÚNotImplementedr   )r   Úotherr   r   r   Ú__eq__D   s   
zPolynomialRing.__eq__c                 C   s"   |j sdS | j}| | || ¡¡S )z/Returns ``True`` if ``a`` is a unit of ``self``F)Ú	is_groundr   Úis_unitÚconvert_from)r   ÚaÚKr   r   r   r7   J   s   zPolynomialRing.is_unitc                 C   s   | j  |j¡}| j |¡S r   )r   Úcanonical_unitÚLCr   Ú
ground_new)r   r9   Úur   r   r   r;   Q   s   zPolynomialRing.canonical_unitc                 C   s   |  ¡ S )zConvert `a` to a SymPy object. )Úas_expr©r   r9   r   r   r   Úto_sympyU   r&   zPolynomialRing.to_sympyc                 C   r   )z'Convert SymPy's expression to `dtype`. )r   Ú	from_exprr@   r   r   r   Ú
from_sympyY   r"   zPolynomialRing.from_sympyc                 C   ó   | | j  ||¡ƒS ©z*Convert a Python `int` object to `dtype`. ©r   Úconvert©ÚK1r9   ÚK0r   r   r   Úfrom_ZZ]   ó   zPolynomialRing.from_ZZc                 C   rD   rE   rF   rH   r   r   r   Úfrom_ZZ_pythona   rL   zPolynomialRing.from_ZZ_pythonc                 C   rD   ©z/Convert a Python `Fraction` object to `dtype`. rF   rH   r   r   r   Úfrom_QQe   rL   zPolynomialRing.from_QQc                 C   rD   rN   rF   rH   r   r   r   Úfrom_QQ_pythoni   rL   zPolynomialRing.from_QQ_pythonc                 C   rD   )z(Convert a GMPY `mpz` object to `dtype`. rF   rH   r   r   r   Úfrom_ZZ_gmpym   rL   zPolynomialRing.from_ZZ_gmpyc                 C   rD   )z(Convert a GMPY `mpq` object to `dtype`. rF   rH   r   r   r   Úfrom_QQ_gmpyq   rL   zPolynomialRing.from_QQ_gmpyc                 C   rD   )z/Convert a `GaussianInteger` object to `dtype`. rF   rH   r   r   r   Úfrom_GaussianIntegerRingu   rL   z'PolynomialRing.from_GaussianIntegerRingc                 C   rD   )z0Convert a `GaussianRational` object to `dtype`. rF   rH   r   r   r   Úfrom_GaussianRationalFieldy   rL   z)PolynomialRing.from_GaussianRationalFieldc                 C   rD   ©z*Convert a mpmath `mpf` object to `dtype`. rF   rH   r   r   r   Úfrom_RealField}   rL   zPolynomialRing.from_RealFieldc                 C   rD   rU   rF   rH   r   r   r   Úfrom_ComplexField�   rL   z PolynomialRing.from_ComplexFieldc                 C   s.   | j |kr| j  ||¡}|dur|  |¡S dS )z*Convert an algebraic number to ``dtype``. N)r   r8   r    rH   r   r   r   Úfrom_AlgebraicField…   s
   

ÿz"PolynomialRing.from_AlgebraicFieldc              	   C   s(   z|  | j¡W S  ttfy   Y dS w )z#Convert a polynomial to ``dtype``. N)Zset_ringr   r   r   rH   r   r   r   Úfrom_PolynomialRingŒ   s
   ÿz"PolynomialRing.from_PolynomialRingc                 C   sP   | j |kr| j |g¡S | |¡ | |¡¡\}}|jr&|  ||jj 	¡ ¡S dS )z*Convert a rational function to ``dtype``. N)
r   r   Ú	from_listÚnumerÚdivÚdenomÚis_zerorY   ÚfieldÚ	to_domain)rI   r9   rJ   ÚqÚrr   r   r   Úfrom_FractionField“   s   
z!PolynomialRing.from_FractionFieldc                    sl   ˆ j |jkr| ¡ }ˆ j|jkr‡ fdd„| ¡ D ƒ}ˆ |ƒS |jr2|jˆ kr4ˆ  | ¡ d |j¡S dS dS )z)Convert from old poly ring to ``dtype``. c                    s   i | ]\}}|ˆ j  |¡“qS r   rF   )Ú.0ÚmÚc©rI   r   r   Ú
<dictcomp>¤   s    z<PolynomialRing.from_GlobalPolynomialRing.<locals>.<dictcomp>r   N)r   r   Úto_dictr   Úitemsr6   r8   Úto_list)rI   r9   rJ   Úadr   rg   r   Úfrom_GlobalPolynomialRingŸ   s   ÿz(PolynomialRing.from_GlobalPolynomialRingc                 C   s   | j  ¡  ¡ S )z(Returns a field associated with `self`. )r   Úto_fieldr`   r%   r   r   r   Ú	get_field©   ó   zPolynomialRing.get_fieldc                 C   ó   | j  |j¡S )z%Returns True if `LC(a)` is positive. )r   Úis_positiver<   r@   r   r   r   rr   ­   rp   zPolynomialRing.is_positivec                 C   rq   )z%Returns True if `LC(a)` is negative. )r   Úis_negativer<   r@   r   r   r   rs   ±   rp   zPolynomialRing.is_negativec                 C   rq   )z)Returns True if `LC(a)` is non-positive. )r   Úis_nonpositiver<   r@   r   r   r   rt   µ   rp   zPolynomialRing.is_nonpositivec                 C   rq   )z)Returns True if `LC(a)` is non-negative. )r   Úis_nonnegativer<   r@   r   r   r   ru   ¹   rp   zPolynomialRing.is_nonnegativec                 C   ó
   |  |¡S )zExtended GCD of `a` and `b`. )Úgcdex©r   r9   Úbr   r   r   rw   ½   ó   
zPolynomialRing.gcdexc                 C   rv   )zReturns GCD of `a` and `b`. )Úgcdrx   r   r   r   r{   Á   rz   zPolynomialRing.gcdc                 C   rv   )zReturns LCM of `a` and `b`. )Úlcmrx   r   r   r   r|   Å   rz   zPolynomialRing.lcmc                 C   s   |   | j |¡¡S )zReturns factorial of `a`. )r   r   Ú	factorialr@   r   r   r   r}   É   rL   zPolynomialRing.factorial)NN)-r1   Ú
__module__Ú__qualname__Ú__doc__Úis_PolynomialRingÚis_PolyÚhas_assoc_RingÚhas_assoc_Fieldr   r    r!   Úpropertyr$   r'   r   r.   r2   r5   r7   r;   rA   rC   rK   rM   rO   rP   rQ   rR   rS   rT   rV   rW   rX   rY   rc   rm   ro   rr   rs   rt   ru   rw   r{   r|   r}   r   r   r   r   r   
   sX    




r   N)r€   Úsympy.polys.domains.ringr   Z#sympy.polys.domains.compositedomainr   Úsympy.polys.polyerrorsr   r   Úsympy.utilitiesr   r   r   r   r   r   Ú<module>   s    