Ticket #5996: trac_5996-reviewer.patch

File trac_5996-reviewer.patch, 24.2 KB (added by mvngu, 8 months ago)

reviewer patch

  • sage/functions/wigner.py

    # 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  
    44Collection of functions for calculating Wigner 3j, 6j, 9j, 
    55Clebsch-Gordan, Racah as well as Gaunt coefficients exactly, all 
    66evaluating to a rational number times the square root of a rational 
    7 number [Rasch03]. 
     7number [Rasch03]_. 
    88 
    99Please see the description of the individual functions for further 
    1010details and examples. 
    1111 
    1212REFERENCES: 
    1313 
    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 
    1515  Pre-calculated Wigner 3j, 6j and Gaunt Coefficients', SIAM 
    1616  J. Sci. Comput. Volume 25, Issue 4, pp. 1416-1428 (2003) 
    1717 
     
    2929#                  http://www.gnu.org/licenses/ 
    3030#*********************************************************************** 
    3131 
     32from sage.rings.complex_number import ComplexNumber 
     33from sage.rings.integer import Integer 
     34from sage.rings.integer_mod import Mod 
    3235from 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 
    3636 
    3737# This list of precomputed factorials is needed to massively 
    3838# accelerate future calculations of the various coefficients 
     
    7474 
    7575    -  ``j_1``, ``j_2``, ``j_3``, ``m_1``, ``m_2``, ``m_3`` - integer or half integer 
    7676 
    77     -  ``prec`` - precision, default: None. Providing a precision can 
     77    -  ``prec`` - precision, default: ``None``. Providing a precision can 
    7878       drastically speed up the calculation. 
    7979 
    8080    OUTPUT: 
    8181 
    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. 
    8484 
    8585    EXAMPLES:: 
    8686 
    8787        sage: wigner_3j(2, 6, 4, 0, 0, 0) 
    8888        sqrt(5/143) 
    89  
    9089        sage: wigner_3j(2, 6, 4, 0, 0, 1) 
    9190        0 
    92  
    9391        sage: wigner_3j(0.5, 0.5, 1, 0.5, -0.5, 0) 
    9492        sqrt(1/6) 
    95  
    9693        sage: wigner_3j(40, 100, 60, -10, 60, -50) 
    9794        95608/18702538494885*sqrt(21082735836735314343364163310/220491455010479533763) 
    98  
    9995        sage: wigner_3j(2500, 2500, 5000, 2488, 2400, -4888, prec=64) 
    10096        7.60424456883448589e-12 
    10197 
     
    106102        Traceback (most recent call last): 
    107103        ... 
    108104        ValueError: j values must be integer or half integer 
    109  
    110105        sage: wigner_3j(2, 6, 4, 1, 0, -1.1) 
    111106        Traceback (most recent call last): 
    112107        ... 
     
    127122          =(-1)^J Wigner3j(j_3,j_2,j_1,m_3,m_2,m_1) 
    128123          =(-1)^J Wigner3j(j_1,j_3,j_2,m_1,m_3,m_2) 
    129124          =(-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. 
    132127 
    133128      .. math:: 
    134129 
    135130         Wigner3j(j_1,j_2,j_3,m_1,m_2,m_3) 
    136131         =(-1)^J Wigner3j(j_1,j_2,j_3,-m_1,-m_2,-m_3) 
    137    
     132 
    138133    - symmetric with respect to the 72 additional symmetries based on 
    139       the work by [Regge58] 
     134      the work by [Regge58]_ 
    140135 
    141136    - 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` 
    144139 
    145140    - 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|` 
    147142 
    148143    ALGORITHM: 
    149144 
    150     This function uses the algorithm of [Edmonds74] to calculate the 
     145    This function uses the algorithm of [Edmonds74]_ to calculate the 
    151146    value of the 3j symbol exactly. Note that the formula contains 
    152147    alternating sums over large factorials and is therefore unsuitable 
    153148    for finite precision arithmetic and only useful for a computer 
    154     algebra system [Rasch03]. 
     149    algebra system [Rasch03]_. 
    155150 
    156151    REFERENCES: 
    157152 
    158     - [Regge58] 'Symmetry Properties of Clebsch-Gordan Coefficients', 
     153    .. [Regge58] 'Symmetry Properties of Clebsch-Gordan Coefficients', 
    159154      T. Regge, Nuovo Cimento, Volume 10, pp. 544 (1958) 
    160155 
    161     - [Edmonds74] 'Angular Momentum in Quantum Mechanics', 
     156    .. [Edmonds74] 'Angular Momentum in Quantum Mechanics', 
    162157      A. R. Edmonds, Princeton University Press (1974) 
    163158 
    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  
    168159    AUTHORS: 
    169160 
    170161    - Jens Rasch (2009-03-24): initial version 
     
    175166    if int(m_1 * 2) != m_1 * 2 or int(m_2 * 2) != m_2 * 2 or \ 
    176167            int(m_3 * 2) != m_3 * 2: 
    177168        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: 
    179170        return 0 
    180     prefid = Integer((-1) ** (int(j_1 - j_2 - m_3))) 
     171    prefid = Integer((-1) ** int(j_1 - j_2 - m_3)) 
    181172    m_3 = -m_3 
    182173    a1 = j_1 + j_2 - j_3 
    183     if (a1 < 0): 
     174    if a1 < 0: 
    184175        return 0 
    185176    a2 = j_1 - j_2 + j_3 
    186     if (a2 < 0): 
     177    if a2 < 0: 
    187178        return 0 
    188179    a3 = -j_1 + j_2 + j_3 
    189     if (a3 < 0): 
     180    if a3 < 0: 
    190181        return 0 
    191182    if (abs(m_1) > j_1) or (abs(m_2) > j_2) or (abs(m_3) > j_3): 
    192183        return 0 
    193184 
    194185    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)) 
    196187    _calc_factlist(maxfact) 
    197188 
    198189    argsqrt = Integer(_Factlist[int(j_1 + j_2 - j_3)] * \ 
     
    209200    ressqrt = argsqrt.sqrt(prec) 
    210201    if type(ressqrt) is ComplexNumber: 
    211202        ressqrt = ressqrt.real() 
    212      
     203 
    213204    imin = max(-j_3 + j_1 + m_2, -j_3 + j_2 - m_1, 0) 
    214205    imax = min(j_2 + m_2, j_1 - m_1, j_1 + j_2 - j_3) 
    215206    sumres = 0 
    216     for ii in range(imin, imax + 1):                    
     207    for ii in range(imin, imax + 1): 
    217208        den = _Factlist[ii] * \ 
    218209            _Factlist[int(ii + j_3 - j_1 - m_2)] * \ 
    219210            _Factlist[int(j_2 + m_2 - ii)] * \ 
     
    228219 
    229220def clebsch_gordan(j_1, j_2, j_3, m_1, m_2, m_3, prec=None): 
    230221    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]_. 
    233226 
    234227    INPUT: 
    235228 
    236229    -  ``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 
    239232       drastically speed up the calculation. 
    240233 
    241234    OUTPUT: 
    242235 
    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. 
    245238 
    246239    EXAMPLES:: 
    247240 
    248241        sage: simplify(clebsch_gordan(3/2,1/2,2, 3/2,1/2,2)) 
    249242        1 
    250          
    251243        sage: clebsch_gordan(1.5,0.5,1, 1.5,-0.5,1) 
    252244        1/2*sqrt(3) 
    253  
    254245        sage: clebsch_gordan(3/2,1/2,1, -1/2,1/2,0) 
    255246        -sqrt(1/6)*sqrt(3) 
    256247 
     
    261252 
    262253    .. math:: 
    263254 
    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 
    265256        =(-1)^{j_1-j_2+m_3} \sqrt{2j_3+1} \; 
    266257        Wigner3j(j_1,j_2,j_3,m_1,m_2,-m_3) 
    267258 
    268259    See also the documentation on Wigner 3j symbols which exhibit much 
    269260    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) 
    279261 
    280262    AUTHORS: 
    281263 
    282264    - Jens Rasch (2009-03-24): initial version 
    283265    """ 
    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) * \ 
    285267        wigner_3j(j_1, j_2, j_3, m_1, m_2, -m_3, prec) 
    286268    return res 
    287269 
     
    300282 
    301283    -  ``cc`` - third angular momentum, integer or half integer 
    302284 
    303     -  ``prec`` - precision of the sqrt() calculation  
     285    -  ``prec`` - precision of the ``sqrt()`` calculation 
    304286 
    305287    OUTPUT: 
    306288 
     
    312294        sage: _big_delta_coeff(1,1,1) 
    313295        1/2*sqrt(1/6) 
    314296    """ 
    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") 
    321303    if (aa + bb - cc) < 0: 
    322304        return 0 
    323305    if (aa + cc - bb) < 0: 
    324306        return 0 
    325307    if (bb + cc - aa) < 0: 
    326308        return 0 
    327    
     309 
    328310    maxfact = max(aa + bb - cc, aa + cc - bb, bb + cc - aa, aa + bb + cc + 1) 
    329311    _calc_factlist(maxfact) 
    330312 
     
    349331 
    350332    -  ``a``, ..., ``f`` - integer or half integer 
    351333 
    352     -  ``prec`` - precision, default: None. Providing a precision can 
     334    -  ``prec`` - precision, default: ``None``. Providing a precision can 
    353335       drastically speed up the calculation. 
    354336 
    355337    OUTPUT: 
    356338 
    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. 
    359341 
    360342    EXAMPLES:: 
    361343 
    362344        sage: racah(3,3,3,3,3,3) 
    363345        -1/14 
    364      
     346 
    365347    NOTES: 
    366348 
    367349    The Racah symbol is related to the Wigner 6j symbol: 
     
    376358 
    377359    ALGORITHM: 
    378360 
    379     This function uses the algorithm of [Edmonds74] to calculate the 
     361    This function uses the algorithm of [Edmonds74]_ to calculate the 
    380362    value of the 6j symbol exactly. Note that the formula contains 
    381363    alternating sums over large factorials and is therefore unsuitable 
    382364    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]_. 
    393366 
    394367    AUTHORS: 
    395368 
     
    418391            _Factlist[int(aa + dd + ee + ff - kk)] * \ 
    419392            _Factlist[int(bb + cc + ee + ff - kk)] 
    420393        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) 
    423396    return res 
    424397 
    425398 
     
    431404 
    432405    -  ``j_1``, ..., ``j_6`` - integer or half integer 
    433406 
    434     -  ``prec`` - precision, default: None. Providing a precision can 
     407    -  ``prec`` - precision, default: ``None``. Providing a precision can 
    435408       drastically speed up the calculation. 
    436409 
    437410    OUTPUT: 
    438411 
    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. 
    441414 
    442415    EXAMPLES:: 
    443416 
    444417        sage: wigner_6j(3,3,3,3,3,3) 
    445418        -1/14 
    446      
    447419        sage: wigner_6j(5,5,5,5,5,5) 
    448420        1/52 
    449  
    450421        sage: wigner_6j(6,6,6,6,6,6) 
    451422        309/10868 
    452          
    453423        sage: wigner_6j(8,8,8,8,8,8) 
    454424        -12219/965770 
    455  
    456425        sage: wigner_6j(30,30,30,30,30,30) 
    457426        36082186869033479581/87954851694828981714124 
    458          
    459427        sage: wigner_6j(0.5,0.5,1,0.5,0.5,1) 
    460428        1/6 
    461  
    462429        sage: wigner_6j(200,200,200,200,200,200, prec=1000)*1.0 
    463430        0.000155903212413242 
    464431 
    465432    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:: 
    467434 
    468435        sage: wigner_6j(2.5,2.5,2.5,2.5,2.5,2.5) 
    469436        Traceback (most recent call last): 
    470437        ... 
    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 
    473439        sage: wigner_6j(0.5,0.5,1.1,0.5,0.5,1.1) 
    474440        Traceback (most recent call last): 
    475441        ... 
    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 
    477443 
    478444    NOTES: 
    479445 
     
    487453 
    488454    The Wigner 6j symbol obeys the following symmetry rules: 
    489455 
    490     - Wigner $6j$ symbols are left invariant under any permutation of 
     456    - Wigner 6j symbols are left invariant under any permutation of 
    491457      the columns: 
    492458 
    493459      .. math:: 
     
    500466          =Wigner6j(j_2,j_1,j_3,j_5,j_4,j_6) 
    501467 
    502468    - 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. 
    504470 
    505471      .. math:: 
    506472 
     
    508474          =Wigner6j(j_1,j_5,j_6,j_4,j_2,j_3) 
    509475          =Wigner6j(j_4,j_2,j_6,j_1,j_5,j_3) 
    510476          =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 
    513479      in total 
    514480 
    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 
    516482 
    517483    ALGORITHM: 
    518484 
    519     This function uses the algorithm of [Edmonds74] to calculate the 
     485    This function uses the algorithm of [Edmonds74]_ to calculate the 
    520486    value of the 6j symbol exactly. Note that the formula contains 
    521487    alternating sums over large factorials and is therefore unsuitable 
    522488    for finite precision arithmetic and only useful for a computer 
    523     algebra system [Rasch03]. 
     489    algebra system [Rasch03]_. 
    524490 
    525491    REFERENCES: 
    526492 
    527     - [Regge59] 'Symmetry Properties of Racah Coefficients', 
     493    .. [Regge59] 'Symmetry Properties of Racah Coefficients', 
    528494      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) 
    536495    """ 
    537     res = (-1) ** (int(j_1 + j_2 + j_4 + j_5)) * \ 
     496    res = (-1) ** int(j_1 + j_2 + j_4 + j_5) * \ 
    538497        racah(j_1, j_2, j_5, j_4, j_3, j_6, prec) 
    539498    return res 
    540499 
     
    548507 
    549508    -  ``j_1``, ..., ``j_9`` - integer or half integer 
    550509 
    551     -  ``prec`` - precision, default: None. Providing a precision can 
     510    -  ``prec`` - precision, default: ``None``. Providing a precision can 
    552511       drastically speed up the calculation. 
    553512 
    554513    OUTPUT: 
    555514 
    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. 
    558517 
    559518    EXAMPLES: 
    560519 
     
    563522 
    564523        sage: wigner_9j(1,1,1, 1,1,1, 1,1,0 ,prec=64) # ==1/18 
    565524        0.0555555555555555555 
    566  
    567525        sage: wigner_9j(1,1,1, 1,1,1, 1,1,1) 
    568526        0 
    569  
    570527        sage: wigner_9j(1,1,1, 1,1,1, 1,1,2 ,prec=64) # ==1/18 
    571528        0.0555555555555555556 
    572  
    573529        sage: wigner_9j(1,2,1, 2,2,2, 1,2,1 ,prec=64) # ==-1/150 
    574530        -0.00666666666666666667 
    575  
    576531        sage: wigner_9j(3,3,2, 2,2,2, 3,3,2 ,prec=64) # ==157/14700 
    577532        0.0106802721088435374 
    578  
    579533        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)) 
    580534        0.00944247746651111739 
    581  
    582535        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)) 
    583536        0.0110216678544351364 
    584  
    585537        sage: wigner_9j(100,80,50, 50,100,70, 60,50,100 ,prec=1000)*1.0 
    586538        1.05597798065761e-7 
    587  
    588539        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) 
    589540        0.0000325841699408828 
    590  
    591541        sage: wigner_9j(64,62.5,114.5, 61.5,61,112.5, 113.5,110.5,60, prec=1000)*1.0 
    592542        -3.41407910055520e-39 
    593  
    594543        sage: wigner_9j(15,15,15, 15,3,15, 15,18,10, prec=1000)*1.0 
    595544        -0.0000778324615309539 
    596  
    597545        sage: wigner_9j(1.5,1,1.5, 1,1,1, 1.5,1,1.5) 
    598546        0 
    599547 
    600548    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:: 
    602550 
    603551        sage: wigner_9j(0.5,0.5,0.5, 0.5,0.5,0.5, 0.5,0.5,0.5,prec=64) 
    604552        Traceback (most recent call last): 
    605553        ... 
    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 
    608555        sage: wigner_9j(1,1,1, 0.5,1,1.5, 0.5,1,2.5,prec=64) 
    609556        Traceback (most recent call last): 
    610557        ... 
    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 
    612559 
    613560    ALGORITHM: 
    614561 
    615     This function uses the algorithm of [Edmonds74] to calculate the 
     562    This function uses the algorithm of [Edmonds74]_ to calculate the 
    616563    value of the 3j symbol exactly. Note that the formula contains 
    617564    alternating sums over large factorials and is therefore unsuitable 
    618565    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]_. 
    629567    """ 
    630568    imin = 0 
    631569    imax = min(j_1 + j_9, j_2 + j_6, j_4 + j_8) 
     
    644582    Calculate the Gaunt coefficient. 
    645583 
    646584    The Gaunt coefficient is defined as the integral over three 
    647     spherical harmonics:  
     585    spherical harmonics: 
    648586 
    649587    .. math:: 
    650588 
    651589        Y(j_1,j_2,j_3,m_1,m_2,m_3) 
    652590        =\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 
    654592        =\sqrt{(2l_1+1)(2l_2+1)(2l_3+1)/(4\pi)} 
    655593         \; Y(j_1,j_2,j_3,0,0,0) \; Y(j_1,j_2,j_3,m_1,m_2,m_3) 
    656594 
     
    658596 
    659597    -  ``l_1``, ``l_2``, ``l_3``, ``m_1``, ``m_2``, ``m_3`` - integer 
    660598 
    661     -  ``prec`` - precision, default: None. Providing a precision can 
     599    -  ``prec`` - precision, default: ``None``. Providing a precision can 
    662600       drastically speed up the calculation. 
    663601 
    664602    OUTPUT: 
    665603 
    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. 
    668606 
    669607    EXAMPLES:: 
    670608 
    671609        sage: gaunt(1,0,1,1,0,-1) 
    672610        -1/2/sqrt(pi) 
    673  
    674611        sage: gaunt(1,0,1,1,0,0) 
    675612        0 
    676  
    677613        sage: gaunt(29,29,34,10,-5,-5) 
    678614        1821867940156/215552371055153321*sqrt(22134)/sqrt(pi) 
    679  
    680615        sage: gaunt(20,20,40,1,-1,0) 
    681616        28384503878959800/74029560764440771/sqrt(pi) 
    682  
    683617        sage: gaunt(12,15,5,2,3,-5) 
    684618        91/124062*sqrt(36890)/sqrt(pi) 
    685  
    686619        sage: gaunt(10,10,12,9,3,-12) 
    687620        -98/62031*sqrt(6279)/sqrt(pi) 
    688  
    689621        sage: gaunt(1000,1000,1200,9,3,-12).n(64) 
    690622        0.00689500421922113448 
    691623 
     
    695627        Traceback (most recent call last): 
    696628        ... 
    697629        ValueError: l values must be integer 
    698  
    699630        sage: gaunt(1,0,1,1.1,0,-1.1) 
    700631        Traceback (most recent call last): 
    701632        ... 
     
    714645          =Y(j_3,j_2,j_1,m_3,m_2,m_1) 
    715646          =Y(j_1,j_3,j_2,m_1,m_3,m_2) 
    716647          =Y(j_2,j_1,j_3,m_2,m_1,m_3) 
    717        
     648 
    718649    - invariant under space inflection, i.e. 
    719650 
    720651      .. math:: 
    721652          Y(j_1,j_2,j_3,m_1,m_2,m_3) 
    722653          =Y(j_1,j_2,j_3,-m_1,-m_2,-m_3) 
    723        
     654 
    724655    - symmetric with respect to the 72 Regge symmetries as inherited 
    725       for the `3j` symbols [Regge58] 
    726    
     656      for the `3j` symbols [Regge58]_ 
     657 
    727658    - 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. 
    733664      `J=l_1+l_2+l_3=2n` for `n` in `\Bold{N}` 
    734665 
    735666    ALGORITHM: 
    736667 
    737     This function uses the algorithm of [Liberatodebrito82] to 
     668    This function uses the algorithm of [Liberatodebrito82]_ to 
    738669    calculate the value of the Gaunt coefficient exactly. Note that 
    739670    the formula contains alternating sums over large factorials and is 
    740671    therefore unsuitable for finite precision arithmetic and only 
    741     useful for a computer algebra system [Rasch03]. 
     672    useful for a computer algebra system [Rasch03]_. 
    742673 
    743674    REFERENCES: 
    744675 
    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 
    749677      spherical harmonics', A. Liberato de Brito, 
    750678      Comput. Phys. Commun., Volume 25, pp. 81-85 (1982) 
    751679 
    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  
    756680    AUTHORS: 
    757681 
    758682    - Jens Rasch (2009-03-24): initial version for Sage 
     
    761685        raise ValueError("l values must be integer") 
    762686    if int(m_1) != m_1 or int(m_2) != m_2 or int(m_3) != m_3: 
    763687        raise ValueError("m values must be integer") 
    764      
     688 
    765689    bigL = (l_1 + l_2 + l_3) / 2 
    766690    a1 = l_1 + l_2 - l_3 
    767     if (a1 < 0): 
     691    if a1 < 0: 
    768692        return 0 
    769693    a2 = l_1 - l_2 + l_3 
    770     if (a2 < 0): 
     694    if a2 < 0: 
    771695        return 0 
    772696    a3 = -l_1 + l_2 + l_3 
    773     if (a3 < 0): 
     697    if a3 < 0: 
    774698        return 0 
    775     if Mod(2 * bigL, 2) <> 0: 
     699    if Mod(2 * bigL, 2) != 0: 
    776700        return 0 
    777     if (m_1 + m_2 + m_3) <> 0: 
     701    if (m_1 + m_2 + m_3) != 0: 
    778702        return 0 
    779703    if (abs(m_1) > l_1) or (abs(m_2) > l_2) or (abs(m_3) > l_3): 
    780704        return 0 
     
    792716    ressqrt = argsqrt.sqrt() 
    793717 
    794718    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 
    799723    sumres = 0 
    800724    for ii in range(imin, imax + 1): 
    801725        den = _Factlist[ii] * _Factlist[ii + l_3 - l_1 - m_2] * \ 
     
    807731    if prec != None: 
    808732        res = res.n(prec) 
    809733    return res 
    810