§
    ]²Åj¨G  ã                   óÂ   — d dl mZ d dlmZmZmZ d dlmZ d dl	m
Z
 d dlmZmZ  G d„ d¦  «        Z G d„ d	¦  «        Zd
„ Zdd„Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zdd„ZdS )é    )Ú_randint)ÚgcdÚinvertÚsqrt)Ú_sqrt_mod_prime_power)Úisprime)Úlogr   c                   ó   — e Zd Zdd„Zd„ ZdS )ÚSievePolynomial© Nc                 ó0   — || _         || _        || _        dS )aÄ  This class denotes the seive polynomial.
        If ``g(x) = (a*x + b)**2 - N``. `g(x)` can be expanded
        to ``a*x**2 + 2*a*b*x + b**2 - N``, so the coefficient
        is stored in the form `[a**2, 2*a*b, b**2 - N]`. This
        ensures faster `eval` method because we dont have to
        perform `a**2, 2*a*b, b**2` every time we call the
        `eval` method. As multiplication is more expensive
        than addition, by using modified_coefficient we get
        a faster seiving process.

        Parameters
        ==========

        modified_coeff : modified_coefficient of sieve polynomial
        a : parameter of the sieve polynomial
        b : parameter of the sieve polynomial
        N)Úmodified_coeffÚaÚb)Úselfr   r   r   s       úAC:\Projects\Historical\venv\Lib\site-packages\sympy/ntheory/qs.pyÚ__init__zSievePolynomial.__init__	   s   € ð$ -ˆÔØˆŒØˆŒˆˆó    c                 ó2   — d}| j         D ]}||z  }||z  }Œ|S )z¢
        Compute the value of the sieve polynomial at point x.

        Parameters
        ==========

        x : Integer parameter for sieve polynomial
        r   )r   )r   ÚxÚansÚcoeffs       r   ÚevalzSievePolynomial.eval   s4   € ð ˆØÔ(ð 	ð 	ˆEØ�1‰HˆCØ�5‰LˆCˆCØˆ
r   )r   NN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r      s7   € € € € € ðð ð ð ð,ð ð ð ð r   r   c                   ó   — e Zd ZdZd„ ZdS )ÚFactorBaseElemz7This class stores an element of the `factor_base`.
    c                 óh   — || _         || _        || _        d| _        d| _        d| _        d| _        dS )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Úa_invÚb_ainv)r   r    r!   r"   s       r   r   zFactorBaseElem.__init__2   s9   € ð ˆŒ
ØˆŒØˆŒ
ØˆŒ
ØˆŒ
ØˆŒ
ØˆŒˆˆr   N)r   r   r   Ú__doc__r   r   r   r   r   r   /   s-   € € € € € ðð ðð ð ð ð r   r   c                 óª  — ddl m} g }d\  }}|                     d| ¦  «        D ]«}t          ||dz
  dz  |¦  «        dk    rŽ|dk    r|€t	          |¦  «        dz
  }|dk    r|€t	          |¦  «        dz
  }t          ||d¦  «        d         }t          t          |¦  «        d	z  ¦  «        }|                     t          |||¦  «        ¦  «         Œ¬|||fS )
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
    r   )Úsieve©NNé   é   iè  Niˆ  é   )
Úsympy.ntheory.generater)   Ú
primerangeÚpowÚlenr   Úroundr	   Úappendr   )	Úprime_boundÚnr)   Úfactor_baseÚidx_1000Úidx_5000r    Úresiduer"   s	            r   Ú_generate_factor_baser:   F   s  € ð -Ð,Ð,Ð,Ð,Ð,Ø€KØ#Ñ€HˆhØ×!Ò! ! [Ñ1Ô1ð Fð FˆÝˆq�5˜1‘9 Ñ" EÑ*Ô*¨aÒ/Ð/Ø�tŠ|ˆ| Ð 0Ý˜{Ñ+Ô+¨aÑ/�Ø�tŠ|ˆ| Ð 0Ý˜{Ñ+Ô+¨aÑ/�Ý+¨A¨u°aÑ8Ô8¸Ô;ˆGÝ�#˜e™*œ* UÑ*Ñ+Ô+ˆEØ×Ò�~¨e°W¸eÑDÔDÑEÔEÐEøØ�X˜{Ð*Ð*r   Nc                 ó  ‡— t          |¦  «        }t          d| z  ¦  «        |z  }d\  }}	}
|€dn|}|€t          |¦  «        dz
  n|}t          d¦  «        D ]Ž}d}g }||k     rOd}|dk    s||v r |||¦  «        }|dk    °||v °||         j        }||z  }|                     |¦  «         ||k     °O||z  }|
�&t          |dz
  ¦  «        t          |
dz
  ¦  «        k     r|}	|}|}
Œ�|}|	}g }|D ]\}||         j        }||         j        t          ||z  |¦  «        z  |z  }||dz  k    r||z
  }|                     ||z  |z  ¦  «         Œ]t          |¦  «        }t          ||z  d|z  |z  ||z  | z
  g||¦  «        }|D ]}Š|‰j        z  dk    rŒt          |‰j        ¦  «        ‰_        ˆfd„|D ¦   «         ‰_        ‰j        ‰j        |z
  z  ‰j        z  ‰_        ‰j        ‰j         |z
  z  ‰j        z  ‰_        Œ~||fS )ag  This step is the initialization of the 1st sieve polynomial.
    Here `a` is selected as a product of several primes of the factor_base
    such that `a` is about to ``sqrt(2*N) / M``. Other initial values of
    factor_base elem are also initialized which includes a_inv, b_ainv, soln1,
    soln2 which are used when the sieve polynomial is changed. The b_ainv
    is required for fast polynomial change as we do not have to calculate
    `2*b*invert(a, prime)` every time.
    We also ensure that the `factor_base` primes which make `a` are between
    1000 and 5000.

    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
    seed : Generate pseudoprime numbers
    r,   )NNNNr   r+   é2   c                 ó:   •— g | ]}d |z  ‰j         z  ‰j        z  ‘ŒS )r,   )r%   r    )Ú.0Úb_elemÚfbs     €r   ú
<listcomp>z0_initialize_first_polynomial.<locals>.<listcomp>£   s+   ø€ ÐBÐBÐB°f�Q�v‘X˜bœhÑ&¨¬Ñ1ÐBÐBÐBr   )r   r   r1   Úranger    r3   Úabsr!   r   Úsumr   r%   r&   r#   r$   )ÚNÚMr6   r7   r8   ÚseedÚrandintÚ
approx_valÚbest_aÚbest_qÚ
best_ratioÚstartÚendÚ_r   ÚqÚrand_pÚpÚratioÚBÚvalÚq_lÚgammar   Úgr@   s                            @r   Ú_initialize_first_polynomialrY   c   s  ø€ õ* �t‰nŒn€GÝ�a˜‘c‘”˜Q‘€Jð
 "2Ñ€FˆF�JØÐ!ˆAˆA x€EØ"*Ð"2�#ˆkÑ
Ô
˜QÑ
Ð
¸€CÝ�2‰YŒYð ð ˆØˆØˆØ�*ŠnˆnØˆFØ˜A’+�+ ¨1  Ø ˜ ¨Ñ,Ô,�ð ˜A’+�+ ¨1  à˜FÔ#Ô)ˆAØ�‰FˆAØ�HŠH�VÑÔÐð �*Šnˆnð �J‘ˆØÐ¥ U¨Q¡Y¡¤µ#°jÀ1±nÑ2EÔ2EÒ!EÐ!EØˆFØˆFØˆJøà€AØ€Aà
€AØð ð ˆØ˜#ÔÔ$ˆØ˜CÔ Ô'­&°°c±¸3Ñ*?Ô*?Ñ?À#ÑEˆØ�3˜‘7Š?ˆ?Ø˜%‘KˆEØ	�Š��C‘˜‘ÑÔÐÐåˆA‰Œ€AÝ˜˜1™˜a ™c !™e Q q¡S¨1¡WÐ-¨q°!Ñ4Ô4€Aàð :ð :ˆØˆrŒx‰<˜1ÒÐØÝ˜!˜RœXÑ&Ô&ˆŒØBÐBÐBÐBÀÐBÑBÔBˆŒ	Ø”H˜bœi¨!™mÑ,°´Ñ8ˆŒØ”H˜rœy˜j¨1™nÑ-°´Ñ9ˆŒˆØˆaˆ4€Kr   c                 óÚ  — ddl m} d}|}|dz  dk    r|dz  }|dz  }|dz  dk    ° ||d|z  z  ¦  «        dz  dk    rd}nd}|j        d|z  ||dz
           z  z   }	|j        }
