# 003-001-electron-spin.ipynb

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.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

In [2]:
ketU = Ket(u)
ketD = Ket(d)
braU = Bra(u)

In [3]:
ketUExpanded = Matrix([[1],[0]])
display(ketUExpanded)
braUExpanded = conjugate(ketUExpanded.T)
display(braUExpanded)

$\displaystyle \left[\begin{matrix}1\\0\end{matrix}\right]$
$\displaystyle \left[\begin{matrix}1 & 0\end{matrix}\right]$
In [4]:
ketDExpanded = Matrix([[0],[1]])
display(ketDExpanded)

$\displaystyle \left[\begin{matrix}0\\1\end{matrix}\right]$
$\displaystyle \left[\begin{matrix}0 & 1\end{matrix}\right]$
In [5]:
kettheta = Ket(theta)
display(kettheta)
bratheta = Bra(theta)
display(bratheta)

$\displaystyle {\left|\theta\right\rangle }$
$\displaystyle {\left\langle \theta\right|}$
In [6]:
ketthetaExpanded = alpha * ketUExpanded + beta * ketDExpanded
display(ketthetaExpanded)
brathetaExpanded = conjugate(ketthetaExpanded.T)
display(brathetaExpanded)

$\displaystyle \left[\begin{matrix}\alpha\\\beta\end{matrix}\right]$
$\displaystyle \left[\begin{matrix}\overline{\alpha} & \overline{\beta}\end{matrix}\right]$
In [7]:
valOfKettheta = Eq(kettheta,
Eq(ketthetaExpanded,
ketthetaExpanded[0] * ketU + ketthetaExpanded[1] * ketD,
evaluate = False),
evaluate = False)
display(valOfKettheta)

$\displaystyle {\left|\theta\right\rangle } = \left[\begin{matrix}\alpha\\\beta\end{matrix}\right] = \alpha {\left|u\right\rangle } + \beta {\left|d\right\rangle }$
In [8]:
P_u, P_d = symbols('P_u P_d')

In [9]:
probU = Eq(P_u, ketthetaExpanded[0] * conjugate(ketthetaExpanded[0]))
display(probU)

$\displaystyle P_{u} = \alpha \overline{\alpha}$
In [10]:
probD = Eq(P_d, ketthetaExpanded[1] * conjugate(ketthetaExpanded[1]))
display(probD)

$\displaystyle P_{d} = \beta \overline{\beta}$
In [11]:
totalProb = Eq(ketthetaExpanded[0] * conjugate(ketthetaExpanded[0]) + ketthetaExpanded[1] * conjugate(ketthetaExpanded[1]), 1)
display(totalProb)

$\displaystyle \alpha \overline{\alpha} + \beta \overline{\beta} = 1$
In [12]:
Mul(0, ketD, evaluate = False)

Out[12]:
$\displaystyle 0 {\left|d\right\rangle }$
In [13]:
valOfKettheta = Eq(kettheta,
ketthetaExpanded[0] * ketU + ketthetaExpanded[1] * ketD,
evaluate = False)
display(valOfKettheta)

$\displaystyle {\left|\theta\right\rangle } = \alpha {\left|u\right\rangle } + \beta {\left|d\right\rangle }$
In [14]:
valOfKetU = Eq(ketU,
Add(Mul(ketUExpanded[0], ketU, evaluate = False),  Mul(ketUExpanded[1], ketD, evaluate = False), evaluate = False),
evaluate = False)
display(valOfKetU)

$\displaystyle {\left|u\right\rangle } = 0 {\left|d\right\rangle } + {\left|u\right\rangle }$
In [15]:
valOfKetD = Eq(ketD,
Add(Mul(ketDExpanded[0], ketU, evaluate = False),  Mul(ketDExpanded[1], ketD, evaluate = False), evaluate = False),
evaluate = False)
display(valOfKetD)

$\displaystyle {\left|d\right\rangle } = {\left|d\right\rangle } + 0 {\left|u\right\rangle }$
In [16]:
ketR = Ket(r)
ketL = Ket(l)
braR = Bra(r)
braL = Bra(l)

