+
    åûjZ:  ã                   ó¾   € ^ RI HtHt ^ RIHt ^ RIHtHtHtH	t
 ^ RIHt ^ RIHt ^ RIHt  ! R R4      t ! R	 R
4      tR tR tR tR tR tR tRR ltRR ltR# )é    )ÚexpÚlog)Ú_randint)Ú	bit_scan1ÚgcdÚinvertÚsqrt)Ú_perfect_power)Úisprime)Ú_sqrt_mod_prime_powerc                   ó2   a € ] tR t^	t o R tR tR tRtV tR# )ÚSievePolynomialc                óŽ   € Wn         W n        V^,          V n        ^V,          V,          V n        V^,          V,
          V n        R# )zôThis class denotes the sieve polynomial.
Provide methods to compute `(a*x + b)**2 - N` and
`a*x + b` when given `x`.

Parameters
==========

a : parameter of the sieve polynomial
b : parameter of the sieve polynomial
N : number to be factored

N)ÚaÚbÚa2ÚabÚb2)Úselfr   r   ÚNs   &&&&ÚLC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\sympy\ntheory\qs.pyÚ__init__ÚSievePolynomial.__init__
   s7   € ð ŒØŒØ�Q•$ˆŒØ�A•#�a•%ˆŒØ�Q•$˜•(ˆŽó    c                óJ   € V P                   V,          V P                  ,           # ©N)r   r   ©r   Úxs   &&r   Úeval_uÚSievePolynomial.eval_u   s   € Ø�v‰v�a�x˜$Ÿ&™&Õ Ð r   c                óz   € V P                   V,          V P                  ,           V,          V P                  ,           # r   )r   r   r   r   s   &&r   Úeval_vÚSievePolynomial.eval_v    s'   € Ø—‘˜•	˜DŸG™GÕ# QÕ&¨¯©Õ0Ð0r   )r   r   r   r   r   N)	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r   r   r"   Ú__static_attributes__Ú__classdictcell__©Ú__classdict__s   @r   r   r   	   s   ø‡ € òò&!÷1ð 1r   r   c                   ó*   a € ] tR t^$t o RtR tRtV tR# )ÚFactorBaseElemz7This class stores an element of the `factor_base`.
    c                óT   € Wn         W n        W0n        RV n        RV n        RV n        R# )zÇ
Initialization of factor_base_elem.

Parameters
==========

prime : prime number of the factor_base
tmem_p : Integer square root of x**2 = n mod prime
log_p : Compute Natural Logarithm of the prime
N)ÚprimeÚtmem_pÚlog_pÚsoln1Úsoln2Úb_ainv)r   r/   r0   r1   s   &&&&r   r   ÚFactorBaseElem.__init__'   s*   € ð Œ
ØŒØŒ
ð ˆŒ
ØˆŒ
ØˆŽr   )r4   r1   r/   r2   r3   r0   N)r$   r%   r&   r'   Ú__doc__r   r(   r)   r*   s   @r   r-   r-   $   s   ø‡ € ñ÷ð r   r-   c                óš  € ^ RI Hp . pRRrTVP                  ^V 4       F§  p\        W^,
          ^,          V4      ^8X  g   K$  VR8”  d   Vf   \	        V4      ^,
          pVR8”  d   Vf   \	        V4      ^,
          p\        W^4      ^ ,          p\        \        V4      R,          4      pVP                  \        WgV4      4       K©  	  WEV3# )a¿  Generate `factor_base` for Quadratic Sieve. The `factor_base`
consists of all the points whose ``legendre_symbol(n, p) == 1``
and ``p < num_primes``. Along with the prime `factor_base` also stores
natural logarithm of prime and the residue n modulo p.
It also returns the of primes numbers in the `factor_base` which are
close to 1000 and 5000.

Parameters
==========

prime_bound : upper prime bound of the factor_base
n : integer to be factored
)ÚsieveNiè  iˆ  é   )
Úsympy.ntheory.generater8   Ú
primerangeÚpowÚlenr   Úroundr   Úappendr-   )	Úprime_boundÚnr8   Úfactor_baseÚidx_1000Úidx_5000r/   Úresiduer1   s	   &&       r   Ú_generate_factor_baserF   <   s¾   € õ -Ø€KØ˜tˆhØ×!Ñ! ! [Ö1ˆÜˆq˜1•9 Õ" EÓ*¨aÖ/Ø�tŒ| Ò 0Ü˜{Ó+¨aÕ/�Ø�tŒ| Ò 0Ü˜{Ó+¨aÕ/�Ü+¨A°aÓ8¸Õ;ˆGÜœ#˜e›* UÕ*Ó+ˆEØ×Ñœ~¨e¸eÓDÖEñ 2ð ˜{Ð*Ð*r   c              #  ó°  "  € \        ^V ,          4      ^,          \        V4      ,
          pT;'       g    ^ pT;'       g    \        V4      ^,
          p RRRrºp	\        ^24       F¬  p^p. p\        V4      V8  dH   ^ pV^ 8X  g   Wþ9   d   V! Wx4      pK  W/,          P                  pVV,          pVP	                  V4       KW  \        \        V4      V,
          4      pVe*   \        V^,
          4      \        V^,
          4      8  g   K¦  Tp
Tp	TpK®  	  T	pT
p. pV F~  pVV,          P                  pVV,          P                  \        VV,          V4      ,          V,          p^V,          V8”  d
   VV,
          pVP	                  VV,          V,          4       K€  	  \        V4      p\        VVV 4      pV FÑ  pVVP                  ,          ^ 8X  d
   RVn        K$  \        VVP                  4      pV Uu. uF$  p^V,          V,          VP                  ,          NK&  	  upVn        VVP                  V,
          ,          VP                  ,          Vn        VVP                  ) V,
          ,          VP                  ,          Vn        KÓ  	  Vx € \        ^^\        V4      ^,
          ,          4       EF  p\        V4      p^VV^,           ,	          ^,          ,          ^,
          pVP                  ^V,          VV,          ,          ,           pVP                   p\        VVV 4      pV F•  pVP                  f   K  VP                  VVP                  V,          ,          ,
          VP                  ,          Vn        VP                  VVP                  V,          ,          ,
          VP                  ,          Vn        K—  	  Vx € EK  	  EK}  u upi 5i)a  Generate sieve polynomials indefinitely.
Information such as `soln1` in the `factor_base` associated with
the polynomial is modified in place.

Parameters
==========

N : Number to be factored
M : sieve interval
factor_base : factor_base primes
idx_1000 : index of prime number in the factor_base near 1000
idx_5000 : index of prime number in the factor_base near to 5000
randint : A callable that takes two integers (a, b) and returns a random integer
          n such that a <= n <= b, similar to `random.randint`.
N)r   r=   Úranger/   r?   r   Úabsr0   r   Úsumr   r2   r4   r3   r   r   r   )r   ÚMrB   rC   rD   ÚrandintÚ
approx_valÚstartÚendÚbest_aÚbest_qÚ
best_ratioÚ_r   ÚqÚrand_pÚpÚratioÚBÚvalÚq_lÚgammar   ÚgÚfbÚa_invÚb_elemÚiÚvÚneg_pows   &&&&&&                        r   Ú_generate_polynomialrc   Y   s	  é € ô  �Q�q•S“˜!•œc !›fÕ$€JØ�MˆM˜€EØ
×
,Ð
,”s˜;Ó'¨!Õ+€CØ
à%)¨4°˜
ˆÜ�r–ˆAØˆAØˆAÜ�a“&˜:Ô%Ø�Ø ”k V¤[Ù$ UÓ0’FØÕ'×-Ñ-�Ø�Q•�Ø—‘˜Ö Üœ˜A› Õ+Ó,ˆEØÒ!¤S¨°­£^´c¸*Àq½.Ó6IÖ%IØ�Ø�Ø"’
ñ ð" ˆØˆØˆÛˆCØ˜cÕ"×(Ñ(ˆCØ Õ$×+Ñ+¬f°Q¸#µX¸sÓ.CÕCÀcÕIˆEØ��w˜Œ}Ø˜e��Ø�H‰H�Q˜•V˜E•\Ö"ñ ô �‹FˆÜ˜A˜q !Ó$ˆÛˆBØ�2—8‘8�|˜qÔ Ø�”ÙÜ˜1˜bŸh™hÓ'ˆEÙABÓCÁ°v˜˜6� %�¨"¯(©(×2Ð2ÁÑCˆBŒIØ˜rŸy™y¨1�}Õ-°·±Õ9ˆBŒHØ §	¡	˜z¨A�~Õ.°"·(±(Õ:ˆBŽHñ ð Šô �q˜!œc !›f Q�h�-×(ˆAÜ˜!“ˆAØ˜!  A¥�,¨!Õ+Õ,¨qÕ0ˆGØ—‘�a˜•i  !¥•nÕ$ˆAØ—‘ˆAÜ  1 aÓ(ˆAÛ!�Ø—8‘8Ò#ÙØŸH™H w¨r¯y©y¸­|Õ';Õ;¸r¿x¹xÕG�”ØŸH™H w¨r¯y©y¸­|Õ';Õ;¸r¿x¹xÕG�–ñ	 "ð
 �Gô )ùò Dùs    ‚>OÁCOÄC,OÇ7*OÈ!F5Oc                ó  € ^ .^V ,          ^,           ,          pV Fî  pVP                   f   K  \        WP                   ,           VP                  ,          ^V ,          VP                  4       F!  pW$;;,          VP                  ,          uu&   K#  	  VP                  ^8X  d   KŠ  \        WP                  ,           VP                  ,          ^V ,          VP                  4       F!  pW$;;,          VP                  ,          uu&   K#  	  Kð  	  V# )a„  Sieve Stage of the Quadratic Sieve. For every prime in the factor_base
that does not divide the coefficient `a` we add log_p over the sieve_array
such that ``-M <= soln1 + i*p <=  M`` and ``-M <= soln2 + i*p <=  M`` where `i`
is an integer. When p = 2 then log_p is only added using
``-M <= soln1 + i*p <=  M``.

Parameters
==========

M : sieve interval
factor_base : factor_base primes
)r2   rH   r/   r1   r3   )rK   rB   Úsieve_arrayÚfactorÚidxs   &&   r   Ú_gen_sieve_arrayrh   ¤   sÁ   € ð �#�q˜•s˜Q•w•-€KÛˆØ�<‰<ÒÙÜ˜!Ÿl™lÕ*¨f¯l©lÕ:¸A¸a½CÀÇÁÖNˆCØ× §¡Õ,Õñ Oà�<‰<˜1ÔÙä˜!Ÿl™lÕ*¨f¯l©lÕ:¸A¸a½CÀÇÁÖNˆCØ× §¡Õ,Õó Oñ ð Ðr   c                ób  € V ^ 8  d   V R,          p ^pM^ p\        V^4       Fˆ  w  r4WP                  ,          '       d   K  ^pWP                  ,          p WP                  ,          ^ 8X  d   V^,          pWP                  ,          p K4  V^,          '       g   Kx  V^V,          ,          pKŠ  	  W 3# )zÑCheck if `num` is smooth with respect to the given `factor_base`
and compute its factorization vector.

Parameters
==========

num : integer whose smootheness is to be checked
factor_base : factor_base primes
éÿÿÿÿ)Ú	enumerater/   )ÚnumrB   Úvecr`   r]   Úes   &&    r   Ú_check_smoothnessro   ¿   s’   € ð ˆQ„wØˆr�	ˆØ‰àˆÜ˜;¨Ö*‰ˆØ—‘�>Œ>ÙØˆØ—‘ÕˆØ—H‘H�n Ô!Ø��FˆAØ—H‘HÕŠCØˆq�5Ž5Ø�1˜•6�MŠCñ +ð ˆ8€Or   c                ó
  € \        V4      \        V 4      ^,          ,           V,
          R,          p. p\        4       p	^€VR,          P                  ,          p
\        W1) 4       EF  w  r¼WÇ8  d   K  VP	                  V4      p\        WÒ4      w  rïV^8X  d%   VP                  VP                  V4      WÞ34       KW  Wú8  g   K_  \        V4      '       g   Kr  W,          ^ 8X  d   V	P                  V4       K’  VP                  V4      pWõ9   dl   VP                  V4      w  pppVV,          \        Wð4      ,          V ,          pVV,          V^,          ,          pVV,          pVP                  VWÞ34       EK  VWÞ3W_&   EK  	  W‰3# )aÝ  Trial division stage. Here we trial divide the values generetated
by sieve_poly in the sieve interval and if it is a smooth number then
it is stored in `smooth_relations`. Moreover, if we find two partial relations
with same large prime then they are combined to form a smooth relation.
First we iterate over sieve array and look for values which are greater
than accumulated_val, as these values have a high chance of being smooth
number. Then using these values we find smooth relations.
In general, let ``t**2 = u*p modN`` and ``r**2 = v*p modN`` be two partial relations
with the same large prime p. Then they can be combined ``(t*r/p)**2 = u*v modN``
to form a smooth relation.

Parameters
==========

N : Number to be factored
M : sieve interval
factor_base : factor_base primes
sieve_array : stores log_p values
sieve_poly : polynomial from which we find smooth relations
partial_relations : stores partial relations with one large prime
ERROR_TERM : error term for accumulated_val
r9   rj   )r   Úsetr/   rk   r"   ro   r?   r   r   ÚaddÚpopr   )r   rK   rB   re   Ú
sieve_polyÚpartial_relationsÚ
ERROR_TERMÚaccumulated_valÚsmooth_relationsÚproper_factorÚpartial_relation_upper_boundr   rY   ra   rm   rl   ÚuÚu_prevÚv_prevÚvec_prevs   &&&&&&&             r   Ú_trial_division_stager   Û   sT  € ô. ˜1“v¤ A£ q¥Õ(¨:Õ5¸Õ>€OØÐÜ“E€MØ#& {°2¥×'<Ñ'<Õ#<Ð Ü˜K¨×,‰ˆØÔ ÙØ×Ñ˜aÓ ˆÜ$ QÓ4‰ˆØ�!Œ8Ø×#Ñ# Z×%6Ñ%6°qÓ%9¸1Ð$BÖCØÖ/´G¸C·L´LØ�w˜!Œ|Ø×!Ñ! #Ô&ÙØ×!Ñ! !Ó$ˆAØÔ'Ø+<×+@Ñ+@ÀÓ+EÑ(�˜ Ø�f•HœV C›^Õ+¨aÕ/�Ø�f•H  Q¥Õ&�Ø�x•�Ø ×'Ñ'¨¨A¨×4à*+¨Q¨Ð!Ô&ñ' -ð( Ð*Ð*r   c              #  ó,  "  € V Uu. uF  q3^,          NK  	  pp\        V4      pR.V,          p\        V4       F”  p^V,          p\        V4       Fy  p	WI,          V,          ;p
'       g   K  W¤V	,          ,          pW„V	&   RWi&   \        V	^,           V4       F.  pWL,          V,          '       g   K  WL;;,          V,          uu&   K0  	   K’  	  K–  	  \        WdV4       F«  w  r�pV'       d   K  V^ ,          V^,          pp\        WdV4       FB  w  pppV'       g   K  VV,          '       g   K"  VV^ ,          ,          pVV^,          ,          pKD  	  \        V4      p^\	        VV,
          V 4      ;pu;8  d
   V 8  g   K£  M K§  Vx € K­  	  R# u upi 5i)ao  Finds proper factor of N using fast gaussian reduction for modulo 2 matrix.

Parameters
==========

N : Number to be factored
smooth_relations : Smooth relations vectors matrix
col : Number of columns in the matrix

Reference
==========

.. [1] A fast algorithm for gaussian elimination over GF(2) and
its implementation on the GAPP. Cetin K.Koc, Sarath N.Arachchige
FTN)r=   rH   ÚzipÚisqrtr   )r   rx   ÚcolÚ
s_relationÚmatrixÚrowÚmarkÚposÚmr`   rV   Úadd_colÚjÚmatÚrelr{   ra   Úm1Úmat1Úrel1r\   s   &&&                  r   Ú_find_factorr‘     s\  é € ñ  /?Ó?Ñ.> 
˜�mˆmÑ.>€FÐ?Ü
ˆf‹+€CØˆ7�S�=€DÜ�SŽzˆØ��HˆÜ�s–ˆAØ•I •MÐ!ˆq×!Ð!Ø Q�i�-�Ø�q‘	Ø�‘Ü˜q 1�u cÖ*�AØ•y 1—}–}ØŸ	 WÕ,�	ñ +ò ó ñ ô ˜4Ð)9Ö:‰ˆ�ßÙØ�1�v�s˜1•vˆ1ˆÜ! $Ð0@ÖA‰NˆB��dß‰r�c˜D—j–jØ�T˜!•W•�Ø�T˜!•W•’ñ Bô
 �!‹HˆØ”S˜˜Q� “]Ð"�Ö' a×'Ò'ØŒGó ;ùò @ùs0   ‚F‡F˜AFÁ-?FÂ1A'FÄFÄ.AFÆFc           	     ó.   € \        \        WW#V4      4      # )a  Performs factorization using Self-Initializing Quadratic Sieve.
