{"id":23010801,"url":"https://github.com/kdungs/cpp-paulimagic","last_synced_at":"2025-04-02T16:45:27.375Z","repository":{"id":29337635,"uuid":"32871460","full_name":"kdungs/cpp-paulimagic","owner":"kdungs","description":"Something with tensors and Pauli-matrices.","archived":false,"fork":false,"pushed_at":"2015-04-12T08:31:17.000Z","size":317,"stargazers_count":1,"open_issues_count":2,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-08T07:25:55.377Z","etag":null,"topics":["physics"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kdungs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-25T14:58:19.000Z","updated_at":"2020-10-03T09:37:22.000Z","dependencies_parsed_at":"2022-09-06T19:30:31.754Z","dependency_job_id":null,"html_url":"https://github.com/kdungs/cpp-paulimagic","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kdungs%2Fcpp-paulimagic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kdungs%2Fcpp-paulimagic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kdungs%2Fcpp-paulimagic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kdungs%2Fcpp-paulimagic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kdungs","download_url":"https://codeload.github.com/kdungs/cpp-paulimagic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246853635,"owners_count":20844614,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["physics"],"created_at":"2024-12-15T09:42:17.442Z","updated_at":"2025-04-02T16:45:27.289Z","avatar_url":"https://github.com/kdungs.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"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)\n\nA 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.\n\n## Background\nThe Pauli matrices σ\u003csub\u003ex\u003c/sub\u003e, σ\u003csub\u003ey\u003c/sub\u003e, σ\u003csub\u003ez\u003c/sub\u003e are traceless 2×2-matrices that are defined such that σ\u003csub\u003ei\u003c/sub\u003eσ\u003csub\u003ei\u003c/sub\u003e=𝟙. Additionally there are the commutation relations [σ\u003csub\u003ea\u003c/sub\u003eσ\u003csub\u003eb\u003c/sub\u003e]=2ⅈε\u003csub\u003eabc\u003c/sub\u003eσ\u003csub\u003ec\u003c/sub\u003e and the anti-commutation relations {σ\u003csub\u003ea\u003c/sub\u003eσ\u003csub\u003eb\u003c/sub\u003e} = 2δ\u003csub\u003eab\u003c/sub\u003e𝟙. It follows directly, that for a≠b, σ\u003csub\u003ea\u003c/sub\u003eσ\u003csub\u003eb\u003c/sub\u003e=ⅈε\u003csub\u003eabc\u003c/sub\u003eσ\u003csub\u003ec\u003c/sub\u003e. For more information see [the corresponding Wikipedia article](https://en.wikipedia.org/wiki/Pauli_matrices).\n\nFor the product of two tensor products (a\u003csub\u003e1\u003c/sub\u003e⊗b\u003csub\u003e1\u003c/sub\u003e) and (a\u003csub\u003e2\u003c/sub\u003e⊗b\u003csub\u003e2\u003c/sub\u003e) it holds (_this is very much a simplification, for more detail check out [this Wikipedia article on the \"Tensor product of algebras\n\"](https://en.wikipedia.org/wiki/Tensor_product_of_algebras)_) that (a\u003csub\u003e1\u003c/sub\u003e⊗b\u003csub\u003e1\u003c/sub\u003e)(a\u003csub\u003e2\u003c/sub\u003e⊗b\u003csub\u003e2\u003c/sub\u003e) = (a\u003csub\u003e1\u003c/sub\u003ea\u003csub\u003e2\u003c/sub\u003e⊗b\u003csub\u003e1\u003c/sub\u003eb\u003csub\u003e2\u003c/sub\u003e). Also for traces of tensor products it holds that Tr(a⊗b) = Tr(a)Tr(b).\n\nThis program uses said relations to simplify tensor products containing Pauli matrices and ultimately calculates traces of those.\n\n## Usage\n\nHere's a minimal program that calculates the trace of the product of four tensor products:\n```cplusplus\n#include \u003ciostream\u003e\n\n#include \"paulimagic/tensorproduct.h\"\n\nint main() {\n  std::cout \u003c\u003c (TensorProduct\u003c4\u003e{PM::X} * TensorProduct\u003c4\u003e{PM::Y} *\n                TensorProduct\u003c4\u003e{PM::Z, PM::I, PM::iI} *\n                TensorProduct\u003c4\u003e{PM::I, PM::nI}).trace() \u003c\u003c '\\n';\n}\n```\n\nCompile 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:\n\n(σ\u003csub\u003ex\u003c/sub\u003e⊗𝟙⊗𝟙⊗𝟙)(σ\u003csub\u003ey\u003c/sub\u003e⊗𝟙⊗𝟙⊗𝟙)(σ\u003csub\u003ez\u003c/sub\u003e⊗𝟙⊗ⅈ𝟙⊗𝟙)(𝟙⊗-𝟙⊗𝟙⊗𝟙)\n = (σ\u003csub\u003ex\u003c/sub\u003eσ\u003csub\u003ey\u003c/sub\u003eσ\u003csub\u003ez\u003c/sub\u003e⊗-𝟙⊗ⅈ𝟙⊗𝟙)\n = (ⅈ𝟙⊗-𝟙⊗ⅈ𝟙⊗𝟙)\n \nTr(ⅈ𝟙⊗-𝟙⊗ⅈ𝟙⊗𝟙) = Tr(ⅈ𝟙)Tr(-𝟙)Tr(ⅈ𝟙)Tr(𝟙) =  2i × (-2) × 2i × 2 = 16\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkdungs%2Fcpp-paulimagic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkdungs%2Fcpp-paulimagic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkdungs%2Fcpp-paulimagic/lists"}