ruvector_math/tropical/
mod.rs

1//! Tropical Algebra (Max-Plus Semiring)
2//!
3//! Tropical algebra replaces (×, +) with (max, +) or (min, +).
4//! Applications:
5//! - Neural network analysis (piecewise linear functions)
6//! - Shortest path algorithms
7//! - Dynamic programming
8//! - Linear programming duality
9//!
10//! ## Mathematical Background
11//!
12//! The tropical semiring (ℝ ∪ {-∞}, ⊕, ⊗) where:
13//! - a ⊕ b = max(a, b)
14//! - a ⊗ b = a + b
15//! - Zero element: -∞
16//! - Unit element: 0
17//!
18//! ## Key Results
19//!
20//! - Tropical polynomials are piecewise linear
21//! - Neural networks with ReLU = tropical rational functions
22//! - Tropical geometry provides bounds on linear regions
23
24mod semiring;
25mod polynomial;
26mod matrix;
27mod neural_analysis;
28
29pub use semiring::{Tropical, TropicalSemiring};
30pub use polynomial::{TropicalPolynomial, TropicalMonomial};
31pub use matrix::{TropicalMatrix, TropicalEigen, MinPlusMatrix};
32pub use neural_analysis::{LinearRegionCounter, TropicalNeuralAnalysis};
33
34#[cfg(test)]
35mod tests {
36    use super::*;
37
38    #[test]
39    fn test_tropical_ops() {
40        let a = Tropical::new(3.0);
41        let b = Tropical::new(5.0);
42
43        assert_eq!(a.add(&b).value(), 5.0); // max(3, 5) = 5
44        assert_eq!(a.mul(&b).value(), 8.0); // 3 + 5 = 8
45    }
46}