Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spherical Harmonics: special cases and more examples #31639

Open
mjungmath opened this issue Apr 10, 2021 · 14 comments
Open

Spherical Harmonics: special cases and more examples #31639

mjungmath opened this issue Apr 10, 2021 · 14 comments

Comments

@mjungmath
Copy link

This ticket is devoted to improve spherical harmonics and make them function properly. That entails treating special cases more efficiently and adding a bunch of doctests for checking correctness.

Depends on #25034
Depends on #31637

CC: @egourgoulhon @tscrim @slel @mkoeppe

Component: misc

Author: Michael Jung

Branch/Commit: public/spher_harmonics_improved_31639 @ e92db1d

Issue created by migration from https://trac.sagemath.org/ticket/31639

@mjungmath mjungmath added this to the sage-9.3 milestone Apr 10, 2021
@mjungmath
Copy link
Author

Dependencies: #25034

@mjungmath
Copy link
Author

Author: Michael Jung

@mjungmath
Copy link
Author

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 10, 2021

Branch pushed to git repo; I updated commit sha1. New commits:

4fcc574Trac #25034: formula for n=m fixed
a4edb24Trac #25034: abs(m) exceeding n gives zero immediately
1ace9faTrac #31639: special cases added + list of first spherical harmonics added

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 10, 2021

Commit: 1ace9fa

@mjungmath
Copy link
Author

comment:4

Here is one first approach based on the current branch of #25034.

Any chance to get rid of terms like sqrt(sin^2(theta)) in a nice way?

@mjungmath

This comment has been minimized.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 10, 2021

Changed commit from 1ace9fa to e92db1d

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 10, 2021

Branch pushed to git repo; I updated commit sha1. New commits:

d5461d4Trac #31639: import statements given when needed
e92db1dTrac #31639: separate special values from general formula

@egourgoulhon
Copy link
Member

comment:7

Replying to @mjungmath:

Here is one first approach based on the current branch of #25034.

Thanks!

Any chance to get rid of terms like sqrt(sin^2(theta)) in a nice way?

These ones are really annoying in Sage; this is why I introduced the functions simplify_sqrt_real and simplify_abs_trig, which are used in the default simplification chain for calculus on manifolds. They do the job here:

sage: x, y = var('x y')
sage: s = spherical_harmonic(2, 1, x, y); s
1/4*sqrt(6)*sqrt(5)*sqrt(sin(x)^2)*cos(x)*e^(I*y)/sqrt(pi)
sage: assume(0 <= x, x <= pi)                              
sage: s.simplify_full()  # no effect despite the above assumptions!
1/4*sqrt(6)*sqrt(5)*sqrt(sin(x)^2)*cos(x)*e^(I*y)/sqrt(pi)
sage: from sage.manifolds.utilities import simplify_sqrt_real, simplify_abs_trig
sage: simplify_abs_trig(simplify_sqrt_real(s))
1/4*sqrt(5)*sqrt(3)*sqrt(2)*cos(x)*e^(I*y)*sin(x)/sqrt(pi)

@egourgoulhon
Copy link
Member

comment:8

The following results given in the EXAMPLES section:

Y_1^-1(x,y)=-1/2*sqrt(3/2)*e^(-I*y)*sin(x)/sqrt(pi)
Y_1^1(x,y)=1/4*sqrt(3)*sqrt(2)*sqrt(sin(x)^2)*e^(I*y)/sqrt(pi)
Y_2^-1(x,y)=-1/4*sqrt(15)*sqrt(2)*sqrt(sin(x)^2)*cos(x)*e^(-I*y)/sqrt(pi)
Y_2^1(x,y)=1/4*sqrt(6)*sqrt(5)*sqrt(sin(x)^2)*cos(x)*e^(I*y)/sqrt(pi)

have signs opposite to https://en.wikipedia.org/wiki/Table_of_spherical_harmonics and https://mathworld.wolfram.com/SphericalHarmonic.html. This is certainly due to the Condon-Shortley phase (-1)m. I think we should agree with Wikipedia's convention, since it is standard in mathematical physics. Problably, we should offer the option condon_shortley=True in spherical_harmonic's arguments. For instance, this is done in the package kerrgeodesic_gw:

sage: from kerrgeodesic_gw import spin_weighted_spherical_harmonic
sage: x, y = var('x y')
sage: spin_weighted_spherical_harmonic(0, 1, -1, x, y)  # weight = 0 -> spherical harmonic
0.25*sqrt(6)*e^(-I*y)*sin(x)/sqrt(pi)
sage: spin_weighted_spherical_harmonic(0, 1, 1, x, y)
-1/4*sqrt(6)*e^(I*y)*sin(x)/sqrt(pi)
sage: spin_weighted_spherical_harmonic(0, 1, 1, x, y, condon_shortley=False)
1/4*sqrt(6)*e^(I*y)*sin(x)/sqrt(pi)

By the way, there is not the sqrt(sin(x)^2) issue discussed in comment:7 in the above outputs, maybe because kerrgeodesic_gw uses the algorithm of Golberg (1967) and does not rely explicitely on associated Legendre function; see the function _compute_sw_spherical_harm in line 27 of the file spin_weighted_spherical_harm.py.

PS: kerrgeodesic_gw can be installed in Sage with sage -pip install kerrgeodesic_gw, but if you want to play with it without installing it, you can run this notebook in Binder.

@egourgoulhon
Copy link
Member

comment:9

Another motivation for using the Condon-Shortley phase: SymPy uses it:

sage: x, y = var('x y')                             
sage: from sympy import Ynm                   
sage: Ynm(1, 1, x, y).expand(func=True)
-sqrt(6)*exp(I*y)*sin(x)/(4*sqrt(pi))

We should certainly agree with SymPy (in addition to Wikipedia, MathWorld, etc.)

@mjungmath
Copy link
Author

comment:10

Thank you for the input. I agree that a flag for the Condon-Shortley phase is the most favorable option.

I'll probably use simplify_abs_trig. Why haven't these simplifications made it to the global namespace though? I think it is definitely worth to add.

Let's wait for #25034 before we wrap this up here.

@mkoeppe mkoeppe modified the milestones: sage-9.3, sage-9.4 Apr 15, 2021
@mjungmath
Copy link
Author

Changed dependencies from #25034 to #25034, #31637

@mkoeppe mkoeppe modified the milestones: sage-9.4, sage-9.5 Aug 10, 2021
@mkoeppe mkoeppe modified the milestones: sage-9.5, sage-9.6 Dec 18, 2021
@mkoeppe mkoeppe modified the milestones: sage-9.6, sage-9.7 Apr 1, 2022
@mkoeppe mkoeppe modified the milestones: sage-9.7, sage-9.8 Sep 19, 2022
@mkoeppe mkoeppe removed this from the sage-9.8 milestone Jan 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants