Learn R Programming

RcppBigIntAlgos (version 1.1.0)

primeFactorizeBig: Vectorized Prime Factorization with GMP

Description

Quickly generates the prime factorization for many (possibly large) numbers, using trial division, Pollard's rho algorithm, Lenstra's Elliptic Curve method, and finally the Quadratic Sieve.

Usage

primeFactorizeBig(v, namedList = FALSE, showStats = FALSE,
                  skipPolRho = FALSE, skipECM = FALSE, nThreads = NULL)

Value

  • Returns an unnamed vector of class bigz if length(v) == 1 regardless of the value of namedList.

  • If length(v) > 1, a named/unnamed list of vectors of class bigz will be returned.

Arguments

v

Vector of integers, numerics, string values, or elements of class bigz.

namedList

Logical flag. If TRUE and the length(v) > 1, a named list is returned. The default is FALSE.

showStats

Logical flag for showing summary statistics. The default is FALSE.

skipPolRho

Logical flag for skipping the extended pollard rho algorithm. The default is FALSE.

skipECM

Logical flag for skipping the extended elliptic curve algorithm. The default is FALSE.

nThreads

Number of threads to be used for the elliptic curve method and the quadratic sieve.s The default is NULL.

Author

Joseph Wood

Details

This function should be preferred in most situations and is identical to quadraticSieve when both skipECM and skipPolRho are set to TRUE.

It is optimized for factoring big and small numbers by dynamically using different algorithms based off of the input. It takes cares to not spend too much time in any of the methods and avoids wastefully switching to the quadratic sieve when the number is very large.

See quadraticSieve for information regarding showStats.

References

See Also

primeFactorize, primeFactors, factorize, quadraticSieve

Examples

Run this code
## Get the prime factorization of a single number
primeFactorizeBig(100)

## Or get the prime factorization of many numbers
set.seed(29)
myVec <- sample(-1000000:1000000, 1000)
system.time(myFacs <- primeFactorizeBig(myVec))

## Return named list
myFacsWithNames <- primeFactorizeBig(myVec, namedList = TRUE)

Run the code above in your browser using DataLab