Sums over repeated indices in an array
.
contraction(x, i = NULL, drop = TRUE)
x  indexed 

i  subset of repeated indices to sum up. If 
drop 

array
.
Guidotti, E. (2020). "calculus: High dimensional numerical and symbolic calculus in R". https://arxiv.org/abs/2101.00086
#> [1] "a + d"#> [1] 42#### tensor contraction over repeated indices x < array(1:27, dim = c(3,3,3)) index(x) < c("i","i","j") contraction(x)#> [1] 15 42 69#### tensor contraction over specific repeated indices only x < array(1:16, dim = c(2,2,2,2)) index(x) < c("i","i","k","k") contraction(x, i = "k")#> [,1] [,2] #> [1,] 14 18 #> [2,] 16 20#### tensor contraction keeping dummy dimensions x < array(letters[1:16], dim = c(2,2,2,2)) index(x) < c("i","i","k","k") contraction(x, drop = FALSE)#> [,1] [,2] #> [1,] "a" "m" #> [2,] "d" "p"