
    sg                        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y)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*y%)&ModularIntegerz(A class representing a modular integer. )NNNN)valc                    | j                   S N)_parentselfs    U/var/www/html/venv/lib/python3.12/site-packages/sympy/polys/domains/modularinteger.pyparentzModularInteger.parent   s    ||    c                    t        || j                        r|j                  | j                  z  | _        y | j                  j                  |      | j                  z  | _        y r   )
isinstance	__class__r   moddomconvert)r   r   s     r   __init__zModularInteger.__init__   sC    c4>>*ww)DHxx'',txx7DHr   c                    | j                   S r   )r   r   s    r   moduluszModularInteger.modulus    s    xxr   c                D    t        | j                  | j                  f      S r   )hashr   r   r   s    r   __hash__zModularInteger.__hash__#   s    TXXtxx())r   c                N    | j                   j                  d| j                  dS )N())r   __name__r   r   s    r   __repr__zModularInteger.__repr__&   s    >>22DHH==r   c                8    | j                   d| j                  S )Nz mod )r   r   r   s    r   __str__zModularInteger.__str__)   s    "hh11r   c                ,    t        | j                        S r   )intr   r   s    r   __int__zModularInteger.__int__,   s    488}r   c                    t        ddd       | j                  rA| 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/   sY    ! &,'>	
 88xx488q=(xxxx$((**88Or   c                    | S r    r   s    r   __pos__zModularInteger.__pos__B   s    r   c                :    | j                  | j                         S r   )r   r   r   s    r   __neg__zModularInteger.__neg__E   s    ~~txxi((r   c                    t        ||       r|j                  S 	 | j                  j                  |      S # t        $ r Y y w xY wr   )r   r   r   r   r   )clsothers     r   _get_valzModularInteger._get_valH   s@    eS!99wwu--! s   5 	A Ac                p    | j                  |      }|| j                  | j                  |z         S t        S r   r:   r   r   NotImplementedr   r9   r   s      r   __add__zModularInteger.__add__R   2    mmE"?>>$((S.11!!r   c                $    | j                  |      S r   r?   r   r9   s     r   __radd__zModularInteger.__radd__Z       ||E""r   c                p    | j                  |      }|| j                  | j                  |z
        S t        S r   r<   r>   s      r   __sub__zModularInteger.__sub__]   r@   r   c                &    |  j                  |      S r   rB   rC   s     r   __rsub__zModularInteger.__rsub__e   s    u%%r   c                p    | j                  |      }|| j                  | j                  |z        S t        S r   r<   r>   s      r   __mul__zModularInteger.__mul__h   r@   r   c                $    | j                  |      S r   )rK   rC   s     r   __rmul__zModularInteger.__rmul__p   rE   r   c                    | j                  |      }|-| j                  | j                  | j                  |      z        S t        S r   )r:   r   r   _invertr=   r>   s      r   __truediv__zModularInteger.__truediv__s   s<    mmE"?>>$((T\\#->">??!!r   c                @    | j                         j                  |      S r   )invertrK   rC   s     r   __rtruediv__zModularInteger.__rtruediv__{   s    {{}$$U++r   c                p    | j                  |      }|| j                  | j                  |z        S t        S r   r<   r>   s      r   __mod__zModularInteger.__mod__~   r@   r   c                p    | j                  |      }|| j                  || j                  z        S t        S r   r<   r>   s      r   __rmod__zModularInteger.__rmod__   s2    mmE"?>>#.11!!r   c                   |s%| j                  | j                  j                        S |dk  r| j                         j                  | }}n| j                  }| j                  t        |t        |      | j                              S )Nr   )r   r   onerR   r   powr)   r   )r   expr   s      r   __pow__zModularInteger.__pow__   sc    >>$((,,//7{{}((3$C((C~~c#s3x:;;r   c                t    | j                  |      }|t        S  || j                  || j                  z        S r   )r:   r=   r   r   r   r9   opr   s       r   _comparezModularInteger._compare   s4    mmE";!!$((C$((N++r   c                    | j                  |      }|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   sN    mmE";!!! &,'?	
 $((C$((N++r   c                B    | j                  |t        j                        S r   )r`   operatoreqrC   s     r   __eq__zModularInteger.__eq__       }}UHKK00r   c                B    | j                  |t        j                        S r   )r`   rf   nerC   s     r   __ne__zModularInteger.__ne__   ri   r   c                B    | j                  |t        j                        S r   )rd   rf   ltrC   s     r   __lt__zModularInteger.__lt__       ''x{{;;r   c                B    | j                  |t        j                        S r   )rd   rf   lerC   s     r   __le__zModularInteger.__le__   rp   r   c                B    | j                  |t        j                        S r   )rd   rf   gtrC   s     r   __gt__zModularInteger.__gt__   rp   r   c                B    | j                  |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    DHH~r   c                N    | j                   j                  || j                        S r   )r   rR   r   )r8   values     r   rO   zModularInteger._invert   s    ww~~eSWW--r   c                V    | j                  | j                  | j                              S r   )r   rO   r   r   s    r   rR   zModularInteger.invert   s    ~~dll4884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      s    23Cc7I8*>2&)  "#"&"#",""	<,,$11<<<< . .6r   r   z0dict[tuple[Any, Any, Any], type[ModularInteger]]_modular_integer_cachec                (    	 j                          d}|r dk  rt        d z         f}	 t        |   }|S # t        $ r d}Y 3w xY w# t        $ r8  G  fddt
              }rd z  |_        n
d z  |_        |t        |<   Y |S w xY w)	z1Create custom class for specific integer modulus.TF   z*modulus must be a positive integer, got %sc                  (    e Zd ZW W  W cZZZW Zy)"ModularIntegerFactory.<locals>.clsN)r$   r   r   r   r   r0   r   )_dom_mod_symr   s   r   r8   r      s     $MCcGr   r8   zSymmetricModularIntegerMod%szModularIntegerMod%s)r   r   
ValueErrorr   KeyErrorr   r$   )r   r   r   r   okkeyr8   s   ````   r   ModularIntegerFactoryr      s    ||D! ELMM
d
C*$S) J1    
*	 	. 	 9D@CL047CL&)s#J
*s    ? 	A 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      sU    7 "   4 1 ; " @}6' }6 }6~ LN H Mr   