-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Tensors whose ranks and dimensions type-inferred and type-checked.
--
-- A tensor class for Haskell that can type-infer and type-check over
-- tensor ranks and dimensions. See
-- https:github.comnushio3typelevel-tensortreemaster/example
-- for examples.
@package typelevel-tensor
@version 0.2.1
-- | A tensor algebra library. Main ingredients are :
--
-- Vec and :~ are data constructors for rank-1 tensor. This
-- is essentially a touple of objects of the same type.
--
-- Vector is a class for rank-1 tensor.
--
-- Axis is an object for accessing the tensor components.
module Data.Tensor.TypeLevel
-- | data constructor for constructing n+1-dimensional tensor from
-- n-dimensional tensor.
data (:~) (n :: * -> *) a
(:~) :: (n a) -> a -> :~ a
-- | data constructor for 0-dimensional tensor.
data Vec a
Vec :: Vec a
-- | An coordinate Axis , labeled by an integer. Axis also carries
-- v, the container type for its corresponding vector. Therefore, An axis
-- of one type can access only vectors of a fixed dimension, but of
-- arbitrary type.
newtype Axis (v :: * -> *)
Axis :: Int -> Axis
axisIndex :: Axis -> Int
-- | a component operator.
(!) :: Vector v => v a -> Axis v -> a
-- | An object that allows component-wise access.
class Traversable v => Vector v where component axis vec = case componentF axis vec of { Just x -> x Nothing -> error $ "axis out of bound: " ++ show axis }
componentF :: (Vector v, Alternative f) => Axis v -> v a -> f a
component :: Vector v => Axis v -> v a -> a
dimension :: Vector v => v a -> Int
compose :: Vector v => (Axis v -> a) -> v a
-- | VectorRing is a Vector whose components belongs to
-- C, thus providing unit vectors.
class (Vector v, C a) => VectorRing v a where unitVector axis = case unitVectorF axis of { Just x -> x Nothing -> error $ "axis out of bound: " ++ show axis }
unitVectorF :: (VectorRing v a, Alternative f) => Axis v -> f (v a)
unitVector :: VectorRing v a => Axis v -> v a
-- | Tensor contraction. Create a Vector from a function that maps
-- axis to component, then sums over the axis and returns a.
contract :: (Vector v, C a) => (Axis v -> a) -> a
-- | Type synonyms
type Vec0 = Vec
type Vec1 = :~ Vec0
type Vec2 = :~ Vec1
type Vec3 = :~ Vec2
type Vec4 = :~ Vec3
type Vec5 = :~ Vec4
type Vec6 = :~ Vec5
type Vec7 = :~ Vec6
type Vec8 = :~ Vec7
type Vec9 = :~ Vec8
type Vec10 = :~ Vec9
-- | Utility functions
vec0 :: Vec0 a
vec1 :: a -> Vec1 a
vec2 :: a -> a -> Vec2 a
vec3 :: a -> a -> a -> Vec3 a
vec4 :: a -> a -> a -> a -> Vec4 a
vec5 :: a -> a -> a -> a -> a -> Vec5 a
vec6 :: a -> a -> a -> a -> a -> a -> Vec6 a
vec7 :: a -> a -> a -> a -> a -> a -> a -> Vec7 a
vec8 :: a -> a -> a -> a -> a -> a -> a -> a -> Vec8 a
vec9 :: a -> a -> a -> a -> a -> a -> a -> a -> a -> Vec9 a
vec10 :: a -> a -> a -> a -> a -> a -> a -> a -> a -> a -> Vec10 a
instance Eq (Vec a)
instance Ord (Vec a)
instance (Eq a, Eq (n a)) => Eq (n :~ a)
instance Eq (Axis v)
instance Ord (Axis v)
instance Show (Axis v)
instance Read (Axis v)
instance (Vector v, Num a) => Num (v :~ a)
instance (C a, VectorRing v a, C (v a)) => VectorRing ((:~) v) a
instance C a => VectorRing Vec a
instance (Vector v, C a) => C (v :~ a)
instance C a => C (Vec a)
instance Vector v => Vector ((:~) v)
instance Vector Vec
instance (Applicative n, Traversable n) => Applicative ((:~) n)
instance Traversable n => Traversable ((:~) n)
instance Traversable n => Functor ((:~) n)
instance Traversable n => Foldable ((:~) n)
instance Applicative Vec
instance Traversable Vec
instance Functor Vec
instance Foldable Vec
instance (Ord (n a), Ord a) => Ord (n :~ a)
instance (Arbitrary a, Arbitrary (n a), Traversable n) => Arbitrary (n :~ a)
instance Arbitrary (Vec a)
instance (Read a, Vector ((:~) n)) => Read (n :~ a)
instance Read (Vec a)
instance (Show a, Traversable ((:~) n)) => Show (n :~ a)
instance Show (Vec a)
module Data.Tensor.TypeLevel.Axis
-- | The dimension of the vector space the axis belongs to.
dimension :: Vector v => Axis v -> Int
-- | The next axis under the Law of Cycles.
next :: Vector v => Axis v -> Axis v
-- | The previous axis under the Law of Cycles.
prev :: Vector v => Axis v -> Axis v
-- | All the axes belonging to the dimension.
all :: Vector v => Axis v -> [Axis v]
-- | All the axes belonging to the dimension, starting from the argument
-- and followed by the Law of Cycles.
allFrom :: Vector v => Axis v -> [Axis v]
-- | All the axes belonging to the dimension but the argument itself, in
-- the order of the Law of Cycles.
others :: Vector v => Axis v -> [Axis v]