o
    3IhO                     @   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| _|rF|jj	rF|jj
rFt|dkrFd| _| j| _d S )Nr   )PolyRing   T)sympy.polys.ringsr   
isinstanceringdtypegensngenssymbolsdomainis_Fieldis_Exactlenis_PIDdom)selfdomain_or_ringr   orderr   r    r   b/home/air/sanwanet/gpt-api/venv/lib/python3.10/site-packages/sympy/polys/domains/polynomialring.py__init__   s   zPolynomialRing.__init__c                 C      | j |S N)r   ring_newr   elementr   r   r   new+   s   zPolynomialRing.newc                 C   r   )z%Check if ``a`` is of type ``dtype``. )r   
is_elementr    r   r   r   of_type.      zPolynomialRing.of_typec                 C      | j jS r   )r   zeror   r   r   r   r'   2      zPolynomialRing.zeroc                 C   r&   r   )r   oner(   r   r   r   r*   6   r)   zPolynomialRing.onec                 C   r&   r   )r   r   r(   r   r   r   r   :   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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   
ground_new)r   r<   ur   r   r   r>   Q   s   zPolynomialRing.canonical_unitc                 C   s   |  S )zConvert `a` to a SymPy object. )as_exprr   r<   r   r   r   to_sympyU   r)   zPolynomialRing.to_sympyc                 C   r   )z'Convert SymPy's expression to `dtype`. )r   	from_exprrC   r   r   r   
from_sympyY   r%   zPolynomialRing.from_sympyc                 C      | | j ||S z*Convert a Python `int` object to `dtype`. r   convertK1r<   K0r   r   r   from_ZZ]      zPolynomialRing.from_ZZc                 C   rG   rH   rI   rK   r   r   r   from_ZZ_pythona   rO   zPolynomialRing.from_ZZ_pythonc                 C   rG   z/Convert a Python `Fraction` object to `dtype`. rI   rK   r   r   r   from_QQe   rO   zPolynomialRing.from_QQc                 C   rG   rQ   rI   rK   r   r   r   from_QQ_pythoni   rO   zPolynomialRing.from_QQ_pythonc                 C   rG   )z(Convert a GMPY `mpz` object to `dtype`. rI   rK   r   r   r   from_ZZ_gmpym   rO   zPolynomialRing.from_ZZ_gmpyc                 C   rG   )z(Convert a GMPY `mpq` object to `dtype`. rI   rK   r   r   r   from_QQ_gmpyq   rO   zPolynomialRing.from_QQ_gmpyc                 C   rG   )z/Convert a `GaussianInteger` object to `dtype`. rI   rK   r   r   r   from_GaussianIntegerRingu   rO   z'PolynomialRing.from_GaussianIntegerRingc                 C   rG   )z0Convert a `GaussianRational` object to `dtype`. rI   rK   r   r   r   from_GaussianRationalFieldy   rO   z)PolynomialRing.from_GaussianRationalFieldc                 C   rG   z*Convert a mpmath `mpf` object to `dtype`. rI   rK   r   r   r   from_RealField}   rO   zPolynomialRing.from_RealFieldc                 C   rG   rX   rI   rK   r   r   r   from_ComplexField   rO   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"   rK   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)set_ringr   r   r   rK   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_listnumerdivdenomis_zeror]   field	to_domain)rL   r<   rM   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   rI   ).0mcrL   r   r   
<dictcomp>   s    z<PolynomialRing.from_GlobalPolynomialRing.<locals>.<dictcomp>r   N)r   r   to_dictr   itemsr9   r;   to_list)rL   r<   rM   adr   rk   r   from_GlobalPolynomialRing   s   z(PolynomialRing.from_GlobalPolynomialRingc                 C   s   | j   S )z(Returns a field associated with `self`. )r   to_fieldrd   r(   r   r   r   	get_field      zPolynomialRing.get_fieldc                 C      | j |jS )z%Returns True if `LC(a)` is positive. )r   is_positiver?   rC   r   r   r   rv      rt   zPolynomialRing.is_positivec                 C   ru   )z%Returns True if `LC(a)` is negative. )r   is_negativer?   rC   r   r   r   rw      rt   zPolynomialRing.is_negativec                 C   ru   )z)Returns True if `LC(a)` is non-positive. )r   is_nonpositiver?   rC   r   r   r   rx      rt   zPolynomialRing.is_nonpositivec                 C   ru   )z)Returns True if `LC(a)` is non-negative. )r   is_nonnegativer?   rC   r   r   r   ry      rt   zPolynomialRing.is_nonnegativec                 C   
   | |S )zExtended GCD of `a` and `b`. )gcdexr   r<   br   r   r   r{         
zPolynomialRing.gcdexc                 C   rz   )zReturns GCD of `a` and `b`. )gcdr|   r   r   r   r      r~   zPolynomialRing.gcdc                 C   rz   )zReturns LCM of `a` and `b`. )lcmr|   r   r   r   r      r~   zPolynomialRing.lcmc                 C   s   |  | j|S )zReturns factorial of `a`. )r   r   	factorialrC   r   r   r   r      rO   zPolynomialRing.factorial)NN)-r4   
__module____qualname____doc__is_PolynomialRingis_Polyhas_assoc_Ringhas_assoc_Fieldr   r"   r$   propertyr'   r*   r   r1   r5   r8   r:   r>   rD   rF   rN   rP   rR   rS   rT   rU   rV   rW   rY   rZ   r[   r]   rg   rq   rs   rv   rw   rx   ry   r{   r   r   r   r   r   r   r   r   
   sX    




r   N)r   sympy.polys.domains.ringr   #sympy.polys.domains.compositedomainr   sympy.polys.polyerrorsr   r   sympy.utilitiesr   r   r   r   r   r   <module>   s    