linear-code-0.1.1: A simple library for linear codes (coding theory, error correction)

Copyright(c) Wanja Chresta 2018
LicenseGPL-3
Maintainerwanja dot hs at chrummibei dot ch
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Math.Algebra.Matrix

Description

Math.Algebra.Matrix wraps matrix's Data.Matrix functions and adds size information on the type level. Additionally, it fixes some issues that makes the library work well with finite fields. The name of most functions is the same as in Data.Matrix

Synopsis

Documentation

newtype Matrix (m :: Nat) (n :: Nat) (f :: *) Source #

A matrix over the type f with m rows and n columns. This just wraps the Matrix constructor and adds size information to the type

Constructors

Matrix (Matrix f) 

Instances

Functor (Matrix m n) Source # 

Methods

fmap :: (a -> b) -> Matrix m n a -> Matrix m n b #

(<$) :: a -> Matrix m n b -> Matrix m n a #

Applicative (Matrix m n) Source # 

Methods

pure :: a -> Matrix m n a #

(<*>) :: Matrix m n (a -> b) -> Matrix m n a -> Matrix m n b #

liftA2 :: (a -> b -> c) -> Matrix m n a -> Matrix m n b -> Matrix m n c #

(*>) :: Matrix m n a -> Matrix m n b -> Matrix m n b #

(<*) :: Matrix m n a -> Matrix m n b -> Matrix m n a #

Foldable (Matrix m n) Source # 

Methods

fold :: Monoid m => Matrix m n m -> m #

foldMap :: Monoid m => (a -> m) -> Matrix m n a -> m #

foldr :: (a -> b -> b) -> b -> Matrix m n a -> b #

foldr' :: (a -> b -> b) -> b -> Matrix m n a -> b #

foldl :: (b -> a -> b) -> b -> Matrix m n a -> b #

foldl' :: (b -> a -> b) -> b -> Matrix m n a -> b #

foldr1 :: (a -> a -> a) -> Matrix m n a -> a #

foldl1 :: (a -> a -> a) -> Matrix m n a -> a #

toList :: Matrix m n a -> [a] #

null :: Matrix m n a -> Bool #

length :: Matrix m n a -> Int #

elem :: Eq a => a -> Matrix m n a -> Bool #

maximum :: Ord a => Matrix m n a -> a #

minimum :: Ord a => Matrix m n a -> a #

sum :: Num a => Matrix m n a -> a #

product :: Num a => Matrix m n a -> a #

Traversable (Matrix m n) Source # 

Methods

traverse :: Applicative f => (a -> f b) -> Matrix m n a -> f (Matrix m n b) #

sequenceA :: Applicative f => Matrix m n (f a) -> f (Matrix m n a) #

mapM :: Monad m => (a -> m b) -> Matrix m n a -> m (Matrix m n b) #

sequence :: Monad m => Matrix m n (m a) -> m (Matrix m n a) #

Eq f => Eq (Matrix m n f) Source # 

Methods

(==) :: Matrix m n f -> Matrix m n f -> Bool #

(/=) :: Matrix m n f -> Matrix m n f -> Bool #

Num f => Num (Matrix m n f) Source # 

Methods

(+) :: Matrix m n f -> Matrix m n f -> Matrix m n f #

(-) :: Matrix m n f -> Matrix m n f -> Matrix m n f #

(*) :: Matrix m n f -> Matrix m n f -> Matrix m n f #

negate :: Matrix m n f -> Matrix m n f #

abs :: Matrix m n f -> Matrix m n f #

signum :: Matrix m n f -> Matrix m n f #

fromInteger :: Integer -> Matrix m n f #

Ord f => Ord (Matrix m n f) Source # 

Methods

compare :: Matrix m n f -> Matrix m n f -> Ordering #

(<) :: Matrix m n f -> Matrix m n f -> Bool #

(<=) :: Matrix m n f -> Matrix m n f -> Bool #

(>) :: Matrix m n f -> Matrix m n f -> Bool #

(>=) :: Matrix m n f -> Matrix m n f -> Bool #

max :: Matrix m n f -> Matrix m n f -> Matrix m n f #

min :: Matrix m n f -> Matrix m n f -> Matrix m n f #

Show f => Show (Matrix m n f) Source # 

Methods

showsPrec :: Int -> Matrix m n f -> ShowS #

show :: Matrix m n f -> String #

showList :: [Matrix m n f] -> ShowS #

Monoid f => Monoid (Matrix m n f) Source # 

Methods

mempty :: Matrix m n f #

mappend :: Matrix m n f -> Matrix m n f -> Matrix m n f #

mconcat :: [Matrix m n f] -> Matrix m n f #

(KnownNat m, KnownNat n, Random a) => Random (Matrix m n a) Source # 

Methods

randomR :: RandomGen g => (Matrix m n a, Matrix m n a) -> g -> (Matrix m n a, g)

random :: RandomGen g => g -> (Matrix m n a, g)

randomRs :: RandomGen g => (Matrix m n a, Matrix m n a) -> g -> [Matrix m n a]

randoms :: RandomGen g => g -> [Matrix m n a]

randomRIO :: (Matrix m n a, Matrix m n a) -> IO (Matrix m n a)

randomIO :: IO (Matrix m n a)

matrix :: forall m n a. (KnownNat m, KnownNat n) => ((Int, Int) -> a) -> Matrix (m :: Nat) (n :: Nat) a Source #

O(rows*cols). Generate a matrix from a generator function. | The elements are 1-indexed, i.e. top-left element is (1,1).

type Vector = Matrix 1 Source #

A row vector (a matrix with one row).

transpose :: forall m n a. Matrix m n a -> Matrix n m a Source #

O(rows*cols). The transpose of a matrix.

(<|>) :: forall m n k a. (KnownNat n, KnownNat k) => Matrix m n a -> Matrix m k a -> Matrix m (k + n) a Source #

Horizontally join two matrices. Visually:

( A ) <|> ( B ) = ( A | B )

(<->) :: forall m k n a. (KnownNat m, KnownNat k) => Matrix m n a -> Matrix k n a -> Matrix (m + k) n a Source #

Horizontally join two matrices. Visually:

                  ( A )
( A ) <-> ( B ) = ( - )
                  ( B )

identity :: forall n a. (Num a, KnownNat n) => Matrix n n a Source #

O(rows*cols). Identity matrix

zero :: forall m n a. (Num a, KnownNat n, KnownNat m) => Matrix m n a Source #

O(rows*cols). The zero matrix

fromList :: forall m n a. (KnownNat m, KnownNat n) => [a] -> Matrix m n a Source #

Create a matrix from a list of elements. The list must have exactly length n*m. This is checked or else an exception is thrown.

fromLists :: forall m n a. (KnownNat m, KnownNat n) => [[a]] -> Matrix m n a Source #

Create a matrix from a list of rows. The list must have exactly m lists of length n. An exception is thrown otherwise.

toList :: forall m n a. Matrix m n a -> [a] Source #

Get the elements of a matrix stored in a list.

toLists :: forall m n a. Matrix m n a -> [[a]] Source #

Get the elements of a matrix stored in a list of lists, where each list contains the elements of a single row.

(.*) :: forall m k n a. Num a => Matrix m k a -> Matrix k n a -> Matrix m n a Source #

Type safe matrix multiplication

(^*) :: forall m n a. Num a => a -> Matrix m n a -> Matrix m n a Source #

Type safe scalar multiplication

rref :: forall m n a. (KnownNat m, KnownNat n, m <= n, Fractional a, Eq a) => Matrix m n a -> Matrix m n a Source #

Reduced row echelon form. Taken from rosettacode. This is not the implementation provided by the matrix package. https://rosettacode.org/wiki/Reduced_row_echelon_form#Haskell

submatrix :: forall m n m' n' a. (KnownNat m, KnownNat n, KnownNat m', KnownNat n', m' <= m, n' <= n) => Int -> Int -> Matrix m n a -> Matrix m' n' a Source #

O(1). Extract a submatrix from the given position. The size of the extract is determined by the types, i.e. the parameters define which element is the top-left element of the extract. CAUTION: It is not checked if an extract is possible. Wrong parameters will cause an exception.