002-001-photon-polarisation.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.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)
$\displaystyle {\left|a\right\rangle }$
$\displaystyle {\left|b\right\rangle }$
In [4]:
braA = Bra('a')
display(braA)
braB = Bra('b')
display(braB)
$\displaystyle {\left\langle a\right|}$
$\displaystyle {\left\langle b\right|}$
In [5]:
ketA_i = Ket('a_i')
display(ketA_i)
ketA_k = Ket('a_k')
display(ketA_k)
$\displaystyle {\left|a_{i}\right\rangle }$
$\displaystyle {\left|a_{k}\right\rangle }$
In [6]:
braA_i = Bra('a_i')
display(braA_i)
braA_k = Bra('a_k')
display(braA_k)
$\displaystyle {\left\langle a_{i}\right|}$
$\displaystyle {\left\langle a_{k}\right|}$
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)
$\displaystyle \begin{cases} \left\langle a_{i} \right. {\left|a_{k}\right\rangle } = 1 & \text{for}\: i = k \\\left\langle a_{i} \right. {\left|a_{k}\right\rangle } = 0 & \text{for}\: i \neq k \end{cases}$
In [8]:
H = HermitianOperator('H')
lambdaA = symbols('lambda_a')
lambdaB = symbols('lambda_b')
In [9]:
systemA = Eq(H * ketA, lambdaA * ketA)
display(systemA)
$\displaystyle H {\left|a\right\rangle } = \lambda_{a} {\left|a\right\rangle }$
In [10]:
systemB = Eq(H * ketB, lambdaB * ketB)
display(systemB)
$\displaystyle H {\left|b\right\rangle } = \lambda_{b} {\left|b\right\rangle }$
In [11]:
innerprodOfBraBsystemA = Eq(braB * H * ketA, lambdaA * InnerProduct(braB, ketA))
display(innerprodOfBraBsystemA)
$\displaystyle {\left\langle b\right|} H {\left|a\right\rangle } = \lambda_{a} \left\langle b \right. {\left|a\right\rangle }$
In [12]:
innerprodOfBraAsystemB = Eq(braA * H * ketB, lambdaB * InnerProduct(braA, ketB))
display(innerprodOfBraAsystemB)
$\displaystyle {\left\langle a\right|} H {\left|b\right\rangle } = \lambda_{b} \left\langle a \right. {\left|b\right\rangle }$
In [13]:
innerprodOfAB = Eq(conjugate(InnerProduct(braA, ketB), evaluate = False), InnerProduct(braB, ketA), evaluate = False)
display(innerprodOfAB)
$\displaystyle \overline{\left\langle a \right. {\left|b\right\rangle }} = \left\langle b \right. {\left|a\right\rangle }$
In [14]:
conjInnerprodOfBraAsystemB = Eq(braB * H * ketA, conjugate(lambdaB * InnerProduct(braA, ketB)))
display(conjInnerprodOfBraAsystemB)
$\displaystyle {\left\langle b\right|} H {\left|a\right\rangle } = \overline{\lambda_{b}} \left\langle b \right. {\left|a\right\rangle }$
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)
$\displaystyle 0 = \left(\lambda_{a} - \overline{\lambda_{b}}\right) \left\langle b \right. {\left|a\right\rangle }$
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)
$\displaystyle \left[\begin{matrix}1\\0\end{matrix}\right]$
$\displaystyle \left[\begin{matrix}1 & 0\end{matrix}\right]$
In [18]:
ketYExpanded = Matrix([[0],[1]])
display(ketYExpanded)
braYExpanded = conjugate(ketYExpanded.T)
display(braYExpanded)
$\displaystyle \left[\begin{matrix}0\\1\end{matrix}\right]$
$\displaystyle \left[\begin{matrix}0 & 1\end{matrix}\right]$
In [19]:
ket0 = Ket(0*degree)
display(ket0)
bra0 = Bra(0*degree)
display(bra0)
$\displaystyle {\left|0\right\rangle }$
$\displaystyle {\left\langle 0\right|}$
In [20]:
ket0Expanded = ketXExpanded
display(ket0Expanded)
bra0Expanded = ket0Expanded.T
display(bra0Expanded)
$\displaystyle \left[\begin{matrix}1\\0\end{matrix}\right]$
$\displaystyle \left[\begin{matrix}1 & 0\end{matrix}\right]$
In [21]:
ket90 = Ket(90*degree)
display(ket90)
bra90 = Bra(90*degree)
display(bra90)
$\displaystyle {\left|90 ^\circ\right\rangle }$
$\displaystyle {\left\langle 90 ^\circ\right|}$
In [22]:
ket90Expanded = ketYExpanded
display(ket90Expanded)
bra90Expanded = ket90Expanded.T
display(bra90Expanded)
$\displaystyle \left[\begin{matrix}0\\1\end{matrix}\right]$
$\displaystyle \left[\begin{matrix}0 & 1\end{matrix}\right]$
In [23]:
ket45 = Ket(45*degree)
display(ket45)
bra45 = Bra(45*degree)
display(bra45)
$\displaystyle {\left|45 ^\circ\right\rangle }$
$\displaystyle {\left\langle 45 ^\circ\right|}$
In [24]:
ket45Expanded = ketXExpanded/sqrt(2) + ketYExpanded/sqrt(2)
display(ket45Expanded)
bra45Expanded = conjugate(ket45Expanded.T)
display(bra45Expanded)
$\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 [25]:
ket135 = Ket(135*degree)
display(ket135)
bra135 = Bra(135*degree)
display(bra135)
$\displaystyle {\left|135 ^\circ\right\rangle }$
$\displaystyle {\left\langle 135 ^\circ\right|}$
In [26]:
ket135Expanded = ketXExpanded/sqrt(2) - ketYExpanded/sqrt(2)
display(ket135Expanded)
bra135Expanded = conjugate(ket135Expanded.T)
display(bra135Expanded)
$\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 [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)
$\displaystyle {\left|0\right\rangle } = \left[\begin{matrix}1\\0\end{matrix}\right] = 0 {\left|y\right\rangle } + {\left|x\right\rangle }$
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)
$\displaystyle {\left|90 ^\circ\right\rangle } = \left[\begin{matrix}0\\1\end{matrix}\right] = {\left|y\right\rangle } + 0 {\left|x\right\rangle }$
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)
$\displaystyle {\left|45 ^\circ\right\rangle } = \left[\begin{matrix}\frac{\sqrt{2}}{2}\\\frac{\sqrt{2}}{2}\end{matrix}\right] = \frac{\sqrt{2}}{2} {\left|y\right\rangle } + \frac{\sqrt{2}}{2} {\left|x\right\rangle }$
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)
$\displaystyle {\left|135 ^\circ\right\rangle } = \left[\begin{matrix}\frac{\sqrt{2}}{2}\\- \frac{\sqrt{2}}{2}\end{matrix}\right] = \frac{\sqrt{2}}{2} {\left|y\right\rangle } + \frac{\sqrt{2}}{2} {\left|x\right\rangle }$
In [31]:
kettheta = Ket(theta)
display(kettheta)
bratheta = Bra(theta)
display(bratheta)
$\displaystyle {\left|\theta\right\rangle }$
$\displaystyle {\left\langle \theta\right|}$
In [32]:
ketthetaExpanded = alpha * ketXExpanded + beta * ketYExpanded
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 [33]:
valOfKettheta = Eq(kettheta,
               Eq(ketthetaExpanded,
                    ketthetaExpanded[0] * ketX + ketthetaExpanded[1] * ketY,
                  evaluate = False),  
               evaluate = False)
