
    Ed                     b    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	dS )z'Implementation of :class:`Ring` class.     )Domain)ExactQuotientFailedNotInvertibleNotReversible)publicc                   j    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dS )RingzRepresents a ring domain. Tc                     | S )z)Returns a ring associated with ``self``.  )selfs    8lib/python3.11/site-packages/sympy/polys/domains/ring.pyget_ringzRing.get_ring   s        c                 8    ||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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                     |                      ||          \  }}}|                     |          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&   sD    **Q""1a;;q>> 	0q5L///r   c                 z    |                      |          s|                      |           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>> 	GT[[!__ 	GH EFFFr   c                 T    	 |                      |           dS # t          $ r Y dS w xY w)NTF)r%   r   r$   s     r   is_unitzRing.is_unit6   s=    	KKNNN4 	 	 	55	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	    x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                 p    ddl m}  ||  |                     d          j        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                     g | ]}|gS r   r   ).0xs     r   
<listcomp>zRing.ideal.<locals>.<listcomp>[   s       aqc   r   )sympy.polys.agca.idealsr2   r0   	submodule)r   gensr2   s      r   idealz
Ring.idealP   sZ     	CBBBBB%%d,ID,<,<Q,?,?,I  4   -" # # 	#r   c                 f    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)r8   r=    sympy.polys.domains.quotientringr>   
isinstancer;   )r   er=   r>   s       r   quotient_ringzRing.quotient_ring]   sY    $ 	211111AAAAAA!U## 	
AA|D!$$$r   c                 ,    |                      |          S )N)rB   )r   rA   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   r;   rB   rD   r   r   r   r	   r	   	   s        $$G          0 0 0G G G      	" 	" 	"# # #% % %0% % % % %r   r	   N)
rH   sympy.polys.domains.domainr   sympy.polys.polyerrorsr   r   r   sympy.utilitiesr   r	   r   r   r   <module>rM      s    - - . - - - - - T T T T T T T T T T " " " " " "l% l% l% l% l%6 l% l% l% l% l%r   