úÎÙdÔ.>      !"#$%&'()*+,-./0123456789:;<=NoneGType of matrices.`Elements can be of any type. Rows and columns are indexed starting by 1. This means that, if  m :: Matrix a and  i,j :: Int, then  m ! (i,j) is the element in the i-th row and j-th column of m.Number of rows.Number of columns.>.Number of columns of the matrix without offset?(Content of the matrix as a plain vector.@/Just a cool way to output the size of a matrix.Display a matrix as a A using the B instance of its elements. O(rows*cols) . Similar to C<. It copies the matrix content dropping any extra memory.Useful when using $ from a big matrix.jFlatten a matrix of matrices. All sub matrices must have same dimensions This criteria is not checked.  O(rows*cols)(. Map a function over a row. Example: Œ ( 1 2 3 ) ( 1 2 3 ) ( 4 5 6 ) ( 5 6 7 ) mapRow (\_ x -> x + 1) 2 ( 7 8 9 ) = ( 7 8 9 ) O(rows*cols)+. Map a function over a column. Example: Œ ( 1 2 3 ) ( 1 3 3 ) ( 4 5 6 ) ( 4 6 6 ) mapCol (\_ x -> x + 1) 2 ( 7 8 9 ) = ( 7 9 9 ) O(rows*cols)$. The zero matrix of the given size. €zero n m = m 1 ( 0 0 ... 0 0 ) 2 ( 0 0 ... 0 0 ) ( ... ) ( 0 0 ... 0 0 ) n ( 0 0 ... 0 0 )  O(rows*cols)C. Generate a matrix from a generator function. Example of usage: à ( 1 0 -1 -2 ) ( 3 2 1 0 ) ( 5 4 3 2 ) matrix 4 4 $ \(i,j) -> 2*i - j = ( 7 6 5 4 )  O(rows*cols)%. Identity matrix of the given order. ‚identity n = n 1 ( 1 0 ... 0 0 ) 2 ( 0 1 ... 0 0 ) ( ... ) ( 0 0 ... 1 0 ) n ( 0 0 ... 0 1 )  Similar to  , but using D$, which should be more efficient. ]Create a matrix from a non-empty list given the desired size. The list must have at least  rows*cols elements. An example: _ ( 1 2 3 ) ( 4 5 6 ) fromList 3 3 [1..] = ( 7 8 9 ) .Get the elements of a matrix stored in a list. H ( 1 2 3 ) ( 4 5 6 ) toList ( 7 8 9 ) = [1,2,3,4,5,6,7,8,9]qGet the elements of a matrix stored in a list of lists, where each list contains the elements of a single row. [ ( 1 2 3 ) [ [1,2,3] ( 4 5 6 ) , [4,5,6] toLists ( 7 8 9 ) = , [7,8,9] ]¥Diagonal matrix from a non-empty list given the desired size. Non-diagonal elements will be filled with the given default element. The list must have at least order elements. šdiagonalList n 0 [1..] = n 1 ( 1 0 ... 0 0 ) 2 ( 0 2 ... 0 0 ) ( ... ) ( 0 0 ... n-1 0 ) n ( 0 0 ... 0 n )=Create a matrix from a non-empty list of non-empty lists. ?Each list must have at least as many elements as the first list. Examples: hfromLists [ [1,2,3] ( 1 2 3 ) , [4,5,6] ( 4 5 6 ) , [7,8,9] ] = ( 7 8 9 ) kfromLists [ [1,2,3 ] ( 1 2 3 ) , [4,5,6,7] ( 4 5 6 ) , [8,9,0 ] ] = ( 8 9 0 )O(1)). Represent a vector as a one row matrix.O(1),. Represent a vector as a one column matrix. O(rows*cols). Permutation matrix. ÿPpermMatrix n i j = i j n 1 ( 1 0 ... 0 ... 0 ... 0 0 ) 2 ( 0 1 ... 0 ... 0 ... 0 0 ) ( ... ... ... ) i ( 0 0 ... 0 ... 1 ... 0 0 ) ( ... ... ... ) j ( 0 0 ... 1 ... 0 ... 0 0 ) ( ... ... ... ) ( 0 0 ... 0 ... 0 ... 1 0 ) n ( 0 0 ... 0 ... 0 ... 0 1 )When i == j it reduces to   n.O(1)1. Get an element of a matrix. Indices range from (1,1) to (n,m). It returns an E. if the requested element is outside of range.O(1). Unsafe variant of , without bounds checking.Short alias for .FInternal alias for . Variant of ( that returns Maybe instead of an error. Variant of ( that returns Maybe instead of an error.O(1)$. Get a row of a matrix as a vector.O(rows)'. Get a column of a matrix as a vector.O(min rows cols). Diagonal of a not necessarily square matrix. O(rows*cols). Transform a  to a D of size  rows*cols?. This is equivalent to get all the rows of the matrix using 0 and then append them, but far more efficient.(Replace the value of a cell in a matrix.Unsafe variant of , without bounds checking. O(rows*cols)(. The transpose of a matrix. Example: _ ( 1 2 3 ) ( 1 4 7 ) ( 4 5 6 ) ( 2 5 8 ) transpose ( 7 8 9 ) = ( 3 6 9 ) %O(rows*rows*rows) = O(cols*cols*cols)M. The inverse of a square matrix. Uses naive Gaussian elimination formula.!O(rows*rows*cols)ÿ¾. Converts a matrix to reduced row echelon form, thus solving a linear system of equations. This requires that (cols > rows) if cols < rows, then there are fewer variables than equations and the problem cannot be solved consistently. If rows = cols, then it is basically a homogenous system of equations, so it will be reduced to identity or an error depending on whether the marix is invertible (this case is allowed for robustness)."ŒExtend a matrix to a given size adding a default element. If the matrix already has the required size, nothing happens. The matrix is never reduced in size. Example: £ ( 1 2 3 0 0 ) ( 1 2 3 ) ( 4 5 6 0 0 ) ( 4 5 6 ) ( 7 8 9 0 0 ) extendTo 0 4 5 ( 7 8 9 ) = ( 0 0 0 0 0 )The definition of " is based on #: BextendTo e n m a = setSize e (max n $ nrows a) (max m $ ncols a) a#}Set the size of a matrix to given parameters. Use a default element for undefined entries if the matrix has been extended.$O(1)>. Extract a submatrix given row and column limits. Example: g ( 1 2 3 ) ( 4 5 6 ) ( 2 3 ) submatrix 1 2 2 3 ( 7 8 9 ) = ( 5 6 )% O(rows*cols)6. Remove a row and a column from a matrix. Example: a ( 1 2 3 ) ( 4 5 6 ) ( 1 3 ) minorMatrix 2 2 ( 7 8 9 ) = ( 7 9 )&O(1)›. Make a block-partition of a matrix using a given element as reference. The element will stay in the bottom-right corner of the top-left corner matrix. ÿq ( ) ( | ) ( ) ( ... | ... ) ( x ) ( x | ) splitBlocks i j ( ) = (-------------) , where x = a_{i,j} ( ) ( | ) ( ) ( ... | ... ) ( ) ( | )WNote that some blocks can end up empty. We use the following notation for these blocks: #( TL | TR ) (---------) ( BL | BR )/Where T = Top, B = Bottom, L = Left, R = Right.'$Join blocks of the form detailed in & . Precisely: @joinBlocks (tl,tr,bl,br) = (tl <|> tr) <-> (bl <|> br)()Horizontally join two matrices. Visually: ( A ) <|> ( B ) = ( A | B )Where both matrices A and B have the same number of rows. This condition is not checked.)'Vertically join two matrices. Visually: G ( A ) ( A ) <-> ( B ) = ( - ) ( B )Where both matrices A and B# have the same number of columns. This condition is not checked.*þPerform an operation element-wise. The second matrix must have at least as many rows and columns as the first matrix. If it's bigger, the leftover items will be ignored. If it's smaller, it will cause a run-time error. You may want to use +D if you are definitely sure that a run-time error won't arise.+Unsafe version of * , but faster.GInternal unsafe addition.HInternal unsafe substraction.,-Standard matrix multiplication by definition.--Standard matrix multiplication by definition.INStandard matrix multiplication by definition, without checking if sizes match.J3Strassen's algorithm over square matrices of order 2^n..!Strassen's matrix multiplication.KStrassen's mixed algorithm./'Mixed Strassen's matrix multiplication.0-Scale a matrix by a given factor. Example: t ( 1 2 3 ) ( 2 4 6 ) ( 4 5 6 ) ( 8 10 12 ) scaleMatrix 2 ( 7 8 9 ) = ( 14 16 18 )1*Scale a row by a given factor. Example: q ( 1 2 3 ) ( 1 2 3 ) ( 4 5 6 ) ( 8 10 12 ) scaleRow 2 2 ( 7 8 9 ) = ( 7 8 9 )2<Add to one row a scalar multiple of another row. Example: € ( 1 2 3 ) ( 1 2 3 ) ( 4 5 6 ) ( 6 9 12 ) combineRows 2 2 1 ( 7 8 9 ) = ( 7 8 9 )3(Switch two rows of a matrix. Example: n ( 1 2 3 ) ( 4 5 6 ) ( 4 5 6 ) ( 1 2 3 ) switchRows 1 2 ( 7 8 9 ) = ( 7 8 9 )4*Switch two coumns of a matrix. Example: n ( 1 2 3 ) ( 2 1 3 ) ( 4 5 6 ) ( 5 4 6 ) switchCols 1 2 ( 7 8 9 ) = ( 8 7 9 )5Matrix LU decomposition with partial pivoting. The result for a matrix M is given in the format  (U,L,P,d) where:U is an upper triangular matrix.L is an unit lower triangular matrix.P is a permutation matrix.d is the determinant of P.PM = LU.™These properties are only guaranteed when the input matrix is invertible. An additional property matches thanks to the strategy followed for pivoting:L_(i,j) <= 1, for all i,j.„This follows from the maximal property of the selected pivots, which also leads to a better numerical stability of the algorithm.Example: ¹ ( 1 2 0 ) ( 2 0 2 ) ( 1 0 0 ) ( 0 0 1 ) ( 0 2 1 ) ( 0 2 -1 ) ( 1/2 1 0 ) ( 1 0 0 ) luDecomp ( 2 0 2 ) = ( ( 0 0 2 ) , ( 0 1 1 ) , ( 0 1 0 ) , 1 )L+ is returned if no LU decomposition exists.6Unsafe version of 5-. It fails when the input matrix is singular.7Matrix LU decomposition with complete pivoting. The result for a matrix M is given in the format  (U,L,P,Q,d,e) where:U is an upper triangular matrix.L is an unit lower triangular matrix.P,Q are permutation matrices.d,e are the determinants of P and Q respectively.PMQ = LU.™These properties are only guaranteed when the input matrix is invertible. An additional property matches thanks to the strategy followed for pivoting:L_(i,j) <= 1, for all i,j.„This follows from the maximal property of the selected pivots, which also leads to a better numerical stability of the algorithm.Example: Ï ( 1 0 ) ( 2 1 ) ( 1 0 0 ) ( 0 0 1 ) ( 0 2 ) ( 0 2 ) ( 0 1 0 ) ( 0 1 0 ) ( 1 0 ) luDecomp' ( 2 1 ) = ( ( 0 0 ) , ( 1/2 -1/4 1 ) , ( 1 0 0 ) , ( 0 1 ) , -1 , 1 )L+ is returned if no LU decomposition exists.8Unsafe version of 7-. It fails when the input matrix is singular.9cSimple Cholesky decomposition of a symmetric, positive definite matrix. The result for a matrix M is a lower triangular matrix L such that:M = LL^T.Example:  ( 2 -1 0 ) ( 1.41 0 0 ) ( -1 2 -1 ) ( -0.70 1.22 0 ) cholDecomp ( 0 -1 2 ) = ( 0.00 -0.81 1.15 ):.Sum of the elements in the diagonal. See also  . Example: 4 ( 1 2 3 ) ( 4 5 6 ) trace ( 7 8 9 ) = 15;2Product of the elements in the diagonal. See also  . Example: = ( 1 2 3 ) ( 4 5 6 ) diagProd ( 7 8 9 ) = 45<FMatrix determinant using Laplace expansion. If the elements of the  are instance of M and N consider to use =4 in order to obtain better performance. Function < is  extremely slow.=^Matrix determinant using LU decomposition. It works even when the input matrix is singular.^OPQ>?RS@9Function takes the current column as additional argument. Row to map.6Function takes the current row as additional argument.Column to map.RowsColumns RowsColumnsGenerator function Default elementDiagonal vector RowsColumnsList of elements Size of the matrix.Permuted row 1.Permuted row 2.Permutation matrix.RowColumnMatrixRowColumnMatrixFT New elementNumber of columns of the matrix Row offset Column offsetPosition to set the new elementMutable vectorU New elementNumber of columns of the matrix Row offset Column offsetPosition to set the new elementMutable vector New value.Position to replace.Original matrix.=Matrix with the given position replaced with the given value. New value.Position to replace.Original matrix.=Matrix with the given position replaced with the given value. !V"Element to add when extending.Minimal number of rows.Minimal number of columns.#Default element.Number of rows.Number of columns.$ Starting row Ending rowStarting column Ending column%Row r to remove.Column c to remove.Original matrix.Matrix with row r and column c removed.&Row of the splitting element. Column of the splitting element.Matrix to split. (TL,TR,BL,BR)'()*+GH,-IWXYJ.ZK/0123Row 1.Row 2.Original matrix."Matrix with rows 1 and 2 switched.4Col 1.Col 2.Original matrix."Matrix with cols 1 and 2 switched.5[ULPd Current row Total rows678\ULPQde Current row Total rows9:;<=]^_`abcde>  !"#$%&'()*+,-./0123456789:;<=@     #" !$%&()'*+,-./0123456789:;<=WOPQ>?RS@ FTU !V"#$%&'()*+GH,-IWXYJ.ZK/012345[678\9:;<=]^_`abcdeGHf      !"#$%&'()*+,-./0123456789:;<=>?@ABCDECFGHIJHIKCLMNOPQRSCDTUVWCXYZ[\]^_`abcdefghijklmnopqmatri_87lu5PzzZxmGIKY6pKIrX1 Data.MatrixMatrixnrowsncols prettyMatrix forceMatrixflattenmapRowmapColzeromatrixidentitydiagonalfromListtoListtoLists diagonalList fromLists rowVector colVector permMatrixgetElem unsafeGet!safeGetsafeSetgetRowgetColgetDiaggetMatrixAsVectorsetElem unsafeSet transposeinverserrefextendTosetSize submatrix minorMatrix splitBlocks joinBlocks<|><-> elementwiseelementwiseUnsafemultStdmultStd2 multStrassenmultStrassenMixed scaleMatrixscaleRow combineRows switchRows switchColsluDecompluDecompUnsafe luDecomp'luDecompUnsafe' cholDecomptracediagProd detLaplacedetLUvcolsmvectsizeStrbaseGHC.BaseStringGHC.ShowShowvecto_LmZ3LQW4ivu8MsQuVgukln Data.VectorforceVectorGHC.Errerror!.+.-.multStd_strassen strassenMixedNothingghc-prim GHC.ClassesOrdGHC.Real FractionalM rowOffset colOffsetencodedecodemsetElem unsafeMsetref multStd__ dotProductfirst strmixFactor recLUDecomp recLUDecomp' $fNumMatrix$fTraversableMatrix$fFoldableMatrix$fApplicativeMatrix$fMonoidMatrix$fFunctorMatrix$fNFDataMatrix $fShowMatrix $fEqMatrix