C++ Tensor Template Library (TTL)

Specification

1.0 General

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.

2.0 Classes

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>.

3.0 Operations

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>).

• ai == bi
• ai != bi

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

• Zero element Ket<C,U,D>((U)0)
• ai + bi = ci
• ai - bi = ci
• - bi = ci

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

• u * ai = bi
• u / ai = bi
• ai * u = bi
• ai / u = bi

Tensor multiplication.

• ai * bi = c
• ai * bi = c
• aij * bj = ci
• aij * bj = ci

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)
• bj / aji = ci is equivalent to a-1 ij * bj = ci
• bj / aji = ci is equivalent to a-1 ij * bj = ci