sequencing: Working with index sequences

Description Usage Arguments Details Value Author(s) See Also Examples

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

1
2
3
4
5
## 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 ^.

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.

Value

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

Author(s)

K. Gerald van den Boogaart

See Also

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
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

tensorA documentation built on Nov. 20, 2020, 9:07 a.m.

Related to sequencing in tensorA...