o
    jg  ã                   @   s^   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„ dƒƒZ
G dd	„ d	eƒZd
S )z.Implementation of :class:`QuotientRing` class.é    ©ÚFreeModuleQuotientRing)ÚRing)ÚNotReversibleÚCoercionFailed)Úpublicc                   @   s„   e Zd ZdZdd„ Zdd„ ZeZdd„ Zdd	„ ZeZ	d
d„ Z
dd„ Zdd„ Zdd„ ZeZdd„ Zdd„ Zdd„ Zdd„ Zd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                 C   s   || _ || _d S ©N)ÚringÚdata)Úselfr
   r   © r   úX/var/www/html/zoom/venv/lib/python3.10/site-packages/sympy/polys/domains/quotientring.pyÚ__init__   s   
zQuotientRingElement.__init__c                 C   s4   ddl m} | jj | j¡}||ƒd t| jjƒ S )Nr   )Ússtrz + )Úsympy.printing.strr   r
   Úto_sympyr   ÚstrÚ
base_ideal)r   r   r   r   r   r   Ú__str__   s   zQuotientRingElement.__str__c                 C   s   | j  | ¡ S r	   )r
   Úis_zero©r   r   r   r   Ú__bool__$   ó   zQuotientRingElement.__bool__c              	   C   sV   t || jƒr|j| jkr"z| j |¡}W n ttfy!   t Y S w |  | j|j ¡S r	   ©Ú
isinstanceÚ	__class__r
   ÚconvertÚNotImplementedErrorr   ÚNotImplementedr   ©r   Úomr   r   r   Ú__add__'   s   ÿzQuotientRingElement.__add__c                 C   s   |   | j| j j  d¡ ¡S )Néÿÿÿÿ)r
   r   r   r   r   r   r   Ú__neg__1   ó   zQuotientRingElement.__neg__c                 C   s   |   | ¡S r	   ©r"   r    r   r   r   Ú__sub__4   ó   zQuotientRingElement.__sub__c                 C   s   |    |¡S r	   r&   r    r   r   r   Ú__rsub__7   r(   zQuotientRingElement.__rsub__c              	   C   sJ   t || jƒsz| j |¡}W n ttfy   t Y S w |  | j|j ¡S r	   r   ©r   Úor   r   r   Ú__mul__:   s   ÿzQuotientRingElement.__mul__c                 C   s   | j  | ¡| S r	   )r
   Úrevertr*   r   r   r   Ú__rtruediv__D   ó   z QuotientRingElement.__rtruediv__c              	   C   sH   t || jƒsz| j |¡}W n ttfy   t Y S w | j |¡|  S r	   )r   r   r
   r   r   r   r   r-   r*   r   r   r   Ú__truediv__G   s   ÿzQuotientRingElement.__truediv__c                 C   s*   |dk r| j  | ¡|  S |   | j| ¡S )Nr   )r
   r-   r   )r   Úothr   r   r   Ú__pow__O   s   zQuotientRingElement.__pow__c                 C   s,   t || jƒr|j| jkrdS | j | | ¡S )NF)r   r   r
   r   r    r   r   r   Ú__eq__T   s   zQuotientRingElement.__eq__c                 C   s
   | |k S r	   r   r    r   r   r   Ú__ne__Y   s   
zQuotientRingElement.__ne__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Ú__repr__r   r"   Ú__radd__r$   r'   r)   r,   Ú__rmul__r.   r0   r2   r3   r4   r   r   r   r   r      s$    	r   c                   @   s¨   e Zd ZdZdZdZeZdd„ Zdd„ Z	dd	„ Z
d
d„ Zdd„ Zdd„ ZeZeZeZeZeZeZeZdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd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                 C   sF   |j |kstd||f ƒ‚|| _ || _| | j jƒ| _| | j jƒ| _d S )NzIdeal must belong to %s, got %s)r
   Ú
ValueErrorr   ÚzeroÚone)r   r
   Úidealr   r   r   r   |   s   
zQuotientRing.__init__c                 C   s   t | jƒd t | jƒ S )Nú/)r   r
   r   r   r   r   r   r   „   s   zQuotientRing.__str__c                 C   s   t | jj| j| j| jfƒS r	   )Úhashr   r5   Údtyper
   r   r   r   r   r   Ú__hash__‡   r%   zQuotientRing.__hash__c                 C   s,   t || jjƒs|  |¡}|  | | j |¡¡S )z4Construct an element of ``self`` domain from ``a``. )r   r
   rC   r   Úreduce_element©r   Úar   r   r   ÚnewŠ   s   
zQuotientRing.newc                 C   s"   t |tƒo| j|jko| j|jkS )z0Returns ``True`` if two domains are equivalent. )r   r<   r
   r   )r   Úotherr   r   r   r3   ‘   s
   

ÿ
ÿzQuotientRing.__eq__c                 C   s   | | j  ||¡ƒS )z.Convert a Python ``int`` object to ``dtype``. )r
   r   )ÚK1rG   ÚK0r   r   r   Úfrom_ZZ–   s   zQuotientRing.from_ZZc                 C   s   | | j  |¡ƒS r	   )r
   Ú
from_sympyrF   r   r   r   rM   ¢   r/   zQuotientRing.from_sympyc                 C   ó   | j  |j¡S r	   )r
   r   r   rF   r   r   r   r   ¥   r   zQuotientRing.to_sympyc                 C   s   || kr|S d S r	   r   )r   rG   rK   r   r   r   Úfrom_QuotientRing¨   s   ÿzQuotientRing.from_QuotientRingc                 G   ó   t dƒ‚)z*Returns a polynomial ring, i.e. ``K[X]``. únested domains not allowed©r   ©r   Úgensr   r   r   Ú	poly_ring¬   ó   zQuotientRing.poly_ringc                 G   rP   )z)Returns a fraction field, i.e. ``K(X)``. rQ   rR   rS   r   r   r   Ú
frac_field°   rV   zQuotientRing.frac_fieldc                 C   sH   | j  |j¡| j }z
| | d¡d ƒW S  ty#   td|| f ƒ‚w )z/
        Compute a**(-1), if possible.
        é   r   z%s not a unit in %r)r
   r@   r   r   Úin_terms_of_generatorsr=   r   )r   rG   ÚIr   r   r   r-   ´   s   ÿzQuotientRing.revertc                 C   rN   r	   )r   Úcontainsr   rF   r   r   r   r   ¾   r   zQuotientRing.is_zeroc                 C   s
   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   Úrankr   r   r   Úfree_moduleÁ   s   
	zQuotientRing.free_moduleN)r5   r6   r7   r8   Úhas_assoc_RingÚhas_assoc_Fieldr   rC   r   r   rD   rH   r3   rL   Úfrom_ZZ_pythonÚfrom_QQ_pythonÚfrom_ZZ_gmpyÚfrom_QQ_gmpyÚfrom_RealFieldÚfrom_GlobalPolynomialRingÚfrom_FractionFieldrM   r   rO   rU   rW   r-   r   r]   r   r   r   r   r<   ]   s4    
r<   N)r8   Úsympy.polys.agca.modulesr   Úsympy.polys.domains.ringr   Úsympy.polys.polyerrorsr   r   Úsympy.utilitiesr   r   r<   r   r   r   r   Ú<module>   s    N