
    Rie                        U d Z ddlmZ ddlmZ ddlZddlmZ ddlm	Z	 ddl
mZ ddlmZ e G d	 d
ee                      Zi Zded<   d ZdS )z1Implementation of :class:`ModularInteger` class.     )annotations)AnyN)PicklableWithSlots)CoercionFailed)DomainElement)publicc                      e Zd ZdZd\  ZZZZdZd Z	d Z
d Zd Zd Zd	 Zd
 Zd Zd Ze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 Z$d Z%d  Z&ed!             Z'd" Z(d#S )$ModularIntegerz(A class representing a modular integer. )NNNN)valc                    | j         S N)_parentselfs    Blib/python3.11/site-packages/sympy/polys/domains/modularinteger.pyparentzModularInteger.parent   s
    |    c                    t          || j                  r|j        | j        z  | _        d S | j                            |          | j        z  | _        d S r   )
isinstance	__class__r   moddomconvert)r   r   s     r   __init__zModularInteger.__init__   sL    c4>** 	8w)DHHHx'',,tx7DHHHr   c                8    t          | j        | j        f          S r   )hashr   r   r   s    r   __hash__zModularInteger.__hash__   s    TXtx()))r   c                0    | j         j        d| j        dS )N())r   __name__r   r   s    r   __repr__zModularInteger.__repr__"   s    >222DHHH==r   c                $    | j         d| j        S )Nz mod )r   r   r   s    r   __str__zModularInteger.__str__%   s    "hhh11r   c                D    t          |                                           S r   )intto_intr   s    r   __int__zModularInteger.__int__(   s    4;;==!!!r   c                p    | j         r)| j        | j        dz  k    r| j        S | j        | j        z
  S | j        S )N   )symr   r   r   s    r   r'   zModularInteger.to_int+   s<    8 	x48q=((xx$(**8Or   c                    | S r    r   s    r   __pos__zModularInteger.__pos__4   s    r   c                8    |                      | j                   S r   )r   r   r   s    r   __neg__zModularInteger.__neg__7   s    ~~txi(((r   c                    t          ||           r|j        S 	 | j                            |          S # t          $ r Y d S w xY wr   )r   r   r   r   r   )clsothers     r   _get_valzModularInteger._get_val:   sW    eS!! 	9wu---!   tts   3 
