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 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 [2]:
M1 = Operator('M_1')
M2 = Operator('M_2')
momentumOperator = HermitianOperator('P')
positionOperator = HermitianOperator('x')
A = Operator('A')
B = Operator('B')
sigma_x = HermitianOperator('sigma_x')
sigma_y = HermitianOperator('sigma_y')
sigma_z = HermitianOperator('sigma_z')

In [3]:
commutatorOfM1_M2 = Eq(Commutator(M1, M2), 0)
display(commutatorOfM1_M2)

$\displaystyle \left[M_{1},M_{2}\right] = 0$
In [4]:
commutatorOfMomentumOperator_PositionOperator = Unequality(Eq(Commutator(momentumOperator,
positionOperator),
I * hbar),
0,
evaluate = False)

display(commutatorOfMomentumOperator_PositionOperator)

$\displaystyle \left[P,x\right] = \hbar i \neq 0$
In [5]:
commutatorOfA_B = Eq(Commutator(A, B), A * B - B * A)
display(commutatorOfA_B)

$\displaystyle \left[A,B\right] = A B - B A$
In [6]:
commutatorOfB_A = Eq(Commutator(B, A), B * A - A * B)
display(commutatorOfB_A)

$\displaystyle - \left[A,B\right] = - A B + B A$
In [7]:
sigma_xExpanded = Matrix([[0, 1],[1, 0]])
display(sigma_xExpanded)

$\displaystyle \left[\begin{matrix}0 & 1\\1 & 0\end{matrix}\right]$
In [8]:
sigma_yExpanded = Matrix([[0, -I],[I, 0]])
display(sigma_yExpanded)

$\displaystyle \left[\begin{matrix}0 & - i\\i & 0\end{matrix}\right]$
In [9]:
sigma_zExpanded = Matrix([[1, 0],[0, -1]])
display(sigma_zExpanded)

$\displaystyle \left[\begin{matrix}1 & 0\\0 & -1\end{matrix}\right]$
In [10]:
commutatorOfSigma_z_sigma_x = Eq(Commutator(sigma_z, sigma_x), sigma_z * sigma_x - sigma_x * sigma_z)
display(commutatorOfSigma_z_sigma_x)

$\displaystyle - \left[\sigma_{x},\sigma_{z}\right] = - \sigma_{x} \sigma_{z} + \sigma_{z} \sigma_{x}$
In [11]:
commutatorOfSigma_z_sigma_x = Eq(Commutator(sigma_z, sigma_x),
MatMul(MatMul(-1, sigma_xExpanded),
sigma_zExpanded),
evaluate = False),
evaluate = False)
display(commutatorOfSigma_z_sigma_x)

$\displaystyle - \left[\sigma_{x},\sigma_{z}\right] = - \left[\begin{matrix}0 & 1\\1 & 0\end{matrix}\right] \left[\begin{matrix}1 & 0\\0 & -1\end{matrix}\right] + \left[\begin{matrix}1 & 0\\0 & -1\end{matrix}\right] \left[\begin{matrix}0 & 1\\1 & 0\end{matrix}\right]$
In [12]:
commutatorOfSigma_z_sigma_x = Eq(Commutator(sigma_z, sigma_x),
MatMul(2 * i,
MatMul(-1, sigma_xExpanded) * sigma_zExpanded)*-I/2),
evaluate = False)
display(commutatorOfSigma_z_sigma_x)

$\displaystyle - \left[\sigma_{x},\sigma_{z}\right] = 2 i \left[\begin{matrix}0 & - i\\i & 0\end{matrix}\right]$
In [13]:
commutatorOfSigma_z_sigma_x = Unequality(Eq(Commutator(sigma_z, sigma_x),
2 * I* sigma_y),
0,
evaluate = False)
display(commutatorOfSigma_z_sigma_x)

