+
    -åûjž)  ã                   ó€  € R t ^ RIt^ RIHt ^ RIHt ^ RIHt ^ RIH	t	 ^ RI
Ht ^ RIHt ^ RIHtHt ^ R	IHt ^ R
IHt ^ RIHt ]R8X  d   R.t]R8X  d;   ^ RIt]P2                  P5                  R4      vttt]! ]4      ]! ]4      3R8  d   RtMRtR tR t R t!]]! RR.R7       ! R R]	]4      4       4       t"]";t#t$R# )z.Implementation of :class:`FiniteField` class. N)ÚGROUND_TYPES)Údoctest_depends_on)Ú
int_valued)ÚField)ÚModularIntegerFactory)ÚSimpleDomain)Úgf_zassenhausÚgf_irred_p_rabin)ÚCoercionFailed)Úpublic)ÚSymPyIntegerÚflintÚFiniteFieldÚ.c                 óØ   a aaa€ \         P                  oS! S 4      o \        P                  o\        P                  o S! ^ S 4       TT T3R lpT T3R lpY3#   \
         d    Ru # i ; i)é    c                 óX   <€  S! V S4      #   \          d    S! S! T 4      S4      u # i ; i©N©Ú	TypeError)ÚxÚindexÚmodÚnmods   &€€€Ú[C:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\sympy\polys\domains\finitefield.pyÚctxÚ&_modular_int_factory_nmod.<locals>.ctx/   s4   ø€ ð	'Ù˜˜3“<ÐøÜô 	'Ù™˜a› #Ó&Ò&ð	'ús   ƒ Œ)¨)c                 ó   <€ S! V S4      # r   © )Úcsr   Ú	nmod_polys   &€€r   Úpoly_ctxÚ+_modular_int_factory_nmod.<locals>.poly_ctx5   s   ø€ Ù˜˜SÓ!Ð!ó    )NN)Úoperatorr   r   r   r    ÚOverflowError)r   r   r!   r   r   r    s   f  @@@r   Ú_modular_int_factory_nmodr&   "   s`   û€ ä�N‰N€EÙ
�‹*€CÜ�:‰:€DÜ—‘€IðÙˆQ�Œ÷'ö"ð ˆ=Ðøô ô ØÒðús   ¾	A ÁA)Á(A)c                 óÄ   aaaa€ \         P                  o\        P                  ! V 4      o\        P                  ! V 4      o\        P
                  oVV3R  lpVV3R lpW3# )c                 óT   <€  S! V 4      #   \          d    S! S! T 4      4      u # i ; ir   r   )r   Úfctxr   s   &€€r   r   Ú*_modular_int_factory_fmpz_mod.<locals>.ctxA   s.   ø€ ð	"Ù˜“7ˆNøÜô 	"á™˜a›“>Ò!ð	"ús   ƒ ‹'¦'c                 ó   <€ S! V S4      # r   r   )r   Ú	fctx_polyÚfmpz_mod_polys   &€€r   r!   Ú/_modular_int_factory_fmpz_mod.<locals>.poly_ctxH   s   ø€ Ù˜R Ó+Ð+r#   )r$   r   r   Úfmpz_mod_ctxÚfmpz_mod_poly_ctxr-   )r   r   r!   r)   r,   r-   r   s   &  @@@@r   Ú_modular_int_factory_fmpz_modr1   ;   sK   û€ Ü�N‰N€EÜ×Ò˜cÓ"€DÜ×'Ò'¨Ó,€IÜ×'Ñ'€Mö"ö,ð ˆ=Ðr#   c                 ó  €  VP                  V 4      p RRRrep\        e7   T P	                  4       '       d!   Rp\        T 4      w  rETf   \        T 4      w  rETf   \        YY#4      pRpYET3#   \         d    \        R T ,          4      hi ; i)z"modulus must be an integer, got %sNFT)Úconvertr
   Ú
