tensorA (version 0.36.1)

sequencing: Working with index sequences

Description

In typical tensor notation the indices are not identified by names but by positions. The operators allow to identify names and positions transparently during calculation.

Usage

## Methods for class tensor
# x $ y
# x ^ y
# x | y
renamefirst.tensor(x,y)

Arguments

x

A tensor

y

Typically a character vector specifying a sequence of names for the tensor. The names can be specified in various ways: The following specifications are equal and specify a sequence of the names i,j and k: x$ijk, x$i.j.k, i.j.k., x"$ijk", x^"i.j.k", x^c("i","j","k"),x^c("i.j","k"), x^c("$i.j","k"),x^c("$ij","k"), x^c("$","ijk") In general names are separated by dots. All notations with \$ either as operator or as the first character of the first string allow to omit the dots assuming that all names are single character. If any dot is present all dots must be given. The difference of \$ and \^ is that the first accepts a name and the second an character valued expression. Multi letter indices like "alpha","beta","gamma" can only be given in the dot-free version of the notation making the following specifications equal: x$alpha.beta.gamma, alpha.beta.gamma., x^"$alpha.beta.gamma", x^"alpha.beta.gamma", x^c("alpha","beta","gamma"), x^c("alpha.beta","gamma"), x^c("$alpha.beta","k"), x^c("$","alpha.beta.gammak") The specification for | is equal to that for ^.

Value

A tensor of the same shape as x but with reordered dimensions (for |) or renamed dimensions (for the others)

Details

These functions are used to mimic the mathematical notation in tensor analysis. Formulae of the form (with Einstein convention): $$E_{ijk}= A_{ihl}C_{hj}C_{lk}$$ with defined tensors \(A_{ijk}\) and \(C_{ij}\) can be given the simple form E <- A$ihl %e% C$hj %e% C$lk |"$ijk" or alternatively for multi letter names: E <- A$i.h.l %e% C$h.j %e% C$l.k |"i.j.k" or more flexible in computation with arguments I,J,K: E <- A^c(I,"h.l") %e% C^c("h",J) %e% C^c("l",K) | c(I,J,K) The $ or ^ binds to the tensors with high precedence and renames the first elements. The | binds with very low precedence and reorders the tensor according to the assumed index sequence of the result afterwards.

See Also

reorder.tensor, names<-.tensor, [[.tensor

Examples

Run this code
# NOT RUN {
A <- to.tensor(1:20,c(i=5,j=2,k=2))
C <- to.tensor(1:4,c(i=2,j=2))
E <- A$ihl %e% C$hj %e% C$lk |"$ijk"
E
# Same as:
E2 <- reorder.tensor(A[[j=~h,k=~l]] %e% C[[i=~h]] %e% C[[i=~l,j=~k]],c("i","j","k"))
E-E2
E <- A$i.h.l %e% C$h.j %e% C$l.k |"i.j.k"
E
E-E2
E <- A^"i.h.l" %e% C^"h.j" %e% C^"l.k" |"i.j.k"
E
E-E2
# }

Run the code above in your browser using DataCamp Workspace