
    sg                     p    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y
)z.Implementation of :class:`QuotientRing` class.    FreeModuleQuotientRing)Ring)NotReversibleCoercionFailed)publicc                   j    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y)QuotientRingElementz
    Class representing elements of (commutative) quotient rings.

    Attributes:

    - ring - containing ring
    - data - element of ring.ring (i.e. base ring) representing self
    c                      || _         || _        y N)ringdata)selfr   r   s      S/var/www/html/venv/lib/python3.12/site-packages/sympy/polys/domains/quotientring.py__init__zQuotientRingElement.__init__   s    		    c                     ddl m} | j                  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__   sD    +yy~~&&tyy1DzE!C		(<(<$===r   c                 :    | j                   j                  |        S r   )r   is_zeror   s    r   __bool__zQuotientRingElement.__bool__$   s    99$$T***r   c                    t        || j                        r|j                  | j                  k7  r	 | j                  j                  |      }| j                  | j                  |j                  z         S # t        t
        f$ r	 t        cY S w xY wr   
isinstance	__class__r   convertNotImplementedErrorr   NotImplementedr   r   oms     r   __add__zQuotientRingElement.__add__'   sr    "dnn-DII1E&YY&&r* yyRWW,-- (8 &%%&s   A4 4BBc                     | j                  | j                  | j                   j                   j                  d      z        S )N)r   r   r"   r   s    r   __neg__zQuotientRingElement.__neg__1   s-    yy499>>#9#9"#==>>r   c                 &    | j                  |       S r   r'   r%   s     r   __sub__zQuotientRingElement.__sub__4   s    ||RC  r   c                 &    |  j                  |      S r   r,   r%   s     r   __rsub__zQuotientRingElement.__rsub__7   s    r""r   c                     t        || j                        s	 | j                  j                  |      }| j                  | j                  |j                  z        S # t        t
        f$ r	 t        cY S w xY wr   r   r   os     r   __mul__zQuotientRingElement.__mul__:   sc    !T^^,&II%%a( yy166)** (8 &%%&s   A A32A3c                 >    | j                   j                  |       |z  S r   )r   revertr1   s     r   __rtruediv__z QuotientRingElement.__rtruediv__D   s    yy%a''r   c                     t        || j                        s	 | j                  j                  |      }| j                  j                  |      | z  S # t        t
        f$ r	 t        cY S w xY wr   )r    r!   r   r"   r#   r   r$   r5   r1   s     r   __truediv__zQuotientRingElement.__truediv__G   sa    !T^^,&II%%a( yy"4'' (8 &%%&s   A A)(A)c                     |dk  r| j                   j                  |       | z  S | j                  | j                  |z        S )Nr   )r   r5   r   )r   oths     r   __pow__zQuotientRingElement.__pow__O   s=    799##D)cT11yyc)**r   c                     t        || j                        r|j                  | j                  k7  ry| j                  j                  | |z
        S )NF)r    r!   r   r   r%   s     r   __eq__zQuotientRingElement.__eq__T   s;    "dnn-DII1Eyy  ++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__r6   r8   r;   r=   r@   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y)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                        | _        y )NzIdeal must belong to z, got )r   
ValueErrorr   zeroone)r   r   ideals      r   r   zQuotientRing.__init__|   sT    zzT!$NOO	(			&r   c                 ^    t        | j                        dz   t        | j                        z   S )N/)r   r   r   r   s    r   r   zQuotientRing.__str__   s#    499~#c$//&:::r   c                     t        | j                  j                  | j                  | j                  | j
                  f      S r   )hashr!   rA   dtyper   r   r   s    r   __hash__zQuotientRing.__hash__   s,    T^^,,djj$))T__UVVr   c                     t        || j                  j                        s| j                  |      }| j                  | | j                  j	                  |            S )z4Construct an element of ``self`` domain from ``a``. )r    r   rS   r   reduce_elementr   as     r   newzQuotientRing.new   sA    !TYY__-		!Azz$ > >q ABBr   c                     t        |t              xr4 | j                  |j                  k(  xr | j                  |j                  k(  S )z0Returns ``True`` if two domains are equivalent. )r    rI   r   r   )r   others     r   r=   zQuotientRing.__eq__   s@    %. LII#L(,5;K;K(K	Lr   c                 F     | | j                   j                  ||            S )z.Convert a Python ``int`` object to ``dtype``. )r   r"   )K1rX   K0s      r   from_ZZzQuotientRing.from_ZZ   s    "''//!R())r   c                 D     | | j                   j                  |            S r   )r   
from_sympyrW   s     r   ra   zQuotientRing.from_sympy   s    DII((+,,r   c                 L    | j                   j                  |j                        S r   )r   r   r   rW   s     r   r   zQuotientRing.to_sympy   s    yy!!!&&))r   c                     || k(  r|S y r   r?   )r   rX   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)``. rf   rg   rh   s     r   
frac_fieldzQuotientRing.frac_field   rk   r   c                     | j                   j                  |j                        | j                  z   }	  | |j	                  d      d         S # t
        $ r t        |d|       w xY w)z/
        Compute a**(-1), if possible.
           r   z not a unit in )r   rN   r   r   in_terms_of_generatorsrK   r   )r   rX   Is      r   r5   zQuotientRing.revert   se     IIOOAFF#doo5	C003A677 	CD ABB	Cs   A A(c                 L    | j                   j                  |j                        S r   )r   containsr   rW   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1r   N)rA   rB   rC   rD   has_assoc_Ringhas_assoc_Fieldr
   rS   r   r   rT   rY   r=   r_   from_ZZ_pythonfrom_QQ_pythonfrom_ZZ_gmpyfrom_QQ_gmpyfrom_RealFieldfrom_GlobalPolynomialRingfrom_FractionFieldra   r   rd   rj   rm   r5   r   rv   r?   r   r   rI   rI   ]   s    4 NOE';WCL
* N#N!L!L#N .'-*@@C0	2r   rI   N)rD   sympy.polys.agca.modulesr   sympy.polys.domains.ringr   sympy.polys.polyerrorsr   r   sympy.utilitiesr   r
   rI   r?   r   r   <module>r      sA    4 < ) @ " K K K\m24 m2r   