*[      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~!(c) Alberto Ruiz 2009BSD3 Alberto Ruiz provisional Safe-Inferred 444(c) Alberto Ruiz 2007BSD3 Alberto Ruiz provisional Safe-Inferred  clear the fpu 0splitEvery 3 [1..9] == [[1,2,3],[4,5,6],[7,8,9]]0obtains the common value of a property of a listcommon value with "adaptable" 1Formatting toolpostfix function application (flip ($))specialized fromIntegral@error codes for the auxiliary functions required by the wrapperscheck the error code%Error capture and conversion to Maybe(  ( (c) Alberto Ruiz 2007BSD3 Alberto Ruiz provisionalNone 3;Number of elementscreates a Vector from a list: +> fromList [2,3,5,7] 4 |> [2.0,3.0,5.0,7.0]&extracts the Vector elements to a listtoList (linspace 5 (1,10))[1.0,3.25,5.5,7.75,10.0]Create a vector from a list of elements and explicit dimension. The input list is explicitly truncated if it is too long, so it may safely be used, for instance, with infinite lists. 5 |> [1..]fromList [1.0,2.0,3.0,4.0,5.0]0access to Vector elements without range checking.access to Vector elements with range checking.4takes a number of consecutive elements from a Vector subVector 2 3 (fromList [1..10])fromList [3.0,4.0,5.0]Reads a vector position:fromList [0..9] @> 77.0concatenate a list of vectors*vjoin [fromList [1..5::Double], konst 1 3]*fromList [1.0,2.0,3.0,4.0,5.0,1.0,1.0,1.0]2Extract consecutive subvectors of the given sizes.)takesV [3,4] (linspace 10 (1,10::Double))3[fromList [1.0,2.0,3.0],fromList [4.0,5.0,6.0,7.0]]Ytransforms a complex vector into a real vector with alternating real and imaginary parts Xtransforms a real vector into a complex vector with alternating real and imaginary partsmap on VectorszipWith for VectorsunzipWith for Vectors'monadic map over Vectors the monad m must be strict monadic map over Vectors!bmonadic map over Vectors with the zero-indexed index passed to the mapping function the monad m must be strict"Smonadic map over Vectors with the zero-indexed index passed to the mapping function.index of the starting elementnumber of elements to extractsourceresult !"#( !"#. !"#  (c) Alberto Ruiz 2007BSD3 Alberto Ruiz provisionalNone 234$Supported matrix elements.This class provides optimized internal operations for selected element types. It provides unoptimised defaults for any 1 type, so you can create instances simply as: instance Element Foo%<Matrix representation suitable for BLAS/LAPACK computations.5The elements are stored in a continuous memory array.Matrix transpose./mCreates a vector by concatenation of rows. If the matrix is ColumnMajor, this operation requires a transpose.flatten (ident 3).fromList [1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0]0the inverse of  1Create a matrix from a list of vectors. All vectors must have the same dimension, or dimension 1, which is are automatically expanded.22extracts the rows of a matrix as a list of vectors33Creates a matrix from a list of vectors, as columns46Creates a list of vectors from the columns of a matrixReads a matrix position.8Creates a matrix from a vector by grouping the elements in rows with the desired number of columns. (GNU-Octave groups by columns. To do it you can define reshapeF r = trans . reshape r( where r is the desired number of rows.)reshape 4 (fromList [1..12])(3><4) [ 1.0, 2.0, 3.0, 4.0 , 5.0, 6.0, 7.0, 8.0 , 9.0, 10.0, 11.0, 12.0 ]9Aapplication of a vector function on the flattened matrix elements:Capplication of a vector function on the flattened matrices elements;#Extracts a submatrix from a matrix.F$(r0,c0) starting position (rt,ct) dimensions of submatrix%&'(    )*+,-./012345678 9:;(r0,c0) starting position (rt,ct) dimensions of submatrix input matrixresult !"#,$%&'(  )*+,-./012345678 9:;<$%&('    )*+,-./012345678 9:; !"# (c) Alberto Ruiz 2010BSD3 Alberto Ruiz provisionalNone  23468=K<+Structures that may contain complex numbers=Supported real types$,Supported single-double precision type pairs%Ccreates a complex vector from vectors with real and imaginary parts&the inverse of  toComplex<'()*+=$,-%&./0123456789:;<=<'()*+= <'()*+=$,-%&./0123 (c) Alberto Ruiz 2007-14BSD3 Alberto Ruiz provisionalNone ?=normal distribution with mean zero and standard deviation one@uniform distribution in [0,1)>sum of elements?sum of elements@sum of elementsAsum of elementsBproduct of elementsCproduct of elementsDproduct of elementsEproduct of elementsFUobtains different functions of a vector: norm1, norm2, max, min, posmax, posmin, etc.GUobtains different functions of a vector: norm1, norm2, max, min, posmax, posmin, etc.H:obtains different functions of a vector: only norm1, norm2I:obtains different functions of a vector: only norm1, norm2J'map of real vectors with given functionK*map of complex vectors with given functionL'map of real vectors with given functionM'map of real vectors with given functionN'map of real vectors with given functionO*map of complex vectors with given functionP'map of real vectors with given functionQ*map of complex vectors with given functionR%elementwise operation on real vectorsS(elementwise operation on complex vectorsT%elementwise operation on real vectorsU(elementwise operation on complex vectorsB!save a matrix as a 2D ASCII tableCNObtains a vector of pseudorandom elements (use randomIO to get a random seed).j>?@AVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~>?@ABCDEFGHIJKLMNOPQRSTUB)"printf" format (e.g. "%.2f", "%g", etc.)C distribution vector sizeDEH>?@AVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|>?@ABCDEFGHIJKLMNOPQRSTUBCDEE>@?AV\[ZYXW]cba`_^djihgfek|{zyxwvutsrqponml}~>?@ABCDEFGHIJKLMNOPQRSTUBCDE (c) Alberto Ruiz 2007BSD3 Alberto Ruiz provisionalNone   !"#$%&'(  )*+,-./012345678 9:;(c) Alberto Ruiz 2008BSD3 Alberto Ruiz provisionalNone HJKM%FGHIJKLMNOPQRSTUVWXYZ[\]^_`aFGHIJKLMNOPQRSTUVWXYZ[\]^_`a#FGHIJKLMNOPQRSTUVWXYZ[\]^_`aNone ;If we use unsafePerformIO, it may not get inlined, so in a function that returns IO (which are all safe uses of app* in this module), there would be unecessary calls to unsafePerformIO or its internals.bGOnly useful since it is left associated with a precedence of 1, unlike #, which is right associative. e.g. msomeFunction `appMatrixLen` m `appVectorLen` v `app` other `app` arguments `app` go here One could also write: c(someFunction `appMatrixLen` m `appVectorLen` v) other arguments (go here) iThis will disregard the order of the matrix, and simply return it as-is. If the order of the matrix is RowMajor, this function is identical to /. bcdefghij bcdefghij bcdefghijbceg(c) Alberto Ruiz 2009BSD3 Alberto Ruiz provisionalportableNone  &'(+,-.567 (c) Alberto Ruiz 2007-10BSD3 Alberto Ruiz provisionalNone  2346=K1creates a matrix from a vertical list of matrices3creates a matrix from a horizontal list of matriceskACreate a matrix from blocks given as a list of lists of matrices.iSingle row-column components are automatically expanded to match the corresponding common row and column: disp = putStr . dispf 2 Bdisp $ fromBlocks [[ident 5, 7, row[10,20]], [3, diagl[1,2,3], 0]] 8x101 0 0 0 0 7 7 7 10 200 1 0 0 0 7 7 7 10 200 0 1 0 0 7 7 7 10 200 0 0 1 0 7 7 7 10 200 0 0 0 1 7 7 7 10 203 3 3 3 3 1 0 0 0 03 3 3 3 3 0 2 0 0 03 3 3 3 3 0 0 3 0 0lcreate a block diagonal matrix<disp 2 $ diagBlock [konst 1 (2,2), konst 2 (3,5), col [5,7]]7x81 1 0 0 0 0 0 01 1 0 0 0 0 0 00 0 2 2 2 2 2 00 0 2 2 2 2 2 00 0 2 2 2 2 2 00 0 0 0 0 0 0 50 0 0 0 0 0 0 75diagBlock [(0><4)[], konst 2 (2,3)] :: Matrix Double(2><7)$ [ 0.0, 0.0, 0.0, 0.0, 2.0, 2.0, 2.0& , 0.0, 0.0, 0.0, 0.0, 2.0, 2.0, 2.0 ]m Reverse rowsnReverse columnso&creates a rectangular diagonal matrix:5diagRect 7 (fromList [10,20,30]) 4 5 :: Matrix Double(4><5) [ 10.0, 7.0, 7.0, 7.0, 7.0 , 7.0, 20.0, 7.0, 7.0, 7.0 , 7.0, 7.0, 30.0, 7.0, 7.0 , 7.0, 7.0, 7.0, 7.0, 7.0 ]p/extracts the diagonal from a rectangular matrixqcreate a general matrix!(2><3) [2, 4, 7+2*V, -3, 11, 0](2><3), [ 2.0 :+ 0.0, 4.0 :+ 0.0, 7.0 :+ 2.0. , (-3.0) :+ (-0.0), 11.0 :+ 0.0, 0.0 :+ 0.0 ]yThe input list is explicitly truncated, so that it can safely be used with lists that are too long (like infinite lists). (2><3)[1..](2><3) [ 1.0, 2.0, 3.0 , 4.0, 5.0, 6.0 ]bThis is the format produced by the instances of Show (Matrix a), which can also be used for input.r8Creates a matrix with the first n rows of another matrixs3Creates a copy of a matrix without the first n rowst;Creates a matrix with the first n columns of another matrixu6Creates a copy of a matrix without the first n columnsv Creates a %+ from a list of lists (considered as rows).fromLists [[1,2],[3,4],[5,6]](3><2) [ 1.0, 2.0 , 3.0, 4.0 , 5.0, 6.0 ]w$creates a 1-row matrix from a vectorasRow (fromList [1..5]) (1><5) [ 1.0, 2.0, 3.0, 4.0, 5.0 ]x'creates a 1-column matrix from a vectorasColumn (fromList [1..5])(5><1) [ 1.0 , 2.0 , 3.0 , 4.0 , 5.0 ]creates a Matrix of the specified size using the supplied function to to map the row/column position to the value at that row/column position. > buildMatrix 3 4 (\(r,c) -> fromIntegral r * fromIntegral c) (3><4) [ 0.0, 0.0, 0.0, 0.0, 0.0 , 0.0, 1.0, 2.0, 3.0, 4.0 , 0.0, 2.0, 4.0, 6.0, 8.0]Hilbert matrix of order N: Ihilb n = buildMatrix n n (\(i,j)->1/(fromIntegral i + fromIntegral j +1))Srearranges the rows of a matrix according to the order given in a list of integers.Srearranges the rows of a matrix according to the order given in a list of integers.zKcreates matrix by repetition of a matrix a given number of rows and columnsrepmat (ident 2) 2 3(4><6) [ 1.0, 0.0, 1.0, 0.0, 1.0, 0.0 , 0.0, 1.0, 0.0, 1.0, 0.0, 1.0 , 1.0, 0.0, 1.0, 0.0, 1.0, 0.0! , 0.0, 1.0, 0.0, 1.0, 0.0, 1.0 ]{ A version of :l which automatically adapt matrices with a single row or column to match the dimensions of the other matrix.|yPartition a matrix into blocks with the given numbers of rows and columns. The remaining rows and columns are discarded.}Fully partition a matrix into blocks of the same size. If the dimensions are not a multiple of the given size the last blocks will be smaller.~cmapMatrixWithIndexM_ (\(i,j) v -> printf "m[%d,%d] = %.f\n" i j v :: IO()) ((2><3)[1 :: Double ..]) m[0,0] = 1 m[0,1] = 2 m[0,2] = 3 m[1,0] = 4 m[1,1] = 5 m[1,2] = 6mmapMatrixWithIndexM (\(i,j) v -> Just $ 100*v + 10*fromIntegral i + fromIntegral j) (ident 3:: Matrix Double) Just (3><3) [ 100.0, 1.0, 2.0 , 10.0, 111.0, 12.0 , 20.0, 21.0, 122.0 ]emapMatrixWithIndex (\(i,j) v -> 100*v + 10*fromIntegral i + fromIntegral j) (ident 3:: Matrix Double)(3><3) [ 100.0, 1.0, 2.0 , 10.0, 111.0, 12.0 , 20.0, 21.0, 122.0 ])klmnopqrstuvwxyz{|}~*$%)*/0123489:;klmnopqrstuvwxyz{|}~)klmnopqrstuvwxyz{|}~(c) Alberto Ruiz 2007-10BSD3 Alberto Ruiz provisionalNone 3ycreates a Vector of the specified length using the supplied function to to map the index to the value at that index. 3> buildVector 4 fromIntegral 4 |> [0.0,1.0,2.0,3.0]zip for Vectorsunzip for Vectors  !"# (c) Alberto Ruiz 2006-2014BSD3 Alberto Ruiz provisionalNone E !"#$%)*/0123489:;klmnopqrstuvwxyz{|}~(c) Alberto Ruiz 2006-14BSD3 Alberto Ruiz provisionalNone 6Matrix product based on BLAS's dgemm.Matrix product based on BLAS's zgemm.Matrix product based on BLAS's sgemm.Matrix product based on BLAS's cgemm.)Full SVD of a real matrix using LAPACK's dgesvd.)Full SVD of a real matrix using LAPACK's dgesdd.,Full SVD of a complex matrix using LAPACK's zgesvd.,Full SVD of a complex matrix using LAPACK's zgesdd.*Thin SVD of a real matrix, using LAPACK's dgesvd with jobu == jobvt == 'S'.-Thin SVD of a complex matrix, using LAPACK's zgesvd with jobu == jobvt == 'S'.*Thin SVD of a real matrix, using LAPACK's dgesdd with jobz == 'S'.-Thin SVD of a complex matrix, using LAPACK's zgesdd with jobz == 'S'.1Singular values of a real matrix, using LAPACK's dgesvd with jobu == jobvt == 'N'.4Singular values of a complex matrix, using LAPACK's zgesvd with jobu == jobvt == 'N'.1Singular values of a real matrix, using LAPACK's dgesdd with jobz == 'N'.4Singular values of a complex matrix, using LAPACK's zgesdd with jobz == 'N'.PSingular values and all right singular vectors of a real matrix, using LAPACK's dgesvd# with jobu == 'N' and jobvt == 'A'.SSingular values and all right singular vectors of a complex matrix, using LAPACK's zgesvd# with jobu == 'N' and jobvt == 'A'.OSingular values and all left singular vectors of a real matrix, using LAPACK's dgesvd$ with jobu == 'A' and jobvt == 'N'.RSingular values and all left singular vectors of a complex matrix, using LAPACK's zgesvd# with jobu == 'A' and jobvt == 'N'.OEigenvalues and right eigenvectors of a general complex matrix, using LAPACK's zgeevI. The eigenvectors are the columns of v. The eigenvalues are not sorted.8Eigenvalues of a general complex matrix, using LAPACK's zgeev3 with jobz == 'N'. The eigenvalues are not sorted.LEigenvalues and right eigenvectors of a general real matrix, using LAPACK's dgeevI. The eigenvectors are the columns of v. The eigenvalues are not sorted.5Eigenvalues of a general real matrix, using LAPACK's dgeev3 with jobz == 'N'. The eigenvalues are not sorted.NEigenvalues and right eigenvectors of a symmetric real matrix, using LAPACK's dsyev_. The eigenvectors are the columns of v. The eigenvalues are sorted in descending order (use  for ascending order). in ascending orderQEigenvalues and right eigenvectors of a hermitian complex matrix, using LAPACK's zheev_. The eigenvectors are the columns of v. The eigenvalues are sorted in descending order (use  for ascending order). in ascending order7Eigenvalues of a symmetric real matrix, using LAPACK's dsyevC with jobz == 'N'. The eigenvalues are sorted in descending order.:Eigenvalues of a hermitian complex matrix, using LAPACK's zheevC with jobz == 'N'. The eigenvalues are sorted in descending order.Solve a real linear system (for square coefficient matrix and several right-hand sides) using the LU decomposition, based on LAPACK's dgesv6. For underconstrained or overconstrained systems use  or  . See also .Solve a complex linear system (for square coefficient matrix and several right-hand sides) using the LU decomposition, based on LAPACK's zgesv6. For underconstrained or overconstrained systems use  or  . See also .wSolves a symmetric positive definite system of linear equations using a precomputed Cholesky factorization obtained by .wSolves a Hermitian positive definite system of linear equations using a precomputed Cholesky factorization obtained by .Least squared error solution of an overconstrained real linear system, or the minimum norm solution of an underconstrained system, using LAPACK's dgels!. For rank-deficient systems use .Least squared error solution of an overconstrained complex linear system, or the minimum norm solution of an underconstrained system, using LAPACK's zgels!. For rank-deficient systems use .kMinimum norm solution of a general real linear least squares problem Ax=B using the SVD, based on LAPACK's dgelss6. Admits rank-deficient systems but it is slower than . The effective rank of A is determined by treating as zero those singular valures which are less than rcond times the largest singular value. If rcond == Nothing machine precision is used.nMinimum norm solution of a general complex linear least squares problem Ax=B using the SVD, based on LAPACK's zgelss6. Admits rank-deficient systems but it is slower than . The effective rank of A is determined by treating as zero those singular valures which are less than rcond times the largest singular value. If rcond == Nothing machine precision is used.WCholesky factorization of a complex Hermitian positive definite matrix, using LAPACK's zpotrf.TCholesky factorization of a real symmetric positive definite matrix, using LAPACK's dpotrf.WCholesky factorization of a complex Hermitian positive definite matrix, using LAPACK's zpotrf ( version).TCholesky factorization of a real symmetric positive definite matrix, using LAPACK's dpotrf ( version).2QR factorization of a real matrix, using LAPACK's dgeqr2.5QR factorization of a complex matrix, using LAPACK's zgeqr2.build rotation from reflectorsbuild rotation from reflectorsAHessenberg factorization of a square real matrix, using LAPACK's dgehrd.DHessenberg factorization of a square complex matrix, using LAPACK's zgehrd.<Schur factorization of a square real matrix, using LAPACK's dgees.?Schur factorization of a square complex matrix, using LAPACK's zgees.:LU factorization of a general real matrix, using LAPACK's dgetrf.=LU factorization of a general complex matrix, using LAPACK's zgetrf.@Solve a real linear system from a precomputed LU decomposition (), using LAPACK's dgetrs.@Solve a real linear system from a precomputed LU decomposition (), using LAPACK's zgetrs.t      !"#$%&'()*+,-./012rcondcoefficient matrixright hand sides (as columns)solution vectors (as columns)rcondcoefficient matrixright hand sides (as columns)solution vectors (as columns)3456789801t      !"#$%&'()*+,-./0123456789(c) Alberto Ruiz 2010-14BSD3 Alberto Ruiz provisionalNone  23468=K!(conjugate) transpose$Matrix product and related functions:matrix product;@sum of absolute value of elements (differs in complex case from norm1)<!sum of absolute value of elements=euclidean norm>element of maximum magnitude9Basic element-by-element functions for numeric containers?6scale the element by element reciprocal of the object: @scaleRecip 2 (fromList [5,i]) == 2 |> [0.4 :+ 0.0,0.0 :+ (-2.0)]@!element by element multiplicationAelement by element division(create a structure with a single elementlet v = fromList [1..3::Double]v / scalar (norm2 v)CfromList [0.2672612419124244,0.5345224838248488,0.8017837257372732]complex conjugatemultiplication by scalarlike BH (cannot implement instance Functor because of Element class constraint)indexing functionindex of minimum elementindex of maximum elementvalue of minimum elementvalue of maximum elementthe sum of elementsthe product of elements#A more efficient implementation of !cmap (\x -> if x>0 then 1 else 0) step $ linspace 5 (-1,1::Double)5 |> [0.0,0.0,0.0,1.0,1.0]Element by element version of /case compare a b of {LT -> l; EQ -> e; GT -> g}.<Arguments with any dimension = 1 are automatically expanded:Econd ((1><4)[1..]) ((3><1)[1..]) 0 100 ((3><4)[1..]) :: Matrix Double(3><4)[ 100.0, 2.0, 3.0, 4.0, 0.0, 100.0, 7.0, 8.0, 0.0, 0.0, 100.0, 12.0 ]0Find index of elements which satisfy a predicate$find (>0) (ident 3 :: Matrix Double)[(0,0),(1,1),(2,2)]+Create a structure from an association list(assoc 5 0 [(3,7),(1,4)] :: Vector DoublefromList [0.0,4.0,0.0,7.0,0.0]Bassoc (2,3) 0 [((0,2),7),((1,0),2*i-3)] :: Matrix (Complex Double)(2><3)( [ 0.0 :+ 0.0, 0.0 :+ 0.0, 7.0 :+ 0.0* , (-3.0) :+ 2.0, 0.0 :+ 0.0, 0.0 :+ 0.0 ]+Modify a structure using an update function:accum (ident 5) (+) [((1,1),5),((0,3),3)] :: Matrix Double(5><5) [ 1.0, 0.0, 0.0, 3.0, 0.0 , 0.0, 6.0, 0.0, 0.0, 0.0 , 0.0, 0.0, 1.0, 0.0, 0.0 , 0.0, 0.0, 0.0, 1.0, 0.0 , 0.0, 0.0, 0.0, 0.0, 1.0 ]computation of histogram:Iaccum (konst 0 7) (+) (map (flip (,) 1) [4,5,4,1,5,2,5]) :: Vector Double&fromList [0.0,1.0,1.0,0.0,2.0,3.0,0.0]unconjugated dot productOuter product of two vectors.)fromList [1,2,3] `outer` fromList [5,2,3](3><3) [ 5.0, 2.0, 3.0 , 10.0, 4.0, 6.0 , 15.0, 6.0, 9.0 ]"Kronecker product of two matrices. m1=(2><3) [ 1.0, 2.0, 0.0 , 0.0, -1.0, 3.0 ] m2=(4><3) [ 1.0, 2.0, 3.0 , 4.0, 5.0, 6.0 , 7.0, 8.0, 9.0 , 10.0, 11.0, 12.0 ]kronecker m1 m2 (8><9): [ 1.0, 2.0, 3.0, 2.0, 4.0, 6.0, 0.0, 0.0, 0.0: , 4.0, 5.0, 6.0, 8.0, 10.0, 12.0, 0.0, 0.0, 0.0: , 7.0, 8.0, 9.0, 14.0, 16.0, 18.0, 0.0, 0.0, 0.0: , 10.0, 11.0, 12.0, 20.0, 22.0, 24.0, 0.0, 0.0, 0.0: , 0.0, 0.0, 0.0, -1.0, -2.0, -3.0, 3.0, 6.0, 9.0: , 0.0, 0.0, 0.0, -4.0, -5.0, -6.0, 12.0, 15.0, 18.0: , 0.0, 0.0, 0.0, -7.0, -8.0, -9.0, 21.0, 24.0, 27.0< , 0.0, 0.0, 0.0, -10.0, -11.0, -12.0, 30.0, 33.0, 36.0 ]Cconjugate transpose.Creates a square matrix with a given diagonal..creates the identity matrix of given dimensionDEFGH:;<=>IJKL?MNO@APQRSTUVWXYZ[\]ablegresult^_size default valueassociation listresult`initial structureupdate functionassociation listresultabcablegresultsize default valueassociation listresultinitial structureupdate functionassociation listresultdefghijCklmnopqrstuvwxyz{|}~_456789:;<=<=DEDEFG:;<=>IJKL?MNO@APQRSTUVWXYZ[\]^_`fghCWDEFGH:;<=>IJKL?MNO@APQRSTUVWXYZ[\]^_`abcdefghijCklmnopqrstuvwxyz{|}~(c) Alberto Ruiz 2006-14BSD3 Alberto Ruiz provisionalNone  2346=K4PGeneric linear algebra functions for double precision real and complex matrices..(Single precision data can be converted using  and )."Full singular value decomposition. a = (5><3) [ 1.0, 2.0, 3.0 , 4.0, 5.0, 6.0 , 7.0, 8.0, 9.0 , 10.0, 11.0, 12.0 , 13.0, 14.0, 15.0 ] :: Matrix Double let (u,s,v) = svd adisp 3 u5x5&-0.101 0.768 0.614 0.028 -0.149&-0.249 0.488 -0.503 0.172 0.646&-0.396 0.208 -0.405 -0.660 -0.449&-0.543 -0.072 -0.140 0.693 -0.447&-0.690 -0.352 0.433 -0.233 0.398sEfromList [35.18264833189422,1.4769076999800903,1.089145439970417e-15]disp 3 v3x3-0.519 -0.751 0.408-0.576 -0.046 -0.816-0.632 0.659 0.408let d = diagRect 0 s 5 3disp 3 d5x335.183 0.000 0.000 0.000 1.477 0.000 0.000 0.000 0.000 0.000 0.000 0.000disp 3 $ u <> d <> tr v5x3 1.000 2.000 3.000 4.000 5.000 6.000 7.000 8.000 9.00010.000 11.000 12.00013.000 14.000 15.000 A version of  which returns only the min (rows m) (cols m) singular vectors of m.If (u,s,v) = thinSVD m then m == u <> diag s <> tr v. a = (5><3) [ 1.0, 2.0, 3.0 , 4.0, 5.0, 6.0 , 7.0, 8.0, 9.0 , 10.0, 11.0, 12.0 , 13.0, 14.0, 15.0 ] :: Matrix Double let (u,s,v) = thinSVD adisp 3 u5x3-0.101 0.768 0.614-0.249 0.488 -0.503-0.396 0.208 -0.405-0.543 -0.072 -0.140-0.690 -0.352 0.433sEfromList [35.18264833189422,1.4769076999800903,1.089145439970417e-15]disp 3 v3x3-0.519 -0.751 0.408-0.576 -0.046 -0.816-0.632 0.659 0.408disp 3 $ u <> diag s <> tr v5x3 1.000 2.000 3.000 4.000 5.000 6.000 7.000 8.000 9.00010.000 11.000 12.00013.000 14.000 15.000Singular values only. A version of G which returns an appropriate diagonal matrix with the singular values.If (u,d,v) = fullSVD m then m == u <> d <> tr v. Similar to T, returning only the nonzero singular values and the corresponding singular vectors. a = (5><3) [ 1.0, 2.0, 3.0 , 4.0, 5.0, 6.0 , 7.0, 8.0, 9.0 , 10.0, 11.0, 12.0 , 13.0, 14.0, 15.0 ] :: Matrix Double let (u,s,v) = compactSVD adisp 3 u5x2-0.101 0.768-0.249 0.488-0.396 0.208-0.543 -0.072-0.690 -0.352s/fromList [35.18264833189422,1.4769076999800903]disp 3 u5x2-0.101 0.768-0.249 0.488-0.396 0.208-0.543 -0.072-0.690 -0.352disp 3 $ u <> diag s <> tr v5x3 1.000 2.000 3.000 4.000 5.000 6.000 7.000 8.000 9.00010.000 11.000 12.00013.000 14.000 15.000<Singular values and all right singular vectors (as columns).;Singular values and all left singular vectors (as columns).RObtains the LU decomposition of a matrix in a compact data structure suitable for .mSolution of a linear system (for several right hand sides) from the precomputed LU factorization obtained by .Solve a linear system (for square coefficient matrix and several right-hand sides) using the LU decomposition. For underconstrained or overconstrained systems use  or . It is similar to  . , but  linearSolve0 raises an error if called on a singular system.Solve a linear system (for square coefficient matrix and several right-hand sides) using the LU decomposition, returning Nothing for a singular system. For underconstrained or overconstrained systems use  or . vSolve a symmetric or Hermitian positive definite linear system using a precomputed Cholesky decomposition obtained by .Minimum norm solution of a general linear least squares problem Ax=B using the SVD. Admits rank-deficient systems but it is slower than g. The effective rank of A is determined by treating as zero those singular valures which are less than " times the largest singular value.Least squared error solution of an overconstrained linear system, or the minimum norm solution of an underconstrained system. For rank-deficient systems use .SEigenvalues (not ordered) and eigenvectors (as columns) of a general square matrix.If  (s,v) = eig m then m <> v == v <> diag s Ba = (3><3) [ 3, 0, -2 , 4, 5, -1 , 3, 1, 0 ] :: Matrix Double let (l, v) = eig aputStr . dispcf 3 . asRow $ l1x3!1.925+1.523i 1.925-1.523i 4.151putStr . dispcf 3 $ v3x3$-0.455+0.365i -0.455-0.365i 0.181$ 0.603 0.603 -0.978$ 0.033+0.543i 0.033-0.543i -0.104"putStr . dispcf 3 $ complex a <> v3x3$-1.432+0.010i -1.432-0.010i 0.753$ 1.160+0.918i 1.160-0.918i -4.059$-0.763+1.096i -0.763-1.096i -0.433putStr . dispcf 3 $ v <> diag l3x3$-1.432+0.010i -1.432-0.010i 0.753$ 1.160+0.918i 1.160-0.918i -4.059$-0.763+1.096i -0.763-1.096i -0.4335Eigenvalues (not ordered) of a general square matrix. Similar to k without checking that the input matrix is hermitian or symmetric. It works with the upper triangular part. Similar to k without checking that the input matrix is hermitian or symmetric. It works with the upper triangular part.oEigenvalues and eigenvectors (as columns) of a complex hermitian or real symmetric matrix, in descending order.If (s,v) = eigSH m then m == v <> diag s <> tr v @a = (3><3) [ 1.0, 2.0, 3.0 , 2.0, 4.0, 5.0 , 3.0, 5.0, 6.0 ] let (l, v) = eigSH alEfromList [11.344814282762075,0.17091518882717918,-0.5157294715892575]disp 3 $ v <> diag l <> tr v3x31.000 2.000 3.0002.000 4.000 5.0003.000 5.000 6.000REigenvalues (in descending order) of a complex hermitian or real symmetric matrix.QR factorization.If  (q,r) = qr m then  m == q <> r/, where q is unitary and r is upper triangular.Dgenerate a matrix with k orthogonal columns from the output of qrRawRQ factorization.If  (r,q) = rq m then  m == r <> q/, where q is unitary and r is upper triangular.Hessenberg factorization.If (p,h) = hess m then m == p <> h <> ctrans pj, where p is unitary and h is in upper Hessenberg form (it has zero entries below the first subdiagonal).Schur factorization.If (u,s) = schur m then m == u <> s <> ctrans u, where u is unitary and s is a Shur matrix. A complex Schur matrix is upper triangular. A real Schur matrix is upper triangular in 2x2 blocks.c"Anything that the Jordan decomposition can do, the Schur decomposition can do better!" (Van Loan) Similar to V, but instead of an error (e.g., caused by a matrix not positive definite) it returns . Similar to l, without checking that the input matrix is hermitian or symmetric. It works with the upper triangular part.LCholesky factorization of a positive definite hermitian or symmetric matrix.If  c = chol m then c is upper triangular and m == ctrans c <> c.MJoint computation of inverse and logarithm of determinant of a square matrix.LDeterminant of a square matrix. To avoid possible overflow or underflow use ..Explicit LU factorization of a general matrix.If (l,u,p,s) = lu m then m == p <> l <> u{, where l is lower triangular, u is upper triangular, p is a permutation matrix and s is the signature of the permutation.%Inverse of a square matrix. See also .:Pseudoinverse of a general matrix with default tolerance ( 1, similar to GNU-Octave). pinvTol r7 computes the pseudoinverse of a matrix with tolerance tol=r*g*eps*(max rows cols)), where g is the greatest singular value. [m = (3><3) [ 1, 0, 0 , 0, 1, 0 , 0, 0, 1e-10] :: Matrix Double pinv m1. 0. 0.0. 1. 0.0. 0. 10000000000. pinvTol 1E8 m1. 0. 0.0. 1. 0.0. 0. 1.4Numeric rank of a matrix from the SVD decomposition.2Numeric rank of a matrix from its singular values.#The machine precision of a Double: eps = 2.22044604925031e-16 (the value used by GNU-Octave).%1 + 0.5*peps == 1, 1 + 0.6*peps /= 1The imaginary unit: i = 0.0 :+ 1.0AThe nullspace of a matrix from its precomputed SVD decomposition.$The nullspace of a matrix. See also .QThe nullspace of a matrix, assumed to be one-dimensional, with machine precision.@The range space a matrix from its precomputed SVD decomposition.:Return an orthonormal basis of the range space of a matrixYReciprocal of the 2-norm condition number of a matrix, computed from the singular values.9Number of linearly independent rows or columns. See also CGeneric matrix functions for diagonalizable matrices. For instance: logm = matFunc logMatrix exponential. It uses a direct translation of Algorithm 11.3.1 in Golub & Van Loan, based on a scaled Pade approximation.Matrix square root. Currently it uses a simple iterative algorithm described in Wikipedia. It only works with invertible matrices that have a real solution. 1m = (2><2) [4,9 ,0,4] :: Matrix Doublesqrtm m(2><2) [ 2.0, 2.25 , 0.0, 2.0 ](For diagonalizable matrices you can try  sqrt: matFunc sqrt ((2><2) [1,0,0,-1])(2><2) [ 1.0 :+ 0.0, 0.0 :+ 0.0 , 0.0 :+ 0.0, 0.0 :+ 1.0 ];Approximate number of common digits in the maximum element.Generalized symmetric positive definite eigensystem Av = lBv, for A and B symmetric, B positive definite (conditions not checked).o.(inverse, (log abs det, sign or phase of det))numeric zero (e.g. 1*)input matrix msv of m rank of mnumeric zero (e.g. 1*)maximum dimension of the matrixsingular values rank of mLeft "numeric" zero (eg. 1*)), or Right "theoretical" matrix rank.input matrix m of m nullspacerelative tolerance in  units (e.g., use 3 to get 3*) input matrix.list of unitary vectors spanning the nullspaceLeft "numeric" zero (eg. 1*)), or Right "theoretical" matrix rank.input matrix m of morthAB?V(c) Alberto Ruiz 2011BSD3 Alberto Ruiz provisionalNone  2346=K  (c) Vivian McPhail 2010BSD36Vivian McPhail <haskell.vivian.mcphail <at> gmail.com> provisionalportableNone lProvide optimal association order for a chain of matrix multiplications and apply the multiplications.xThe algorithm is the well-known O(n^3) dynamic programming algorithm that builds a pyramid of optimal associations. mm1, m2, m3, m4 :: Matrix Double m1 = (10><15) [1..] m2 = (15><20) [1..] m3 = (20><5) [1..] m4 = (5><10) [1..] >>> optimiseMult [m1,m2,m3,m4] will perform ((m1 : (m2 : m3)) : m4)2The naive left-to-right multiplication would take 4500? scalar multiplications whereas the optimised version performs 2750 scalar multiplications. The complexity in this case is 32 (= 4^3/2) * (2 comparisons, 3 scalar multiplications, 3 scalar additions, 5 lookups, 2 updates) + a constant (= three table allocations)(c) Alberto Ruiz 2014BSD3 Alberto Ruiz provisionalNone  2346=K(c) Alberto Ruiz 2009-14BSD3 Alberto Ruiz provisionalNone `Obtains a matrix whose rows are pseudorandom samples from a multivariate Gaussian distribution._Obtains a matrix whose rows are pseudorandom samples from a multivariate uniform distribution.9pseudorandom matrix with uniform elements between 0 and 19pseudorandom matrix with uniform elements between 0 and 1(pseudorandom matrix with normal elementsdisp 3 =<< randn 3 53x5%0.386 -1.141 0.491 -0.510 1.512%0.069 -0.919 1.022 -0.181 0.745%0.313 -0.670 -0.097 -1.575 -0.583number of rows mean vectorcovariance matrixresultnumber of rowsranges for each columnresultrowscolumns >?@AC(c) Alberto Ruiz 2010BSD3 Alberto Ruiz provisionalNone Creates a string from a matrix given a separator and a function to show each entry. Using this function the user can easily define any desired display function: import Text.Printf(printf) +disp = putStr . format " " (printf "%.2f")FShow a matrix with "autoscaling" and a given number of decimal places.%putStr . disps 2 $ 120 * (3><4) [1..]3x4 E3 0.12 0.24 0.36 0.48 0.60 0.72 0.84 0.96 1.08 1.20 1.32 1.444Show a matrix with a given number of decimal places.dispf 2 (1/3 + ident 3)="3x3\n1.33 0.33 0.33\n0.33 1.33 0.33\n0.33 0.33 1.33\n""putStr . dispf 2 $ (3><4)[1,1.5..]3x41.00 1.50 2.00 2.503.00 3.50 4.00 4.505.00 5.50 6.00 6.50EputStr . unlines . tail . lines . dispf 2 . asRow $ linspace 10 (0,1):0.00 0.11 0.22 0.33 0.44 0.56 0.67 0.78 0.89 1.004Show a vector using a function for showing matrices..putStr . vecdisp (dispf 2) $ linspace 10 (0,1)@10 |> 0.00 0.11 0.22 0.33 0.44 0.56 0.67 0.78 0.89 1.00+Tool to display matrices with latex syntax.)latexFormat "bmatrix" (dispf 2 $ ident 2):"\\begin{bmatrix}\n1 & 0\n\\\\\n0 & 1\n\\end{bmatrix}"<Pretty print a complex number with at most n decimal digits.<Pretty print a complex matrix with at most n decimal digits.;reads a matrix from a string containing a table of numbers.9load a matrix from an ASCII file formatted as a 2D table.4type of braces: "matrix", "bmatrix", "pmatrix", etc.@Formatted matrix, with elements separated by spaces and newlines By(c) Alberto Ruiz 2010-14BSD3 Alberto Ruiz provisionalNone 23468 build 5 (**2) :: Vector DoublefromList [0.0,1.0,4.0,9.0,16.0]Hilbert matrix of order N:=let hilb n = build (n,n) (\i j -> 1/(i+j+1)) :: Matrix DoubleputStr . dispf 2 $ hilb 33x31.00 0.50 0.330.50 0.33 0.250.33 0.25 0.20konst 7 3 :: Vector FloatfromList [7.0,7.0,7.0]konst i (3::Int,4::Int)(3><4)1 [ 0.0 :+ 1.0, 0.0 :+ 1.0, 0.0 :+ 1.0, 0.0 :+ 1.01 , 0.0 :+ 1.0, 0.0 :+ 1.0, 0.0 :+ 1.0, 0.0 :+ 1.03 , 0.0 :+ 1.0, 0.0 :+ 1.0, 0.0 :+ 1.0, 0.0 :+ 1.0 ]9Matrix-matrix, matrix-vector, and vector-matrix products.3Creates a real vector containing a range of values:linspace 5 (-3,7::Double)!fromList [-3.0,-0.5,2.0,4.5,7.0]@-linspace 5 (8,2+i) :: Vector (Complex Double)CfromList [8.0 :+ 0.0,6.5 :+ 0.25,5.0 :+ 0.5,3.5 :+ 0.75,2.0 :+ 1.0].Logarithmic spacing can be defined as follows: )logspace n (a,b) = 10 ** linspace n (a,b) An infix synonym for infix synonym for &vector [1,2,3,4] <> vector [-2,0,1,1]5.0let V = 0:+1 :: !%fromList [1+V,1] <> fromList [1,1+V] 2.0 :+ 0.0,(the dot symbol "" is obtained by Alt-Gr .)infix synonym for let m = (2><3) [1..]m(2><3) [ 1.0, 2.0, 3.0 , 4.0, 5.0, 6.0 ]let v = vector [10,20,30]m #> vfromList [140.0,320.0]dense matrix-vector productoLeast squares solution of a linear system, similar to the \ operator of Matlab/Octave (based on linearSolveSVD) 4a = (3><2) [ 1.0, 2.0 , 2.0, 4.0 , 2.0, -1.0 ]  v = vector [13.0,27.0,1.0] let x = a <\> vx/fromList [3.0799999999999996,5.159999999999999]a #> x4fromList [13.399999999999999,26.799999999999997,1.0]GIt also admits multiple right-hand sides stored as columns in a matrix.BCompute mean vector and covariance matrix of the rows of a matrix.>meanCov $ gaussianSample 666 1000 (fromList[4,5]) (diagl[2,3])1(fromList [4.010341078059521,5.0197204699640405],(2><2)1 [ 1.9862461923890056, -1.0127225830525157e-24 , -1.0127225830525157e-2, 3.0373954915729318 ])     456789:;<= !"#$%)*/0123489:;<=>?@BCDEklmnopqrstuvwxyz{|}~DEFG:;<=>IJKL?MNO@APQRSTUVWXYZ[\]^_`fghC        None 456789:;<= !"#$%)*/0123489:;<=>?@BCklmnopqrstuvwxyz{|}~:;<=>?MNO@APfghC  (c) Alberto Ruiz 2006-14BSD3 Alberto Ruiz provisionalNone 456789:;<= !"#$%)*/0123489:;<=>?@BCklmnopqrstuvwxyz{|}~:;<=>?MNO@APfghC  (c) Alberto Ruiz 2012BSD3 Alberto Ruiz provisionalNone 3 correlation)corr (fromList[1,2,3]) (fromList [1..10])2fromList [14.0,20.0,26.0,32.0,38.0,44.0,50.0,56.0] convolution (I with reversed kernel and padded input, equivalent to polynomial product)&conv (fromList[1,1]) (fromList [-1,1])fromList [-1.0,0.0,1.0] similar to , using  instead of (*) 2D correlation (without padding):disp 5 $ corr2 (konst 1 (3,3)) (ident 10 :: Matrix Double) 8x83 2 1 0 0 0 0 02 3 2 1 0 0 0 01 2 3 2 1 0 0 00 1 2 3 2 1 0 00 0 1 2 3 2 1 00 0 0 1 2 3 2 10 0 0 0 1 2 3 20 0 0 0 0 1 2 32D convolution:disp 5 $ conv2 (konst 1 (3,3)) (ident 10 :: Matrix Double) 12x12"1 1 1 0 0 0 0 0 0 0 0 0"1 2 2 1 0 0 0 0 0 0 0 0"1 2 3 2 1 0 0 0 0 0 0 0"0 1 2 3 2 1 0 0 0 0 0 0"0 0 1 2 3 2 1 0 0 0 0 0"0 0 0 1 2 3 2 1 0 0 0 0"0 0 0 0 1 2 3 2 1 0 0 0"0 0 0 0 0 1 2 3 2 1 0 0"0 0 0 0 0 0 1 2 3 2 1 0"0 0 0 0 0 0 0 1 2 3 2 1"0 0 0 0 0 0 0 0 1 2 2 1"0 0 0 0 0 0 0 0 0 1 1 1Rmatrix computation implemented as separated vector operations by rows and columns.kernelsourcekernel(c) Alberto Ruiz 2013BSD3 Alberto Ruiz provisionalNone   23468=Kvect [1..10] ! 34.0mat 5 [1..15] ! 1fromList [6.0,7.0,8.0,9.0,10.0]mat 5 [1..15] ! 1 ! 39.0imaginary unitcreate a real vector vector [1..5]fromList [1.0,2.0,3.0,4.0,5.0]create a real matrixmatrix 5 [1..15](3><5) [ 1.0, 2.0, 3.0, 4.0, 5.0 , 6.0, 7.0, 8.0, 9.0, 10.0! , 11.0, 12.0, 13.0, 14.0, 15.0 ]Gprint a real matrix with given number of digits after the decimal pointdisp 5 $ ident 2 / 32x20.33333 0.000000.00000 0.33333)create a real diagonal matrix from a list diagl [1,2,3](3><3) [ 1.0, 0.0, 0.0 , 0.0, 2.0, 0.0 , 0.0, 0.0, 3.0 ]a real matrix of zerosa real matrix of onesconcatenation of real vectors)horizontal concatenation of real matricesident 3 ||| konst 7 (3,4)(3><7)$ [ 1.0, 0.0, 0.0, 7.0, 7.0, 7.0, 7.0$ , 0.0, 1.0, 0.0, 7.0, 7.0, 7.0, 7.0& , 0.0, 0.0, 1.0, 7.0, 7.0, 7.0, 7.0 ] a synonym for () (unicode 0x00a6, broken bar) 'vertical concatenation of real matrices a synonym for ( ) (unicode 0x2014, em dash) +create a single row real matrix from a list .create a single column real matrix from a list extract rows(20><4) [1..] ? [2,1,1](3><4) [ 9.0, 10.0, 11.0, 12.0 , 5.0, 6.0, 7.0, 8.0 , 5.0, 6.0, 7.0, 8.0 ]extract columns2(unicode 0x00bf, inverted question mark, Alt-Gr ?)(3><4) [1..] [3,0](3><2) [ 4.0, 1.0 , 8.0, 5.0 , 12.0, 9.0 ].cross product (for three-element real vectors) 2-norm of real vector!4Obtains a vector in the same direction with 2-norm=1" trans . invsize $ fromList[1..10::Double]10size $ (2><5)[1..10::Double](2,5)#gMatrix of pairwise squared distances of row vectors (using the matrix product trick in blog.smola.org)outer products of rowsa(3><2) [ 1.0, 2.0 , 10.0, 20.0 , 100.0, 200.0 ]b(3><3) [ 1.0, 2.0, 3.0 , 4.0, 5.0, 6.0 , 7.0, 8.0, 9.0 ]rowOuters a (b ||| 1)(3><8)< [ 1.0, 2.0, 3.0, 1.0, 2.0, 4.0, 6.0, 2.0< , 40.0, 50.0, 60.0, 10.0, 80.0, 100.0, 120.0, 20.0> , 700.0, 800.0, 900.0, 100.0, 1400.0, 1600.0, 1800.0, 200.0 ]5solution of overconstrained homogeneous linear system?solution of overconstrained homogeneous symmetric linear system$stacking of columns%1half-vectorization (of the lower triangular part)&duplication matrix (& k <> % m == $ m, for symmetric m of  k)'$generalized "vector" transposition: ' 1 == , and ' () m) m == x ($ m);()columnselementsrowscolumnsrowscolumns   *   !"#$%&'+,-./01234567;()   *   !"#$%&'+,-.6()   *   !"#$%&'+,-./01234567    *  + None 246yGeneral matrix with specialized internal representations for dense, sparse, diagonal, banded, and constant elements./let m = mkSparse [((0,999),1.0),((1,1999),2.0)]m3SparseR {gmCSR = CSR {csrVals = fromList [1.0,2.0],5 csrCols = fromList [1000,2000],1 csrRows = fromList [1,2,3],# csrNRows = 2,' csrNCols = 2000}, nRows = 2,# nCols = 2000}let m = mkDense (mat 2 [1..4])mDense {gmDense = (2><2) [ 1.0, 2.0$ , 3.0, 4.0 ], nRows = 2, nCols = 2}2general matrix - vector product/let m = mkSparse [((0,999),1.0),((1,1999),2.0)]m !#> vector [1..2000]fromList [1000.0,4000.0]+89: !"#$;<=>?@A%&'()*+,BCD-./01E23FGH !"#$%&'()*+,-./01E2389:!"#$ #$#$#$;<=>?@A%&'()*+,BCD-./01E23FGHD2(c) Alberto Ruiz 2014BSD3 Alberto Ruiz provisionalNone j  !"#&'(+,-.5679:FGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghij{~ !"#$%&'()*+-0pbcdefghij7. &('+,-65GTHOJQRMNFaU]W^_Z[SKLIP`XYV\# !"~9:{%&'()*+0-!"#$ #$#$#$(c) Alberto Ruiz 2014BSD3 Alberto Ruiz provisionalNone p456789:;<=%)*/012348;BDEklmnopqrstuvwxyz|}     #$,./13nqop/8wx  1234v0yrstu;nmk lz|}D,3/1.BE)*  %#$#$#$#$#$!None 2346conjugate gradient7residual8squared norm of residual9current solution:normalized size of correction456789:IJKLMN; is symmetriccoefficient matrixright-hand sidesolution< symmetric/relative tolerance for the residual (e.g. 1E-4)%relative tolerance for x (e.g. 1E-3)maximum number of iterationscoefficient matrixinitial solutionright-hand sidesolutionO 456789:IJ;< 456789:IJKLMN;<O(c) Alberto Ruiz 2006-14BSD3 Alberto Ruiz provisionalNone =infix synonym of >let a = (3><5) [1..]a(3><5) [ 1.0, 2.0, 3.0, 4.0, 5.0 , 6.0, 7.0, 8.0, 9.0, 10.0! , 11.0, 12.0, 13.0, 14.0, 15.0 ])let b = (5><2) [1,3, 0,2, -1,5, 7,7, 6,0]b(5><2) [ 1.0, 3.0 , 0.0, 2.0 , -1.0, 5.0 , 7.0, 7.0 , 6.0, 0.0 ]a <> b(3><2) [ 56.0, 50.0 , 121.0, 135.0 , 186.0, 220.0 ]>dense matrix product?Solve a linear system (for square coefficient matrix and several right-hand sides) using the LU decomposition, returning Nothing for a singular system. For underconstrained or overconstrained systems use  or . %a = (2><2) [ 1.0, 2.0 , 3.0, 5.0 ]  3b = (2><3) [ 6.0, 1.0, 10.0 , 15.0, 3.0, 26.0 ] linearSolve a b Just (2><3)E [ -1.4802973661668753e-15, 0.9999999999999997, 1.999999999999997G , 3.000000000000001, 1.6653345369377348e-16, 4.000000000000002 ]let Just x = itdisp 5 x2x3-0.00000 1.00000 2.00000 3.00000 0.00000 4.00000a <> x(2><3) [ 6.0, 1.0, 10.0 , 15.0, 3.0, 26.0 ]@Dreturn an orthonormal basis of the null space of a matrix. See also .AEreturn an orthonormal basis of the range space of a matrix. See also .=>?@A456789:;<=$%)*/012348;<=>?@ABCDEklmnopqrstuvwxyz|}     #$,./123456789:;<=>?@Av2>=?;<A@A>@?C$<=456789:=>?@A="(c) Alberto Ruiz 2006-14BSD3 provisionalNone  (23468=BHJKMLBCDEFGHIJPQKRLSMTNUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~2BCDEFGHIJPQKRLSMTNUVWXYZ[\]^_`abcdefghijklmnopqrst@BCDEFGHIJPQKRLSMTNUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~(c) Alberto Ruiz 2014BSD3 experimentalNone  !"(23468<=BHJKMWOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~JBCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~JN_`a]^bdefL\jkonlmhgicMKU|{pqrstu~vwWXY}BCOPQRSTDEFGHIJZ[VxyzMOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~]^nopqr#$%#$&#$'#$()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_` a b c d e f g h i jklmnopqrstuvwxyz{|}~       !"#$%&'()*+,-./0123456789:;< = > ? @ A B C D E F G H H I J K L M N O P Q R S T U!V!V!W!X!Y!Z![!\!]^_`ab"c")"d""e"'"f"g"6"h"i"j"kl_3mnopq@rstuvw'(xyz{/0|}.,^~WY y#$J      6!"#$%&' ( ) * + , - . / 0 1 2 3 4 5 6 7898:8;8<8=8>8?8@8A8B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~                                      kl                         !"#$%&'()*+,-./0123456789:;<=>?@ABCD_EFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~`b^~f     s6 !"#$t%&'()*+,-./01 2 3 4 5 5 6 7 8 9 : ; < % = > ? @!3!k!A!B!C!D!E"F"3"h"i"j"k"G"G"H"I"J"K"L"M"N"O"P"Q"R"S"T"U"V"W"X"Y"Z"["\"]"^"_"`"a"b"c"d"e"f"g"h"i"j"k"l"m"n"o"p"q"r"s"t"u"v"w"x"y"z"{"|"}"~nohmatrix-0.16.1.2Numeric.LinearAlgebra.DevelNumeric.LinearAlgebra.DataNumeric.LinearAlgebra.HMatrixNumeric.LinearAlgebra.StaticData.Packed.Internal.SignaturesData.Packed.Internal.CommonData.Packed.Internal.VectorData.Packed.Internal.MatrixData.Packed.Matrix fromListsNumeric.ConversionNumeric.VectorizedData.Packed.InternalData.Packed.STData.Packed.ForeignData.Packed.DevelopmentData.Packed.Vector Data.PackedNumeric.LinearAlgebra.LAPACKData.Packed.Internal.Numeric Numeric.LinearAlgebra.AlgorithmsNumeric.Vector Numeric.ChainNumeric.MatrixNumeric.LinearAlgebra.RandomData.Packed.IOData.Packed.NumericNumeric.ContainerNumeric.LinearAlgebra&Numeric.LinearAlgebra.Util.ConvolutionNumeric.LinearAlgebra.UtilNumeric.SparseNumeric.LinearAlgebra.Util.CG%Numeric.LinearAlgebra.Static.Internalvector-0.10.12.2Data.Vector.StorableunsafeToForeignPtrunsafeFromForeignPtrfromListVector//fiapp1app2app3app4app5app6app7app8app9app10checkvec createVectortoList|>at' subVectorvjointakesV zipVectorWithunzipVectorWith foldVectorfoldVectorWithIndexfoldLoop foldVectorG mapVectorM mapVectorM_mapVectorWithIndexMmapVectorWithIndexM_mapVectorWithIndexElementMatrix MatrixOrder ColumnMajorRowMajorrowscolsorderOfcmatfmatmatflattentoListsfromRowstoRows fromColumns toColumnsatM'matrixFromVector createMatrixreshape liftMatrix liftMatrix2 subMatrix Complexable RealElementRandDistGaussianUniformSeed saveMatrix randomVector sortVector roundVectorSTMatrixSTVector thawVectorunsafeThawVector runSTVectorunsafeReadVectorunsafeWriteVector modifyVector liftSTVector freezeVectorunsafeFreezeVector readVector writeVectornewUndefinedVector newVector thawMatrixunsafeThawMatrix runSTMatrixunsafeReadMatrixunsafeWriteMatrix modifyMatrix liftSTMatrixunsafeFreezeMatrix freezeMatrix readMatrix writeMatrixnewUndefinedMatrix newMatrixapp appVector appVectorLen appMatrix appMatrixLen appMatrixRawappMatrixRawLenunsafeMatrixToVectorunsafeMatrixToForeignPtr fromBlocks diagBlockflipudfliprldiagRecttakeDiag><takeRowsdropRows takeColumns dropColumnsasRowasColumn fromArray2DrepmatliftMatrix2AutotoBlocks toBlocksEverymapMatrixWithIndexM_mapMatrixWithIndexMmapMatrixWithIndex toByteStringfromByteString zipVector unzipVectorTestablecheckTioCheckT TransposabletrDoubleOfSingleOf ComplexOfRealOfConvertrealcomplexsingledouble toComplex fromComplexProduct ContainerIndexOfscalarconjscalearctan2cmapatIndexminIndexmaxIndex minElement maxElement sumElements prodElementsstepcondfindassocaccumudotouter kroneckerdiagidentFieldsvdthinSVDsingularValues compactSVDrightSVleftSVluPackedluSolve cholSolvelinearSolveSVD linearSolveLSeig eigenvalueseigSH'eigenvaluesSH'eigSH eigenvaluesSHqrqrRawqrgrrqhessschurmbCholSHcholSHcholinvlndetdetluinvpinvpinvTolranksvpeps nullspaceSVDorthSVD haussholderrcondrankmatFuncexpmsqrtm relativeErrorgeigSH'gaussianSample uniformSamplerandrandnformatdispsdispf latexFormatdispcf loadMatrix loadMatrix'NumericBuildbuildKonstkonstLSDivlinspace<·>#><\>dot optimiseMultmeanCovcorrconvcorrMincorr2conv2 separable Indexable!Normednorm_0norm_1norm_2norm_InfℂℝiCvectormatrixdispdiagl|||¦===——rowcol?¿cross norm_Frob norm_nuclearsize rowOutersnull1null1symdispDots dispBlanks dispShortGMatrixDensegmDenseDiagdiagValsSparseCgmCSCSparseRgmCSRnRowsnColsCSRcsrValscsrColscsrRowscsrNRowscsrNCols AssocMatrixmkCSRmkDensemkSparsefromCSRmkDiagR!#>toDenseCGStatecgpcgrcgr2cgxcgdxcgSolvecgSolve'<>mul linearSolve nullspaceorthDispSizedunwrapextractcreateMLCRDomaindiagRHerSymEigen eigensystemSq&#vec2vec3vec4rangedimeyeblockAtunrowuncollinSolvesvdTallsvdFlatsymmTmunSym𝑖her withNullspacewithCompactSVDsplitheadTail splitRows splitCols withVector withMatrixmeanTMMCVMTMCVMTCVMTVCVTCMCVTQMQMQMTQMQMTQMTQVFTQVQVQVTQVQVTQVTCVVTCVCVCVTCVCVTCVTCMCMCMTCMCMVCMTCMVCMTVCMTCMCM TCMCMCVCMTMCMCVCMTCMCVCMTCVCMTCMTMMVMTMVMTMMVTMVTVVMTVMTMMMTMVMMTVMMTMMTMTFMFMFMTFMFMTFMTVVVTVVTVTFFFTVFTFVTFFTFPCPQPDPFfinit splitEverycommon compatdimtable errorCodembCatchAdapt10Adapt9Adapt8Adapt7Adapt6Adapt5Adapt4Adapt3Adapt2Adapt1Adaptww2ww3ww4ww5ww6ww7ww8ww9ww10safeReadat@>asReal asComplex mapVector c_conjugateC c_conjugateQc_condDc_condFc_stepDc_stepFc_double2floatc_float2doubleinlinePerformIOsafe float2DoubleV double2FloatVstepFstepDcondFcondD conjugateAux conjugateQ conjugateC cloneVector unsafeWithbaseForeign.StorableStorabletrans@@> subMatrixD transdata constantDirowsicolsxdatorder cconstantP cconstantC cconstantQ cconstantR cconstantFctransPctransCctransQctransRctransF transOrdercdatfdat singletoncompat transdataAux transdataP constantAux constantP subMatrix'' subMatrix'maxZ conformMs conformVs conformMTo conformVTorepRowsrepColsshSizeemptyM$fNFDataMatrix$fElementComplex$fElementComplex0$fElementDouble$fElementFloat Precision toComplexV fromComplexV toComplex' fromComplex'comp'single'double' double2FloatG float2DoubleG$fComplexableMatrix$fComplexableVector$fRealElementFloat$fRealElementDouble$fPrecisionComplexComplex$fPrecisionFloatDouble Data.Complexphase magnitudepolarcismkPolar conjugateimagPartrealPart:+ComplexsumFsumRsumQsumCprodFprodRprodQprodC toScalarR toScalarF toScalarC toScalarQ vectorMapR vectorMapC vectorMapF vectorMapQ vectorMapValR vectorMapValC vectorMapValF vectorMapValQ vectorZipR vectorZipC vectorZipF vectorZipQFunCodeSMinMinIdxMaxMaxIdxAbsSumNorm2 FunCodeVVATan2PowDivMulSubAdd FunCodeSVPowVSPowSVNegate AddConstantRecipScaleFunCodeVSqrtSignLogExpATanhACoshASinhTanhCoshSinhATanACosASinAbsTanCosSinc_round_vector c_sort_valuesc_random_vector c_saveMatrix c_vectorScan c_vectorZipQ c_vectorZipF c_vectorZipC c_vectorZipRc_vectorMapValQc_vectorMapValFc_vectorMapValCc_vectorMapValR c_vectorMapQ c_vectorMapF c_vectorMapC c_vectorMapR c_toScalarQ c_toScalarC c_toScalarF c_toScalarRc_prodCc_prodQc_prodRc_prodFc_sumCc_sumQc_sumRc_sumFfromei toScalarAux vectorMapAuxvectorMapValAux vectorZipAux vectorScanioReadVioWriteV safeIndexVioReadMioWriteM cloneMatrix safeIndexMunsafeInlinePerformIOGHC.Base$joinVert joinHoriz buildMatrix extractRowsextractColumnssizesdspbreakAt fromBlocksRaw adaptBlockslMcompat' toBlockRows toBlockColsmk mapMatrix $fReadMatrix $fShowMatrix$fBinaryMatrix buildVectorchunkchunks putVector getVectorjoin$fBinaryVector multiplyR multiplyC multiplyF multiplyQsvdRsvdRdsvdCsvdCdthinSVDRthinSVDC thinSVDRd thinSVDCdsvRsvCsvRdsvCdrightSVRrightSVCleftSVRleftSVCeigCeigOnlyCeigReigOnlyReigSeigS'eigHeigH'eigOnlySeigOnlyH linearSolveRlinearSolveLSRlinearSolveSVDRlusR linearSolveClinearSolveLSClinearSolveSVDClusC cholSolveRcholS cholSolveCcholHmbCholH Data.MaybeMaybembCholSqrRqrCqrgrRqrgrChessRhessCschurRschurCluRluCTQTWzgetrsdgetrszgetrfdgetrfzgeesdgeeszgehrddgehrdzungqrdorgqrzgeqr2dgeqr2dpotrfzpotrfzgelssdgelsszgelsdgelszpotrsdpotrszgesvdgesvzheevdsyevzgeevdgeevzgesdddgesddzgesvddgesvdcgemmcsgemmczgemmcdgemmcisTtt multiplyAuxsvdAux thinSVDAuxsvAux rightSVAux leftSVAuxeigAux eigOnlyAuxeigRauxfixeig1fixeigeigSHAuxvrevlinearSolveSQAuxmbLinearSolveRmbLinearSolveClinearSolveAuxcholAuxqrAuxqrgrAuxhessAuxschurAuxluAuxlusAuxmultiplyabsSumnorm1norm2normInf scaleRecipdividefmapctransLinearscalarLaddLscaleL ElementOfsize'scalar'conj'scale' addConstantaddsubequalarctan2'cmap'konst'build'atIndex' minIndex' maxIndex' minElement' maxElement' sumElements' prodElements'step'cond'find'assoc'accum'ArgOf emptyErrorV emptyErrorMemptyMulemptyValmXmmXvvXmbuildMbuildVfindVfindMassocVassocMaccumVaccumMcondMcondV$fTransposableMatrixMatrixTFCo:R:ElementOfMatrixTFCo:R:ElementOfVectorTFCo:R:DoubleOfComplexTFCo:R:DoubleOfFloatTFCo:R:DoubleOfDoubleTFCo:R:SingleOfComplexTFCo:R:SingleOfFloatTFCo:R:SingleOfDoubleTFCo:R:ComplexOfComplexTFCo:R:ComplexOfFloatTFCo:R:ComplexOfComplex0TFCo:R:ComplexOfDoubleTFCo:R:RealOfComplexTFCo:R:RealOfFloatTFCo:R:RealOfComplex0TFCo:R:RealOfDouble$fConvertComplex$fConvertComplex0$fConvertFloat$fConvertDouble$fProductComplex$fProductComplex0$fProductDouble$fProductFloat$fContainerMatrixa$fContainerVectorComplex$fContainerVectorComplex0$fContainerVectorDouble$fContainerVectorFloatTFCo:R:ArgOfMatrixaTFCo:R:ArgOfVectoraTFCo:R:IndexOfMatrixTFCo:R:IndexOfVectorfullSVD mbLinearSolveepsNothingrankSVDi nullspacePrec nullVectorrelativeError'pnormNormType FrobeniusPNorm2PNorm1Infinitysvd'thinSVD'sv' luPacked'luSolve'mbLinearSolve' linearSolve' cholSolve'linearSolveSVD'linearSolveLS'eig'eigSH''eigOnly eigOnlySHcholSH' mbCholSH'qr'qrgr'hess'schur'squareverticalexactHermitianzhztunpackQR unpackHessuH diagonalizegolubepsepslistgepsexpGolubsqrtmInvsignlpswapfixPermtriangluFact$fNormedMatrixComplex$fNormedMatrixFloat$fNormedMatrixComplex0$fNormedMatrixDouble$fNormedVectorComplex$fNormedVectorFloat$fNormedVectorComplex0$fNormedVectorDouble$fFieldComplex $fFieldDouble adaptScalar$fFloatingVector$fFloatingVector0$fFloatingVector1$fFloatingVector2$fFractionalVector $fNumVector $fNumVector0 $fNumVector1 $fNumVector2IndexesCostSizesMatricesupdatenewWorkSpaceCostnewWorkSpaceIndexesmatricesToSizeschain chain_cost chain_cost' minimum_cost smaller_cost fulcrum_orderpartner chain_parenisScalar adaptScalarM$fMonoidMatrix$fFloatingMatrix$fFractionalMatrix $fNumMatrix $fEqMatrixrandmvecdisp showComplexsdims formatFixedisInt formatScaledshcr lookslikeIntisZeroisOne apparentCols<.>$fNumericComplex$fNumericFloat$fNumericComplex0$fNumericDouble$fBuild(,)(->)Matrixe$fBuildInt(->)Vectore$fKonste(,)Matrix$fKonsteIntVector $fLSDivMatrix $fLSDivVector$fMulVectorMatrixVector$fMulMatrixVectorVector$fMulMatrixMatrixMatrixconstantghc-prim GHC.ClassesminvectSSmatSSzerosonesnormunitarymt pairwiseD2vechdupvtransℤℕ~!~ formatSparse approxInt formatShort$fIndexableMatrixVector$fIndexableVectorComplex$fIndexableVectorComplex0$fIndexableVectorFloat$fIndexableVectorDouble$fNormedMatrix$fNormedMatrix0$fNormedVector$fNormedVector0SMxVVIVCSCcscValscscRowscscColscscNRowscscNColsc_smTXvc_smXvgmXv$fTransposableGMatrixGMatrix$fTransposableCSCCSR$fTransposableCSRCSCcg conjugradsolveG takeUntil$fTestableGMatrixGMDimlift1Flift2FmkRmkCmkLmkMudmkVvconcatgvec2gvec3gvec4gvectgmatsingleVsingleMisDiagisDiagCisDiagg adaptDiagisFulllift1Llift2Llift2LD adaptDiagCisFullClift1Mlift2Mlift2MD$fDispC$fDispR$fDispM$fDispL $fFloatingM $fFractionalM$fNumM $fFloatingL $fFractionalL$fNumL $fFloatingDim$fFractionalDim$fNumDim$fFloatingDim0$fFractionalDim0 $fNumDim0$fShowM$fShowL$fShowC$fShowR$fTransposableMM$fTransposableLL$fSizedComplexMMatrix$fSizedDoubleLMatrix$fSizedDoubleRVector$fSizedComplexCVectorGSqGLud1ud2isKonstisKonstCmulRappRdotRcrossRmulCappCdotCcrossC diagRectR diagRectCtest splittest $fTestableL$fDomainComplexCM$fDomainDoubleRL $fEigenLCM $fEigenSymRL$fDiagLR $fDiagLR0 $fDiagLR1