#![deny(missing_docs)]
#![warn(unused_extern_crates)]
#![warn(clippy::all)]
pub mod cache;
pub mod cohomology;
pub mod curvature;
pub mod gauge;
pub mod hidden_dimensions;
pub mod holonomy;
pub mod kdtree;
pub mod manifold;
pub mod percolation;
pub mod quantizer;
pub mod simd;
pub mod tile;
pub mod csp;
pub mod ac3;
pub mod backtracking;
pub mod cdcl;
pub mod puzzle;
pub mod sudoku;
#[cfg(test)]
mod edge_case_tests;
pub use cache::{CachedLattice, LatticeCache, global_cache, clear_global_cache};
pub use curvature::{ricci_flow_step, RicciFlow};
pub use hidden_dimensions::{
hidden_dim_count, holographic_accuracy, lift_to_hidden, precision_from_hidden_dims,
project_to_visible, HiddenDimensionConfig,
};
pub use holonomy::{compute_holonomy, verify_holonomy, HolonomyChecker, HolonomyResult};
pub use manifold::{snap, PythagoreanManifold, PythagoreanTriple};
pub use percolation::{FastPercolation, RigidityResult};
pub use quantizer::{PythagoreanQuantizer, QuantizationMode, QuantizationResult, Rational};
pub use tile::{ConstraintBlock, Origin, Tile};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CTErr {
InvalidDimension,
ManifoldEmpty,
NumericalInstability,
ZeroVector,
NaNInput,
InfinityInput,
BufferSizeMismatch,
Overflow,
DivisionByZero,
InvalidDensity,
InvalidThreshold,
}
impl std::fmt::Display for CTErr {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::InvalidDimension => write!(f, "Invalid input dimension - expected 2D vector. Provide input as [x, y] where both are finite numbers."),
Self::ManifoldEmpty => write!(f, "Manifold is empty - initialize with new() before performing operations."),
Self::NumericalInstability => write!(f, "Numerical instability detected - input values may cause precision loss. Consider normalizing input vectors."),
Self::ZeroVector => write!(f, "Input vector is zero length - cannot normalize. Provide a non-zero vector [x, y]."),
Self::NaNInput => write!(f, "Input contains NaN values. Ensure all input values are valid numbers."),
Self::InfinityInput => write!(f, "Input contains Infinity values. Ensure all input values are finite."),
Self::BufferSizeMismatch => write!(f, "Input and output buffers have different lengths. Ensure buffers are pre-allocated with matching sizes."),
Self::Overflow => write!(f, "Numerical overflow detected - computed value exceeds f32::MAX. Consider scaling down input values."),
Self::DivisionByZero => write!(f, "Division by zero attempted - this is an internal error. Please report this issue."),
Self::InvalidDensity => write!(f, "Invalid density parameter - must be a positive integer. Recommended range: 50-500."),
Self::InvalidThreshold => write!(f, "Invalid threshold - must be between 0.0 and 1.0 inclusive."),
}
}
}
impl std::error::Error for CTErr {}
pub type CTResult<T> = Result<T, CTErr>;
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub const VERSION_MAJOR: usize = 1;
pub const VERSION_MINOR: usize = 0;
pub const VERSION_PATCH: usize = 1;
pub fn hidden_dimensions(epsilon: f32) -> usize {
if epsilon <= 0.0 {
return usize::MAX;
}
(1.0 / epsilon).log2().ceil() as usize
}
pub fn max_angular_error_for_states(state_count: usize) -> f32 {
if state_count == 0 {
return std::f32::consts::PI;
}
std::f32::consts::PI / state_count as f32
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_snap_accuracy() {
let manifold = PythagoreanManifold::new(200);
let vec = [0.6f32, 0.8];
let (snapped, noise) = snap(&manifold, vec);
assert!(noise < 0.001, "Noise should be near zero for exact triple");
assert!((snapped[0] - 0.6).abs() < 0.01);
assert!((snapped[1] - 0.8).abs() < 0.01);
}
#[test]
fn test_version() {
assert!(!VERSION.is_empty());
assert_eq!(VERSION_MAJOR, 1);
assert_eq!(VERSION_MINOR, 0);
assert_eq!(VERSION_PATCH, 1);
}
#[test]
fn test_hidden_dimensions() {
assert_eq!(hidden_dimensions(0.1), 4);
assert_eq!(hidden_dimensions(0.01), 7);
assert_eq!(hidden_dimensions(0.001), 10);
assert_eq!(hidden_dimensions(0.0001), 14);
}
#[test]
fn test_max_angular_error() {
let error = max_angular_error_for_states(1000);
assert!(error > 0.0);
assert!(error < 0.01); }
#[test]
fn test_cterr_display() {
assert!(!CTErr::InvalidDimension.to_string().is_empty());
assert!(!CTErr::ManifoldEmpty.to_string().is_empty());
assert!(!CTErr::NumericalInstability.to_string().is_empty());
assert!(!CTErr::ZeroVector.to_string().is_empty());
assert!(!CTErr::NaNInput.to_string().is_empty());
assert!(!CTErr::InfinityInput.to_string().is_empty());
assert!(!CTErr::BufferSizeMismatch.to_string().is_empty());
assert!(!CTErr::Overflow.to_string().is_empty());
assert!(!CTErr::DivisionByZero.to_string().is_empty());
assert!(!CTErr::InvalidDensity.to_string().is_empty());
assert!(!CTErr::InvalidThreshold.to_string().is_empty());
}
#[test]
fn test_cterr_actionable_messages() {
let zero_msg = CTErr::ZeroVector.to_string();
assert!(zero_msg.contains("Provide"), "Error message should suggest action");
let nan_msg = CTErr::NaNInput.to_string();
assert!(nan_msg.contains("Ensure"), "Error message should suggest action");
let density_msg = CTErr::InvalidDensity.to_string();
assert!(density_msg.contains("Recommended"), "Error message should provide guidance");
}
}