o
    §ƒðjØ  ã                   @   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 )	z0Implementation of :class:`FractionField` class. é    )ÚCompositeDomain)ÚField)ÚCoercionFailedÚGeneratorsError)Úpublicc                   @   s.  e Zd ZdZd ZZdZdZdDd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(dS )EÚFractionFieldz@A class for representing multivariate rational function fields. TNc                 C   sr   ddl m} t||ƒr|d u r|d u r|}n||||ƒ}|| _|j| _|j| _|j| _|j| _|j| _| j| _	d S )Nr   )Ú	FracField)
Úsympy.polys.fieldsr   Ú
isinstanceÚfieldÚdtypeÚgensÚngensÚsymbolsÚdomainÚdom)ÚselfÚdomain_or_fieldr   Úorderr   r   © r   ú£/tmp/claude-1000/-var-www-html-academy/3f42efd1-c2b7-4d08-9b05-30d86bb35479/scratchpad/piper/venv/lib/python3.10/site-packages/sympy/polys/domains/fractionfield.pyÚ__init__   s   zFractionField.__init__c                 C   ó   | j  |¡S ©N)r   Ú	field_new©r   Úelementr   r   r   Únew%   s   zFractionField.newc                 C   r   )z%Check if ``a`` is of type ``dtype``. )r   Ú
is_elementr   r   r   r   Úof_type(   ó   zFractionField.of_typec                 C   ó   | j jS r   )r   Úzero©r   r   r   r   r"   ,   ó   zFractionField.zeroc                 C   r!   r   )r   Úoner#   r   r   r   r%   0   r$   zFractionField.onec                 C   r!   r   )r   r   r#   r   r   r   r   4   r$   zFractionField.orderc                 C   s$   t | jƒd d tt | jƒ¡ d S )Nú(ú,ú))Ústrr   ÚjoinÚmapr   r#   r   r   r   Ú__str__8   s   $zFractionField.__str__c                 C   s   t | jj| j| j| jfƒS r   )ÚhashÚ	__class__Ú__name__r   r   r   r#   r   r   r   Ú__hash__;   s   zFractionField.__hash__c                 C   s   t |tƒstS | j|jkS )z0Returns ``True`` if two domains are equivalent. )r
   r   ÚNotImplementedr   )r   Úotherr   r   r   Ú__eq__>   s   
zFractionField.__eq__c                 C   s   |  ¡ S )z!Convert ``a`` to a SymPy object. )Úas_expr©r   Úar   r   r   Úto_sympyD   r$   zFractionField.to_sympyc                 C   r   )z)Convert SymPy's expression to ``dtype``. )r   Ú	from_exprr5   r   r   r   Ú
from_sympyH   r    zFractionField.from_sympyc                 C   ó   | | j  ||¡ƒS ©z.Convert a Python ``int`` object to ``dtype``. ©r   Úconvert©ÚK1r6   ÚK0r   r   r   Úfrom_ZZL   ó   zFractionField.from_ZZc                 C   r:   r;   r<   r>   r   r   r   Úfrom_ZZ_pythonP   rB   zFractionField.from_ZZ_pythonc                 C   sH   | j }|j}|jr| || |¡|ƒƒ| || |¡|ƒƒ S | |||ƒƒS ©z3Convert a Python ``Fraction`` object to ``dtype``. )r   Úconvert_fromÚis_ZZÚnumerÚdenom)r?   r6   r@   r   Úconvr   r   r   Úfrom_QQT   s
   (zFractionField.from_QQc                 C   r:   rD   r<   r>   r   r   r   Úfrom_QQ_python]   rB   zFractionField.from_QQ_pythonc                 C   r:   )z,Convert a GMPY ``mpz`` object to ``dtype``. r<   r>   r   r   r   Úfrom_ZZ_gmpya   rB   zFractionField.from_ZZ_gmpyc                 C   r:   )z,Convert a GMPY ``mpq`` object to ``dtype``. r<   r>   r   r   r   Úfrom_QQ_gmpye   rB   zFractionField.from_QQ_gmpyc                 C   r:   )z4Convert a ``GaussianRational`` object to ``dtype``. r<   r>   r   r   r   Úfrom_GaussianRationalFieldi   rB   z(FractionField.from_GaussianRationalFieldc                 C   r:   )z3Convert a ``GaussianInteger`` object to ``dtype``. r<   r>   r   r   r   Úfrom_GaussianIntegerRingm   rB   z&FractionField.from_GaussianIntegerRingc                 C   r:   ©z.Convert a mpmath ``mpf`` object to ``dtype``. r<   r>   r   r   r   Úfrom_RealFieldq   rB   zFractionField.from_RealFieldc                 C   r:   rP   r<   r>   r   r   r   Úfrom_ComplexFieldu   rB   zFractionField.from_ComplexFieldc                 C   s.   | j |kr| j  ||¡}|dur|  |¡S dS )z*Convert an algebraic number to ``dtype``. N)r   rE   r   r>   r   r   r   Úfrom_AlgebraicFieldy   s
   

ÿz!FractionField.from_AlgebraicFieldc                 C   sp   |j r|  | d¡|j¡S z|  | | jj¡¡W S  tt	fy7   z|  |¡W  Y S  tt	fy6   Y Y dS w w )z#Convert a polynomial to ``dtype``. é   N)
Ú	is_groundrE   Úcoeffr   r   Úset_ringr   Úringr   r   r>   r   r   r   Úfrom_PolynomialRing€   s   ÿùz!FractionField.from_PolynomialRingc              	   C   s(   z|  | j¡W S  ttfy   Y dS w )z*Convert a rational function to ``dtype``. N)Ú	set_fieldr   r   r   r>   r   r   r   Úfrom_FractionField�   s
   ÿz FractionField.from_FractionFieldc                 C   s   | j  ¡  ¡ S )z*Returns a field associated with ``self``. )r   Úto_ringÚ	to_domainr#   r   r   r   Úget_ring—   s   zFractionField.get_ringc                 C   ó   | j  |jj¡S )z'Returns True if ``LC(a)`` is positive. )r   Úis_positiverG   ÚLCr5   r   r   r   r`   ›   ó   zFractionField.is_positivec                 C   r_   )z'Returns True if ``LC(a)`` is negative. )r   Úis_negativerG   ra   r5   r   r   r   rc   Ÿ   rb   zFractionField.is_negativec                 C   r_   )z+Returns True if ``LC(a)`` is non-positive. )r   Úis_nonpositiverG   ra   r5   r   r   r   rd   £   rb   zFractionField.is_nonpositivec                 C   r_   )z+Returns True if ``LC(a)`` is non-negative. )r   Úis_nonnegativerG   ra   r5   r   r   r   re   §   rb   zFractionField.is_nonnegativec                 C   ó   |j S )zReturns numerator of ``a``. )rG   r5   r   r   r   rG   «   ó   zFractionField.numerc                 C   rf   )zReturns denominator of ``a``. )rH   r5   r   r   r   rH   ¯   rg   zFractionField.denomc                 C   s   |   | j |¡¡S )zReturns factorial of ``a``. )r   r   Ú	factorialr5   r   r   r   rh   ³   rB   zFractionField.factorial)NN))r/   Ú
__module__Ú__qualname__Ú__doc__Úis_FractionFieldÚis_FracÚhas_assoc_RingÚhas_assoc_Fieldr   r   r   Úpropertyr"   r%   r   r,   r0   r3   r7   r9   rA   rC   rJ   rK   rL   rM   rN   rO   rQ   rR   rS   rY   r[   r^   r`   rc   rd   re   rG   rH   rh   r   r   r   r   r   	   sP    



	r   N)rk   Ú#sympy.polys.domains.compositedomainr   Úsympy.polys.domains.fieldr   Úsympy.polys.polyerrorsr   r   Úsympy.utilitiesr   r   r   r   r   r   Ú<module>   s    