In [1]:
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 *
from sympy.abc import a, b, x, y, z, t, alpha, n, theta, h, f, lamda, i, k, w, beta
In [2]:
def listAttr(obj, s = None):
if s:
return [x for x in dir(obj) if s.lower() in x.lower()]
return [x for x in dir(obj) if x[0] != "_"]
pass
In [3]:
ketA = Ket('a')
display(ketA)
ketB = Ket('b')
display(ketB)
In [4]:
braA = Bra('a')
display(braA)
braB = Bra('b')
display(braB)
In [5]:
ketA_i = Ket('a_i')
display(ketA_i)
ketA_k = Ket('a_k')
display(ketA_k)
In [6]:
braA_i = Bra('a_i')
display(braA_i)
braA_k = Bra('a_k')
display(braA_k)
In [7]:
innerprodOfEigenvect = Piecewise(
(Eq(InnerProduct(braA_i, ketA_k), 1)
, Eq(i, k)),
(Eq(InnerProduct(braA_i, ketA_k), 0)
, Unequality(i, k))
, evaluate = False)
display(innerprodOfEigenvect)
In [8]:
H = HermitianOperator('H')
lambdaA = symbols('lambda_a')
lambdaB = symbols('lambda_b')
In [9]:
systemA = Eq(H * ketA, lambdaA * ketA)
display(systemA)
In [10]:
systemB = Eq(H * ketB, lambdaB * ketB)
display(systemB)
In [11]:
innerprodOfBraBsystemA = Eq(braB * H * ketA, lambdaA * InnerProduct(braB, ketA))
display(innerprodOfBraBsystemA)
In [12]:
innerprodOfBraAsystemB = Eq(braA * H * ketB, lambdaB * InnerProduct(braA, ketB))
display(innerprodOfBraAsystemB)
In [13]:
innerprodOfAB = Eq(conjugate(InnerProduct(braA, ketB), evaluate = False), InnerProduct(braB, ketA), evaluate = False)
display(innerprodOfAB)
In [14]:
conjInnerprodOfBraAsystemB = Eq(braB * H * ketA, conjugate(lambdaB * InnerProduct(braA, ketB)))
display(conjInnerprodOfBraAsystemB)
In [15]:
differenceOf_ConjInnerprodOfBraAsystemB_InnerprodOfBraBsystemA = Eq(
braB * H * ketA- braB * H * ketA,
(lambdaA * InnerProduct(
braB,
ketA) - conjugate(
lambdaB * InnerProduct(
braA,
ketB))).simplify())
display(differenceOf_ConjInnerprodOfBraAsystemB_InnerprodOfBraBsystemA)
In [16]:
ketX = XKet()
ketY = Ket(y)
braX = XBra()
braY = Bra(y)
In [17]:
ketXExpanded = Matrix([[1],[0]])
display(ketXExpanded)
braXExpanded = conjugate(ketXExpanded.T)
display(braXExpanded)
In [18]:
ketYExpanded = Matrix([[0],[1]])
display(ketYExpanded)
braYExpanded = conjugate(ketYExpanded.T)
display(braYExpanded)
In [19]:
ket0 = Ket(0*degree)
display(ket0)
bra0 = Bra(0*degree)
display(bra0)
In [20]:
ket0Expanded = ketXExpanded
display(ket0Expanded)
bra0Expanded = ket0Expanded.T
display(bra0Expanded)
In [21]:
ket90 = Ket(90*degree)
display(ket90)
bra90 = Bra(90*degree)
display(bra90)
In [22]:
ket90Expanded = ketYExpanded
display(ket90Expanded)
bra90Expanded = ket90Expanded.T
display(bra90Expanded)
In [23]:
ket45 = Ket(45*degree)
display(ket45)
bra45 = Bra(45*degree)
display(bra45)
In [24]:
ket45Expanded = ketXExpanded/sqrt(2) + ketYExpanded/sqrt(2)
display(ket45Expanded)
bra45Expanded = conjugate(ket45Expanded.T)
display(bra45Expanded)
In [25]:
ket135 = Ket(135*degree)
display(ket135)
bra135 = Bra(135*degree)
display(bra135)
In [26]:
ket135Expanded = ketXExpanded/sqrt(2) - ketYExpanded/sqrt(2)
display(ket135Expanded)
bra135Expanded = conjugate(ket135Expanded.T)
display(bra135Expanded)
In [27]:
valOfKet0 = Eq(ket0,
Eq(ket0Expanded,
Add(Mul(ket0Expanded[0], ketX, evaluate = False), Mul(ket0Expanded[1], ketY, evaluate = False), evaluate = False),
evaluate = False),
evaluate = False)
display(valOfKet0)
In [28]:
valOfKet90 = Eq(ket90,
Eq(ket90Expanded,
Add(Mul(ket90Expanded[0], ketX, evaluate = False), Mul(ket90Expanded[1], ketY, evaluate = False), evaluate = False),
evaluate = False),
evaluate = False)
display(valOfKet90)
In [29]:
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 [30]:
valOfKet135 = Eq(ket135,
Eq(ket135Expanded,
Add(Mul(ket45Expanded[0], ketX, evaluate = False), Mul(ket45Expanded[1], ketY, evaluate = False), evaluate = False),
evaluate = False),
evaluate = False)
display(valOfKet135)
In [31]:
kettheta = Ket(theta)
display(kettheta)
bratheta = Bra(theta)
display(bratheta)
In [32]:
ketthetaExpanded = alpha * ketXExpanded + beta * ketYExpanded
display(ketthetaExpanded)
brathetaExpanded = conjugate(ketthetaExpanded.T)
display(brathetaExpanded)
In [33]:
valOfKettheta = Eq(kettheta,
Eq(ketthetaExpanded,
ketthetaExpanded[0] * ketX + ketthetaExpanded[1] * ketY,
evaluate = False),
evaluate = False)
display(valOfKettheta)
In [34]:
ketthetaExpanded = (alpha * ketXExpanded + beta * ketYExpanded).subs(alpha, cos(theta)).subs(beta, sin(theta))
display(ketthetaExpanded)
brathetaExpanded = conjugate(ketthetaExpanded.T).subs(conjugate(theta), theta)
display(brathetaExpanded)
In [35]:
valOfKettheta = Eq(kettheta,
Eq(ketthetaExpanded,
ketthetaExpanded[0] * ketX + ketthetaExpanded[1] * ketY,
evaluate = False),
evaluate = False)
display(valOfKettheta)
In [36]:
eField = symbols('E')
In [37]:
eFieldExpanded = Eq(eField, h*f)
display(eFieldExpanded)
In [38]:
ketnegtheta = Ket(-theta)
display(ketnegtheta)
branegtheta = Bra(-theta)
display(branegtheta)
In [39]:
ketnegthetaExpanded = (alpha * ketXExpanded + beta * ketYExpanded).subs(alpha, -sin(theta)).subs(beta, cos(theta))
display(ketnegthetaExpanded)
branegthetaExpanded = conjugate(ketnegthetaExpanded.T).subs(conjugate(theta), theta)
display(branegthetaExpanded)
In [40]:
innerprodOftheta_negtheta = Eq(Eq(Abs(InnerProduct(bratheta, ketnegtheta), evaluate = False)**2,
Abs(MatMul(brathetaExpanded, ketnegthetaExpanded), evaluate = False)**2,
evaluate = False),
(Abs(brathetaExpanded * ketnegthetaExpanded)**2).simplify(),
evaluate = False)
display(innerprodOftheta_negtheta)
In [41]:
innerprodOftheta_theta = Eq(Eq(Abs(InnerProduct(bratheta, kettheta), evaluate = False)**2,
Abs(MatMul(brathetaExpanded, ketthetaExpanded), evaluate = False)**2,
evaluate = False),
(Abs(brathetaExpanded * ketthetaExpanded)**2).simplify(),
evaluate = False)
display(innerprodOftheta_theta)
In [42]:
innerprodOfnegtheta_negtheta = Eq(Eq(Abs(InnerProduct(branegtheta, ketnegtheta), evaluate = False)**2,
Abs(MatMul(branegthetaExpanded, ketnegthetaExpanded), evaluate = False)**2,
evaluate = False),
(Abs(branegthetaExpanded * ketnegthetaExpanded)**2).simplify(),
evaluate = False)
display(innerprodOfnegtheta_negtheta)
In [43]:
innerprodOfX_theta = Eq(Eq(Abs(InnerProduct(braX, kettheta), evaluate = False)**2,
Abs(MatMul(braXExpanded, ketthetaExpanded), evaluate = False)**2,
evaluate = False),
(Abs(braXExpanded * ketthetaExpanded)**2).simplify(),
evaluate = False)
display(innerprodOfX_theta)
In [44]:
innerprodOfY_theta = Eq(Eq(Abs(InnerProduct(braY, kettheta), evaluate = False)**2,
Abs(MatMul(braYExpanded, ketthetaExpanded), evaluate = False)**2,
evaluate = False),
(Abs(braYExpanded * ketthetaExpanded)**2).simplify(),
evaluate = False)
display(innerprodOfY_theta)
In [45]:
ketAlpha = Ket(alpha)
display(ketAlpha)
braAlpha = Bra(alpha)
display(braAlpha)
In [46]:
ketAlphaExpanded = (alpha * ketXExpanded + beta * ketYExpanded).subs(alpha, cos(alpha)).subs(beta, sin(alpha))
display(ketAlphaExpanded)
braAlphaExpanded = conjugate(ketAlphaExpanded.T).subs(conjugate(alpha), alpha)
display(braAlphaExpanded)
In [47]:
ketBeta = Ket(beta)
display(ketBeta)
braBeta = Bra(beta)
display(braBeta)
In [48]:
ketBetaExpanded = (alpha * ketXExpanded + beta * ketYExpanded).subs(beta, sin(beta)).subs(alpha, cos(beta))
display(ketBetaExpanded)
braBetaExpanded = conjugate(ketBetaExpanded.T).subs(conjugate(beta), beta)
display(braBetaExpanded)
In [49]:
innerprodOfAlpha_Beta = Eq(Eq(Abs(InnerProduct(braAlpha, ketBeta), evaluate = False)**2,
Abs(MatMul(braAlphaExpanded, ketBetaExpanded), evaluate = False)**2,
evaluate = False),
(Abs(braAlphaExpanded * ketBetaExpanded)**2).simplify(),
evaluate = False)
display(innerprodOfAlpha_Beta)
In [50]:
HExpanded = Matrix([[cos(2 * theta), sin(2 * theta)],[sin(2 * theta), -cos(2 * theta)]])
display(HExpanded)
In [51]:
cos2ThetaExpanded = Eq(cos(2 * theta), cos(theta)**2 - sin(theta)**2)
display(cos2ThetaExpanded)
In [52]:
sin2ThetaExpanded = Eq(sin(2 * theta),2 * sin(theta) * cos(theta))
display(sin2ThetaExpanded)
In [53]:
HExpanded = Matrix([
[cos(2 * theta), sin(2 * theta)],
[sin(2 * theta), -cos(2 * theta)]]).subs(
cos(2 * theta), cos(theta)**2 - sin(theta)**2).subs(
sin(2 * theta), 2 * sin(theta) * cos(theta))
display(HExpanded)
In [54]:
productOfHExpanded_kettheta = Eq(MatMul(HExpanded, ketthetaExpanded),
MatMul(lamda, ketthetaExpanded,
evaluate = False),
evaluate = False)
display(productOfHExpanded_kettheta)
In [55]:
productOfHExpanded_kettheta = Eq(HExpanded * ketthetaExpanded,
Matrix([(HExpanded * ketthetaExpanded)[0].simplify(),
(HExpanded * ketthetaExpanded)[1].simplify()]),
evaluate = False)
display(productOfHExpanded_kettheta)
In [56]:
valOfLambda = Eq(lamda, 1)
display(valOfLambda)
In [57]:
productOfHExpanded_ketnegtheta = Eq(MatMul(HExpanded, ketnegthetaExpanded),
MatMul(lamda, ketnegthetaExpanded,
evaluate = False),
evaluate = False)
display(productOfHExpanded_ketnegtheta)
In [58]:
productOfHExpanded_ketnegtheta = Eq(MatMul(HExpanded, ketnegthetaExpanded),
Eq(HExpanded * ketnegthetaExpanded,
Matrix([(HExpanded * ketnegthetaExpanded)[0].simplify(),
(HExpanded * ketnegthetaExpanded)[1].simplify()]),
evaluate = False),evaluate = False)
display(productOfHExpanded_ketnegtheta)
In [59]:
valOfLambda = Eq(lamda, -1)
display(valOfLambda)
In [60]:
eFieldX, eFieldY, eField0 = symbols('E_x E_y E_0')
In [61]:
valOfEX = Eq(eFieldX, eField0 * sin(k*eField - w*t))
display(valOfEX)
In [62]:
valOfEY = Eq(eFieldY, eField0 * cos(k*eField - w*t))
display(valOfEY)
In [63]:
ketClock = Ket('Clock')
display(ketClock)
braClock = Bra('Clock')
display(braClock)
In [64]:
ketClockExpanded = alpha * ketXExpanded + beta * ketYExpanded
display(ketClockExpanded)
braClockExpanded = conjugate(ketClockExpanded.T)
display(braClockExpanded)
In [65]:
valOfKetClock = Eq(ketClock,
Eq(ketClockExpanded,
ketClockExpanded[0] * ketX + ketClockExpanded[1] * ketY,
evaluate = False),
evaluate = False)
display(valOfKetClock)
In [66]:
ketClockExpanded = 1/sqrt(2) * ketXExpanded + I/sqrt(2) * ketYExpanded
display(ketClockExpanded)
braClockExpanded = conjugate(ketClockExpanded.T)
display(braClockExpanded)
In [67]:
valOfKetClock = Eq(ketClock,
Eq(ketClockExpanded,
(ketClockExpanded[0] * ketX + ketClockExpanded[1] * ketY),
evaluate = False),
evaluate = False)
display(valOfKetClock)
In [68]:
ketAntiClock = Ket('AntiClock')
display(ketAntiClock)
braAntiClock = Bra('AntiClock')
display(braAntiClock)
In [69]:
ketAntiClockExpanded = 1/sqrt(2) * ketXExpanded + -I/sqrt(2) * ketYExpanded
display(ketAntiClockExpanded)
braAntiClockExpanded = conjugate(ketAntiClockExpanded.T)
display(braAntiClockExpanded)
In [70]:
innerprodOfClock_AntiClock = Eq(Eq(Abs(InnerProduct(braClock, ketAntiClock), evaluate = False)**2,
Abs(MatMul(braClockExpanded, ketAntiClockExpanded), evaluate = False)**2,
evaluate = False),
(Abs(braClockExpanded * ketAntiClockExpanded)**2).simplify(),
evaluate = False)
display(innerprodOfClock_AntiClock)
In [71]:
innerprodOftheta_Clock = Eq(Eq(Abs(InnerProduct(bratheta, ketClock), evaluate = False)**2,
Abs(MatMul(brathetaExpanded, ketClockExpanded), evaluate = False)**2,
evaluate = False),
(Abs(brathetaExpanded * ketClockExpanded)**2).simplify(),
evaluate = False)
display(innerprodOftheta_Clock)
In [72]:
HExpanded = Matrix([[0, -I],[I, 0]])
display(HExpanded)
In [73]:
productOfHExpanded_ketClock = Eq(MatMul(HExpanded, ketClockExpanded),
MatMul(lamda, ketClockExpanded,
evaluate = False),
evaluate = False)
display(productOfHExpanded_ketClock)
In [74]:
productOfHExpanded_ketClock = Eq(MatMul(HExpanded, ketClockExpanded),
Matrix([(HExpanded * ketClockExpanded)[0].simplify(),
(HExpanded * ketClockExpanded)[1].simplify()]),
evaluate = False)
display(productOfHExpanded_ketClock)
In [75]:
valOfLambda = Eq(lamda, 1)
display(valOfLambda)
In [76]:
productOfHExpanded_ketAntiClock = Eq(MatMul(HExpanded, ketAntiClockExpanded),
MatMul(lamda, ketAntiClockExpanded,
evaluate = False),
evaluate = False)
display(productOfHExpanded_ketAntiClock)
In [77]:
productOfHExpanded_ketAntiClock = Eq(MatMul(HExpanded, ketAntiClockExpanded),
Matrix([(HExpanded * ketAntiClockExpanded)[0].simplify(),
(HExpanded * ketAntiClockExpanded)[1].simplify()]),
evaluate = False)
display(productOfHExpanded_ketAntiClock)
In [78]:
valOfLambda = Eq(lamda, -1)
display(valOfLambda)
In [ ]: