Created
October 27, 2010 05:05
-
-
Save ellisonbg/648484 to your computer and use it in GitHub Desktop.
Simple Demos for sympy.physics.quantum and friends
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sympy.physics.quantum import * | |
from sympy.physics.cartesian import * | |
from sympy.physics.piab import * | |
from sympy.physics.spin import * | |
# Basic manipulations with operators, bras, kets and commutators | |
psi, phi = Ket('psi'), Ket('phi') | |
psi, phi | |
A, B, C = Operator('A'), Operator('B'), Operator('C') | |
Dagger(phi)*Commutator(2*A+B,I*C)*psi | |
_.expand(commutator=True) # '_' = last result | |
_.doit().expand() | |
Dagger(_) | |
# Basic 1D position and momentum | |
Commutator(X, Px) | |
_.doit() | |
Commutator(X, X) | |
X**2*XKet('y') | |
apply_operators(_) | |
XBra('xp')*XKet('x') | |
_.doit() | |
# The 1D PIAB | |
H = PIABHamiltonian('H') | |
boxket = PIABKet('n') | |
H*boxket | |
apply_operators(_) | |
represent(boxket, X) | |
# Spin commutation relations and operator identities | |
Commutator(Jx, Jy) | |
_.doit() | |
Commutator(J2, Jz) | |
_.doit() | |
Dagger(Jx), Dagger(Jy), Dagger(Jz) | |
J2.rewrite('plusminus') | |
# A crazy tensor product representation | |
H = TensorProduct(Jx,Jx)+TensorProduct(Jy,Jy)+TensorProduct(Jz, Jz) | |
H | |
represent(H, Jz, j=Rational(1,2)) | |
# Applying spin operators and looking at R | |
k = JzKet(('j','m')) | |
Jx*k | |
apply_operators(_) | |
Jplus*Jminus*k | |
apply_operators(_) | |
# Rotation operator | |
R = Rotation((0, pi/2, 0)) # Rotation operator (Wigner D-Function) | |
R | |
represent(R, Jz, j=Rational(1,2)) # Represent for j=1/2 | |
represent(R, Jz, j=1) # Now for j=1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment