Currently there may be errors shown on top of a page, because of a missing Wiki update (PHP version and extension DPL3).
Navigation
Topics Help • Register • News • History • How to • Sequences statistics • Template prototypes

Multiple polynomial quadratic sieve

From Prime-Wiki
Jump to: navigation, search

The multiple polynomial quadratic sieve (MPQS) is a factorization method.

Introduction

Let N be the number to be factored. This number must not be a perfect power. If somehow we find two integers X and Y such that X2Y2(modN) and X±Y(modN), then gcd(X+Y,N) will reveal a proper factor of N.

In order to find these values X and Y the method finds relations which have the form t2u(modN) where u is the product of small prime numbers. The set of these primes is the factor base. These relations will be found using sieving as will be explained below.

The relations found are combined using multiplications. The left hand side will always be a square because is a product of squares, so the goal is to have a square at the right hand side. A number is a square when all its prime factors appear an even number of times.

For example: let the number to factor be N = 1817 and we have found the following relations with factor base = {2, 7, 13}:

4522470131
123221070131

Both relations have non-square RHS, since the exponent of 13 is not even. But multiplying them we get:

842214132
842(2713)2

Since 2713=1664 we get the factor gcd(84+1664,1817)=23.

Which relations have to multiplied to find a square in the RHS is a linear algebra problem.

Sieving

We will sieve in the interval [-M, +M] using several polynomials ga,b(x)=(ax+b)2N where b2n=ac so ga,b(x)=a(ax2+bx+c) with different values of a and b. The advantage here is that we know the factorization of a, so the other factor is small compared to N, thus increasing the probability that all its prime factors are included in the factor base. Using the notation of the previous section, t2u(modN) where t=ax+b and u=ga,b(x).

Generating the factor base

In order to determine the factor base, we have to notice that it includes all the possible factors of ga,b(x). Since ga,b(x)=t2N, we get that 0t2N or t2N modulo any prime of the factor base. This means that about half of the primes cannot be in the factor base because N cannot be a quadratic residue modulo that prime. Notice that the content of this paragraph does not depend on the particular values of a or b, so the factor base can be computed at the beginning of MPQS. The upper bound for the factor base is determined from experimentation, for example:

  • Factoring a 60 digit number: F = 60000
  • Factoring a 70 digit number: F = 350000
  • Factoring a 80 digit number: F = 900000

The next step consists in computing the modular square roots of N modulo the different primes in the factor base and computing the logarithms in base 2 of the different primes rounded to the nearest integer, storing these values in the arrays tsqrt and tlog.

Generating a polynomial

We have to compute the coefficients a and b. The first coefficient will be the square of a prime near 2N/M such that N is a quadratic residue modulo this prime, and the second will be a modular square root of a. All these operations will require multiple precision arithmetic.

For each prime p in the factor base:

  • Compute ainv as the inverse of a modulo p.
  • Compute the first solution as soln1=ainv(tsqrt[p]b)modp and add tlog[p] to all locations soln1+kp of the sieve array.
  • Compute the second solution as soln2=ainv(tsqrt[p]b)modp and add tlog[p] to all locations soln2+kp of the sieve array.

Obtaining relations

Walk through the sieve array. For each element greater than about log(2xN) minus a small error term (because the logarithms are rounded and we do not sieve with powers of prime numbers), perform a trial division of ga,b(x)/a by the elements of the factor base. If all prime factors are less than or equal to F, save the relation. If there are enough relations (generally about 5% more relations than elements of the factor base), perform the linear algebra stage. Otherwise more relations must be collected. When the sieve stage is exhausted, change polynomial.

Large prime variation

A variation that makes the sieving about twice as fast but requiring more memory, named PMPQS, consists in selecting a large prime bound (about 64 F). If after the trial division by the primes in the factor base the quotient is less than the large prime bound, we collect this partial relation in a different location than full relations (when the final quotient is 1). If the large prime found is the same than the large prime found in a previous partial relation, we can combine them:

Let t2up(modN) and r2vp(modN) be two partial relations with the same large prime p. Then a full relation will be:

(trp)2uv(modN).

This full relation can be stored with the other full relations found.

At the beginning of PMPQS the number of full relations found in this way will be small, but it increases as the algorithm progresses, and then there will be more relations found from partial relations than without large primes.

External links