Skip to content

HMath.Matrix.LU

Module index · Numerical conventions

Description

Dense real LU factorization with partial row pivoting. This pure reference implementation accepts RealFloat scalars (including Float and Double). It reuses the existing row-major Matrix API and requires no native backend.

The factors satisfy P A = L U. Pivot acceptance uses the largest absolute entry of the original matrix as a fixed scale. The default relative tolerance is n * epsilon, where epsilon is the gap above one for the scalar type. This is a pivot-size policy, not a condition-number estimate or an accuracy guarantee. Use luDecomposeWithTolerance to select a different policy.

All coefficients and right-hand sides must be finite. Arithmetic producing NaN or infinity returns NonFiniteResult; finite rounding and underflow follow the scalar type. Existing generic matrix arithmetic is unchanged.

On this page

API Purpose
LU An immutable, reusable factorization.
luDecompose Factor a square matrix using the default relative pivot tolerance.
luDecomposeWithTolerance Factor with a finite, nonnegative relative tolerance.
luLower Unit lower-triangular factor.
luUpper Upper-triangular factor.
luPermutation Final zero-based row order: row i of P A is row luPermutation factors !! i of A.
solveLU Solve A x = b using an existing factorization.
solveMatrixLU Solve A X = B for any number of right-hand-side columns.
solve Factor A with the default tolerance and solve A x = b.
solveMatrix Factor A with the default tolerance and solve A X = B.
determinantLU Determinant from the permutation sign and diagonal of U.
determinant Determinant using the default factorization policy.
inverse Invert a nonsingular square matrix by solving against the identity.

Documentation

LU

data LU a Source #

An immutable, reusable factorization. Its constructor is hidden so solves can rely on square, finite factors with nonzero pivots and a valid permutation.

Instances

Instances details
Show a => Show (LU a) Source # 
Instance details

Defined in HMath.Matrix.LU

Methods

showsPrec :: Int -> LU a -> ShowS #

show :: LU a -> String #

showList :: [LU a] -> ShowS #

Eq a => Eq (LU a) Source # 
Instance details

Defined in HMath.Matrix.LU

Methods

(==) :: LU a -> LU a -> Bool #

(/=) :: LU a -> LU a -> Bool #

luDecompose

luDecompose :: RealFloat a => Matrix a -> Either MathError (LU a) Source #

Factor a square matrix using the default relative pivot tolerance. A 0 x 0 matrix has a successful empty factorization.

luDecomposeWithTolerance

luDecomposeWithTolerance :: RealFloat a => a -> Matrix a -> Either MathError (LU a) Source #

Factor with a finite, nonnegative relative tolerance. A zero tolerance accepts every nonzero pivot. For positive tolerance, a nonzero pivot is rejected when abs pivot / maxAbsInput <= tolerance. Exactly zero pivots return SingularMatrix; small nonzero pivots return NearSingularMatrix.

Validation order is square shape, tolerance, all coefficient finiteness, then elimination. Thus a nonfinite entry cannot be hidden by an earlier singular pivot. Row swaps include the previously computed L multipliers.

luLower

luLower :: LU a -> Matrix a Source #

Unit lower-triangular factor.

luUpper

luUpper :: LU a -> Matrix a Source #

Upper-triangular factor.

luPermutation

luPermutation :: LU a -> [Int] Source #

Final zero-based row order: row i of P A is row luPermutation factors !! i of A. This is not a sequence of swap indices.

solveLU

solveLU :: RealFloat a => LU a -> [a] -> Either MathError [a] Source #

Solve A x = b using an existing factorization. The RHS must be a finite list; its length is checked before its values. Each solve preserves the factorization for reuse.

solveMatrixLU

solveMatrixLU :: RealFloat a => LU a -> Matrix a -> Either MathError (Matrix a) Source #

Solve A X = B for any number of right-hand-side columns. Check the RHS row count before its values. An n x 0 RHS and an empty 0 x m system retain their exact shapes, without enumerating empty columns.

solve

solve :: RealFloat a => Matrix a -> [a] -> Either MathError [a] Source #

Factor A with the default tolerance and solve A x = b. Matrix validation and factorization precede RHS validation. For repeated solves or a custom tolerance, use luDecomposeWithTolerance and solveLU.

solveMatrix

solveMatrix :: RealFloat a => Matrix a -> Matrix a -> Either MathError (Matrix a) Source #

Factor A with the default tolerance and solve A X = B.

determinantLU

determinantLU :: RealFloat a => LU a -> Either MathError a Source #

Determinant from the permutation sign and diagonal of U. The finite pivots are multiplied exactly as rationals and rounded once to avoid intermediate product overflow/underflow. An unrepresentable final result returns NonFiniteResult; final underflow may produce zero and does not imply singularity. The empty determinant is one.

determinant

determinant :: RealFloat a => Matrix a -> Either MathError a Source #

Determinant using the default factorization policy. An exactly zero pivot returns zero; near-singular and nonfinite failures are propagated. Use an explicit factorization and determinantLU to choose another tolerance.

inverse

inverse :: RealFloat a => Matrix a -> Either MathError (Matrix a) Source #

Invert a nonsingular square matrix by solving against the identity. The inverse of the 0 x 0 matrix is 0 x 0. For solving a system directly, prefer solve or solveMatrix to explicitly forming the inverse.