t	          |
|
z  d|
z  |	z  |	|	z  | z
  g|
|	¦  «        }|D ]a}|
|j        z  dk    rŒ|j        ||j        |dz
           z  z
  |j        z  |_        |j        ||j        |dz
           z  z
  |j        z  |_        Œb|S )aÐ  Initialization stage of ith poly. After we finish sieving 1`st polynomial
    here we quickly change to the next polynomial from which we will again
    start sieving. Suppose we generated ith sieve polynomial and now we
    want to generate (i + 1)th polynomial, where ``1 <= i <= 2**(j - 1) - 1``
    where `j` is the number of prime factors of the coefficient `a`
    then this function can be used to go to the next polynomial. If
    ``i = 2**(j - 1) - 1`` then go to _initialize_first_polynomial stage.

    Parameters
    ==========

    N : number to be factored
    factor_base : factor_base primes
    i : integer denoting ith polynomial
    g : (i - 1)th polynomial
    B : array that stores a//q_l*gamma
    r   )Úceilingr+   r,   éÿÿÿÿ)	Ú#sympy.functions.elementary.integersr[   r   r   r   r    r#   r&   r$   )rE   r6   ÚirX   rT   r[   ÚvÚjÚneg_powr   r   r@   s               r   Ú_initialize_ith_polyrb   ©   sD  € ð$ <Ð;Ð;Ð;Ð;Ð;Ø	€AØ	€AØ
ˆa‰%�1Š*ˆ*Ø	ˆQ‰ˆØ	ˆa‰ˆð ˆa‰%�1Š*ˆ*ð €wˆq�A�q‘D‰zÑÔ˜QÑ !Ò#Ð#ØˆˆàˆØ	Œˆa�‰i˜˜!˜a™%œÑ Ñ €AØ	Œ€AÝ˜˜1™˜a ™c !™e Q q¡S¨1¡WÐ-¨q°!Ñ4Ô4€AØð Dð DˆØˆrŒx‰<˜1ÒÐØØ”H˜w r¤y°°Q±Ô'7Ñ7Ñ7¸2¼8ÑCˆŒØ”H˜w r¤y°°Q±Ô'7Ñ7Ñ7¸2¼8ÑCˆŒˆà€Hr   c                 óT  — dgd| z  dz   z  }|D ]˜}|j         €Œ
t          | |j         z   |j        z  d| z  |j        ¦  «        D ]}||xx         |j        z  cc<   Œ|j        dk    rŒWt          | |j        z   |j        z  d| z  |j        ¦  «        D ]}||xx         |j        z  cc<   ŒŒ™|S )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
    r   r,   r+   )r#   rB   r    r"   r$   )rF   r6   Úsieve_arrayÚfactorÚidxs        r   Ú_gen_sieve_arrayrg   Ñ   sì   € ð �#�q˜‘s˜Q‘w‘-€KØð 	-ð 	-ˆØŒ<ÐØÝ˜!˜fœlÑ*¨f¬lÑ:¸A¸a¹CÀÄÑNÔNð 	-ð 	-ˆCØ˜ÐÐÔ ¤Ñ,ÐÐÑÐØŒ<˜1ÒÐØå˜!˜fœlÑ*¨f¬lÑ:¸A¸a¹CÀÄÑNÔNð 	-ð 	-ˆCØ˜ÐÐÔ ¤Ñ,ÐÐÑÐð	-àÐr   c                 óŒ  — g }| dk     r|                      d¦  «         | dz  } n|                      d¦  «         |D ]k}| |j        z  dk    r|                      d¦  «         Œ&d}| |j        z  dk    r|dz  }| |j        z  } | |j        z  dk    °|                      |dz  ¦  «         Œl| dk    r|dfS t          | ¦  «        r| dfS dS )ab  Here we check that if `num` is a smooth number or not. If `a` is a smooth
    number then it returns a vector of prime exponents modulo 2. For example
    if a = 2 * 5**2 * 7**3 and the factor base contains {2, 3, 5, 7} then
    `a` is a smooth number and this function returns ([1, 0, 0, 1], True). If
    `a` is a partial relation which means that `a` a has one prime factor
    greater than the `factor_base` then it returns `(a, False)` which denotes `a`
    is a partial relation.

    Parameters
    ==========

    a : integer whose smootheness is to be checked
    factor_base : factor_base primes
    r   r+   r\   r,   TFr*   )r3   r    r   )Únumr6   Úvecre   Ú
factor_exps        r   Ú_check_smoothnessrl   ì   sù   € ð €CØ
ˆQ‚w€wØ�
Š
�1‰ŒˆØˆr‰	ˆˆà�
Š
�1‰Œˆàð #ð #ˆØ�”Ñ Ò"Ð"Ø�JŠJ�q‰MŒMˆMØØˆ
Ø�F”LÑ  AÒ%Ð%Ø˜!‰OˆJØ�F”LÑ ˆCð �F”LÑ  AÒ%Ð%ð 	�
Š
�: ‘>Ñ"Ô"Ð"Ð"Ø
ˆa‚x€xØ�DˆyÐÝˆs�|„|ð Ø�EˆzÐØˆ:r   c                 ó°  — t          | ¦  «        }t          ||z  ¦  «        dz  |z
  }g }	t          ¦   «         }
d|d         j        z  }t	          |¦  «        D ]ü\  }}||k     rŒ||z
  }|                     |¦  «        }t          ||¦  «        \  }}|€Œ<|j        |z  |j        z   }|du r’|}||k    rŒ[||vr||f||<   Œg||         \  }}| 	                    |¦  «         	 t          || ¦  «        }n%# t          $ r |
                     |¦  «         Y Œºw xY w||z  |z  }||z  ||z  z  }t          ||¦  «        \  }}|	                     |||f¦  «         Œý|	|
fS )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
    r-   é€   r\   NF)Úisqrtr	   Úsetr    Ú	enumerater   rl   r   r   Úpopr   ÚZeroDivisionErrorÚaddr3   )rE   rF   r6   rd   Ú
sieve_polyÚpartial_relationsÚ
ERROR_TERMÚsqrt_nÚaccumulated_valÚsmooth_relationsÚproper_factorÚpartial_relation_upper_boundrf   rU   r   r_   rj   Ú	is_smoothÚuÚlarge_primeÚu_prevÚv_prevÚlarge_prime_invs                          r   Ú_trial_division_stagerƒ     sÃ  € õ. �1‰XŒX€FÝ˜!˜f™*‘o”o eÑ+¨jÑ8€OØÐÝ‘E”E€MØ#& {°2¤Ô'<Ñ#<Ð Ý˜kÑ*Ô*ð -ð -‰ˆˆSØ�Ò Ð ØØ�!‰GˆØ�OŠO˜AÑÔˆÝ*¨1¨kÑ:Ô:‰ˆˆYØÐØØŒL˜‰N˜Zœ\Ñ)ˆð ˜ÐÐØˆKàÐ9Ò9Ð9ØØÐ"3Ð3Ð3Ø23°Q°Ð! +Ñ.Øà!2°;Ô!?‘�˜Ø!×%Ò% kÑ2Ô2Ð2ðÝ&,¨[¸!Ñ&<Ô&<�O�OøÝ(ð ð ð Ø!×%Ò% kÑ2Ô2Ð2Ø�Hðøøøð �f‘H˜_Ñ,�Ø�f‘H ¨[Ñ!8Ñ9�Ý!2°1°kÑ!BÔ!B‘��Yà×Ò  A s Ñ,Ô,Ð,Ð,Ø˜]Ð*Ð*s   ÃC0Ã0DÄDc                 óJ   — g }| D ]}|                      |d         ¦  «         Œ|S )z|Build a 2D matrix from smooth relations.

    Parameters
    ==========

    smooth_relations : Stores smooth relations
    r,   )r3   )rz   ÚmatrixÚ
s_relations      r   Ú_build_matrixr‡   R  s6   € ð €FØ&ð %ð %ˆ
Ø�Š�j ”mÑ$Ô$Ð$Ð$Ø€Mr   c                 óL  — ddl }|                     | ¦  «        }t          |¦  «        }t          |d         ¦  «        }dg|z  }t          |¦  «        D ]“}t          |¦  «        D ]}||         |         dk    r nŒd||<   t          |¦  «        D ]V}||k    rŒ	||         |         dk    r;t          |¦  «        D ]+}	||	         |         ||	         |         z   dz  ||	         |<   Œ,ŒWŒ”g }
t	          |¦  «        D ](\  }}|dk    r|
                     ||         |g¦  «         Œ)|
||fS )aþ  Fast gaussian reduction for modulo 2 matrix.

    Parameters
    ==========

    A : Matrix

    Examples
    ========

    >>> from sympy.ntheory.qs import _gauss_mod_2
    >>> _gauss_mod_2([[0, 1, 1], [1, 0, 1], [0, 1, 0], [1, 1, 1]])
    ([[[1, 0, 1], 3]],
     [True, True, True, False],
     [[0, 1, 0], [1, 0, 0], [0, 0, 1], [1, 0, 1]])

    Reference
    ==========

    .. [1] A fast algorithm for gaussian elimination over GF(2) and
    its implementation on the GAPP. Cetin K.Koc, Sarath N.Arachchiger   NFr+   Tr,   )ÚcopyÚdeepcopyr1   rB   rq   r3   )ÚAr‰   r…   ÚrowÚcolÚmarkÚcÚrÚc1Úr2Údependent_rowrf   rU   s                r   Ú_gauss_mod_2r”   `  sf  € ð, €K€K€KØ�]Š]˜1ÑÔ€FÝ