In [17]:
ketRExpanded = Matrix([[1/sqrt(2)],[1/sqrt(2)]])
display(ketRExpanded)
braRExpanded = conjugate(ketRExpanded.T)
display(braRExpanded)

$\displaystyle \left[\begin{matrix}\frac{\sqrt{2}}{2}\\\frac{\sqrt{2}}{2}\end{matrix}\right]$
$\displaystyle \left[\begin{matrix}\frac{\sqrt{2}}{2} & \frac{\sqrt{2}}{2}\end{matrix}\right]$
In [18]:
ketLExpanded = Matrix([[1/sqrt(2)],[-1/sqrt(2)]])
display(ketLExpanded)
braLExpanded = conjugate(ketLExpanded.T)
display(braLExpanded)

$\displaystyle \left[\begin{matrix}\frac{\sqrt{2}}{2}\\- \frac{\sqrt{2}}{2}\end{matrix}\right]$
$\displaystyle \left[\begin{matrix}\frac{\sqrt{2}}{2} & - \frac{\sqrt{2}}{2}\end{matrix}\right]$
In [19]:
valOfKetR = Eq(ketR,
Add(Mul(ketRExpanded[0], ketU, evaluate = False),  Mul(ketRExpanded[1], ketD, evaluate = False), evaluate = False),
evaluate = False)
display(valOfKetR)

$\displaystyle {\left|r\right\rangle } = \frac{\sqrt{2}}{2} {\left|d\right\rangle } + \frac{\sqrt{2}}{2} {\left|u\right\rangle }$
In [20]:
i = symbols('I')

In [21]:
ketI = Ket(i)
ketO = Ket(o)
braI = Bra(i)
braO = Bra(o)

In [22]:
ketIExpanded = Matrix([[1/sqrt(2)],[I/sqrt(2)]])
display(ketIExpanded)
braIExpanded = conjugate(ketIExpanded.T)
display(braIExpanded)

$\displaystyle \left[\begin{matrix}\frac{\sqrt{2}}{2}\\\frac{\sqrt{2} i}{2}\end{matrix}\right]$
$\displaystyle \left[\begin{matrix}\frac{\sqrt{2}}{2} & - \frac{\sqrt{2} i}{2}\end{matrix}\right]$
In [23]:
ketOExpanded = Matrix([[1/sqrt(2)],[-I/sqrt(2)]])
display(ketOExpanded)
braOExpanded = conjugate(ketOExpanded.T)
display(braOExpanded)

$\displaystyle \left[\begin{matrix}\frac{\sqrt{2}}{2}\\- \frac{\sqrt{2} i}{2}\end{matrix}\right]$
$\displaystyle \left[\begin{matrix}\frac{\sqrt{2}}{2} & \frac{\sqrt{2} i}{2}\end{matrix}\right]$
In [24]:
valOfKetI = Eq(ketI,
Add(Mul(ketIExpanded[0], ketU, evaluate = False),  Mul(ketIExpanded[1], ketD, evaluate = False), evaluate = False),
evaluate = False)
display(valOfKetI)

$\displaystyle {\left|I\right\rangle } = \frac{\sqrt{2} i}{2} {\left|d\right\rangle } + \frac{\sqrt{2}}{2} {\left|u\right\rangle }$
In [25]:
HPlus = HermitianOperator('H_+')
sigma_z = HermitianOperator('sigma_z')

In [26]:
HPlusExpanded = Matrix([[1, 0],[0, -1]])
display(HPlusExpanded)

$\displaystyle \left[\begin{matrix}1 & 0\\0 & -1\end{matrix}\right]$
In [27]:
hermitianOpForU_D = Eq(Eq(HPlus, HPlusExpanded, evaluate = False), sigma_z, evaluate = False)
display(hermitianOpForU_D)

$\displaystyle H_{+} = \left[\begin{matrix}1 & 0\\0 & -1\end{matrix}\right] = \sigma_{z}$
In [28]:
HCross = HermitianOperator(r'H_\times')
sigma_x = HermitianOperator('sigma_x')

