Verified Commit c8a22c2f authored by Chris Kerr's avatar Chris Kerr

Include sign of k_sum function in final result

parent b447ab21
......@@ -117,7 +117,7 @@ def _gaunt_big_L_part(l_1, l_2, l_3, *, factorials):
def _modified_gaunt_squared(l_1, l_2, l_3, m, *, factorials=None):
"""Square of the modified Gaunt coefficient.
"""Square magnitude and sign of the modified Gaunt coefficient.
Here we are calculating a modified Gaunt coefficient which differs from
the standard coefficient by a factor of sqrt((2 * l_3 + 1) / 4 * pi). That
......@@ -130,19 +130,21 @@ def _modified_gaunt_squared(l_1, l_2, l_3, m, *, factorials=None):
_gaunt_ksum(l_1, l_2, l_3, m, factorials=factorials),
_gaunt_big_L_part(l_1, l_2, l_3, factorials=factorials),
))
return prod((
sq_mag = prod((
_gaunt_sqrt_arg(l_1, l_2, l_3, m, factorials=factorials),
non_sqrt_part * non_sqrt_part,
(2 * l_3 + 1), # For standard Gaunt, omit this
)) # For standard Gaunt, divide by (4 * math.pi)
sign = (-1) ** ((l_1 + l_2 - l_3) // 2)
if non_sqrt_part < 0:
sign *= -1
return sq_mag, sign
def modified_gaunt(l_1, l_2, l_3, m, *, factorials=None):
"""Modified Gaunt coefficient used in the Z translation matrix."""
sign = (-1) ** ((l_1 + l_2 - l_3) // 2)
return sign * math.sqrt(
_modified_gaunt_squared(l_1, l_2, l_3, m, factorials=factorials)
)
sq_mag, sign = _modified_gaunt_squared(l_1, l_2, l_3, m, factorials=factorials)
return sign * math.sqrt(sq_mag)
def shzmat(LMAX):
......
......@@ -55,11 +55,12 @@ def test_sympy_gaunt_vs_wigner(lmkp):
@given(lmkp=LMKP())
def test_python_vs_sympy_gaunt2(lmkp):
L, M, K, P = lmkp
sympy_result = sympy_matrix_element_G(L, M, K, P) ** 2
python_result = gaunt._modified_gaunt_squared(L, K, P, M)
sympy_result = sympy_matrix_element_G(L, M, K, P)
python_result, sign = gaunt._modified_gaunt_squared(L, K, P, M)
assert sign == sympy.sign(sympy_result)
assert_sympy_equal(
python_result,
sympy_result,
sympy_result ** 2,
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment