Import the sho1d.py file as well as the test_sho1d.py file
%load_ext sympy.interactive.ipythonprinting
from sympy import *
from IPython.display import display_pretty
from sympy.physics.quantum import *
from sympy.physics.quantum.sho1d import *
from sympy.physics.quantum.tests.test_sho1d import *
Create a raising and lowering operator and make sure they print correctly
ad = RaisingOp('a')
a = LoweringOp('a')
ad
a
print latex(ad)
print latex(a)
display_pretty(ad)
display_pretty(a)
print srepr(ad)
print srepr(a)
print repr(ad)
print repr(a)
Create a simple harmonic state and check its printing
k = SHOKet('k')
b = SHOBra('b')
k
b
print pretty(k)
print pretty(b)
print latex(k)
print latex(b)
print srepr(k)
print srepr(b)
Take the dagger of the raising and lowering operators. They should return eachother.
Dagger(ad)
Dagger(a)
Check Commutators of the raising and lowering operators
Commutator(ad,a).doit()
Commutator(a,ad).doit()
Take a look at the dual states of the bra and ket
k.dual
b.dual
Taking the InnerProduct of the bra and ket will return the KroneckerDelta function
InnerProduct(b,k).doit()
Take a look at how the raising and lowering operators act on states. We use qapply to apply an operator to a state
qapply(ad*k)
qapply(a*k)
But the states may have an explicit energy level. Let's look at the ground and first excited states
kg = SHOKet(0)
kf = SHOKet(1)
qapply(ad*kg)
qapply(ad*kf)
qapply(a*kg)
qapply(a*kf)
Notice that akg is 0 and akf is the |0> the ground state.
Let's look at the Number Operator and Hamiltonian Operator
k = SHOKet('k')
ad = RaisingOp('a')
a = LoweringOp('a')
N = NumberOp('N')
H = Hamiltonian('H')
The number operator is simply expressed as ad*a
N().rewrite('a').doit()
The number operator expressed in terms of the position and momentum operators
N().rewrite('xp').doit()
It can also be expressed in terms of the Hamiltonian operator
N().rewrite('H').doit()
The Hamiltonian operator can be expressed in terms of the raising and lowering operators, position and momentum operators, and the number operator
H().rewrite('a').doit()
H().rewrite('xp').doit()
H().rewrite('N').doit()
The raising and lowering operators can also be expressed in terms of the position and momentum operators
ad().rewrite('xp').doit()
a().rewrite('xp').doit()
Let's take a look at how the NumberOp and Hamiltonian act on states
qapply(N*k)
Apply the Number operator to a state returns the state times the ket
ks = SHOKet(2)
qapply(N*ks)
qapply(H*k)
Let's see how the operators commute with each other
Commutator(N,ad).doit()
Commutator(N,a).doit()
Commutator(N,H).doit()
We can express the operators in NumberOp basis. There are different ways to create a matrix in Python, we will use 3 different ways.
represent(ad, basis=N, ndim=4, format='sympy')
represent(ad, basis=N, ndim=5, format='numpy')
represent(ad, basis=N, ndim=4, format='scipy.sparse', spmatrix='lil')
print represent(ad, basis=N, ndim=4, format='scipy.sparse', spmatrix='lil')
The same can be done for the other operators
represent(a, basis=N, ndim=4, format='sympy')
represent(N, basis=N, ndim=4, format='sympy')
represent(H, basis=N, ndim=4, format='sympy')
k0 = SHOKet(0)
k1 = SHOKet(1)
b0 = SHOBra(0)
b1 = SHOBra(1)
print represent(k0, basis=N, ndim=5, format='sympy')
print represent(k1, basis=N, ndim=5, format='sympy')
print represent(b0, basis=N, ndim=5, format='sympy')
print represent(b1, basis=N, ndim=5, format='sympy')