In [29]:
HCrossExpanded = Matrix([[0, 1],[1, 0]])
display(HCrossExpanded)

$\displaystyle \left[\begin{matrix}0 & 1\\1 & 0\end{matrix}\right]$
In [30]:
hermitianOpForR_L = Eq(Eq(HCross, HCrossExpanded, evaluate = False), sigma_x, evaluate = False)
display(hermitianOpForR_L)

$\displaystyle H_\times = \left[\begin{matrix}0 & 1\\1 & 0\end{matrix}\right] = \sigma_{x}$
In [31]:
HCircular = HermitianOperator(r'H_\circlearrowleft')
sigma_y = HermitianOperator('sigma_y')

In [32]:
HCircularExpanded = Matrix([[0, -I],[I, 0]])
display(HCircularExpanded)

$\displaystyle \left[\begin{matrix}0 & - i\\i & 0\end{matrix}\right]$
In [33]:
hermitianOpForI_O = Eq(Eq(HCircular, HCircularExpanded, evaluate = False), sigma_y, evaluate = False)
display(hermitianOpForI_O)

$\displaystyle H_\circlearrowleft = \left[\begin{matrix}0 & - i\\i & 0\end{matrix}\right] = \sigma_{y}$
In [34]:
ketPsi = Ket(psi)
braPsi = Bra(psi)

In [35]:
H = HermitianOperator('H')

In [36]:
prodOfH_ketPsi = Eq(H * ketPsi, lamda * ketPsi)
display(prodOfH_ketPsi)

$\displaystyle H {\left|\psi\right\rangle } = \lambda {\left|\psi\right\rangle }$
In [37]:
innerprodOfR_U = Eq(Eq(Abs(InnerProduct(braR, ketU), evaluate = False)**2,
Abs(MatMul(braRExpanded, ketUExpanded), evaluate = False)**2,
evaluate = False),
(Abs(braRExpanded * ketUExpanded)**2).simplify(),
evaluate = False)
display(innerprodOfR_U)

$\displaystyle \left|{\left\langle r \right. {\left|u\right\rangle }}\right|^{2} = \left|{\left[\begin{matrix}\frac{\sqrt{2}}{2} & \frac{\sqrt{2}}{2}\end{matrix}\right] \left[\begin{matrix}1\\0\end{matrix}\right]}\right|^{2} = \left[\begin{matrix}\frac{1}{2}\end{matrix}\right]$
In [38]:
innerprodOfI_L = Eq(Eq(Abs(InnerProduct(braI, ketL), evaluate = False)**2,
Abs(MatMul(braIExpanded, ketLExpanded), evaluate = False)**2,
evaluate = False),
(Abs(braIExpanded * ketLExpanded)**2).simplify(),
evaluate = False)
display(innerprodOfI_L)

$\displaystyle \left|{\left\langle I \right. {\left|l\right\rangle }}\right|^{2} = \left|{\left[\begin{matrix}\frac{\sqrt{2}}{2} & - \frac{\sqrt{2} i}{2}\end{matrix}\right] \left[\begin{matrix}\frac{\sqrt{2}}{2}\\- \frac{\sqrt{2}}{2}\end{matrix}\right]}\right|^{2} = \left[\begin{matrix}\frac{1}{2}\end{matrix}\right]$
In [39]:
prodOfH_ketPsi = Eq(H * ketPsi, lamda * ketPsi)
display(prodOfH_ketPsi)

$\displaystyle H {\left|\psi\right\rangle } = \lambda {\left|\psi\right\rangle }$
In [40]:
valOfKetPsi = Eq(ketPsi, alpha * ketU + beta * ketD)
display(valOfKetPsi)

$\displaystyle {\left|\psi\right\rangle } = \alpha {\left|u\right\rangle } + \beta {\left|d\right\rangle }$
In [41]:
probU = Eq(P_u, cos(theta)**2, evaluate = False)
display(probU)

$\displaystyle P_{u} = \cos^{2}{\left(\theta \right)}$
In [42]:
P_uAmp = symbols('P_uAmp')

