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

Let sphericalharmonicy call FastTransforms.sphevaluatepi? #20

Open
MikaelSlevinsky opened this issue Feb 4, 2021 · 1 comment
Open

Comments

@MikaelSlevinsky
Copy link
Member

I wonder how accurate and efficient the normalization is

function sphericalharmonicy(ℓ, m, θ, φ)
= abs(m)
exp((lgamma(ℓ++1)+lgamma(ℓ-+1)-2lgamma(ℓ+1))/2)*sqrt((2+1)/(4π)) * exp(im*m*φ) * sin/2)^* cos/2)^* jacobip(ℓ-m̃,m̃,m̃,cos(θ))
end

compared to recurrence relations with normalization built-in

julia> θ, φ, ℓ, m = 0.1, 0.2, 2, 1
(0.1, 0.2, 2, 1)

julia> @time FastTransforms.sphevaluatepi/π, ℓ, m)*exp(im*m*φ)/sqrt(2π)
  0.000011 seconds (7 allocations: 176 bytes)
0.07521112971423365 + 0.015246050775019672im

julia> θ, φ, ℓ, m = π/2, 0.2, 10_000, 5000
(1.5707963267948966, 0.2, 10000, 5000)

julia> @time FastTransforms.sphevaluatepi/π, ℓ, m)*exp(im*m*φ)/sqrt(2π)
  0.000060 seconds (7 allocations: 176 bytes)
0.19235804128133974 + 0.2828286746396144im
@TSGut
Copy link
Member

TSGut commented Feb 11, 2021

Here are some basic tests.

julia> using BenchmarkTools, FastTransforms

julia> θ, φ, ℓ, m = 0.1, 0.2, 2, 1
(0.1, 0.2, 2, 1)

julia> @btime FastTransforms.sphevaluatepi/π, ℓ, m)*exp(im*m*φ)/sqrt(2π)
  150.510 ns (8 allocations: 208 bytes)
0.07521112971423365 + 0.015246050775019672im

julia> @btime sphericalharmonicy(ℓ, m, θ, φ)
  136.160 ns (2 allocations: 128 bytes)
0.07521112971423363 + 0.015246050775019674im

julia> abs(FastTransforms.sphevaluatepi/π, ℓ, m)*exp(im*m*φ)/sqrt(2π)-sphericalharmonicy(ℓ, m, θ, φ))
1.3985787785349405e-17

There's an issue for high values of m, though:

julia> θ, φ, ℓ, m = π/2, 0.2, 10000, 5000
(1.5707963267948966, 0.2, 10000, 5000)

julia> @btime FastTransforms.sphevaluatepi/π, ℓ, m)*exp(im*m*φ)/sqrt(2π)
  51.562 μs (8 allocations: 208 bytes)
0.19235804128133974 + 0.2828286746396144im

julia> # the following clearly doesn't work

julia> sphericalharmonicy(ℓ, m, θ, φ)
NaN + NaN*im

julia> # with BigFloat and BigInt it works but is slow

julia> sphericalharmonicy(BigInt(ℓ), m, BigFloat(θ), φ)
0.1923580412813398318764142897415155812528907393225858348966156677614988766433293 + 0.2828286746396146063051417153359899381451149677419309920950959124851106430082544im

julia> # this originates in the call to jacobip 
julia> θ, φ, ℓ, m = π/2, 0.2, 10000, 1000
(1.5707963267948966, 0.2, 10000, 1000)

julia> jacobip(ℓ-abs(m),abs(m),abs(m),cos(θ))
1.5242151618568348e277

julia> θ, φ, ℓ, m = π/2, 0.2, 10000, 5000
(1.5707963267948966, 0.2, 10000, 5000)

julia> jacobip(ℓ-abs(m),abs(m),abs(m),cos(θ))
NaN

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants