Skip to main content

amari_enumerative/
lib.rs

1//! # Amari Enumerative Geometry
2//!
3//! This crate provides enumerative geometry capabilities for the Amari mathematical library.
4//! It implements intersection theory, Schubert calculus, and tools for counting geometric
5//! configurations such as curves, surfaces, and higher-dimensional varieties.
6//!
7//! ## Features
8//!
9//! - **Intersection Theory**: Chow rings, intersection multiplicities, and Bezout's theorem
10//! - **Schubert Calculus**: Computations on Grassmannians and flag varieties
11//! - **Littlewood-Richardson Coefficients**: Complete LR coefficient computation
12//! - **Gromov-Witten Theory**: Curve counting and quantum cohomology
13//! - **Tropical Geometry**: Tropical curve counting and correspondence theorems
14//! - **Moduli Spaces**: Computations on moduli spaces of curves and surfaces
15//! - **Namespace/Capabilities**: ShaperOS integration via geometric access control
16//! - **Phantom Types**: Compile-time verification of mathematical properties
17//!
18//! ## Usage
19//!
20//! ```rust
21//! use amari_enumerative::{ProjectiveSpace, ChowClass, IntersectionRing};
22//!
23//! // Create projective 2-space
24//! let p2 = ProjectiveSpace::new(2);
25//!
26//! // Define two curves
27//! let cubic = ChowClass::hypersurface(3);
28//! let quartic = ChowClass::hypersurface(4);
29//!
30//! // Compute intersection number (Bezout's theorem)
31//! let intersection = p2.intersect(&cubic, &quartic);
32//! assert_eq!(intersection.multiplicity(), 12); // 3 * 4 = 12
33//! ```
34//!
35//! ## Schubert Calculus Example
36//!
37//! ```rust
38//! use amari_enumerative::{SchubertCalculus, SchubertClass, IntersectionResult};
39//!
40//! // How many lines meet 4 general lines in projective 3-space?
41//! let mut calc = SchubertCalculus::new((2, 4)); // Gr(2,4)
42//! let sigma_1 = SchubertClass::new(vec![1], (2, 4)).unwrap();
43//!
44//! let classes = vec![sigma_1.clone(), sigma_1.clone(), sigma_1.clone(), sigma_1.clone()];
45//! let result = calc.multi_intersect(&classes);
46//!
47//! assert_eq!(result, IntersectionResult::Finite(2)); // Answer: 2 lines!
48//! ```
49//!
50//! ## Phantom Types for Compile-Time Verification
51//!
52//! The crate provides zero-cost phantom types for compile-time verification:
53//!
54//! - `ValidPartition` / `UnvalidatedPartition`: Partition validity states
55//! - `Semistandard` / `LatticeWord`: Tableau property markers
56//! - `Granted` / `Pending` / `Revoked`: Capability grant states
57//! - `Transverse` / `Excess` / `Deficient`: Intersection dimension states
58//! - `FitsInBox` / `UnverifiedBox`: Grassmannian containment states
59
60#[cfg(test)]
61pub mod comprehensive_tests;
62pub mod verified_contracts;
63
64pub mod geometric_algebra;
65pub mod gromov_witten;
66pub mod higher_genus;
67pub mod intersection;
68pub mod littlewood_richardson;
69pub mod moduli_space;
70pub mod namespace;
71pub mod performance;
72pub mod phantom;
73pub mod schubert;
74pub mod tropical_curves;
75
76#[cfg(feature = "tropical-schubert")]
77pub mod tropical_schubert;
78
79// Re-export core types
80pub use geometric_algebra::{
81    quantum_k_theory, signatures, GeometricProjectiveSpace, GeometricSchubertClass,
82    GeometricVariety,
83};
84pub use gromov_witten::{CurveClass as GWCurveClass, GromovWittenInvariant, QuantumCohomology};
85pub use higher_genus::{
86    AdvancedCurveCounting, DTInvariant, HigherGenusCurve, JacobianData, PTInvariant,
87};
88pub use intersection::{
89    AlgebraicVariety, ChowClass, Constraint, Grassmannian, IntersectionNumber, IntersectionPoint,
90    IntersectionRing, MockMultivector, ProjectiveSpace, QuantumProduct,
91};
92pub use moduli_space::{CurveClass, ModuliSpace, TautologicalClass};
93pub use performance::{
94    CurveBatchProcessor, FastIntersectionComputer, MemoryPool, SparseSchubertMatrix,
95    WasmPerformanceConfig,
96};
97
98// Schubert calculus exports
99pub use schubert::{FlagVariety, IntersectionResult, SchubertCalculus, SchubertClass};
100
101// Littlewood-Richardson exports
102pub use littlewood_richardson::{
103    lr_coefficient, schubert_product, Partition, SkewShape, SkewTableau,
104};
105
106// Parallel batch operations (when parallel feature is enabled)
107#[cfg(feature = "parallel")]
108pub use littlewood_richardson::lr_coefficients_batch;
109#[cfg(feature = "parallel")]
110pub use namespace::{
111    capability_accessible_batch, count_configurations_batch, namespace_intersection_batch,
112};
113#[cfg(feature = "parallel")]
114pub use schubert::multi_intersect_batch;
115
116// Namespace exports for ShaperOS
117pub use namespace::{
118    capability_accessible, namespace_intersection, Capability, CapabilityId, Namespace,
119    NamespaceBuilder, NamespaceError, NamespaceIntersection,
120};
121
122// Tropical curves
123pub use tropical_curves::{
124    TropicalCurve, TropicalEdge, TropicalIntersection, TropicalModuliSpace, TropicalPoint,
125};
126
127// Optional tropical Schubert exports
128#[cfg(all(feature = "tropical-schubert", feature = "parallel"))]
129pub use tropical_schubert::{tropical_convexity_batch, tropical_intersection_batch};
130#[cfg(feature = "tropical-schubert")]
131pub use tropical_schubert::{
132    tropical_convexity_check, tropical_intersection_count, TropicalResult, TropicalSchubertClass,
133};
134
135// Phantom types for compile-time verification
136pub use phantom::{
137    // Box containment
138    BoxContainment,
139    Deficient,
140    Excess,
141    FitsInBox,
142    // Grant states
143    GrantState,
144    Granted,
145    // Intersection dimension
146    IntersectionDimension,
147    LatticeWord,
148    // Partition validity
149    PartitionValidity,
150    Pending,
151    // Properties wrapper
152    Properties,
153    Revoked,
154    Semistandard,
155    // Tableau validity
156    TableauValidity,
157    Transverse,
158    UnknownDimension,
159    UnvalidatedPartition,
160    UnverifiedBox,
161    UnverifiedTableau,
162    // Type aliases
163    ValidLRTableau,
164    ValidPartition,
165    ValidSchubertClass,
166};
167
168use thiserror::Error;
169
170/// Error types for enumerative geometry computations
171#[derive(Error, Debug, Clone, PartialEq)]
172pub enum EnumerativeError {
173    /// Invalid dimension for the ambient space
174    #[error("Invalid dimension: {0}")]
175    InvalidDimension(String),
176
177    /// Intersection computation failed
178    #[error("Intersection error: {0}")]
179    IntersectionError(String),
180
181    /// Schubert calculus error
182    #[error("Schubert calculus error: {0}")]
183    SchubertError(String),
184
185    /// Gromov-Witten invariant computation error
186    #[error("Gromov-Witten error: {0}")]
187    GromovWittenError(String),
188
189    /// General computational error
190    #[error("Computation error: {0}")]
191    ComputationError(String),
192}
193
194/// Result type for enumerative geometry computations
195pub type EnumerativeResult<T> = Result<T, EnumerativeError>;
196
197// GPU acceleration exports