B
    [                 @   sb   d Z ddlmZm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.     )print_functiondivision)Ring)CompositeDomain)CoercionFailedGeneratorsError)publicc               @   s  e Zd ZdZd ZZdZdZd: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d.d/ Zd0d1 Zd2d3 Z d4d5 Z!d6d7 Z"d8d9 Z#dS );PolynomialRingz8A class for representing multivariate polynomial rings. TNc             C   s   ddl m} t||r,|d kr,|d kr,|}n||||}|| _|j| _|j| _|j| _|j| _|j| _|r|jj	r|jj
rt|dkrd| _| j| _d S )Nr   )PolyRing   T)Zsympy.polys.ringsr
   
isinstanceringdtypeZgensZngenssymbolsdomainZis_FieldZis_ExactlenZis_PIDZdom)selfZdomain_or_ringr   orderr
   r    r   Alib/python3.7/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 jS )N)r   zero)r   r   r   r   r   /   s    zPolynomialRing.zeroc             C   s   | j jS )N)r   one)r   r   r   r   r   3   s    zPolynomialRing.onec             C   s   | j jS )N)r   r   )r   r   r   r   r   7   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| jfS )N)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__A   s    
zPolynomialRing.__eq__c             C   s   |  S )zConvert `a` to a SymPy object. )Zas_expr)r   ar   r   r   to_sympyG   s    zPolynomialRing.to_sympyc             C   s   | j |S )z'Convert SymPy's expression to `dtype`. )r   Z	from_expr)r   r(   r   r   r   
from_sympyK   s    zPolynomialRing.from_sympyc             C   s   | | j ||S )z*Convert a Python `int` object to `dtype`. )r   convert)K1r(   K0r   r   r   from_ZZ_pythonO   s    zPolynomialRing.from_ZZ_pythonc             C   s   | | j ||S )z/Convert a Python `Fraction` object to `dtype`. )r   r+   )r,   r(   r-   r   r   r   from_QQ_pythonS   s    zPolynomialRing.from_QQ_pythonc             C   s   | | j ||S )z(Convert a GMPY `mpz` object to `dtype`. )r   r+   )r,   r(   r-   r   r   r   from_ZZ_gmpyW   s    zPolynomialRing.from_ZZ_gmpyc             C   s   | | j ||S )z(Convert a GMPY `mpq` object to `dtype`. )r   r+   )r,   r(   r-   r   r   r   from_QQ_gmpy[   s    zPolynomialRing.from_QQ_gmpyc             C   s   | | j ||S )z*Convert a mpmath `mpf` object to `dtype`. )r   r+   )r,   r(   r-   r   r   r   from_RealField_   s    zPolynomialRing.from_RealFieldc             C   s   | j |kr| |S dS )z*Convert an algebraic number to ``dtype``. N)r   r   )r,   r(   r-   r   r   r   from_AlgebraicFieldc   s    
z"PolynomialRing.from_AlgebraicFieldc          	   C   s*   y| | jS  ttfk
r$   dS X dS )z#Convert a polynomial to ``dtype``. N)Zset_ringr   r   r   )r,   r(   r-   r   r   r   from_PolynomialRingh   s    z"PolynomialRing.from_PolynomialRingc             C   s<   | |||\}}|jr4| ||jj S dS dS )z*Convert a rational function to ``dtype``. N)ZnumerZdivZdenomZis_zeror4   Zfieldr   	to_domain)r,   r(   r-   qrr   r   r   from_FractionFieldo   s    z!PolynomialRing.from_FractionFieldc             C   s   | j   S )z(Returns a field associated with `self`. )r   Zto_fieldr5   )r   r   r   r   	get_fieldx   s    zPolynomialRing.get_fieldc             C   s   | j |jS )z%Returns True if `LC(a)` is positive. )r   is_positiveLC)r   r(   r   r   r   r:   |   s    zPolynomialRing.is_positivec             C   s   | j |jS )z%Returns True if `LC(a)` is negative. )r   is_negativer;   )r   r(   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_nonpositiver;   )r   r(   r   r   r   r=      s    zPolynomialRing.is_nonpositivec             C   s   | j |jS )z)Returns True if `LC(a)` is non-negative. )r   is_nonnegativer;   )r   r(   r   r   r   r>      s    zPolynomialRing.is_nonnegativec             C   s
   | |S )zExtended GCD of `a` and `b`. )gcdex)r   r(   br   r   r   r?      s    zPolynomialRing.gcdexc             C   s
   | |S )zReturns GCD of `a` and `b`. )gcd)r   r(   r@   r   r   r   rA      s    zPolynomialRing.gcdc             C   s
   | |S )zReturns LCM of `a` and `b`. )lcm)r   r(   r@   r   r   r   rB      s    zPolynomialRing.lcmc             C   s   |  | j|S )zReturns factorial of `a`. )r   r   	factorial)r   r(   r   r   r   rC      s    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)   r*   r.   r/   r0   r1   r2   r3   r4   r8   r9   r:   r<   r=   r>   r?   rA   rB   rC   r   r   r   r   r	      s>   
	r	   N)rF   Z
__future__r   r   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   