U
    L?h                     @   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   J/var/www/html/venv/lib/python3.8/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
   quo   s    zRing.quoc                 C   s   || S )z4Remainder of ``a`` and ``b``, implies ``__mod__``.  r   r   r   r   r
   rem   s    zRing.remc                 C   s
   t ||S )z5Division of ``a`` and ``b``, implies ``__divmod__``. )divmodr   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&   |  |s|  | r|S tddS )z!Returns ``a**(-1)`` if possible. z#only units are reversible in a ringN)r   r   r	   r   r   r   r
   revert/   s    zRing.revertc                 C   s,   z|  | W dS  tk
r&   Y dS X d S )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=   s    z
Ring.numerc                 C   s   | j S )zReturns denominator of `a`. )oner   r   r   r
   denomA   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_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    	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
   