safe-tensor: Dependently typed tensor algebra

[ library, math, mit ] [ Propose Tags ]

Please see the README on GitHub at

[Skip to Readme]
Versions [faq],,
Change log
Dependencies base (>=4.7 && <5), constraints (>=0.10 && <0.13), containers (==0.6.*), hmatrix (==0.20.*), mtl (==2.2.*), singletons (>=2.5 && <2.8) [details]
License MIT
Copyright 2020 Nils Alex
Author Nils Alex
Category Math
Home page
Bug tracker
Source repo head: git clone
Uploaded by nalex at 2020-07-07T18:55:17Z
Distributions NixOS:
Downloads 151 total (16 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs not available [build log]
All reported builds failed as of 2020-07-07 [all 2 reports]


  • Math
    • Math.Tensor
      • Math.Tensor.Basic
        • Math.Tensor.Basic.Area
        • Math.Tensor.Basic.Delta
        • Math.Tensor.Basic.Epsilon
        • Math.Tensor.Basic.Sym2
        • Math.Tensor.Basic.TH
      • Math.Tensor.LinearAlgebra
        • Math.Tensor.LinearAlgebra.Equations
        • Math.Tensor.LinearAlgebra.Matrix
        • Math.Tensor.LinearAlgebra.Scalar
      • Math.Tensor.Safe
        • Math.Tensor.Safe.Proofs
        • Math.Tensor.Safe.TH
        • Math.Tensor.Safe.Vector


Maintainer's Corner

For package maintainers and hackage trustees

Readme for safe-tensor-

[back to package description]


Dependently typed tensor algebra in Haskell. Useful for applications in field theory, e.g., carrying out calculations for


Tensor calculus is reflected in the type system. Let us view a tensor as a multilinear map from a product of vector spaces and duals thereof to the common field. The type of each tensor is its generalized rank, describing the vector spaces it acts on and assigning a label to each vector space. There are a few rules for tensor operations:

  • Only tensors of the same type may be added. The result is a tensor of this type.
  • Tensors may be multiplied if the resulting generalized rank does not contain repeated labels for the same (dual) vector space.
  • The contraction of a tensors removes pairs of vector space and dual vector space with the same label from the generalized rank.

It is thus impossible to perform inconsistent tensor operations.

There is also an existentially typed variant of the tensor type useful for runtime computations. These computations take place in the Error monad, throwing errors if operand types are not consistent.