Erato
A Rust library for primality testing algorithms with integrated benchmarking using Criterion.
Features
- Multiple primality testing algorithms
- Sieve of Eratosthenes (trial division)
- Miller-Rabin (probabilistic, deterministic)
- Riemann Zeta (spectroscopic analysis using zeta function zeros)
- Extensible architecture - Easily add new algorithms
- Integrated benchmarking - Compare algorithm performance automatically
- Zero-cost abstractions - Efficient implementations
- Well-tested - Comprehensive test suite
Quick Start
Using individual functions
use ;
Using the trait-based interface
use ;
Using the registry
use PrimalityRegistry;
Benchmarking
Run the benchmarks to compare algorithm performance:
This generates HTML reports in target/criterion/ with detailed performance analysis.
Benchmark categories:
- Small primes (< 1,000)
- Small composites
- Medium primes (10,000 - 100,000)
- Medium composites
- Large primes (1,000,000 - 1,000,000,000)
- Very large primes (up to 100 billion)
Adding a New Algorithm
- Create a new file in
src/algorithms/:
use cratePrimalityTest;
;
- Add the module to
src/algorithms/mod.rs:
- Register it in the registry (in
mod.rs):
registry.register;
- Export from
src/lib.rs:
pub use ;
That's it! Your algorithm will automatically be included in benchmarks and the public API.
Riemann Hypothesis-based Testing
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:
- Oscillation coherence across zeta zeros (Σ cos(γ·log(n)))
- Chebyshev psi function jumps estimated via the explicit formula
- Spectral resonance patterns characteristic of prime numbers
- Phase alignment analysis inspired by Fourier transforms
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.
Usage
use ;
Zeta Example
WebAssembly Demo
This project includes a web interface that uses the Zeta primality algorithm compiled to WebAssembly for maximum performance.
Prerequisites
Install wasm-pack:
|
Building
Compile the Rust code to WebAssembly:
This generates the pkg/ directory containing:
erato.js- JavaScript bindingserato_bg.wasm- Compiled WebAssembly module
Running
Serve the files with any HTTP server:
Then open http://localhost:8080 in your browser.
The index.html automatically loads the WASM module:
const module = await import;
await module.;

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