Skip to main content

amari_fusion/
lib.rs

1//! Tropical-Dual-Clifford fusion system for optimal LLM evaluation
2//!
3//! This crate combines three exotic number systems:
4//! - **Tropical algebra**: Converts expensive softmax operations to max operations
5//! - **Dual numbers**: Provides automatic differentiation without computational graphs
6//! - **Clifford algebra**: Handles geometric relationships and rotations
7//!
8//! Together, these systems create a powerful framework for efficient neural network
9//! evaluation and optimization.
10//!
11//! # Key Types
12//!
13//! The main type is [`TropicalDualClifford`], which fuses all three algebras:
14//!
15//! ```ignore
16//! use amari_fusion::TropicalDualClifford;
17//!
18//! // Create TDC values
19//! let tdc1 = TropicalDualClifford::<f64, 8>::random_with_scale(1.0);
20//! let tdc2 = TropicalDualClifford::<f64, 8>::random_with_scale(1.0);
21//!
22//! // Geometric operations
23//! let product = &tdc1 * &tdc2;  // Tropical-modified geometric product
24//! let rotated = tdc1.rotate_by(&tdc2);  // Rotor-based rotation
25//!
26//! // Access components
27//! let tropical_val = tdc1.tropical_value();
28//! let gradient = tdc1.gradient();
29//! ```
30//!
31//! # Vector Symbolic Architectures
32//!
33//! [`TropicalDualClifford`] has built-in binding operations for holographic memory:
34//!
35//! ```ignore
36//! use amari_fusion::TropicalDualClifford;
37//!
38//! let key = TropicalDualClifford::<f64, 8>::random_with_scale(1.0);
39//! let value = TropicalDualClifford::<f64, 8>::random_with_scale(1.0);
40//!
41//! // Binding operations (inherent methods)
42//! let bound = key.bind(&value);              // Create association
43//! let retrieved = key.unbind(&bound);        // Retrieve value
44//! let superposed = key.bundle(&value, 1.0);  // Superposition
45//! let sim = key.similarity(&value);          // Cosine similarity
46//! ```
47//!
48//! # Holographic Memory (v0.12.3+)
49//!
50//! For dedicated Vector Symbolic Architectures (VSA) and holographic reduced
51//! representations with multiple algebra options, use the standalone
52//! [`amari-holographic`](https://docs.rs/amari-holographic) crate:
53//!
54//! ```ignore
55//! use amari_holographic::{HolographicMemory, ProductCliffordAlgebra, BindingAlgebra, AlgebraConfig};
56//!
57//! type ProductCl3x32 = ProductCliffordAlgebra<32>;
58//!
59//! // Create memory with 256-dimensional algebra
60//! let mut memory = HolographicMemory::<ProductCl3x32>::new(AlgebraConfig::default());
61//!
62//! // Store and retrieve
63//! let key = ProductCl3x32::random_versor(2);
64//! let value = ProductCl3x32::random_versor(2);
65//! memory.store(&key, &value);
66//! let result = memory.retrieve(&key);
67//! ```
68//!
69//! When the `holographic` feature is enabled, types are re-exported here for
70//! backward compatibility.
71//!
72//! # Feature Flags
73//!
74//! | Feature | Description |
75//! |---------|-------------|
76//! | `std` | Standard library support (default) |
77//! | `high-precision` | Enable 128-bit and arbitrary precision floats |
78//! | `holographic` | Re-export `amari-holographic` types |
79//! | `parallel` | Enable parallel operations via rayon |
80
81#![cfg_attr(not(feature = "std"), no_std)]
82
83extern crate alloc;
84
85// Re-export precision types from all constituent crates
86pub use amari_core::{ExtendedFloat, PrecisionFloat, StandardFloat};
87pub use amari_dual::{ExtendedDual, ExtendedMultiDual, StandardDual, StandardMultiDual};
88pub use amari_tropical::{ExtendedTropical, StandardTropical};
89
90#[cfg(feature = "high-precision")]
91pub use amari_core::HighPrecisionFloat;
92
93// Core fusion types
94pub mod types;
95
96// Domain modules
97pub mod attention;
98pub mod evaluation;
99pub mod optimizer;
100
101// Verification modules
102pub mod verified;
103pub mod verified_contracts;
104
105// Re-export core types
106pub use types::{EvaluationError, EvaluationResult, TropicalDualClifford};
107
108// Re-export holographic types when feature is enabled (backward compatibility)
109#[cfg(feature = "holographic")]
110pub use amari_holographic::{
111    // Algebra types
112    AlgebraConfig,
113    AlgebraError,
114    AlgebraResult,
115    // Memory types
116    Bindable,
117    BindingAlgebra,
118    CapacityInfo,
119    Cl3,
120    // Resonator types
121    CleanupResult,
122    CliffordAlgebra,
123    FHRRAlgebra,
124    FactorizationResult,
125    GeometricAlgebra,
126    // Error types
127    HolographicError,
128    HolographicMemory,
129    HolographicResult,
130    MAPAlgebra,
131    ProductCliffordAlgebra,
132    Resonator,
133    ResonatorConfig,
134    RetrievalResult,
135};
136
137// GPU acceleration exports