Changes between Version 2 and Version 7 of Ticket #25034


Ignore:
Timestamp:
06/15/20 23:11:41 (12 months ago)
Author:
slelievre
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #25034

    • Property Cc fredrik.johansson added
    • Property Milestone changed from sage-8.2 to sage-9.2
  • Ticket #25034 – Description

    v2 v7  
    1 I am using the gen_legendre_P function (an instance of Func_assoc_legendre_P
    2 from sage/functions/orthogonal_polys.py) to evaluate associated Legendre
     1I am using the `gen_legendre_P` function (an instance of `Func_assoc_legendre_P`
     2from `sage/functions/orthogonal_polys.py`) to evaluate associated Legendre
    33functions / Ferrers functions in !SageMath 8.1.
    44
    55There appears to be a discrepancy in the results I obtain, depending on whether
    6 I use gen_legendre_P.eval_poly() or directly call gen_legendre_P() in some cases.
    7 I think this is because the _eval_ method first tries to call the _eval_special_values_
    8 method, before using eval_poly.
     6I use `gen_legendre_P.eval_poly()` or directly call `gen_legendre_P()` in some cases.
     7I think this is because the `_eval_` method first tries to call the `_eval_special_values_`
     8method, before using `eval_poly`.
    99
    1010With this input
    11 
    1211{{{
    1312x = SR.var('x')
    14 print gen_legendre_P.eval_poly(1,1,x)
    15 print gen_legendre_P(1,1,x)
    16 print gen_legendre_P.eval_poly(1,1,0.5)
    17 print gen_legendre_P(1,1,0.5)
     13print(gen_legendre_P.eval_poly(1, 1, x))
     14print(gen_legendre_P(1, 1, x))
     15print(gen_legendre_P.eval_poly(1, 1, 0.5))
     16print(gen_legendre_P(1, 1, 0.5))
    1817}}}
    1918
    2019I obtain
    21 
    2220{{{
    2321-sqrt(-x^2 + 1)
     
    2826
    2927The result from eval_poly agrees with Mathematica, i.e.
    30 
    3128{{{
    3229LegendreP[1, 1, 0.5]
     
    3431}}}
    3532
    36 Based on the above output, it seems to me that gen_legendre_P.eval_poly(1,1,cos(theta)) will always be real while gen_legendre_P(1,1,cos(theta)) will be complex (unless |cos(theta)| = 1), since cos(theta) is in the interval [-1,1].
     33Based on the above output, it seems to me that `gen_legendre_P.eval_poly(1, 1, cos(theta))` will always be real while `gen_legendre_P(1, 1, cos(theta))` will be complex (unless |cos(theta)| = 1), since cos(theta) is in the interval [-1,1].
    3734
    38 Looking at the code for Func_assoc_legendre_P._eval_special_values_, I suspect the culprit is the n == m case, which returns
    39 
     35Looking at the code for `Func_assoc_legendre_P._eval_special_values_`, I suspect the culprit is the `n == m` case, which returns
    4036{{{
    4137factorial(2*m)/2**m/factorial(m) * (x**2-1)**(m/2)
    4238}}}
    4339
    44 This discrepancy also seems to be present in spherical_harmonic when
    45 n == m (an instance of !SphericalHarmonic from sage/functions/special.py),
    46 which is built using gen_legendre_P.
     40This discrepancy also seems to be present in `spherical_harmonic` when
     41`n == m` (an instance of `SphericalHarmonic` from `sage/functions/special.py`),
     42which is built using `gen_legendre_P`.
    4743
    4844After [[https://groups.google.com/d/msg/sage-devel/IDtiGF6HB28/ErLsqI1eBAAJ|discussion]]
    49 in the sage-devel mailing list it appears that this is because the n == m
    50 case in _eval_special_values_ is based on  https://dlmf.nist.gov/14.7#E15,
     45in the sage-devel mailing list it appears that this is because the `n == m`
     46case in `_eval_special_values_` is based on  https://dlmf.nist.gov/14.7#E15,
    5147but this is not defined in (-infinity,1].
    5248
    5349For the spherical harmonics, where the argument x = cos(theta),
    5450x will always be in the range [-1, 1 ], where special case used
    55 in _eval_special_values_ is not defined.
     51in `_eval_special_values_` is not defined.
    5652
    5753On the sage-devel mailing list, Howard Cohl suggested that
    5854the correct formula for x in [-1, 1] is
    59 
    6055{{{
    6156P_m^m(x)=(-1)^m (2m)!/(2^m m!) (1-x^2)^(m/2)
     
    7065Legendre functions.
    7166
    72 My proposed fix would be to have Func_assoc_legendre_P._eval_special_values_ choose between two n == m special cases, based on whether -1 <= x <= 1 (above expression) or > 1 (current expression).
     67My proposed fix would be to have `Func_assoc_legendre_P._eval_special_values_` choose between two `n == m` special cases, based on whether `-1 <= x <= 1` (above expression) or `> 1` (current expression).
    7368
    74 This raises the question of whether Func_assoc_legendre_P is correctly defined, as at present it would seem to cover both Ferrers functions and associated Legendre functions.
     69This raises the question of whether `Func_assoc_legendre_P` is correctly defined, as at present it would seem to cover both Ferrers functions and associated Legendre functions.
    7570
    76 In my experience with the physics/chemistry literature, the spherical harmonics are universally defined in terms of "associated Legendre functions", even though the argument is x = cos(theta). DLMF suggests these are defined in terms of Ferrers functions of the first kind (https://dlmf.nist.gov/14.30.E1). Wolfram Mathematica does not seem to distinguish. Possibly it is worth flagging in the docstring for Func_assoc_legendre_P that the class seems to cover both functions.
     71In my experience with the physics/chemistry literature, the spherical harmonics are universally defined in terms of "associated Legendre functions", even though the argument is x = cos(theta). DLMF suggests these are defined in terms of Ferrers functions of the first kind (https://dlmf.nist.gov/14.30.E1). Wolfram Mathematica does not seem to distinguish. Possibly it is worth flagging in the docstring for `Func_assoc_legendre_P` that the class seems to cover both functions.