K iUdZddlmZddlmZddlZddlmZddlm Z ddl m Z ddl m Z dd lmZe Gd d ee ZiZd ed <dZy)z1Implementation of :class:`ModularInteger` class. ) annotations)AnyN)PicklableWithSlots)CoercionFailed) DomainElement)public)sympy_deprecation_warningceZdZdZd\ZZZZdZdZ dZ dZ dZ dZ d Zd Zd Zd Zd ZedZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$dZ%d Z&d!Z'd"Z(ed#Z)d$Z*y%)&ModularIntegerz(A class representing a modular integer. )NNNN)valc|jSN)_parentselfs h/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/polys/domains/modularinteger.pyparentzModularInteger.parents ||ct||jr|j|jz|_y|jj ||jz|_yr) isinstance __class__r moddomconvert)rr s r__init__zModularInteger.__init__sC c4>> *ww)DHxx'',txx7DHrc|jSr)rrs rmoduluszModularInteger.modulus s xxrcDt|j|jfSr)hashr rrs r__hash__zModularInteger.__hash__#sTXXtxx())rcN|jjd|jdS)N())r__name__r rs r__repr__zModularInteger.__repr__&s>>22DHH==rc8|jd|jS)Nz mod )r rrs r__str__zModularInteger.__str__)s"hh11rc,t|jSr)intr rs r__int__zModularInteger.__int__,s488}rctddd|jrA|j|jdzkr |jS|j|jz S|jS)NzModularInteger.to_int() is deprecated. Use int(a) or K = GF(p) and K.to_int(a) instead of a.to_int(). 1.13zmodularinteger-to-int)deprecated_since_versionactive_deprecations_target)r symr rrs rto_intzModularInteger.to_int/sY! &,'>   88xx488q=(xxxx$((**88Orc|Srrs r__pos__zModularInteger.__pos__Bs rc:|j|j Sr)rr rs r__neg__zModularInteger.__neg__Es~~txxi((rct||r |jS |jj|S#t$rYywxYwr)rr rrr)clsothers r_get_valzModularInteger._get_valHs@ eS !99  wwu--!  s5 AAcp|j|}||j|j|zStSrr:rr NotImplementedrr9r s r__add__zModularInteger.__add__R2mmE" ?>>$((S.1 1! !rc$|j|Srr?rr9s r__radd__zModularInteger.__radd__Z||E""rcp|j|}||j|j|z StSrr<r>s r__sub__zModularInteger.__sub__]r@rc&| j|SrrBrCs r__rsub__zModularInteger.__rsub__esu%%rcp|j|}||j|j|zStSrr<r>s r__mul__zModularInteger.__mul__hr@rc$|j|Sr)rKrCs r__rmul__zModularInteger.__rmul__prErc|j|}|-|j|j|j|zStSr)r:rr _invertr=r>s r __truediv__zModularInteger.__truediv__ss<mmE" ?>>$((T\\#->">? ?! !rc@|jj|Sr)invertrKrCs r __rtruediv__zModularInteger.__rtruediv__{s{{}$$U++rcp|j|}||j|j|zStSrr<r>s r__mod__zModularInteger.__mod__~r@rcp|j|}||j||jzStSrr<r>s r__rmod__zModularInteger.__rmod__s2mmE" ?>>#.1 1! !rc |s%|j|jjS|dkr|jj| }}n |j}|jt |t ||jS)Nr)rronerRr powr)r)rexpr s r__pow__zModularInteger.__pow__sc>>$((,,/ / 7{{}((3$C((C~~c#s3x:;;rct|j|}|tS||j||jzSr)r:r=r rrr9opr s r_comparezModularInteger._compares4mmE" ;! !$((C$((N++rc|j|}|tStdddd||j||jzS)Nz~Ordered comparisons with modular integers are deprecated. Use e.g. int(a) < int(b) instead of a < b. r,zmodularinteger-compare)r-r. stacklevel)r:r=r r rr^s r_compare_deprecatedz"ModularInteger._compare_deprecatedsNmmE" ;! !! &,'? $((C$((N++rcB|j|tjSr)r`operatoreqrCs r__eq__zModularInteger.__eq__}}UHKK00rcB|j|tjSr)r`rfnerCs r__ne__zModularInteger.__ne__rircB|j|tjSr)rdrfltrCs r__lt__zModularInteger.__lt__''x{{;;rcB|j|tjSr)rdrflerCs r__le__zModularInteger.__le__rprcB|j|tjSr)rdrfgtrCs r__gt__zModularInteger.__gt__rprcB|j|tjSr)rdrfgerCs r__ge__zModularInteger.__ge__rprc,t|jSr)boolr rs r__bool__zModularInteger.__bool__sDHH~rcN|jj||jSr)rrRr)r8values rrOzModularInteger._invertsww~~eSWW--rcV|j|j|jSr)rrOr rs rrRzModularInteger.inverts~~dll488455rN)+r$ __module__ __qualname____doc__rrr0r __slots__rrrr r%r'r*r1r4r6 classmethodr:r?rDrGrIrKrMrPrSrUrWr\r`rdrhrlrorsrvryr|rOrRr3rrr r s23Cc7I8 *>2&)"#"&"#","" <,,$11<<<<..6rr z0dict[tuple[Any, Any, Any], type[ModularInteger]]_modular_integer_cachec( jd}|rdkrtdzf} t|}|S#t$rd}Y3wxYw#t$r8Gfddt }r dz|_n dz|_|t|<Y|SwxYw) z1Create custom class for specific integer modulus.TFz*modulus must be a positive integer, got %sc(eZdZWWWcZZZWZy)"ModularIntegerFactory..clsN)r$rrrrr0r)_dom_mod_symrsrr8rs $MCcGrr8zSymmetricModularIntegerMod%szModularIntegerMod%s)rr ValueErrorrKeyErrorr r$)rrrrokkeyr8s```` rModularIntegerFactoryrs||D! ELMM d C *$S) J1    *  .  9D@CL047CL&)s# J *s ? A A  A =BB)r __future__rtypingrrfsympy.polys.polyutilsrsympy.polys.polyerrorsr!sympy.polys.domains.domainelementrsympy.utilitiesrsympy.utilities.exceptionsr r r__annotations__rr3rrrsU7"41;"@}6'}6}6~LNHMr