Mathematica Asked on June 3, 2021
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…otimessigma_{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!
Probably not the most efficient way to do so, but for descently sized n
, this should work well:
T[i_, list_List] := Tr[i.KroneckerProduct @@ PauliMatrix[list]]
n = 4;
ρ = RandomReal[{-1, 1}, 2^n];
A = ArrayReshape[
T[ρ, #] & /@ Tuples[Range[3], n],
ConstantArray[3, n]
];
A // Dimensions
{3, 3, 3, 3}
Answered by Henrik Schumacher on June 3, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP