sign problem spherical harmonics

Skip to first unread message

Evys Ancede

Jun 14, 2019, 2:15:38 PM6/14/19
to sage-support
Today I have been working with the sage function "spherical_harmonic" and have had problems reproducing the tabulated results for these functions. For example, "spherical_harmonic(2, 1, theta, phi)" gives results that are wrong in a minus sign and happen similarly with other parameters. However, I use the sympy library function that I thought was the default for symbolic calculations in SageMath and you can see that it works correctly. Could it help me understand what's going on?

Eric Gourgoulhon

Jun 15, 2019, 11:55:07 AM6/15/19
to sage-support
Unfortunately, the current implementation of spherical harmonics in Sage suffers from various issues. One is the sign convention, which is different from the standard one, as you pointed out. Another issue is getting false results for some parameters, like

sage: theta, phi = var('theta phi')
: spherical_harmonic(1, 1, theta, phi)

The term sqrt(-sin(theta)^2) in the above expression is plain false. It should be sin(theta).
This issue is related to the bug reported in

As a workaround, I would recommend to use the function spin_weighted_spherical_harmonic with the spin weight set to zero instead of spherical_harmonic. The function spin_weighted_spherical_harmonic is not part of the main SageMath, but of the SageMath package kerrgeodesics_gw. So you have to install the later via
sage -pip install kerrgeodesic_gw
NB: on CoCalc, you have to add the option --user: 
sage -pip install --user kerrgeodesic_gw

Then, you will get (the first argument, i.e. 0, is the spin weight; if zero, one gets the standard spherical harmonics):

sage: from kerrgeodesic_gw import spin_weighted_spherical_harmonic
: spin_weighted_spherical_harmonic(0, 2, 1, theta, phi)
: spin_weighted_spherical_harmonic(0, 1, 1, theta, phi)

Both results agree with the standard values, as given e.g. in


Evys Ancede

Jun 15, 2019, 10:29:12 PM6/15/19
Can I someone tell me in whats files (path) are implemented de algorithm for spherical harmonics for take a time for doing a modification in cython??

Dima Pasechnik

Jun 16, 2019, 4:09:15 AM6/16/19
to sage-support
On Sun, Jun 16, 2019 at 3:29 AM Evys Ancede <> wrote:
> Can I someone tell me in whats files (path) are implemented de algorithm for spherical harmonics for take a time for doing a modification in cython??

It is Python, in fact, there is class SphericalHarmonic in
functions/, and you want to fix its
_eval_ member.

> --
> You received this message because you are subscribed to the Google Groups "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> To post to this group, send email to
> Visit this group at
> To view this discussion on the web visit
> For more options, visit
Reply all
Reply to author
0 new messages