Get the Prime Factorization for a number with a particular coding.
ReducePrime(code, out.summary = FALSE, primes.div = NULL)
code | A vector representing a number. See details. |
---|---|
out.summary | Is the result to be summarized? For example,
(2, 3, 0, 0, 1) can be summarized as 2, 5; 3, 1. Default is |
primes.div | The vector of all prime numbers
up to |
Two rows representing prime numbers
A code
is the coding of a number as follows,
$$number = \prod i^{code[i]},$$
or, which is equivalent,
$$\log(number) = \sum code[i] * \log(i).$$
For example,
5 is coded as (0, 0, 0, 0, 1),
5! is coded as (1, 1, 1, 1, 1),
8! is coded as (1, 1, 1, 1, 1, 1, 1, 1),
8! / 5! is therefore coded as (0, 0, 0, 0, 0, 1, 1, 1),
5! = 5 * 3 * 2^3 can be reduced to (0, 3, 1, 0, 1).
Note that the first element of a code
has no effect.
code100 <- c(rep(0, 99), 1) ReducePrime(c(rep(0, 99), 1), out.summary = TRUE)#> [,1] [,2] #> primes 2 5 #> power 2 2primes.div <- AllPrimesUpTo(floor(sqrt(length(code100)))) ReducePrime(c(rep(0, 99), 1), primes.div = primes.div)#> [1] 0 2 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 #> [38] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 #> [75] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0