In [90]:
from sympy.physics.quantum import *
from sympy.physics.quantum.cartesian import *
from sympy.physics.quantum.operator import *
from sympy.physics.quantum.state import *
from sympy import *
from sympy.core.relational import *
from sympy.physics.units import degree
from sympy.abc import a, b, x, y, z, t, alpha, n, theta, h, f, lamda, i, k, w, u, d, beta, r, psi, o, l, c, gamma, phi, j, p
In [91]:
dotDummy = Dummy('.')
ketX = XKet()
ketY = Ket(y)
identity = symbols('I')
a_i, a_1, a_2, a_3, a_j = symbols('a_i a_1 a_2 a_3 a_j', complex = True)
b_j, b_1, b_2, b_3 = symbols('b_j b_1 b_2 b_3', complex = True)
psi_1, psi_2, psi_3, psi_j, psi_i = symbols('psi_1 psi_2 psi_3 psi_j psi_i')
phi_1, phi_2, phi_3, phi_j, phi_i = symbols('phi_1 phi_2 phi_3 phi_j phi_i')
ketPsi = Ket(psi)
ketX_1 = Ket('x_1')
ketX_2 = Ket('x_2')
ketX_i = Ket('x_i')
ketX_j = Ket('x_j')
braPsi = Bra(psi)
braX_1 = Bra('x_1')
braX_2 = Bra('x_2')
braX_i = Bra('x_i')
braX_j = Bra('x_j')
x_i = symbols('x_i')
prob = Function('P')
ketPhi = Ket(phi)
braPhi = Bra(phi)
braX_j = Bra('x_j')
ketU = Ket(u)
ketD = Ket(d)
braU = Bra(u)
braD = Bra(d)
ketR = Ket(r)
H = HermitianOperator('H')
X = HermitianOperator('X')
uFunc = Function('u')(x)
vFunc = Function('v')(x)
K = HermitianOperator('K')
blankSpace = Dummy(' ')
momentumOperator = HermitianOperator('P')
positionOperator = HermitianOperator('x')
M1 = Operator('M_1')
M2 = Operator('M_2')
ketA = Ket('a')
ketB = Ket('b')
In [92]:
ketXExpanded = Matrix([[1],[0]])
display(ketXExpanded)
ketYExpanded = Matrix([[0],[1]])
display(ketYExpanded)
In [93]:
ket45 = Ket(45*degree)
display(ket45)
ket45Expanded = ketXExpanded/sqrt(2) + ketYExpanded/sqrt(2)
display(ket45Expanded)
In [94]:
valOfKet45 = Eq(ket45,
Eq(ket45Expanded,
Add(Mul(ket45Expanded[0],
ketX,
evaluate = False),
Mul(ket45Expanded[1],
ketY,
evaluate = False),
evaluate = False),
evaluate = False),
evaluate = False)
display(valOfKet45)
In [95]:
valOfKetPsi = Eq(ketPsi,
a_1 * ketX_1 + a_2 * ketX_2,
evaluate = False)
display(valOfKetPsi)
In [96]:
valOfKetPsi = Eq(ketPsi,
Sum(a_i * ketX_i, (i, 1, n)),
evaluate = False)
display(valOfKetPsi)
In [97]:
valOfKetPsiExpanded = Eq(Eq(ketPsi,
Matrix([[a_1], [a_2], [a_3], [dotDummy], [dotDummy], [dotDummy]]),
evaluate = False),
Matrix([[psi_1], [psi_2], [psi_3], [dotDummy], [dotDummy], [dotDummy]]),
evaluate = False)
display(valOfKetPsiExpanded)
In [98]:
ProbOfX_i = Eq(Eq(prob(x_i), Abs(a_i)**2), Mul(a_i, conjugate(a_i)), evaluate = False)
display(ProbOfX_i)
In [99]:
valOfKetPhi = Eq(ketPhi,
Sum(b_j * ketX_j, (j, 1, n)),
evaluate = False)
display(valOfKetPhi)
In [100]:
valOfBraPhi = Eq(braPhi,
Sum(conjugate(b_j) * braX_j, (j, 1, n)),
evaluate = False)
display(valOfBraPhi)
In [101]:
InnerProductOfPhi_Psi = Eq(InnerProduct(braPhi, ketPsi),
Mul(valOfBraPhi.rhs, valOfKetPsi.rhs),
evaluate = False)
display(InnerProductOfPhi_Psi)
In [102]:
InnerProductOfPhi_Psi = Eq(InnerProduct(braPhi, ketPsi),
Sum(conjugate(b_j) * a_i * InnerProduct(braX_j, ketX_i), (i, 1, n), (j, 1, n)),
evaluate = False)
display(InnerProductOfPhi_Psi)
In [103]:
ketUExpanded = Matrix([[1],[0]])
display(ketUExpanded)
braUExpanded = conjugate(ketUExpanded.T)
display(braUExpanded)
ketDExpanded = Matrix([[0],[1]])
display(ketDExpanded)
braDExpanded = conjugate(ketDExpanded.T)
display(braDExpanded)
In [104]:
ketRExpanded = Matrix([[1/sqrt(2)],[1/sqrt(2)]])
display(ketRExpanded)
In [105]:
valOfKetR = Eq(ketR,
Add(Mul(ketRExpanded[0], ketU, evaluate = False), Mul(ketRExpanded[1], ketD, evaluate = False), evaluate = False),
evaluate = False)
display(valOfKetR)
In [106]:
innerprodOfU_R = Eq(Eq(Abs(InnerProduct(braU, ketR), evaluate = False)**2,
Abs(MatMul(braUExpanded, ketRExpanded), evaluate = False)**2,
evaluate = False),
(Abs(braUExpanded * ketRExpanded)**2).simplify(),
evaluate = False)
display(innerprodOfU_R)
In [107]:
valOfKetPsi = Eq(ketPsi,
Sum(a_i * ketX_i, (i, 1, n)),
evaluate = False)
display(valOfKetPsi)
In [108]:
innerprodOfX_i_Psi = Eq(InnerProduct(braX_j, ketPsi), Mul(braX_j, valOfKetPsi.rhs))
display(innerprodOfX_i_Psi)
In [109]:
innerprodOfX_i_Psi = Eq(InnerProduct(braX_j, ketPsi), Sum(a_i * InnerProduct(braX_j, ketX_i), (i, 1, n), (j, 1, n)))
display(innerprodOfX_i_Psi)
In [110]:
innerprodOfX_i_Psi = Eq(Eq(InnerProduct(braX_j, ketPsi), Sum(a_j, (j, 1, n))), psi_j)
display(innerprodOfX_i_Psi)
In [111]:
identityExpanded = Identity(3).as_explicit()
In [112]:
valOfIdentity = Eq(identity, identityExpanded, evaluate = False)
display(valOfIdentity)
In [113]:
prodOfIdentity_KetPsi = Eq(identity * ketPsi, ketPsi)
display(prodOfIdentity_KetPsi)
In [114]:
identityExpanded = Identity(2).as_explicit()
ketPsiExpanded = Matrix([[a],[b]])
In [115]:
prodOfiExpanded_ketPsiExpanded = Eq(MatMul(identityExpanded, ketPsiExpanded), ketPsiExpanded)
display(prodOfiExpanded_ketPsiExpanded)
In [116]:
innerprodOfU_U = Eq(InnerProduct(braU,
ketU),
(Abs(braUExpanded * ketUExpanded)**2)[0],
evaluate = False)
display(innerprodOfU_U)
In [117]:
outerprodOfU_U = Eq(Eq(OuterProduct(ketU,
braU),
MatMul(ketUExpanded,
braUExpanded),
evaluate = False),
ketUExpanded * braUExpanded,
evaluate = False)
display(outerprodOfU_U)
In [118]:
outerprodOfD_D = Eq(Eq(OuterProduct(ketD,
braD),
MatMul(ketDExpanded,
braDExpanded),
evaluate = False),
ketDExpanded * braDExpanded,
evaluate = False)
display(outerprodOfD_D)
In [119]:
AddOfOuterprodOfD_D_OuterprodOfU_U = Eq(Eq(Eq(MatAdd(ketUExpanded * braUExpanded,
ketDExpanded * braDExpanded,
evaluate = False),
ketUExpanded * braUExpanded + ketDExpanded * braDExpanded),
identity),
Sum(ketX_i*braX_i,
(i, 1, n)),
evaluate = False)
display(AddOfOuterprodOfD_D_OuterprodOfU_U)
In [120]:
valOfIdentity = Eq(identity, Sum(ketX_i*braX_i,(i, 1, n)),evaluate = False)
display(valOfIdentity)
In [121]:
prodOfIdentity_KetPsi = Eq(identity * ketPsi, ketPsi)
display(prodOfIdentity_KetPsi)
In [122]:
prodOfIdentity_KetPsi = Eq(Sum(ketX_i * InnerProduct(braX_i, ketPsi),(i, 1, n)), ketPsi)
display(prodOfIdentity_KetPsi)
In [123]:
prodOfIdentity_KetPsi = Eq(Sum(ketX_i * braX_i * Sum(a_j * ketX_j,
(j, 1, n)),
(i, 1, n)),
ketPsi)
display(prodOfIdentity_KetPsi)
In [124]:
prodOfIdentity_KetPsi = Eq(Sum(ketX_i * a_j * InnerProduct(braX_i,
ketX_j),
(i, 1, n),
(j, 1, n)),
ketPsi)
display(prodOfIdentity_KetPsi)
In [125]:
prodOfIdentity_KetPsi = Eq(Sum(ketX_i * a_j,
(i, 1, n),
(j, 1, n)),
ketPsi)
display(prodOfIdentity_KetPsi)
In [126]:
prodOfIdentity_KetPsi = Eq(Sum(ketX_j * a_j,
(j, 1, n)),
ketPsi)
display(prodOfIdentity_KetPsi)
In [127]:
prodOfH_KetPsi = Eq(H * ketPsi, lamda * ketPsi)
display(prodOfH_KetPsi)
In [128]:
prodOfH_KetPsi = Eq(braPsi * H * ketPsi, braPsi * lamda * ketPsi)
display(prodOfH_KetPsi)
In [129]:
prodOfH_KetPsi = Eq(lamda * InnerProduct(braPsi, ketPsi), lamda)
display(prodOfH_KetPsi)
In [130]:
prodOfKetPhi_H_KetPsi = braPhi * H * ketPsi
display(prodOfKetPhi_H_KetPsi)
In [131]:
prodOfH_KetPsi = Eq(conjugate(braPhi * H * ketPsi), braPsi * Dagger(H) * ketPhi)
display(prodOfH_KetPsi)
In [132]:
prodOfX_Psi = Eq(X * ketPsi, x * ketPsi)
display(prodOfX_Psi)
In [133]:
valOfKetPsi = Eq(Eq(ketPsi,
Sum(a_i * ketX_i, (i, 1, n)),
evaluate = False),
Integral(a_i, (x, -oo, oo)),
evaluate = False)
display(valOfKetPsi)
In [134]:
InnerProductOfPhi_Psi = Eq(Eq(InnerProduct(braPhi, ketPsi),
Sum(conjugate(phi_j) * psi_j, (j, 1, n)),
evaluate = False),
Integral(conjugate(phi_j) * psi_j, (x, -oo, oo)),
evaluate = False)
display(InnerProductOfPhi_Psi)
In [135]:
display(uFunc)
display(vFunc)
In [136]:
diffByParts = Eq(Derivative(uFunc * vFunc, x), Derivative(uFunc * vFunc, x).doit())
display(diffByParts)
In [137]:
intergrateByParts = Eq(Integral(Derivative(vFunc * uFunc,
x),
(x, -oo, oo)),
Integral(Derivative(uFunc * vFunc,
x).doit(),
(x, oo, -oo)).expand())
display(intergrateByParts)
In [138]:
intergrateByParts = Eq(Integral(Derivative(vFunc,
x) * uFunc,
(x, -oo, oo)),
integrate(Derivative(uFunc * vFunc
, x),
(x, -oo, oo)) - Integral(Derivative(uFunc,
x) * vFunc,
(x, -oo, oo)))
display(intergrateByParts)
In [139]:
valOfUFunc = Eq(uFunc, psi)
display(valOfUFunc)
In [140]:
valOfVFunc = Eq(vFunc, conjugate(psi))
display(valOfVFunc)
In [141]:
intergrateByParts = Piecewise((Eq(Integral(Derivative(vFunc,
x) * uFunc,
(x, -oo, oo)),
- Integral(Derivative(uFunc,
x) * vFunc,
(x, -oo, oo))),
Eq((uFunc, vFunc),
(psi, conjugate(psi)),
evaluate = False)))
display(intergrateByParts)
In [142]:
prodOfH_KetPsi = Eq(H * ketPsi, -I * Derivative(ketPsi, x))
display(prodOfH_KetPsi)
In [143]:
prodOfH_KetPhi = Eq(H * ketPhi, -I * Derivative(ketPhi, x))
display(prodOfH_KetPhi)
In [144]:
proofOfHermitian = Eq(braPsi * H * ketPhi, conjugate(braPhi * H * ketPhi))
display(proofOfHermitian)
In [145]:
proofOfHermitian = Eq(braPsi * -I * Derivative(ketPhi, x), conjugate(braPhi * -I * Derivative(ketPsi, x)))
display(proofOfHermitian)
In [146]:
valOfBraPsi = Eq(braPsi,
Integral(conjugate(psi), (x, -oo, oo)),
evaluate = False)
display(valOfBraPsi)
In [147]:
valOfBraPhi = Eq(braPhi,
Integral(conjugate(phi), (x, -oo, oo)),
evaluate = False)
display(valOfBraPhi)
In [148]:
proofOfHermitian = Eq(-I * Integral(conjugate(psi) * Derivative(phi, x), x),
conjugate(-I * Integral(conjugate(phi) * Derivative(psi, x), x)))
display(proofOfHermitian)
In [149]:
proofOfHermitian = Eq(-I * Integral(conjugate(psi) * Derivative(phi, x), x),
conjugate(I * Integral(psi * Derivative(conjugate(phi), x), x)))
display(proofOfHermitian)
In [150]:
valOfK = Eq(K, -I * Derivative(blankSpace, x))
display(valOfK)
In [151]:
prodOfK_KetPsi = Eq(K * ketPsi, k * ketPsi)
display(prodOfK_KetPsi)
In [152]:
prodOfK_KetPsi = Eq(-I * Derivative(ketPsi, x), k * ketPsi)
display(prodOfK_KetPsi)
In [153]:
prodOfK_KetPsi = Eq(Derivative(ketPsi, x), I * k * ketPsi)
display(prodOfK_KetPsi)
In [154]:
valOfKetPsi = Eq(ketPsi, exp(I*k*x))
display(valOfKetPsi)
In [155]:
valOfKetPsi = Eq(Eq(ketPsi, exp(I*k*x)), cos(k*x) + I * sin(k*x), evaluate = False)
display(valOfKetPsi)
In [156]:
valOfk = Eq(k, 2*pi/lamda)
display(valOfk)
In [157]:
deBroglieEq = Eq(lamda, h/p)
display(deBroglieEq)
In [158]:
valOfk = Eq(k, 2*pi/lamda).subs(lamda, deBroglieEq.rhs).subs(2*pi/h, 1/hbar)
display(valOfk)
In [159]:
waveFunc = Eq(ketPsi, exp(I*k*x)).subs(k, valOfk.rhs)
display(waveFunc)
In [160]:
diffOfWaveFunc = Eq(Derivative(ketPsi, x), Derivative(waveFunc.rhs, x).doit().subs(waveFunc.rhs, ketPsi))
display(diffOfWaveFunc)
In [161]:
diffOfWaveFunc = Eq(Derivative(ketPsi, x) * hbar / I,
Derivative(waveFunc.rhs, x).doit().subs(waveFunc.rhs, ketPsi) * hbar / I)
display(diffOfWaveFunc)
In [162]:
prodOfMomentumOperator_KetPsi = Eq(momentumOperator * ketPsi, p * ketPsi)
display(prodOfMomentumOperator_KetPsi)
In [163]:
valOfmomentumOperator = Eq(momentumOperator, diffOfWaveFunc.lhs.subs(ketPsi, blankSpace))
display(valOfmomentumOperator)
In [164]:
measurement1 = Eq(M1 * ketA, alpha * ketA)
display(measurement1)
In [165]:
measurement2 = Eq(M2 * ketA, beta * ketA)
display(measurement2)
In [166]:
CommutativeEq = Eq(M1 * M2 * ketA, M2 * M1 * ketA)
display(CommutativeEq)
In [167]:
CommutativeEqSimply = Eq((M1 * M2 - M2 * M1) * ketA, 0)
display(CommutativeEqSimply)
In [168]:
commutatorOfM1_M2 = Eq(Commutator(M1, M2), 0)
display(commutatorOfM1_M2)
In [169]:
commutatorOfMomentumOperator_positionOperator = Eq(Commutator(momentumOperator, positionOperator), 0)
display(commutatorOfMomentumOperator_positionOperator)
In [170]:
CommutativeEqOfMomentumOperator_positionOperator = Eq(Mul(Add(Mul(positionOperator,
momentumOperator),
- Mul(momentumOperator,
positionOperator)),
ketPsi),
Add(Mul(positionOperator,
valOfmomentumOperator.rhs.subs(blankSpace, ketPsi)),
- valOfmomentumOperator.rhs.subs(blankSpace, positionOperator * ketPsi)))
display(CommutativeEqOfMomentumOperator_positionOperator)
In [171]:
CommutativeEqOfMomentumOperator_positionOperator = Eq(Mul(Add(Mul(positionOperator,
momentumOperator),
- Mul(momentumOperator,
positionOperator)),
ketPsi),
Add(Mul(positionOperator,
valOfmomentumOperator.rhs.subs(blankSpace, ketPsi)),
- I*hbar*Add(Derivative(positionOperator, x) * ketPsi,
positionOperator * Derivative(ketPsi, x))))
display(CommutativeEqOfMomentumOperator_positionOperator)
In [172]:
CommutativeEqOfMomentumOperator_positionOperator = Eq(Mul(Add(Mul(positionOperator,
momentumOperator),
- Mul(momentumOperator,
positionOperator)),
ketPsi),
I*hbar*Derivative(positionOperator, x) * ketPsi)
display(CommutativeEqOfMomentumOperator_positionOperator)
In [173]:
CommutativeEqOfMomentumOperator_positionOperator = Eq(Mul(Add(Mul(positionOperator,
momentumOperator),
- Mul(momentumOperator,
positionOperator)),
ketPsi),
I * hbar * ketPsi)
display(CommutativeEqOfMomentumOperator_positionOperator)
In [174]:
CommutativeEqOfMomentumOperator_positionOperator = Unequality(Eq(Add(Mul(positionOperator,
momentumOperator),
- Mul(momentumOperator,
positionOperator)),
I * hbar),
0, evaluate = False)
display(CommutativeEqOfMomentumOperator_positionOperator)
In [ ]:
In [ ]: