Skip to contents

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 VV is a vector space over \mathbb{R}, we denote the kk-fold product V××VV\times\cdots\times V by VkV^k. A function T:VkT\colon V^k\longrightarrow\mathbb{R} is called multilinear if for each ii with 1ik1\leqslant i\leqslant k 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 T:vkT\colon v^k\longrightarrow\mathbb{R} is called a kk-tensor on VV and the set of all kk-tensors, denoted by 𝒥k(V)\mathcal{J}^k(V), becomes a vector space (over \mathbb{R}) if for S,T𝒥k(V)S,T\in\mathcal{J}^k(V) and aa\in\mathbb{R} we define

(S+T)(v1,,vk)=S(v1,,vk)+T(v1,,vk)(aS)(v1,,vk)=aS(v1,,vk) (S+T)(v_1,\ldots,v_k) = S(v_1,\ldots,v_k) + T(v_1,\ldots,v_k) (aS)(v_1,\ldots,v_k) = a\cdot S(v_1,\ldots,v_k)

There is also an operation connecting the various spaces 𝒥(V)\mathcal{J}(V). If S𝒥k(V)S\in\mathcal{J}^k(V) and T𝒥l(V)T\in\mathcal{J}^l(V), we define the tensor product ST𝒥k+l(V)S\otimes T\in\mathcal{J}^{k+l}(V) by

ST(v1,,vk,vk+1,,vk+l)=S(v1,,vk)T(vk+1,,vk+l). S\otimes T(v_1,\ldots,v_k,v_{k+1},\ldots,v_{k+l})= S(v_1,\ldots,v_k)\cdot T(v_{k+1},\ldots,v_{k+l}).

- 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 kk-fold tensor products

ϕi1ϕik1i1,,ikn \phi_{i_1}\otimes\cdots\otimes\phi_{i_k}\qquad 1\leqslant i_1,\ldots,i_k\leqslant n

[where ϕi(vj)=δij\phi_i(v_j)=\delta_{ij},v1,,vkv_1,\ldots,v_k being a basis for VV] is a basis for 𝒥k(V)\mathcal{J}^k(V), which therefore has dimension nkn^k. Function spraycross2() evaluates the tensor product and I give examples here.

References

Hankin, Robin K. S. 2022. “Sparse Arrays in : The Package.” arXiv. https://doi.org/10.48550/ARXIV.2210.10848.
Spivak, M. 1965. Calculus on Manifolds. Addison-Wesley.