
    MZd                     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      B/usr/lib/python3/dist-packages/sympy/polys/domains/quotientring.py__init__zQuotientRingElement.__init__   s    		    c                 x    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,    +DII&TYY-A-A)BBBr   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__0   s-    yy499>>#9#9"#==>>r   c                 &    | j                  |       S r   r&   r$   s     r   __sub__zQuotientRingElement.__sub__3   s    ||RC  r   c                 &    |  j                  |      S r   r+   r$   s     r   __rsub__zQuotientRingElement.__rsub__6   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__9   sc    !T^^,&II%%a( yy166)** (8 &%%&s   A A32A3c                 >    | j                   j                  |       |z  S r   )r   revertr0   s     r   __rtruediv__z QuotientRingElement.__rtruediv__C   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#   r4   r0   s     r   __truediv__zQuotientRingElement.__truediv__F   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   r4   r   )r   oths     r   __pow__zQuotientRingElement.__pow__N   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__S   s;    "dnn-DII1Eyy  ++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__r5   r7   r:   r<   r?   r>   r   r   r
   r
      s^    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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    r@   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   rR   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   rH   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!   )K1rW   K0s      r   from_ZZzQuotientRing.from_ZZ   s    "''//!R())r   c                 D     | | j                   j                  |            S r   )r   
from_sympyrV   s     r   r`   zQuotientRing.from_sympy   s    DII((+,,r   c                 L    | j                   j                  |j                        S r   )r   to_sympyr   rV   s     r   rb   zQuotientRing.to_sympy   s    yy!!!&&))r   c                     || k(  r|S y r   r>   )r   rW   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   rM   r   r   in_terms_of_generatorsrJ   r   )r   rW   Is      r   r4   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   rV   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)r@   rA   rB   rC   has_assoc_Ringhas_assoc_Fieldr
   rR   r   r   rS   rX   r<   r^   from_ZZ_pythonfrom_QQ_pythonfrom_ZZ_gmpyfrom_QQ_gmpyfrom_RealFieldfrom_GlobalPolynomialRingfrom_FractionFieldr`   rb   rd   rj   rm   r4   r   rv   r>   r   r   rH   rH   \   s    4 NOE';WCL
* N#N!L!L#N .'-*@@C0	2r   rH   N)rC   sympy.polys.agca.modulesr   sympy.polys.domains.ringr   sympy.polys.polyerrorsr   r   sympy.utilitiesr   r
   rH   r>   r   r   <module>r      sA    4 < ) @ " J J JZm24 m2r   