Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kdungs/cpp-paulimagic
Something with tensors and Pauli-matrices.
https://github.com/kdungs/cpp-paulimagic
physics
Last synced: 25 days ago
JSON representation
Something with tensors and Pauli-matrices.
- Host: GitHub
- URL: https://github.com/kdungs/cpp-paulimagic
- Owner: kdungs
- License: mit
- Created: 2015-03-25T14:58:19.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-04-12T08:31:17.000Z (over 9 years ago)
- Last Synced: 2023-03-24T18:56:11.875Z (almost 2 years ago)
- Topics: physics
- Language: C++
- Homepage:
- Size: 310 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Pauli Magic :sparkles: [![Build Status](https://travis-ci.org/kdungs/cpp-paulimagic.svg)](https://travis-ci.org/kdungs/cpp-paulimagic) [![Coverage Status](https://coveralls.io/repos/kdungs/cpp-paulimagic/badge.svg?branch=master)](https://coveralls.io/r/kdungs/cpp-paulimagic?branch=master)
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](https://github.com/McUrbn) for his Bachelor thesis. I merely implemented his ideas.
## Background
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](https://en.wikipedia.org/wiki/Pauli_matrices).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
"](https://en.wikipedia.org/wiki/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.
## Usage
Here's a minimal program that calculates the trace of the product of four tensor products:
```cplusplus
#include#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