switching to high quality piper tts and added label translations
This commit is contained in:
@@ -0,0 +1,223 @@
|
||||
from sympy.core.numbers import (I, pi, Rational)
|
||||
from sympy.core.singleton import S
|
||||
from sympy.core.symbol import symbols
|
||||
from sympy.functions.elementary.exponential import exp
|
||||
from sympy.functions.elementary.miscellaneous import sqrt
|
||||
from sympy.functions.elementary.trigonometric import (cos, sin)
|
||||
from sympy.functions.special.spherical_harmonics import Ynm
|
||||
from sympy.matrices.dense import Matrix
|
||||
from sympy.physics.wigner import (clebsch_gordan, wigner_9j, wigner_6j, gaunt,
|
||||
real_gaunt, racah, dot_rot_grad_Ynm, wigner_3j, wigner_d_small, wigner_d)
|
||||
from sympy.testing.pytest import raises, skip
|
||||
|
||||
# for test cases, refer : https://en.wikipedia.org/wiki/Table_of_Clebsch%E2%80%93Gordan_coefficients
|
||||
|
||||
def test_clebsch_gordan_docs():
|
||||
assert clebsch_gordan(Rational(3, 2), S.Half, 2, Rational(3, 2), S.Half, 2) == 1
|
||||
assert clebsch_gordan(Rational(3, 2), S.Half, 1, Rational(3, 2), Rational(-1, 2), 1) == sqrt(3)/2
|
||||
assert clebsch_gordan(Rational(3, 2), S.Half, 1, Rational(-1, 2), S.Half, 0) == -sqrt(2)/2
|
||||
|
||||
|
||||
def test_clebsch_gordan():
|
||||
# Argument order: (j_1, j_2, j, m_1, m_2, m)
|
||||
|
||||
h = S.One
|
||||
k = S.Half
|
||||
l = Rational(3, 2)
|
||||
i = Rational(-1, 2)
|
||||
n = Rational(7, 2)
|
||||
p = Rational(5, 2)
|
||||
assert clebsch_gordan(k, k, 1, k, k, 1) == 1
|
||||
assert clebsch_gordan(k, k, 1, k, k, 0) == 0
|
||||
assert clebsch_gordan(k, k, 1, i, i, -1) == 1
|
||||
assert clebsch_gordan(k, k, 1, k, i, 0) == sqrt(2)/2
|
||||
assert clebsch_gordan(k, k, 0, k, i, 0) == sqrt(2)/2
|
||||
assert clebsch_gordan(k, k, 1, i, k, 0) == sqrt(2)/2
|
||||
assert clebsch_gordan(k, k, 0, i, k, 0) == -sqrt(2)/2
|
||||
assert clebsch_gordan(h, k, l, 1, k, l) == 1
|
||||
assert clebsch_gordan(h, k, l, 1, i, k) == 1/sqrt(3)
|
||||
assert clebsch_gordan(h, k, k, 1, i, k) == sqrt(2)/sqrt(3)
|
||||
assert clebsch_gordan(h, k, k, 0, k, k) == -1/sqrt(3)
|
||||
assert clebsch_gordan(h, k, l, 0, k, k) == sqrt(2)/sqrt(3)
|
||||
assert clebsch_gordan(h, h, S(2), 1, 1, S(2)) == 1
|
||||
assert clebsch_gordan(h, h, S(2), 1, 0, 1) == 1/sqrt(2)
|
||||
assert clebsch_gordan(h, h, S(2), 0, 1, 1) == 1/sqrt(2)
|
||||
assert clebsch_gordan(h, h, 1, 1, 0, 1) == 1/sqrt(2)
|
||||
assert clebsch_gordan(h, h, 1, 0, 1, 1) == -1/sqrt(2)
|
||||
assert clebsch_gordan(l, l, S(3), l, l, S(3)) == 1
|
||||
assert clebsch_gordan(l, l, S(2), l, k, S(2)) == 1/sqrt(2)
|
||||
assert clebsch_gordan(l, l, S(3), l, k, S(2)) == 1/sqrt(2)
|
||||
assert clebsch_gordan(S(2), S(2), S(4), S(2), S(2), S(4)) == 1
|
||||
assert clebsch_gordan(S(2), S(2), S(3), S(2), 1, S(3)) == 1/sqrt(2)
|
||||
assert clebsch_gordan(S(2), S(2), S(3), 1, 1, S(2)) == 0
|
||||
assert clebsch_gordan(p, h, n, p, 1, n) == 1
|
||||
assert clebsch_gordan(p, h, p, p, 0, p) == sqrt(5)/sqrt(7)
|
||||
assert clebsch_gordan(p, h, l, k, 1, l) == 1/sqrt(15)
|
||||
|
||||
|
||||
def test_clebsch_gordan_numpy():
|
||||
try:
|
||||
import numpy as np
|
||||
except ImportError:
|
||||
skip("numpy not installed")
|
||||
assert clebsch_gordan(*np.zeros(6).astype(np.int64)) == 1
|
||||
assert wigner_3j(2, np.float64(6.0), 4.0, 0, 0, 0) == sqrt(715)/143
|
||||
assert wigner_3j(0, 0.5, 0.5, 0, 0.5, -0.5) == sqrt(2)/2
|
||||
raises(ValueError, lambda: wigner_3j(2.1, 6, 4, 0, 0, 0))
|
||||
|
||||
|
||||
def test_wigner():
|
||||
try:
|
||||
import numpy as np
|
||||
except ImportError:
|
||||
skip("numpy not installed")
|
||||
def tn(a, b):
|
||||
return (a - b).n(64) < S('1e-64')
|
||||
assert tn(wigner_9j(1, 1, 1, 1, 1, 1, 1, 1, 0, prec=64), Rational(1, 18))
|
||||
assert wigner_9j(3, 3, 2, 3, 3, 2, 3, 3, 2) == 3221*sqrt(
|
||||
70)/(246960*sqrt(105)) - 365/(3528*sqrt(70)*sqrt(105))
|
||||
assert wigner_6j(5, 5, 5, 5, 5, 5) == Rational(1, 52)
|
||||
assert tn(wigner_6j(8, 8, 8, 8, 8, 8, prec=64), Rational(-12219, 965770))
|
||||
assert wigner_6j(1, 1, 1, 1.0, np.float64(1.0), 1) == Rational(1, 6)
|
||||
assert wigner_6j(3.0, np.float32(3), 3.0, 3, 3, 3) == Rational(-1, 14)
|
||||
# regression test for #8747
|
||||
half = S.Half
|
||||
assert wigner_9j(0, 0, 0, 0, half, half, 0, half, half) == half
|
||||
assert (wigner_9j(3, 5, 4,
|
||||
7 * half, 5 * half, 4,
|
||||
9 * half, 9 * half, 0)
|
||||
== -sqrt(Rational(361, 205821000)))
|
||||
assert (wigner_9j(1, 4, 3,
|
||||
5 * half, 4, 5 * half,
|
||||
5 * half, 2, 7 * half)
|
||||
== -sqrt(Rational(3971, 373403520)))
|
||||
assert (wigner_9j(4, 9 * half, 5 * half,
|
||||
2, 4, 4,
|
||||
5, 7 * half, 7 * half)
|
||||
== -sqrt(Rational(3481, 5042614500)))
|
||||
assert (wigner_9j(5, 5, 5.0,
|
||||
np.float64(5.0), 5, 5,
|
||||
5, 5, 5)
|
||||
== 0)
|
||||
assert (wigner_9j(1.0, 2.0, 3.0,
|
||||
3, 2, 1,
|
||||
2, 1, 3)
|
||||
== -4*sqrt(70)/11025)
|
||||
|
||||
|
||||
def test_gaunt():
|
||||
def tn(a, b):
|
||||
return (a - b).n(64) < S('1e-64')
|
||||
assert gaunt(1, 0, 1, 1, 0, -1) == -1/(2*sqrt(pi))
|
||||
assert isinstance(gaunt(1, 1, 0, -1, 1, 0).args[0], Rational)
|
||||
assert isinstance(gaunt(0, 1, 1, 0, -1, 1).args[0], Rational)
|
||||
|
||||
assert tn(gaunt(
|
||||
10, 10, 12, 9, 3, -12, prec=64), (Rational(-98, 62031)) * sqrt(6279)/sqrt(pi))
|
||||
def gaunt_ref(l1, l2, l3, m1, m2, m3):
|
||||
return (
|
||||
sqrt((2 * l1 + 1) * (2 * l2 + 1) * (2 * l3 + 1) / (4 * pi)) *
|
||||
wigner_3j(l1, l2, l3, 0, 0, 0) *
|
||||
wigner_3j(l1, l2, l3, m1, m2, m3)
|
||||
)
|
||||
threshold = 1e-10
|
||||
l_max = 3
|
||||
l3_max = 24
|
||||
for l1 in range(l_max + 1):
|
||||
for l2 in range(l_max + 1):
|
||||
for l3 in range(l3_max + 1):
|
||||
for m1 in range(-l1, l1 + 1):
|
||||
for m2 in range(-l2, l2 + 1):
|
||||
for m3 in range(-l3, l3 + 1):
|
||||
args = l1, l2, l3, m1, m2, m3
|
||||
g = gaunt(*args)
|
||||
g0 = gaunt_ref(*args)
|
||||
assert abs(g - g0) < threshold
|
||||
if m1 + m2 + m3 != 0:
|
||||
assert abs(g) < threshold
|
||||
if (l1 + l2 + l3) % 2:
|
||||
assert abs(g) < threshold
|
||||
assert gaunt(1, 1, 0, 0, 2, -2) is S.Zero
|
||||
|
||||
|
||||
def test_realgaunt():
|
||||
# All non-zero values corresponding to l values from 0 to 2
|
||||
for l in range(3):
|
||||
for m in range(-l, l+1):
|
||||
assert real_gaunt(0, l, l, 0, m, m) == 1/(2*sqrt(pi))
|
||||
assert real_gaunt(1, 1, 2, 0, 0, 0) == sqrt(5)/(5*sqrt(pi))
|
||||
assert real_gaunt(1, 1, 2, 1, 1, 0) == -sqrt(5)/(10*sqrt(pi))
|
||||
assert real_gaunt(2, 2, 2, 0, 0, 0) == sqrt(5)/(7*sqrt(pi))
|
||||
assert real_gaunt(2, 2, 2, 0, 2, 2) == -sqrt(5)/(7*sqrt(pi))
|
||||
assert real_gaunt(2, 2, 2, -2, -2, 0) == -sqrt(5)/(7*sqrt(pi))
|
||||
assert real_gaunt(1, 1, 2, -1, 0, -1) == sqrt(15)/(10*sqrt(pi))
|
||||
assert real_gaunt(1, 1, 2, 0, 1, 1) == sqrt(15)/(10*sqrt(pi))
|
||||
assert real_gaunt(1, 1, 2, 1, 1, 2) == sqrt(15)/(10*sqrt(pi))
|
||||
assert real_gaunt(1, 1, 2, -1, 1, -2) == sqrt(15)/(10*sqrt(pi))
|
||||
assert real_gaunt(1, 1, 2, -1, -1, 2) == -sqrt(15)/(10*sqrt(pi))
|
||||
assert real_gaunt(2, 2, 2, 0, 1, 1) == sqrt(5)/(14*sqrt(pi))
|
||||
assert real_gaunt(2, 2, 2, 1, 1, 2) == sqrt(15)/(14*sqrt(pi))
|
||||
assert real_gaunt(2, 2, 2, -1, -1, 2) == -sqrt(15)/(14*sqrt(pi))
|
||||
|
||||
assert real_gaunt(-2, -2, -2, -2, -2, 0) is S.Zero # m test
|
||||
assert real_gaunt(-2, 1, 0, 1, 1, 1) is S.Zero # l test
|
||||
assert real_gaunt(-2, -1, -2, -1, -1, 0) is S.Zero # m and l test
|
||||
assert real_gaunt(-2, -2, -2, -2, -2, -2) is S.Zero # m and k test
|
||||
assert real_gaunt(-2, -1, -2, -1, -1, -1) is S.Zero # m, l and k test
|
||||
|
||||
x = symbols('x', integer=True)
|
||||
v = [0]*6
|
||||
for i in range(len(v)):
|
||||
v[i] = x # non literal ints fail
|
||||
raises(ValueError, lambda: real_gaunt(*v))
|
||||
v[i] = 0
|
||||
|
||||
|
||||
def test_racah():
|
||||
assert racah(3,3,3,3,3,3) == Rational(-1,14)
|
||||
assert racah(2,2,2,2,2,2) == Rational(-3,70)
|
||||
assert racah(7,8,7,1,7,7, prec=4).is_Float
|
||||
assert racah(5.5,7.5,9.5,6.5,8,9) == -719*sqrt(598)/1158924
|
||||
assert abs(racah(5.5,7.5,9.5,6.5,8,9, prec=4) - (-0.01517)) < S('1e-4')
|
||||
|
||||
|
||||
def test_dot_rota_grad_SH():
|
||||
theta, phi = symbols("theta phi")
|
||||
assert dot_rot_grad_Ynm(1, 1, 1, 1, 1, 0) != \
|
||||
sqrt(30)*Ynm(2, 2, 1, 0)/(10*sqrt(pi))
|
||||
assert dot_rot_grad_Ynm(1, 1, 1, 1, 1, 0).doit() == \
|
||||
sqrt(30)*Ynm(2, 2, 1, 0)/(10*sqrt(pi))
|
||||
assert dot_rot_grad_Ynm(1, 5, 1, 1, 1, 2) != \
|
||||
0
|
||||
assert dot_rot_grad_Ynm(1, 5, 1, 1, 1, 2).doit() == \
|
||||
0
|
||||
assert dot_rot_grad_Ynm(3, 3, 3, 3, theta, phi).doit() == \
|
||||
15*sqrt(3003)*Ynm(6, 6, theta, phi)/(143*sqrt(pi))
|
||||
assert dot_rot_grad_Ynm(3, 3, 1, 1, theta, phi).doit() == \
|
||||
sqrt(3)*Ynm(4, 4, theta, phi)/sqrt(pi)
|
||||
assert dot_rot_grad_Ynm(3, 2, 2, 0, theta, phi).doit() == \
|
||||
3*sqrt(55)*Ynm(5, 2, theta, phi)/(11*sqrt(pi))
|
||||
assert dot_rot_grad_Ynm(3, 2, 3, 2, theta, phi).doit().expand() == \
|
||||
-sqrt(70)*Ynm(4, 4, theta, phi)/(11*sqrt(pi)) + \
|
||||
45*sqrt(182)*Ynm(6, 4, theta, phi)/(143*sqrt(pi))
|
||||
|
||||
|
||||
def test_wigner_d():
|
||||
half = S(1)/2
|
||||
assert wigner_d_small(half, 0) == Matrix([[1, 0], [0, 1]])
|
||||
assert wigner_d_small(half, pi/2) == Matrix([[1, 1], [-1, 1]])/sqrt(2)
|
||||
assert wigner_d_small(half, pi) == Matrix([[0, 1], [-1, 0]])
|
||||
|
||||
alpha, beta, gamma = symbols("alpha, beta, gamma", real=True)
|
||||
D = wigner_d(half, alpha, beta, gamma)
|
||||
assert D[0, 0] == exp(I*alpha/2)*exp(I*gamma/2)*cos(beta/2)
|
||||
assert D[0, 1] == exp(I*alpha/2)*exp(-I*gamma/2)*sin(beta/2)
|
||||
assert D[1, 0] == -exp(-I*alpha/2)*exp(I*gamma/2)*sin(beta/2)
|
||||
assert D[1, 1] == exp(-I*alpha/2)*exp(-I*gamma/2)*cos(beta/2)
|
||||
|
||||
# Test Y_{n mi}(g*x)=\sum_{mj}D^n_{mi mj}*Y_{n mj}(x)
|
||||
theta, phi = symbols("theta phi", real=True)
|
||||
v = Matrix([Ynm(1, mj, theta, phi) for mj in range(1, -2, -1)])
|
||||
w = wigner_d(1, -pi/2, pi/2, -pi/2)@v.subs({theta: pi/4, phi: pi})
|
||||
w_ = v.subs({theta: pi/2, phi: pi/4})
|
||||
assert w.expand(func=True).as_real_imag() == w_.expand(func=True).as_real_imag()
|
||||
@@ -0,0 +1,126 @@
|
||||
from sympy.core.numbers import (I, Rational, oo, pi)
|
||||
from sympy.core.singleton import S
|
||||
from sympy.core.symbol import symbols
|
||||
from sympy.functions.elementary.exponential import exp
|
||||
from sympy.functions.elementary.miscellaneous import sqrt
|
||||
from sympy.functions.elementary.trigonometric import (cos, sin)
|
||||
from sympy.integrals.integrals import integrate
|
||||
from sympy.simplify.simplify import simplify
|
||||
from sympy.physics.hydrogen import R_nl, E_nl, E_nl_dirac, Psi_nlm
|
||||
from sympy.testing.pytest import raises
|
||||
|
||||
n, r, Z = symbols('n r Z')
|
||||
|
||||
|
||||
def feq(a, b, max_relative_error=1e-12, max_absolute_error=1e-12):
|
||||
a = float(a)
|
||||
b = float(b)
|
||||
# if the numbers are close enough (absolutely), then they are equal
|
||||
if abs(a - b) < max_absolute_error:
|
||||
return True
|
||||
# if not, they can still be equal if their relative error is small
|
||||
if abs(b) > abs(a):
|
||||
relative_error = abs((a - b)/b)
|
||||
else:
|
||||
relative_error = abs((a - b)/a)
|
||||
return relative_error <= max_relative_error
|
||||
|
||||
|
||||
def test_wavefunction():
|
||||
a = 1/Z
|
||||
R = {
|
||||
(1, 0): 2*sqrt(1/a**3) * exp(-r/a),
|
||||
(2, 0): sqrt(1/(2*a**3)) * exp(-r/(2*a)) * (1 - r/(2*a)),
|
||||
(2, 1): S.Half * sqrt(1/(6*a**3)) * exp(-r/(2*a)) * r/a,
|
||||
(3, 0): Rational(2, 3) * sqrt(1/(3*a**3)) * exp(-r/(3*a)) *
|
||||
(1 - 2*r/(3*a) + Rational(2, 27) * (r/a)**2),
|
||||
(3, 1): Rational(4, 27) * sqrt(2/(3*a**3)) * exp(-r/(3*a)) *
|
||||
(1 - r/(6*a)) * r/a,
|
||||
(3, 2): Rational(2, 81) * sqrt(2/(15*a**3)) * exp(-r/(3*a)) * (r/a)**2,
|
||||
(4, 0): Rational(1, 4) * sqrt(1/a**3) * exp(-r/(4*a)) *
|
||||
(1 - 3*r/(4*a) + Rational(1, 8) * (r/a)**2 - Rational(1, 192) * (r/a)**3),
|
||||
(4, 1): Rational(1, 16) * sqrt(5/(3*a**3)) * exp(-r/(4*a)) *
|
||||
(1 - r/(4*a) + Rational(1, 80) * (r/a)**2) * (r/a),
|
||||
(4, 2): Rational(1, 64) * sqrt(1/(5*a**3)) * exp(-r/(4*a)) *
|
||||
(1 - r/(12*a)) * (r/a)**2,
|
||||
(4, 3): Rational(1, 768) * sqrt(1/(35*a**3)) * exp(-r/(4*a)) * (r/a)**3,
|
||||
}
|
||||
for n, l in R:
|
||||
assert simplify(R_nl(n, l, r, Z) - R[(n, l)]) == 0
|
||||
|
||||
|
||||
def test_norm():
|
||||
# Maximum "n" which is tested:
|
||||
n_max = 2 # it works, but is slow, for n_max > 2
|
||||
for n in range(n_max + 1):
|
||||
for l in range(n):
|
||||
assert integrate(R_nl(n, l, r)**2 * r**2, (r, 0, oo)) == 1
|
||||
|
||||
def test_psi_nlm():
|
||||
r=S('r')
|
||||
phi=S('phi')
|
||||
theta=S('theta')
|
||||
assert (Psi_nlm(1, 0, 0, r, phi, theta) == exp(-r) / sqrt(pi))
|
||||
assert (Psi_nlm(2, 1, -1, r, phi, theta)) == S.Half * exp(-r / (2)) * r \
|
||||
* (sin(theta) * exp(-I * phi) / (4 * sqrt(pi)))
|
||||
assert (Psi_nlm(3, 2, 1, r, phi, theta, 2) == -sqrt(2) * sin(theta) \
|
||||
* exp(I * phi) * cos(theta) / (4 * sqrt(pi)) * S(2) / 81 \
|
||||
* sqrt(2 * 2 ** 3) * exp(-2 * r / (3)) * (r * 2) ** 2)
|
||||
|
||||
def test_hydrogen_energies():
|
||||
assert E_nl(n, Z) == -Z**2/(2*n**2)
|
||||
assert E_nl(n) == -1/(2*n**2)
|
||||
|
||||
assert E_nl(1, 47) == -S(47)**2/(2*1**2)
|
||||
assert E_nl(2, 47) == -S(47)**2/(2*2**2)
|
||||
|
||||
assert E_nl(1) == -S.One/(2*1**2)
|
||||
assert E_nl(2) == -S.One/(2*2**2)
|
||||
assert E_nl(3) == -S.One/(2*3**2)
|
||||
assert E_nl(4) == -S.One/(2*4**2)
|
||||
assert E_nl(100) == -S.One/(2*100**2)
|
||||
|
||||
raises(ValueError, lambda: E_nl(0))
|
||||
|
||||
|
||||
def test_hydrogen_energies_relat():
|
||||
# First test exact formulas for small "c" so that we get nice expressions:
|
||||
assert E_nl_dirac(2, 0, Z=1, c=1) == 1/sqrt(2) - 1
|
||||
assert simplify(E_nl_dirac(2, 0, Z=1, c=2) - ( (8*sqrt(3) + 16)
|
||||
/ sqrt(16*sqrt(3) + 32) - 4)) == 0
|
||||
assert simplify(E_nl_dirac(2, 0, Z=1, c=3) - ( (54*sqrt(2) + 81)
|
||||
/ sqrt(108*sqrt(2) + 162) - 9)) == 0
|
||||
|
||||
# Now test for almost the correct speed of light, without floating point
|
||||
# numbers:
|
||||
assert simplify(E_nl_dirac(2, 0, Z=1, c=137) - ( (352275361 + 10285412 *
|
||||
sqrt(1173)) / sqrt(704550722 + 20570824 * sqrt(1173)) - 18769)) == 0
|
||||
assert simplify(E_nl_dirac(2, 0, Z=82, c=137) - ( (352275361 + 2571353 *
|
||||
sqrt(12045)) / sqrt(704550722 + 5142706*sqrt(12045)) - 18769)) == 0
|
||||
|
||||
# Test using exact speed of light, and compare against the nonrelativistic
|
||||
# energies:
|
||||
for n in range(1, 5):
|
||||
for l in range(n):
|
||||
assert feq(E_nl_dirac(n, l), E_nl(n), 1e-5, 1e-5)
|
||||
if l > 0:
|
||||
assert feq(E_nl_dirac(n, l, False), E_nl(n), 1e-5, 1e-5)
|
||||
|
||||
Z = 2
|
||||
for n in range(1, 5):
|
||||
for l in range(n):
|
||||
assert feq(E_nl_dirac(n, l, Z=Z), E_nl(n, Z), 1e-4, 1e-4)
|
||||
if l > 0:
|
||||
assert feq(E_nl_dirac(n, l, False, Z), E_nl(n, Z), 1e-4, 1e-4)
|
||||
|
||||
Z = 3
|
||||
for n in range(1, 5):
|
||||
for l in range(n):
|
||||
assert feq(E_nl_dirac(n, l, Z=Z), E_nl(n, Z), 1e-3, 1e-3)
|
||||
if l > 0:
|
||||
assert feq(E_nl_dirac(n, l, False, Z), E_nl(n, Z), 1e-3, 1e-3)
|
||||
|
||||
# Test the exceptions:
|
||||
raises(ValueError, lambda: E_nl_dirac(0, 0))
|
||||
raises(ValueError, lambda: E_nl_dirac(1, -1))
|
||||
raises(ValueError, lambda: E_nl_dirac(1, 0, False))
|
||||
@@ -0,0 +1,57 @@
|
||||
from sympy.core.numbers import I
|
||||
from sympy.core.symbol import symbols
|
||||
from sympy.physics.paulialgebra import Pauli
|
||||
from sympy.testing.pytest import XFAIL
|
||||
from sympy.physics.quantum import TensorProduct
|
||||
|
||||
sigma1 = Pauli(1)
|
||||
sigma2 = Pauli(2)
|
||||
sigma3 = Pauli(3)
|
||||
|
||||
tau1 = symbols("tau1", commutative = False)
|
||||
|
||||
|
||||
def test_Pauli():
|
||||
|
||||
assert sigma1 == sigma1
|
||||
assert sigma1 != sigma2
|
||||
|
||||
assert sigma1*sigma2 == I*sigma3
|
||||
assert sigma3*sigma1 == I*sigma2
|
||||
assert sigma2*sigma3 == I*sigma1
|
||||
|
||||
assert sigma1*sigma1 == 1
|
||||
assert sigma2*sigma2 == 1
|
||||
assert sigma3*sigma3 == 1
|
||||
|
||||
assert sigma1**0 == 1
|
||||
assert sigma1**1 == sigma1
|
||||
assert sigma1**2 == 1
|
||||
assert sigma1**3 == sigma1
|
||||
assert sigma1**4 == 1
|
||||
|
||||
assert sigma3**2 == 1
|
||||
|
||||
assert sigma1*2*sigma1 == 2
|
||||
|
||||
|
||||
def test_evaluate_pauli_product():
|
||||
from sympy.physics.paulialgebra import evaluate_pauli_product
|
||||
|
||||
assert evaluate_pauli_product(I*sigma2*sigma3) == -sigma1
|
||||
|
||||
# Check issue 6471
|
||||
assert evaluate_pauli_product(-I*4*sigma1*sigma2) == 4*sigma3
|
||||
|
||||
assert evaluate_pauli_product(
|
||||
1 + I*sigma1*sigma2*sigma1*sigma2 + \
|
||||
I*sigma1*sigma2*tau1*sigma1*sigma3 + \
|
||||
((tau1**2).subs(tau1, I*sigma1)) + \
|
||||
sigma3*((tau1**2).subs(tau1, I*sigma1)) + \
|
||||
TensorProduct(I*sigma1*sigma2*sigma1*sigma2, 1)
|
||||
) == 1 -I + I*sigma3*tau1*sigma2 - 1 - sigma3 - I*TensorProduct(1,1)
|
||||
|
||||
|
||||
@XFAIL
|
||||
def test_Pauli_should_work():
|
||||
assert sigma1*sigma3*sigma1 == -sigma3
|
||||
@@ -0,0 +1,84 @@
|
||||
from sympy.physics.matrices import msigma, mgamma, minkowski_tensor, pat_matrix, mdft
|
||||
from sympy.core.numbers import (I, Rational)
|
||||
from sympy.core.singleton import S
|
||||
from sympy.functions.elementary.miscellaneous import sqrt
|
||||
from sympy.matrices.dense import (Matrix, eye, zeros)
|
||||
from sympy.testing.pytest import warns_deprecated_sympy
|
||||
|
||||
|
||||
def test_parallel_axis_theorem():
|
||||
# This tests the parallel axis theorem matrix by comparing to test
|
||||
# matrices.
|
||||
|
||||
# First case, 1 in all directions.
|
||||
mat1 = Matrix(((2, -1, -1), (-1, 2, -1), (-1, -1, 2)))
|
||||
assert pat_matrix(1, 1, 1, 1) == mat1
|
||||
assert pat_matrix(2, 1, 1, 1) == 2*mat1
|
||||
|
||||
# Second case, 1 in x, 0 in all others
|
||||
mat2 = Matrix(((0, 0, 0), (0, 1, 0), (0, 0, 1)))
|
||||
assert pat_matrix(1, 1, 0, 0) == mat2
|
||||
assert pat_matrix(2, 1, 0, 0) == 2*mat2
|
||||
|
||||
# Third case, 1 in y, 0 in all others
|
||||
mat3 = Matrix(((1, 0, 0), (0, 0, 0), (0, 0, 1)))
|
||||
assert pat_matrix(1, 0, 1, 0) == mat3
|
||||
assert pat_matrix(2, 0, 1, 0) == 2*mat3
|
||||
|
||||
# Fourth case, 1 in z, 0 in all others
|
||||
mat4 = Matrix(((1, 0, 0), (0, 1, 0), (0, 0, 0)))
|
||||
assert pat_matrix(1, 0, 0, 1) == mat4
|
||||
assert pat_matrix(2, 0, 0, 1) == 2*mat4
|
||||
|
||||
|
||||
def test_Pauli():
|
||||
#this and the following test are testing both Pauli and Dirac matrices
|
||||
#and also that the general Matrix class works correctly in a real world
|
||||
#situation
|
||||
sigma1 = msigma(1)
|
||||
sigma2 = msigma(2)
|
||||
sigma3 = msigma(3)
|
||||
|
||||
assert sigma1 == sigma1
|
||||
assert sigma1 != sigma2
|
||||
|
||||
# sigma*I -> I*sigma (see #354)
|
||||
assert sigma1*sigma2 == sigma3*I
|
||||
assert sigma3*sigma1 == sigma2*I
|
||||
assert sigma2*sigma3 == sigma1*I
|
||||
|
||||
assert sigma1*sigma1 == eye(2)
|
||||
assert sigma2*sigma2 == eye(2)
|
||||
assert sigma3*sigma3 == eye(2)
|
||||
|
||||
assert sigma1*2*sigma1 == 2*eye(2)
|
||||
assert sigma1*sigma3*sigma1 == -sigma3
|
||||
|
||||
|
||||
def test_Dirac():
|
||||
gamma0 = mgamma(0)
|
||||
gamma1 = mgamma(1)
|
||||
gamma2 = mgamma(2)
|
||||
gamma3 = mgamma(3)
|
||||
gamma5 = mgamma(5)
|
||||
|
||||
# gamma*I -> I*gamma (see #354)
|
||||
assert gamma5 == gamma0 * gamma1 * gamma2 * gamma3 * I
|
||||
assert gamma1 * gamma2 + gamma2 * gamma1 == zeros(4)
|
||||
assert gamma0 * gamma0 == eye(4) * minkowski_tensor[0, 0]
|
||||
assert gamma2 * gamma2 != eye(4) * minkowski_tensor[0, 0]
|
||||
assert gamma2 * gamma2 == eye(4) * minkowski_tensor[2, 2]
|
||||
|
||||
assert mgamma(5, True) == \
|
||||
mgamma(0, True)*mgamma(1, True)*mgamma(2, True)*mgamma(3, True)*I
|
||||
|
||||
def test_mdft():
|
||||
with warns_deprecated_sympy():
|
||||
assert mdft(1) == Matrix([[1]])
|
||||
with warns_deprecated_sympy():
|
||||
assert mdft(2) == 1/sqrt(2)*Matrix([[1,1],[1,-1]])
|
||||
with warns_deprecated_sympy():
|
||||
assert mdft(4) == Matrix([[S.Half, S.Half, S.Half, S.Half],
|
||||
[S.Half, -I/2, Rational(-1,2), I/2],
|
||||
[S.Half, Rational(-1,2), S.Half, Rational(-1,2)],
|
||||
[S.Half, I/2, Rational(-1,2), -I/2]])
|
||||
@@ -0,0 +1,41 @@
|
||||
from sympy.physics.pring import wavefunction, energy
|
||||
from sympy.core.numbers import (I, pi)
|
||||
from sympy.functions.elementary.exponential import exp
|
||||
from sympy.functions.elementary.miscellaneous import sqrt
|
||||
from sympy.integrals.integrals import integrate
|
||||
from sympy.simplify.simplify import simplify
|
||||
from sympy.abc import m, x, r
|
||||
from sympy.physics.quantum.constants import hbar
|
||||
|
||||
|
||||
def test_wavefunction():
|
||||
Psi = {
|
||||
0: (1/sqrt(2 * pi)),
|
||||
1: (1/sqrt(2 * pi)) * exp(I * x),
|
||||
2: (1/sqrt(2 * pi)) * exp(2 * I * x),
|
||||
3: (1/sqrt(2 * pi)) * exp(3 * I * x)
|
||||
}
|
||||
for n in Psi:
|
||||
assert simplify(wavefunction(n, x) - Psi[n]) == 0
|
||||
|
||||
|
||||
def test_norm(n=1):
|
||||
# Maximum "n" which is tested:
|
||||
for i in range(n + 1):
|
||||
assert integrate(
|
||||
wavefunction(i, x) * wavefunction(-i, x), (x, 0, 2 * pi)) == 1
|
||||
|
||||
|
||||
def test_orthogonality(n=1):
|
||||
# Maximum "n" which is tested:
|
||||
for i in range(n + 1):
|
||||
for j in range(i+1, n+1):
|
||||
assert integrate(
|
||||
wavefunction(i, x) * wavefunction(j, x), (x, 0, 2 * pi)) == 0
|
||||
|
||||
|
||||
def test_energy(n=1):
|
||||
# Maximum "n" which is tested:
|
||||
for i in range(n+1):
|
||||
assert simplify(
|
||||
energy(i, m, r) - ((i**2 * hbar**2) / (2 * m * r**2))) == 0
|
||||
@@ -0,0 +1,50 @@
|
||||
from sympy.core.numbers import (Rational, oo, pi)
|
||||
from sympy.core.singleton import S
|
||||
from sympy.core.symbol import Symbol
|
||||
from sympy.functions.elementary.exponential import exp
|
||||
from sympy.functions.elementary.miscellaneous import sqrt
|
||||
from sympy.integrals.integrals import integrate
|
||||
from sympy.simplify.simplify import simplify
|
||||
from sympy.abc import omega, m, x
|
||||
from sympy.physics.qho_1d import psi_n, E_n, coherent_state
|
||||
from sympy.physics.quantum.constants import hbar
|
||||
|
||||
nu = m * omega / hbar
|
||||
|
||||
|
||||
def test_wavefunction():
|
||||
Psi = {
|
||||
0: (nu/pi)**Rational(1, 4) * exp(-nu * x**2 /2),
|
||||
1: (nu/pi)**Rational(1, 4) * sqrt(2*nu) * x * exp(-nu * x**2 /2),
|
||||
2: (nu/pi)**Rational(1, 4) * (2 * nu * x**2 - 1)/sqrt(2) * exp(-nu * x**2 /2),
|
||||
3: (nu/pi)**Rational(1, 4) * sqrt(nu/3) * (2 * nu * x**3 - 3 * x) * exp(-nu * x**2 /2)
|
||||
}
|
||||
for n in Psi:
|
||||
assert simplify(psi_n(n, x, m, omega) - Psi[n]) == 0
|
||||
|
||||
|
||||
def test_norm(n=1):
|
||||
# Maximum "n" which is tested:
|
||||
for i in range(n + 1):
|
||||
assert integrate(psi_n(i, x, 1, 1)**2, (x, -oo, oo)) == 1
|
||||
|
||||
|
||||
def test_orthogonality(n=1):
|
||||
# Maximum "n" which is tested:
|
||||
for i in range(n + 1):
|
||||
for j in range(i + 1, n + 1):
|
||||
assert integrate(
|
||||
psi_n(i, x, 1, 1)*psi_n(j, x, 1, 1), (x, -oo, oo)) == 0
|
||||
|
||||
|
||||
def test_energies(n=1):
|
||||
# Maximum "n" which is tested:
|
||||
for i in range(n + 1):
|
||||
assert E_n(i, omega) == hbar * omega * (i + S.Half)
|
||||
|
||||
def test_coherent_state(n=10):
|
||||
# Maximum "n" which is tested:
|
||||
# test whether coherent state is the eigenstate of annihilation operator
|
||||
alpha = Symbol("alpha")
|
||||
for i in range(n + 1):
|
||||
assert simplify(sqrt(n + 1) * coherent_state(n + 1, alpha)) == simplify(alpha * coherent_state(n, alpha))
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,21 @@
|
||||
from sympy.core import symbols, Rational, Function, diff
|
||||
from sympy.physics.sho import R_nl, E_nl
|
||||
from sympy.simplify.simplify import simplify
|
||||
|
||||
|
||||
def test_sho_R_nl():
|
||||
omega, r = symbols('omega r')
|
||||
l = symbols('l', integer=True)
|
||||
u = Function('u')
|
||||
|
||||
# check that it obeys the Schrodinger equation
|
||||
for n in range(5):
|
||||
schreq = ( -diff(u(r), r, 2)/2 + ((l*(l + 1))/(2*r**2)
|
||||
+ omega**2*r**2/2 - E_nl(n, l, omega))*u(r) )
|
||||
result = schreq.subs(u(r), r*R_nl(n, l, omega/2, r))
|
||||
assert simplify(result.doit()) == 0
|
||||
|
||||
|
||||
def test_energy():
|
||||
n, l, hw = symbols('n l hw')
|
||||
assert simplify(E_nl(n, l, hw) - (2*n + l + Rational(3, 2))*hw) == 0
|
||||
Reference in New Issue
Block a user