In [43]:
probAmpU = Eq(P_uAmp, cos(theta), evaluate = False)
display(probAmpU)

$\displaystyle P_{uAmp} = \cos{\left(\theta \right)}$
In [44]:
probU = Eq(P_u, cos(theta/2)**2, evaluate = False)
display(probU)

$\displaystyle P_{u} = \cos^{2}{\left(\frac{\theta}{2} \right)}$
In [45]:
probAmpU = Eq(P_uAmp, cos(theta/2), evaluate = False)
display(probAmpU)

$\displaystyle P_{uAmp} = \cos{\left(\frac{\theta}{2} \right)}$
In [46]:
valOfKetTheta = Eq(kettheta, cos(theta/2) * ketU + sin(theta/2) * ketD)
display(valOfKetTheta)

$\displaystyle {\left|\theta\right\rangle } = \sin{\left(\frac{\theta}{2} \right)} {\left|d\right\rangle } + \cos{\left(\frac{\theta}{2} \right)} {\left|u\right\rangle }$
In [47]:
valOfKetU = Eq(ketU,
Add(Mul(ketUExpanded[0], ketU, evaluate = False),  Mul(ketUExpanded[1], ketD, evaluate = False), evaluate = False),
evaluate = False)
display(valOfKetU)

$\displaystyle {\left|u\right\rangle } = 0 {\left|d\right\rangle } + {\left|u\right\rangle }$
In [48]:
valOfKetD = Eq(ketD,
Add(Mul(ketDExpanded[0], ketU, evaluate = False),  Mul(ketDExpanded[1], ketD, evaluate = False), evaluate = False),
evaluate = False)
display(valOfKetD)

$\displaystyle {\left|d\right\rangle } = {\left|d\right\rangle } + 0 {\left|u\right\rangle }$
In [49]:
valOfKetR = Eq(ketR,
Add(Mul(ketRExpanded[0], ketU, evaluate = False),  Mul(ketRExpanded[1], ketD, evaluate = False), evaluate = False),
evaluate = False)
display(valOfKetR)

$\displaystyle {\left|r\right\rangle } = \frac{\sqrt{2}}{2} {\left|d\right\rangle } + \frac{\sqrt{2}}{2} {\left|u\right\rangle }$
In [50]:
valOfKetL = Eq(ketL,
Add(Mul(ketLExpanded[0], ketU, evaluate = False),  Mul(ketLExpanded[1], ketD, evaluate = False), evaluate = False),
evaluate = False)
display(valOfKetL)

$\displaystyle {\left|l\right\rangle } = - \frac{\sqrt{2}}{2} {\left|d\right\rangle } + \frac{\sqrt{2}}{2} {\left|u\right\rangle }$
In [51]:
valOfKetI = Eq(ketI,
Add(Mul(ketIExpanded[0], ketU, evaluate = False),  Mul(ketIExpanded[1], ketD, evaluate = False), evaluate = False),
evaluate = False)
display(valOfKetI)

$\displaystyle {\left|I\right\rangle } = \frac{\sqrt{2} i}{2} {\left|d\right\rangle } + \frac{\sqrt{2}}{2} {\left|u\right\rangle }$
In [52]:
valOfKetO = Eq(ketO,
Add(Mul(ketOExpanded[0], ketU, evaluate = False),  Mul(ketOExpanded[1], ketD, evaluate = False), evaluate = False),
evaluate = False)
display(valOfKetO)

$\displaystyle {\left|o\right\rangle } = - \frac{\sqrt{2} i}{2} {\left|d\right\rangle } + \frac{\sqrt{2}}{2} {\left|u\right\rangle }$
In [53]:
addOfR_L = Eq((ketR + ketL)/sqrt(2), ketU)

$\displaystyle \frac{\sqrt{2} \left({\left|l\right\rangle } + {\left|r\right\rangle }\right)}{2} = {\left|u\right\rangle }$
In [54]:
sigma_zExpanded = Matrix([[a, b],[c, d]])
display(sigma_zExpanded)