ValueErrorr   Úis_primer&   r1   r   )r   ÚdomÚ	symmetricÚselfr   r!   Úis_flints   &&&&   r   Ú_modular_int_factoryr:   N   s    € ðEØ�k‰k˜#Óˆð # D¨%�8€Cô Ò˜SŸ\™\Ÿ^š^àˆô 2°#Ó6‰ˆàŠ;ä9¸#Ó>‰MˆCà
‚{ô $ C¨iÓ>ˆØˆà˜(Ð"Ð"øô/ ô EÜÐ=ÀÕCÓDÐDðEús   ‚A, Á,B
ÚpythonÚgmpy)Úmodulesc                   ó&  a € ] tR t^lt o RtRtRtR;ttRt	Rt
RtRtRtR"R lt]R 4       t]R 4       tR	 tR
 tR tR tR tR tR tR tR tR tR tR tR#R ltR#R ltR#R lt R#R lt!R#R lt"R#R lt#R#R lt$R#R lt%R#R lt&R t'R t(R  t)R!t*V t+R# )$r   aÿ  Finite field of prime order :ref:`GF(p)`

A :ref:`GF(p)` domain represents a `finite field`_ `\mathbb{F}_p` of prime
order as :py:class:`~.Domain` in the domain system (see
:ref:`polys-domainsintro`).

A :py:class:`~.Poly` created from an expression with integer
coefficients will have the domain :ref:`ZZ`. However, if the ``modulus=p``
option is given then the domain will be a finite field instead.

>>> from sympy import Poly, Symbol
>>> x = Symbol('x')
>>> p = Poly(x**2 + 1)
>>> p
Poly(x**2 + 1, x, domain='ZZ')
>>> p.domain
ZZ
>>> p2 = Poly(x**2 + 1, modulus=2)
>>> p2
Poly(x**2 + 1, x, modulus=2)
>>> p2.domain
GF(2)

It is possible to factorise a polynomial over :ref:`GF(p)` using the
modulus argument to :py:func:`~.factor` or by specifying the domain
explicitly. The domain can also be given as a string.

>>> from sympy import factor, GF
>>> factor(x**2 + 1)
x**2 + 1
>>> factor(x**2 + 1, modulus=2)
(x + 1)**2
>>> factor(x**2 + 1, domain=GF(2))
(x + 1)**2
>>> factor(x**2 + 1, domain='GF(2)')
(x + 1)**2

It is also possible to use :ref:`GF(p)` with the :py:func:`~.cancel`
and :py:func:`~.gcd` functions.

>>> from sympy import cancel, gcd
>>> cancel((x**2 + 1)/(x + 1))
(x**2 + 1)/(x + 1)
>>> cancel((x**2 + 1)/(x + 1), domain=GF(2))
x + 1
>>> gcd(x**2 + 1, x + 1)
1
>>> gcd(x**2 + 1, x + 1, domain=GF(2))
x + 1

When using the domain directly :ref:`GF(p)` can be used as a constructor
to create instances which then support the operations ``+,-,*,**,/``

>>> from sympy import GF
>>> K = GF(5)
>>> K
GF(5)
>>> x = K(3)
>>> y = K(2)
>>> x
3 mod 5
>>> y
2 mod 5
>>> x * y
1 mod 5
>>> x / y
4 mod 5

Notes
=====

It is also possible to create a :ref:`GF(p)` domain of **non-prime**
order but the resulting ring is **not** a field: it is just the ring of
the integers modulo ``n``.

>>> K = GF(9)
>>> z = K(3)
>>> z
3 mod 9
>>> z**2
0 mod 9

It would be good to have a proper implementation of prime power fields
(``GF(p**n)``) but these are not yet implemented in SymPY.

