Linear algebra
Decompositions, derived quantities, and matrix functions over FixedMatrix, each
chained at the wide compute tier.
What it is
Three modules build on FixedMatrix: decompose
(factorizations and the solvers built on them), derived (norms, inverses,
condition numbers, least squares), and matrix_functions (exp, log, sqrt,
pow of a matrix). Operation chains run through a ComputeMatrix at tier N+1 so
the whole chain rounds once at the end rather than once per intermediate.
Usage
use g_math::fixed_point::{FixedMatrix, FixedVector, Q64_64};
use g_math::fixed_point::imperative::decompose;
let a = FixedMatrix::from_slice(2, 2, &[
Q64_64::from_int(4), Q64_64::from_int(3),
Q64_64::from_int(6), Q64_64::from_int(3),
]);
let lu = decompose::lu_decompose(&a).unwrap(); // Doolittle, partial pivoting
let b = FixedVector::from_slice(&[Q64_64::from_int(1), Q64_64::from_int(2)]);
let x = lu.solve(&b).unwrap(); // solve A x = b
let det = lu.determinant();
What's here
- Decompositions (
decompose): LU (Doolittle, partial pivoting), QR (Householder), Cholesky, SVD (Golub-Kahan), symmetric eigenvalues (Jacobi), Schur (Francis QR). Each returns a struct exposingsolve/determinant/inversewhere applicable, plus iterative refinement on LU. - Derived (
derived):frobenius_norm,norm_1,norm_inf,solve,solve_spd,determinant,inverse,inverse_spd,pseudoinverse,rank,nullspace,least_squares,condition_number_1/_2. - Matrix functions (
matrix_functions):matrix_exp(Padé + scaling-and-squaring),matrix_sqrt(Denman-Beavers),matrix_log(inverse scaling-and-squaring),matrix_pow: all chained throughComputeMatrix(on the 32-bit formats through a Q64.64 matrix, since their compute tier holds only2Fbits), one rounding per output entry. Against mpmath they are correctly rounded at every format and at the 32-bit splits from 8 to 24 fraction bits, including norms up to 7 and SPD spectra from 1/8 to 60. - Walsh-Hadamard transform (
hadamard, 0.7.6):walsh_hadamard_in_placeand the block-diagonalwalsh_hadamard_blocks_in_placeon any integer word, exact (additions and subtractions only); the1 / sqrt(n)normalisation is left to the caller's rounding (an exact shift for powers of four). A result past the word isTierOverflow, the input unchanged.
Public API
See PUBLIC_API.md → Linear algebra and docs.rs.
Behaviour & limits
- Solver and factor accuracy is validated against mpmath references combined with structural checks (PA=LU, QᵀQ=I, exp/log roundtrips).
- Error in a solved system scales with the condition number of the matrix. An ill-conditioned system (e.g. a Hilbert matrix) amplifies input error by orders of magnitude in any finite precision; iterative refinement recovers the residual but not the lost input information. See the precision guide.
- LU, Cholesky and QR factor at the compute tier (
2Ffractional bits) and keep those factors:solve,inverse,determinantandrefinerun on them, every sum exact, and round the result once. The publicl,u,q,rfields are the same factors rounded once, for inspection. Against exact rationals and mpmath on well-conditioned 2x2 to 4x4 systems, factors, solutions, inverses and determinants are within one unit at every format and at the 32-bit splits from 8 to 24 fraction bits (0.6.3 stored the factors at storage precision: up to 114 units in a solve, 70 in a determinant). On an ill-conditioned system the error before the final rounding grows askappa * 2^-2F, so a solve stays within a unit whilekappais well below2^F. - The iterative decompositions (
svd_decompose,eigen_symmetric,schur_decompose) carry the matrix being reduced and the accumulated transforms at the compute tier and round them to storage once. They either converge or return an error, never a partially converged result:Err(PrecisionLimit)when the iteration budget runs out,Err(TierOverflow)when a norm or an entry leaves the range. An off-diagonal entry counts as zero within2^-(3F/2)of its diagonal neighbours (2^-17at least on the 32-bit formats withF < 16), never below2^-(3F/2)absolute, so exactly rank-deficient matrices converge. Rotation and reflection coefficients carry the compute tier's2Ffraction bits, or 48 on the 32-bit formats withF < 16, where2Fwould be coarser than the entries they rotate (before 0.7.1: 129 units at Q22.10 on entries of2^17). Against mpmath on well-separated spectra, eigenvalues and eigenvectors, singular values and vectors, and Schur eigenvalues are within one unit at every format and split (0.6.3 converged to2^-(2F/3): up to 1483 units at Q16.16 and past2^30units at the wide formats). A Schur eigenvalue's error is still the deflation bound times the eigenvalue's condition number, and a vector of a nearly repeated eigen- or singular value is only as well determined as the gap allows. On matrices whose entries span many orders of magnitude the compute tier's own2^-2Fis amplified by that spread: aboutkappa 2^-Funits, one unit at Q22.10 on entries2^10apart.schur_decomposereturns a real Schur form: exact zeros below the subdiagonal, and 2×2 blocks only for complex pairs, decided on the returned values (0.7.0 decided on the compute-tier values, and rounding to storage could make a block at a defective eigenvalue read real). Gate:tests/decomposition_convergence_validation.rs, 38 fixed cases plus a seeded random corpus from the same failure classes (rank-deficient, interior zero diagonals, rectangular, scaled and small entries, repeated spectra, signed permutations, hidden complex pairs, companion matrices); CI draws a fresh seed weekly.
Determinism guarantees are in CONTRACT.md.
Disclaimer
This software is provided "as is", without warranty of any kind, express or implied. Use of this software is entirely at your own risk. In no event shall the author or contributors be held liable for any damages arising from the use or inability to use this software.
Built by Niels Erik Toren · support & donations.