$\displaystyle - \left[\sigma_{x},\sigma_{z}\right] = 2 i \sigma_{y} \neq 0$
In [14]:
commutatorOfSigma_z_sigma_y = Eq(Commutator(sigma_z, sigma_y), sigma_z * sigma_y - sigma_y * sigma_z)
display(commutatorOfSigma_z_sigma_y)

$\displaystyle - \left[\sigma_{y},\sigma_{z}\right] = - \sigma_{y} \sigma_{z} + \sigma_{z} \sigma_{y}$
In [15]:
commutatorOfSigma_z_sigma_y = Eq(Commutator(sigma_z, sigma_y),
MatMul(MatMul(-1, sigma_yExpanded),
sigma_zExpanded),
evaluate = False),
evaluate = False)
display(commutatorOfSigma_z_sigma_y)

$\displaystyle - \left[\sigma_{y},\sigma_{z}\right] = - \left[\begin{matrix}0 & - i\\i & 0\end{matrix}\right] \left[\begin{matrix}1 & 0\\0 & -1\end{matrix}\right] + \left[\begin{matrix}1 & 0\\0 & -1\end{matrix}\right] \left[\begin{matrix}0 & - i\\i & 0\end{matrix}\right]$
In [16]:
commutatorOfSigma_z_sigma_y = Eq(Commutator(sigma_z, sigma_y),
MatMul(-2 * i,
MatMul(-1, sigma_yExpanded) * sigma_zExpanded)*I/2),
evaluate = False)
display(commutatorOfSigma_z_sigma_y)

$\displaystyle - \left[\sigma_{y},\sigma_{z}\right] = - 2 i \left[\begin{matrix}0 & 1\\1 & 0\end{matrix}\right]$
In [17]:
commutatorOfSigma_z_sigma_y = Unequality(Eq(Commutator(sigma_z, sigma_y),
-2 * I* sigma_x),
0,
evaluate = False)
display(commutatorOfSigma_z_sigma_y)

$\displaystyle - \left[\sigma_{y},\sigma_{z}\right] = - 2 i \sigma_{x} \neq 0$
In [18]:
commutatorOfSigma_x_sigma_y = Eq(Commutator(sigma_x, sigma_y), sigma_x * sigma_y - sigma_y * sigma_x)
display(commutatorOfSigma_x_sigma_y)

$\displaystyle \left[\sigma_{x},\sigma_{y}\right] = \sigma_{x} \sigma_{y} - \sigma_{y} \sigma_{x}$
In [19]:
commutatorOfSigma_x_sigma_y = Eq(Commutator(sigma_x, sigma_y),
MatMul(MatMul(-1, sigma_yExpanded),
sigma_xExpanded),
evaluate = False),
evaluate = False)
display(commutatorOfSigma_x_sigma_y)

$\displaystyle \left[\sigma_{x},\sigma_{y}\right] = - \left[\begin{matrix}0 & - i\\i & 0\end{matrix}\right] \left[\begin{matrix}0 & 1\\1 & 0\end{matrix}\right] + \left[\begin{matrix}0 & 1\\1 & 0\end{matrix}\right] \left[\begin{matrix}0 & - i\\i & 0\end{matrix}\right]$
In [20]:
commutatorOfSigma_x_sigma_y = Eq(Commutator(sigma_x, sigma_y),
MatMul(2 * i,
-sigma_yExpanded * sigma_xExpanded)*-I/2),
evaluate = False)
display(commutatorOfSigma_x_sigma_y)

$\displaystyle \left[\sigma_{x},\sigma_{y}\right] = 2 i \left[\begin{matrix}1 & 0\\0 & -1\end{matrix}\right]$
In [21]:
commutatorOfSigma_x_sigma_y = Unequality(Eq(Commutator(sigma_x, sigma_y),
2 * I* sigma_z),
0,
evaluate = False)
display(commutatorOfSigma_x_sigma_y)

$\displaystyle \left[\sigma_{x},\sigma_{y}\right] = 2 i \sigma_{z} \neq 0$
In [ ]: