tuppu_scalar/lib.rs
1//! Exact scalar arithmetic with uncertainty tracking.
2//!
3//! This crate provides the [`Scalar`] type which combines:
4//! - [`SymbolicExpr`]: Exact symbolic representation in Q(√2,√3,√5)[π,e]
5//! - [`Ball`]: Interval arithmetic for uncertainty tracking
6//!
7//! # Architecture
8//!
9//! ```text
10//! Scalar = SymbolicExpr + Option<Ball>
11//! ↓ ↓
12//! Exact symbolic Lazy numerical
13//! computation bounds
14//! ```
15//!
16//! # Key Types
17//!
18//! - [`Rational`]: Arbitrary-precision rationals with GCD overflow protection
19//! - [`BasisElement`]: Algebraic basis {1, √2, √3, √5, √6, √10, √15, √30} × {1, π, e, πe, ...}
20//! - [`SymbolicExpr`]: Sparse linear combination of basis elements
21//! - [`Ball`]: Interval [center - radius, center + radius]
22//! - [`Scalar`]: The unified type combining symbolic + ball
23//!
24//! # Example
25//!
26//! ```
27//! use tuppu_scalar::{Scalar, SymbolicExpr};
28//!
29//! // Create exact values
30//! let half = Scalar::from_ratio(1, 2);
31//! let sqrt2 = Scalar::sqrt2();
32//! let pi = Scalar::pi();
33//!
34//! // Arithmetic preserves exactness
35//! let cos_45 = sqrt2.mul(&half); // √2/2 exactly
36//!
37//! // Get numerical approximation when needed
38//! assert!((cos_45.to_f64() - 0.7071067811865476).abs() < 1e-10);
39//! ```
40
41#![warn(missing_docs)]
42#![warn(clippy::all)]
43
44pub mod rational;
45pub mod ball;
46pub mod basis;
47pub mod symbolic;
48pub mod identity;
49pub mod scalar;
50pub mod traits;
51pub mod error;
52pub mod unit;
53
54pub use rational::Rational;
55pub use ball::Ball;
56pub use basis::BasisElement;
57pub use symbolic::SymbolicExpr;
58pub use scalar::Scalar;
59pub use traits::{ScalarValue, MultivectorValue};
60pub use error::MathError;