#primes #number-theory #bigint

num-prime

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

16 releases

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

#673 in Math

Download history 11199/week @ 2023-11-18 9097/week @ 2023-11-25 8311/week @ 2023-12-02 7726/week @ 2023-12-09 7083/week @ 2023-12-16 5544/week @ 2023-12-23 5456/week @ 2023-12-30 5555/week @ 2024-01-06 5068/week @ 2024-01-13 5463/week @ 2024-01-20 6059/week @ 2024-01-27 10186/week @ 2024-02-03 8085/week @ 2024-02-10 5525/week @ 2024-02-17 4866/week @ 2024-02-24 5099/week @ 2024-03-02

25,058 downloads per month
Used in 13 crates

Apache-2.0

430KB
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

~3MB
~53K SLoC