Ë
    täiš  ã                  óœ   — 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    úq/Volumes/fast/ai/experiments/MLX_z-image/.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   € Ü�c˜4Ÿ>™>Ô*Ø—w‘w §¡Ñ)ˆD�Hà—x‘x×'Ñ'¨Ó,¨t¯x©xÑ7ˆD�Hr   c                ó   — | j                   S r   )r   r   s    r   ÚmoduluszModularInteger.modulus    s   € Ø�x‰xˆr   c                óD   — t        | j                  | j                  f«      S r   )Úhashr   r   r   s    r   Ú__hash__zModularInteger.__hash__#   s   € Ü�T—X‘X˜tŸx™xÐ(Ó)Ð)r   c                óN   — | j                   j                  ›d| j                  ›d�S )NÚ(Ú))r   Ú__name__r   r   s    r   Ú__repr__zModularInteger.__repr__&   s   € ØŸ>™>×2Ó2°D·H³HÐ=Ð=r   c                ó8   — | j                   ›d| j                  ›�S )Nz mod )r   r   r   s    r   Ú__str__zModularInteger.__str__)   s   € Ø"Ÿh›h¨¯ªÐ1Ð1r   c                ó,   — t        | j                  «      S r   )Úintr   r   s    r   Ú__int__zModularInteger.__int__,   s   € Ü�4—8‘8‹}Ð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   € ä!ðð &,Ø'>õ	
ð �8Š8Ø�x‰x˜4Ÿ8™8 q™=Ò(Ø—x‘x�à—x‘x $§(¡(Ñ*Ð*à—8‘8ˆOr   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   € Ø�~‰~˜tŸx™x˜iÓ(Ð(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@   € ä�e˜SÔ!Ø—9‘9ÐðØ—w‘w—‘ 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   € Ø�m‰m˜EÓ"ˆàˆ?Ø—>‘> $§(¡(¨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<   € Ø�m‰m˜EÓ"ˆàˆ?Ø—>‘> $§(¡(¨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   € Ø�m‰m˜EÓ"ˆàˆ?Ø—>‘> #¨¯©¡.Ó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 #¤s¨3£x°·±Ó:Ó;Ð;r   c                ót   — | j                  |«      }|€t        S  || j                  || j                  z  «      S r   )r:   r=   r   r   ©r   r9   Úopr   s       r   Ú_comparezModularInteger._compare™   s4   € Ø�m‰m˜EÓ"ˆàˆ;Ü!Ð!á�$—(‘(˜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   € Ø�m‰m˜EÓ"ˆàˆ;Ü!Ð!ä!ðð &,Ø'?Øõ	
ñ �$—(‘(˜C $§(¡(™NÓ+Ð+r   c                óB   — | j                  |t        j                  «      S r   )r`   ÚoperatorÚeqrC   s     r   Ú__eq__zModularInteger.__eq__³   ó   € Ø�}‰}˜U¤H§K¡KÓ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   € Ü�D—H‘H‹~Ðr   c                óN   — | j                   j                  || j                  «      S r   )r   rR   r   )r8   Úvalues     r   rO   zModularInteger._invertÈ   s   € à�w‰w�~‰~˜e S§W¡WÓ-Ð-r   c                óV   — | j                  | j                  | j                  «      «      S r   )r   rO   r   r   s    r   rR   zModularInteger.invertÌ   s   € Ø�~‰~˜dŸl™l¨4¯8©8Ó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ˆˆc�7à€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   ø„ Ù ¡$©ˆMˆC��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Ñ)ˆð €Jøô1 ò ØŠðûô ò 
*÷	ñ 	”.ô 	ñ Ø9¸DÑ@ˆC�Là0°4Ñ7ˆCŒLà&)Ô˜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   