wigner.py 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159
  1. # -*- coding: utf-8 -*-
  2. r"""
  3. Wigner, Clebsch-Gordan, Racah, and Gaunt coefficients
  4. Collection of functions for calculating Wigner 3j, 6j, 9j,
  5. Clebsch-Gordan, Racah as well as Gaunt coefficients exactly, all
  6. evaluating to a rational number times the square root of a rational
  7. number [Rasch03]_.
  8. Please see the description of the individual functions for further
  9. details and examples.
  10. References
  11. ==========
  12. .. [Regge58] 'Symmetry Properties of Clebsch-Gordan Coefficients',
  13. T. Regge, Nuovo Cimento, Volume 10, pp. 544 (1958)
  14. .. [Regge59] 'Symmetry Properties of Racah Coefficients',
  15. T. Regge, Nuovo Cimento, Volume 11, pp. 116 (1959)
  16. .. [Edmonds74] A. R. Edmonds. Angular momentum in quantum mechanics.
  17. Investigations in physics, 4.; Investigations in physics, no. 4.
  18. Princeton, N.J., Princeton University Press, 1957.
  19. .. [Rasch03] J. Rasch and A. C. H. Yu, 'Efficient Storage Scheme for
  20. Pre-calculated Wigner 3j, 6j and Gaunt Coefficients', SIAM
  21. J. Sci. Comput. Volume 25, Issue 4, pp. 1416-1428 (2003)
  22. .. [Liberatodebrito82] 'FORTRAN program for the integral of three
  23. spherical harmonics', A. Liberato de Brito,
  24. Comput. Phys. Commun., Volume 25, pp. 81-85 (1982)
  25. .. [Homeier96] 'Some Properties of the Coupling Coefficients of Real
  26. Spherical Harmonics and Their Relation to Gaunt Coefficients',
  27. H. H. H. Homeier and E. O. Steinborn J. Mol. Struct., Volume 368,
  28. pp. 31-37 (1996)
  29. Credits and Copyright
  30. =====================
  31. This code was taken from Sage with the permission of all authors:
  32. https://groups.google.com/forum/#!topic/sage-devel/M4NZdu-7O38
  33. Authors
  34. =======
  35. - Jens Rasch (2009-03-24): initial version for Sage
  36. - Jens Rasch (2009-05-31): updated to sage-4.0
  37. - Oscar Gerardo Lazo Arjona (2017-06-18): added Wigner D matrices
  38. - Phil Adam LeMaitre (2022-09-19): added real Gaunt coefficient
  39. Copyright (C) 2008 Jens Rasch <jyr2000@gmail.com>
  40. """
  41. from sympy.concrete.summations import Sum
  42. from sympy.core.add import Add
  43. from sympy.core.function import Function
  44. from sympy.core.numbers import (I, Integer, pi)
  45. from sympy.core.singleton import S
  46. from sympy.core.symbol import Dummy
  47. from sympy.core.sympify import sympify
  48. from sympy.functions.combinatorial.factorials import (binomial, factorial)
  49. from sympy.functions.elementary.complexes import re
  50. from sympy.functions.elementary.exponential import exp
  51. from sympy.functions.elementary.miscellaneous import sqrt
  52. from sympy.functions.elementary.trigonometric import (cos, sin)
  53. from sympy.functions.special.spherical_harmonics import Ynm
  54. from sympy.matrices.dense import zeros
  55. from sympy.matrices.immutable import ImmutableMatrix
  56. from sympy.utilities.misc import as_int
  57. # This list of precomputed factorials is needed to massively
  58. # accelerate future calculations of the various coefficients
  59. _Factlist = [1]
  60. def _calc_factlist(nn):
  61. r"""
  62. Function calculates a list of precomputed factorials in order to
  63. massively accelerate future calculations of the various
  64. coefficients.
  65. Parameters
  66. ==========
  67. nn : integer
  68. Highest factorial to be computed.
  69. Returns
  70. =======
  71. list of integers :
  72. The list of precomputed factorials.
  73. Examples
  74. ========
  75. Calculate list of factorials::
  76. sage: from sage.functions.wigner import _calc_factlist
  77. sage: _calc_factlist(10)
  78. [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800]
  79. """
  80. if nn >= len(_Factlist):
  81. for ii in range(len(_Factlist), int(nn + 1)):
  82. _Factlist.append(_Factlist[ii - 1] * ii)
  83. return _Factlist[:int(nn) + 1]
  84. def wigner_3j(j_1, j_2, j_3, m_1, m_2, m_3):
  85. r"""
  86. Calculate the Wigner 3j symbol `\operatorname{Wigner3j}(j_1,j_2,j_3,m_1,m_2,m_3)`.
  87. Parameters
  88. ==========
  89. j_1, j_2, j_3, m_1, m_2, m_3 :
  90. Integer or half integer.
  91. Returns
  92. =======
  93. Rational number times the square root of a rational number.
  94. Examples
  95. ========
  96. >>> from sympy.physics.wigner import wigner_3j
  97. >>> wigner_3j(2, 6, 4, 0, 0, 0)
  98. sqrt(715)/143
  99. >>> wigner_3j(2, 6, 4, 0, 0, 1)
  100. 0
  101. It is an error to have arguments that are not integer or half
  102. integer values::
  103. sage: wigner_3j(2.1, 6, 4, 0, 0, 0)
  104. Traceback (most recent call last):
  105. ...
  106. ValueError: j values must be integer or half integer
  107. sage: wigner_3j(2, 6, 4, 1, 0, -1.1)
  108. Traceback (most recent call last):
  109. ...
  110. ValueError: m values must be integer or half integer
  111. Notes
  112. =====
  113. The Wigner 3j symbol obeys the following symmetry rules:
  114. - invariant under any permutation of the columns (with the
  115. exception of a sign change where `J:=j_1+j_2+j_3`):
  116. .. math::
  117. \begin{aligned}
  118. \operatorname{Wigner3j}(j_1,j_2,j_3,m_1,m_2,m_3)
  119. &=\operatorname{Wigner3j}(j_3,j_1,j_2,m_3,m_1,m_2) \\
  120. &=\operatorname{Wigner3j}(j_2,j_3,j_1,m_2,m_3,m_1) \\
  121. &=(-1)^J \operatorname{Wigner3j}(j_3,j_2,j_1,m_3,m_2,m_1) \\
  122. &=(-1)^J \operatorname{Wigner3j}(j_1,j_3,j_2,m_1,m_3,m_2) \\
  123. &=(-1)^J \operatorname{Wigner3j}(j_2,j_1,j_3,m_2,m_1,m_3)
  124. \end{aligned}
  125. - invariant under space inflection, i.e.
  126. .. math::
  127. \operatorname{Wigner3j}(j_1,j_2,j_3,m_1,m_2,m_3)
  128. =(-1)^J \operatorname{Wigner3j}(j_1,j_2,j_3,-m_1,-m_2,-m_3)
  129. - symmetric with respect to the 72 additional symmetries based on
  130. the work by [Regge58]_
  131. - zero for `j_1`, `j_2`, `j_3` not fulfilling triangle relation
  132. - zero for `m_1 + m_2 + m_3 \neq 0`
  133. - zero for violating any one of the conditions
  134. `j_1 \ge |m_1|`, `j_2 \ge |m_2|`, `j_3 \ge |m_3|`
  135. Algorithm
  136. =========
  137. This function uses the algorithm of [Edmonds74]_ to calculate the
  138. value of the 3j symbol exactly. Note that the formula contains
  139. alternating sums over large factorials and is therefore unsuitable
  140. for finite precision arithmetic and only useful for a computer
  141. algebra system [Rasch03]_.
  142. Authors
  143. =======
  144. - Jens Rasch (2009-03-24): initial version
  145. """
  146. if int(j_1 * 2) != j_1 * 2 or int(j_2 * 2) != j_2 * 2 or \
  147. int(j_3 * 2) != j_3 * 2:
  148. raise ValueError("j values must be integer or half integer")
  149. if int(m_1 * 2) != m_1 * 2 or int(m_2 * 2) != m_2 * 2 or \
  150. int(m_3 * 2) != m_3 * 2:
  151. raise ValueError("m values must be integer or half integer")
  152. if m_1 + m_2 + m_3 != 0:
  153. return S.Zero
  154. prefid = Integer((-1) ** int(j_1 - j_2 - m_3))
  155. m_3 = -m_3
  156. a1 = j_1 + j_2 - j_3
  157. if a1 < 0:
  158. return S.Zero
  159. a2 = j_1 - j_2 + j_3
  160. if a2 < 0:
  161. return S.Zero
  162. a3 = -j_1 + j_2 + j_3
  163. if a3 < 0:
  164. return S.Zero
  165. if (abs(m_1) > j_1) or (abs(m_2) > j_2) or (abs(m_3) > j_3):
  166. return S.Zero
  167. maxfact = max(j_1 + j_2 + j_3 + 1, j_1 + abs(m_1), j_2 + abs(m_2),
  168. j_3 + abs(m_3))
  169. _calc_factlist(int(maxfact))
  170. argsqrt = Integer(_Factlist[int(j_1 + j_2 - j_3)] *
  171. _Factlist[int(j_1 - j_2 + j_3)] *
  172. _Factlist[int(-j_1 + j_2 + j_3)] *
  173. _Factlist[int(j_1 - m_1)] *
  174. _Factlist[int(j_1 + m_1)] *
  175. _Factlist[int(j_2 - m_2)] *
  176. _Factlist[int(j_2 + m_2)] *
  177. _Factlist[int(j_3 - m_3)] *
  178. _Factlist[int(j_3 + m_3)]) / \
  179. _Factlist[int(j_1 + j_2 + j_3 + 1)]
  180. ressqrt = sqrt(argsqrt)
  181. if ressqrt.is_complex or ressqrt.is_infinite:
  182. ressqrt = ressqrt.as_real_imag()[0]
  183. imin = max(-j_3 + j_1 + m_2, -j_3 + j_2 - m_1, 0)
  184. imax = min(j_2 + m_2, j_1 - m_1, j_1 + j_2 - j_3)
  185. sumres = 0
  186. for ii in range(int(imin), int(imax) + 1):
  187. den = _Factlist[ii] * \
  188. _Factlist[int(ii + j_3 - j_1 - m_2)] * \
  189. _Factlist[int(j_2 + m_2 - ii)] * \
  190. _Factlist[int(j_1 - ii - m_1)] * \
  191. _Factlist[int(ii + j_3 - j_2 + m_1)] * \
  192. _Factlist[int(j_1 + j_2 - j_3 - ii)]
  193. sumres = sumres + Integer((-1) ** ii) / den
  194. res = ressqrt * sumres * prefid
  195. return res
  196. def clebsch_gordan(j_1, j_2, j_3, m_1, m_2, m_3):
  197. r"""
  198. Calculates the Clebsch-Gordan coefficient.
  199. `\left\langle j_1 m_1 \; j_2 m_2 | j_3 m_3 \right\rangle`.
  200. The reference for this function is [Edmonds74]_.
  201. Parameters
  202. ==========
  203. j_1, j_2, j_3, m_1, m_2, m_3 :
  204. Integer or half integer.
  205. Returns
  206. =======
  207. Rational number times the square root of a rational number.
  208. Examples
  209. ========
  210. >>> from sympy import S
  211. >>> from sympy.physics.wigner import clebsch_gordan
  212. >>> clebsch_gordan(S(3)/2, S(1)/2, 2, S(3)/2, S(1)/2, 2)
  213. 1
  214. >>> clebsch_gordan(S(3)/2, S(1)/2, 1, S(3)/2, -S(1)/2, 1)
  215. sqrt(3)/2
  216. >>> clebsch_gordan(S(3)/2, S(1)/2, 1, -S(1)/2, S(1)/2, 0)
  217. -sqrt(2)/2
  218. Notes
  219. =====
  220. The Clebsch-Gordan coefficient will be evaluated via its relation
  221. to Wigner 3j symbols:
  222. .. math::
  223. \left\langle j_1 m_1 \; j_2 m_2 | j_3 m_3 \right\rangle
  224. =(-1)^{j_1-j_2+m_3} \sqrt{2j_3+1}
  225. \operatorname{Wigner3j}(j_1,j_2,j_3,m_1,m_2,-m_3)
  226. See also the documentation on Wigner 3j symbols which exhibit much
  227. higher symmetry relations than the Clebsch-Gordan coefficient.
  228. Authors
  229. =======
  230. - Jens Rasch (2009-03-24): initial version
  231. """
  232. res = (-1) ** sympify(j_1 - j_2 + m_3) * sqrt(2 * j_3 + 1) * \
  233. wigner_3j(j_1, j_2, j_3, m_1, m_2, -m_3)
  234. return res
  235. def _big_delta_coeff(aa, bb, cc, prec=None):
  236. r"""
  237. Calculates the Delta coefficient of the 3 angular momenta for
  238. Racah symbols. Also checks that the differences are of integer
  239. value.
  240. Parameters
  241. ==========
  242. aa :
  243. First angular momentum, integer or half integer.
  244. bb :
  245. Second angular momentum, integer or half integer.
  246. cc :
  247. Third angular momentum, integer or half integer.
  248. prec :
  249. Precision of the ``sqrt()`` calculation.
  250. Returns
  251. =======
  252. double : Value of the Delta coefficient.
  253. Examples
  254. ========
  255. sage: from sage.functions.wigner import _big_delta_coeff
  256. sage: _big_delta_coeff(1,1,1)
  257. 1/2*sqrt(1/6)
  258. """
  259. if int(aa + bb - cc) != (aa + bb - cc):
  260. raise ValueError("j values must be integer or half integer and fulfill the triangle relation")
  261. if int(aa + cc - bb) != (aa + cc - bb):
  262. raise ValueError("j values must be integer or half integer and fulfill the triangle relation")
  263. if int(bb + cc - aa) != (bb + cc - aa):
  264. raise ValueError("j values must be integer or half integer and fulfill the triangle relation")
  265. if (aa + bb - cc) < 0:
  266. return S.Zero
  267. if (aa + cc - bb) < 0:
  268. return S.Zero
  269. if (bb + cc - aa) < 0:
  270. return S.Zero
  271. maxfact = max(aa + bb - cc, aa + cc - bb, bb + cc - aa, aa + bb + cc + 1)
  272. _calc_factlist(maxfact)
  273. argsqrt = Integer(_Factlist[int(aa + bb - cc)] *
  274. _Factlist[int(aa + cc - bb)] *
  275. _Factlist[int(bb + cc - aa)]) / \
  276. Integer(_Factlist[int(aa + bb + cc + 1)])
  277. ressqrt = sqrt(argsqrt)
  278. if prec:
  279. ressqrt = ressqrt.evalf(prec).as_real_imag()[0]
  280. return ressqrt
  281. def racah(aa, bb, cc, dd, ee, ff, prec=None):
  282. r"""
  283. Calculate the Racah symbol `W(a,b,c,d;e,f)`.
  284. Parameters
  285. ==========
  286. a, ..., f :
  287. Integer or half integer.
  288. prec :
  289. Precision, default: ``None``. Providing a precision can
  290. drastically speed up the calculation.
  291. Returns
  292. =======
  293. Rational number times the square root of a rational number
  294. (if ``prec=None``), or real number if a precision is given.
  295. Examples
  296. ========
  297. >>> from sympy.physics.wigner import racah
  298. >>> racah(3,3,3,3,3,3)
  299. -1/14
  300. Notes
  301. =====
  302. The Racah symbol is related to the Wigner 6j symbol:
  303. .. math::
  304. \operatorname{Wigner6j}(j_1,j_2,j_3,j_4,j_5,j_6)
  305. =(-1)^{j_1+j_2+j_4+j_5} W(j_1,j_2,j_5,j_4,j_3,j_6)
  306. Please see the 6j symbol for its much richer symmetries and for
  307. additional properties.
  308. Algorithm
  309. =========
  310. This function uses the algorithm of [Edmonds74]_ to calculate the
  311. value of the 6j symbol exactly. Note that the formula contains
  312. alternating sums over large factorials and is therefore unsuitable
  313. for finite precision arithmetic and only useful for a computer
  314. algebra system [Rasch03]_.
  315. Authors
  316. =======
  317. - Jens Rasch (2009-03-24): initial version
  318. """
  319. prefac = _big_delta_coeff(aa, bb, ee, prec) * \
  320. _big_delta_coeff(cc, dd, ee, prec) * \
  321. _big_delta_coeff(aa, cc, ff, prec) * \
  322. _big_delta_coeff(bb, dd, ff, prec)
  323. if prefac == 0:
  324. return S.Zero
  325. imin = max(aa + bb + ee, cc + dd + ee, aa + cc + ff, bb + dd + ff)
  326. imax = min(aa + bb + cc + dd, aa + dd + ee + ff, bb + cc + ee + ff)
  327. maxfact = max(imax + 1, aa + bb + cc + dd, aa + dd + ee + ff,
  328. bb + cc + ee + ff)
  329. _calc_factlist(maxfact)
  330. sumres = 0
  331. for kk in range(int(imin), int(imax) + 1):
  332. den = _Factlist[int(kk - aa - bb - ee)] * \
  333. _Factlist[int(kk - cc - dd - ee)] * \
  334. _Factlist[int(kk - aa - cc - ff)] * \
  335. _Factlist[int(kk - bb - dd - ff)] * \
  336. _Factlist[int(aa + bb + cc + dd - kk)] * \
  337. _Factlist[int(aa + dd + ee + ff - kk)] * \
  338. _Factlist[int(bb + cc + ee + ff - kk)]
  339. sumres = sumres + Integer((-1) ** kk * _Factlist[kk + 1]) / den
  340. res = prefac * sumres * (-1) ** int(aa + bb + cc + dd)
  341. return res
  342. def wigner_6j(j_1, j_2, j_3, j_4, j_5, j_6, prec=None):
  343. r"""
  344. Calculate the Wigner 6j symbol `\operatorname{Wigner6j}(j_1,j_2,j_3,j_4,j_5,j_6)`.
  345. Parameters
  346. ==========
  347. j_1, ..., j_6 :
  348. Integer or half integer.
  349. prec :
  350. Precision, default: ``None``. Providing a precision can
  351. drastically speed up the calculation.
  352. Returns
  353. =======
  354. Rational number times the square root of a rational number
  355. (if ``prec=None``), or real number if a precision is given.
  356. Examples
  357. ========
  358. >>> from sympy.physics.wigner import wigner_6j
  359. >>> wigner_6j(3,3,3,3,3,3)
  360. -1/14
  361. >>> wigner_6j(5,5,5,5,5,5)
  362. 1/52
  363. It is an error to have arguments that are not integer or half
  364. integer values or do not fulfill the triangle relation::
  365. sage: wigner_6j(2.5,2.5,2.5,2.5,2.5,2.5)
  366. Traceback (most recent call last):
  367. ...
  368. ValueError: j values must be integer or half integer and fulfill the triangle relation
  369. sage: wigner_6j(0.5,0.5,1.1,0.5,0.5,1.1)
  370. Traceback (most recent call last):
  371. ...
  372. ValueError: j values must be integer or half integer and fulfill the triangle relation
  373. Notes
  374. =====
  375. The Wigner 6j symbol is related to the Racah symbol but exhibits
  376. more symmetries as detailed below.
  377. .. math::
  378. \operatorname{Wigner6j}(j_1,j_2,j_3,j_4,j_5,j_6)
  379. =(-1)^{j_1+j_2+j_4+j_5} W(j_1,j_2,j_5,j_4,j_3,j_6)
  380. The Wigner 6j symbol obeys the following symmetry rules:
  381. - Wigner 6j symbols are left invariant under any permutation of
  382. the columns:
  383. .. math::
  384. \begin{aligned}
  385. \operatorname{Wigner6j}(j_1,j_2,j_3,j_4,j_5,j_6)
  386. &=\operatorname{Wigner6j}(j_3,j_1,j_2,j_6,j_4,j_5) \\
  387. &=\operatorname{Wigner6j}(j_2,j_3,j_1,j_5,j_6,j_4) \\
  388. &=\operatorname{Wigner6j}(j_3,j_2,j_1,j_6,j_5,j_4) \\
  389. &=\operatorname{Wigner6j}(j_1,j_3,j_2,j_4,j_6,j_5) \\
  390. &=\operatorname{Wigner6j}(j_2,j_1,j_3,j_5,j_4,j_6)
  391. \end{aligned}
  392. - They are invariant under the exchange of the upper and lower
  393. arguments in each of any two columns, i.e.
  394. .. math::
  395. \operatorname{Wigner6j}(j_1,j_2,j_3,j_4,j_5,j_6)
  396. =\operatorname{Wigner6j}(j_1,j_5,j_6,j_4,j_2,j_3)
  397. =\operatorname{Wigner6j}(j_4,j_2,j_6,j_1,j_5,j_3)
  398. =\operatorname{Wigner6j}(j_4,j_5,j_3,j_1,j_2,j_6)
  399. - additional 6 symmetries [Regge59]_ giving rise to 144 symmetries
  400. in total
  401. - only non-zero if any triple of `j`'s fulfill a triangle relation
  402. Algorithm
  403. =========
  404. This function uses the algorithm of [Edmonds74]_ to calculate the
  405. value of the 6j symbol exactly. Note that the formula contains
  406. alternating sums over large factorials and is therefore unsuitable
  407. for finite precision arithmetic and only useful for a computer
  408. algebra system [Rasch03]_.
  409. """
  410. res = (-1) ** int(j_1 + j_2 + j_4 + j_5) * \
  411. racah(j_1, j_2, j_5, j_4, j_3, j_6, prec)
  412. return res
  413. def wigner_9j(j_1, j_2, j_3, j_4, j_5, j_6, j_7, j_8, j_9, prec=None):
  414. r"""
  415. Calculate the Wigner 9j symbol
  416. `\operatorname{Wigner9j}(j_1,j_2,j_3,j_4,j_5,j_6,j_7,j_8,j_9)`.
  417. Parameters
  418. ==========
  419. j_1, ..., j_9 :
  420. Integer or half integer.
  421. prec : precision, default
  422. ``None``. Providing a precision can
  423. drastically speed up the calculation.
  424. Returns
  425. =======
  426. Rational number times the square root of a rational number
  427. (if ``prec=None``), or real number if a precision is given.
  428. Examples
  429. ========
  430. >>> from sympy.physics.wigner import wigner_9j
  431. >>> wigner_9j(1,1,1, 1,1,1, 1,1,0, prec=64) # ==1/18
  432. 0.05555555...
  433. >>> wigner_9j(1/2,1/2,0, 1/2,3/2,1, 0,1,1, prec=64) # ==1/6
  434. 0.1666666...
  435. It is an error to have arguments that are not integer or half
  436. integer values or do not fulfill the triangle relation::
  437. sage: wigner_9j(0.5,0.5,0.5, 0.5,0.5,0.5, 0.5,0.5,0.5,prec=64)
  438. Traceback (most recent call last):
  439. ...
  440. ValueError: j values must be integer or half integer and fulfill the triangle relation
  441. sage: wigner_9j(1,1,1, 0.5,1,1.5, 0.5,1,2.5,prec=64)
  442. Traceback (most recent call last):
  443. ...
  444. ValueError: j values must be integer or half integer and fulfill the triangle relation
  445. Algorithm
  446. =========
  447. This function uses the algorithm of [Edmonds74]_ to calculate the
  448. value of the 3j symbol exactly. Note that the formula contains
  449. alternating sums over large factorials and is therefore unsuitable
  450. for finite precision arithmetic and only useful for a computer
  451. algebra system [Rasch03]_.
  452. """
  453. imax = int(min(j_1 + j_9, j_2 + j_6, j_4 + j_8) * 2)
  454. imin = imax % 2
  455. sumres = 0
  456. for kk in range(imin, int(imax) + 1, 2):
  457. sumres = sumres + (kk + 1) * \
  458. racah(j_1, j_2, j_9, j_6, j_3, kk / 2, prec) * \
  459. racah(j_4, j_6, j_8, j_2, j_5, kk / 2, prec) * \
  460. racah(j_1, j_4, j_9, j_8, j_7, kk / 2, prec)
  461. return sumres
  462. def gaunt(l_1, l_2, l_3, m_1, m_2, m_3, prec=None):
  463. r"""
  464. Calculate the Gaunt coefficient.
  465. Explanation
  466. ===========
  467. The Gaunt coefficient is defined as the integral over three
  468. spherical harmonics:
  469. .. math::
  470. \begin{aligned}
  471. \operatorname{Gaunt}(l_1,l_2,l_3,m_1,m_2,m_3)
  472. &=\int Y_{l_1,m_1}(\Omega)
  473. Y_{l_2,m_2}(\Omega) Y_{l_3,m_3}(\Omega) \,d\Omega \\
  474. &=\sqrt{\frac{(2l_1+1)(2l_2+1)(2l_3+1)}{4\pi}}
  475. \operatorname{Wigner3j}(l_1,l_2,l_3,0,0,0)
  476. \operatorname{Wigner3j}(l_1,l_2,l_3,m_1,m_2,m_3)
  477. \end{aligned}
  478. Parameters
  479. ==========
  480. l_1, l_2, l_3, m_1, m_2, m_3 :
  481. Integer.
  482. prec - precision, default: ``None``.
  483. Providing a precision can
  484. drastically speed up the calculation.
  485. Returns
  486. =======
  487. Rational number times the square root of a rational number
  488. (if ``prec=None``), or real number if a precision is given.
  489. Examples
  490. ========
  491. >>> from sympy.physics.wigner import gaunt
  492. >>> gaunt(1,0,1,1,0,-1)
  493. -1/(2*sqrt(pi))
  494. >>> gaunt(1000,1000,1200,9,3,-12).n(64)
  495. 0.00689500421922113448...
  496. It is an error to use non-integer values for `l` and `m`::
  497. sage: gaunt(1.2,0,1.2,0,0,0)
  498. Traceback (most recent call last):
  499. ...
  500. ValueError: l values must be integer
  501. sage: gaunt(1,0,1,1.1,0,-1.1)
  502. Traceback (most recent call last):
  503. ...
  504. ValueError: m values must be integer
  505. Notes
  506. =====
  507. The Gaunt coefficient obeys the following symmetry rules:
  508. - invariant under any permutation of the columns
  509. .. math::
  510. \begin{aligned}
  511. Y(l_1,l_2,l_3,m_1,m_2,m_3)
  512. &=Y(l_3,l_1,l_2,m_3,m_1,m_2) \\
  513. &=Y(l_2,l_3,l_1,m_2,m_3,m_1) \\
  514. &=Y(l_3,l_2,l_1,m_3,m_2,m_1) \\
  515. &=Y(l_1,l_3,l_2,m_1,m_3,m_2) \\
  516. &=Y(l_2,l_1,l_3,m_2,m_1,m_3)
  517. \end{aligned}
  518. - invariant under space inflection, i.e.
  519. .. math::
  520. Y(l_1,l_2,l_3,m_1,m_2,m_3)
  521. =Y(l_1,l_2,l_3,-m_1,-m_2,-m_3)
  522. - symmetric with respect to the 72 Regge symmetries as inherited
  523. for the `3j` symbols [Regge58]_
  524. - zero for `l_1`, `l_2`, `l_3` not fulfilling triangle relation
  525. - zero for violating any one of the conditions: `l_1 \ge |m_1|`,
  526. `l_2 \ge |m_2|`, `l_3 \ge |m_3|`
  527. - non-zero only for an even sum of the `l_i`, i.e.
  528. `L = l_1 + l_2 + l_3 = 2n` for `n` in `\mathbb{N}`
  529. Algorithms
  530. ==========
  531. This function uses the algorithm of [Liberatodebrito82]_ to
  532. calculate the value of the Gaunt coefficient exactly. Note that
  533. the formula contains alternating sums over large factorials and is
  534. therefore unsuitable for finite precision arithmetic and only
  535. useful for a computer algebra system [Rasch03]_.
  536. Authors
  537. =======
  538. Jens Rasch (2009-03-24): initial version for Sage.
  539. """
  540. l_1, l_2, l_3, m_1, m_2, m_3 = [
  541. as_int(i) for i in (l_1, l_2, l_3, m_1, m_2, m_3)]
  542. if l_1 + l_2 - l_3 < 0:
  543. return S.Zero
  544. if l_1 - l_2 + l_3 < 0:
  545. return S.Zero
  546. if -l_1 + l_2 + l_3 < 0:
  547. return S.Zero
  548. if (m_1 + m_2 + m_3) != 0:
  549. return S.Zero
  550. if (abs(m_1) > l_1) or (abs(m_2) > l_2) or (abs(m_3) > l_3):
  551. return S.Zero
  552. bigL, remL = divmod(l_1 + l_2 + l_3, 2)
  553. if remL % 2:
  554. return S.Zero
  555. imin = max(-l_3 + l_1 + m_2, -l_3 + l_2 - m_1, 0)
  556. imax = min(l_2 + m_2, l_1 - m_1, l_1 + l_2 - l_3)
  557. _calc_factlist(max(l_1 + l_2 + l_3 + 1, imax + 1))
  558. ressqrt = sqrt((2 * l_1 + 1) * (2 * l_2 + 1) * (2 * l_3 + 1) * \
  559. _Factlist[l_1 - m_1] * _Factlist[l_1 + m_1] * _Factlist[l_2 - m_2] * \
  560. _Factlist[l_2 + m_2] * _Factlist[l_3 - m_3] * _Factlist[l_3 + m_3] / \
  561. (4*pi))
  562. prefac = Integer(_Factlist[bigL] * _Factlist[l_2 - l_1 + l_3] *
  563. _Factlist[l_1 - l_2 + l_3] * _Factlist[l_1 + l_2 - l_3])/ \
  564. _Factlist[2 * bigL + 1]/ \
  565. (_Factlist[bigL - l_1] *
  566. _Factlist[bigL - l_2] * _Factlist[bigL - l_3])
  567. sumres = 0
  568. for ii in range(int(imin), int(imax) + 1):
  569. den = _Factlist[ii] * _Factlist[ii + l_3 - l_1 - m_2] * \
  570. _Factlist[l_2 + m_2 - ii] * _Factlist[l_1 - ii - m_1] * \
  571. _Factlist[ii + l_3 - l_2 + m_1] * _Factlist[l_1 + l_2 - l_3 - ii]
  572. sumres = sumres + Integer((-1) ** ii) / den
  573. res = ressqrt * prefac * sumres * Integer((-1) ** (bigL + l_3 + m_1 - m_2))
  574. if prec is not None:
  575. res = res.n(prec)
  576. return res
  577. def real_gaunt(l_1, l_2, l_3, m_1, m_2, m_3, prec=None):
  578. r"""
  579. Calculate the real Gaunt coefficient.
  580. Explanation
  581. ===========
  582. The real Gaunt coefficient is defined as the integral over three
  583. real spherical harmonics:
  584. .. math::
  585. \begin{aligned}
  586. \operatorname{RealGaunt}(l_1,l_2,l_3,m_1,m_2,m_3)
  587. &=\int Z^{m_1}_{l_1}(\Omega)
  588. Z^{m_2}_{l_2}(\Omega) Z^{m_3}_{l_3}(\Omega) \,d\Omega \\
  589. \end{aligned}
  590. Alternatively, it can be defined in terms of the standard Gaunt
  591. coefficient by relating the real spherical harmonics to the standard
  592. spherical harmonics via a unitary transformation `U`, i.e.
  593. `Z^{m}_{l}(\Omega)=\sum_{m'}U^{m}_{m'}Y^{m'}_{l}(\Omega)` [Homeier96]_.
  594. The real Gaunt coefficient is then defined as
  595. .. math::
  596. \begin{aligned}
  597. \operatorname{RealGaunt}(l_1,l_2,l_3,m_1,m_2,m_3)
  598. &=\int Z^{m_1}_{l_1}(\Omega)
  599. Z^{m_2}_{l_2}(\Omega) Z^{m_3}_{l_3}(\Omega) \,d\Omega \\
  600. &=\sum_{m'_1 m'_2 m'_3} U^{m_1}_{m'_1}U^{m_2}_{m'_2}U^{m_3}_{m'_3}
  601. \operatorname{Gaunt}(l_1,l_2,l_3,m'_1,m'_2,m'_3)
  602. \end{aligned}
  603. The unitary matrix `U` has components
  604. .. math::
  605. \begin{aligned}
  606. U^m_{m'} = \delta_{|m||m'|}*(\delta_{m'0}\delta_{m0} + \frac{1}{\sqrt{2}}\big[\Theta(m)
  607. \big(\delta_{m'm}+(-1)^{m'}\delta_{m'-m}\big)+i\Theta(-m)\big((-1)^{-m}
  608. \delta_{m'-m}-\delta_{m'm}*(-1)^{m'-m}\big)\big])
  609. \end{aligned}
  610. where `\delta_{ij}` is the Kronecker delta symbol and `\Theta` is a step
  611. function defined as
  612. .. math::
  613. \begin{aligned}
  614. \Theta(x) = \begin{cases} 1 \,\text{for}\, x > 0 \\ 0 \,\text{for}\, x \leq 0 \end{cases}
  615. \end{aligned}
  616. Parameters
  617. ==========
  618. l_1, l_2, l_3, m_1, m_2, m_3 :
  619. Integer.
  620. prec - precision, default: ``None``.
  621. Providing a precision can
  622. drastically speed up the calculation.
  623. Returns
  624. =======
  625. Rational number times the square root of a rational number.
  626. Examples
  627. ========
  628. >>> from sympy.physics.wigner import real_gaunt
  629. >>> real_gaunt(2,2,4,-1,-1,0)
  630. -2/(7*sqrt(pi))
  631. >>> real_gaunt(10,10,20,-9,-9,0).n(64)
  632. -0.00002480019791932209313156167...
  633. It is an error to use non-integer values for `l` and `m`::
  634. real_gaunt(2.8,0.5,1.3,0,0,0)
  635. Traceback (most recent call last):
  636. ...
  637. ValueError: l values must be integer
  638. real_gaunt(2,2,4,0.7,1,-3.4)
  639. Traceback (most recent call last):
  640. ...
  641. ValueError: m values must be integer
  642. Notes
  643. =====
  644. The real Gaunt coefficient inherits from the standard Gaunt coefficient,
  645. the invariance under any permutation of the pairs `(l_i, m_i)` and the
  646. requirement that the sum of the `l_i` be even to yield a non-zero value.
  647. It also obeys the following symmetry rules:
  648. - zero for `l_1`, `l_2`, `l_3` not fulfiling the condition
  649. `l_1 \in \{l_{\text{max}}, l_{\text{max}}-2, \ldots, l_{\text{min}}\}`,
  650. where `l_{\text{max}} = l_2+l_3`,
  651. .. math::
  652. \begin{aligned}
  653. l_{\text{min}} = \begin{cases} \kappa(l_2, l_3, m_2, m_3) & \text{if}\,
  654. \kappa(l_2, l_3, m_2, m_3) + l_{\text{max}}\, \text{is even} \\
  655. \kappa(l_2, l_3, m_2, m_3)+1 & \text{if}\, \kappa(l_2, l_3, m_2, m_3) +
  656. l_{\text{max}}\, \text{is odd}\end{cases}
  657. \end{aligned}
  658. and `\kappa(l_2, l_3, m_2, m_3) = \max{\big(|l_2-l_3|, \min{\big(|m_2+m_3|,
  659. |m_2-m_3|\big)}\big)}`
  660. - zero for an odd number of negative `m_i`
  661. Algorithms
  662. ==========
  663. This function uses the algorithms of [Homeier96]_ and [Rasch03]_ to
  664. calculate the value of the real Gaunt coefficient exactly. Note that
  665. the formula used in [Rasch03]_ contains alternating sums over large
  666. factorials and is therefore unsuitable for finite precision arithmetic
  667. and only useful for a computer algebra system [Rasch03]_. However, this
  668. function can in principle use any algorithm that computes the Gaunt
  669. coefficient, so it is suitable for finite precision arithmetic in so far
  670. as the algorithm which computes the Gaunt coefficient is.
  671. """
  672. l_1, l_2, l_3, m_1, m_2, m_3 = [
  673. as_int(i) for i in (l_1, l_2, l_3, m_1, m_2, m_3)]
  674. # check for quick exits
  675. if sum(1 for i in (m_1, m_2, m_3) if i < 0) % 2:
  676. return S.Zero # odd number of negative m
  677. if (l_1 + l_2 + l_3) % 2:
  678. return S.Zero # sum of l is odd
  679. lmax = l_2 + l_3
  680. lmin = max(abs(l_2 - l_3), min(abs(m_2 + m_3), abs(m_2 - m_3)))
  681. if (lmin + lmax) % 2:
  682. lmin += 1
  683. if lmin not in range(lmax, lmin - 2, -2):
  684. return S.Zero
  685. kron_del = lambda i, j: 1 if i == j else 0
  686. s = lambda e: -1 if e % 2 else 1 # (-1)**e to give +/-1, avoiding float when e<0
  687. A = lambda a, b: (-kron_del(a, b)*s(a-b) + kron_del(a, -b)*
  688. s(b)) if b < 0 else 0
  689. B = lambda a, b: (kron_del(a, b) + kron_del(a, -b)*s(a)) if b > 0 else 0
  690. C = lambda a, b: kron_del(abs(a), abs(b))*(kron_del(a, 0)*kron_del(b, 0) +
  691. (B(a, b) + I*A(a, b))/sqrt(2))
  692. ugnt = 0
  693. for i in range(-l_1, l_1+1):
  694. U1 = C(i, m_1)
  695. for j in range(-l_2, l_2+1):
  696. U2 = C(j, m_2)
  697. U3 = C(-i-j, m_3)
  698. ugnt = ugnt + re(U1*U2*U3)*gaunt(l_1, l_2, l_3, i, j, -i-j)
  699. if prec is not None:
  700. ugnt = ugnt.n(prec)
  701. return ugnt
  702. class Wigner3j(Function):
  703. def doit(self, **hints):
  704. if all(obj.is_number for obj in self.args):
  705. return wigner_3j(*self.args)
  706. else:
  707. return self
  708. def dot_rot_grad_Ynm(j, p, l, m, theta, phi):
  709. r"""
  710. Returns dot product of rotational gradients of spherical harmonics.
  711. Explanation
  712. ===========
  713. This function returns the right hand side of the following expression:
  714. .. math ::
  715. \vec{R}Y{_j^{p}} \cdot \vec{R}Y{_l^{m}} = (-1)^{m+p}
  716. \sum\limits_{k=|l-j|}^{l+j}Y{_k^{m+p}} * \alpha_{l,m,j,p,k} *
  717. \frac{1}{2} (k^2-j^2-l^2+k-j-l)
  718. Arguments
  719. =========
  720. j, p, l, m .... indices in spherical harmonics (expressions or integers)
  721. theta, phi .... angle arguments in spherical harmonics
  722. Example
  723. =======
  724. >>> from sympy import symbols
  725. >>> from sympy.physics.wigner import dot_rot_grad_Ynm
  726. >>> theta, phi = symbols("theta phi")
  727. >>> dot_rot_grad_Ynm(3, 2, 2, 0, theta, phi).doit()
  728. 3*sqrt(55)*Ynm(5, 2, theta, phi)/(11*sqrt(pi))
  729. """
  730. j = sympify(j)
  731. p = sympify(p)
  732. l = sympify(l)
  733. m = sympify(m)
  734. theta = sympify(theta)
  735. phi = sympify(phi)
  736. k = Dummy("k")
  737. def alpha(l,m,j,p,k):
  738. return sqrt((2*l+1)*(2*j+1)*(2*k+1)/(4*pi)) * \
  739. Wigner3j(j, l, k, S.Zero, S.Zero, S.Zero) * \
  740. Wigner3j(j, l, k, p, m, -m-p)
  741. return (S.NegativeOne)**(m+p) * Sum(Ynm(k, m+p, theta, phi) * alpha(l,m,j,p,k) / 2 \
  742. *(k**2-j**2-l**2+k-j-l), (k, abs(l-j), l+j))
  743. def wigner_d_small(J, beta):
  744. """Return the small Wigner d matrix for angular momentum J.
  745. Explanation
  746. ===========
  747. J : An integer, half-integer, or SymPy symbol for the total angular
  748. momentum of the angular momentum space being rotated.
  749. beta : A real number representing the Euler angle of rotation about
  750. the so-called line of nodes. See [Edmonds74]_.
  751. Returns
  752. =======
  753. A matrix representing the corresponding Euler angle rotation( in the basis
  754. of eigenvectors of `J_z`).
  755. .. math ::
  756. \\mathcal{d}_{\\beta} = \\exp\\big( \\frac{i\\beta}{\\hbar} J_y\\big)
  757. The components are calculated using the general form [Edmonds74]_,
  758. equation 4.1.15.
  759. Examples
  760. ========
  761. >>> from sympy import Integer, symbols, pi, pprint
  762. >>> from sympy.physics.wigner import wigner_d_small
  763. >>> half = 1/Integer(2)
  764. >>> beta = symbols("beta", real=True)
  765. >>> pprint(wigner_d_small(half, beta), use_unicode=True)
  766. ⎡ ⎛β⎞ ⎛β⎞⎤
  767. ⎢cos⎜─⎟ sin⎜─⎟⎥
  768. ⎢ ⎝2⎠ ⎝2⎠⎥
  769. ⎢ ⎥
  770. ⎢ ⎛β⎞ ⎛β⎞⎥
  771. ⎢-sin⎜─⎟ cos⎜─⎟⎥
  772. ⎣ ⎝2⎠ ⎝2⎠⎦
  773. >>> pprint(wigner_d_small(2*half, beta), use_unicode=True)
  774. ⎡ 2⎛β⎞ ⎛β⎞ ⎛β⎞ 2⎛β⎞ ⎤
  775. ⎢ cos ⎜─⎟ √2⋅sin⎜─⎟⋅cos⎜─⎟ sin ⎜─⎟ ⎥
  776. ⎢ ⎝2⎠ ⎝2⎠ ⎝2⎠ ⎝2⎠ ⎥
  777. ⎢ ⎥
  778. ⎢ ⎛β⎞ ⎛β⎞ 2⎛β⎞ 2⎛β⎞ ⎛β⎞ ⎛β⎞⎥
  779. ⎢-√2⋅sin⎜─⎟⋅cos⎜─⎟ - sin ⎜─⎟ + cos ⎜─⎟ √2⋅sin⎜─⎟⋅cos⎜─⎟⎥
  780. ⎢ ⎝2⎠ ⎝2⎠ ⎝2⎠ ⎝2⎠ ⎝2⎠ ⎝2⎠⎥
  781. ⎢ ⎥
  782. ⎢ 2⎛β⎞ ⎛β⎞ ⎛β⎞ 2⎛β⎞ ⎥
  783. ⎢ sin ⎜─⎟ -√2⋅sin⎜─⎟⋅cos⎜─⎟ cos ⎜─⎟ ⎥
  784. ⎣ ⎝2⎠ ⎝2⎠ ⎝2⎠ ⎝2⎠ ⎦
  785. From table 4 in [Edmonds74]_
  786. >>> pprint(wigner_d_small(half, beta).subs({beta:pi/2}), use_unicode=True)
  787. ⎡ √2 √2⎤
  788. ⎢ ── ──⎥
  789. ⎢ 2 2 ⎥
  790. ⎢ ⎥
  791. ⎢-√2 √2⎥
  792. ⎢──── ──⎥
  793. ⎣ 2 2 ⎦
  794. >>> pprint(wigner_d_small(2*half, beta).subs({beta:pi/2}),
  795. ... use_unicode=True)
  796. ⎡ √2 ⎤
  797. ⎢1/2 ── 1/2⎥
  798. ⎢ 2 ⎥
  799. ⎢ ⎥
  800. ⎢-√2 √2 ⎥
  801. ⎢──── 0 ── ⎥
  802. ⎢ 2 2 ⎥
  803. ⎢ ⎥
  804. ⎢ -√2 ⎥
  805. ⎢1/2 ──── 1/2⎥
  806. ⎣ 2 ⎦
  807. >>> pprint(wigner_d_small(3*half, beta).subs({beta:pi/2}),
  808. ... use_unicode=True)
  809. ⎡ √2 √6 √6 √2⎤
  810. ⎢ ── ── ── ──⎥
  811. ⎢ 4 4 4 4 ⎥
  812. ⎢ ⎥
  813. ⎢-√6 -√2 √2 √6⎥
  814. ⎢──── ──── ── ──⎥
  815. ⎢ 4 4 4 4 ⎥
  816. ⎢ ⎥
  817. ⎢ √6 -√2 -√2 √6⎥
  818. ⎢ ── ──── ──── ──⎥
  819. ⎢ 4 4 4 4 ⎥
  820. ⎢ ⎥
  821. ⎢-√2 √6 -√6 √2⎥
  822. ⎢──── ── ──── ──⎥
  823. ⎣ 4 4 4 4 ⎦
  824. >>> pprint(wigner_d_small(4*half, beta).subs({beta:pi/2}),
  825. ... use_unicode=True)
  826. ⎡ √6 ⎤
  827. ⎢1/4 1/2 ── 1/2 1/4⎥
  828. ⎢ 4 ⎥
  829. ⎢ ⎥
  830. ⎢-1/2 -1/2 0 1/2 1/2⎥
  831. ⎢ ⎥
  832. ⎢ √6 √6 ⎥
  833. ⎢ ── 0 -1/2 0 ── ⎥
  834. ⎢ 4 4 ⎥
  835. ⎢ ⎥
  836. ⎢-1/2 1/2 0 -1/2 1/2⎥
  837. ⎢ ⎥
  838. ⎢ √6 ⎥
  839. ⎢1/4 -1/2 ── -1/2 1/4⎥
  840. ⎣ 4 ⎦
  841. """
  842. M = [J-i for i in range(2*J+1)]
  843. d = zeros(2*J+1)
  844. for i, Mi in enumerate(M):
  845. for j, Mj in enumerate(M):
  846. # We get the maximum and minimum value of sigma.
  847. sigmamax = max([-Mi-Mj, J-Mj])
  848. sigmamin = min([0, J-Mi])
  849. dij = sqrt(factorial(J+Mi)*factorial(J-Mi) /
  850. factorial(J+Mj)/factorial(J-Mj))
  851. terms = [(-1)**(J-Mi-s) *
  852. binomial(J+Mj, J-Mi-s) *
  853. binomial(J-Mj, s) *
  854. cos(beta/2)**(2*s+Mi+Mj) *
  855. sin(beta/2)**(2*J-2*s-Mj-Mi)
  856. for s in range(sigmamin, sigmamax+1)]
  857. d[i, j] = dij*Add(*terms)
  858. return ImmutableMatrix(d)
  859. def wigner_d(J, alpha, beta, gamma):
  860. """Return the Wigner D matrix for angular momentum J.
  861. Explanation
  862. ===========
  863. J :
  864. An integer, half-integer, or SymPy symbol for the total angular
  865. momentum of the angular momentum space being rotated.
  866. alpha, beta, gamma - Real numbers representing the Euler.
  867. Angles of rotation about the so-called vertical, line of nodes, and
  868. figure axes. See [Edmonds74]_.
  869. Returns
  870. =======
  871. A matrix representing the corresponding Euler angle rotation( in the basis
  872. of eigenvectors of `J_z`).
  873. .. math ::
  874. \\mathcal{D}_{\\alpha \\beta \\gamma} =
  875. \\exp\\big( \\frac{i\\alpha}{\\hbar} J_z\\big)
  876. \\exp\\big( \\frac{i\\beta}{\\hbar} J_y\\big)
  877. \\exp\\big( \\frac{i\\gamma}{\\hbar} J_z\\big)
  878. The components are calculated using the general form [Edmonds74]_,
  879. equation 4.1.12.
  880. Examples
  881. ========
  882. The simplest possible example:
  883. >>> from sympy.physics.wigner import wigner_d
  884. >>> from sympy import Integer, symbols, pprint
  885. >>> half = 1/Integer(2)
  886. >>> alpha, beta, gamma = symbols("alpha, beta, gamma", real=True)
  887. >>> pprint(wigner_d(half, alpha, beta, gamma), use_unicode=True)
  888. ⎡ ⅈ⋅α ⅈ⋅γ ⅈ⋅α -ⅈ⋅γ ⎤
  889. ⎢ ─── ─── ─── ───── ⎥
  890. ⎢ 2 2 ⎛β⎞ 2 2 ⎛β⎞ ⎥
  891. ⎢ ℯ ⋅ℯ ⋅cos⎜─⎟ ℯ ⋅ℯ ⋅sin⎜─⎟ ⎥
  892. ⎢ ⎝2⎠ ⎝2⎠ ⎥
  893. ⎢ ⎥
  894. ⎢ -ⅈ⋅α ⅈ⋅γ -ⅈ⋅α -ⅈ⋅γ ⎥
  895. ⎢ ───── ─── ───── ───── ⎥
  896. ⎢ 2 2 ⎛β⎞ 2 2 ⎛β⎞⎥
  897. ⎢-ℯ ⋅ℯ ⋅sin⎜─⎟ ℯ ⋅ℯ ⋅cos⎜─⎟⎥
  898. ⎣ ⎝2⎠ ⎝2⎠⎦
  899. """
  900. d = wigner_d_small(J, beta)
  901. M = [J-i for i in range(2*J+1)]
  902. D = [[exp(I*Mi*alpha)*d[i, j]*exp(I*Mj*gamma)
  903. for j, Mj in enumerate(M)] for i, Mi in enumerate(M)]
  904. return ImmutableMatrix(D)