
    g                         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                      Z
 G d d	e          Zd
S )z.Implementation of :class:`QuotientRing` class.    FreeModuleQuotientRing)Ring)NotReversibleCoercionFailed)publicc                   l    e Zd ZdZd Zd ZeZd Zd ZeZ	d Z
d Zd Zd	 ZeZd
 Zd Zd Zd Zd ZdS )QuotientRingElementz
    Class representing elements of (commutative) quotient rings.

    Attributes:

    - ring - containing ring
    - data - element of ring.ring (i.e. base ring) representing self
    c                 "    || _         || _        d S N)ringdata)selfr   r   s      \/var/www/html/ai-engine/env/lib/python3.11/site-packages/sympy/polys/domains/quotientring.py__init__zQuotientRingElement.__init__   s    				    c                     ddl m} | j        j                            | j                  } ||          dz   t          | j        j                  z   S )Nr   )sstrz + )sympy.printing.strr   r   to_sympyr   str
base_ideal)r   r   r   s      r   __str__zQuotientRingElement.__str__   sR    ++++++y~&&ty11tDzzE!C	(<$=$===r   c                 8    | j                             |            S r   )r   is_zeror   s    r   __bool__zQuotientRingElement.__bool__$   s    9$$T****r   c                    t          || j                  r|j        | j        k    r:	 | j                            |          }n# t          t
          f$ r
 t          cY S w xY w|                     | j        |j        z             S r   
isinstance	__class__r   convertNotImplementedErrorr   NotImplementedr   r   oms     r   __add__zQuotientRingElement.__add__'   s    "dn-- 	&DI1E1E&Y&&r**'8 & & &%%%%&yyRW,---s   A AAc                 v    |                      | j        | j         j                             d          z            S )N)r   r   r"   r   s    r   __neg__zQuotientRingElement.__neg__1   s-    yy49>#9#9"#=#==>>>r   c                 .    |                      |           S r   r'   r%   s     r   __sub__zQuotientRingElement.__sub__4   s    ||RC   r   c                 .    |                       |          S r   r,   r%   s     r   __rsub__zQuotientRingElement.__rsub__7   s    r"""r   c                     t          || j                  s:	 | j                            |          }n# t          t
          f$ r
 t          cY S w xY w|                     | j        |j        z            S r   r   r   os     r   __mul__zQuotientRingElement.__mul__:   sy    !T^,, 	&&I%%a(('8 & & &%%%%&yy16)***   2 AAc                 <    | j                             |           |z  S r   )r   revertr1   s     r   __rtruediv__z QuotientRingElement.__rtruediv__D   s    y%%a''r   c                     t          || j                  s:	 | j                            |          }n# t          t
          f$ r
 t          cY S w xY w| j                            |          | z  S r   )r    r!   r   r"   r#   r   r$   r6   r1   s     r   __truediv__zQuotientRingElement.__truediv__G   sy    !T^,, 	&&I%%a(('8 & & &%%%%&y""4''r4   c                     |dk     r| j                             |           | z  S |                      | j        |z            S )Nr   )r   r6   r   )r   oths     r   __pow__zQuotientRingElement.__pow__O   sA    779##D))cT11yyc)***r   c                     t          || j                  r|j        | j        k    rdS | j                            | |z
            S )NF)r    r!   r   r   r%   s     r   __eq__zQuotientRingElement.__eq__T   sC    "dn-- 	DI1E1E5y  +++r   c                     | |k     S r    r%   s     r   __ne__zQuotientRingElement.__ne__Y   s    2:~r   N)__name__
__module____qualname____doc__r   r   __repr__r   r'   __radd__r*   r-   r/   r3   __rmul__r7   r9   r<   r>   rA   r@   r   r   r
   r
      s           > > >
 H+ + +. . . H? ? ?! ! !# # #+ + + H( ( (( ( (+ + +
, , ,
    r   r
   c                       e Zd ZdZdZdZeZd Zd Z	d Z
d Zd Zd	 ZeZeZeZeZeZeZeZd
 Zd Zd Zd Zd Zd Zd Zd ZdS )QuotientRingaa  
    Class representing (commutative) quotient rings.

    You should not usually instantiate this by hand, instead use the constructor
    from the base ring in the construction.

    >>> from sympy.abc import x
    >>> from sympy import QQ
    >>> I = QQ.old_poly_ring(x).ideal(x**3 + 1)
    >>> QQ.old_poly_ring(x).quotient_ring(I)
    QQ[x]/<x**3 + 1>

    Shorter versions are possible:

    >>> QQ.old_poly_ring(x)/I
    QQ[x]/<x**3 + 1>

    >>> QQ.old_poly_ring(x)/[x**3 + 1]
    QQ[x]/<x**3 + 1>

    Attributes:

    - ring - the base ring
    - base_ideal - the ideal used to form the quotient
    TFc                     |j         |k    st          d|d|          || _         || _         | | j         j                  | _         | | j         j                  | _        d S )NzIdeal must belong to z, got )r   