In SIQS, let N be a number to be factored, and this N should not be a
perfect power. If we find two integers such that ``X**2 = Y**2 modN`` and
``X != +-Y modN``, then `gcd(X + Y, N)` will reveal a proper factor of N.
In order to find these integers X and Y we try to find relations of form
t**2 = u modN where u is a product of small primes. If we have enough of
these relations then we can form ``(t1*t2...ti)**2 = u1*u2...ui modN`` such that
the right hand side is a square, thus we found a relation of ``X**2 = Y**2 modN``.

Here, several optimizations are done like using multiple polynomials for
sieving, fast changing between polynomials and using partial relations.
The use of partial relations can speeds up the factoring by 2 times.

Parameters
==========

N : Number to be Factored
prime_bound : upper bound for primes in the factor base
M : Sieve Interval
ERROR_TERM : Error term for checking smoothness
seed : seed of random number generator

Returns
=======

set(int) : A set of factors of N without considering multiplicity.
           Returns ``{N}`` if factorization fails.

Examples
========

>>> from sympy.ntheory import qs
>>> qs(25645121643901801, 2000, 10000)
{5394769, 4753701529}
>>> qs(9804659461513846513, 2000, 10000)
{4641991, 2112166839943}

See Also
========

qs_factor

References
==========

.. [1] https://pdfs.semanticscholar.org/5c52/8a975c1405bd35c65993abf5a4edb667c1db.pdf
.. [2] https://www.rieselprime.de/ziki/Self-initializing_quadratic_sieve
)rq   Ú	qs_factor)r   r@   rK   rv   Úseeds   &&&&&r   Úqsr•   :  s   € ôb Œy˜¨¸Ó=Ó>Ð>r   c           
     óÆ  € V ^8  d   \        R4      h/ p. p/ pV ^,          ^ 8X  d2   ^pV ^,          p V ^,          ^ 8X  d   V ^,          p V^,          pK"  W…^&   \        V 4      '       d   ^WP&   V# \        V ^4      ;p	'       d   V	w  r¨W…V
