calculus (version 0.1.0)

einstein: Numerical and Symbolic Einstein Summation

Description

Implements the Einstein notation for summation over repeated indices.

Usage

einstein(..., drop = TRUE)

Arguments

...

arbitrary number of indexed arrays.

drop

logical. Drop summation indices? If FALSE, keep dummy dimensions.

Value

array.

See Also

index, trace

Examples

Run this code
# NOT RUN {
##################################
# A{i,j} B{j,k,k} C{k,l} D{j,k}
#

a <- array(1:10, dim = c(2,5))
b <- array(1:45, dim = c(5,3,3))
c <- array(1:12, dim = c(3,4))
d <- array(1:15, dim = c(5,3))

index(a) <- c('i','j')
index(b) <- c('j','k','k')
index(c) <- c('k', 'l')
index(d) <- c('j', 'k')

einstein(a,b,c,d)


##################################
# A{i,j} B{j,k}
#

a <- array(letters[1:6], dim = c(2,3))
b <- array(letters[1:12], dim = c(3,4))

index(a) <- c('i','j')
index(b) <- c('j','k')

einstein(a,b)

# }

Run the code above in your browser using DataCamp Workspace