
    sg                     T    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e             Z	y)z'Implementation of :class:`Ring` class.     )Domain)ExactQuotientFailedNotInvertibleNotReversible)publicc                   h    e Zd ZdZdZd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zy)RingzRepresents a ring domain. Tc                     | S )z)Returns a ring associated with ``self``.  )selfs    K/var/www/html/venv/lib/python3.12/site-packages/sympy/polys/domains/ring.pyget_ringzRing.get_ring   s        c                 0    ||z  rt        |||       ||z  S )z>Exact quotient of ``a`` and ``b``, implies ``__floordiv__``.  )r   r   abs      r   exquoz
Ring.exquo   s!    q5%aD116Mr   c                     ||z  S )z7Quotient of ``a`` and ``b``, implies ``__floordiv__``. r   r   s      r   quozRing.quo   s    Avr   c                     ||z  S )z4Remainder of ``a`` and ``b``, implies ``__mod__``.  r   r   s      r   remzRing.rem   s    1ur   c                     t        ||      S )z5Division of ``a`` and ``b``, implies ``__divmod__``. )divmodr   s      r   divzRing.div"   s    a|r   c                 p    | j                  ||      \  }}}| j                  |      r||z  S t        d      )z"Returns inversion of ``a mod b``. zzero divisor)gcdexis_oner   )r   r   r   sths         r   invertzRing.invert&   s7    **Q"1a;;q>q5L//r   c                 b    | j                  |      s| j                  |       r|S t        d      )z!Returns ``a**(-1)`` if possible. z#only units are reversible in a ring)r   r   r   r   s     r   revertzRing.revert/   s*    ;;q>T[[!_H EFFr   c                 F    	 | j                  |       y# t        $ r Y yw xY w)NTF)r%   r   r$   s     r   is_unitzRing.is_unit6   s'    	KKN 		s    	  c                     |S )zReturns numerator of ``a``. r   r$   s     r   numerz
Ring.numer=   s    r   c                     | j                   S )zReturns denominator of `a`. )oner$   s     r   denomz
Ring.denomA   s    xxr   c                     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   ranks     r   free_modulezRing.free_moduleE   s
     "!r   c           	          ddl m}  ||  | j                  d      j                  |D cg c]  }|g c}       S c c}w )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   )sympy.polys.agca.idealsr2   r0   	submodule)r   gensr2   xs       r   idealz
Ring.idealP   sE     	C%d,ID,<,<Q,?,I,I aqc -" # 	# s   
;c                 b    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)r4   r:    sympy.polys.domains.quotientringr;   
isinstancer8   )r   er:   r;   s       r   quotient_ringzRing.quotient_ring]   s0    $ 	2A!U#

AAD!$$r   c                 $    | j                  |      S )N)r?   )r   r>   s     r   __truediv__zRing.__truediv__u   s    !!!$$r   N)__name__
__module____qualname____doc__is_Ringr   r   r   r   r   r"   r%   r'   r)   r,   r0   r8   r?   rA   r   r   r   r	   r	   	   sQ    $G0G	"#%0%r   r	   N)
rE   sympy.polys.domains.domainr   sympy.polys.polyerrorsr   r   r   sympy.utilitiesr   r	   r   r   r   <module>rJ      s2    - . T T "l%6 l% l%r   