a
    RG5d¤  ã                   @   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   úT/var/www/html/django/DPS/env/lib/python3.9/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)Ú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y$   Y dS 0 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	   Ú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>[   ó    zRing.ideal.<locals>.<listcomp>)Úsympy.polys.agca.idealsr#   r"   Z	submodule)r	   Ú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)r0   )r	   r/   r   r   r
   Ú__truediv__u   s    zRing.__truediv__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úis_Ringr   r   r   r   r   r   r   r   r   r   r"   r+   r0   r1   r   r   r   r
   r   	   s    	r   N)
r5   Zsympy.polys.domains.domainr   Úsympy.polys.polyerrorsr   r   r   Úsympy.utilitiesr   r   r   r   r   r
   Ú<module>   s
   