display(valOfKettheta)
$\displaystyle {\left|\theta\right\rangle } = \left[\begin{matrix}\alpha\\\beta\end{matrix}\right] = \alpha {\left|x\right\rangle } + \beta {\left|y\right\rangle }$
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)
$\displaystyle \left[\begin{matrix}\cos{\left(\theta \right)}\\\sin{\left(\theta \right)}\end{matrix}\right]$
$\displaystyle \left[\begin{matrix}\cos{\left(\theta \right)} & \sin{\left(\theta \right)}\end{matrix}\right]$
In [35]:
valOfKettheta = Eq(kettheta,
               Eq(ketthetaExpanded,
                    ketthetaExpanded[0] * ketX + ketthetaExpanded[1] * ketY,
                  evaluate = False),  
               evaluate = False)
display(valOfKettheta)
$\displaystyle {\left|\theta\right\rangle } = \left[\begin{matrix}\cos{\left(\theta \right)}\\\sin{\left(\theta \right)}\end{matrix}\right] = \sin{\left(\theta \right)} {\left|y\right\rangle } + \cos{\left(\theta \right)} {\left|x\right\rangle }$
In [36]:
eField = symbols('E')
In [37]:
eFieldExpanded = Eq(eField, h*f)
display(eFieldExpanded)
$\displaystyle E = f h$
In [38]:
ketnegtheta = Ket(-theta)
display(ketnegtheta)
branegtheta = Bra(-theta)
display(branegtheta)
$\displaystyle {\left|- \theta\right\rangle }$
$\displaystyle {\left\langle - \theta\right|}$
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)
$\displaystyle \left[\begin{matrix}- \sin{\left(\theta \right)}\\\cos{\left(\theta \right)}\end{matrix}\right]$
$\displaystyle \left[\begin{matrix}- \sin{\left(\theta \right)} & \cos{\left(\theta \right)}\end{matrix}\right]$
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)
$\displaystyle \left|{\left\langle \theta \right. {\left|- \theta\right\rangle }}\right|^{2} = \left|{\left[\begin{matrix}\cos{\left(\theta \right)} & \sin{\left(\theta \right)}\end{matrix}\right] \left[\begin{matrix}- \sin{\left(\theta \right)}\\\cos{\left(\theta \right)}\end{matrix}\right]}\right|^{2} = \left[\begin{matrix}0\end{matrix}\right]$
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)
$\displaystyle \left|{\left\langle \theta \right. {\left|\theta\right\rangle }}\right|^{2} = \left|{\left[\begin{matrix}\cos{\left(\theta \right)} & \sin{\left(\theta \right)}\end{matrix}\right] \left[\begin{matrix}\cos{\left(\theta \right)}\\\sin{\left(\theta \right)}\end{matrix}\right]}\right|^{2} = \left[\begin{matrix}1\end{matrix}\right]$
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)
$\displaystyle \left|{\left\langle - \theta \right. {\left|- \theta\right\rangle }}\right|^{2} = \left|{\left[\begin{matrix}- \sin{\left(\theta \right)} & \cos{\left(\theta \right)}\end{matrix}\right] \left[\begin{matrix}- \sin{\left(\theta \right)}\\\cos{\left(\theta \right)}\end{matrix}\right]}\right|^{2} = \left[\begin{matrix}1\end{matrix}\right]$
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)
$\displaystyle \left|{\left\langle x \right. {\left|\theta\right\rangle }}\right|^{2} = \left|{\left[\begin{matrix}1 & 0\end{matrix}\right] \left[\begin{matrix}\cos{\left(\theta \right)}\\\sin{\left(\theta \right)}\end{matrix}\right]}\right|^{2} = \left[\begin{matrix}\left|{\cos{\left(\theta \right)}}\right|^{2}\end{matrix}\right]$
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)
$\displaystyle \left|{\left\langle y \right. {\left|\theta\right\rangle }}\right|^{2} = \left|{\left[\begin{matrix}0 & 1\end{matrix}\right] \left[\begin{matrix}\cos{\left(\theta \right)}\\\sin{\left(\theta \right)}\end{matrix}\right]}\right|^{2} = \left[\begin{matrix}\left|{\sin{\left(\theta \right)}}\right|^{2}\end{matrix}\right]$
In [45]:
ketAlpha = Ket(alpha)
display(ketAlpha)
braAlpha = Bra(alpha)
display(braAlpha)
$\displaystyle {\left|\alpha\right\rangle }$
$\displaystyle {\left\langle \alpha\right|}$
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)
$\displaystyle \left[\begin{matrix}\cos{\left(\alpha \right)}\\\sin{\left(\alpha \right)}\end{matrix}\right]$
$\displaystyle \left[\begin{matrix}\cos{\left(\alpha \right)} & \sin{\left(\alpha \right)}\end{matrix}\right]$
In [47]:
ketBeta = Ket(beta)
display(ketBeta)
braBeta = Bra(beta)
display(braBeta)
$\displaystyle {\left|\beta\right\rangle }$
$\displaystyle {\left\langle \beta\right|}$
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)
$\displaystyle \left[\begin{matrix}\cos{\left(\beta \right)}\\\sin{\left(\beta \right)}\end{matrix}\right]$
$\displaystyle \left[\begin{matrix}\cos{\left(\beta \right)} & \sin{\left(\beta \right)}\end{matrix}\right]$
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)
$\displaystyle \left|{\left\langle \alpha \right. {\left|\beta\right\rangle }}\right|^{2} = \left|{\left[\begin{matrix}\cos{\left(\alpha \right)} & \sin{\left(\alpha \right)}\end{matrix}\right] \left[\begin{matrix}\cos{\left(\beta \right)}\\\sin{\left(\beta \right)}\end{matrix}\right]}\right|^{2} = \left[\begin{matrix}\left|{\cos{\left(\alpha - \beta \right)}}\right|^{2}\end{matrix}\right]$
In [50]:
HExpanded = Matrix([[cos(2 * theta), sin(2 * theta)],[sin(2 * theta), -cos(2 * theta)]])
display(HExpanded)
$\displaystyle \left[\begin{matrix}\cos{\left(2 \theta \right)} & \sin{\left(2 \theta \right)}\\\sin{\left(2 \theta \right)} & - \cos{\left(2 \theta \right)}\end{matrix}\right]$
In [51]:
cos2ThetaExpanded = Eq(cos(2 * theta), cos(theta)**2 - sin(theta)**2)
display(cos2ThetaExpanded)
$\displaystyle \cos{\left(2 \theta \right)} = - \sin^{2}{\left(\theta \right)} + \cos^{2}{\left(\theta \right)}$
In [52]:
sin2ThetaExpanded = Eq(sin(2 * theta),2 * sin(theta) * cos(theta))
display(sin2ThetaExpanded)
$\displaystyle \sin{\left(2 \theta \right)} = 2 \sin{\left(\theta \right)} \cos{\left(\theta \right)}$
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)
$\displaystyle \left[\begin{matrix}- \sin^{2}{\left(\theta \right)} + \cos^{2}{\left(\theta \right)} & 2 \sin{\left(\theta \right)} \cos{\left(\theta \right)}\\2 \sin{\left(\theta \right)} \cos{\left(\theta \right)} & \sin^{2}{\left(\theta \right)} - \cos^{2}{\left(\theta \right)}\end{matrix}\right]$
In [54]:
productOfHExpanded_kettheta = Eq(MatMul(HExpanded, ketthetaExpanded),
                                        MatMul(lamda, ketthetaExpanded,
                                               evaluate = False),
                                        evaluate = False) 