ˆf‰+Œ+€CÝ
ˆf�QŒi‰.Œ.€CØˆ7�3‰;€DÝ�3‰ZŒZð 
Jð 
JˆÝ�s‘”ð 	ð 	ˆAØ�aŒy˜Œ|˜qÒ Ð Ø�ð !àˆˆQ‰Ý˜‘*”*ð 	Jð 	JˆBØ�QŠwˆwØØ�aŒy˜Œ} Ò!Ð!Ý ™*œ*ð Jð J�BØ&,¨R¤j°¤n°v¸b´zÀ!´}Ñ&DÈÑ%I�F˜2”J˜r‘N�Nøð	Jð €MÝ˜d‘O”Oð 5ð 5‰ˆˆSØ�%Š<ˆ<Ø× Ò  &¨¤+¨sÐ!3Ñ4Ô4Ð4øØ˜$ Ð&Ð&r   c                 ó"  — | |         d         }||         d         g}||         d         g}| |         d         }	t          |	¦  «        D ]Œ\  }
}|dk    r�t          t          |¦  «        ¦  «        D ]d}||         |
         dk    rP||         dk    rD|                     ||         d         ¦  «         |                     ||         d         ¦  «          nŒeŒ�d}d}|D ]}||z  }Œ|D ]}||z  }Œt	          |¦  «        }t          ||z
  |¦  «        S )a�  Finds proper factor of N. Here, transform the dependent rows as a
    combination of independent rows of the gauss_matrix to form the desired
    relation of the form ``X**2 = Y**2 modN``. After obtaining the desired relation
    we obtain a proper factor of N by `gcd(X - Y, N)`.

    Parameters
    ==========

    dependent_rows : denoted dependent rows in the reduced matrix form
    mark : boolean array to denoted dependent and independent rows
    gauss_matrix : Reduced form of the smooth relations matrix
    index : denoted the index of the dependent_rows
    smooth_relations : Smooth relations vectors matrix
    N : Number to be factored
    r+   r   T)rq   rB   r1   r3   ro   r   )Údependent_rowsrŽ   Úgauss_matrixÚindexrz   rE   Úidx_in_smoothÚindependent_uÚindependent_vÚdept_rowrf   rU   rŒ   r~   r_   r^   s                   r   Ú_find_factorr�   �  sL  € ð  # 5Ô)¨!Ô,€MØ% mÔ4°QÔ7Ð8€MØ% mÔ4°QÔ7Ð8€MØ˜eÔ$ QÔ'€Hå˜hÑ'Ô'ð ð ‰ˆˆSØ�!Š8ˆ8Ý�S Ñ.Ô.Ñ/Ô/ð ð �Ø Ô$ SÔ)¨QÒ.Ð.°4¸´9ÀÒ3DÐ3DØ!×(Ò(Ð)9¸#Ô)>¸qÔ)AÑBÔBÐBØ!×(Ò(Ð)9¸#Ô)>¸qÔ)AÑBÔBÐBØ�Eøøà	€AØ	€AØð ð ˆØ	ˆQ‰ˆˆØð ð ˆØ	ˆQ‰ˆˆåˆa‰Œ€AÝˆq�1‰u�a‰=Œ=Ðr   é   éÒ  c           	      óT  — |dz  }t          || ¦  «        \  }}}g }d}	i }
