
    g                        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 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)public)sympy_deprecation_warningc                  
   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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'd" Z(ed#             Z)d$ Z*d%S )&ModularIntegerz(A class representing a modular integer. )NNNN)valc                    | j         S N)_parentselfs    ^/var/www/html/ai-engine/env/lib/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                    | j         S r   )r   r   s    r   moduluszModularInteger.modulus    s	    xr   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                *    t          | j                  S r   )intr   r   s    r   __int__zModularInteger.__int__,   s    48}}r   c                    t          ddd           | j        r)| j        | j        dz  k    r| j        S | j        | j        z
  S | j        S )NzModularInteger.to_int() is deprecated.

            Use int(a) or K = GF(p) and K.to_int(a) instead of a.to_int().
            1.13zmodularinteger-to-int)deprecated_since_versionactive_deprecations_target   )r	   symr   r   r   s    r   to_intzModularInteger.to_int/   sb    ! &,'>	
 	
 	
 	
 8 	x48q=((xx$(**8Or   c                    | S r    r   s    r   __pos__zModularInteger.__pos__B   s    r   c                8    |                      | j                   S r   )r   r   r   s    r   __neg__zModularInteger.__neg__E   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_valH   sW    eS!! 	9wu---!   tts   3 
A Ac                x    |                      |          }||                     | j        |z             S t          S r   r:   r   r   NotImplementedr   r9   r   s      r   __add__zModularInteger.__add__R   6    mmE""?>>$(S.111!!r   c                ,    |                      |          S r   r?   r   r9   s     r   __radd__zModularInteger.__radd__Z       ||E"""r   c                x    |                      |          }||                     | j        |z
            S t          S r   r<   r>   s      r   __sub__zModularInteger.__sub__]   r@   r   c                .    |                       |          S r   rB   rC   s     r   __rsub__zModularInteger.__rsub__e   s    u%%%r   c                x    |                      |          }||                     | j        |z            S t          S r   r<   r>   s      r   __mul__zModularInteger.__mul__h   r@   r   c                ,    |                      |          S r   )rK   rC   s     r   __rmul__zModularInteger.__rmul__p   rE   r   c                    |                      |          }|0|                     | j        |                     |          z            S t          S r   )r:   r   r   _invertr=   r>   s      r   __truediv__zModularInteger.__truediv__s   sC    mmE""?>>$(T\\#->->">???!!r   c                P    |                                                      |          S r   )invertrK   rC   s     r   __rtruediv__zModularInteger.__rtruediv__{   s    {{}}$$U+++r   c                x    |                      |          }||                     | j        |z            S t          S r   r<   r>   s      r   __mod__zModularInteger.__mod__~   r@   r   c                x    |                      |          }||                     || j        z            S t          S r   r<   r>   s      r   __rmod__zModularInteger.__rmod__   s6    mmE""?>>#.111!!r   c                   |s|                      | j        j                  S |dk     r|                                 j        | }}n| j        }|                      t          |t          |          | j                            S )Nr   )r   r   onerR   r   powr)   r   )r   expr   s      r   __pow__zModularInteger.__pow__   sn     	0>>$(,///77{{}}(3$CC(C~~c#s3xx::;;;r   c                p    |                      |          }|t          S  || j        || j        z            S r   )r:   r=   r   r   r   r9   opr   s       r   _comparezModularInteger._compare   s8    mmE"";!!r$(C$(N+++r   c                    |                      |          }|t          S t          dddd            || j        || j        z            S )Nz~Ordered comparisons with modular integers are deprecated.

            Use e.g. int(a) < int(b) instead of a < b.
            r,   zmodularinteger-compare   )r-   r.   
stacklevel)r:   r=   r	   r   r   r^   s       r   _compare_deprecatedz"ModularInteger._compare_deprecated   sa    mmE"";!!! &,'?	
 	
 	
 	
 r$(C$(N+++r   c                B    |                      |t          j                  S r   )r`   operatoreqrC   s     r   __eq__zModularInteger.__eq__       }}UHK000r   c                B    |                      |t          j                  S r   )r`   rf   nerC   s     r   __ne__zModularInteger.__ne__   ri   r   c                B    |                      |t          j                  S r   )rd   rf   ltrC   s     r   __lt__zModularInteger.__lt__       ''x{;;;r   c                B    |                      |t          j                  S r   )rd   rf   lerC   s     r   __le__zModularInteger.__le__   rp   r   c                B    |                      |t          j                  S r   )rd   rf   gtrC   s     r   __gt__zModularInteger.__gt__   rp   r   c                B    |                      |t          j                  S r   )rd   rf   gerC   s     r   __ge__zModularInteger.__ge__   rp   r   c                *    t          | j                  S r   )boolr   r   s    r   __bool__zModularInteger.__bool__   s    DH~~r   c                B    | j                             || j                  S r   )r   rR   r   )r8   values     r   rO   zModularInteger._invert   s    w~~eSW---r   c                \    |                      |                     | j                            S r   )r   rO   r   r   s    r   rR   zModularInteger.invert   s"    ~~dll4844555r   N)+r$   
__module____qualname____doc__r   r   r0   r   	__slots__r   r   r   r    r%   r'   r*   r1   r4   r6   classmethodr:   r?   rD   rG   rI   rK   rM   rP   rS   rU   rW   r\   r`   rd   rh   rl   ro   rs   rv   ry   r|   rO   rR   r3   r   r   r   r      s4       223Cc7I  8 8 8  * * *> > >2 2 2    &  ) ) )   [" " "# # #" " "& & &" " "# # #" " ", , ," " "" " "	< 	< 	<, , ,, , ,$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$   r   r   r   r   r0   r   )_dom_mod_symr   s   r   r8   r      s#         $MCcGGGr   r8   zSymmetricModularIntegerMod%szModularIntegerMod%s)r   r   
ValueErrorr   KeyErrorr   r$   )r   r   r   r   okkeyr8   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$)r   
__future__r   typingr   rf   sympy.polys.polyutilsr   sympy.polys.polyerrorsr   !sympy.polys.domains.domainelementr   sympy.utilitiesr   sympy.utilities.exceptionsr	   r   r   __annotations__r   r3   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   