.. _finite field: https://en.wikipedia.org/wiki/Finite_field
ÚFFTFNc                ó:  € ^ RI Hp TpV^ 8:  d   \        RV,          4      h\        WW 4      w  rVpWPn        W`n        Wpn        V P	                  ^ 4      V n        V P	                  ^4      V n        W@n	        Wn
        W n        \        V P                  4      V n        R# )r   )ÚZZz*modulus must be a positive integer, got %sN)Úsympy.polys.domainsrA   r4   r:   ÚdtypeÚ	_poly_ctxÚ	_is_flintÚzeroÚoner6   r   ÚsymÚtypeÚ_tp)r8   r   r7   rA   r6   r   r!   r9   s   &&&     r   Ú__init__ÚFiniteField.__init__Ó   s~   € Ý*Øˆà�!Œ8ÜÐIÈCÕOÓPÐPä"6°sÀÓ"QÑˆ�xàŒ
Ø!ŒØ!Œà—J‘J˜q“MˆŒ	Ø—:‘:˜a“=ˆŒØŒØŒØŒÜ˜Ÿ	™	“?ˆŽr#   c                ó   € V P                   # r   )rJ   ©r8   s   &r   ÚtpÚFiniteField.tpç   ó   € à�x‰xˆr#   c                óf   € \        V R R4      pVf    ^ RIHp V! V P                  4      ;V n        pV# )Ú	_is_fieldN)Úisprime)ÚgetattrÚsympy.ntheory.primetestrT   r   rS   )r8   Úis_fieldrT   s   &  r   Úis_FieldÚFiniteField.is_Fieldë   s3   € ä˜4 ¨dÓ3ˆØÒÝ7Ù(/°·±Ó(9Ð9ˆDŒN˜XØˆr#   c                ó(   € R V P                   ,          # )zGF(%s)©r   rN   s   &r   Ú__str__ÚFiniteField.__str__ó   s   € Ø˜$Ÿ(™(Õ"Ð"r#   c                ó„   € \        V P                  P                  V P                  V P                  V P
                  34      # r   )ÚhashÚ	__class__Ú__name__rC   r   r6   rN   s   &r   Ú__hash__ÚFiniteField.__hash__ö   s,   € Ü�T—^‘^×,Ñ,¨d¯j©j¸$¿(¹(ÀDÇHÁHÐMÓNÐNr#   c                ó¦   € \        V\        4      ;'       d;    V P                  VP                  8H  ;'       d    V P                  VP                  8H  # )z0Returns ``True`` if two domains are equivalent. )Ú
isinstancer   r   r6   )r8   Úothers   &&r   Ú__eq__ÚFiniteField.__eq__ù   sE   € ä˜%¤Ó-÷ <ð <Ø�H‰H˜Ÿ	™	Ñ!÷<ð <Ø&*§h¡h°%·)±)Ñ&;ð	<r#   c                ó   € V P                   # )z*Return the characteristic of this domain. r[   rN   s   &r   ÚcharacteristicÚFiniteField.characteristicþ   rQ   r#   c                ó   € V # )z*Returns a field associated with ``self``. r   rN   s   &r   Ú	get_fieldÚFiniteField.get_field  s   € àˆr#   c                ó6   € \        V P                  V4      4      # )z!Convert ``a`` to a SymPy object. )r   Úto_int©r8   Úas   &&r   Úto_sympyÚFiniteField.to_sympy  s   € ä˜DŸK™K¨›NÓ+Ð+r#   c                ó8  € VP                   '       d4   V P                  V P                  P                  \        V4      4      4      # \	        V4      '       d4   V P                  V P                  P                  \        V4      4      4      # \        RV,          4      h)z0Convert SymPy's Integer to SymPy's ``Integer``. zexpected an integer, got %s)Ú
is_IntegerrC   r6   Úintr   r
   rq   s   &&r   Ú
from_sympyÚFiniteField.from_sympy
  se   € à�<�<ˆ<Ø—:‘:˜dŸh™hŸn™n¬S°«VÓ4Ó5Ð5Ü˜�]Š]Ø—:‘:˜dŸh™hŸn™n¬S°«VÓ4Ó5Ð5ä Ð!>ÀÕ!BÓCÐCr#   c                ó’   € \        V4      pV P                  '       d*   W P                  ^,          8”  d   W P                  ,          pV# )z,Convert ``val`` to a Python ``int`` object. )rw   rH   r   )r8   rr   Úavals   && r   rp   ÚFiniteField.to_int  s2   € ä�1‹vˆØ�8�8ˆ8˜Ÿx™x¨1�}Ô,Ø—H‘HÕˆDØˆr#   c                ó   € \        V4      # )z#Returns True if ``a`` is positive. )Úboolrq   s   &&r   Úis_positiveÚFiniteField.is_positive  s   € ä�A‹wˆr#   c                ó   € R# )z'Returns True if ``a`` is non-negative. Tr   rq   s   &&r   Úis_nonnegativeÚFiniteField.is_nonnegative  s   € ár#   c                ó   € R# )z#Returns True if ``a`` is negative. Fr   rq   s   &&r   Úis_negativeÚFiniteField.is_negative"  s   € ár#   c                ó   € V'       * # )z'Returns True if ``a`` is non-positive. r   rq   s   &&r   Úis_nonpositiveÚFiniteField.is_nonpositive&  s	   € àŒuˆr#   c                ó~   € V P                  V P                  P                  \        V4      VP                  4      4      # ©z.Convert ``ModularInteger(int)`` to ``dtype``. )rC   r6   Úfrom_ZZrw   ©ÚK1rr   ÚK0s   &&&r   Úfrom_FFÚFiniteField.from_FF*  s(   € à�x‰x˜Ÿ™Ÿ™¤s¨1£v¨r¯v©vÓ6Ó7Ð7r#   c                ó~   € V P                  V P                  P                  \        V4      VP                  4      4      # r‹   )rC   r6   Úfrom_ZZ_pythonrw   r�   s   &&&r   Úfrom_FF_pythonÚFiniteField.from_FF_python.  s*   € à�x‰x˜Ÿ™×-Ñ-¬c°!«f°b·f±fÓ=Ó>Ð>r#   c                óV   € V P                  V P                  P                  W4      4      # ©z'Convert Python's ``int`` to ``dtype``. ©rC   r6   r“   r�   s   &&&r   rŒ   ÚFiniteField.from_ZZ2  ó    € à�x‰x˜Ÿ™×-Ñ-¨aÓ4Ó5Ð5r#   c                óV   € V P                  V P                  P                  W4      4      # r—   r˜   r�   s   &&&r   r“   ÚFiniteField.from_ZZ_python6  rš   r#   c                ó^   € VP                   ^8X  d   V P                  VP                  4      # R# ©z,Convert Python's ``Fraction`` to ``dtype``. N©Údenominatorr“   Ú	numeratorr�   s   &&&r   Úfrom_QQÚFiniteField.from_QQ:  ó(   € à�=‰=˜AÔØ×$Ñ$ Q§[¡[Ó1Ð1ñ r#   c                ó^   € VP                   ^8X  d   V P                  VP                  4      # R# rž   rŸ   r�   s   &&&r   Úfrom_QQ_pythonÚFiniteField.from_QQ_python?  r¤   r#   c                ó€   € V P                  V P                  P                  VP                  VP                  4      4      # )z.Convert ``ModularInteger(mpz)`` to ``dtype``. )rC   r6   Úfrom_ZZ_gmpyÚvalr�   s   &&&r   Úfrom_FF_gmpyÚFiniteField.from_FF_gmpyD  s*   € à�x‰x˜Ÿ™×+Ñ+¨A¯E©E°2·6±6Ó:Ó;Ð;r#   c                óV   € V P                  V P                  P                  W4      4      # )z%Convert GMPY's ``mpz`` to ``dtype``. )rC   r6   r©   r�   s   &&&r   r©   ÚFiniteField.from_ZZ_gmpyH  s    € à�x‰x˜Ÿ™×+Ñ+¨AÓ2Ó3Ð3r#   c                ó^   € VP                   ^8X  d   V P                  VP                  4      # R# )z%Convert GMPY's ``mpq`` to ``dtype``. N)r    r©   r¡   r�   s   &&&r   Úfrom_QQ_gmpyÚFiniteField.from_QQ_gmpyL  s&   € à�=‰=˜AÔØ—?‘? 1§;¡;Ó/Ð/ñ r#   c                óŽ   € VP                  V4      w  r4V^8X  d+   V P                  V P                  P                  V4      4      # R# )z'Convert mpmath's ``mpf`` to ``dtype``. N)Úto_rationalrC   r6   )rŽ   rr   r�   ÚpÚqs   &&&  r   Úfrom_RealFieldÚFiniteField.from_RealFieldQ  s9   € à�~‰~˜aÓ ‰ˆà�Œ6Ø—8‘8˜BŸF™FŸL™L¨›OÓ,Ð,ñ r#   c                óº   € V P                   V P                  V) 3 Uu. uF  p\        V4      NK  	  pp\        W0P                  V P
                  4      '       * # u upi )z7Returns True if ``a`` is a quadratic residue modulo p. )rG   rF   rw   r	   r   r6   )r8   rr   r   Úpolys   &&  r   Ú	is_squareÚFiniteField.is_squareX  sL   € ð "&§¡¨4¯9©9°q°bÑ 9Ó:Ñ 9˜1”�A–Ñ 9ˆÐ:Ü# D¯(©(°D·H±HÓ=Ô=Ð=ùò ;s   �Ac                óŒ  € V P                   ^8X  g   V^ 8X  d   V# V P                  V P                  V) 3 Uu. uF  p\        V4      NK  	  pp\	        W0P                   V P
                  4       FN  p\        V4      ^8X  g   K  V^,          V P                   ^,          8:  g   K6  V P                  V^,          4      u # 	  R# u upi )z—Square root modulo p of ``a`` if it is a quadratic residue.

Explanation
===========
Always returns the square root that is no larger than ``p // 2``.
N)r   rG   rF   rw   r   r6   ÚlenrC   )r8   rr   r   r¹   Úfactors   &&   r   ÚexsqrtÚFiniteField.exsqrt^  sš   € ð �8‰8�qŒ=˜A œFØˆHà!%§¡¨4¯9©9°q°bÑ 9Ó:Ñ 9˜1”�A–Ñ 9ˆÐ:Ü# D¯(©(°D·H±HÖ=ˆFÜ�6‹{˜aÖ F¨1¥I°·±¸QµÖ$>Ø—z‘z &¨¥)Ó,Ò,ñ >ñ ùò	 ;s   ·C)
rS   rE   rD   rJ   r6   rC   r   rG   rH   rF   )Tr   ),ra   Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__ÚrepÚaliasÚis_FiniteFieldÚis_FFÚis_NumericalÚhas_assoc_RingÚhas_assoc_Fieldr6   r   rK   ÚpropertyrO   rX   r\   rb   rg   rj   rm   rs   rx   rp   r   r‚   r…   rˆ   r�   r”   rŒ   r“   r¢   r¦   r«   r©   r°   r¶   rº   r¿   Ú__static_attributes__Ú__classdictcell__)Ú__classdict__s   @r   r   r   l   sç   ø‡ € ñVðp €CØ€Eà!Ð!€N�UØ€Là€NØ€Oà
€CØ
€Cô#ð( ñó ðð ñó ðò#òOò<ò
òò,òDòòòòòô8ô?ô6ô6ô2ô
2ô
<ô4ô0ò
-ò>÷ð r#   )r   é   )%rÄ   r$   Úsympy.external.gmpyr   Úsympy.utilities.decoratorr   Úsympy.core.numbersr   Úsympy.polys.domains.fieldr   Ú"sympy.polys.domains.modularintegerr   Ú sympy.polys.domains.simpledomainr   Úsympy.polys.galoistoolsr   r	   Úsympy.polys.polyerrorsr
   Úsympy.utilitiesr   Úsympy.polys.domains.groundtypesr   Ú__doctest_skip__r   Ú__version__ÚsplitÚ_majorÚ_minorÚ_rw   r&   r1   r:   r   r?   ÚGFr   r#   r   Ú<module>râ      sÕ   ðÙ 4ã å ,Ý 8å )Ý +å DÝ 9ß CÝ 1Ý "Ý 8ð �7ÔØ%�Ðð �7ÔÛð ×*Ñ*×0Ñ0°Ó5Ð€FˆF�QÙˆF‹‘S˜“[Ð! FÔ*Øˆøà€Eòò2ò&#ð< Ù˜X vÐ.Ô/ô�%˜ó ó 0ó ððD Ð €‚Rr#   