| Crates.io | erato |
| lib.rs | erato |
| version | 0.2.1 |
| created_at | 2025-11-01 12:48:07.315743+00 |
| updated_at | 2025-11-07 05:20:17.840934+00 |
| description | A library for primality testing algorithms with benchmarking |
| homepage | |
| repository | https://github.com/Green-Mice/erato |
| max_upload_size | |
| id | 1911960 |
| size | 404,287 |
A Rust library for primality testing algorithms with integrated benchmarking using Criterion.
use erato::{is_prime_sieve, is_prime_miller_rabin};
fn main() {
println!("17 is prime: {}", is_prime_sieve(17));
println!("100 is prime: {}", is_prime_miller_rabin(100, 20));
}
use erato::{PrimalityTest, SieveAlgorithm, MillerRabinAlgorithm};
fn main() {
let sieve = SieveAlgorithm;
let miller_rabin = MillerRabinAlgorithm;
println!("Sieve: {}", sieve.is_prime(17));
println!("Miller-Rabin: {}", miller_rabin.is_prime(17));
}
use erato::PrimalityRegistry;
fn main() {
let registry = PrimalityRegistry::with_all_algorithms();
for algo in registry.algorithms() {
println!("{}: {}", algo.name(), algo.is_prime(17));
}
}
Run the benchmarks to compare algorithm performance:
cargo bench
This generates HTML reports in target/criterion/ with detailed performance analysis.
Benchmark categories:
src/algorithms/:use crate::PrimalityTest;
#[derive(Default)]
pub struct MyAlgorithm;
impl PrimalityTest for MyAlgorithm {
fn name(&self) -> &'static str {
"My Algorithm"
}
fn is_prime(&self, n: u64) -> bool {
// Your implementation
}
}
pub fn is_prime_my_algorithm(n: u64) -> bool {
is_prime_my_algorithm_internal(n)
}
fn is_prime_my_algorithm_internal(n: u64) -> bool {
// Implementation
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_example() {
assert!(is_prime_my_algorithm(17));
}
}
src/algorithms/mod.rs:pub mod my_algorithm;
mod.rs):registry.register(my_algorithm::MyAlgorithm::default());
src/lib.rs:pub use algorithms::my_algorithm::{is_prime_my_algorithm, MyAlgorithm};
That's it! Your algorithm will automatically be included in benchmarks and the public API.
The library includes an experimental primality test based on the Riemann Hypothesis (RH), which remains one of the most important unproven conjectures in mathematics. While RH is not proven, it has been computationally verified for the first 10 trillion non-trivial zeros of the zeta function, making it highly reliable for practical applications within reasonable bounds.
This algorithm exploits the explicit formula connecting the Riemann zeta function zeros to prime distribution. It uses a spectroscopic approach: the first 50 non-trivial zeros create oscillatory "frequency signatures" that distinguish primes from composites through interference patterns. The method computes:
While the algorithm still performs trial division for verification, it uses RH-derived properties to compute prime probability scores that guide the search strategy. This demonstrates the deep connection between analytic number theory and computational primality testing, offering an educational glimpse into how the zeros of zeta encode information about primes.
Note: This implementation assumes RH for its analytical optimizations. Since RH is verified computationally to very high limits, the algorithm is reliable for all practical integer ranges, though it remains theoretical for arbitrarily large numbers.
use erato::{is_prime_zeta, ZetaAlgorithm, PrimalityTest};
fn main() {
// Direct function call
println!("17 is prime: {}", is_prime_zeta(17));
// Using the trait interface
let zeta = ZetaAlgorithm;
println!("Using {}: {}", zeta.name(), zeta.is_prime(1000000007));
}
cargo run --example zeta_primality
This project includes a web interface that uses the Zeta primality algorithm compiled to WebAssembly for maximum performance.
Install wasm-pack:
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
Compile the Rust code to WebAssembly:
wasm-pack build --target web --release
This generates the pkg/ directory containing:
erato.js - JavaScript bindingserato_bg.wasm - Compiled WebAssembly moduleServe the files with any HTTP server:
python3 -m http.server 8080
Then open http://localhost:8080 in your browser.
The index.html automatically loads the WASM module:
const module = await import('./pkg/erato.js');
await module.default();

This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.