U
    ZÊ¹jš  ã                   @  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  s   | j S ©N)Ú_parent©Úself© r   úa/var/www/html/bwave/python/venv/lib/python3.8/site-packages/sympy/polys/domains/modularinteger.pyÚparent   s    zModularInteger.parentc                 C  s4   t || jƒr|j| j | _n| j |¡| j | _d S r   )Ú
isinstanceÚ	__class__r
   ÚmodÚdomÚconvert)r   r
   r   r   r   Ú__init__   s    zModularInteger.__init__c                 C  s   | j S r   )r   r   r   r   r   Úmodulus    s    zModularInteger.modulusc                 C  s   t | j| jfƒS r   )Úhashr
   r   r   r   r   r   Ú__hash__#   s    zModularInteger.__hash__c                 C  s   d| j j| jf S )Nz%s(%s))r   Ú__name__r
   r   r   r   r   Ú__repr__&   s    zModularInteger.__repr__c                 C  s   d| j | jf S )Nz	%s mod %s)r
   r   r   r   r   r   Ú__str__)   s    zModularInteger.__str__c                 C  s
   t | jƒS r   )Úintr
   r   r   r   r   Ú__int__,   s    zModularInteger.__int__c                 C  sB   t dddd� | jr8| j| jd kr*| jS | j| j S n| jS d 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   s    zModularInteger.__neg__c                 C  s:   t || ƒr|jS z| j |¡W S  tk
r4   Y d S X d S r   )r   r
   r   r   r   )ÚclsÚotherr   r   r   Ú_get_valH   s    
zModularInteger._get_valc                 C  s*   |   |¡}|d k	r"|  | j| ¡S tS d S r   ©r*   r   r
   ÚNotImplemented©r   r)   r
   r   r   r   Ú__add__R   s    
zModularInteger.__add__c                 C  s
   |   |¡S r   ©r.   ©r   r)   r   r   r   Ú__radd__Z   s    zModularInteger.__radd__c                 C  s*   |   |¡}|d k	r"|  | j| ¡S tS d S r   r+   r-   r   r   r   Ú__sub__]   s    
zModularInteger.__sub__c                 C  s   |    |¡S r   r/   r0   r   r   r   Ú__rsub__e   s    zModularInteger.__rsub__c                 C  s*   |   |¡}|d k	r"|  | j| ¡S tS d S r   r+   r-   r   r   r   Ú__mul__h   s    
zModularInteger.__mul__c                 C  s
   |   |¡S r   )r4   r0   r   r   r   Ú__rmul__p   s    zModularInteger.__rmul__c                 C  s0   |   |¡}|d k	r(|  | j|  |¡ ¡S tS d S r   )r*   r   r
   Ú_invertr,   r-   r   r   r   Ú__truediv__s   s    
zModularInteger.__truediv__c                 C  s   |   ¡  |¡S r   )Úinvertr4   r0   r   r   r   Ú__rtruediv__{   s    zModularInteger.__rtruediv__c                 C  s*   |   |¡}|d k	r"|  | j| ¡S tS d S r   r+   r-   r   r   r   Ú__mod__~   s    
zModularInteger.__mod__c                 C  s*   |   |¡}|d k	r"|  || j ¡S tS d S r   r+   r-   r   r   r   Ú__rmod__†   s    
zModularInteger.__rmod__c                 C  sL   |s|   | jj¡S |dk r.|  ¡ j|  }}n| j}|   t|t|ƒ| jƒ¡S )Nr   )r   r   Úoner8   r
   Úpowr   r   )r   Úexpr
   r   r   r   Ú__pow__Ž   s    zModularInteger.__pow__c                 C  s(   |   |¡}|d krtS || j|| j ƒS r   )r*   r,   r
   r   ©r   r)   Úopr
   r   r   r   Ú_compare™   s    
zModularInteger._comparec                 C  s8   |   |¡}|d k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)r*   r,   r   r
   r   r@   r   r   r   Ú_compare_deprecated¡   s    
ù
z"ModularInteger._compare_deprecatedc                 C  s   |   |tj¡S r   )rB   ÚoperatorÚeqr0   r   r   r   Ú__eq__³   s    zModularInteger.__eq__c                 C  s   |   |tj¡S r   )rB   rF   Úner0   r   r   r   Ú__ne__¶   s    zModularInteger.__ne__c                 C  s   |   |tj¡S r   )rE   rF   Últr0   r   r   r   Ú__lt__¹   s    zModularInteger.__lt__c                 C  s   |   |tj¡S r   )rE   rF   Úler0   r   r   r   Ú__le__¼   s    zModularInteger.__le__c                 C  s   |   |tj¡S r   )rE   rF   Úgtr0   r   r   r   Ú__gt__¿   s    zModularInteger.__gt__c                 C  s   |   |tj¡S r   )rE   rF   Úger0   r   r   r   Ú__ge__Â   s    zModularInteger.__ge__c                 C  s
   t | jƒS r   )Úboolr
   r   r   r   r   Ú__bool__Å   s    zModularInteger.__bool__c                 C  s   | j  || j¡S r   )r   r8   r   )r(   Úvaluer   r   r   r6   È   s    zModularInteger._invertc                 C  s   |   |  | j¡¡S r   )r   r6   r
   r   r   r   r   r8   Ì   s    zModularInteger.invertN)+r   Ú
__module__Ú__qualname__Ú__doc__r   r   r$   r   Ú	__slots__r   r   r   r   r   r   r   r%   r&   r'   Úclassmethodr*   r.   r1   r2   r3   r4   r5   r7   r9   r:   r;   r?   rB   rE   rH   rJ   rL   rN   rP   rR   rT   r6   r8   r   r   r   r   r	      sL   
	
r	   z0dict[tuple[Any, Any, Any], type[ModularInteger]]Ú_modular_integer_cachec                   s°   zˆ   ˆ¡‰W n tk
r&   d}Y nX d}|r8ˆdk rDtdˆ ƒ‚ˆˆ ˆf}zt| }W nP tk
rª   G ‡ ‡‡‡fdd„dtƒ}ˆr”dˆ |_n
dˆ |_|t|< Y nX |S )	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   rV   rW   r   r   r$   r   r   ©Ú_domÚ_modÚ_symr   r   r   r(   â   s   r(   zSymmetricModularIntegerMod%szModularIntegerMod%s)r   r   Ú
ValueErrorr[   ÚKeyErrorr	   r   )r_   r^   r`   r   ÚokÚkeyr(   r   r]   r   ÚModularIntegerFactoryÑ   s"    


re   )rX   Ú
__future__r   Útypingr   rF   Zsympy.polys.polyutilsr   Zsympy.polys.polyerrorsr   Z!sympy.polys.domains.domainelementr   Zsympy.utilitiesr   Zsympy.utilities.exceptionsr   r	   r[   Ú__annotations__re   r   r   r   r   Ú<module>   s    @