contraction {calculus}R Documentation

Numerical and Symbolic Tensor Contraction

Description

Sums over repeated indices in an array.

Usage

contraction(x, i = NULL, drop = TRUE)

Arguments

x

indexed array. See index.

i

subset of repeated indices to sum up. If NULL, the summation takes place on all the repeated indices.

drop

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

Value

array.

References

Guidotti, E. (2020). "calculus: High dimensional numerical and symbolic calculus in R". https://arxiv.org/abs/2101.00086

See Also

Other tensor algebra: delta(), diagonal(), einstein(), epsilon(), index()

Examples

### matrix trace
x <- matrix(letters[1:4], nrow = 2)
contraction(x)

### tensor trace
x <- array(1:27, dim = c(3,3,3))
contraction(x)

#### tensor contraction over repeated indices
x <- array(1:27, dim = c(3,3,3))
index(x) <- c("i","i","j")
contraction(x)

#### 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")

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


[Package calculus version 0.3.1 Index]