B
    ˜‘[×  ã               @   sX   d Z ddlmZm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. é    )Úprint_functionÚdivision)Ú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eZdS ) ÚRingzRepresents a ring domain. Tc             C   s   | S )z)Returns a ring associated with ``self``. © )Úselfr
   r
   ú7lib/python3.7/site-packages/sympy/polys/domains/ring.pyÚget_ring   s    zRing.get_ringc             C   s"   || rt ||| ƒ‚n|| S dS )z>Exact quotient of ``a`` and ``b``, implies ``__floordiv__``.  N)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
   r
   r   Úquo   s    zRing.quoc             C   s   || S )z4Remainder of ``a`` and ``b``, implies ``__mod__``.  r
   )r   r   r   r
   r
   r   Úrem   s    zRing.remc             C   s
   t ||ƒS )z5Division of ``a`` and ``b``, implies ``__divmod__``. )Údivmod)r   r   r   r
   r
   r   Údiv#   s    zRing.divc             C   s0   |   ||¡\}}}|  |¡r$|| S tdƒ‚dS )z"Returns inversion of ``a mod b``. zzero divisorN)ZgcdexÚis_oner   )r   r   r   ÚsÚtÚhr
   r
   r   Úinvert'   s    
zRing.invertc             C   s   |   |¡r|S tdƒ‚dS )z!Returns ``a**(-1)`` if possible. z"only unity is reversible in a ringN)r   r   )r   r   r
   r
   r   Úrevert0   s    
zRing.revertc             C   s(   y|   |¡ dS  tk
r"   dS X d S )NTF)r   r   )r   r   r
   r
   r   Úis_unit7   s
    
zRing.is_unitc             C   s   |S )zReturns numerator of ``a``. r
   )r   r   r
   r
   r   Únumer>   s    z
Ring.numerc             C   s   | j S )zReturns denominator of `a`. )Zone)r   r   r
   r
   r   ÚdenomB   s    z
Ring.denomc             C   s   t ‚d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).free_module(2)
        QQ[x]**2
        N)ÚNotImplementedError)r   Zrankr
   r
   r   Úfree_moduleF   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   ÚidealQ   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   Ú__div__v   s    zRing.__div__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Zis_Ringr   r   r   r   r   r   r   r   r   r   r   r&   r+   r,   Ú__truediv__r
   r
   r
   r   r	   
   s"   	r	   N)r0   Z
__future__r   r   Zsympy.polys.domains.domainr   Zsympy.polys.polyerrorsr   r   r   Zsympy.utilitiesr   r	   r
   r
   r
   r   Ú<module>   s   