$\displaystyle \left[\begin{matrix}a & b\\c & d\end{matrix}\right]$
In [55]:
valOfSigma_z = Eq(sigma_z, sigma_zExpanded, evaluate = False)
display(valOfSigma_z)

$\displaystyle \sigma_{z} = \left[\begin{matrix}a & b\\c & d\end{matrix}\right]$
In [56]:
prodOfSigma_z_ketU = Eq(Eq(sigma_z * ketU,
MatMul(sigma_zExpanded,
ketUExpanded),
evaluate = False),
1 * ketUExpanded,
evaluate = False)
display(prodOfSigma_z_ketU)

$\displaystyle \sigma_{z} {\left|u\right\rangle } = \left[\begin{matrix}a & b\\c & d\end{matrix}\right] \left[\begin{matrix}1\\0\end{matrix}\right] = \left[\begin{matrix}1\\0\end{matrix}\right]$
In [57]:
prodOfSigma_z_ketD = Eq(Eq(sigma_z * ketD,
MatMul(sigma_zExpanded,
ketDExpanded),
evaluate = False),
-1 * ketDExpanded,
evaluate = False)
display(prodOfSigma_z_ketD)

$\displaystyle \sigma_{z} {\left|d\right\rangle } = \left[\begin{matrix}a & b\\c & d\end{matrix}\right] \left[\begin{matrix}0\\1\end{matrix}\right] = \left[\begin{matrix}0\\-1\end{matrix}\right]$
In [58]:
t1 = Eq(MatMul(sigma_zExpanded, ketUExpanded), 1 * ketUExpanded, evaluate = False)
t2 = Eq(MatMul(sigma_zExpanded, ketDExpanded), -1 * ketDExpanded, evaluate = False)
solveForValues = solve((t1, t2), a, b, c, d)
display(solveForValues)

{a: 1, b: 0, c: 0, d: -1}
In [59]:
sigma_zExpanded = sigma_zExpanded.subs(a, solveForValues[a])\
.subs(b, solveForValues[b])\
.subs(c, solveForValues[c])\
.subs(d, solveForValues[d])
display(sigma_zExpanded)

$\displaystyle \left[\begin{matrix}1 & 0\\0 & -1\end{matrix}\right]$
In [60]:
sigma_xExpanded = Matrix([[a, b],[c, d]])
display(sigma_xExpanded)

$\displaystyle \left[\begin{matrix}a & b\\c & d\end{matrix}\right]$
In [61]:
valOfSigma_x = Eq(sigma_x, sigma_xExpanded, evaluate = False)
display(valOfSigma_x)

$\displaystyle \sigma_{x} = \left[\begin{matrix}a & b\\c & d\end{matrix}\right]$
In [62]:
prodOfSigma_x_ketR = Eq(Eq(sigma_x * ketR,
MatMul(sigma_xExpanded,
ketRExpanded),
evaluate = False),
1 * ketRExpanded,
evaluate = False)
display(prodOfSigma_x_ketR)

$\displaystyle \sigma_{x} {\left|r\right\rangle } = \left[\begin{matrix}a & b\\c & d\end{matrix}\right] \left[\begin{matrix}\frac{\sqrt{2}}{2}\\\frac{\sqrt{2}}{2}\end{matrix}\right] = \left[\begin{matrix}\frac{\sqrt{2}}{2}\\\frac{\sqrt{2}}{2}\end{matrix}\right]$
In [63]:
prodOfSigma_x_ketL = Eq(Eq(sigma_x * ketL,
MatMul(sigma_xExpanded,
ketLExpanded),
evaluate = False),
-1 * ketLExpanded,
evaluate = False)
display(prodOfSigma_x_ketL)

$\displaystyle \sigma_{x} {\left|l\right\rangle } = \left[\begin{matrix}a & b\\c & d\end{matrix}\right] \left[\begin{matrix}\frac{\sqrt{2}}{2}\\- \frac{\sqrt{2}}{2}\end{matrix}\right] = \left[\begin{matrix}- \frac{\sqrt{2}}{2}\\\frac{\sqrt{2}}{2}\end{matrix}\right]$
In [64]:
t1 = Eq(MatMul(sigma_xExpanded, ketRExpanded), 1 * ketRExpanded, evaluate = False)
t2 = Eq(MatMul(sigma_xExpanded, ketLExpanded), -1 * ketLExpanded, evaluate = False)
solveForValues = solve((t1, t2), a, b, c, d)
display(solveForValues)

