Ops.tensor | R Documentation |
Once a labeled array (tensor) has been defined, tensor arithmetic operations
can be carried out with the usual +
, -
, *
, /
, and ==
symbols.
## S3 method for class 'tensor'
Ops(e1, e2)
e1 , e2 |
Labeled arrays created with %_%. |
A resulting labeled array in case of +
, -
, *
, /
.
TRUE
or FALSE
in case of ==
.
Addition and subtraction requires the two tensors to have an equal index structure, i.e. the index names their position and the dimensions associated to the index names have to agree. The index order does not matter, the operation will match dimensions by index name.
Tensor multiplication takes into account implicit Ricci calculus rules depending on index placement.
Equal-named and opposite-positioned dimensions are contracted.
Equal-named and equal-positioned dimensions are subsetted.
The result is an outer product for distinct index names.
Division performs element-wise division. If the second argument is a scalar, each element is simply divided by the scalar. Similar to addition and subtraction, division requires the two tensors to have an equal index structure, i.e. the index names their position and the dimensions associated to the index names have to agree.
A tensor a_{i_1 i_2 ...}
is equal to a tensor b_{j_1 j_2 ...}
if
and only if the index structure agrees and all components are equal.
Other tensor operations:
asym()
,
kron()
,
l()
,
r()
,
subst()
,
sym()
a <- array(1:4, c(2, 2))
b <- array(3 + 1:4, c(2, 2))
# addition
a %_% .(i, j) + b %_% .(j, i)
# multiplication
a %_% .(i, j) * b %_% .(+i, k)
# division
a %_% .(i, j) / 10
# equality check
a %_% .(i, j) == a %_% .(i, j)
a %_% .(i, j) == a %_% .(j, i)
a %_% .(i, j) == b %_% .(i, j)
# this will err because index structure does not agree
try(a %_% .(i, j) == a %_% .(k, j))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.