I am trying to create a function called TensorBasis
that takes as input a list (thought of as a list of names of basis vectors of a vector space) and an integer d
and output the lexicographically ordered basis of the d
-fold tensor product of the vector space with itself.
For instance, the output of TensorBasis[{v1,v2},2]
should be
{ v1 [\CircleTimes] v1, v1 [\CircleTimes] v2, v2 [\CircleTimes] v1, v2 [\CircleTimes] v2 },
and so on.
I have written the following code:
TensorBasis[labels_, d_] := Module[
{dim = Length[labels], basis, j, k, indexlist, tmp},
basis = ConstantArray[0, dim^d];
tmp = ConstantArray[0, d];
For[j = 1, j <= dim^d, j++,
(* Indexlist stores the indices of the jth element of the basis for the d-fold tensor product *)
indexlist = InverseLex[dim, d, j];
(* tmp holds the list of individual factors that will make up the jth element of the basis *)
For[k = 1, k <= d, k++,
tmp[[k]] = labels[[indexlist[[k]] ]]
];
(* jth element of the basis is created by tensoring together all elements of tmp *)
basis[[j]] = Infix[tmp, "\[CircleTimes]"]
];
Return[basis]
];
The function InverseLex just gives me the appropriate list of indices for the basis element I am trying to construct. I am sure that that function is working properly. But the output is all weird. The problem is that in the output, the [CircleTimes] (i.e. tensor product) symbol is replaced by some junk: in Plain Text form it is
{Subscript[v, 1]â Subscript[v, 1],Subscript[v, 1]â Subscript[v, 2],Subscript[v, 2]â Subscript[v, 1],Subscript[v, 2]â Subscript[v, 2]}
When I use the Infix notation with "[CircleTimes]" otherwise it works fine. Why won't it work inside this function?
basis[[j]] = CircleTimes[Sequence @@ tmp]]
. $\endgroup$Sequence
command. $\endgroup$