{a: 0, b: 1, c: 1, d: 0}
In [65]:
sigma_xExpanded = sigma_xExpanded.subs(a, solveForValues[a])\
.subs(b, solveForValues[b])\
.subs(c, solveForValues[c])\
.subs(d, solveForValues[d])
display(sigma_xExpanded)

$\displaystyle \left[\begin{matrix}0 & 1\\1 & 0\end{matrix}\right]$
In [66]:
sigma_yExpanded = Matrix([[a, b],[c, d]])
display(sigma_yExpanded)

$\displaystyle \left[\begin{matrix}a & b\\c & d\end{matrix}\right]$
In [67]:
valOfSigma_y = Eq(sigma_y, sigma_yExpanded, evaluate = False)
display(valOfSigma_y)

$\displaystyle \sigma_{y} = \left[\begin{matrix}a & b\\c & d\end{matrix}\right]$
In [68]:
prodOfSigma_y_ketI = Eq(Eq(sigma_y * ketI,
MatMul(sigma_yExpanded,
ketIExpanded),
evaluate = False),
1 * ketIExpanded,
evaluate = False)
display(prodOfSigma_y_ketI)

$\displaystyle \sigma_{y} {\left|I\right\rangle } = \left[\begin{matrix}a & b\\c & d\end{matrix}\right] \left[\begin{matrix}\frac{\sqrt{2}}{2}\\\frac{\sqrt{2} i}{2}\end{matrix}\right] = \left[\begin{matrix}\frac{\sqrt{2}}{2}\\\frac{\sqrt{2} i}{2}\end{matrix}\right]$
In [69]:
prodOfSigma_y_ketO = Eq(Eq(sigma_y * ketO,
MatMul(sigma_yExpanded,
ketOExpanded),
evaluate = False),
-1 * ketOExpanded,
evaluate = False)
display(prodOfSigma_y_ketO)

$\displaystyle \sigma_{y} {\left|o\right\rangle } = \left[\begin{matrix}a & b\\c & d\end{matrix}\right] \left[\begin{matrix}\frac{\sqrt{2}}{2}\\- \frac{\sqrt{2} i}{2}\end{matrix}\right] = \left[\begin{matrix}- \frac{\sqrt{2}}{2}\\\frac{\sqrt{2} i}{2}\end{matrix}\right]$
In [70]:
t1 = Eq(MatMul(sigma_yExpanded, ketIExpanded), 1 * ketIExpanded, evaluate = False)
t2 = Eq(MatMul(sigma_yExpanded, ketOExpanded), -1 * ketOExpanded, evaluate = False)
solveForValues = solve((t1, t2), a, b, c, d)
display(solveForValues)

{a: 0, b: -I, c: I, d: 0}
In [71]:
sigma_yExpanded = sigma_yExpanded.subs(a, solveForValues[a])\
.subs(b, solveForValues[b])\
.subs(c, solveForValues[c])\
.subs(d, solveForValues[d])
display(sigma_yExpanded)

$\displaystyle \left[\begin{matrix}0 & - i\\i & 0\end{matrix}\right]$
In [72]:
n_x, n_y, n_z = symbols('n_x n_y n_z', integer = True)
display(n_x, n_y, n_z)

$\displaystyle n_{x}$
$\displaystyle n_{y}$
$\displaystyle n_{z}$
In [73]:
vecLength = Eq(n_x**2 + n_y**2 + n_z**2, 1)
display(vecLength)

$\displaystyle n_{x}^{2} + n_{y}^{2} + n_{z}^{2} = 1$
In [74]:
sigma_n = HermitianOperator('sigma_n')