display(productOfHExpanded_kettheta)
$\displaystyle \left[\begin{matrix}- \sin^{2}{\left(\theta \right)} + \cos^{2}{\left(\theta \right)} & 2 \sin{\left(\theta \right)} \cos{\left(\theta \right)}\\2 \sin{\left(\theta \right)} \cos{\left(\theta \right)} & \sin^{2}{\left(\theta \right)} - \cos^{2}{\left(\theta \right)}\end{matrix}\right] \left[\begin{matrix}\cos{\left(\theta \right)}\\\sin{\left(\theta \right)}\end{matrix}\right] = \lambda \left[\begin{matrix}\cos{\left(\theta \right)}\\\sin{\left(\theta \right)}\end{matrix}\right]$
In [55]:
productOfHExpanded_kettheta = Eq(HExpanded * ketthetaExpanded,
                                 Matrix([(HExpanded * ketthetaExpanded)[0].simplify(),
                                         (HExpanded * ketthetaExpanded)[1].simplify()]),
                                 evaluate = False) 
display(productOfHExpanded_kettheta)
$\displaystyle \left[\begin{matrix}\left(- \sin^{2}{\left(\theta \right)} + \cos^{2}{\left(\theta \right)}\right) \cos{\left(\theta \right)} + 2 \sin^{2}{\left(\theta \right)} \cos{\left(\theta \right)}\\\left(\sin^{2}{\left(\theta \right)} - \cos^{2}{\left(\theta \right)}\right) \sin{\left(\theta \right)} + 2 \sin{\left(\theta \right)} \cos^{2}{\left(\theta \right)}\end{matrix}\right] = \left[\begin{matrix}\cos{\left(\theta \right)}\\\sin{\left(\theta \right)}\end{matrix}\right]$
In [56]:
valOfLambda = Eq(lamda, 1)
display(valOfLambda)
$\displaystyle \lambda = 1$
In [57]:
productOfHExpanded_ketnegtheta = Eq(MatMul(HExpanded, ketnegthetaExpanded),
                                        MatMul(lamda, ketnegthetaExpanded,
                                               evaluate = False),
                                        evaluate = False)