ValueErrorr   zeroone)r   r   ideals      r   r   zQuotientRing.__init__|   sf    zT!!*$$$NOOO	D((	4	&&r   c                 Z    t          | j                  dz   t          | j                  z   S )N/)r   r   r   r   s    r   r   zQuotientRing.__str__   s$    49~~#c$/&:&:::r   c                 Z    t          | j        j        | j        | j        | j        f          S r   )hashr!   rB   dtyper   r   r   s    r   __hash__zQuotientRing.__hash__   s$    T^,dj$)T_UVVVr   c                     t          || j        j                  s|                     |          }|                     | | j                            |                    S )z4Construct an element of ``self`` domain from ``a``. )r    r   rT   r   reduce_elementr   as     r   newzQuotientRing.new   sK    !TY_-- 			!Azz$ > >q A ABBBr   c                 l    t          |t                    o| j        |j        k    o| j        |j        k    S )z0Returns ``True`` if two domains are equivalent. )r    rJ   r   r   )r   others     r   r>   zQuotientRing.__eq__   s:    %.. LI#L(,5;K(K	Lr   c                 J     | | j                             ||                    S )z.Convert a Python ``int`` object to ``dtype``. )r   r"   )K1rY   K0s      r   from_ZZzQuotientRing.from_ZZ   s"    r"'//!R(()))r   c                 H     | | j                             |                    S r   )r   
from_sympyrX   s     r   rb   zQuotientRing.from_sympy   s"    tDI((++,,,r   c                 @    | j                             |j                  S r   )r   r   r   rX   s     r   r   zQuotientRing.to_sympy   s    y!!!&)))r   c                     || k    r|S d S r   r@   )r   rY   r_   s      r   from_QuotientRingzQuotientRing.from_QuotientRing   s    ::H :r   c                      t          d          )z*Returns a polynomial ring, i.e. ``K[X]``. nested domains not allowedr#   r   genss     r   	poly_ringzQuotientRing.poly_ring       !">???r   c                      t          d          )z)Returns a fraction field, i.e. ``K(X)``. rg   rh   ri   s     r   
frac_fieldzQuotientRing.frac_field   rl   r   c                     | j                             |j                  | j        z   }	  | |                    d          d                   S # t
          $ r t          |d|           w xY w)z/
        Compute a**(-1), if possible.
           r   z not a unit in )r   rO   r   r   in_terms_of_generatorsrL   r   )r   rY   Is      r   r6   zQuotientRing.revert   s     IOOAF##do5	C40033A6777 	C 	C 	CDD ABBB	Cs   #A A,c                 @    | j                             |j                  S r   )r   containsr   rX   s     r   r   zQuotientRing.is_zero   s    ''///r   c                 "    t          | |          S )z
        Generate a free module of rank ``rank`` over ``self``.

        >>> from sympy.abc import x
        >>> from sympy import QQ
        >>> (QQ.old_poly_ring(x)/[x**2 + 1]).free_module(2)
        (QQ[x]/<x**2 + 1>)**2
        r   )r   ranks     r   free_modulezQuotientRing.free_module   s     &dD111r   N)rB   rC   rD   rE   has_assoc_Ringhas_assoc_Fieldr
   rT   r   r   rU   rZ   r>   r`   from_ZZ_pythonfrom_QQ_pythonfrom_ZZ_gmpyfrom_QQ_gmpyfrom_RealFieldfrom_GlobalPolynomialRingfrom_FractionFieldrb   r   re   rk   rn   r6   r   rw   r@   r   r   rJ   rJ   ]   s:        4 NOE' ' '; ; ;W W WC C CL L L
* * * N#N!L!L#N .'- - -* * *  @ @ @@ @ @C C C0 0 0	2 	2 	2 	2 	2r   rJ   N)rE   sympy.polys.agca.modulesr   sympy.polys.domains.ringr   sympy.polys.polyerrorsr   r   sympy.utilitiesr   r
   rJ   r@   r   r   <module>r      s    4 4 < ; ; ; ; ; ) ) ) ) ) ) @ @ @ @ @ @ @ @ " " " " " " K K K K K K K K\m2 m2 m2 m2 m24 m2 m2 m2 m2 m2r   