Skip to main content

hyperlattice/
lib.rs

1//! Real-centered linear algebra primitives backed by exact hyperreal arithmetic.
2//!
3//! `hyperlattice` exposes complex numbers, 2D/3D/4D vectors, and 3x3/4x4
4//! matrices whose coordinate and scalar type is [`Real`]. Primitive
5//! floating-point values are supported only at API edges: finite `f32`/`f64`
6//! inputs are lifted through checked [`Real`] constructors, and
7//! [`Real::to_f64_lossy`] provides a named lossy export for rendering, IO, and
8//! other external libraries.
9//!
10//! Most arithmetic that can fail returns [`BlasResult`]. Checked APIs use
11//! [`ZeroStatus`] and reject both definite zero and unknown-zero divisors,
12//! returning [`Problem::UnknownZero`] for the latter.
13//!
14//! Exactness is carried as conservative structure, not by eagerly
15//! canonicalizing every coordinate after every vector or matrix operation.
16//! Following Yap's exact geometric computation model, lattice-owned facts such
17//! as sparsity, shared scales, determinant schedules, and transform kinds are
18//! non-certifying scheduling metadata until an exact `Real` or predicate route
19//! consumes them. See Yap, "Towards Exact Geometric Computation,"
20//! *Computational Geometry*, 1997, pp. 3-23.
21//!
22//! # Examples
23//!
24//! ```
25//! use hyperlattice::{Matrix3, Real, Vector3, sqrt};
26//!
27//! fn r(value: i32) -> Real {
28//!     value.into()
29//! }
30//!
31//! let v = Vector3::new([r(3), r(4), r(0)]);
32//! assert_eq!(v.dot(&v), r(25));
33//! assert_eq!(sqrt(v.dot(&v)).unwrap(), r(5));
34//!
35//! let identity = Matrix3::identity();
36//! assert_eq!(identity * v.clone(), v);
37//! ```
38
39#![warn(missing_docs)]
40
41pub use hyperreal::{
42    DomainFacts as RealDomainFacts, DomainStatus as RealDomainStatus,
43    ExpressionDegree as RealExpressionDegree, MagnitudeBits as RealMagnitudeBits, Rational,
44    RationalStorageClass, Real, RealExactSetDenominatorKind, RealExactSetDyadicExponentClass,
45    RealExactSetSignPattern, RealSign, RealStructuralFacts as RealFacts,
46    SymbolicDependencyMask as RealSymbolicDependencyMask, ZeroKnowledge as ZeroStatus,
47    ZeroOneMinusOneStatus as RealZeroOneMinusOneStatus,
48};
49
50mod trace;
51pub(crate) use trace::trace_dispatch;
52
53mod error;
54pub use error::{AbortSignal, BlasResult, CheckedBlasResult, Problem};
55
56mod kernels;
57pub use kernels::ExactRealSetFacts;
58pub(crate) use kernels::{ExactRationalKind, RealKernelExt};
59
60mod algebra2;
61pub use algebra2::{
62    Displacement2Facts, Orient2Facts, ProductSum2Facts, ProductTerm2Facts, displacement2,
63    displacement2_facts, dot2, orient2_expr, orient2_expr_facts, positive_product_sum2,
64    product_sum2_facts, product_term2_facts, signed_product_sum2, squared_distance2, squared_norm2,
65    wedge2,
66};
67
68mod scalar;
69pub use scalar::{
70    acos, acos_with_abort, acosh, acosh_with_abort, asin, asin_with_abort, asinh, asinh_with_abort,
71    atan, atan_with_abort, atanh, atanh_with_abort, cos, cosh, e, exp, i, ln, log10,
72    log10_with_abort, one, pi, pow, powi, reciprocal, reciprocal_checked,
73    reciprocal_checked_with_abort, reciprocal_ref, reciprocal_ref_checked, sin, sinh, sqrt, tan,
74    tanh, tau, zero, zero_status, zero_status_with_abort,
75};
76
77mod complex;
78pub use complex::Complex;
79
80mod vector;
81pub use vector::{
82    Axis2, SharedScaleVec, SignedAxis2, Vector2, Vector2Facts, Vector3, Vector3Facts, Vector4,
83    Vector4Facts, Vector4HomogeneousKind, VectorSharedScaleFacts, VectorSharedScaleView,
84};
85
86mod point;
87pub use point::{
88    Point2, Point2Facts, Point3, Point3Facts, PointSharedScaleFacts, PointSharedScaleView,
89};
90
91mod aabb;
92pub use aabb::Aabb;
93
94mod projective;
95pub use projective::{
96    HomogeneousLine3, HomogeneousPoint3, Plane3Coefficients, ProjectivePlane3,
97    homogeneous_point_plane_expression, intersect_homogeneous_line_plane, intersect_three_planes,
98    intersect_two_planes,
99};
100
101mod matrix;
102pub use matrix::{
103    Matrix3, Matrix3StructuralFacts, Matrix3TransformKind, Matrix4, Matrix4StructuralFacts,
104    Matrix4TransformKind, MatrixDeterminantScheduleHint, MatrixPreparedCacheState, PreparedMatrix3,
105    PreparedMatrix4, PreparedRightDivisor3, PreparedRightDivisor4, SignedAxis4,
106};
107
108#[cfg(feature = "arbitrary")]
109mod arbitrary_impls;