t          ¦   «         }dt          |¦  «        z  dz  }	 |	dk    rt          | ||||¦  «        \  }}nt	          | ||	||¦  «        }|	dz  }	|	dt          |¦  «        dz
  z  k    rd}	t          ||¦  «        }t          | |||||
|¦  «        \  }}||z  }||z  }t          |¦  «        t          |¦  «        |z   k    rnŒ§t          |¦  «        }t          |¦  «        \  }}}| }t          t          |¦  «        ¦  «        D ]|}t          |||||| ¦  «        }|dk    r`|| k     rZ|                     |¦  «         ||z  dk    r||z  }||z  dk    °t          |¦  «        r|                     |¦  «          n	|dk    r nŒ}|S )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
    threshold : Extra smooth relations for factorization
    seed : generate pseudo prime numbers

    Examples
    ========

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

    References
    ==========

    .. [1] https://pdfs.semanticscholar.org/5c52/8a975c1405bd35c65993abf5a4edb667c1db.pdf
    .. [2] https://www.rieselprime.de/ziki/Self-initializing_quadratic_sieve
    r-   r   é   éd   Tr+   r,   )r:   rp   r1   rY   rb   rg   rƒ   r‡   r”   rB   r�   rt   r   )rE   r4   rF   rw   rG   r7   r8   r6   rz   Úith_polyrv   r{   Ú	thresholdÚith_sieve_polyÚB_arrayrd   Ús_relÚp_fr…   r“   rŽ   r—   ÚN_copyr˜   re   s                            r   Úqsrª   µ  s  € ðN �Ñ€JÝ&;¸KÈÑ&KÔ&KÑ#€Hˆh˜ØÐØ€HØÐÝ‘E”E€MØ•#�kÑ"Ô"Ñ" cÑ)€IðØ�qŠ=ˆ=Ý&BÀ1ÀaÈÐV^Ð`hÑ&iÔ&iÑ#ˆN˜G˜Gå1°!°[À(ÈNÐ\cÑdÔdˆNØ�A‰ˆØ�q�3˜w™<œ<¨!Ñ+Ñ,Ò,Ð,ØˆHÝ& q¨+Ñ6Ô6ˆÝ*¨1¨a°¸kÈ>Ð[lÐnxÑyÔy‰
ˆˆsØ˜EÑ!ÐØ˜ÑˆÝÐÑ Ô ¥C¨Ñ$4Ô$4°yÑ$@Ò@Ð@Øðõ Ð+Ñ,Ô,€FÝ(4°VÑ(<Ô(<Ñ%€M�4˜Ø€FÝ•s˜=Ñ)Ô)Ñ*Ô*ð 
ð 
ˆÝ˜m¨T°<ÀÐHXÐZ[Ñ\Ô\ˆØ�AŠ:ˆ:˜& 1š*˜*Ø×Ò˜fÑ%Ô%Ð%Ø˜6‘/ QÒ&Ð&Ø˜6Ñ!�ð ˜6‘/ QÒ&Ð&å�v‰Œð Ø×!Ò! &Ñ)Ô)Ð)Ø�Ø˜Š{ˆ{Ø�øØÐr   )N)rž   rŸ   )Úsympy.core.randomr   Úsympy.external.gmpyr   r   r   ro   Úsympy.ntheory.residue_ntheoryr   Úsympy.ntheoryr   Úmathr	   r   r   r:   rY   rb   rg   rl   rƒ   r‡   r”   r�   rª   r   r   r   ú<module>r°      s|  ðØ &Ð &Ð &Ð &Ð &Ð &Ø :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ø ?Ð ?Ð ?Ð ?Ð ?Ð ?Ø !Ð !Ð !Ð !Ð !Ð !Ø Ð Ð Ð Ð Ð Ð Ð ð$ð $ð $ð $ð $ñ $ô $ð $ðNð ð ð ð ñ ô ð ð.+ð +ð +ð:Cð Cð Cð CðL%ð %ð %ðPð ð ð6#ð #ð #ðL<+ð <+ð <+ð@ð ð ð*'ð *'ð *'ðZ%ð %ð %ðPJð Jð Jð Jð Jð Jr   