# HG changeset patch
# User Minh Van Nguyen <nguyenminh2@gmail.com>
# Date 1247689434 25200
# Node ID c9174878092a0d8ba1999bb5b895d967f4106e37
# Parent 961601aa9eded1d935214503f2c5c618a8a14d10
trac 5996: reviewer patch
diff -r 961601aa9ede -r c9174878092a sage/functions/wigner.py
|
a
|
b
|
|
| 4 | 4 | Collection of functions for calculating Wigner 3j, 6j, 9j, |
| 5 | 5 | Clebsch-Gordan, Racah as well as Gaunt coefficients exactly, all |
| 6 | 6 | evaluating to a rational number times the square root of a rational |
| 7 | | number [Rasch03]. |
| | 7 | number [Rasch03]_. |
| 8 | 8 | |
| 9 | 9 | Please see the description of the individual functions for further |
| 10 | 10 | details and examples. |
| 11 | 11 | |
| 12 | 12 | REFERENCES: |
| 13 | 13 | |
| 14 | | - [Rasch03] J. Rasch and A. C. H. Yu, 'Efficient Storage Scheme for |
| | 14 | .. [Rasch03] J. Rasch and A. C. H. Yu, 'Efficient Storage Scheme for |
| 15 | 15 | Pre-calculated Wigner 3j, 6j and Gaunt Coefficients', SIAM |
| 16 | 16 | J. Sci. Comput. Volume 25, Issue 4, pp. 1416-1428 (2003) |
| 17 | 17 | |
| … |
… |
|
| 29 | 29 | # http://www.gnu.org/licenses/ |
| 30 | 30 | #*********************************************************************** |
| 31 | 31 | |
| | 32 | from sage.rings.complex_number import ComplexNumber |
| | 33 | from sage.rings.integer import Integer |
| | 34 | from sage.rings.integer_mod import Mod |
| 32 | 35 | from sage.symbolic.constants import pi |
| 33 | | from sage.rings.integer import Integer |
| 34 | | from sage.rings.complex_number import ComplexNumber |
| 35 | | from sage.rings.integer_mod import Mod |
| 36 | 36 | |
| 37 | 37 | # This list of precomputed factorials is needed to massively |
| 38 | 38 | # accelerate future calculations of the various coefficients |
| … |
… |
|
| 74 | 74 | |
| 75 | 75 | - ``j_1``, ``j_2``, ``j_3``, ``m_1``, ``m_2``, ``m_3`` - integer or half integer |
| 76 | 76 | |
| 77 | | - ``prec`` - precision, default: None. Providing a precision can |
| | 77 | - ``prec`` - precision, default: ``None``. Providing a precision can |
| 78 | 78 | drastically speed up the calculation. |
| 79 | 79 | |
| 80 | 80 | OUTPUT: |
| 81 | 81 | |
| 82 | | rational number times the square root of a rational number (if prec=None), or |
| 83 | | real number if a precision is given |
| | 82 | Rational number times the square root of a rational number |
| | 83 | (if ``prec=None``), or real number if a precision is given. |
| 84 | 84 | |
| 85 | 85 | EXAMPLES:: |
| 86 | 86 | |
| 87 | 87 | sage: wigner_3j(2, 6, 4, 0, 0, 0) |
| 88 | 88 | sqrt(5/143) |
| 89 | | |
| 90 | 89 | sage: wigner_3j(2, 6, 4, 0, 0, 1) |
| 91 | 90 | 0 |
| 92 | | |
| 93 | 91 | sage: wigner_3j(0.5, 0.5, 1, 0.5, -0.5, 0) |
| 94 | 92 | sqrt(1/6) |
| 95 | | |
| 96 | 93 | sage: wigner_3j(40, 100, 60, -10, 60, -50) |
| 97 | 94 | 95608/18702538494885*sqrt(21082735836735314343364163310/220491455010479533763) |
| 98 | | |
| 99 | 95 | sage: wigner_3j(2500, 2500, 5000, 2488, 2400, -4888, prec=64) |
| 100 | 96 | 7.60424456883448589e-12 |
| 101 | 97 | |
| … |
… |
|
| 106 | 102 | Traceback (most recent call last): |
| 107 | 103 | ... |
| 108 | 104 | ValueError: j values must be integer or half integer |
| 109 | | |
| 110 | 105 | sage: wigner_3j(2, 6, 4, 1, 0, -1.1) |
| 111 | 106 | Traceback (most recent call last): |
| 112 | 107 | ... |
| … |
… |
|
| 127 | 122 | =(-1)^J Wigner3j(j_3,j_2,j_1,m_3,m_2,m_1) |
| 128 | 123 | =(-1)^J Wigner3j(j_1,j_3,j_2,m_1,m_3,m_2) |
| 129 | 124 | =(-1)^J Wigner3j(j_2,j_1,j_3,m_2,m_1,m_3) |
| 130 | | |
| 131 | | - invariant under space inflection, i. e. |
| | 125 | |
| | 126 | - invariant under space inflection, i.e. |
| 132 | 127 | |
| 133 | 128 | .. math:: |
| 134 | 129 | |
| 135 | 130 | Wigner3j(j_1,j_2,j_3,m_1,m_2,m_3) |
| 136 | 131 | =(-1)^J Wigner3j(j_1,j_2,j_3,-m_1,-m_2,-m_3) |
| 137 | | |
| | 132 | |
| 138 | 133 | - symmetric with respect to the 72 additional symmetries based on |
| 139 | | the work by [Regge58] |
| | 134 | the work by [Regge58]_ |
| 140 | 135 | |
| 141 | 136 | - zero for `j_1`, `j_2`, `j_3` not fulfilling triangle relation |
| 142 | | |
| 143 | | - zero for `m_1+m_2+m_3\neq 0` |
| | 137 | |
| | 138 | - zero for `m_1 + m_2 + m_3 \neq 0` |
| 144 | 139 | |
| 145 | 140 | - zero for violating any one of the conditions |
| 146 | | `j_1\ge|m_1|`, `j_2\ge|m_2|`, `j_3\ge|m_3|` |
| | 141 | `j_1 \ge |m_1|`, `j_2 \ge |m_2|`, `j_3 \ge |m_3|` |
| 147 | 142 | |
| 148 | 143 | ALGORITHM: |
| 149 | 144 | |
| 150 | | This function uses the algorithm of [Edmonds74] to calculate the |
| | 145 | This function uses the algorithm of [Edmonds74]_ to calculate the |
| 151 | 146 | value of the 3j symbol exactly. Note that the formula contains |
| 152 | 147 | alternating sums over large factorials and is therefore unsuitable |
| 153 | 148 | for finite precision arithmetic and only useful for a computer |
| 154 | | algebra system [Rasch03]. |
| | 149 | algebra system [Rasch03]_. |
| 155 | 150 | |
| 156 | 151 | REFERENCES: |
| 157 | 152 | |
| 158 | | - [Regge58] 'Symmetry Properties of Clebsch-Gordan Coefficients', |
| | 153 | .. [Regge58] 'Symmetry Properties of Clebsch-Gordan Coefficients', |
| 159 | 154 | T. Regge, Nuovo Cimento, Volume 10, pp. 544 (1958) |
| 160 | 155 | |
| 161 | | - [Edmonds74] 'Angular Momentum in Quantum Mechanics', |
| | 156 | .. [Edmonds74] 'Angular Momentum in Quantum Mechanics', |
| 162 | 157 | A. R. Edmonds, Princeton University Press (1974) |
| 163 | 158 | |
| 164 | | - [Rasch03] 'Efficient Storage Scheme for Pre-calculated Wigner 3j, |
| 165 | | 6j and Gaunt Coefficients', J. Rasch and A. C. H. Yu, SIAM |
| 166 | | J. Sci. Comput. Volume 25, Issue 4, pp. 1416-1428 (2003) |
| 167 | | |
| 168 | 159 | AUTHORS: |
| 169 | 160 | |
| 170 | 161 | - Jens Rasch (2009-03-24): initial version |
| … |
… |
|
| 175 | 166 | if int(m_1 * 2) != m_1 * 2 or int(m_2 * 2) != m_2 * 2 or \ |
| 176 | 167 | int(m_3 * 2) != m_3 * 2: |
| 177 | 168 | raise ValueError("m values must be integer or half integer") |
| 178 | | if (m_1 + m_2 + m_3 <> 0): |
| | 169 | if m_1 + m_2 + m_3 != 0: |
| 179 | 170 | return 0 |
| 180 | | prefid = Integer((-1) ** (int(j_1 - j_2 - m_3))) |
| | 171 | prefid = Integer((-1) ** int(j_1 - j_2 - m_3)) |
| 181 | 172 | m_3 = -m_3 |
| 182 | 173 | a1 = j_1 + j_2 - j_3 |
| 183 | | if (a1 < 0): |
| | 174 | if a1 < 0: |
| 184 | 175 | return 0 |
| 185 | 176 | a2 = j_1 - j_2 + j_3 |
| 186 | | if (a2 < 0): |
| | 177 | if a2 < 0: |
| 187 | 178 | return 0 |
| 188 | 179 | a3 = -j_1 + j_2 + j_3 |
| 189 | | if (a3 < 0): |
| | 180 | if a3 < 0: |
| 190 | 181 | return 0 |
| 191 | 182 | if (abs(m_1) > j_1) or (abs(m_2) > j_2) or (abs(m_3) > j_3): |
| 192 | 183 | return 0 |
| 193 | 184 | |
| 194 | 185 | maxfact = max(j_1 + j_2 + j_3 + 1, j_1 + abs(m_1), j_2 + abs(m_2), \ |
| 195 | | j_3 + abs(m_3)) |
| | 186 | j_3 + abs(m_3)) |
| 196 | 187 | _calc_factlist(maxfact) |
| 197 | 188 | |
| 198 | 189 | argsqrt = Integer(_Factlist[int(j_1 + j_2 - j_3)] * \ |
| … |
… |
|
| 209 | 200 | ressqrt = argsqrt.sqrt(prec) |
| 210 | 201 | if type(ressqrt) is ComplexNumber: |
| 211 | 202 | ressqrt = ressqrt.real() |
| 212 | | |
| | 203 | |
| 213 | 204 | imin = max(-j_3 + j_1 + m_2, -j_3 + j_2 - m_1, 0) |
| 214 | 205 | imax = min(j_2 + m_2, j_1 - m_1, j_1 + j_2 - j_3) |
| 215 | 206 | sumres = 0 |
| 216 | | for ii in range(imin, imax + 1): |
| | 207 | for ii in range(imin, imax + 1): |
| 217 | 208 | den = _Factlist[ii] * \ |
| 218 | 209 | _Factlist[int(ii + j_3 - j_1 - m_2)] * \ |
| 219 | 210 | _Factlist[int(j_2 + m_2 - ii)] * \ |
| … |
… |
|
| 228 | 219 | |
| 229 | 220 | def clebsch_gordan(j_1, j_2, j_3, m_1, m_2, m_3, prec=None): |
| 230 | 221 | r""" |
| 231 | | Calculates the Clebsch-Gordan coefficient |
| 232 | | `< j_1 m_1 \; j_2 m_2 | j_3 m_3 >`. |
| | 222 | Calculates the Clebsch-Gordan coefficient |
| | 223 | `\langle j_1 m_1 \; j_2 m_2 | j_3 m_3 \rangle`. |
| | 224 | |
| | 225 | The reference for this function is [Edmonds74]_. |
| 233 | 226 | |
| 234 | 227 | INPUT: |
| 235 | 228 | |
| 236 | 229 | - ``j_1``, ``j_2``, ``j_3``, ``m_1``, ``m_2``, ``m_3`` - integer or half integer |
| 237 | | |
| 238 | | - ``prec`` - precision, default: None. Providing a precision can |
| | 230 | |
| | 231 | - ``prec`` - precision, default: ``None``. Providing a precision can |
| 239 | 232 | drastically speed up the calculation. |
| 240 | 233 | |
| 241 | 234 | OUTPUT: |
| 242 | 235 | |
| 243 | | rational number times the square root of a rational number (if prec=None), or |
| 244 | | real number if a precision is given |
| | 236 | Rational number times the square root of a rational number |
| | 237 | (if ``prec=None``), or real number if a precision is given. |
| 245 | 238 | |
| 246 | 239 | EXAMPLES:: |
| 247 | 240 | |
| 248 | 241 | sage: simplify(clebsch_gordan(3/2,1/2,2, 3/2,1/2,2)) |
| 249 | 242 | 1 |
| 250 | | |
| 251 | 243 | sage: clebsch_gordan(1.5,0.5,1, 1.5,-0.5,1) |
| 252 | 244 | 1/2*sqrt(3) |
| 253 | | |
| 254 | 245 | sage: clebsch_gordan(3/2,1/2,1, -1/2,1/2,0) |
| 255 | 246 | -sqrt(1/6)*sqrt(3) |
| 256 | 247 | |
| … |
… |
|
| 261 | 252 | |
| 262 | 253 | .. math:: |
| 263 | 254 | |
| 264 | | < j_1 m_1 \; j_2 m_2 | j_3 m_3 > |
| | 255 | \langle j_1 m_1 \; j_2 m_2 | j_3 m_3 \rangle |
| 265 | 256 | =(-1)^{j_1-j_2+m_3} \sqrt{2j_3+1} \; |
| 266 | 257 | Wigner3j(j_1,j_2,j_3,m_1,m_2,-m_3) |
| 267 | 258 | |
| 268 | 259 | See also the documentation on Wigner 3j symbols which exhibit much |
| 269 | 260 | higher symmetry relations than the Clebsch-Gordan coefficient. |
| 270 | | |
| 271 | | REFERENCES: |
| 272 | | |
| 273 | | - [Edmonds74] 'Angular Momentum in Quantum Mechanics', |
| 274 | | A. R. Edmonds, Princeton University Press (1974) |
| 275 | | |
| 276 | | - [Rasch03] 'Efficient Storage Scheme for Pre-calculated Wigner 3j, |
| 277 | | 6j and Gaunt Coefficients', J. Rasch and A. C. H. Yu, SIAM |
| 278 | | J. Sci. Comput. Volume 25, Issue 4, pp. 1416-1428 (2003) |
| 279 | 261 | |
| 280 | 262 | AUTHORS: |
| 281 | 263 | |
| 282 | 264 | - Jens Rasch (2009-03-24): initial version |
| 283 | 265 | """ |
| 284 | | res = (-1) ** (int(j_1 - j_2 + m_3)) * (2 * j_3 + 1).sqrt(prec) * \ |
| | 266 | res = (-1) ** int(j_1 - j_2 + m_3) * (2 * j_3 + 1).sqrt(prec) * \ |
| 285 | 267 | wigner_3j(j_1, j_2, j_3, m_1, m_2, -m_3, prec) |
| 286 | 268 | return res |
| 287 | 269 | |
| … |
… |
|
| 300 | 282 | |
| 301 | 283 | - ``cc`` - third angular momentum, integer or half integer |
| 302 | 284 | |
| 303 | | - ``prec`` - precision of the sqrt() calculation |
| | 285 | - ``prec`` - precision of the ``sqrt()`` calculation |
| 304 | 286 | |
| 305 | 287 | OUTPUT: |
| 306 | 288 | |
| … |
… |
|
| 312 | 294 | sage: _big_delta_coeff(1,1,1) |
| 313 | 295 | 1/2*sqrt(1/6) |
| 314 | 296 | """ |
| 315 | | if (int(aa + bb - cc) != (aa + bb - cc)): |
| 316 | | raise ValueError("j values must be integer or half integer and fulfil the triangle relation") |
| 317 | | if (int(aa + cc - bb) != (aa + cc - bb)): |
| 318 | | raise ValueError("j values must be integer or half integer and fulfil the triangle relation") |
| 319 | | if (int(bb + cc - aa) != (bb + cc - aa)): |
| 320 | | raise ValueError("j values must be integer or half integer and fulfil the triangle relation") |
| | 297 | if int(aa + bb - cc) != (aa + bb - cc): |
| | 298 | raise ValueError("j values must be integer or half integer and fulfill the triangle relation") |
| | 299 | if int(aa + cc - bb) != (aa + cc - bb): |
| | 300 | raise ValueError("j values must be integer or half integer and fulfill the triangle relation") |
| | 301 | if int(bb + cc - aa) != (bb + cc - aa): |
| | 302 | raise ValueError("j values must be integer or half integer and fulfill the triangle relation") |
| 321 | 303 | if (aa + bb - cc) < 0: |
| 322 | 304 | return 0 |
| 323 | 305 | if (aa + cc - bb) < 0: |
| 324 | 306 | return 0 |
| 325 | 307 | if (bb + cc - aa) < 0: |
| 326 | 308 | return 0 |
| 327 | | |
| | 309 | |
| 328 | 310 | maxfact = max(aa + bb - cc, aa + cc - bb, bb + cc - aa, aa + bb + cc + 1) |
| 329 | 311 | _calc_factlist(maxfact) |
| 330 | 312 | |
| … |
… |
|
| 349 | 331 | |
| 350 | 332 | - ``a``, ..., ``f`` - integer or half integer |
| 351 | 333 | |
| 352 | | - ``prec`` - precision, default: None. Providing a precision can |
| | 334 | - ``prec`` - precision, default: ``None``. Providing a precision can |
| 353 | 335 | drastically speed up the calculation. |
| 354 | 336 | |
| 355 | 337 | OUTPUT: |
| 356 | 338 | |
| 357 | | rational number times the square root of a rational number (if prec=None), or |
| 358 | | real number if a precision is given |
| | 339 | Rational number times the square root of a rational number |
| | 340 | (if ``prec=None``), or real number if a precision is given. |
| 359 | 341 | |
| 360 | 342 | EXAMPLES:: |
| 361 | 343 | |
| 362 | 344 | sage: racah(3,3,3,3,3,3) |
| 363 | 345 | -1/14 |
| 364 | | |
| | 346 | |
| 365 | 347 | NOTES: |
| 366 | 348 | |
| 367 | 349 | The Racah symbol is related to the Wigner 6j symbol: |
| … |
… |
|
| 376 | 358 | |
| 377 | 359 | ALGORITHM: |
| 378 | 360 | |
| 379 | | This function uses the algorithm of [Edmonds74] to calculate the |
| | 361 | This function uses the algorithm of [Edmonds74]_ to calculate the |
| 380 | 362 | value of the 6j symbol exactly. Note that the formula contains |
| 381 | 363 | alternating sums over large factorials and is therefore unsuitable |
| 382 | 364 | for finite precision arithmetic and only useful for a computer |
| 383 | | algebra system [Rasch03]. |
| 384 | | |
| 385 | | REFERENCES: |
| 386 | | |
| 387 | | - [Edmonds74] 'Angular Momentum in Quantum Mechanics', |
| 388 | | A. R. Edmonds, Princeton University Press (1974) |
| 389 | | |
| 390 | | - [Rasch03] 'Efficient Storage Scheme for Pre-calculated Wigner 3j, |
| 391 | | 6j and Gaunt Coefficients', J. Rasch and A. C. H. Yu, SIAM |
| 392 | | J. Sci. Comput. Volume 25, Issue 4, pp. 1416-1428 (2003) |
| | 365 | algebra system [Rasch03]_. |
| 393 | 366 | |
| 394 | 367 | AUTHORS: |
| 395 | 368 | |
| … |
… |
|
| 418 | 391 | _Factlist[int(aa + dd + ee + ff - kk)] * \ |
| 419 | 392 | _Factlist[int(bb + cc + ee + ff - kk)] |
| 420 | 393 | sumres = sumres + Integer((-1) ** kk * _Factlist[kk + 1]) / den |
| 421 | | |
| 422 | | res = prefac * sumres * (-1) ** (int(aa + bb + cc + dd)) |
| | 394 | |
| | 395 | res = prefac * sumres * (-1) ** int(aa + bb + cc + dd) |
| 423 | 396 | return res |
| 424 | 397 | |
| 425 | 398 | |
| … |
… |
|
| 431 | 404 | |
| 432 | 405 | - ``j_1``, ..., ``j_6`` - integer or half integer |
| 433 | 406 | |
| 434 | | - ``prec`` - precision, default: None. Providing a precision can |
| | 407 | - ``prec`` - precision, default: ``None``. Providing a precision can |
| 435 | 408 | drastically speed up the calculation. |
| 436 | 409 | |
| 437 | 410 | OUTPUT: |
| 438 | 411 | |
| 439 | | rational number times the square root of a rational number (if prec=None), or |
| 440 | | real number if a precision is given |
| | 412 | Rational number times the square root of a rational number |
| | 413 | (if ``prec=None``), or real number if a precision is given. |
| 441 | 414 | |
| 442 | 415 | EXAMPLES:: |
| 443 | 416 | |
| 444 | 417 | sage: wigner_6j(3,3,3,3,3,3) |
| 445 | 418 | -1/14 |
| 446 | | |
| 447 | 419 | sage: wigner_6j(5,5,5,5,5,5) |
| 448 | 420 | 1/52 |
| 449 | | |
| 450 | 421 | sage: wigner_6j(6,6,6,6,6,6) |
| 451 | 422 | 309/10868 |
| 452 | | |
| 453 | 423 | sage: wigner_6j(8,8,8,8,8,8) |
| 454 | 424 | -12219/965770 |
| 455 | | |
| 456 | 425 | sage: wigner_6j(30,30,30,30,30,30) |
| 457 | 426 | 36082186869033479581/87954851694828981714124 |
| 458 | | |
| 459 | 427 | sage: wigner_6j(0.5,0.5,1,0.5,0.5,1) |
| 460 | 428 | 1/6 |
| 461 | | |
| 462 | 429 | sage: wigner_6j(200,200,200,200,200,200, prec=1000)*1.0 |
| 463 | 430 | 0.000155903212413242 |
| 464 | 431 | |
| 465 | 432 | It is an error to have arguments that are not integer or half |
| 466 | | integer values or do not fulfil the triangle relation:: |
| | 433 | integer values or do not fulfill the triangle relation:: |
| 467 | 434 | |
| 468 | 435 | sage: wigner_6j(2.5,2.5,2.5,2.5,2.5,2.5) |
| 469 | 436 | Traceback (most recent call last): |
| 470 | 437 | ... |
| 471 | | ValueError: j values must be integer or half integer and fulfil the triangle relation |
| 472 | | |
| | 438 | ValueError: j values must be integer or half integer and fulfill the triangle relation |
| 473 | 439 | sage: wigner_6j(0.5,0.5,1.1,0.5,0.5,1.1) |
| 474 | 440 | Traceback (most recent call last): |
| 475 | 441 | ... |
| 476 | | ValueError: j values must be integer or half integer and fulfil the triangle relation |
| | 442 | ValueError: j values must be integer or half integer and fulfill the triangle relation |
| 477 | 443 | |
| 478 | 444 | NOTES: |
| 479 | 445 | |
| … |
… |
|
| 487 | 453 | |
| 488 | 454 | The Wigner 6j symbol obeys the following symmetry rules: |
| 489 | 455 | |
| 490 | | - Wigner $6j$ symbols are left invariant under any permutation of |
| | 456 | - Wigner 6j symbols are left invariant under any permutation of |
| 491 | 457 | the columns: |
| 492 | 458 | |
| 493 | 459 | .. math:: |
| … |
… |
|
| 500 | 466 | =Wigner6j(j_2,j_1,j_3,j_5,j_4,j_6) |
| 501 | 467 | |
| 502 | 468 | - They are invariant under the exchange of the upper and lower |
| 503 | | arguments in each of any two columns, i. e. |
| | 469 | arguments in each of any two columns, i.e. |
| 504 | 470 | |
| 505 | 471 | .. math:: |
| 506 | 472 | |
| … |
… |
|
| 508 | 474 | =Wigner6j(j_1,j_5,j_6,j_4,j_2,j_3) |
| 509 | 475 | =Wigner6j(j_4,j_2,j_6,j_1,j_5,j_3) |
| 510 | 476 | =Wigner6j(j_4,j_5,j_3,j_1,j_2,j_6) |
| 511 | | |
| 512 | | - additional 6 symmetries [Regge59] giving rise to 144 symmetries |
| | 477 | |
| | 478 | - additional 6 symmetries [Regge59]_ giving rise to 144 symmetries |
| 513 | 479 | in total |
| 514 | 480 | |
| 515 | | - only non-zero if any triple of `j`'s fulfil a triangle relation |
| | 481 | - only non-zero if any triple of `j`'s fulfill a triangle relation |
| 516 | 482 | |
| 517 | 483 | ALGORITHM: |
| 518 | 484 | |
| 519 | | This function uses the algorithm of [Edmonds74] to calculate the |
| | 485 | This function uses the algorithm of [Edmonds74]_ to calculate the |
| 520 | 486 | value of the 6j symbol exactly. Note that the formula contains |
| 521 | 487 | alternating sums over large factorials and is therefore unsuitable |
| 522 | 488 | for finite precision arithmetic and only useful for a computer |
| 523 | | algebra system [Rasch03]. |
| | 489 | algebra system [Rasch03]_. |
| 524 | 490 | |
| 525 | 491 | REFERENCES: |
| 526 | 492 | |
| 527 | | - [Regge59] 'Symmetry Properties of Racah Coefficients', |
| | 493 | .. [Regge59] 'Symmetry Properties of Racah Coefficients', |
| 528 | 494 | T. Regge, Nuovo Cimento, Volume 11, pp. 116 (1959) |
| 529 | | |
| 530 | | - [Edmonds74] 'Angular Momentum in Quantum Mechanics', |
| 531 | | A. R. Edmonds, Princeton University Press (1974) |
| 532 | | |
| 533 | | - [Rasch03] 'Efficient Storage Scheme for Pre-calculated Wigner 3j, |
| 534 | | 6j and Gaunt Coefficients', J. Rasch and A. C. H. Yu, SIAM |
| 535 | | J. Sci. Comput. Volume 25, Issue 4, pp. 1416-1428 (2003) |
| 536 | 495 | """ |
| 537 | | res = (-1) ** (int(j_1 + j_2 + j_4 + j_5)) * \ |
| | 496 | res = (-1) ** int(j_1 + j_2 + j_4 + j_5) * \ |
| 538 | 497 | racah(j_1, j_2, j_5, j_4, j_3, j_6, prec) |
| 539 | 498 | return res |
| 540 | 499 | |
| … |
… |
|
| 548 | 507 | |
| 549 | 508 | - ``j_1``, ..., ``j_9`` - integer or half integer |
| 550 | 509 | |
| 551 | | - ``prec`` - precision, default: None. Providing a precision can |
| | 510 | - ``prec`` - precision, default: ``None``. Providing a precision can |
| 552 | 511 | drastically speed up the calculation. |
| 553 | 512 | |
| 554 | 513 | OUTPUT: |
| 555 | 514 | |
| 556 | | rational number times the square root of a rational number (if prec=None), or |
| 557 | | real number if a precision is given |
| | 515 | Rational number times the square root of a rational number |
| | 516 | (if ``prec=None``), or real number if a precision is given. |
| 558 | 517 | |
| 559 | 518 | EXAMPLES: |
| 560 | 519 | |
| … |
… |
|
| 563 | 522 | |
| 564 | 523 | sage: wigner_9j(1,1,1, 1,1,1, 1,1,0 ,prec=64) # ==1/18 |
| 565 | 524 | 0.0555555555555555555 |
| 566 | | |
| 567 | 525 | sage: wigner_9j(1,1,1, 1,1,1, 1,1,1) |
| 568 | 526 | 0 |
| 569 | | |
| 570 | 527 | sage: wigner_9j(1,1,1, 1,1,1, 1,1,2 ,prec=64) # ==1/18 |
| 571 | 528 | 0.0555555555555555556 |
| 572 | | |
| 573 | 529 | sage: wigner_9j(1,2,1, 2,2,2, 1,2,1 ,prec=64) # ==-1/150 |
| 574 | 530 | -0.00666666666666666667 |
| 575 | | |
| 576 | 531 | sage: wigner_9j(3,3,2, 2,2,2, 3,3,2 ,prec=64) # ==157/14700 |
| 577 | 532 | 0.0106802721088435374 |
| 578 | | |
| 579 | 533 | sage: wigner_9j(3,3,2, 3,3,2, 3,3,2 ,prec=64) # ==3221*sqrt(70)/(246960*sqrt(105)) - 365/(3528*sqrt(70)*sqrt(105)) |
| 580 | 534 | 0.00944247746651111739 |
| 581 | | |
| 582 | 535 | sage: wigner_9j(3,3,1, 3.5,3.5,2, 3.5,3.5,1 ,prec=64) # ==3221*sqrt(70)/(246960*sqrt(105)) - 365/(3528*sqrt(70)*sqrt(105)) |
| 583 | 536 | 0.0110216678544351364 |
| 584 | | |
| 585 | 537 | sage: wigner_9j(100,80,50, 50,100,70, 60,50,100 ,prec=1000)*1.0 |
| 586 | 538 | 1.05597798065761e-7 |
| 587 | | |
| 588 | 539 | sage: wigner_9j(30,30,10, 30.5,30.5,20, 30.5,30.5,10 ,prec=1000)*1.0 # ==(80944680186359968990/95103769817469)*sqrt(1/682288158959699477295) |
| 589 | 540 | 0.0000325841699408828 |
| 590 | | |
| 591 | 541 | sage: wigner_9j(64,62.5,114.5, 61.5,61,112.5, 113.5,110.5,60, prec=1000)*1.0 |
| 592 | 542 | -3.41407910055520e-39 |
| 593 | | |
| 594 | 543 | sage: wigner_9j(15,15,15, 15,3,15, 15,18,10, prec=1000)*1.0 |
| 595 | 544 | -0.0000778324615309539 |
| 596 | | |
| 597 | 545 | sage: wigner_9j(1.5,1,1.5, 1,1,1, 1.5,1,1.5) |
| 598 | 546 | 0 |
| 599 | 547 | |
| 600 | 548 | It is an error to have arguments that are not integer or half |
| 601 | | integer values or do not fulfil the triangle relation:: |
| | 549 | integer values or do not fulfill the triangle relation:: |
| 602 | 550 | |
| 603 | 551 | sage: wigner_9j(0.5,0.5,0.5, 0.5,0.5,0.5, 0.5,0.5,0.5,prec=64) |
| 604 | 552 | Traceback (most recent call last): |
| 605 | 553 | ... |
| 606 | | ValueError: j values must be integer or half integer and fulfil the triangle relation |
| 607 | | |
| | 554 | ValueError: j values must be integer or half integer and fulfill the triangle relation |
| 608 | 555 | sage: wigner_9j(1,1,1, 0.5,1,1.5, 0.5,1,2.5,prec=64) |
| 609 | 556 | Traceback (most recent call last): |
| 610 | 557 | ... |
| 611 | | ValueError: j values must be integer or half integer and fulfil the triangle relation |
| | 558 | ValueError: j values must be integer or half integer and fulfill the triangle relation |
| 612 | 559 | |
| 613 | 560 | ALGORITHM: |
| 614 | 561 | |
| 615 | | This function uses the algorithm of [Edmonds74] to calculate the |
| | 562 | This function uses the algorithm of [Edmonds74]_ to calculate the |
| 616 | 563 | value of the 3j symbol exactly. Note that the formula contains |
| 617 | 564 | alternating sums over large factorials and is therefore unsuitable |
| 618 | 565 | for finite precision arithmetic and only useful for a computer |
| 619 | | algebra system [Rasch03]. |
| 620 | | |
| 621 | | REFERENCES: |
| 622 | | |
| 623 | | - [Edmonds74] 'Angular Momentum in Quantum Mechanics', |
| 624 | | A. R. Edmonds, Princeton University Press (1974) |
| 625 | | |
| 626 | | - [Rasch03] 'Efficient Storage Scheme for Pre-calculated Wigner 3j, |
| 627 | | 6j and Gaunt Coefficients', J. Rasch and A. C. H. Yu, SIAM |
| 628 | | J. Sci. Comput. Volume 25, Issue 4, pp. 1416-1428 (2003) |
| | 566 | algebra system [Rasch03]_. |
| 629 | 567 | """ |
| 630 | 568 | imin = 0 |
| 631 | 569 | imax = min(j_1 + j_9, j_2 + j_6, j_4 + j_8) |
| … |
… |
|
| 644 | 582 | Calculate the Gaunt coefficient. |
| 645 | 583 | |
| 646 | 584 | The Gaunt coefficient is defined as the integral over three |
| 647 | | spherical harmonics: |
| | 585 | spherical harmonics: |
| 648 | 586 | |
| 649 | 587 | .. math:: |
| 650 | 588 | |
| 651 | 589 | Y(j_1,j_2,j_3,m_1,m_2,m_3) |
| 652 | 590 | =\int Y_{l_1,m_1}(\Omega) |
| 653 | | Y_{l_2,m_2}(\Omega) Y_{l_3,m_3}(\Omega) d\Omega |
| | 591 | Y_{l_2,m_2}(\Omega) Y_{l_3,m_3}(\Omega) d\Omega |
| 654 | 592 | =\sqrt{(2l_1+1)(2l_2+1)(2l_3+1)/(4\pi)} |
| 655 | 593 | \; Y(j_1,j_2,j_3,0,0,0) \; Y(j_1,j_2,j_3,m_1,m_2,m_3) |
| 656 | 594 | |
| … |
… |
|
| 658 | 596 | |
| 659 | 597 | - ``l_1``, ``l_2``, ``l_3``, ``m_1``, ``m_2``, ``m_3`` - integer |
| 660 | 598 | |
| 661 | | - ``prec`` - precision, default: None. Providing a precision can |
| | 599 | - ``prec`` - precision, default: ``None``. Providing a precision can |
| 662 | 600 | drastically speed up the calculation. |
| 663 | 601 | |
| 664 | 602 | OUTPUT: |
| 665 | 603 | |
| 666 | | rational number times the square root of a rational number (if prec=None), or |
| 667 | | real number if a precision is given |
| | 604 | Rational number times the square root of a rational number |
| | 605 | (if ``prec=None``), or real number if a precision is given. |
| 668 | 606 | |
| 669 | 607 | EXAMPLES:: |
| 670 | 608 | |
| 671 | 609 | sage: gaunt(1,0,1,1,0,-1) |
| 672 | 610 | -1/2/sqrt(pi) |
| 673 | | |
| 674 | 611 | sage: gaunt(1,0,1,1,0,0) |
| 675 | 612 | 0 |
| 676 | | |
| 677 | 613 | sage: gaunt(29,29,34,10,-5,-5) |
| 678 | 614 | 1821867940156/215552371055153321*sqrt(22134)/sqrt(pi) |
| 679 | | |
| 680 | 615 | sage: gaunt(20,20,40,1,-1,0) |
| 681 | 616 | 28384503878959800/74029560764440771/sqrt(pi) |
| 682 | | |
| 683 | 617 | sage: gaunt(12,15,5,2,3,-5) |
| 684 | 618 | 91/124062*sqrt(36890)/sqrt(pi) |
| 685 | | |
| 686 | 619 | sage: gaunt(10,10,12,9,3,-12) |
| 687 | 620 | -98/62031*sqrt(6279)/sqrt(pi) |
| 688 | | |
| 689 | 621 | sage: gaunt(1000,1000,1200,9,3,-12).n(64) |
| 690 | 622 | 0.00689500421922113448 |
| 691 | 623 | |
| … |
… |
|
| 695 | 627 | Traceback (most recent call last): |
| 696 | 628 | ... |
| 697 | 629 | ValueError: l values must be integer |
| 698 | | |
| 699 | 630 | sage: gaunt(1,0,1,1.1,0,-1.1) |
| 700 | 631 | Traceback (most recent call last): |
| 701 | 632 | ... |
| … |
… |
|
| 714 | 645 | =Y(j_3,j_2,j_1,m_3,m_2,m_1) |
| 715 | 646 | =Y(j_1,j_3,j_2,m_1,m_3,m_2) |
| 716 | 647 | =Y(j_2,j_1,j_3,m_2,m_1,m_3) |
| 717 | | |
| | 648 | |
| 718 | 649 | - invariant under space inflection, i.e. |
| 719 | 650 | |
| 720 | 651 | .. math:: |
| 721 | 652 | Y(j_1,j_2,j_3,m_1,m_2,m_3) |
| 722 | 653 | =Y(j_1,j_2,j_3,-m_1,-m_2,-m_3) |
| 723 | | |
| | 654 | |
| 724 | 655 | - symmetric with respect to the 72 Regge symmetries as inherited |
| 725 | | for the `3j` symbols [Regge58] |
| 726 | | |
| | 656 | for the `3j` symbols [Regge58]_ |
| | 657 | |
| 727 | 658 | - zero for `l_1`, `l_2`, `l_3` not fulfilling triangle relation |
| 728 | | |
| 729 | | - zero for violating any one of the conditions: `l_1\ge|m_1|`, |
| 730 | | `l_2\ge|m_2|`, `l_3\ge|m_3|` |
| 731 | | |
| 732 | | - non-zero only for an even sum of the `l_i`, i. e. |
| | 659 | |
| | 660 | - zero for violating any one of the conditions: `l_1 \ge |m_1|`, |
| | 661 | `l_2 \ge |m_2|`, `l_3 \ge |m_3|` |
| | 662 | |
| | 663 | - non-zero only for an even sum of the `l_i`, i.e. |
| 733 | 664 | `J=l_1+l_2+l_3=2n` for `n` in `\Bold{N}` |
| 734 | 665 | |
| 735 | 666 | ALGORITHM: |
| 736 | 667 | |
| 737 | | This function uses the algorithm of [Liberatodebrito82] to |
| | 668 | This function uses the algorithm of [Liberatodebrito82]_ to |
| 738 | 669 | calculate the value of the Gaunt coefficient exactly. Note that |
| 739 | 670 | the formula contains alternating sums over large factorials and is |
| 740 | 671 | therefore unsuitable for finite precision arithmetic and only |
| 741 | | useful for a computer algebra system [Rasch03]. |
| | 672 | useful for a computer algebra system [Rasch03]_. |
| 742 | 673 | |
| 743 | 674 | REFERENCES: |
| 744 | 675 | |
| 745 | | - [Regge58] 'Symmetry Properties of Clebsch-Gordan Coefficients', |
| 746 | | T. Regge, Nuovo Cimento, Volume 10, pp. 544 (1958) |
| 747 | | |
| 748 | | - [Liberatodebrito82] 'FORTRAN program for the integral of three |
| | 676 | .. [Liberatodebrito82] 'FORTRAN program for the integral of three |
| 749 | 677 | spherical harmonics', A. Liberato de Brito, |
| 750 | 678 | Comput. Phys. Commun., Volume 25, pp. 81-85 (1982) |
| 751 | 679 | |
| 752 | | - [Rasch03] 'Efficient Storage Scheme for Pre-calculated Wigner 3j, |
| 753 | | 6j and Gaunt Coefficients', J. Rasch and A. C. H. Yu, SIAM |
| 754 | | J. Sci. Comput. Volume 25, Issue 4, pp. 1416-1428 (2003) |
| 755 | | |
| 756 | 680 | AUTHORS: |
| 757 | 681 | |
| 758 | 682 | - Jens Rasch (2009-03-24): initial version for Sage |
| … |
… |
|
| 761 | 685 | raise ValueError("l values must be integer") |
| 762 | 686 | if int(m_1) != m_1 or int(m_2) != m_2 or int(m_3) != m_3: |
| 763 | 687 | raise ValueError("m values must be integer") |
| 764 | | |
| | 688 | |
| 765 | 689 | bigL = (l_1 + l_2 + l_3) / 2 |
| 766 | 690 | a1 = l_1 + l_2 - l_3 |
| 767 | | if (a1 < 0): |
| | 691 | if a1 < 0: |
| 768 | 692 | return 0 |
| 769 | 693 | a2 = l_1 - l_2 + l_3 |
| 770 | | if (a2 < 0): |
| | 694 | if a2 < 0: |
| 771 | 695 | return 0 |
| 772 | 696 | a3 = -l_1 + l_2 + l_3 |
| 773 | | if (a3 < 0): |
| | 697 | if a3 < 0: |
| 774 | 698 | return 0 |
| 775 | | if Mod(2 * bigL, 2) <> 0: |
| | 699 | if Mod(2 * bigL, 2) != 0: |
| 776 | 700 | return 0 |
| 777 | | if (m_1 + m_2 + m_3) <> 0: |
| | 701 | if (m_1 + m_2 + m_3) != 0: |
| 778 | 702 | return 0 |
| 779 | 703 | if (abs(m_1) > l_1) or (abs(m_2) > l_2) or (abs(m_3) > l_3): |
| 780 | 704 | return 0 |
| … |
… |
|
| 792 | 716 | ressqrt = argsqrt.sqrt() |
| 793 | 717 | |
| 794 | 718 | prefac = Integer(_Factlist[bigL] * _Factlist[l_2 - l_1 + l_3] * \ |
| 795 | | _Factlist[l_1 - l_2 + l_3] * _Factlist[l_1 + l_2 - l_3])/ \ |
| 796 | | _Factlist[2 * bigL+1]/ \ |
| 797 | | (_Factlist[bigL - l_1] * _Factlist[bigL - l_2] * _Factlist[bigL - l_3]) |
| 798 | | |
| | 719 | _Factlist[l_1 - l_2 + l_3] * _Factlist[l_1 + l_2 - l_3])/ \ |
| | 720 | _Factlist[2 * bigL+1]/ \ |
| | 721 | (_Factlist[bigL - l_1] * _Factlist[bigL - l_2] * _Factlist[bigL - l_3]) |
| | 722 | |
| 799 | 723 | sumres = 0 |
| 800 | 724 | for ii in range(imin, imax + 1): |
| 801 | 725 | den = _Factlist[ii] * _Factlist[ii + l_3 - l_1 - m_2] * \ |
| … |
… |
|
| 807 | 731 | if prec != None: |
| 808 | 732 | res = res.n(prec) |
| 809 | 733 | return res |
| 810 | | |