-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathladder_ops.py
78 lines (56 loc) · 2.16 KB
/
ladder_ops.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import numpy as np
import math
def J_plus(j: int) -> np.ndarray:
if int(2 * j + 1) != 2 * j + 1:
raise ValueError(f"j must be a half integer. Found: {j}")
dim = int(2 * j + 1)
mat = np.zeros((dim, dim))
m_prime_list = np.linspace(-j, j, dim)
m_list = np.linspace(-j, j, dim)
for row, m_prime in enumerate(m_prime_list):
for col, m in enumerate(m_list):
mat[row, col] = J_plus_component(j, m_prime, j, m)
return mat
def J_minus(j: int) -> np.ndarray:
if int(2 * j + 1) != 2 * j + 1:
raise ValueError(f"j must be a half integer. Found: {j}")
dim = int(2 * j + 1)
mat = np.zeros((dim, dim))
m_prime_list = np.linspace(-j, j, dim)
m_list = np.linspace(-j, j, dim)
for row, m_prime in enumerate(m_prime_list):
for col, m in enumerate(m_list):
mat[row, col] = J_minus_component(j, m_prime, j, m)
return mat
def J_plus_component(j_prime: int, m_prime: int, j: int, m: int) -> float:
"""
Get the matrix element of the raising operator
..math::
\langle j_\prime, m_\prime | J_+ | j, m \rangle
\sqrt{(j - m) * (j + m + 1)} \delta_{j_\prime, j} \delta_{m_\prime, m + 1}.
"""
if (j_prime != j) or (m_prime != m + 1):
return 0
return J_plus_coefficient(j, m)
def J_minus_component(j_prime: int, m_prime: int, j: int, m: int) -> float:
"""
Get the matrix element of the lowering operator
..math::
\langle j_\prime, m_\prime | J_+ | j, m \rangle
\sqrt{(j + m) * (j - m + 1)} \delta_{j_\prime, j} \delta_{m_\prime, m - 1}.
"""
if (j_prime != j) or (m_prime != m - 1):
return 0
return J_minus_coefficient(j, m)
def J_plus_coefficient(j: int, m: int) -> float:
"""
Applies raising operator on the state :math:`|j, m \rangle`
and returns the coefficient (:math:`\sqrt{(j + m) (j - m + 1)}`).
"""
return math.sqrt((j - m) * (j + m + 1))
def J_minus_coefficient(j: int, m: int) -> float:
"""
Applies lowering operator on the state :math:`|j, m \rangle`
and returns the coefficient (:math:`\sqrt{(j - m) (j + m + 1)}`).
"""
return math.sqrt((j + m) * (j - m + 1))