display(productOfHExpanded_ketnegtheta)
$\displaystyle \left[\begin{matrix}- \sin^{2}{\left(\theta \right)} + \cos^{2}{\left(\theta \right)} & 2 \sin{\left(\theta \right)} \cos{\left(\theta \right)}\\2 \sin{\left(\theta \right)} \cos{\left(\theta \right)} & \sin^{2}{\left(\theta \right)} - \cos^{2}{\left(\theta \right)}\end{matrix}\right] \left[\begin{matrix}- \sin{\left(\theta \right)}\\\cos{\left(\theta \right)}\end{matrix}\right] = \lambda \left[\begin{matrix}- \sin{\left(\theta \right)}\\\cos{\left(\theta \right)}\end{matrix}\right]$
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)
$\displaystyle \left[\begin{matrix}- \sin^{2}{\left(\theta \right)} + \cos^{2}{\left(\theta \right)} & 2 \sin{\left(\theta \right)} \cos{\left(\theta \right)}\\2 \sin{\left(\theta \right)} \cos{\left(\theta \right)} & \sin^{2}{\left(\theta \right)} - \cos^{2}{\left(\theta \right)}\end{matrix}\right] \left[\begin{matrix}- \sin{\left(\theta \right)}\\\cos{\left(\theta \right)}\end{matrix}\right] = \left[\begin{matrix}- \left(- \sin^{2}{\left(\theta \right)} + \cos^{2}{\left(\theta \right)}\right) \sin{\left(\theta \right)} + 2 \sin{\left(\theta \right)} \cos^{2}{\left(\theta \right)}\\\left(\sin^{2}{\left(\theta \right)} - \cos^{2}{\left(\theta \right)}\right) \cos{\left(\theta \right)} - 2 \sin^{2}{\left(\theta \right)} \cos{\left(\theta \right)}\end{matrix}\right] = \left[\begin{matrix}\sin{\left(\theta \right)}\\- \cos{\left(\theta \right)}\end{matrix}\right]$
In [59]:
valOfLambda = Eq(lamda, -1)
display(valOfLambda)
$\displaystyle \lambda = -1$
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)
$\displaystyle E_{x} = E_{0} \sin{\left(E k - t w \right)}$
In [62]:
valOfEY = Eq(eFieldY, eField0 * cos(k*eField - w*t))
display(valOfEY)
$\displaystyle E_{y} = E_{0} \cos{\left(E k - t w \right)}$
In [63]:
ketClock = Ket('Clock')
display(ketClock)
braClock = Bra('Clock')
display(braClock)
$\displaystyle {\left|Clock\right\rangle }$
$\displaystyle {\left\langle Clock\right|}$
In [64]:
ketClockExpanded = alpha * ketXExpanded + beta * ketYExpanded
display(ketClockExpanded)
braClockExpanded = conjugate(ketClockExpanded.T)
display(braClockExpanded)
$\displaystyle \left[\begin{matrix}\alpha\\\beta\end{matrix}\right]$
$\displaystyle \left[\begin{matrix}\overline{\alpha} & \overline{\beta}\end{matrix}\right]$
In [65]:
valOfKetClock = Eq(ketClock,
               Eq(ketClockExpanded,
                    ketClockExpanded[0] * ketX + ketClockExpanded[1] * ketY,
                  evaluate = False),  
               evaluate = False)