&   V# T p\        V4      p\	        W4      w  rÞp\        V4      ^i,          ^d,          p\        WWýWì4       F†  p\        W/4      p\        WVVVWs4      w  ppVV,          pV FE  pVV,          '       d   K  ^pVV,          pVV,          ^ 8X  d   VV,          pV^,          pK"  W…V&   KG  	  V\        V4      8:  g   K†   M	  \        W\        V4      ^,           4       F^  pVV,          ^ 8X  g   K  ^pVV,          pVV,          ^ 8X  d   VV,          pV^,          pK"  W…V&   V^8X  g   \        V4      '       g   K^   M	  V^8w  d   ^W[&   V# )aU  Performs factorization using Self-Initializing Quadratic Sieve.

Parameters
==========

N : Number to be Factored
prime_bound : upper bound for primes in the factor base
M : Sieve Interval
ERROR_TERM : Error term for checking smoothness
seed : seed of random number generator

Returns
=======

dict[int, int] : Factors of N.
                 Returns ``{N: 1}`` if factorization fails.
                 Note that the key is not always a prime number.

Examples
========

>>> from sympy.ntheory import qs_factor
>>> qs_factor(1009 * 100003, 2000, 10000)
{1009: 1, 100003: 1}

See Also
========

qs

zN should be greater than 1)
Ú
ValueErrorr   r
   r   rF   r=   rc   rh   r   r‘   )r   r@   rK   rv   r”   Úfactorsrx   ru   rn   ÚresultrA   ÚN_copyrL   rC   rD   rB   Ú	thresholdr\   re   Ús_relÚp_frV   rf   s   &&&&&                  r   r“   r“   n  sô  € ð@ 	ˆ1„uÜÐ5Ó6Ð6Ø€GØÐØÐð 	ˆ1…u�„zØˆØ	ˆa�ˆØ�!�e�qŒjØ�!�GˆAØ��FŠAØ�‰
Üˆq‡z‚zØˆ‰
ØˆÜ  1Ó%Ð%€vÖ%Ø‰ˆØ�‰
ØˆØ€FÜ�t‹n€GÜ&;¸KÓ&KÑ#€H˜Ü�KÓ  3Õ&¨Õ+€IÜ! !¨¸xÖQˆÜ& qÓ6ˆÜ*¨1°¸kÈ1ÐN_Ól‰
ˆˆsØ˜EÕ!ÐÛˆAØ˜�zŒzÙØˆAØ�q�LˆFØ˜1•* ”/Ø˜1•�Ø�Q•’Ø�A‹Jñ ð œÐ,Ó-Ö-Ùñ Rô  ˜q´C¸Ó4DÀqÕ4HÖIˆØ�F�?˜aÖØˆAØ�vÕˆFØ˜6•/ QÔ&Ø˜6Õ!�Ø�Q•’Ø�F‰OØ˜Œ{œg fŸoœoÙñ Jð �„{Øˆ‰Ø€Nr   N)é   iÒ  )Úmathr   r   Úsympy.core.randomr   Úsympy.external.gmpyr   r   r   r	   r‚   Úsympy.ntheory.factor_r
   Úsympy.ntheory.primetestr   Úsympy.ntheory.residue_ntheoryr   r   r-   rF   rc   rh   ro   r   r‘   r•   r“   © r   r   Ú<module>r¦      s\   ðß Ý &ß EÓ EÝ 0Ý +Ý ?÷1ñ 1÷6ñ ò0+ò:HòVò6ò8/+òd*ôZ1?öhUr   