Function `spraycross()` function in the `spray` package
Robin K. S. Hankin
Source:vignettes/spraycross.Rmd
spraycross.Rmd
spraycross
function (S, ...)
{
if (nargs() < 3) {
spraycross2(S, ...)
}
else {
spraycross2(S, Recall(...))
}
}
spraycross2
function (S1, S2)
{
M1 <- index(S1)
M2 <- index(S2)
jj <- as.matrix(expand.grid(seq_len(nrow(M1)), seq_len(nrow(M2))))
f <- function(i) {
c(M1[jj[i, 1], ], M2[jj[i, 2], ])
}
spray(t(sapply(seq_len(nrow(jj)), f)), c(outer(coeffs(S1),
coeffs(S2))))
}
To cite the spray
package in publications, please use
Hankin (2022). Function
spraycross()
returns the tensor cross product of any number
of spray
objects (interpreted as tensors);
spraycross2()
is a helper function that returns the product
of two such spray
objects.
The tensor cross product
In a memorable passage, Spivak (1965) states:
Integration on chains
If is a vector space over , we denote the -fold product by . A function is called multilinear if for each with we have
$$ T\left(v_1,\ldots, v_i + {v'}_i,\ldots, v_k\right)= T\left(v_1,\ldots,v_i,\ldots,v_k\right)+ T\left(v_1,\ldots,{v'}_i,\ldots,v_k\right),\\ T\left(v_1,\ldots,av_i,\ldots,v_k\right)=aT\left(v_1,\ldots,v_i,\ldots,v_k\right) $$
A multilinear function is called a -tensor on and the set of all -tensors, denoted by , becomes a vector space (over ) if for and we define
There is also an operation connecting the various spaces . If and , we define the tensor product by
- Michael Spivak, 1969 (Calculus on Manifolds, Perseus books). Page 75
Spivak goes on to observe that the tensor product is distributive and associative but not commutative. He then proves that the set of all -fold tensor products
[where
,
being a basis for
]
is a basis for
,
which therefore has dimension
.
Function spraycross2()
evaluates the tensor product and I
give examples here.