display(valOfKetClock)
$\displaystyle {\left|Clock\right\rangle } = \left[\begin{matrix}\alpha\\\beta\end{matrix}\right] = \alpha {\left|x\right\rangle } + \beta {\left|y\right\rangle }$
In [66]:
ketClockExpanded = 1/sqrt(2) * ketXExpanded + I/sqrt(2) * ketYExpanded
display(ketClockExpanded)
braClockExpanded = conjugate(ketClockExpanded.T)
display(braClockExpanded)
$\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 [67]:
valOfKetClock = Eq(ketClock,
               Eq(ketClockExpanded,
                    (ketClockExpanded[0] * ketX + ketClockExpanded[1] * ketY),
                  evaluate = False),  
               evaluate = False)
display(valOfKetClock)
$\displaystyle {\left|Clock\right\rangle } = \left[\begin{matrix}\frac{\sqrt{2}}{2}\\\frac{\sqrt{2} i}{2}\end{matrix}\right] = \frac{\sqrt{2} i {\left|y\right\rangle }}{2} + \frac{\sqrt{2} {\left|x\right\rangle }}{2}$
In [68]:
ketAntiClock = Ket('AntiClock')
display(ketAntiClock)
braAntiClock = Bra('AntiClock')
display(braAntiClock)
$\displaystyle {\left|AntiClock\right\rangle }$
$\displaystyle {\left\langle AntiClock\right|}$
In [69]:
ketAntiClockExpanded = 1/sqrt(2) * ketXExpanded + -I/sqrt(2) * ketYExpanded
display(ketAntiClockExpanded)
braAntiClockExpanded = conjugate(ketAntiClockExpanded.T)
display(braAntiClockExpanded)
$\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 [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)
$\displaystyle \left|{\left\langle Clock \right. {\left|AntiClock\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} i}{2}\end{matrix}\right]}\right|^{2} = \left[\begin{matrix}0\end{matrix}\right]$
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)
$\displaystyle \left|{\left\langle \theta \right. {\left|Clock\right\rangle }}\right|^{2} = \left|{\left[\begin{matrix}\cos{\left(\theta \right)} & \sin{\left(\theta \right)}\end{matrix}\right] \left[\begin{matrix}\frac{\sqrt{2}}{2}\\\frac{\sqrt{2} i}{2}\end{matrix}\right]}\right|^{2} = \left[\begin{matrix}\frac{e^{- 2 \operatorname{im}{\left(\theta\right)}}}{2}\end{matrix}\right]$
In [72]:
HExpanded = Matrix([[0, -I],[I, 0]])
display(HExpanded)
$\displaystyle \left[\begin{matrix}0 & - i\\i & 0\end{matrix}\right]$
In [73]:
productOfHExpanded_ketClock = Eq(MatMul(HExpanded, ketClockExpanded),
                                        MatMul(lamda, ketClockExpanded,
                                               evaluate = False),
                                        evaluate = False) 
