| Title: | Use Prime Factorization for Computations |
|---|---|
| Description: | Use Prime Factorization for simplifying computations, for instance for ratios of large factorials. |
| Authors: | Florian Privé [aut, cre] |
| Maintainer: | Florian Privé <[email protected]> |
| License: | GPL-3 |
| Version: | 0.1.1 |
| Built: | 2026-06-06 08:39:45 UTC |
| Source: | https://github.com/privefl/primefactr |
TODO
n |
A positive integer. |
Get all prime numbers up to n.
AllPrimesUpTo(n)AllPrimesUpTo(n)
n |
A positive integer. |
A integer vector of all prime numbers up to n.
AllPrimesUpTo(10) AllPrimesUpTo(100) AllPrimesUpTo(1e6)AllPrimesUpTo(10) AllPrimesUpTo(100) AllPrimesUpTo(1e6)
Compute the ratio of factorials
using Prime Factorization.
For example, ComputeDivFact(c(a, b), c(d, e, f)) computes
.
ComputeDivFact(num, deno = NULL, out.log = FALSE)ComputeDivFact(num, deno = NULL, out.log = FALSE)
num |
The vector of all numbers which have their factorials in the numerator. |
deno |
The vector of all numbers which have their factorials
in the denominator. Default is |
out.log |
Is the logarithm of the result returned instead?
Default is |
The result of the ratio or its logarithm
if out.log = TRUE.
choose
choose(100, 20) ComputeDivFact(100, c(20, 80)) lchoose(100, 20) ComputeDivFact(100, c(20, 80), out.log = TRUE) factorial(100) ComputeDivFact(100) lfactorial(100) ComputeDivFact(100, out.log = TRUE)choose(100, 20) ComputeDivFact(100, c(20, 80)) lchoose(100, 20) ComputeDivFact(100, c(20, 80), out.log = TRUE) factorial(100) ComputeDivFact(100) lfactorial(100) ComputeDivFact(100, out.log = TRUE)
Is n a prime number? You can see what is a prime number there.
IsPrime(n)IsPrime(n)
n |
A positive integer. |
A boolean.
IsPrime(1) # FALSE IsPrime(5) # TRUE IsPrime(59999999) # TRUEIsPrime(1) # FALSE IsPrime(5) # TRUE IsPrime(59999999) # TRUE
Get the Prime Factorization for a number with a particular coding.
ReducePrime(code, out.summary = FALSE, primes.div = NULL)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 |
A code is the coding of a number as follows,
or, which is equivalent,
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.
Two rows representing prime numbers
code100 <- c(rep(0, 99), 1) ReducePrime(c(rep(0, 99), 1), out.summary = TRUE) primes.div <- AllPrimesUpTo(floor(sqrt(length(code100)))) ReducePrime(c(rep(0, 99), 1), primes.div = primes.div)code100 <- c(rep(0, 99), 1) ReducePrime(c(rep(0, 99), 1), out.summary = TRUE) primes.div <- AllPrimesUpTo(floor(sqrt(length(code100)))) ReducePrime(c(rep(0, 99), 1), primes.div = primes.div)