amari_functional/
lib.rs

1//! Functional analysis on multivector spaces.
2//!
3//! This crate provides the mathematical foundations of functional analysis
4//! applied to Clifford algebra-valued function spaces, including:
5//!
6//! - **Hilbert spaces**: Complete inner product spaces over multivectors
7//! - **Linear operators**: Bounded and unbounded operators on Hilbert spaces
8//! - **Spectral theory**: Eigenvalues, eigenvectors, and spectral decomposition
9//! - **Compact operators**: Fredholm theory and index theorems
10//! - **Sobolev spaces**: Function spaces with weak derivatives
11//!
12//! # Space Hierarchy
13//!
14//! The module implements the standard functional analysis hierarchy:
15//!
16//! ```text
17//! VectorSpace
18//!     ↓
19//! NormedSpace (adds ||·||)
20//!     ↓
21//! BanachSpace (complete normed space)
22//!     ↓
23//! InnerProductSpace (adds ⟨·,·⟩)
24//!     ↓
25//! HilbertSpace (complete inner product space)
26//! ```
27//!
28//! # Quick Start
29//!
30//! ## Finite-Dimensional Hilbert Space
31//!
32//! ```
33//! use amari_functional::space::{MultivectorHilbertSpace, HilbertSpace, InnerProductSpace};
34//!
35//! // Create the Hilbert space Cl(2,0,0) ≅ ℝ⁴
36//! let space: MultivectorHilbertSpace<2, 0, 0> = MultivectorHilbertSpace::new();
37//!
38//! // Create elements
39//! let x = space.from_coefficients(&[1.0, 2.0, 0.0, 0.0]).unwrap();
40//! let y = space.from_coefficients(&[0.0, 0.0, 3.0, 4.0]).unwrap();
41//!
42//! // Compute inner product
43//! let ip = space.inner_product(&x, &y);
44//! assert!(ip.abs() < 1e-10); // x and y are orthogonal
45//! ```
46//!
47//! ## L² Space of Multivector Functions
48//!
49//! ```
50//! use amari_functional::space::{MultivectorL2, L2Function, NormedSpace};
51//! use amari_core::Multivector;
52//!
53//! // Create L²([0,1], Cl(2,0,0))
54//! let l2: MultivectorL2<2, 0, 0> = MultivectorL2::unit_interval();
55//!
56//! // Define a function f(x) = x * e₀ (scalar coefficient is x)
57//! let f = L2Function::new(|x| {
58//!     Multivector::<2, 0, 0>::scalar(x[0])
59//! });
60//!
61//! // Compute L² norm: ||f||² = ∫₀¹ x² dx = 1/3
62//! let norm_sq = l2.norm(&f).powi(2);
63//! assert!((norm_sq - 1.0/3.0).abs() < 0.1);
64//! ```
65//!
66//! # Mathematical Background
67//!
68//! This crate is built on the following mathematical concepts:
69//!
70//! - **Clifford algebras Cl(P,Q,R)**: 2^(P+Q+R)-dimensional real algebras
71//! - **Hilbert spaces**: Complete inner product spaces with orthogonal decomposition
72//! - **Bounded operators**: Continuous linear maps between Hilbert spaces
73//! - **Spectral theorem**: Self-adjoint operators have orthonormal eigenbases
74//! - **Compact operators**: Operators mapping bounded sets to precompact sets
75//!
76//! # Features
77//!
78//! - `std` (default): Enable standard library features
79//! - `parallel`: Enable Rayon parallelism for large-scale computations
80//! - `formal-verification`: Enable Creusot contracts for formal verification
81
82#![cfg_attr(not(feature = "std"), no_std)]
83#![warn(missing_docs)]
84#![warn(clippy::all)]
85#![allow(dead_code)] // SpaceWithCompleteness reserved for future use
86#![allow(clippy::type_complexity)] // Complex function types are intentional for flexibility
87#![allow(clippy::needless_range_loop)] // Matrix indexing is clearer with explicit ranges
88
89// Note: formal-verification feature is reserved for future Creusot integration
90// #[cfg(feature = "formal-verification")]
91// extern crate creusot_contracts;
92
93// Re-export core types
94pub use amari_core::{Multivector, Scalar};
95
96// Error types
97mod error;
98pub use error::{FunctionalError, Result};
99
100// Phantom types for compile-time property verification
101mod phantom;
102pub use phantom::{
103    // Boundedness
104    Bounded,
105    BoundednessProperty,
106    // Compactness
107    Compact,
108    // Type aliases
109    CompactSelfAdjointOperator,
110    CompactnessProperty,
111    // Completeness
112    Complete,
113    CompletenessProperty,
114    // Spectral
115    ContinuousSpectrum,
116    DiscreteSpectrum,
117    // Fredholm
118    Fredholm,
119    FredholmProperty,
120    // Symmetry
121    General,
122    // Regularity
123    H1Regularity,
124    H1SpaceProperties,
125    H2Regularity,
126    HilbertSchmidtOperator,
127    HkRegularity,
128    L2Regularity,
129    L2SpaceProperties,
130    MixedSpectrum,
131    NonCompact,
132    Normal,
133    NotFredholm,
134    PreHilbert,
135    // Wrapper
136    Properties,
137    PurePointSpectrum,
138    RegularityProperty,
139    SelfAdjoint,
140    SemiFredholm,
141    SpectralProperty,
142    SymmetryProperty,
143    Unbounded,
144    Unitary,
145    UnitaryOperator,
146};
147
148// Function spaces
149pub mod space;
150pub use space::{
151    BanachSpace, Domain, HilbertSpace, InnerProductSpace, L2Function, MultivectorHilbertSpace,
152    MultivectorL2, NormedSpace, VectorSpace,
153};
154
155// Linear operators
156pub mod operator;
157pub use operator::{
158    AdjointableOperator, BoundedOperator, CompactMatrixOperator, CompactOperator,
159    CompositeOperator, FiniteRankOperator, FredholmMatrixOperator, FredholmOperator,
160    IdentityOperator, LinearOperator, MatrixOperator, OperatorNorm, ProjectionOperator,
161    ScalingOperator, SelfAdjointOperator, ZeroOperator,
162};
163
164// Spectral theory
165pub mod spectral;
166pub use spectral::{
167    compute_eigenvalues, inverse_iteration, power_method, spectral_decompose, Eigenpair,
168    Eigenvalue, SpectralDecomposition,
169};
170
171// Sobolev spaces
172pub mod sobolev;
173pub use sobolev::{poincare_constant_estimate, H1Space, H2Space, SobolevFunction, SobolevSpace};
174
175#[cfg(test)]
176mod tests {
177    use super::*;
178
179    #[test]
180    fn test_crate_compiles() {
181        // Basic smoke test to ensure the crate structure is valid
182        let space: MultivectorHilbertSpace<2, 0, 0> = MultivectorHilbertSpace::new();
183        assert_eq!(space.signature(), (2, 0, 0));
184    }
185
186    #[test]
187    fn test_l2_space_compiles() {
188        let l2: MultivectorL2<2, 0, 0> = MultivectorL2::unit_interval();
189        assert_eq!(l2.signature(), (2, 0, 0));
190    }
191}