display(productOfHExpanded_ketClock)
$\displaystyle \left[\begin{matrix}0 & - i\\i & 0\end{matrix}\right] \left[\begin{matrix}\frac{\sqrt{2}}{2}\\\frac{\sqrt{2} i}{2}\end{matrix}\right] = \lambda \left[\begin{matrix}\frac{\sqrt{2}}{2}\\\frac{\sqrt{2} i}{2}\end{matrix}\right]$
In [74]:
productOfHExpanded_ketClock = Eq(MatMul(HExpanded, ketClockExpanded),
                                 Matrix([(HExpanded * ketClockExpanded)[0].simplify(),
                                         (HExpanded * ketClockExpanded)[1].simplify()]),
                                 evaluate = False) 
display(productOfHExpanded_ketClock)
$\displaystyle \left[\begin{matrix}0 & - i\\i & 0\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 [75]:
valOfLambda = Eq(lamda, 1)
display(valOfLambda)
$\displaystyle \lambda = 1$
In [76]:
productOfHExpanded_ketAntiClock = Eq(MatMul(HExpanded, ketAntiClockExpanded),
                                        MatMul(lamda, ketAntiClockExpanded,
                                               evaluate = False),
                                        evaluate = False) 
display(productOfHExpanded_ketAntiClock)
$\displaystyle \left[\begin{matrix}0 & - i\\i & 0\end{matrix}\right] \left[\begin{matrix}\frac{\sqrt{2}}{2}\\- \frac{\sqrt{2} i}{2}\end{matrix}\right] = \lambda \left[\begin{matrix}\frac{\sqrt{2}}{2}\\- \frac{\sqrt{2} i}{2}\end{matrix}\right]$
In [77]:
productOfHExpanded_ketAntiClock = Eq(MatMul(HExpanded, ketAntiClockExpanded),
                                 Matrix([(HExpanded * ketAntiClockExpanded)[0].simplify(),
                                         (HExpanded * ketAntiClockExpanded)[1].simplify()]),
                                 evaluate = False) 
display(productOfHExpanded_ketAntiClock)
$\displaystyle \left[\begin{matrix}0 & - i\\i & 0\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 [78]:
valOfLambda = Eq(lamda, -1)
display(valOfLambda)
$\displaystyle \lambda = -1$
In [ ]:
    

Machine Learning

  1. Deal Banking Marketing Campaign Dataset With Machine Learning

TensorFlow

  1. Difference Between Scalar, Vector, Matrix and Tensor
  2. TensorFlow Deep Learning Model With IRIS Dataset
  3. Sequence to Sequence Learning With Neural Networks To Perform Number Addition
  4. Image Classification Model MobileNet V2 from TensorFlow Hub
  5. Step by Step Intent Recognition With BERT
  6. Sentiment Analysis for Hotel Reviews With NLTK and Keras
  7. Simple Sequence Prediction With LSTM
  8. Image Classification With ResNet50 Model
  9. Predict Amazon Inc Stock Price with Machine Learning
  10. Predict Diabetes With Machine Learning Algorithms
  11. TensorFlow Build Custom Convolutional Neural Network With MNIST Dataset
  12. Deal Banking Marketing Campaign Dataset With Machine Learning

PySpark

  1. How to Parallelize and Distribute Collection in PySpark
  2. Role of StringIndexer and Pipelines in PySpark ML Feature - Part 1
  3. Role of OneHotEncoder and Pipelines in PySpark ML Feature - Part 2
  4. Feature Transformer VectorAssembler in PySpark ML Feature - Part 3
  5. Logistic Regression in PySpark (ML Feature) with Breast Cancer Data Set

PyTorch

  1. Build the Neural Network with PyTorch
  2. Image Classification with PyTorch
  3. Twitter Sentiment Classification In PyTorch
  4. Training an Image Classifier in Pytorch

Natural Language Processing

  1. Spelling Correction Of The Text Data In Natural Language Processing
  2. Handling Text For Machine Learning
  3. Extracting Text From PDF File in Python Using PyPDF2
  4. How to Collect Data Using Twitter API V2 For Natural Language Processing
  5. Converting Text to Features in Natural Language Processing
  6. Extract A Noun Phrase For A Sentence In Natural Language Processing