In [75]:
sigma_nExpanded = Matrix(Add(MatMul(n_x,
sigma_xExpanded,
evaluate = False),
MatMul(n_y,
sigma_yExpanded,
evaluate = False),
MatMul(n_z,
sigma_zExpanded,
evaluate = False),
evaluate = False))
display(sigma_nExpanded)

$\displaystyle \left[\begin{matrix}n_{z} & n_{x} - i n_{y}\\n_{x} + i n_{y} & - n_{z}\end{matrix}\right]$
In [76]:
linearEq = Eq(n_x*sigma_x + n_y*sigma_y + n_z*sigma_z, sigma_n)
display(linearEq)

$\displaystyle n_{x} \sigma_{x} + n_{y} \sigma_{y} + n_{z} \sigma_{z} = \sigma_{n}$
In [77]:
valOfSigma_n = Eq(sigma_n,
sigma_xExpanded,
evaluate = False),
MatMul(n_y,
sigma_yExpanded,
evaluate = False),
MatMul(n_z,
sigma_zExpanded,
evaluate = False),
evaluate = False),
evaluate = False)
display(valOfSigma_n)

$\displaystyle \sigma_{n} = \left[\begin{matrix}n_{z} & n_{x} - i n_{y}\\n_{x} + i n_{y} & - n_{z}\end{matrix}\right]$
In [78]:
ketPsiExpanded = Matrix([[alpha],[beta]], evaluate = False)
display(ketPsiExpanded)

$\displaystyle \left[\begin{matrix}\alpha\\\beta\end{matrix}\right]$
In [79]:
prodOfSigma_n_KetPsiExpanded =  Eq(MatMul(Dummy('sigma_n'),
ketPsiExpanded,
evaluate = False),
MatMul(lamda,
ketPsiExpanded,
evaluate = False),
evaluate = False)
display(prodOfSigma_n_KetPsiExpanded)

$\displaystyle \sigma_{n} \left[\begin{matrix}\alpha\\\beta\end{matrix}\right] = \lambda \left[\begin{matrix}\alpha\\\beta\end{matrix}\right]$
In [80]:
valOfLambda = Eq(lamda, 1)
display(valOfLambda)

$\displaystyle \lambda = 1$
In [81]:
ketPsiExpanded = Matrix([[1],[gamma]])

In [82]:
prodOfSigma_nExpanded_KetPsiExpanded =  Eq((sigma_nExpanded *
ketPsiExpanded),
MatMul(1,
ketPsiExpanded,
evaluate = False),
evaluate = False)
display(prodOfSigma_nExpanded_KetPsiExpanded)

$\displaystyle \left[\begin{matrix}\gamma \left(n_{x} - i n_{y}\right) + n_{z}\\- \gamma n_{z} + n_{x} + i n_{y}\end{matrix}\right] = 1 \left[\begin{matrix}1\\\gamma\end{matrix}\right]$
In [83]:
solveForGamma = solve(Eq(prodOfSigma_nExpanded_KetPsiExpanded.lhs[0],
prodOfSigma_nExpanded_KetPsiExpanded.rhs.simplify()[0, 0]),
gamma)[0]
display(solveForGamma)

$\displaystyle \frac{1 - n_{z}}{n_{x} - i n_{y}}$
In [84]:
display(ketPsiExpanded.subs(gamma, solveForGamma))

$\displaystyle \left[\begin{matrix}1\\\frac{1 - n_{z}}{n_{x} - i n_{y}}\end{matrix}\right]$
In [85]:
braPsiExpanded = conjugate(ketPsiExpanded.T)

In [86]:
valOfKetPsi = Eq(ketPsi, ketPsiExpanded, evaluate = False)
display(valOfKetPsi)

$\displaystyle {\left|\psi\right\rangle } = \left[\begin{matrix}1\\\gamma\end{matrix}\right]$
In [87]:
InnerproductOfPsi_Psi = Eq(InnerProduct(braPsi, ketPsi), 1)
display(InnerproductOfPsi_Psi)

