tensorprod.Rd
Tensor products of \(k\)-tensors
tensorprod(U, ...)
tensorprod2(U1,U2)
Given a \(k\)-tensor \(S\) and an \(l\)-tensor \(T\), we can form the tensor product \(S\otimes T\), defined as
$$S\otimes T\left(v_1,\ldots,v_k,v_{k+1},\ldots, v_{k+l}\right)= S\left(v_1,\ldots v_k\right)\cdot T\left(v_{k+1},\ldots v_{k+l}\right).$$
Package idiom for this includes tensorprod(S,T)
and S %X%
T
; note that the tensor product is not commutative. Function
tensorprod()
can take any number of arguments (the result is
well-defined because the tensor product is associative); it uses
tensorprod2()
as a low-level helper function.
The functions documented here all return a spray
object.
Spivak 1961
The binary form %X%
uses uppercase X to avoid clashing with
%x%
which is the Kronecker product in base R.
(A <- ktensor(spray(matrix(c(1,1,2,2,3,3),2,3,byrow=TRUE),1:2)))
#> A linear map from V^3 to R with V=R^3:
#> val
#> 2 3 3 = 2
#> 1 1 2 = 1
(B <- ktensor(spray(10+matrix(4:9,3,2),5:7)))
#> A linear map from V^2 to R with V=R^19:
#> val
#> 16 19 = 7
#> 15 18 = 6
#> 14 17 = 5
tensorprod(A,B)
#> A linear map from V^5 to R with V=R^19:
#> val
#> 1 1 2 14 17 = 5
#> 2 3 3 14 17 = 10
#> 1 1 2 15 18 = 6
#> 2 3 3 15 18 = 12
#> 1 1 2 16 19 = 7
#> 2 3 3 16 19 = 14
A %X% B - B %X% A
#> A linear map from V^5 to R with V=R^19:
#> val
#> 2 3 3 16 19 = 14
#> 1 1 2 16 19 = 7
#> 2 3 3 15 18 = 12
#> 16 19 1 1 2 = -7
#> 1 1 2 15 18 = 6
#> 2 3 3 14 17 = 10
#> 1 1 2 14 17 = 5
#> 16 19 2 3 3 = -14
#> 15 18 2 3 3 = -12
#> 14 17 2 3 3 = -10
#> 15 18 1 1 2 = -6
#> 14 17 1 1 2 = -5
Va <- matrix(rnorm(9),3,3)
Vb <- matrix(rnorm(38),19,2)
LHS <- as.function(A %X% B)(cbind(rbind(Va,matrix(0,19-3,3)),Vb))
RHS <- as.function(A)(Va) * as.function(B)(Vb)
c(LHS=LHS,RHS=RHS,diff=LHS-RHS)
#> LHS RHS diff
#> -0.582478 -0.582478 0.000000