o
    8Va	                     @   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                   @   sF  e Zd ZdZd ZZdZdZdJd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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+dS )K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)Zsympy.polys.ringsr   
isinstanceringdtypegensZngenssymbolsdomainZis_FieldZis_ExactlenZis_PIDZdom)selfZdomain_or_ringr   orderr   r    r   D/usr/lib/python3/dist-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      | j jS r   )r   zeror   r   r   r   r   .      zPolynomialRing.zeroc                 C   r   r   )r   oner   r   r   r   r   2   r   zPolynomialRing.onec                 C   r   r   )r   r   r   r   r   r   r   6   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| jfS r   )hash	__class____name__r   r   r   r   r   r   r   r   __hash__=   s   zPolynomialRing.__hash__c                 C   s.   t |to| jj| j| jf|jj|j|jfkS )z.Returns `True` if two domains are equivalent. )r
   r   r   r   r   r   )r   otherr   r   r   __eq__@   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-   F   s   zPolynomialRing.is_unitc                 C   s   | j |j}| j|S r   )r   canonical_unitLCr   Z
ground_new)r   r/   ur   r   r   r1   M   s   zPolynomialRing.canonical_unitc                 C   s   |  S )zConvert `a` to a SymPy object. )Zas_exprr   r/   r   r   r   to_sympyQ   r   zPolynomialRing.to_sympyc                 C   r   )z'Convert SymPy's expression to `dtype`. )r   Z	from_exprr4   r   r   r   
from_sympyU   s   zPolynomialRing.from_sympyc                 C      | | j ||S z*Convert a Python `int` object to `dtype`. r   ZconvertK1r/   K0r   r   r   from_ZZY      zPolynomialRing.from_ZZc                 C   r7   r8   r9   r:   r   r   r   from_ZZ_python]   r>   zPolynomialRing.from_ZZ_pythonc                 C   r7   z/Convert a Python `Fraction` object to `dtype`. r9   r:   r   r   r   from_QQa   r>   zPolynomialRing.from_QQc                 C   r7   r@   r9   r:   r   r   r   from_QQ_pythone   r>   zPolynomialRing.from_QQ_pythonc                 C   r7   )z(Convert a GMPY `mpz` object to `dtype`. r9   r:   r   r   r   from_ZZ_gmpyi   r>   zPolynomialRing.from_ZZ_gmpyc                 C   r7   )z(Convert a GMPY `mpq` object to `dtype`. r9   r:   r   r   r   from_QQ_gmpym   r>   zPolynomialRing.from_QQ_gmpyc                 C   r7   )z/Convert a `GaussianInteger` object to `dtype`. r9   r:   r   r   r   from_GaussianIntegerRingq   r>   z'PolynomialRing.from_GaussianIntegerRingc                 C   r7   )z0Convert a `GaussianRational` object to `dtype`. r9   r:   r   r   r   from_GaussianRationalFieldu   r>   z)PolynomialRing.from_GaussianRationalFieldc                 C   r7   z*Convert a mpmath `mpf` object to `dtype`. r9   r:   r   r   r   from_RealFieldy   r>   zPolynomialRing.from_RealFieldc                 C   r7   rG   r9   r:   r   r   r   from_ComplexField}   r>   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 w )z#Convert a polynomial to ``dtype``. N)Zset_ringr   r   r   r:   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_listZnumerZdivZdenomZis_zerorK   Zfield	to_domain)r;   r/   r<   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   r9   ).0mcr;   r   r   
<dictcomp>   s    z<PolynomialRing.from_GlobalPolynomialRing.<locals>.<dictcomp>r   N)r   r   Zto_dictr   itemsr,   r.   Zto_list)r;   r/   r<   Zadr   rT   r   from_GlobalPolynomialRing   s   z(PolynomialRing.from_GlobalPolynomialRingc                 C   s   | j   S )z(Returns a field associated with `self`. )r   Zto_fieldrM   r   r   r   r   	get_field      zPolynomialRing.get_fieldc                 C      | j |jS )z%Returns True if `LC(a)` is positive. )r   is_positiver2   r4   r   r   r   r[      rY   zPolynomialRing.is_positivec                 C   rZ   )z%Returns True if `LC(a)` is negative. )r   is_negativer2   r4   r   r   r   r\      rY   zPolynomialRing.is_negativec                 C   rZ   )z)Returns True if `LC(a)` is non-positive. )r   is_nonpositiver2   r4   r   r   r   r]      rY   zPolynomialRing.is_nonpositivec                 C   rZ   )z)Returns True if `LC(a)` is non-negative. )r   is_nonnegativer2   r4   r   r   r   r^      rY   zPolynomialRing.is_nonnegativec                 C   
   | |S )zExtended GCD of `a` and `b`. )gcdexr   r/   br   r   r   r`         
zPolynomialRing.gcdexc                 C   r_   )zReturns GCD of `a` and `b`. )gcdra   r   r   r   rd      rc   zPolynomialRing.gcdc                 C   r_   )zReturns LCM of `a` and `b`. )lcmra   r   r   r   re      rc   zPolynomialRing.lcmc                 C   s   |  | j|S )zReturns factorial of `a`. )r   r   	factorialr4   r   r   r   rf      r>   zPolynomialRing.factorial)NN),r(   
__module____qualname____doc__Zis_PolynomialRingZis_PolyZhas_assoc_RingZhas_assoc_Fieldr   r   propertyr   r   r   r%   r)   r+   r-   r1   r5   r6   r=   r?   rA   rB   rC   rD   rE   rF   rH   rI   rJ   rK   rP   rW   rX   r[   r\   r]   r^   r`   rd   re   rf   r   r   r   r   r   
   sV    




r   N)ri   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    