
    Ed                         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      @lib/python3.11/site-packages/sympy/polys/domains/quotientring.py__init__zQuotientRingElement.__init__   s    				    c                 h    ddl m}  || j                  dz   t          | j        j                  z   S )Nr   )sstrz + )sympy.printing.strr   r   strr   
base_ideal)r   r   s     r   __str__zQuotientRingElement.__str__   s;    ++++++tDI&TY-A)B)BBBr   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-- 	&DI1E 	&&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__0   s-    yy49>#9#9"#=#==>>>r   c                 .    |                      |           S r   r&   r$   s     r   __sub__zQuotientRingElement.__sub__3   s    ||RC   r   c                 .    |                       |          S r   r+   r$   s     r   __rsub__zQuotientRingElement.__rsub__6   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__9   sy    !T^,, 	&&I%%a(('8 & & &%%%%&yy16)***   2 AAc                 <    | j                             |           |z  S r   )r   revertr0   s     r   __rtruediv__z QuotientRingElement.__rtruediv__C   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#   r5   r0   s     r   __truediv__zQuotientRingElement.__truediv__F   sy    !T^,, 	&&I%%a(('8 & & &%%%%&y""4''r3   c                     |dk     r| j                             |           | z  S |                      | j        |z            S )Nr   )r   r5   r   )r   oths     r   __pow__zQuotientRingElement.__pow__N   sD    7 	2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__S   sE    "dn-- 	DI1E 	5y  +++r   c                     | |k     S r    r$   s     r   __ne__zQuotientRingElement.__ne__X   s    2:~r   N)__name__
__module____qualname____doc__r   r   __repr__r   r&   __radd__r)   r,   r.   r2   __rmul__r6   r8   r;   r=   r@   r?   r   r   r
   r
      s           C C C 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__{   si    zT! 	P*$$$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    rA   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   rS   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   rI   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!   )K1rX   K0s      r   from_ZZzQuotientRing.from_ZZ   s"    r"'//!R(()))r   c                 H     | | j                             |                    S r   )r   
from_sympyrW   s     r   ra   zQuotientRing.from_sympy   s"    tDI((++,,,r   c                 @    | j                             |j                  S r   )r   to_sympyr   rW   s     r   rc   zQuotientRing.to_sympy   s    y!!!&)))r   c                     || k    r|S d S 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)``. 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   rN   r   r   in_terms_of_generatorsrK   r   )r   rX   Is      r   r5   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   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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   rc   re   rk   rn   r5   r   rw   r?   r   r   rI   rI   \   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   rI   N)rD   sympy.polys.agca.modulesr   sympy.polys.domains.ringr   sympy.polys.polyerrorsr   r   sympy.utilitiesr   r
   rI   r?   r   r   <module>r      s    4 4 < ; ; ; ; ; ) ) ) ) ) ) @ @ @ @ @ @ @ @ " " " " " " J J J J J J J JZm2 m2 m2 m2 m24 m2 m2 m2 m2 m2r   