View source: R/IntegerFactorization.R
quadraticSieve | R Documentation |
Get the prime factorization of a number, n
, using the Quadratic Sieve.
quadraticSieve(n, showStats = FALSE, nThreads = NULL)
n |
An integer, numeric, string value, or an element of class bigz. |
showStats |
Logical flag. If |
nThreads |
Number of threads to be used. The default is |
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.
Vector of class bigz
primeFactorizeBig
is preferred for general prime factorization.
Both the extended Pollard's rho algorithm and the elliptic curve method are skipped. For general prime factorization, see primeFactorizeBig
.
Safely interrupt long executing commands by pressing Ctrl + c
, Esc
, or whatever interruption command offered by the user's GUI. If you are using multiple threads, you can still interrupt execution, however there will be a delay up to 30 seconds if the number is very large.
Note, the function primeFactorizeBig(n, skipECM = T, skipPolRho = T)
is the same as quadraticSieve(n)
Joseph Wood
primeFactorizeBig
, factorize
mySemiPrime <- gmp::prod.bigz(gmp::nextprime(gmp::urand.bigz(2, 50, 17)))
quadraticSieve(mySemiPrime)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.