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
In [2]:
dotSym = Symbol('.')
display(dotSym)
In [3]:
a_1, a_2, a_3, a_n_1, a_n = symbols('a_1 a_2 a_3 a_n-1 a_n')
display(a_1, a_2, a_3, a_n_1, a_n)
In [4]:
b_1, b_2, b_3 = symbols('b_1 b_2 b_3')
display(b_1, b_2, b_3)
In [5]:
c_1, c_2, c_3 = symbols('c_1 c_2 c_3')
display(c_1, c_2, c_3)
In [6]:
ketA = Ket('a')
display(ketA)
In [7]:
ketAExpanded = Matrix((a_1, a_2, a_3, dotSym, dotSym, dotSym, a_n_1, a_n ))
display(ketAExpanded)
In [8]:
braA = Bra('a')
display(braA)
In [9]:
braAExpanded = Dagger(ketAExpanded)
display(braAExpanded)
In [10]:
comp = Eq(z, x + I*y)
display(comp)
In [11]:
iValue = Eq(I, sqrt(-1, evaluate = False), evaluate = False)
display(iValue)
In [12]:
modOfZ = Eq(Abs(z)**2, x**2 + y**2)
display(modOfZ)
In [ ]:
In [13]:
display(conjugate(z))
display(conjugate( x + I*y))
compconj = Eq(conjugate(z),conjugate( x + I*y))
display(compconj)
In [14]:
zxzconj = (x + I*y) * conjugate(x + I*y)
display(zxzconj)
In [15]:
ketB = Ket('b')
ketC = Ket('c')
In [16]:
ketAExpanded = Matrix((a_1, a_2, a_3))
display(ketAExpanded)
ketBExpanded = Matrix((b_1, b_2, b_3))
display(ketBExpanded)
ketCExpanded = Matrix((c_1, c_2, c_3))
display(ketCExpanded)
In [17]:
braB = Bra('b')
display(braB)
braC = Bra('c')
display(braC)
In [18]:
braAExpanded = Dagger(Matrix((a_1, a_2, a_3)))
display(braAExpanded)
braBExpanded = Dagger(Matrix((b_1, b_2, b_3)))
display(braBExpanded)
braCExpanded = Dagger(Matrix((c_1, c_2, c_3)))
display(braCExpanded)
In [19]:
addOfKetsExpanded = Eq(ketAExpanded + ketBExpanded, ketCExpanded)
display(addOfKetsExpanded)
In [20]:
mulOfKets = Eq(alpha * ketA, ketC)
display(mulOfKets)
In [21]:
mulOfKetsExpanded = Eq(alpha * ketAExpanded, ketCExpanded)
display(mulOfKetsExpanded)
In [22]:
inprodOfAB = InnerProduct(braA, ketB)
display(inprodOfAB)
In [23]:
inprodOfABExpanded = braAExpanded * ketBExpanded
display(inprodOfABExpanded)
In [24]:
inprodOfAB = Eq(InnerProduct(braA, ketB), inprodOfABExpanded, evaluate = False)
display(inprodOfAB)
In [25]:
inprodOfBA = InnerProduct(braB, ketA)
display(inprodOfBA)
In [26]:
inprodOfBAExpanded = braBExpanded * ketAExpanded
display(inprodOfBAExpanded)
In [27]:
inprodOfBA = Eq(InnerProduct(braB, ketA), inprodOfBAExpanded, evaluate = False)
display(inprodOfBA)
In [28]:
inprodOfBAconj = Eq(conjugate(InnerProduct(braB, ketA)), conjugate(inprodOfBAExpanded), evaluate = False)
display(inprodOfBAconj)
In [29]:
display(inprodOfBAconj == inprodOfAB)
In [30]:
M = MatrixSymbol('M', 3, 3)
display(M)
In [31]:
MExpanded = Matrix(M)
display(MExpanded)
In [32]:
MExpandedConj = conjugate(MExpanded)
display(MExpandedConj)
In [33]:
MExpandedTranspose = transpose(MExpanded)
display(MExpandedTranspose)
In [34]:
MExpandedDagger = Dagger(MExpanded)
display(MExpandedDagger)
In [35]:
M = Matrix([[1, 1 + I],[1 - I, 3]])
display(M)
In [36]:
MDagger = Dagger(Matrix([[1, 1 + I],[1 - I, 3]]))
display(MDagger)
In [37]:
display(M == MDagger)
In [38]:
M = MatrixSymbol('M', 2, 2)
display(M)
In [39]:
MExpanded = Matrix(M)
display(MExpanded)
In [40]:
ketAExpanded = Matrix(ketAExpanded[:2])
display(ketAExpanded)
In [41]:
M = symbols('M')
In [42]:
prodOfMKetA = Eq((M * ketA), MExpanded * ketAExpanded, evaluate = False)
display(prodOfMKetA)
In [43]:
M = MatrixSymbol('M', 2, 2)
display(M)
In [44]:
i = MatrixSymbol('I', 3, 3)
iExpanded = Identity(3).as_explicit()
In [45]:
iMatrix = Eq(i, iExpanded, evaluate = False)
display(iMatrix)
In [46]:
U = MatrixSymbol('U', n, n)
In [47]:
term1 = U * Dagger(U)
term2 = iExpanded
term3 = Eq(term1, term2, evaluate = False)
display(term1)
display(term2)
display(term3)
display(term1 == term2)
In [48]:
prodOfUUDagger = Eq(U * Dagger(U), iExpanded, evaluate = False)
display(prodOfUUDagger)
In [49]:
U = UnitaryOperator('U')
display(U)
In [50]:
U * Dagger(U)
Out[50]:
In [51]:
Identity(3).as_explicit()
Out[51]:
In [52]:
U * Dagger(U) == Identity(3).as_explicit()
Out[52]:
In [53]:
M = MatrixSymbol('M', 2, 2)
display(M)
In [54]:
MExpanded = Matrix(M)
display(MExpanded)
In [55]:
Det = symbols('Det')
In [56]:
detOfM = Eq(Determinant(M), Determinant(MExpanded), evaluate = False)
display(detOfM)
In [57]:
i = MatrixSymbol('I', 2, 2)
iExpanded = Identity(2).as_explicit()
In [58]:
detOfI = Eq(Eq(Determinant(i), Determinant(iExpanded)), iExpanded.det(), evaluate = False)
display(detOfI)
In [59]:
traceOfM = Eq(Eq(Trace(i), Trace(MExpanded)), trace(MExpanded), evaluate = False)
display(traceOfM)
In [60]:
H = HermitianOperator('H')
lambdaA = symbols('lambda_a')
lambdaB = symbols('lambda_b')
In [61]:
mostImportantEqOfA = Eq(H * ketA, lambdaA * ketA)
display(mostImportantEqOfA)
In [62]:
mostImportantEqOfB = Eq(H * ketB, lambdaB * ketB)
display(mostImportantEqOfB)
In [63]:
probabilityOfPolorisation = cos(theta)**2
display(probabilityOfPolorisation)
In [64]:
intensity, eField = symbols('I E')
In [65]:
intensityOfRadiation = Eq(intensity, eField**2)
display(intensityOfRadiation)
In [66]:
eFieldExpanded = Eq(eField, h*f)
display(eFieldExpanded)
In [67]:
ketX = XKet()
ketY = Ket(y)
braX = XBra()
braY = Bra(y)
In [68]:
ketXExpanded = Matrix([[1],[0]])
display(ketXExpanded)
braXExpanded = conjugate(ketXExpanded.T)
display(braXExpanded)
In [69]:
valOfKetX = Eq(ketX, ketXExpanded, evaluate = False)
display(valOfKetX)
valOfBraX = Eq(braX, braXExpanded, evaluate = False)
display(valOfBraX)
In [70]:
ketYExpanded = Matrix([[0],[1]])
display(ketYExpanded)
braYExpanded = conjugate(ketYExpanded.T)
display(braYExpanded)
In [71]:
valOfKetY = Eq(ketY, ketYExpanded, evaluate = False)
display(valOfKetY)
valOfBraY = Eq(braY, braYExpanded, evaluate = False)
display(valOfBraY)
In [72]:
absOfXY = Eq(Abs(InnerProduct(braX, ketY), evaluate = False)**2, Abs(InnerProduct(braX, ketY))**2)
display(absOfXY)
In [73]:
innerprodOfXY = Eq(Eq(Abs(InnerProduct(braX, ketY))**2,
Abs(MatMul(braXExpanded, ketYExpanded), evaluate = False)**2,
evaluate = False),
Abs(braXExpanded * ketYExpanded)**2,
evaluate = False)
display(innerprodOfXY)
In [74]:
innerprodOfXX = Eq(Eq(Abs(InnerProduct(braX, ketX))**2,
Abs(MatMul(braXExpanded, ketXExpanded), evaluate = False)**2,
evaluate = False),
Abs(braXExpanded * ketXExpanded)**2,
evaluate = False)
display(innerprodOfXX)
In [75]:
innerprodOfYY = Eq(Eq(Abs(InnerProduct(braY, ketY))**2,
Abs(MatMul(braYExpanded, ketYExpanded), evaluate = False)**2,
evaluate = False),
Abs(braYExpanded * ketYExpanded)**2,
evaluate = False)
display(innerprodOfYY)
In [76]:
HPlus = HermitianOperator('H_+')
In [77]:
HPlusExpanded = Matrix([[1, 0],[0, -1]])
display(HPlusExpanded)
In [78]:
measurement1 = Eq(HPlus * ketX, lamda * ketX)
display(measurement1)
In [79]:
measurement1solve = Eq(HPlusExpanded * ketXExpanded, lamda * ketX, evaluate = False)
display(measurement1solve)
In [80]:
valOfLambdaViaM1 = Eq(lamda, 1)
display(valOfLambdaViaM1)
In [81]:
measurement2 = Eq(HPlus * ketY, lamda * ketY)
display(measurement2)
In [82]:
measurement2solve = Eq(HPlusExpanded * ketYExpanded, lamda * ketY, evaluate = False)
display(measurement2solve)
In [83]:
valOfLambdaViaM2 = Eq(lamda, -1)
display(valOfLambdaViaM2)
In [84]:
ket45 = Ket(45*degree)
display(ket45)
bra45 = Bra(45*degree)
display(bra45)
In [85]:
ket45Expanded = ketXExpanded + ketYExpanded
display(ket45Expanded)
bra45Expanded = ket45Expanded.T
display(bra45Expanded)
In [86]:
valOfKet45 = Eq(Eq(ket45,
ketX + ketY,
evaluate = False),
ket45Expanded,
evaluate = False)
display(valOfKet45)
In [87]:
innerprodOf4545 = Eq(Eq(Abs(InnerProduct(bra45, ket45), evaluate = False)**2,
Abs(MatMul(bra45Expanded, ket45Expanded), evaluate = False)**2,
evaluate = False),
Abs(bra45Expanded * ket45Expanded)**2,
evaluate = False)
display(innerprodOf4545)
In [88]:
ket45Expanded = ketXExpanded/sqrt(2) + ketYExpanded/sqrt(2)
display(ket45Expanded)
bra45Expanded = conjugate(ket45Expanded.T)
display(bra45Expanded)
In [89]:
innerprodOf4545 = Eq(Eq(Abs(InnerProduct(bra45, ket45), evaluate = False)**2,
Abs(MatMul(bra45Expanded, ket45Expanded), evaluate = False)**2,
evaluate = False),
Abs(bra45Expanded * ket45Expanded)**2,
evaluate = False)
display(innerprodOf4545)
In [90]:
ket135 = Ket(135*degree)
display(ket135)
bra135 = Bra(135*degree)
display(bra135)
In [91]:
ket135Expanded = ketXExpanded/sqrt(2) - ketYExpanded/sqrt(2)
display(ket135Expanded)
bra135Expanded = conjugate(ket135Expanded.T)
display(bra135Expanded)
In [92]:
innerprodOf13545 = Eq(Eq(Abs(InnerProduct(bra135, ket45), evaluate = False)**2,
Abs(MatMul(bra135Expanded, ket45Expanded), evaluate = False)**2,
evaluate = False),
Abs(bra135Expanded * ket45Expanded)**2,
evaluate = False)
display(innerprodOf13545)
In [93]:
innerprodOf45Y = Eq(Eq(Abs(InnerProduct(bra45, ketY), evaluate = False)**2,
Abs(MatMul(bra45Expanded, ketYExpanded), evaluate = False)**2,
evaluate = False),
Abs(bra45Expanded * ketYExpanded)**2,
evaluate = False)
display(innerprodOf45Y)
In [94]:
# cross = symbols(r'\times')
HCross = HermitianOperator(r'H_\times')
In [95]:
HCrossExpanded = Matrix([[0, 1],[1, 0]])
display(HCrossExpanded)
In [96]:
measurement1 = Eq(HCross * ket45, lamda * ket45)
display(measurement1)
In [97]:
measurement1solve = Eq(HCrossExpanded * ket45Expanded, lamda * ket45, evaluate = False)
display(measurement1solve)
In [98]:
valOfLambdaViaM1 = Eq(lamda, 1)
display(valOfLambdaViaM1)
In [99]:
measurement2 = Eq(HCross * ket135, lamda * ket135)
display(measurement2)
In [100]:
measurement2solve = Eq(HCrossExpanded * ket135Expanded, lamda * ket135, evaluate = False)
display(measurement2solve)
In [101]:
valOfLambdaViaM2 = Eq(lamda, -1)
display(valOfLambdaViaM2)
In [ ]: