C++ Tensor Template Library (TTL)

This is an attempt to build a library using algebra definitions. This means we need an underlying set (represented as class), several operations defined on this set, which we will denote with arithmetic signs +,-,*,/, as well as zero and unary element on this set and means to compare two elements from the set.

The above rools are fulfilled by standard numeric types and classes and they are easy to implement in user classes. It is also planned to add such useful classes to the library.

The same rools are used to build vector / matrix / tensor algebras in the library. This allows simple and intuitive notation for different linear algebra problems.

Strict compile time type-safe checking should include vector / matrix / tensor dimensions.

Two twin classes Ket<C,U,D> and Bra<C,U,D> represent vectors with components of type C and dimension D. Class Ket<C,U,D> corresponds to upper tensor index, or matrix rows, and class Bra<C,U,D> corresponds to lower tensor index or matrix columns.

Class U is the class of tensor elements, which is used as terminal class for template recursions. All standard numerical types can be used, as well as other classes, which fulfill certain requirements.

Minimum requirements for user defined class (to create additive group):

- constructor, which takes 0 as argument to produce zero element;
- bool operator ==(const OwnClass&,const OwnClass&);
- bool operator !=(const OwnClass&,const OwnClass&);
- OwnClass operator +(const OwnClass&,const OwnClass&);
- OwnClass operator -(const OwnClass&,const OwnClass&);
- OwnClass operator -(const OwnClass&);

Additional requirements to create vector space:

- OwnClass operator *(const OwnClass&,const OwnClass&);

Additional requirements to create a ring or field:

- constructor, which takes 1 as argument to produce unary element;
- OwnClass operator /(const OwnClass&,const OwnClass&);

One dimensional tensor (vector) is represented as Ket<U,U,D>, i.e. class U is used as class C. Tensors of higher dimensions are created using another Ket or Bra class as class C, e.g. matrix is represented as Ket<Bra<U,U,D>,U,D>.

Operations are divided into several groups. The compiler will allow operations from the group, if corresponding operations on the class U are defined.

Comparison for Ket<C,U,D> (dual for Bra<C,U,D>).

- a
^{i}== b^{i} - a
^{i}!= b^{i}

Additive group for Ket<C,U,D> (dual for Bra<C,U,D>).

- Zero element Ket<C,U,D>((U)0)
- a
^{i}+ b^{i}= c^{i} - a
^{i}- b^{i}= c^{i} - - b
^{i}= c^{i}

Vector space over Ket<C,U,D> (dual over Bra<C,U,D>).

- u * a
^{i}= b^{i} - u / a
^{i}= b^{i} - a
^{i}* u = b^{i} - a
^{i}/ u = b^{i}

Tensor multiplication.

- a
^{i}* b_{i}= c - a
_{i}* b^{i}= c - a
^{i}_{j}* b^{j}= c^{i} - a
_{i}^{j}* b_{j}= c_{i}

Tensor division, defines also multiplicative group on Ket<Bra<U,U,D>,U,D> (dual on Bra<Ket<U,U,D>,U,D>).

- Unary element Ket<Bra<U,U,D>,U,D>((U)1) or dual Bra<Ket<U,U,D>,U,D>((U)1)
- b
^{j}/ a^{j}_{i}= c^{i}is equivalent to a^{-1 i}_{j}* b^{j}= c^{i} - b
_{j}/ a_{j}^{i}= c_{i}is equivalent to a^{-1 }_{i}^{j}* b_{j}= c_{i}