Learn R Programming

bigIntegerAlgos (version 0.1.2)

divisorsBig: Vectorized Factorization (Complete) with GMP

Description

Quickly generates the complete factorization for many (possibly large) numbers.

Usage

divisorsBig(v, namedList = FALSE)

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.

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.

Details

Highly optimized algorithm to generate the complete factorization for many numbers. It is built specifically for the data type that is used in the gmp library (i.e. mpz_t).

The main part of this algorithm is essentially the same algorithm that is implemented in divisorsRcpp from the RcppAlgos package. A modified merge sort algorithm is implemented to better deal with the mpz_t data type. This algorithm avoids directly swapping elements of the main factor array of type mpz_t but instead generates a vector of indexing integers for ordering.

See this stack overflow post for examples and benchmarks : R Function for returning ALL factors.

References

Divisor

See Also

divisorsRcpp, divisors, factorize

Examples

Run this code
# NOT RUN {
## Get the complete factorization of a single number
divisorsBig(10^15)

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

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

Run the code above in your browser using DataLab