HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulenumeric-prelude-0.4.4Haskell98

MathObj.Matrix

Routines and abstractions for Matrices and basic linear algebra over fields or rings.

We stick to simple Int indices. Although advanced indices would be nice e.g. for matrices with sub-matrices, this is not easily implemented since arrays do only support a lower and an upper bound but no additional parameters.

ToDo: - Matrix inverse, determinant (see htam:Matrix)

  • 2 types
  • 18 values
newtypenewtype T a
#

A matrix is a twodimensional array, indexed by integers.

Instances9Functor, Eq, Ord, Read, Show, C, …
  • Functor TDefined in numeric-prelude-0.4.4 · MathObj.Matrix
  • C TDefined in numeric-prelude-0.4.4 · MathObj.Matrix
  • C a b => C a (T b)Defined in numeric-prelude-0.4.4 · MathObj.Matrix
  • Eq a => Eq (T a)Defined in numeric-prelude-0.4.4 · MathObj.Matrix
  • Ord a => Ord (T a)Defined in numeric-prelude-0.4.4 · MathObj.Matrix
  • Read a => Read (T a)Defined in numeric-prelude-0.4.4 · MathObj.Matrix
  • Show a => Show (T a)Defined in numeric-prelude-0.4.4 · MathObj.Matrix
  • C a => C (T a)Defined in numeric-prelude-0.4.4 · MathObj.Matrix
    Property
    genIntMatrix /\ \a -> Laws.leftIdentity  (*) (Matrix.one (Matrix.numRows a)) a
    Property
    genIntMatrix /\ \a -> Laws.rightIdentity (*) (Matrix.one (Matrix.numColumns a)) a
    Property
    genIntMatrix /\ \a -> genFactorMatrix a /\ \b -> Laws.homomorphism Matrix.transpose (*) (flip (*)) a b
    Property
    genIntMatrix /\ \a -> genFactorMatrix a /\ \b -> genFactorMatrix b /\ \c -> Laws.associative (*) a b c
    Property
    genIntMatrix /\ \b -> genSameMatrix b /\ \c -> genFactorMatrix b /\ \a -> Laws.leftDistributive (*) (+) a b c
    Property
    genIntMatrix /\ \a -> genFactorMatrix a /\ \b -> genSameMatrix b /\ \c -> Laws.rightDistributive (*) (+) a b c
    Property
    QC.choose (0,10) /\ \k -> genDimension /\ \n -> genMatrixFor n n /\ \a -> a^k == nest (fromInteger k) ((a::Matrix.T Integer)*) (Matrix.one n)
  • C a => C (T a)Defined in numeric-prelude-0.4.4 · MathObj.Matrix
    Property
    genIntMatrix /\ \a -> genSameMatrix a /\ \b -> Laws.commutative (+) a b
    Property
    genIntMatrix /\ \a -> genSameMatrix a /\ \b -> genSameMatrix b /\ \c -> Laws.associative (+) a b c
valuetranspose :: T a -> T a
#

Transposition of matrices is just transposition in the sense of Data.List.

Property
genIntMatrix /\ \a -> Matrix.rows a == Matrix.columns (Matrix.transpose a)
Property
genIntMatrix /\ \a -> Matrix.columns a == Matrix.rows (Matrix.transpose a)
Property
genIntMatrix /\ \a -> genSameMatrix a /\ \b -> Laws.homomorphism Matrix.transpose (+) (+) a b
valuerows :: T a -> [[a]]
#
valuefromRows :: Dimension -> Dimension -> [[a]] -> T a
#
Property
genIntMatrix /\ \a -> a == uncurry Matrix.fromRows (Matrix.dimension a) (Matrix.rows a)
valuefromColumns :: Dimension -> Dimension -> [[a]] -> T a
#
Property
genIntMatrix /\ \a -> a == uncurry Matrix.fromColumns (Matrix.dimension a) (Matrix.columns a)
valuezipWith :: (a -> b -> c) -> T a -> T b -> T c
#
valuezero :: C a => Dimension -> Dimension -> T a
#
Property
genIntMatrix /\ \a -> Laws.identity (+) (uncurry Matrix.zero $ Matrix.dimension a) a
valuediagonal :: C a => [a] -> T a
#
Property
genDimension /\ \n -> Matrix.one n == Matrix.diagonal (replicate n Ring.one :: [Integer])