a
    kº”hO  ã                   @   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| _|rŒ|jj	rŒ|jj
rŒt|ƒdkrŒd| _| j| _d S )Nr   )ÚPolyRingé   T)Zsympy.polys.ringsr   Ú
isinstanceÚringÚdtypeÚgensZngensÚsymbolsÚdomainZis_FieldZis_ExactÚlenZis_PIDÚdom)ÚselfZdomain_or_ringr   Úorderr   r   © r   úP/var/www/auris/lib/python3.9/site-packages/sympy/polys/domains/polynomialring.pyÚ__init__   s    zPolynomialRing.__init__c                 C   s   | j  |¡S ©N)r   Zring_new©r   Úelementr   r   r   Únew+   s    zPolynomialRing.newc                 C   s   | j  |¡S )z%Check if ``a`` is of type ``dtype``. )r   Z
is_elementr   r   r   r   Úof_type.   s    zPolynomialRing.of_typec                 C   s   | j jS r   )r   Úzero©r   r   r   r   r   2   s    zPolynomialRing.zeroc                 C   s   | j jS r   )r   Úoner   r   r   r   r   6   s    zPolynomialRing.onec                 C   s   | j jS r   )r   r   r   r   r   r   r   :   s    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   r.   J   s    zPolynomialRing.is_unitc                 C   s   | j  |j¡}| j |¡S r   )r   Úcanonical_unitÚLCr   Z
ground_new)r   r0   Úur   r   r   r2   Q   s    zPolynomialRing.canonical_unitc                 C   s   |  ¡ S )zConvert `a` to a SymPy object. )Zas_expr©r   r0   r   r   r   Úto_sympyU   s    zPolynomialRing.to_sympyc                 C   s   | j  |¡S )z'Convert SymPy's expression to `dtype`. )r   Z	from_exprr5   r   r   r   Ú
from_sympyY   s    zPolynomialRing.from_sympyc                 C   s   | | j  ||¡ƒS ©z*Convert a Python `int` object to `dtype`. ©r   Úconvert©ÚK1r0   ÚK0r   r   r   Úfrom_ZZ]   s    zPolynomialRing.from_ZZc                 C   s   | | j  ||¡ƒS r8   r9   r;   r   r   r   Úfrom_ZZ_pythona   s    zPolynomialRing.from_ZZ_pythonc                 C   s   | | j  ||¡ƒS ©z/Convert a Python `Fraction` object to `dtype`. r9   r;   r   r   r   Úfrom_QQe   s    zPolynomialRing.from_QQc                 C   s   | | j  ||¡ƒS r@   r9   r;   r   r   r   Úfrom_QQ_pythoni   s    zPolynomialRing.from_QQ_pythonc                 C   s   | | j  ||¡ƒS )z(Convert a GMPY `mpz` object to `dtype`. r9   r;   r   r   r   Úfrom_ZZ_gmpym   s    zPolynomialRing.from_ZZ_gmpyc                 C   s   | | j  ||¡ƒS )z(Convert a GMPY `mpq` object to `dtype`. r9   r;   r   r   r   Úfrom_QQ_gmpyq   s    zPolynomialRing.from_QQ_gmpyc                 C   s   | | j  ||¡ƒS )z/Convert a `GaussianInteger` object to `dtype`. r9   r;   r   r   r   Úfrom_GaussianIntegerRingu   s    z'PolynomialRing.from_GaussianIntegerRingc                 C   s   | | j  ||¡ƒS )z0Convert a `GaussianRational` object to `dtype`. r9   r;   r   r   r   Úfrom_GaussianRationalFieldy   s    z)PolynomialRing.from_GaussianRationalFieldc                 C   s   | | j  ||¡ƒS ©z*Convert a mpmath `mpf` object to `dtype`. r9   r;   r   r   r   Úfrom_RealField}   s    zPolynomialRing.from_RealFieldc                 C   s   | | j  ||¡ƒS rG   r9   r;   r   r   r   Úfrom_ComplexField   s    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   r/   r   r;   r   r   r   Úfrom_AlgebraicField…   s    
z"PolynomialRing.from_AlgebraicFieldc              	   C   s,   z|  | j¡W S  ttfy&   Y dS 0 dS )z#Convert a polynomial to ``dtype``. N)Zset_ringr   r   r   r;   r   r   r   Úfrom_PolynomialRingŒ   s    z"PolynomialRing.from_PolynomialRingc                 C   sT   | j |kr| j |g¡S | |¡ | |¡¡\}}|jrL|  ||jj 	¡ ¡S dS dS )z*Convert a rational function to ``dtype``. N)
r   r   Ú	from_listZnumerÚdivZdenomÚis_zerorK   ÚfieldÚ	to_domain)r<   r0   r=   ÚqÚrr   r   r   Úfrom_FractionField“   s    
z!PolynomialRing.from_FractionFieldc                    sh   ˆ j |jkr>| ¡ }ˆ j|jkr6‡ fdd„| ¡ D ƒ}ˆ |ƒS |jrd|jˆ krdˆ  | ¡ d |j¡S dS )z)Convert from old poly ring to ``dtype``. c                    s   i | ]\}}|ˆ j  |¡“qS r   r9   )Ú.0ÚmÚc©r<   r   r   Ú
<dictcomp>¤   ó    z<PolynomialRing.from_GlobalPolynomialRing.<locals>.<dictcomp>r   N)r   r   Úto_dictr   Úitemsr-   r/   Zto_list)r<   r0   r=   Úadr   rW   r   Úfrom_GlobalPolynomialRingŸ   s    z(PolynomialRing.from_GlobalPolynomialRingc                 C   s   | j  ¡  ¡ S )z(Returns a field associated with `self`. )r   Zto_fieldrP   r   r   r   r   Ú	get_field©   s    zPolynomialRing.get_fieldc                 C   s   | j  |j¡S )z%Returns True if `LC(a)` is positive. )r   Úis_positiver3   r5   r   r   r   r_   ­   s    zPolynomialRing.is_positivec                 C   s   | j  |j¡S )z%Returns True if `LC(a)` is negative. )r   Úis_negativer3   r5   r   r   r   r`   ±   s    zPolynomialRing.is_negativec                 C   s   | j  |j¡S )z)Returns True if `LC(a)` is non-positive. )r   Úis_nonpositiver3   r5   r   r   r   ra   µ   s    zPolynomialRing.is_nonpositivec                 C   s   | j  |j¡S )z)Returns True if `LC(a)` is non-negative. )r   Úis_nonnegativer3   r5   r   r   r   rb   ¹   s    zPolynomialRing.is_nonnegativec                 C   s
   |  |¡S )zExtended GCD of `a` and `b`. )Úgcdex©r   r0   Úbr   r   r   rc   ½   s    zPolynomialRing.gcdexc                 C   s
   |  |¡S )zReturns GCD of `a` and `b`. )Úgcdrd   r   r   r   rf   Á   s    zPolynomialRing.gcdc                 C   s
   |  |¡S )zReturns LCM of `a` and `b`. )Úlcmrd   r   r   r   rg   Å   s    zPolynomialRing.lcmc                 C   s   |   | j |¡¡S )zReturns factorial of `a`. )r   r   Ú	factorialr5   r   r   r   rh   É   s    zPolynomialRing.factorial)NN)-r(   Ú
__module__Ú__qualname__Ú__doc__Zis_PolynomialRingZis_PolyZhas_assoc_RingZhas_assoc_Fieldr   r   r   Úpropertyr   r   r   r%   r)   r,   r.   r2   r6   r7   r>   r?   rA   rB   rC   rD   rE   rF   rH   rI   rJ   rK   rS   r]   r^   r_   r`   ra   rb   rc   rf   rg   rh   r   r   r   r   r   
   sV   




r   N)rk   Zsympy.polys.domains.ringr   Z#sympy.polys.domains.compositedomainr   Zsympy.polys.polyerrorsr   r   Zsympy.utilitiesr   r   r   r   r   r   Ú<module>   s   