#miller-rabin #primality-test #prime #gmp #rabin #miller

rug-miller-rabin

A multi-threaded, arbitrary precision implementation of the Miller-Rabin primality test using rug (GMP)

2 releases

0.1.1 Dec 28, 2024
0.1.0 Mar 9, 2024

#911 in Math

Download history 24/week @ 2024-09-21 24/week @ 2024-09-28 1/week @ 2024-10-05 7/week @ 2024-10-12 7/week @ 2024-10-19 13/week @ 2024-10-26 10/week @ 2024-11-02 4/week @ 2024-11-16 8/week @ 2024-11-23 9/week @ 2024-11-30 23/week @ 2024-12-07 23/week @ 2024-12-14 9/week @ 2024-12-21 126/week @ 2024-12-28 22/week @ 2025-01-04

181 downloads per month
Used in 4 crates (2 directly)

LGPL-3.0+

17KB
170 lines

Miller Rabin Primality Test for rug (GMP)

Introduction

This crate implements a multi-threaded, arbitrary precision implementation of the Miller-Rabin primality test.

The implementation ist done for Integer from the crate rug, a high-level interface for GMP.

The crate is strongly inspired from the crate miller_rabin.

Installation

See rug for the requirements and installation steps.

Licence

Rug is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. See the full text of the GNU LGPL for details.


lib.rs:

Miller-Rabin Test (multi-threaded) for Integer (rug / GMP)

The methog [is_prime] test if a given number is probably prime using the Miller-Rabin method with the given number of iterations.

Example

use miller_rabin::is_prime;

// Mersenne Prime (2^31 - 1)
let n: u64 = 0x7FFF_FFFF;
assert!(is_prime(&n, 16));

Feature

Per default the test will be run in parallel (using [rayon]). The test can run iteratively deactivate the default feature by importing the crate.

Dependencies

~22MB
~513K SLoC