#prime #number-theory

primal-sieve

A high performance prime sieve

17 releases

0.3.6 Jan 3, 2023
0.3.5 Oct 10, 2022
0.3.3 Aug 15, 2022
0.3.2 Feb 16, 2022
0.2.4 Jun 30, 2015

#1074 in Math

Download history 2095/week @ 2023-12-13 1297/week @ 2023-12-20 676/week @ 2023-12-27 1537/week @ 2024-01-03 2279/week @ 2024-01-10 2180/week @ 2024-01-17 2329/week @ 2024-01-24 2341/week @ 2024-01-31 3064/week @ 2024-02-07 3113/week @ 2024-02-14 4411/week @ 2024-02-21 4264/week @ 2024-02-28 4341/week @ 2024-03-06 3398/week @ 2024-03-13 3150/week @ 2024-03-20 2122/week @ 2024-03-27

13,728 downloads per month
Used in 74 crates (5 directly)

MIT/Apache

560KB
8K SLoC

primal

crates.io documentation minimum rustc 1.36

primal puts raw power into prime numbers.

This crates includes

  • optimised prime sieves
  • checking for primality
  • enumerating primes
  • factorising numbers
  • estimating upper and lower bounds for π(n) (the number of primes below n) and pk (the kth prime)

This uses a state-of-the-art cache-friendly Sieve of Eratosthenes to enumerate the primes up to some fixed bound (in a memory efficient manner), and then allows this cached information to be used for things like enumerating and counting primes.

primal takes around 2.8 seconds and less than 3MB of RAM to count the exact number of primes below 1010 (455052511) on the author's laptop (i7-3517U).

Documentation


lib.rs:

Highly optimised prime sieves.

This is designed to be used via the primal crate.

Dependencies