$\displaystyle \left\langle \psi \right. {\left|\psi\right\rangle } = 1$
In [88]:
InnerproductOfPsiExpanded_PsiExpanded = Eq(MatMul(braPsiExpanded, ketPsiExpanded), 1, evaluate = False)
display(InnerproductOfPsiExpanded_PsiExpanded)

$\displaystyle \left[\begin{matrix}1 & \overline{\gamma}\end{matrix}\right] \left[\begin{matrix}1\\\gamma\end{matrix}\right] = 1$
In [89]:
valOfKetPsi = Eq(ketPsi, MatMul(alpha, ketPsiExpanded), evaluate = False)
display(valOfKetPsi)

$\displaystyle {\left|\psi\right\rangle } = \alpha \left[\begin{matrix}1\\\gamma\end{matrix}\right]$
In [90]:
InnerproductOfPsi_Psi = Eq(InnerProduct(braPsi, ketPsi), 1)
display(InnerproductOfPsi_Psi)

$\displaystyle \left\langle \psi \right. {\left|\psi\right\rangle } = 1$
In [91]:
InnerproductOfPsiExpanded_PsiExpanded = Eq(Mul(alpha**2,
MatMul(braPsiExpanded,
ketPsiExpanded,
evaluate = False),
evaluate = False),
1,
evaluate = False)
display(InnerproductOfPsiExpanded_PsiExpanded)

$\displaystyle \alpha^{2} \left[\begin{matrix}\gamma \overline{\gamma} + 1\end{matrix}\right] = 1$
In [92]:
InnerproductOfPsiExpanded_PsiExpanded = Eq(Mul(alpha**2,
MatMul(braPsiExpanded,
ketPsiExpanded,
evaluate = False).subs(gamma,
solveForGamma),
evaluate = False).subs((n_x - I*n_y)*(n_x + I*n_y),
((n_x - I*n_y)*(n_x + I*n_y)).expand()),
1,
evaluate = False)
display(InnerproductOfPsiExpanded_PsiExpanded)

$\displaystyle \alpha^{2} \left[\begin{matrix}\frac{\left(1 - n_{z}\right)^{2}}{n_{x}^{2} + n_{y}^{2}} + 1\end{matrix}\right] = 1$
In [93]:
InnerproductOfPsiExpanded_PsiExpanded = Eq(Mul(alpha**2,
MatMul(braPsiExpanded,
ketPsiExpanded,
evaluate = False).subs(gamma,
solveForGamma),
evaluate = False).subs((n_x - I*n_y)*(n_x + I*n_y),
1 - n_z**2),
1,
evaluate = False)
display(InnerproductOfPsiExpanded_PsiExpanded)

$\displaystyle \alpha^{2} \left[\begin{matrix}\frac{\left(1 - n_{z}\right)^{2}}{1 - n_{z}^{2}} + 1\end{matrix}\right] = 1$
In [94]:
InnerproductOfPsiExpanded_PsiExpanded = Eq(Mul(alpha**2,
MatMul(braPsiExpanded,
ketPsiExpanded,
evaluate = False).subs(gamma,
solveForGamma),
evaluate = False).subs((n_x - I*n_y)*(n_x + I*n_y),
1 - n_z**2).simplify(),
1,
evaluate = False)
display(InnerproductOfPsiExpanded_PsiExpanded)

$\displaystyle \alpha^{2} \left[\begin{matrix}\frac{2}{n_{z} + 1}\end{matrix}\right] = 1$
In [95]:
solveOfAlpha = Eq(alpha, sqrt((1 + n_z)/2))
display(solveOfAlpha)

$\displaystyle \alpha = \sqrt{\frac{n_{z}}{2} + \frac{1}{2}}$
In [96]:
valOfKetPsi = Eq(ketPsi, MatMul(solveOfAlpha.rhs, ketPsiExpanded.subs(gamma, solveForGamma)), evaluate = False)
display(valOfKetPsi)

$\displaystyle {\left|\psi\right\rangle } = \sqrt{\frac{n_{z}}{2} + \frac{1}{2}} \left[\begin{matrix}1\\\frac{1 - n_{z}}{n_{x} - i n_{y}}\end{matrix}\right]$
In [ ]: