R-Math Algorithms
A Rust crate for rare, high-performance mathematical algorithms not commonly found in mainstream libraries.
Current Features
-
Tonelli-Shanks: Modular square roots (r^2 ≡ n mod p) over prime moduli (constant-time version)
-
Cuthill–McKee & Reverse Cuthill–McKee: Bandwidth reduction for sparse symmetric matrices (adjacency list, CSR, and CSC formats)
- Supports conversion from
sprssparse matrix types
- Supports conversion from
-
Freivalds' Algorithm: Fast probabilistic verification of matrix multiplication (scalar, modular, and SIMD-accelerated variants)
-
Well-documented, tested, and benchmarked implementations
-
SIMD acceleration for Freivalds' algorithm (nightly Rust required)
More about the algorithms here
Installation
Add to your Cargo.toml:
[]
= "0.1"
Enable SIMD features (nightly Rust required):
[]
= { = "0.1", = ["simd"] }
Benchmarks
Benchmarks are provided using criterion in the benches/ directory.
On stable Rust:
- Run all benchmarks:
- Run a specific benchmark (e.g., only Freivalds):
On nightly Rust (to enable SIMD):
- Run all benchmarks with SIMD:
- Run a specific benchmark with SIMD:
becnhes naming convention is filename with the _bench suffix; you check all in Cargo.toml
Testing
On stable Rust:
- Run all tests:
On nightly Rust (to enable SIMD tests):
- Run all tests with SIMD:
Documentation
Minimum Supported Rust Version
- Nightly Rust required for SIMD features (
#![feature(portable_simd)]) - Stable Rust for scalar and modular algorithms
Roadmap & Contributions
This crate will be updated with new algorithms over time, focusing on rare, advanced, or otherwise unported mathematical algorithms.
License
Licensed under either of
- Apache License, Version 2.0
- MIT license
r-math aims to be a home for rare, advanced, and high-performance mathematical algorithms in Rust.