7

I want to compute a partial trace using formula

$\rho_A=\sum\langle B|\rho_{AB}|B\rangle$ .

Example,

$\rho_{AB}= $$ \begin{pmatrix} a & b & c & d\\ e & f & g & h\\ i & j & k & l\\ m & n & o & p \end{pmatrix} $

I try to evaluate

MatrixForm[
 Sum[
   TensorProduct[{{a, b, c, d}, {e, f, g, h}, {i, j, k, l}, {m, n, o, p}}, (q*r)], 
   {1, 2}]]

but Mathematica returns the expression unevaluated.

The output is wrong. I am not sure whether the operator should be TensorProduct or Cross.

I expected to get

$\rho_{A}= $$ \begin{pmatrix} a +f & c+h\\ i+n & k+p\\ \end{pmatrix} $

glS
  • 7,623
  • 1
  • 21
  • 61
munirah
  • 171
  • 2
  • 10

2 Answers2

10

Your example can be achieved using Map with a level specification, Partition to generate the sub-matrices and Tr to calculate the traces.

ClearAll[a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p]
r = {{a, b, c, d}, {e, f, g, h}, {i, j, k, l}, {m, n, o, p}};

Map[Tr, Partition[r, {2, 2}], {2}]

{{a + f, c + h}, {i + n, k + p}}

MikeLimaOscar
  • 3,456
  • 17
  • 29
8

You can achieve this by partitioning your matrix and performing a tensor contraction. To be clear, having: $$ \rho_{AB} = \sum_{ijkl} \rho_{ij}^{kl} | ij \rangle \langle kl |$$ the partial trace over $B$ may be defined as: $$ \mathrm{tr}_B \rho_{AB} = \sum_{jl} |j\rangle \langle l| \sum_m \rho_{mj}^{ml}, $$ which is a tensor contraction. You have written $\rho$ as a matrix (or a two-indexed tensor), so first you need to partition it:

rhop = ArrayReshape[rho, {2, 2, 2, 2}];

Now rhop[[i,j,k,l]] will give you $\rho_{ij}^{kl}$. Then the tensor contraction is easily done by Mathematica's libraries:

rhoc = TensorContract[rhop, {2, 4}]; rhoc//TeXForm

This yields $$\left(\begin{array}{cc} a+f & c+h \\ i+n & k+p \\\end{array}\right). $$ Similarly, if you wanted to take the partial trace over $A$, you just need to contract the first indices:

rhod = TensorContract[rhop, {1, 3}]; rhod // TeXForm

Which returns:

$$ \left( \begin{array}{cc} a+k & b+l \\ e+o & f+p \\ \end{array} \right). $$

Note that using Partition yields a slightly different tensor than ArrayReshape, but you can convert one in another by performing a TensorTranspose over the indices 2 and 3.

Javier Garcia
  • 297
  • 2
  • 6