A small header-only library that can help you with traces of tensor products that contain Pauli matrices. This is based on previous work by McUrbn for his Bachelor thesis. I merely implemented his ideas.
The Pauli matrices σx, σy, σz are traceless 2×2-matrices that are defined such that σiσi=𝟙. Additionally there are the commutation relations [σaσb]=2ⅈεabcσc and the anti-commutation relations {σaσb} = 2δab𝟙. It follows directly, that for a≠b, σaσb=ⅈεabcσc. For more information see the corresponding Wikipedia article.
For the product of two tensor products (a1⊗b1) and (a2⊗b2) it holds (this is very much a simplification, for more detail check out this Wikipedia article on the "Tensor product of algebras ") that (a1⊗b1)(a2⊗b2) = (a1a2⊗b1b2). Also for traces of tensor products it holds that Tr(a⊗b) = Tr(a)Tr(b).
This program uses said relations to simplify tensor products containing Pauli matrices and ultimately calculates traces of those.
Here's a minimal program that calculates the trace of the product of four tensor products:
#include <iostream>
#include "paulimagic/tensorproduct.h"
int main() {
std::cout << (TensorProduct<4>{PM::X} * TensorProduct<4>{PM::Y} *
TensorProduct<4>{PM::Z, PM::I, PM::iI} *
TensorProduct<4>{PM::I, PM::nI}).trace() << '\n';
}
Compile it with the flags -O3 -Wall -Werror -pedantic -std=c++11 -I/path/to/cpp-paulimagic
. It should print out the result (16,0)
representing the complex number 16+0ⅈ. We can indeed verify this result by hand:
(σx⊗𝟙⊗𝟙⊗𝟙)(σy⊗𝟙⊗𝟙⊗𝟙)(σz⊗𝟙⊗ⅈ𝟙⊗𝟙)(𝟙⊗-𝟙⊗𝟙⊗𝟙) = (σxσyσz⊗-𝟙⊗ⅈ𝟙⊗𝟙) = (ⅈ𝟙⊗-𝟙⊗ⅈ𝟙⊗𝟙)
Tr(ⅈ𝟙⊗-𝟙⊗ⅈ𝟙⊗𝟙) = Tr(ⅈ𝟙)Tr(-𝟙)Tr(ⅈ𝟙)Tr(𝟙) = 2i × (-2) × 2i × 2 = 16