Learn R Programming

RcppBigIntAlgos (version 1.1.0)

quadraticSieve: Prime Factorization with the Parallel Quadratic Sieve

Description

Get the prime factorization of a number, \(n\), using the Quadratic Sieve.

Usage

quadraticSieve(n, showStats = FALSE, nThreads = NULL)

Value

Vector of class bigz

Arguments

n

An integer, numeric, string value, or an element of class bigz.

showStats

Logical flag. If TRUE, summary statistics will be displayed.

nThreads

Number of threads to be used. The default is NULL.

Author

Joseph Wood

Details

First, trial division is carried out to remove small prime numbers, then a constrained version of Pollard's rho algorithm is called to quickly remove further prime numbers. Next, we check to make sure that we are not passing a perfect power to the main quadratic sieve algorithm. After removing any perfect powers, we finally call the quadratic sieve with multiple polynomials in a recursive fashion until we have completely factored our number.

When showStats = TRUE, summary statistics will be shown. The frequency of updates is dynamic as writing to stdout can be expensive. It is determined by how fast smooth numbers (including partially smooth numbers) are found along with the total number of smooth numbers required in order to find a non-trivial factorization. The statistics are:

MPQS Time

The time measured for the multiple polynomial quadratic sieve section in hours h, minutes m, seconds s, and milliseconds ms.

Complete

The percent of smooth numbers plus partially smooth numbers required to guarantee a non-trivial solution when Gaussian Elimination is performed on the matrix of powers of primes.

Polynomials

The number of polynomials sieved

Smooths

The number of Smooth numbers found

Partials

The number of partially smooth numbers found. These numbers have one large factor, F, that is not reduced by the prime factor base determined in the algorithm. When we encounter another number that is almost smooth with the same large factor, F, we can combine them into one partially smooth number.

References

See Also

primeFactorizeBig, factorize

Examples

Run this code
mySemiPrime <- gmp::prod.bigz(gmp::nextprime(gmp::urand.bigz(2, 50, 17)))
quadraticSieve(mySemiPrime)

Run the code above in your browser using DataLab