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 )
z0Implementation of :class:`FractionField` class. é    )Úprint_functionÚdivision)ÚField)ÚCompositeDomain)ÚCoercionFailedÚGeneratorsError)Úpublicc               @   sþ   e Zd ZdZd ZZdZdZd8d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"dS )9ÚFractionFieldz@A class for representing multivariate rational function fields. TNc             C   sr   ddl m} t||ƒr,|d kr,|d kr,|}n||||ƒ}|| _|j| _|j| _|j| _|j| _|j| _| j| _	d S )Nr   )Ú	FracField)
Zsympy.polys.fieldsr
   Ú
isinstanceÚfieldÚdtypeZgensZngensÚsymbolsÚdomainZdom)ÚselfZdomain_or_fieldr   Úorderr
   r   © r   ú@lib/python3.7/site-packages/sympy/polys/domains/fractionfield.pyÚ__init__   s    zFractionField.__init__c             C   s   | j  |¡S )N)r   Z	field_new)r   Úelementr   r   r   Únew'   s    zFractionField.newc             C   s   | j jS )N)r   Úzero)r   r   r   r   r   *   s    zFractionField.zeroc             C   s   | j jS )N)r   Úone)r   r   r   r   r   .   s    zFractionField.onec             C   s   | j jS )N)r   r   )r   r   r   r   r   2   s    zFractionField.orderc             C   s$   t | jƒd d tt | jƒ¡ d S )Nú(ú,ú))Ústrr   ÚjoinÚmapr   )r   r   r   r   Ú__str__6   s    zFractionField.__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__9   s    zFractionField.__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FractionField.__eq__c             C   s   |  ¡ S )zConvert `a` to a SymPy object. )Zas_expr)r   Úar   r   r   Úto_sympyB   s    zFractionField.to_sympyc             C   s   | j  |¡S )z'Convert SymPy's expression to `dtype`. )r   Z	from_expr)r   r&   r   r   r   Ú
from_sympyF   s    zFractionField.from_sympyc             C   s   | | j  ||¡ƒS )z*Convert a Python `int` object to `dtype`. )r   Úconvert)ÚK1r&   ÚK0r   r   r   Úfrom_ZZ_pythonJ   s    zFractionField.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_pythonN   s    zFractionField.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_gmpyR   s    zFractionField.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_gmpyV   s    zFractionField.from_QQ_gmpyc             C   s   | | j  ||¡ƒS )z*Convert a mpmath `mpf` object to `dtype`. )r   r)   )r*   r&   r+   r   r   r   Úfrom_RealFieldZ   s    zFractionField.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_AlgebraicField^   s    
z!FractionField.from_AlgebraicFieldc          	   C   s(   y
|   |¡S  ttfk
r"   dS X dS )z#Convert a polynomial to ``dtype``. N)r   r   r   )r*   r&   r+   r   r   r   Úfrom_PolynomialRingc   s    
z!FractionField.from_PolynomialRingc          	   C   s*   y|  | j¡S  ttfk
r$   dS X dS )z*Convert a rational function to ``dtype``. N)Z	set_fieldr   r   r   )r*   r&   r+   r   r   r   Úfrom_FractionFieldj   s    z FractionField.from_FractionFieldc             C   s   | j  ¡  ¡ S )z(Returns a field associated with `self`. )r   Zto_ringZ	to_domain)r   r   r   r   Úget_ringq   s    zFractionField.get_ringc             C   s   | j  |jj¡S )z%Returns True if `LC(a)` is positive. )r   Úis_positiveÚnumerÚLC)r   r&   r   r   r   r5   u   s    zFractionField.is_positivec             C   s   | j  |jj¡S )z%Returns True if `LC(a)` is negative. )r   Úis_negativer6   r7   )r   r&   r   r   r   r8   y   s    zFractionField.is_negativec             C   s   | j  |jj¡S )z)Returns True if `LC(a)` is non-positive. )r   Úis_nonpositiver6   r7   )r   r&   r   r   r   r9   }   s    zFractionField.is_nonpositivec             C   s   | j  |jj¡S )z)Returns True if `LC(a)` is non-negative. )r   Úis_nonnegativer6   r7   )r   r&   r   r   r   r:      s    zFractionField.is_nonnegativec             C   s   |j S )zReturns numerator of ``a``. )r6   )r   r&   r   r   r   r6   …   s    zFractionField.numerc             C   s   |j S )zReturns denominator of ``a``. )Údenom)r   r&   r   r   r   r;   ‰   s    zFractionField.denomc             C   s   |   | j |¡¡S )zReturns factorial of `a`. )r   r   Ú	factorial)r   r&   r   r   r   r<      s    zFractionField.factorial)NN)#r"   Ú
__module__Ú__qualname__Ú__doc__Zis_FractionFieldZis_FracZhas_assoc_RingZhas_assoc_Fieldr   r   Úpropertyr   r   r   r   r#   r%   r'   r(   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r8   r9   r:   r6   r;   r<   r   r   r   r   r	      s<   
r	   N)r?   Z
__future__r   r   Zsympy.polys.domains.fieldr   Z#sympy.polys.domains.compositedomainr   Zsympy.polys.polyerrorsr   r   Zsympy.utilitiesr   r	   r   r   r   r   Ú<module>   s   