# The tensor package

This library defines data types and classes for fixed dimension vectors and tensors. The main objects are:

`Data.Ordinal.Ordinal`

- A totally ordered set with fixed
size. The

type`Data.Ordinal.Ordinal`

contains 1 element,`Data.Ordinal.One`

contains 2 elements,`Data.Ordinal.Succ`

`Data.Ordinal.One`

contains 3 elements, and so on (see Data.Ordinal for more details). The type`Data.Ordinal.Succ`

`Data.Ordinal.Succ`

`Data.Ordinal.One`

is an alias for`Data.Ordinal.Two`

,`Data.Ordinal.Succ`

`Data.Ordinal.One`

is an alias for`Data.Ordinal.Three`

, and so on.`Data.Ordinal.Succ`

`Data.Ordinal.Succ`

`Data.Ordinal.One`

`Data.TypeList.MultiIndex.MultiIndex`

- The index set. It can be
linear, rectangular, parallelepipedal, etc. The dimensions of the
sides are expressed using

types and the type constructor`Data.Ordinal.Ordinal`

, e.g.`Data.TypeList.MultiIndex.:|:`

`(`

is a rectangular index set with 2 rows and 3 columns. The index set also contains elements, for example`Data.Ordinal.Two`

`Data.TypeList.MultiIndex.:|:`

(`Data.Ordinal.Three`

`Data.TypeList.MultiIndex.:|:`

`Data.TypeList.MultiIndex.Nil`

))`(`

contains all the pairs`Data.Ordinal.Two`

`Data.TypeList.MultiIndex.:|:`

(`Data.Ordinal.Three`

`Data.TypeList.MultiIndex.:|:`

`Data.TypeList.MultiIndex.Nil`

))`(i`

where i is in`Data.TypeList.MultiIndex.:|:`

(j`Data.TypeList.MultiIndex.:|:`

Nil))

and j is in`Data.Ordinal.Two`

. See Data.TypeList.MultiIndex for more details.`Data.Ordinal.Three`

`Data.Tensor.Tensor`

- It is an assignment of elements to each
element of its

.`Data.TypeList.MultiIndex.MultiIndex`

Objects like vectors and matrices are special cases of tensors. Most of the functions to manipulate tensors are grouped into type classes. This allow the possibility of having different internal representations (backends) of a tensor, and act on these with the same functions. At the moment we only provide one backend based on http://hackage.haskell.org/package/vector, which is accessible by importing the module Data.Tensor.Vector. More backends will be provided in future releases.

Here is a usage example:

`>>>`

`:m Data.Ordinal Data.TypeList.MultiIndex Data.Tensor.Vector`

`>>>`

[[2,3,5],[1,3,6],[0,5,4],[2,1,3]]`fromList [2,3,5,1,3,6,0,5,4,2,1,3] :: Tensor (Four :|: (Three :|: Nil)) Int`

The above defines a tensor with 4 rows and 3 columns (a matrix) and

coefficients. The entries of this matrix are taken from a
list using `Int`

which is a method of the class
`Data.Tensor.fromList`

. Notice the output: the `Data.Tensor.FromList`

instance
is defined in such a way to give a readable representation as list
of lists. The is equivalent but slightly more readable code:`Show`

`>>>`

[[2,3,5],[1,3,6],[0,5,4],[2,1,3]]`fromList [2,3,5,1,3,6,0,5,4,2,1,3] :: Matrix Four Three Int`

Analogously

`>>>`

[7,3,-6]`fromList [7,3,-6] :: Tensor (Three :|: Nil) Int`

and

`>>>`

[7,3,-6]`fromList [7,3,-6] :: Vector Three Int`

are the same. In order to access an entry of a

we use the `Data.Tensor.Tensor`

operator, which
takes the same `Data.Tensor.!`

of the
`Data.TypeList.MultiIndex.MultiIndex`

as its second argument:`Data.Tensor.Tensor`

`>>>`

`let a = fromList [2,3,5,1,3,6,0,5,4,2,1,3] :: Matrix Four Three Int`

`>>>`

`let b = fromList [7,3,-6] :: Vector Three Int`

`>>>`

5`a ! (toMultiIndex [1,3] :: (Four :|: (Three :|: Nil)))`

`>>>`

3`b ! (toMultiIndex [2] :: (Three :|: Nil))`

it returns the element at the coordinate (1,3) of the matrix `a`

,
and the element at the coordinate 2 of the vector b. In fact, thanks
to type inference, we could simply write

`>>>`

5`a ! toMultiIndex [1,3]`

`>>>`

2`b ! toMultiIndex [2]`

And now a couple of examples of algebraic operations (requires adding Data.Tensor.LinearAlgebra.Vector to the import list):

`>>>`

`:m Data.Ordinal Data.TypeList.MultiIndex Data.Tensor.Vector Data.Tensor.LinearAlgebra.Vector`

`>>>`

`let a = fromList [2,3,5,1,3,6,0,5,4,2,1,3] :: Matrix Four Three Int`

`>>>`

`let b = fromList [7,3,-6] :: Vector Three Int`

`>>>`

[-7,-20,-9,-1]`a .*. b`

is the product of matrix `a`

and vector `b`

, while

`>>>`

`let c = fromList [3,4,0,-1,4,5,6,2,1] :: Matrix Three Three Int`

`>>>`

[[3,4,0],[-1,4,5],[6,2,1]]`c`

`>>>`

[106,13,8]`charPoly c`

gives the coefficients of the characteristic polynomial of the
matrix `c`

.

## Properties

Versions | 0.1, 0.1.1, 0.2.0, 0.3.0, 0.3.0.1 |
---|---|

Dependencies | base (==4.*), vector [details] |

License | GPL-3 |

Author | Federico Squartini, Nicola Squartini |

Maintainer | Nicola Squartini <tensor5@gmail.com> |

Category | Data, Math |

Uploaded | Wed Jun 13 20:09:36 UTC 2012 by NicolaSquartini |

Distributions | Debian:1.0.0.1, NixOS:0.3.0.1 |

Downloads | 1195 total (5 in the last 30 days) |

Rating | (no votes yet) [estimated by rule of succession] |

Your Rating | |

Status | Docs uploaded by user Build status unknown [no reports yet] Hackage Matrix CI |

## Downloads

- tensor-0.1.tar.gz [browse] (Cabal source package)
- Package description (included in the package)