@@ -32,6 +32,7 @@ while keeping the API intentionally small and explicit.
3232- ✅ ` const fn ` where possible (compile-time evaluation of determinants, dot products, etc.)
3333- ✅ Explicit algorithms (LU, solve, determinant)
3434- ✅ Robust geometric predicates via optional exact arithmetic (` det_sign_exact ` , ` det_errbound ` )
35+ - ✅ Exact linear system solve via optional arbitrary-precision arithmetic (` solve_exact ` , ` solve_exact_f64 ` )
3536- ✅ No runtime dependencies by default (optional features may add deps)
3637- ✅ Stack storage only (no heap allocation in core types)
3738- ✅ ` unsafe ` forbidden
@@ -46,9 +47,9 @@ See [CHANGELOG.md](CHANGELOG.md) for details.
4647
4748## 🔢 Scalar types
4849
49- Today, the core types are implemented for ` f64 ` . The intent is to support ` f32 ` and ` f64 `
50- (and ` f128 ` if/when Rust gains a stable primitive for it). Arbitrary -precision arithmetic
51- is available via the optional ` "exact" ` feature (see below).
50+ The core types use ` f64 ` . When f64 precision is insufficient (e.g. near-degenerate
51+ geometric configurations), the optional ` "exact" ` feature provides arbitrary -precision
52+ arithmetic via ` BigRational ` (see below).
5253
5354## 🚀 Quickstart
5455
@@ -136,22 +137,30 @@ for D ≤ 4 and falls back to LU for D ≥ 5 — no API change needed.
136137## 🔬 Exact arithmetic (` "exact" ` feature)
137138
138139The default build has ** zero runtime dependencies** . Enable the optional
139- ` exact ` Cargo feature to add exact determinant methods using adaptive -precision
140- arithmetic (this pulls in ` num-bigint ` , ` num-rational ` , and ` num-traits ` for
140+ ` exact ` Cargo feature to add exact arithmetic methods using arbitrary -precision
141+ rationals (this pulls in ` num-bigint ` , ` num-rational ` , and ` num-traits ` for
141142` BigRational ` ):
142143
143144``` toml
144145[dependencies ]
145146la-stack = { version = " 0.2.2" , features = [" exact" ] }
146147```
147148
149+ ** Determinants:**
150+
148151- ** ` det_exact() ` ** — returns the exact determinant as a ` BigRational `
149152- ** ` det_exact_f64() ` ** — returns the exact determinant converted to the nearest ` f64 `
150153- ** ` det_sign_exact() ` ** — returns the provably correct sign (−1, 0, or +1)
151154
155+ ** Linear system solve:**
156+
157+ - ** ` solve_exact(b) ` ** — solves ` Ax = b ` exactly, returning ` [BigRational; D] `
158+ - ** ` solve_exact_f64(b) ` ** — solves ` Ax = b ` exactly, converting the result to ` Vector<D> ` (f64)
159+
152160``` rust,ignore
153161use la_stack::prelude::*;
154162
163+ // Exact determinant
155164let m = Matrix::<3>::from_rows([
156165 [1.0, 2.0, 3.0],
157166 [4.0, 5.0, 6.0],
@@ -161,6 +170,13 @@ assert_eq!(m.det_sign_exact().unwrap(), 0); // exactly singular
161170
162171let det = m.det_exact().unwrap();
163172assert_eq!(det, BigRational::from_integer(0.into())); // exact zero
173+
174+ // Exact linear system solve
175+ let a = Matrix::<2>::from_rows([[1.0, 2.0], [3.0, 4.0]]);
176+ let b = Vector::<2>::new([5.0, 11.0]);
177+ let x = a.solve_exact_f64(b).unwrap().into_array();
178+ assert!((x[0] - 1.0).abs() <= f64::EPSILON);
179+ assert!((x[1] - 2.0).abs() <= f64::EPSILON);
164180```
165181
166182` BigRational ` is re-exported from the crate root and prelude when the ` exact `
@@ -204,11 +220,14 @@ exposed for advanced use cases.
204220| Type | Storage | Purpose | Key methods |
205221| ---| ---| ---| ---|
206222| ` Vector<D> ` | ` [f64; D] ` | Fixed-length vector | ` new ` , ` zero ` , ` dot ` , ` norm2_sq ` |
207- | ` Matrix<D> ` | ` [[f64; D]; D] ` | Square matrix | ` lu ` , ` ldlt ` , ` det ` , ` det_direct ` , ` det_errbound ` , ` det_exact ` ¹, ` det_exact_f64 ` ¹, ` det_sign_exact ` ¹ |
223+ | ` Matrix<D> ` | ` [[f64; D]; D] ` | Square matrix | See below |
208224| ` Lu<D> ` | ` Matrix<D> ` + pivot array | Factorization for solves/det | ` solve_vec ` , ` det ` |
209225| ` Ldlt<D> ` | ` Matrix<D> ` | Factorization for symmetric SPD/PSD solves/det | ` solve_vec ` , ` det ` |
210226
211- Storage shown above reflects the current ` f64 ` implementation.
227+ Storage shown above reflects the ` f64 ` implementation.
228+
229+ ` Matrix<D> ` key methods: ` lu ` , ` ldlt ` , ` det ` , ` det_direct ` , ` det_errbound ` ,
230+ ` det_exact ` ¹, ` det_exact_f64 ` ¹, ` det_sign_exact ` ¹, ` solve_exact ` ¹, ` solve_exact_f64 ` ¹.
212231
213232¹ Requires ` features = ["exact"] ` .
214233
@@ -218,18 +237,22 @@ The `examples/` directory contains small, runnable programs:
218237
219238- ** ` solve_5x5 ` ** — solve a 5×5 system via LU with partial pivoting
220239- ** ` det_5x5 ` ** — determinant of a 5×5 matrix via LU
240+ - ** ` ldlt_solve_3x3 ` ** — solve a 3×3 symmetric positive definite system via LDLT
221241- ** ` const_det_4x4 ` ** — compile-time 4×4 determinant via ` det_direct() `
222242- ** ` exact_det_3x3 ` ** — exact determinant value of a near-singular 3×3 matrix (requires ` exact ` feature)
223243- ** ` exact_sign_3x3 ` ** — exact determinant sign of a near-singular 3×3 matrix (requires ` exact ` feature)
244+ - ** ` exact_solve_3x3 ` ** — exact solve of a near-singular 3×3 system vs f64 LU (requires ` exact ` feature)
224245
225246``` bash
226247just examples
227248# or individually:
228249cargo run --example solve_5x5
229250cargo run --example det_5x5
251+ cargo run --example ldlt_solve_3x3
230252cargo run --example const_det_4x4
231253cargo run --features exact --example exact_det_3x3
232254cargo run --features exact --example exact_sign_3x3
255+ cargo run --features exact --example exact_solve_3x3
233256```
234257
235258## 🤝 Contributing
0 commit comments