o
    jg                     @  s   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 deeZi Zded< dd ZdS )z1Implementation of :class:`ModularInteger` class.     )annotations)AnyN)PicklableWithSlots)CoercionFailed)DomainElement)public)sympy_deprecation_warningc                   @  s0  e Zd ZdZd\ZZZZdZdd Z	dd Z
dd	 Zd
d Zdd Zdd Zdd Zdd Zdd Zdd Zedd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Z d2d3 Z!d4d5 Z"d6d7 Z#d8d9 Z$d:d; Z%d<d= Z&d>d? Z'd@dA Z(edBdC Z)dDdE Z*dFS )GModularIntegerz(A class representing a modular integer. )NNNN)valc                 C     | j S N)_parentself r   Z/var/www/html/zoom/venv/lib/python3.10/site-packages/sympy/polys/domains/modularinteger.pyparent      zModularInteger.parentc                 C  s6   t || jr|j| j | _d S | j|| j | _d S r   )
isinstance	__class__r
   moddomconvert)r   r
   r   r   r   __init__   s   zModularInteger.__init__c                 C  r   r   )r   r   r   r   r   modulus    r   zModularInteger.modulusc                 C  s   t | j| jfS r   )hashr
   r   r   r   r   r   __hash__#      zModularInteger.__hash__c                 C  s   d| j j| jf S )Nz%s(%s))r   __name__r
   r   r   r   r   __repr__&      zModularInteger.__repr__c                 C  s   d| j | jf S )Nz	%s mod %s)r
   r   r   r   r   r   __str__)   r   zModularInteger.__str__c                 C  
   t | jS r   )intr
   r   r   r   r   __int__,      
zModularInteger.__int__c                 C  s<   t dddd | jr| j| jd kr| jS | j| j 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   r   r   r   to_int/   s   	zModularInteger.to_intc                 C  s   | S r   r   r   r   r   r   __pos__B   s   zModularInteger.__pos__c                 C  s   |  | j S r   )r   r
   r   r   r   r   __neg__E      zModularInteger.__neg__c                 C  s4   t || r|jS z| j|W S  ty   Y d S w r   )r   r
   r   r   r   )clsotherr   r   r   _get_valH   s   
zModularInteger._get_valc                 C  s&   |  |}|d ur| | j| S tS r   r1   r   r
   NotImplementedr   r0   r
   r   r   r   __add__R      
zModularInteger.__add__c                 C  
   |  |S r   r5   r   r0   r   r   r   __radd__Z   r%   zModularInteger.__radd__c                 C  s&   |  |}|d ur| | j| S tS r   r2   r4   r   r   r   __sub__]   r6   zModularInteger.__sub__c                 C  s   |   |S r   r8   r9   r   r   r   __rsub__e   s   zModularInteger.__rsub__c                 C  s&   |  |}|d ur| | j| S tS r   r2   r4   r   r   r   __mul__h   r6   zModularInteger.__mul__c                 C  r7   r   )r=   r9   r   r   r   __rmul__p   r%   zModularInteger.__rmul__c                 C  s,   |  |}|d ur| | j| | S tS r   )r1   r   r
   _invertr3   r4   r   r   r   __truediv__s   s   
zModularInteger.__truediv__c                 C  s   |   |S r   )invertr=   r9   r   r   r   __rtruediv__{   r.   zModularInteger.__rtruediv__c                 C  s&   |  |}|d ur| | j| S tS r   r2   r4   r   r   r   __mod__~   r6   zModularInteger.__mod__c                 C  s&   |  |}|d ur| || j S tS r   r2   r4   r   r   r   __rmod__   r6   zModularInteger.__rmod__c                 C  sL   |s	|  | jjS |dk r|  j| }}n| j}|  t|t|| jS )Nr   )r   r   onerA   r
   powr#   r   )r   expr
   r   r   r   __pow__   s   zModularInteger.__pow__c                 C  s(   |  |}|d u rtS || j|| j S r   )r1   r3   r
   r   r   r0   opr
   r   r   r   _compare   s   
zModularInteger._comparec                 C  s8   |  |}|d u rtS tddddd || j|| j 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)r1   r3   r   r
   r   rI   r   r   r   _compare_deprecated   s   

z"ModularInteger._compare_deprecatedc                 C     |  |tjS r   )rK   operatoreqr9   r   r   r   __eq__   r.   zModularInteger.__eq__c                 C  rO   r   )rK   rP   ner9   r   r   r   __ne__   r.   zModularInteger.__ne__c                 C  rO   r   )rN   rP   ltr9   r   r   r   __lt__   r.   zModularInteger.__lt__c                 C  rO   r   )rN   rP   ler9   r   r   r   __le__   r.   zModularInteger.__le__c                 C  rO   r   )rN   rP   gtr9   r   r   r   __gt__   r.   zModularInteger.__gt__c                 C  rO   r   )rN   rP   ger9   r   r   r   __ge__   r.   zModularInteger.__ge__c                 C  r"   r   )boolr
   r   r   r   r   __bool__   r%   zModularInteger.__bool__c                 C  s   | j || jS r   )r   rA   r   )r/   valuer   r   r   r?      s   zModularInteger._invertc                 C  s   |  | | jS r   )r   r?   r
   r   r   r   r   rA      r    zModularInteger.invertN)+r   
__module____qualname____doc__r   r   r*   r   	__slots__r   r   r   r   r   r!   r$   r+   r,   r-   classmethodr1   r5   r:   r;   r<   r=   r>   r@   rB   rC   rD   rH   rK   rN   rR   rT   rV   rX   rZ   r\   r^   r?   rA   r   r   r   r   r	      sN    
	
r	   z0dict[tuple[Any, Any, Any], type[ModularInteger]]_modular_integer_cachec                   s   z  W n ty   d}Y nw d}|rdk r!td  f}zt| }W |S  tyU   G  fdddt}rId |_nd |_|t|< Y |S w )	z1Create custom class for specific integer modulus.FT   z*modulus must be a positive integer, got %sc                      s    e Zd Z ZZZZdS )z"ModularIntegerFactory.<locals>.clsN)r   r`   ra   r   r   r*   r   r   _dom_mod_symr   r   r   r/      s    r/   zSymmetricModularIntegerMod%szModularIntegerMod%s)r   r   
ValueErrorre   KeyErrorr	   r   )ri   rh   rj   r   okkeyr/   r   rg   r   ModularIntegerFactory   s(   



ro   )rb   
__future__r   typingr   rP   sympy.polys.polyutilsr   sympy.polys.polyerrorsr   !sympy.polys.domains.domainelementr   sympy.utilitiesr   sympy.utilities.exceptionsr   r	   re   __annotations__ro   r   r   r   r   <module>   s     @