#prime #primality-test #number-theory #big-int

num-prime

Generic and optimized primality test, factorization and various number theoretic functions with arbitrary precision based on num

17 releases

0.4.4 May 6, 2024
0.4.3 Dec 23, 2022
0.4.2 Oct 10, 2022
0.4.1 May 24, 2022
0.3.0-alpha Mar 3, 2022

#118 in Math

Download history 14583/week @ 2024-07-29 12731/week @ 2024-08-05 14853/week @ 2024-08-12 13693/week @ 2024-08-19 11495/week @ 2024-08-26 14348/week @ 2024-09-02 15842/week @ 2024-09-09 19698/week @ 2024-09-16 14582/week @ 2024-09-23 14780/week @ 2024-09-30 19035/week @ 2024-10-07 17757/week @ 2024-10-14 17031/week @ 2024-10-21 16237/week @ 2024-10-28 8805/week @ 2024-11-04 12655/week @ 2024-11-11

56,531 downloads per month
Used in 16 crates

Apache-2.0

440KB
7K SLoC

num-prime

This crate provides utilities for prime number related functionalities:

  • Primality testing
    • Deterministic primality check of u64 integers (using a very fast hashing algorithm)
    • Fermat probable prime test
    • Miller-rabin probable prime test
    • (strong/extra strong) Lucas probable prime test
    • Baillie-PSW test
    • Sophie Germain safe prime test
  • Primes generation and indexing
    • A naive implementation of the sieve of Eratosthenes
    • Unified API to support other prime generation backends
    • Generate random (safe) primes
    • Find previous/next prime
  • Integer factorization
    • Trial division
    • Pollard's rho algorithm
    • Shanks's square forms factorization (SQUFOF)
    • Fast factorization of u64 and u128 integers
  • Number theoretic functions
    • Prime Pi function (number of primes under limit), its estimation and its bounds
    • Nth prime, its estimation and its bounds
    • Moebius function
    • Divisor Sigma function (in examples)
    • Prime Omega function (in examples)

It's based on the num creates and most functions are decently optimized with pre-computed tables (see benchmark results here).

Dependencies

~2.5MB
~51K SLoC