| Crates.io | amari-tropical |
| lib.rs | amari-tropical |
| version | 0.17.0 |
| created_at | 2025-10-03 20:57:38.422016+00 |
| updated_at | 2026-01-11 22:31:51.795127+00 |
| description | Tropical (max-plus) algebra implementation |
| homepage | https://github.com/justinelliottcobb/Amari |
| repository | https://github.com/justinelliottcobb/Amari |
| max_upload_size | |
| id | 1867190 |
| size | 122,186 |
Tropical (max-plus) algebra implementation for optimization and neural network applications.
amari-tropical implements tropical algebra, also known as max-plus algebra, where the traditional operations (+, ×) are replaced with (max, +). This transformation converts expensive softmax and multiplication operations into simple max and addition operations, making it particularly useful for:
Add to your Cargo.toml:
[dependencies]
amari-tropical = "0.12"
[dependencies]
# Default features
amari-tropical = "0.12"
# With serialization
amari-tropical = { version = "0.12", features = ["serialize"] }
# With GPU acceleration
amari-tropical = { version = "0.12", features = ["gpu"] }
# High-precision arithmetic
amari-tropical = { version = "0.12", features = ["high-precision"] }
use amari_tropical::TropicalNumber;
// Create tropical numbers
let a = TropicalNumber::new(3.0);
let b = TropicalNumber::new(5.0);
// Tropical addition: max(3, 5) = 5
let sum = a.tropical_add(&b);
assert_eq!(sum.value(), 5.0);
// Tropical multiplication: 3 + 5 = 8
let product = a.tropical_mul(&b);
assert_eq!(product.value(), 8.0);
// Tropical identities
let zero = TropicalNumber::<f64>::tropical_zero(); // -∞ (additive identity)
let one = TropicalNumber::<f64>::tropical_one(); // 0 (multiplicative identity)
In tropical algebra, we define:
| Standard | Tropical |
|---|---|
| a + b | max(a, b) |
| a × b | a + b |
| 0 (additive identity) | -∞ |
| 1 (multiplicative identity) | 0 |
The name honors Brazilian mathematician Imre Simon, who pioneered this field. The algebra is particularly powerful because:
use amari_tropical::TropicalNumber;
let x = TropicalNumber::new(2.5);
// Access the underlying value
let val = x.value();
// Tropical operations (take references)
let y = TropicalNumber::new(3.0);
let sum = x.tropical_add(&y); // max(2.5, 3.0) = 3.0
let prod = x.tropical_mul(&y); // 2.5 + 3.0 = 5.5
use amari_tropical::TropicalMatrix;
// Create matrices for shortest path computation
let distances = TropicalMatrix::new(/* ... */);
// Tropical matrix multiplication gives shortest paths
let paths = distances.tropical_matmul(&distances);
use amari_tropical::viterbi::ViterbiDecoder;
// Efficient sequence decoding using tropical algebra
let decoder = ViterbiDecoder::new(&transitions, &emissions);
let best_path = decoder.decode(&observations);
| Module | Description |
|---|---|
types |
Core tropical number, matrix, and multivector types |
viterbi |
Viterbi algorithm for sequence decoding |
polytope |
Tropical polytopes and geometric structures |
verified |
Phantom types for compile-time verification |
error |
Error types for tropical operations |
Tropical algebra offers significant performance benefits:
The API was updated in v0.12.0 for better encapsulation:
// Before (v0.11.x)
let a = TropicalNumber(3.0);
let sum = a.tropical_add(b);
let val = a.0;
// After (v0.12.0+)
let a = TropicalNumber::new(3.0);
let sum = a.tropical_add(&b); // Now takes reference
let val = a.value();
Licensed under either of Apache License, Version 2.0 or MIT License at your option.
This crate is part of the Amari mathematical computing library.