
    Ed                         d Z ddlmZmZmZ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
 ZdS )z1Implementation of :class:`ModularInteger` class.     )AnyDictTupleTypeN)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   r6   r   r   NotImplementedr   r5   r   s      r   __add__zModularInteger.__add__D   9    mmE"" 	">>$(S.111!!r   c                 ,    |                      |          S r   r;   r   r5   s     r   __radd__zModularInteger.__radd__L       ||E"""r   c                 x    |                      |          }||                     | j        |z
            S t          S r   r8   r:   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   r8   r:   s      r   __mul__zModularInteger.__mul__Z   r<   r   c                 ,    |                      |          S r   )rG   r?   s     r   __rmul__zModularInteger.__rmul__b   rA   r   c                     |                      |          }|0|                     | j        |                     |          z            S t          S r   )r6   r   r   _invertr9   r:   s      r   __truediv__zModularInteger.__truediv__e   sF    mmE"" 	">>$(T\\#->->">???!!r   c                 P    |                                                      |          S r   )invertrG   r?   s     r   __rtruediv__zModularInteger.__rtruediv__m   s    {{}}$$U+++r   c                 x    |                      |          }||                     | j        |z            S t          S r   r8   r:   s      r   __mod__zModularInteger.__mod__p   r<   r   c                 x    |                      |          }||                     || j        z            S t          S r   r8   r:   s      r   __rmod__zModularInteger.__rmod__x   s9    mmE"" 	">>#.111!!r   c                    |s|                      | j        j                  S |dk     r|                                 j        | }}n| j        }|                      t          |t          |          | j                            S )Nr   )r   r   onerN   r   powr(   r   )r   expr   s      r   __pow__zModularInteger.__pow__   sq     	0>>$(,///7 	{{}}(3$CC(C~~c#s3xx::;;;r   c                 p    |                      |          }| || j        || j        z            S t          S r   )r6   r   r   r9   )r   r5   opr   s       r   _comparezModularInteger._compare   s;    mmE"" 	"2dhdh///!!r   c                 B    |                      |t          j                  S r   )r[   operatoreqr?   s     r   __eq__zModularInteger.__eq__       }}UHK000r   c                 B    |                      |t          j                  S r   )r[   r]   ner?   s     r   __ne__zModularInteger.__ne__   r`   r   c                 B    |                      |t          j                  S r   )r[   r]   ltr?   s     r   __lt__zModularInteger.__lt__   r`   r   c                 B    |                      |t          j                  S r   )r[   r]   ler?   s     r   __le__zModularInteger.__le__   r`   r   c                 B    |                      |t          j                  S r   )r[   r]   gtr?   s     r   __gt__zModularInteger.__gt__   r`   r   c                 B    |                      |t          j                  S r   )r[   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   rN   r   )r4   values     r   rK   zModularInteger._invert   s    w~~eSW---r   c                 \    |                      |                     | j                            S r   )r   rK   r   r   s    r   rN   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)   r0   r2   classmethodr6   r;   r@   rC   rE   rG   rI   rL   rO   rQ   rS   rX   r[   r_   rc   rf   ri   rl   ro   rr   rK   rN   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   c                 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#   rv   rw   r   r   r-   r   )_dom_mod_symr   s   r   r4   r~      s#         $MCcGGGr   r4   zSymmetricModularIntegerMod%szModularIntegerMod%s)r   r   
ValueError_modular_integer_cacheKeyErrorr   r#   )r   r   r   r   okkeyr4   s   ````   r   ModularIntegerFactoryr      s-   ||D!!     
  N NELMMM
d
C*$S) 
* 
* 
*	 	 	 	 	 	 	 	 	 	. 	 	 	  	89D@CLL047CL&)s###
* Js    --A AB$#B$)rx   typingr   r   tDictr   tTupler   r]   sympy.polys.polyutilsr   sympy.polys.polyerrorsr   !sympy.polys.domains.domainelementr	   sympy.utilitiesr
   r   r   r   r/   r   r   <module>r      s    7 7 = < < < < < < < < < < <  4 4 4 4 4 4 1 1 1 1 1 1 ; ; ; ; ; ; " " " " " "^6 ^6 ^6 ^6 ^6' ^6 ^6 ^6@      r   