
    sg	                     ^    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ee             Z
y)	z1Implementation of :class:`PolynomialRing` class.     )Ring)CompositeDomain)CoercionFailedGeneratorsError)publicc                      e Zd ZdZdxZZdZdZd'dZd Z	e
d        Ze
d        Ze
d        Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"d Z#d Z$d  Z%d! Z&d" Z'd# Z(d$ Z)d% Z*d& Z+y)(PolynomialRingz8A class for representing multivariate polynomial rings. TNc                    ddl m} t        ||      r|||}n
 ||||      }|| _        |j                  | _        |j
                  | _        |j                  | _        |j                  | _        |j                  | _        |rA|j                  j                  r+|j                  j                  rt        |      dk(  rd| _        | j                  | _        y )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   s         U/var/www/html/venv/lib/python3.12/site-packages/sympy/polys/domains/polynomialring.py__init__zPolynomialRing.__init__   s    .nh/GO!DG^U;D	ZZ
II	ZZ
||kk {{##(<(<Wq" ;;    c                 8    | j                   j                  |      S N)r   ring_new)r   elements     r   newzPolynomialRing.new+   s    yy!!'**r   c                 .    | j                   j                  S r!   )r   zeror   s    r   r&   zPolynomialRing.zero.   s    yy~~r   c                 .    | j                   j                  S r!   )r   oner'   s    r   r)   zPolynomialRing.one2   s    yy}}r   c                 .    | j                   j                  S r!   )r   r   r'   s    r   r   zPolynomialRing.order6   s    yyr   c                     t        | j                        dz   dj                  t        t         | j                              z   dz   S )N[,])strr   joinmapr   r'   s    r   __str__zPolynomialRing.__str__:   s4    4;;#%S$,,1G(HH3NNr   c                     t        | j                  j                  | j                  j                  | j
                  | j                  f      S r!   )hash	__class____name__r   r   r   r   r'   s    r   __hash__zPolynomialRing.__hash__=   s0    T^^,,djjoot{{DLLYZZr   c                     t        |t              xr[ | 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   others     r   __eq__zPolynomialRing.__eq__@   sQ    %0 <ZZ__dkk4<<8[[u||U]];<	<r   c                 v    |j                   sy| j                  }|j                  |j                  ||             S )z/Returns ``True`` if ``a`` is a unit of ``self``F)	is_groundr   is_unitconvert_from)r   aKs      r   r=   zPolynomialRing.is_unitF   s/    {{KKyy4011r   c                     | j                   j                  |j                        }| j                  j	                  |      S r!   )r   canonical_unitLCr   
ground_new)r   r?   us      r   rB   zPolynomialRing.canonical_unitM   s/    KK&&qtt,yy##A&&r   c                 "    |j                         S )zConvert `a` to a SymPy object. )as_exprr   r?   s     r   to_sympyzPolynomialRing.to_sympyQ   s    yy{r   c                 8    | j                   j                  |      S )z'Convert SymPy's expression to `dtype`. )r   	from_exprrH   s     r   
from_sympyzPolynomialRing.from_sympyU   s    yy""1%%r   c                 F     | | j                   j                  ||            S z*Convert a Python `int` object to `dtype`. r   convertK1r?   K0s      r   from_ZZzPolynomialRing.from_ZZY       "))##Ar*++r   c                 F     | | j                   j                  ||            S rN   rO   rQ   s      r   from_ZZ_pythonzPolynomialRing.from_ZZ_python]   rU   r   c                 F     | | j                   j                  ||            S z/Convert a Python `Fraction` object to `dtype`. rO   rQ   s      r   from_QQzPolynomialRing.from_QQa   rU   r   c                 F     | | j                   j                  ||            S rY   rO   rQ   s      r   from_QQ_pythonzPolynomialRing.from_QQ_pythone   rU   r   c                 F     | | j                   j                  ||            S )z(Convert a GMPY `mpz` object to `dtype`. rO   rQ   s      r   from_ZZ_gmpyzPolynomialRing.from_ZZ_gmpyi   rU   r   c                 F     | | j                   j                  ||            S )z(Convert a GMPY `mpq` object to `dtype`. rO   rQ   s      r   from_QQ_gmpyzPolynomialRing.from_QQ_gmpym   rU   r   c                 F     | | j                   j                  ||            S )z/Convert a `GaussianInteger` object to `dtype`. rO   rQ   s      r   from_GaussianIntegerRingz'PolynomialRing.from_GaussianIntegerRingq   rU   r   c                 F     | | j                   j                  ||            S )z0Convert a `GaussianRational` object to `dtype`. rO   rQ   s      r   from_GaussianRationalFieldz)PolynomialRing.from_GaussianRationalFieldu   rU   r   c                 F     | | j                   j                  ||            S z*Convert a mpmath `mpf` object to `dtype`. rO   rQ   s      r   from_RealFieldzPolynomialRing.from_RealFieldy   rU   r   c                 F     | | j                   j                  ||            S rf   rO   rQ   s      r   from_ComplexFieldz PolynomialRing.from_ComplexField}   rU   r   c                     | j                   |k7  r| j                   j                  ||      }|| j                  |      S y)z*Convert an algebraic number to ``dtype``. N)r   r>   r$   rQ   s      r   from_AlgebraicFieldz"PolynomialRing.from_AlgebraicField   s;    99?		&&q"-A=66!9 r   c                 d    	 |j                  | j                        S # t        t        f$ r Y yw xY w)z#Convert a polynomial to ``dtype``. N)set_ringr   r   r   rQ   s      r   from_PolynomialRingz"PolynomialRing.from_PolynomialRing   s1    	::bgg&&0 		s    //c                 >   | j                   |k(  r| j                  j                  |g      S |j                  |      j	                  |j                  |            \  }}|j                  r4| j                  ||j                  j                  j                               S y)z*Convert a rational function to ``dtype``. N)
r   r   	from_listnumerdivdenomis_zerorn   field	to_domain)rR   r?   rS   qrs        r   from_FractionFieldz!PolynomialRing.from_FractionField   st    99?77$$aS))xx{rxx{+199))!RXX]]-D-D-FGGr   c                    | j                   |j                  k(  rm|j                         }| j                  |j                  k7  r<|j	                         D ci c]!  \  }}|| j                  j                  |      # }}} | |      S |j                  r=|j                  | k(  r-| j                  |j                         d   |j                        S yyc c}}w )z)Convert from old poly ring to ``dtype``. r   N)	r   r   to_dictr   itemsrP   r<   r>   to_list)rR   r?   rS   admcs         r   from_GlobalPolynomialRingz(PolynomialRing.from_GlobalPolynomialRing   s    :: ByyBII%:<((*E$!Qa**1--EEb6M[[RYY"_??199;q>299== -[ Fs   &Cc                 R    | j                   j                         j                         S )z(Returns a field associated with `self`. )r   to_fieldrv   r'   s    r   	get_fieldzPolynomialRing.get_field   s    yy!!#--//r   c                 L    | j                   j                  |j                        S )z%Returns True if `LC(a)` is positive. )r   is_positiverC   rH   s     r   r   zPolynomialRing.is_positive       {{&&qtt,,r   c                 L    | j                   j                  |j                        S )z%Returns True if `LC(a)` is negative. )r   is_negativerC   rH   s     r   r   zPolynomialRing.is_negative   r   r   c                 L    | j                   j                  |j                        S )z)Returns True if `LC(a)` is non-positive. )r   is_nonpositiverC   rH   s     r   r   zPolynomialRing.is_nonpositive       {{))!$$//r   c                 L    | j                   j                  |j                        S )z)Returns True if `LC(a)` is non-negative. )r   is_nonnegativerC   rH   s     r   r   zPolynomialRing.is_nonnegative   r   r   c                 $    |j                  |      S )zExtended GCD of `a` and `b`. )gcdexr   r?   bs      r   r   zPolynomialRing.gcdex   s    wwqzr   c                 $    |j                  |      S )zReturns GCD of `a` and `b`. )gcdr   s      r   r   zPolynomialRing.gcd       uuQxr   c                 $    |j                  |      S )zReturns LCM of `a` and `b`. )lcmr   s      r   r   zPolynomialRing.lcm   r   r   c                 V    | j                  | j                  j                  |            S )zReturns factorial of `a`. )r   r   	factorialrH   s     r   r   zPolynomialRing.factorial   s     zz$++//233r   )NN),r6   
__module____qualname____doc__is_PolynomialRingis_Polyhas_assoc_Ringhas_assoc_Fieldr   r$   propertyr&   r)   r   r2   r7   r:   r=   rB   rI   rL   rT   rW   rZ   r\   r^   r`   rb   rd   rg   ri   rk   rn   ry   r   r   r   r   r   r   r   r   r   r    r   r   r	   r	   
   s    B"&&NO0+      O[<2'&,,,,,,,,,,
>0--004r   r	   N)r   sympy.polys.domains.ringr   #sympy.polys.domains.compositedomainr   sympy.polys.polyerrorsr   r   sympy.utilitiesr   r	   r   r   r   <module>r      s4    7 * ? B "|4T? |4 |4r   