Advanced Algorithms Library
A comprehensive Rust library providing high-performance implementations of advanced algorithms across multiple domains: numerical analysis, linear algebra, number theory, cryptography, optimization, statistics, and graph theory.
๐ Features
- High Performance: Optimized implementations with multi-threading support via Rayon
- Numerically Stable: Algorithms prioritize numerical stability and accuracy
- Well Documented: Comprehensive documentation with examples for each algorithm
- Type Safe: Leverages Rust's type system for correctness and safety
- Production Ready: Thoroughly tested with extensive test suites
๐ฆ Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
๐งฎ Algorithms Included
Numerical Analysis & Linear Algebra
Fast Fourier Transform (FFT)
The "most important numerical algorithm of our lifetime." Essential for signal processing, audio compression, and image processing.
use fft;
let signal = vec!;
let spectrum = fft;
// For large datasets, use parallel version
let large_signal: = .map.collect;
let spectrum_parallel = fft_parallel;
// Compute power spectrum
let power = power_spectrum;
QR Decomposition
Robust method for solving linear least squares problems using Householder transformations. More numerically stable than Gaussian elimination.
use QRDecomposition;
let matrix = vec!;
let qr = decompose.unwrap;
let q = qr.q; // Orthogonal matrix
let r = qr.r; // Upper triangular matrix
// Solve linear system Ax = b
let b = vec!;
let x = qr.solve.unwrap;
Newton-Raphson Method
Iterative root-finding algorithm with quadratic convergence. Used in calculators and physics engines.
use newton_raphson;
// Find square root of 2 by solving xยฒ - 2 = 0
let f = ;
let df = ;
let root = find_root.unwrap;
assert!;
// Advanced solver with history
use ;
let solver = new
.with_config;
let result = solver.solve.unwrap;
println!;
Singular Value Decomposition (SVD)
Matrix factorization for dimensionality reduction, PCA, and pseudoinverse computation.
use SVD;
let matrix = vec!;
let svd = SVDdecompose.unwrap;
let singular_values = svd.singular_values;
let rank = svd.rank;
let condition_number = svd.condition_number;
Number Theory & Cryptography
Miller-Rabin Primality Test
Probabilistic primality testing for RSA key generation and cryptographic applications.
use miller_rabin;
// Probabilistic test
assert!;
// Deterministic test for 64-bit integers
assert!;
// Generate random prime
let prime = generate_prime;
Extended Euclidean Algorithm
Computes GCD and modular multiplicative inverses for cryptography.
use extended_euclidean;
// Find GCD and Bรฉzout coefficients
let result = extended_gcd;
assert_eq!;
assert_eq!;
// Modular inverse for RSA
let inv = mod_inverse.unwrap;
assert_eq!;
// Solve linear congruence: 3x โก 6 (mod 9)
let solutions = solve_linear_congruence;
Mersenne Twister (MT19937)
High-quality pseudo-random number generator with period 2^19937 - 1.
use MersenneTwister;
let mut rng = new;
let random_int = rng.next_u32;
let random_float = rng.next_f64; // [0, 1)
let random_range = rng.next_range; // [0, 100)
let gaussian = rng.next_gaussian; // N(0, 1)
Optimization & Statistics
Gradient Descent
Fundamental optimizer for machine learning and neural network training.
use ;
// Minimize Rosenbrock function
let f = ;
let grad_f = ;
let gd = new
.with_learning_rate
.with_momentum
.with_max_iterations;
let result = gd.minimize.unwrap;
Levenberg-Marquardt Algorithm
Specialized optimizer for curve fitting and non-linear least squares.
use LevenbergMarquardt;
// Fit exponential: y = a*exp(b*x)
let x_data = vec!;
let y_data = vec!;
let residual = ;
let lm = new
.with_max_iterations
.with_tolerance;
let result = lm.fit.unwrap;
println!;
Monte Carlo Integration
Numerical integration using random sampling with parallel processing.
use monte_carlo;
// Integrate xยฒ from 0 to 1 (should be 1/3)
let f = ;
let bounds = vec!;
let result = integrate.unwrap;
println!;
// Multidimensional integration
let f_2d = ;
let bounds_2d = vec!;
let result_2d = integrate.unwrap;
Graph Algorithms
Dijkstra's Algorithm
Shortest path for graphs with non-negative weights.
use ;
let mut graph = new;
graph.add_edge;
graph.add_edge;
graph.add_edge;
graph.add_edge;
graph.add_edge;
let result = shortest_path;
let path = result.path_to.unwrap;
println!;
A* Search Algorithm
Heuristic-based pathfinding for optimal paths.
use ;
let mut graph = new;
// ... add edges ...
// Manhattan distance heuristic for grid
let heuristic = ;
let result = find_path.unwrap;
println!;
Bellman-Ford Algorithm
Shortest paths with negative edge weights and cycle detection.
use ;
let mut graph = new;
graph.add_edge;
graph.add_edge; // Negative weight OK
graph.add_edge;
let result = shortest_path.unwrap;
// Detect negative cycles
if has_negative_cycle
Floyd-Warshall Algorithm
All-pairs shortest paths.
use ;
let mut graph = new;
// ... add edges ...
let result = all_pairs_shortest_path.unwrap;
// Get distance between any two nodes
let dist = result.distance;
let path = result.path.unwrap;
// Find graph properties
let diameter = diameter;
let centers = find_center;
๐ง Performance Tips
Multi-threading
Many algorithms support parallel processing:
// FFT automatically uses parallel processing for large inputs
let spectrum = fft_parallel;
// Monte Carlo integration parallelizes automatically
let result = integrate.unwrap;
Optimization Levels
For maximum performance, compile with optimizations:
[]
= 3
= true
= 1
๐ Examples
See the examples/ directory for complete working examples:
๐งช Testing
Run the test suite:
Run benchmarks:
๐ Documentation
Full API documentation is available at docs.rs.
Generate local documentation:
๐ค Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
๐ License
This project is dual-licensed under:
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
You may choose either license for your use.
๐ Acknowledgments
This library implements classic algorithms from computer science and numerical analysis. Special thanks to:
- Donald Knuth for The Art of Computer Programming
- William H. Press et al. for Numerical Recipes
- Cormen, Leiserson, Rivest, and Stein for Introduction to Algorithms
๐ Support
- ๐ง Email: your.email@example.com
- ๐ Issues: GitHub Issues
- ๐ฌ Discussions: GitHub Discussions
๐บ๏ธ Roadmap
- Additional optimization algorithms (L-BFGS, Conjugate Gradient)
- More linear algebra operations (Cholesky decomposition, LU decomposition)
- Statistical distributions and hypothesis tests
- Parallel graph algorithms
- GPU acceleration support