The following code takes a vector x
of variable length, computes the outer product of the vector with itself to form the matrix $\rho$ of dimension $2^n \times 2^n$. The function T[i_, list_List]
then computes elements of a tensor $\mathcal{T}$ of rank $n$ according to
$$T_{\mu_1,...,\mu_n}=\text{Tr}(\rho \;\; \sigma_{\mu_1}\otimes...\otimes\sigma_{\mu_n})$$
with $\mu_1,...,\mu_n=1,2,3$ and $\sigma_i$ being the three Pauli Matrices.
OuterVectorProduct[x_] := KroneckerProduct[x, x]
T[i_, list_List] :=
FullSimplify[Tr[i.KroneckerProduct @@ PauliMatrix[list]]]
That is: T[rho,{1,1}]
outputs the $T_{11}$ element of the Tensor $\mathcal T$ with respect to some matrix $\rho$.
I would now like to write a function that outputs the entire tensor. To do so, I need to extract the number of arguments within the list in the function T[i_,list_List]
.
That is, in our example T[rho,{1,1}]
, I need to extract the number of arguments in the curly braces.
How does one do that?
Thanks!