| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Circuit.Mat.Dense
Description
Value-sized dense matrices backed by Array.
This module provides the canonical dense-matrix carrier for numhask-based
computation: Kleene star (reflexive-transitive closure), matrix
multiplication, and matrix-vector products. It is intentionally rank-2 and
value-sized so it can serve categories whose object constraints live at
runtime (e.g. Finite enumeration or plain list channels) as
well as typed settings.
Moved from harpie-numhask as part of the matrix-calculus extraction into
circuits-mat.
Synopsis
- newtype Matrix a = Matrix {}
- fromLists :: [[a]] -> Matrix a
- toLists :: Matrix a -> [[a]]
- matPlus :: Additive a => Matrix a -> Matrix a -> Matrix a
- matTimes :: (Additive a, Multiplicative a) => Matrix a -> Matrix a -> Matrix a
- matVec :: (Additive a, Multiplicative a) => Matrix a -> [a] -> [a]
- starMatrix :: StarSemiring a => Matrix a -> Matrix a
- qrM :: (ExpField a, Ord a) => Matrix a -> (Matrix a, Matrix a)
- forwardSubstStream :: (Subtractive a, Multiplicative a) => Array a -> Array a -> Array a
- solve2 :: [[Double]] -> [Double] -> [Double]
Documentation
Square matrix stored as a rank-2 Array in row-major order.
fromLists :: [[a]] -> Matrix a Source #
Build a matrix from nested rows.
An empty list becomes a 0×0 matrix.
matTimes :: (Additive a, Multiplicative a) => Matrix a -> Matrix a -> Matrix a Source #
Matrix multiplication.
starMatrix :: StarSemiring a => Matrix a -> Matrix a Source #
Kleene star of a square matrix by the standard state-elimination (Warshall / Floyd-Kleene) algorithm.
For a matrix A, computes A* = I + A + A² + ... as the least fixed
point of X ↦ I + A·X. Requires a StarSemiring element type so that
star x is available for the pivot updates.
When the element type is a Quantale, this is the
join of the geometric series I + A + A² + …; the algorithm uses the
StarSemiring fragment (iterative joins) to compute it finitely.
qrM :: (ExpField a, Ord a) => Matrix a -> (Matrix a, Matrix a) Source #
QR decomposition via Householder reflections.
Returns (q, r) with q orthogonal and r upper triangular such that
a = q r. The algorithm is the standard column-by-column Householder
reduction on value-sized Array matrices.
forwardSubstStream :: (Subtractive a, Multiplicative a) => Array a -> Array a -> Array a Source #
Forward substitution as a stream morphism.
Solves L y = b for unit lower-triangular L by streaming rows of L and
components of b, accumulating y one component at a time. Each step is a
dot product of the already-computed prefix of y with the active row prefix
of L, followed by subtraction from the current b component.