Skip to content

Instantly share code, notes, and snippets.

@arvsrao
Last active July 28, 2023 04:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arvsrao/dd53f7ff7b73ba41ae581417e2f3fdc7 to your computer and use it in GitHub Desktop.
Save arvsrao/dd53f7ff7b73ba41ae581417e2f3fdc7 to your computer and use it in GitHub Desktop.
from sympy import Matrix
from sympy.abc import a,b
from sympy.physics.quantum import TensorProduct
A = Matrix([[a, -b, 0],
[b, a, 0],
[0, 0, 1]])
#Embedding into tensor space.
E = Matrix([[1, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 0, 1]])
#Project from tensor space back into the space where variables commute.
S = Matrix([[1, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0],
[0, 1, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0],
[0, 0, 0, 0, 1, 0],
[0, 0, 0, 1, 0, 0],
[0, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 0, 1]])
PTwoRepN = S.transpose() * TensorProduct(A,A) * E
S3 = Matrix([[1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0, 0, 0, 0, 0 ],
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0 ],
[0, 0, 0, 0, 1, 0, 0, 0, 0, 0 ],
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ],
[0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ],
[0, 1, 0, 0, 0, 0, 0, 0, 0, 0 ],
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0 ],
[0, 0, 0, 1, 0, 0, 0, 0, 0, 0 ],
[0, 0, 0, 0, 0, 1, 0, 0, 0,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