!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ (c) Alberto Ruiz 2009BSD3 Alberto Ruiz provisionalNone3457(-Class of compatible indices for contractions.:A multidimensional array with index type i and elements t.3Get detailed dimension information about the array.UGet the coordinates of an array as a flattened structure (in the order specified by ).Dimension descriptor. :indices are denoted by strings, (frequently single-letter) :Types that can be elements of the multidimensional arrays.2development function not intended for the end user $change the whole set of coordinates.!Create a 0-dimensional structure.IRename indices (in the internal order). Equal indices are contracted out.)Rename indices using an association list. Index names (in internal order). Index names.Dimension of given index.Type of given index.5The number of dimensions of a multidimensional array.gTensor product with automatic contraction of repeated indices, following Einstein summation convention.Obtain a matrix whose columns are the fibers of the array in the given dimension. The column order depends on the selected index (see ).bReshapes an array as a matrix with the desired dimensions as flattened rows and flattened columns.Reshapes an array as a matrix with the desired dimensions as flattened rows and flattened columns. We do not force the order of the columns.6Create a list of the substructures at the given level.iChange the internal layout of coordinates. The array, considered as an abstract object, does not change.%Apply a function (defined on hmatrix (s) to all elements of a structure. Use mapArray (mapVector f) for general functions.,Check if two arrays have the same structure.~Apply an element-by-element binary function to the coordinates of two arrays. The arguments are automatically made conformant.:Create an array from a list of subarrays. (The inverse of .) &Obtain a canonical base for the array.0obtains the common value of a property of a list! Extract the C corresponding to a two-dimensional array, in the rows,cols order." Extract the * corresponding to a one-dimensional array.#BExtract the scalar element corresponding to a 0-dimensional array.$ Create a 1st order array from a .% Create a 2nd order array from a .&FSelect some parts of an array, taking into account position and value.'@Apply a list function to the parts of an array at a given index.(DObtains most general structure of a list of dimension specifications)0Converts a list of arrays to a common structure.,"This is equivalent to the regular H, but in the order that minimizes the size of the intermediate factors.'sequence of n indices with given prefixO  new names input arrayrow dimensionscolumn dimensionsresult input arrayrow dimensions(result, column dimensions)index to expandtransformation index type !"#$%&'()*+,<  !"#$%&'()*+,F  !"#$%&'()*+, (c) Alberto Ruiz 2009BSD3 Alberto Ruiz provisionalNone4-3Show a multidimensional array as a nested 2D table..QPrint the array as a nested table with the desired format (e.g. %7.2f) (see also -, and /)./9Show the array as a nested table with autoscaled entries.0Show the array as a nested table with a "%.nf" format. If all entries are approximate integers the array is shown without the .00.. digits.1OInsert a dummy index of dimension 1 at a given level (for formatting purposes).2>Rename indices so that they are not shown in formatted output.-#format function (eg. printf "5.2f")./number of of decimal places0number of of decimal places12-./012-./012 (c) Alberto Ruiz 2009BSD3 Alberto Ruiz provisionalNone34539Multidimensional array with unespecified coordinate type.4IUnespecified coordinate type. Contractions only require equal dimension.6Construction of an 3I from a list of dimensions and a list of elements in left to right order.3456 dimensionselements34563456(c) Alberto Ruiz 2009BSD3 Alberto Ruiz provisionalNone 7)Multidimensional diagonal of given order.8/Explicit renaming of single letter index names.For instance,  t >@> "pi qj") changes index "p" to "i" and "q" to "j".9ZRename indices in alphabetical order. Equal indices of compatible type are contracted out.:&Rename indices in alphabetical order (9) using single letter names.;@ (transpose) dimensions of the array (with single letter names).qOperations are defined by named indices, so the transposed array is operationally equivalent to the original one.<AMap a function at the internal level selected by a set of indices=;Outer product of a list of arrays along the common indices.>!Define an array using a function.?*Define an array using an association list.@Change type of index.A Extract the R of an array, and renameRaw one of the remaining indices with succesive integers. 789:;<=>?@Aindex of the parts to extract input arrayindex to renameRawprefix for the new nameslist or resultsB>  !"#$%&'()*+,-/012789:;<=>?@AB@  89:,=&'<;-0/12() +*7>?@A #"!B$% 789:;<=>?@AB8 : ;(c) Alberto Ruiz 2009BSD3 Alberto Ruiz provisionalNoneC Create an 3 from a list of parts (index =  4).DElement by element product.CD .34568:;CD 4536C:8;D.CDD(c) Alberto Ruiz 2009BSD3 Alberto Ruiz experimentalNone345 IUCreates a tensor from a list of dimensions and a list of coordinates. A positive dimension means that the index is assumed to be contravariant (vector-like), and a negative dimension means that the index is assumed to be covariant (like a linear function, or covector). Contractions can only be performed between indices of different type.J Create an H2 from a list of parts with a contravariant index ( superindex =  F).K Create an H. from a list of parts with a covariant index ( subindex =  G).L Change the E/ nature of all dimensions to the opposite ones.MMake all dimensions covariant.N"Make all dimensions contravariant.O Remove the E nature of coordinates.PCCreate a contravariant 1st order tensor from a list of coordinates.Q?Create a covariant 1st order tensor from a list of coordinates.RRCreate a 1-contravariant, 1-covariant 2nd order from list of lists of coordinates.EFGHI dimensions coordinatesJKLMNOPQR.34568:;CDEFGHIJKLMNOPQRHEFGIJKPQRLMNOEFGHIJKLMNOPQR(c) Alberto Ruiz 2009BSD3 Alberto Ruiz experimentalNone XThe reversion operator.AShow the non zero coordinates of a multivector in a nicer format.YCreates a scalar multivector.Z<Creates a grade 1 multivector of from a list of coordinates.[The k-th basis element.\The exterior (outer) product.]The contractive inner product.^hThe full space of the given dimension. This is the leviCivita simbol, and the basis of the pseudoscalar._Intersection of subspaces.`/The rotor operator, used in a sandwich product.aFExtract a multivector representation from a full antisymmetric tensor.<(We do not check that the tensor is actually antisymmetric.)bWApply a linear transformation, expressed as the image of the element i-th of the basis.(This is a monadic bind!)/STUVWXYZ[\]^_`dimension of the spaceangleaxisresultabSTUVWXYZ[\]^_`abSTTYZ[\]_X^`bVUWa-STUVWXYZ[\]^_`ab\]_(c) Alberto Ruiz 2009BSD3 Alberto Ruiz experimentalNone4cLThe exterior (wedge) product of two tensors. Obtains the union of subspaces.<Implemented as the antisymmetrization of the tensor product.dAThe full antisymmetric tensor of order n (contravariant version).e;The "meet" operator. Obtains the intersection of subspaces.  a \/ b = dual (dual a /\ dual b)f1Inner product of a r-vector with the whole space. dual t = inner (leviCivita n) tg(Euclidean inner product of multivectors.hNExtract a compact multivector representation from a full antisymmetric tensor.asMultivector = Multivector.a.<(We do not check that the tensor is actually antisymmetric.)i!Create an explicit antisymmetric H7 from the components of a Multivector of a given grade.cdefghi .34568:;CDEFGHIJKLMNOPQRcdefghicgdfehicdefghice(c) Alberto Ruiz 2009BSD3 Alberto Ruiz provisionalNone4>Lj5optimization parameters for alternating least squareslmaximum number of iterationsmDminimum relative improvement in the optimization (percent, e.g. 0.1)nmaximum relative error. For nonhomogeneous problems it is the reconstruction error in percent (e.g. 1E-3), and for homogeneous problems is the frobenius norm of the expected zero structure in the right hand side.o9post-processing function after each full iteration (e.g. )p5post-processing function for the k-th argument (e.g.  )q3preprocessing function for the linear systems (eg. , or )rSolution of the linear system a x = b, where a and b are general multidimensional arrays. The structure and dimension names of the result are inferred from the arguments.t`Solution of the homogeneous linear system a x = 0, where a is a general multidimensional array.[If the system is overconstrained we may provide the theoretical rank to get a MSE solution.vA simpler way to use ta, which returns just one solution. If the system is overconstrained it returns the MSE solution.xv for single letter index names.ySolution of the linear system a x = b, where a and b are general multidimensional arrays, with homogeneous equality along a given index.{TSolution of a multilinear system a x y z ... = b based on alternating least squares.|bSolution of the homogeneous multilinear system a x y z ... = 0 based on alternating least squares.}oSolution of a multilinear system a x y z ... = b, with a homogeneous index, based on alternating least squares.~Given two arrays a (source) and b (target), we try to compute linear transformations x,y,z,... for each dimension, such that product [a,x,y,z,...] == b. (We can use  for o processing, or .)Homogeneous factorized system. Given an array a, given as a list of factors as, and a list of pairs of indices ["pi","qj", "rk", etc.], we try to compute linear transformations x!"pi", y!"pi", z!"rk", etc. such that product [a,x,y,z,...] == 0.`post processing function that modifies a list of tensors so that they have equal frobenius normNnMax = 20, epsilon = 1E-3, delta = 1, post = id, postk = const id, presys = iddebugging function (e.g. for qT), which shows rows, columns and rank of the coefficient matrix of a linear system.*jklmnopqrcoefficients (a)target (b)result (x)stcoefficients (a)Idesired dimensions for the result (a subset selected from the target).8Left "numeric zero" (e.g. eps), Right "theoretical" rankbasis for the solutions (x)uvwxycoefficients (a)desired result (b)the homogeneous dimension result (x)zmethoderror functionstarting pointoptimization parameterssolution and error history{optimization parameters-coefficients (a), given as a list of factors.initial solution [x,y,z...] target (b)Solution and error history|optimization parameters-coefficients (a), given as a list of factors.initial solution [x,y,z...]Solution and error history}optimization parameters-coefficients (a), given as a list of factors.initial solution [x,y,z...] target (b)homogeneous indexSolution and error history~seed for random initializationoptimization parameterssource (also factorized)/index pairs for the factors separated by spacestargetsolution and error historyseed for random initializationoptimization parameters(coefficient array (a), (also factorized)/index pairs for the factors separated by spacessolution and error history  jklmnopqrstuvwxyz{|}~rtvxyjklmnopq{|}~suwz#jklmnopqrstuvwxyz{|}~  (c) Alberto Ruiz 2009BSD3 Alberto Ruiz experimentalNone4Full version of .{The first element in the result pair is a list with the core (head) and rotations so that t == product (fst (hsvd' t)).uThe second element is a list of rank and singular values along each mode, to give some idea about core structure.TMultilinear Singular Value Decomposition (or Tucker's method, see Lathauwer et al.).ZThe result is a list with the core (head) and rotations so that t == product (hsvd t).BThe core and the rotations are truncated to the rank of each mode.Use B to get full transformations and rank information about each mode. Truncate a Q decomposition from the desired number of principal components in each dimension.\Basic CP optimization for a given rank. The result includes the obtained sequence of errors.kFor example, a rank 3 approximation can be obtained as follows, where initialization is based on the hosvd: g(y,errs) = cpRank 3 t where cpRank r t = cpRun (cpInitSvd (fst $ hosvd' t) r) defaultParameters t Experimental implementation of the CP decomposition, based on alternating least squares. We try approximations of increasing rank, until the relative reconstruction error is below a desired percent of Frobenius norm (epsilon).hThe approximation of rank k is abandoned if the error does not decrease at least delta% in an iteration.4Practical usage can be based on something like this: cp finit d e t = cpAuto (finit t) defaultParameters {delta = d, epsilon = e} t cpS = cp (InitSvd . fst . hosvd') cpR s = cp (cpInitRandom s) So we can write p -- initialization based on hosvd y = cpS 0.01 1E-6 t -- (pseudo)random initialization z = cpR seed 0.1 0.1 t $cp initialization based on the hosvd0pseudorandom cp initialization from a given seed   starting pointoptimization parameters input arrayfactors and error history%Initialization function for each rankoptimization parameters input arrayfactors'hosvd decomposition of the target arrayrankstarting pointseedtarget array to decomposerankrandom starting pointjklmnopqjklmnopq       !"#$%&'()*+,-./0123456 7 8 9 : ; < = > > ?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`Yabcdefghbiejklmnnopqrstuvwxyz{|}~        hTens_HgoIccIqGJMCvQUHNI9eQf Numeric.LinearAlgebra.Array.UtilNumeric.LinearAlgebra.ArrayNumeric.LinearAlgebra.Tensor!Numeric.LinearAlgebra.MultivectorNumeric.LinearAlgebra.Exterior!Numeric.LinearAlgebra.Array.Solve)Numeric.LinearAlgebra.Array.Decomposition$Numeric.LinearAlgebra.Array.Internal#Numeric.LinearAlgebra.Array.Display"Numeric.LinearAlgebra.Array.SimpleCompatcompatoposNArraydimscoordsIdxiTypeiDimiNameNameCoord resetCoordsscalarrenameExplicitnamessizesizestypeOforderanalyzeProduct|*|fibers matrixatormatrixatorFreepartsreordermapArray sameStructurezipArraynewIndexbasisOfasMatrixasVectorasScalar fromVector fromMatrixextractonIndex conformablemakeConformant takeDiagTatT smartProduct formatArrayprintA formatScaled formatFixeddummyAtnoIdxArrayNone listArraydiagT!>renameO!~>mapTatoutersmkFunmkAssocsetType renameParts applyAsMatrixindex.*VariantContraCoTensor listTensor superindexsubindexswitchcovcontravforgetvectorcovectortransf MultivectormaxGradegrademaxDimrevere/\-|full\/rotor fromTensorapply leviCivitadualinner asMultivectorfromMultivectorALSParamnMaxdeltaepsilonpostpostkpresyssolvesolve' solveHomog solveHomog' solveHomog1 solveHomog1'solveHsolvePsolveP'mlSolvemlSolveHmlSolveP solveFactors solveFactorsHeqnormdefaultParametersinfoRankhosvd'hosvdtruncateFactorscpRuncpAuto cpInitSvd cpInitRandommkNArray renameRawnamesRvecto_A9qWf1eecPQGJD12EBZIxFData.Vector.StorableVectorcommonhmatr_J2ncT4cuHNGJnh9PH8pFTsInternal.MatrixMatrixbase Data.FoldableproductseqIdxAdimtransidentdebugrenameSuperRawmapDimsmapTypesmapNamessizesRselDimscommon2lastIdxfirstIdxpartsRawtridxliftNA2 contract1getName contract1ccommon1contractextendmakeConformantT dropElemPos$fOrdIdx $fCoordCInt$fCoordComplex $fCoordDoubleInternal.VectorIRectlicoels showBasesrectpaddispHdispVmapTail formatAuxshowNice showRawDimsdecorUp decorLeftisInt lookslikeIntwidth $fShowNArray $fCompatNone $fShowIdx$fFloatingNArray$fFractionalNArray $fNumNArray $fEqNArrayflipV$fCompatVariantshowMVMVpowersetbase'r1r2r3simplifygsgpgeginormVecunitarygpruleseprulesgpreprexpandcompactgatensortmvmatpmatdivimvrecippart$fFractionalMultivector$fNumMultivector$fShowMultivector interchanges signaturegsymantisymmetrizefactwedgelevidual'renseqrenseq'isScalarGHC.BaseidconstsolveP1optimizepercentpercentPfrobTreplaceElemPostakesalsStepalsArgalsArgHalsArgPinitFactorsSeqinitFactorsRandominitFactorsHSeqinitFactorsHRandomsepflatsusOfSVDttakeunitRows cpInitSeq