# How to flatten a tensor product

Say I have a tensor product of four two dimensional spaces $$\Lambda = S\otimes S\otimes S\otimes S$$. The basis of $$S$$ is CB={{1,0},{0,1}} . I generate the representation of $$\Lambda$$ by

Lambda=ArrayFlatten[
ArrayFlatten[
ArrayFlatten[
Table[TensorProduct[CB[[i]], CB[[j]], CB[[k]], CB[[m]]],
{i, 1, 2}, {j, 1, 2}, {k, 1, 2}, {m, 1, 2}]
]
]
]


The result is

$$\Lambda=\left( \begin{array}{cccccccccccccccc} 1 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 1 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 1 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 1 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 1 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 1 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 1 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 1 \\ \end{array} \right)$$

Now, I have a problem to generate the corresponding basis vectors, which I thought are given by

Flatten[ArrayFlatten[TensorProduct[CB[[i]], CB[[j]], CB[[k]], CB[[m]]]]]


for $$i,j,k,m\in\{1,2\}$$. But, e.g.

Lambda.Flatten[ArrayFlatten[TensorProduct[CB[[2]], CB[[2]], CB[[1]], CB[[1]]]]]


results in the null vector. How to generate the correct basis vectors using ArrayFlatten[] or Flatten[]?

The basis vectors are

CB = {{1, 0}, {0, 1}};
Flatten@*KroneckerProduct @@@ Tuples[CB, 4]

(*    {{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}}    *)


I'm not sure what your matrix $$\Lambda$$ is: you said it was a vector space, but matrices are rather elements of this vector space, not the space itself.

I've written a book covering this topic: see chapter 2 of Using Mathematica for Quantum Mechanics: A Student's Manual.

• My problem is: how do I write e.g. the vector a=TensorProduct[CB[[1]],CB[[2]],CB[[1]],C[[1]]] in the same basis as Lambda, i.e., which of the basis vectors you wrote is a? Thank you for the link, I’ll have a look! – pawel_winzig Nov 4 '19 at 22:02
• a = Flatten@KroneckerProduct[CB[[1]], CB[[2]], CB[[1]], CB[[1]]] gives the basis vector {0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}. – Roman Nov 5 '19 at 21:29
• Shoudn't $\Lambda$ be in this case not a diagonal matrix? – pawel_winzig Nov 6 '19 at 7:45
• Again, Λ is a vector space, not a matrix. – Roman Nov 6 '19 at 13:55
• It seems my description of the question is misleading: See $\Lambda$ as an operator acting on four spins. The matrix is the representation of this operator. – pawel_winzig Nov 6 '19 at 16:24