A Ac                x    |                      |          }||                     | j        |z             S t          S r   r4   r   r   NotImplementedr   r3   r   s      r   __add__zModularInteger.__add__D   6    mmE""?>>$(S.111!!r   c                ,    |                      |          S r   r9   r   r3   s     r   __radd__zModularInteger.__radd__L       ||E"""r   c                x    |                      |          }||                     | j        |z
            S t          S r   r6   r8   s      r   __sub__zModularInteger.__sub__O   r:   r   c                .    |                       |          S r   r<   r=   s     r   __rsub__zModularInteger.__rsub__W   s    u%%%r   c                x    |                      |          }||                     | j        |z            S t          S r   r6   r8   s      r   __mul__zModularInteger.__mul__Z   r:   r   c                ,    |                      |          S r   )rE   r=   s     r   __rmul__zModularInteger.__rmul__b   r?   r   c                    |                      |          }|0|                     | j        |                     |          z            S t          S r   )r4   r   r   _invertr7   r8   s      r   __truediv__zModularInteger.__truediv__e   sC    mmE""?>>$(T\\#->->">???!!r   c                P    |                                                      |          S r   )invertrE   r=   s     r   __rtruediv__zModularInteger.__rtruediv__m   s    {{}}$$U+++r   c                x    |                      |          }||                     | j        |z            S t          S r   r6   r8   s      r   __mod__zModularInteger.__mod__p   r:   r   c                x    |                      |          }||                     || j        z            S t          S r   r6   r8   s      r   __rmod__zModularInteger.__rmod__x   s6    mmE""?>>#.111!!r   c                   |s|                      | j        j                  S |dk     r|                                 j        | }}n| j        }|                      t          |t          |          | j                            S )Nr   )r   r   onerL   r   powr&   r   )r   expr   s      r   __pow__zModularInteger.__pow__   sn     	0>>$(,///77{{}}(3$CC(C~~c#s3xx::;;;r   c                p    |                      |          }| || j        || j        z            S t          S r   )r4   r   r   r7   )r   r3   opr   s       r   _comparezModularInteger._compare   s8    mmE""?2dhdh///!!r   c                B    |                      |t          j                  S r   )rY   operatoreqr=   s     r   __eq__zModularInteger.__eq__       }}UHK000r   c                B    |                      |t          j                  S r   )rY   r[   ner=   s     r   __ne__zModularInteger.__ne__   r^   r   c                B    |                      |t          j                  S r   )rY   r[   ltr=   s     r   __lt__zModularInteger.__lt__   r^   r   c                B    |                      |t          j                  S r   )rY   r[   ler=   s     r   __le__zModularInteger.__le__   r^   r   c                B    |                      |t          j                  S r   )rY   r[   gtr=   s     r   __gt__zModularInteger.__gt__   r^   r   c                B    |                      |t          j                  S r   )rY   r[   ger=   s     r   __ge__zModularInteger.__ge__   r^   r   c                *    t          | j                  S r   )boolr   r   s    r   __bool__zModularInteger.__bool__   s    DH~~r   c                B    | j                             || j                  S r   )r   rL   r   )r2   values     r   rI   zModularInteger._invert   s    w~~eSW---r   c                \    |                      |                     | j                            S r   )r   rI   r   r   s    r   rL   zModularInteger.invert   s"    ~~dll4844555r   N))r!   
__module____qualname____doc__r   r   r+   r   	__slots__r   r   r   r"   r$   r(   r'   r.   r0   classmethodr4   r9   r>   rA   rC   rE   rG   rJ   rM   rO   rQ   rV   rY   r]   ra   rd   rg   rj   rm   rp   rI   rL   r-   r   r   r
   r
      s       223Cc7I  8 8 8* * *> > >2 2 2" " "    ) ) )   [" " "# # #" " "& & &" " "# # #" " ", , ," " "" " "	< 	< 	<" " "1 1 11 1 11 1 11 1 11 1 11 1 1   . . [.6 6 6 6 6r   r
   z0dict[tuple[Any, Any, Any], type[ModularInteger]]_modular_integer_cachec                R    	                                  d}n# t          $ r d}Y nw xY w|r dk     rt          d z             f}	 t          |         }nI# t          $ r<  G  fddt
                    }rd z  |_        n
d z  |_        |t          |<   Y nw xY w|S )	z1Create custom class for specific integer modulus.TF   z*modulus must be a positive integer, got %sc                  "    e Zd Z cZZZZdS )"ModularIntegerFactory.<locals>.clsN)r!   rt   ru   r   r   r+   r   )_dom_mod_symr   s   r   r2   r}      s#         $MCcGGGr   r2   zSymmetricModularIntegerMod%szModularIntegerMod%s)r   r   
ValueErrorry   KeyErrorr
   r!   )r   r~   r   r   okkeyr2   s   ````   r   ModularIntegerFactoryr      s)   ||D!!     
  NELMMM
d
C*$S) 
* 
* 
*	 	 	 	 	 	 	 	 	 	. 	 	 	  	89D@CLL047CL&)s###
* Js    --A AB$#B$)rv   
__future__r   typingr   r[   sympy.polys.polyutilsr   sympy.polys.polyerrorsr   !sympy.polys.domains.domainelementr   sympy.utilitiesr   r
   ry   __annotations__r   r-   r   r   <module>r      s    7 7 7 " " " " " "        4 4 4 4 4 4 1 1 1 1 1 1 ; ; ; ; ; ; " " " " " "^6 ^6 ^6 ^6 ^6' ^6 ^6 ^6@ LN  M M M M    r   