o
    à8Va¤  ã                   @   sH   d Z ddlmZ ddlmZmZmZ ddlmZ eG dd„ deƒƒZ	dS )z'Implementation of :class:`Ring` class. é    )ÚDomain)ÚExactQuotientFailedÚNotInvertibleÚNotReversible)Úpublicc                   @   s„   e Zd ZdZd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d„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS ) ÚRingzRepresents a ring domain. Tc                 C   s   | S )z)Returns a ring associated with ``self``. © )Úselfr   r   ú:/usr/lib/python3/dist-packages/sympy/polys/domains/ring.pyÚget_ring   ó   zRing.get_ringc                 C   s   || r
t ||| ƒ‚|| S )z>Exact quotient of ``a`` and ``b``, implies ``__floordiv__``.  )r   ©r	   ÚaÚbr   r   r
   Úexquo   s   z
Ring.exquoc                 C   s   || S )z7Quotient of ``a`` and ``b``, implies ``__floordiv__``. r   r   r   r   r
   Úquo   ó   zRing.quoc                 C   s   || S )z4Remainder of ``a`` and ``b``, implies ``__mod__``.  r   r   r   r   r
   Úrem   r   zRing.remc                 C   s
   t ||ƒS )z5Division of ``a`` and ``b``, implies ``__divmod__``. )Údivmodr   r   r   r
   Údiv"   s   
zRing.divc                 C   s,   |   ||¡\}}}|  |¡r|| S tdƒ‚)z"Returns inversion of ``a mod b``. zzero divisor)ZgcdexÚis_oner   )r	   r   r   ÚsÚtÚhr   r   r
   Úinvert&   s   
zRing.invertc                 C   s"   |   |¡s|   | ¡r|S tdƒ‚)z!Returns ``a**(-1)`` if possible. z#only units are reversible in a ring)r   r   ©r	   r   r   r   r
   Úrevert/   s   zRing.revertc                 C   s&   z|   |¡ W dS  ty   Y dS w )NTF)r   r   r   r   r   r
   Úis_unit6   s   
ÿzRing.is_unitc                 C   s   |S )zReturns numerator of ``a``. r   r   r   r   r
   Únumer=   r   z
Ring.numerc                 C   s   | j S )zReturns denominator of `a`. )Zoner   r   r   r
   ÚdenomA   s   z
Ring.denomc                 C   s   t ‚)zÊ
        Generate a free module of rank ``rank`` over self.

        >>> from sympy.abc import x
        >>> from sympy import QQ
        >>> QQ.old_poly_ring(x).free_module(2)
        QQ[x]**2
        )ÚNotImplementedError)r	   Zrankr   r   r
   Úfree_moduleE   s   	zRing.free_modulec                 G   s,   ddl m} || |  d¡jdd„ |D ƒŽ ƒS )z±
        Generate an ideal of ``self``.

        >>> from sympy.abc import x
        >>> from sympy import QQ
        >>> QQ.old_poly_ring(x).ideal(x**2)
        <x**2>
        r   )ÚModuleImplementedIdealé   c                 S   s   g | ]}|g‘qS r   r   )Ú.0Úxr   r   r
   Ú
<listcomp>[   s    zRing.ideal.<locals>.<listcomp>)Úsympy.polys.agca.idealsr"   r!   Z	submodule)r	   Zgensr"   r   r   r
   ÚidealP   s   	ÿz
Ring.idealc                 C   s6   ddl m} ddlm} t||ƒs| j|Ž }|| |ƒS )aÖ  
        Form a quotient ring of ``self``.

        Here ``e`` can be an ideal or an iterable.

        >>> from sympy.abc import x
        >>> from sympy import QQ
        >>> QQ.old_poly_ring(x).quotient_ring(QQ.old_poly_ring(x).ideal(x**2))
        QQ[x]/<x**2>
        >>> QQ.old_poly_ring(x).quotient_ring([x**2])
        QQ[x]/<x**2>

        The division operator has been overloaded for this:

        >>> QQ.old_poly_ring(x)/[x**2]
        QQ[x]/<x**2>
        r   )ÚIdeal)ÚQuotientRing)r'   r)   Z sympy.polys.domains.quotientringr*   Ú
isinstancer(   )r	   Úer)   r*   r   r   r
   Úquotient_ring]   s
   


zRing.quotient_ringc                 C   s
   |   |¡S )N)r-   )r	   r,   r   r   r
   Ú__truediv__u   s   
zRing.__truediv__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Zis_Ringr   r   r   r   r   r   r   r   r   r   r!   r(   r-   r.   r   r   r   r
   r   	   s"    	r   N)
r2   Zsympy.polys.domains.domainr   Zsympy.polys.polyerrorsr   r   r   Zsympy.utilitiesr   r   r   r   r   r
   Ú<module>   s    