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

Faster compilation time #97

Merged
merged 6 commits into from
Feb 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/gaussquadrature.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Gauss quadrature for the weight functions ``w(x) = (1-x)^\alpha(1+x)^\beta``, ``

* For ``n ≤ 100``: Use Newton's method to solve ``P_n(x)=0``. Evaluate ``P_n`` and ``P_n'`` by three-term recurrence.
* For ``n > 100``: Use Newton's method to solve ``P_n(x)=0``. Evaluate ``P_n`` and ``P_n'`` by an asymptotic expansion (in the interior of ``[-1,1]``) and the three-term recurrence ``O(n^{-2})`` close to the endpoints. (This is a small modification to the algorithm described in [[3]](http://epubs.siam.org/doi/abs/10.1137/120889873).)
* For ``max(a,b) > 5``: Use the Golub-Welsch algorithm requiring ``O(n^2)`` operations.
* For ``\max(a,b) > 5``: Use the Golub-Welsch algorithm requiring ``O(n^2)`` operations.

```@docs
gaussjacobi(n::Integer, α::Real, β::Real)
Expand Down
12 changes: 6 additions & 6 deletions src/besselroots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ function approx_besselroots(ν::Float64, n::Integer)
x = zeros(n)
if ν == 0
for k in 1:min(n,20)
x[k] = J0_roots[k]
x[k] = BESSELJ0_ROOTS[k]
end
for k in min(n,20)+1:n
x[k] = McMahon(ν, k)
end
elseif -1 ≤ ν ≤ 5
correctFirstFew = Piessens(ν)
correctFirstFew = piessens(ν)
for k in 1:min(n,6)
x[k] = correctFirstFew[k]
end
Expand Down Expand Up @@ -131,10 +131,10 @@ function _piessens_chebyshev30(ν::Float64)
return T
end

function Piessens(ν::Float64)
function piessens(ν::Float64)
# Piessens's Chebyshev series approximations (1984). Calculates the 6 first
# zeros to at least 12 decimal figures in region -1 ≤ ν ≤ 5:
C = Piessens_C
C = PIESSENS_C
T = _piessens_chebyshev30(ν)
y = C'*T
_y = collect(y)
Expand All @@ -151,7 +151,7 @@ function besselZeroRoots(m)
0.0, -124 / 3, 0.0, 1.0, 0.0)
# First 20 are precomputed:
@inbounds for jj = 1:min(m, 20)
jk[jj] = J0_roots[jj]
jk[jj] = BESSELJ0_ROOTS[jj]
end
@inbounds for jj = 21:min(m, 47)
ak = π * (jj - .25)
Expand Down Expand Up @@ -184,7 +184,7 @@ function besselJ1(m)
151 / 80, -7 / 24, 0.0, 2.0)
# First 10 are precomputed:
@inbounds for jj = 1:min(m, 10)
Jk2[jj] = besselJ1_10[jj]
Jk2[jj] = BESSELJ1_ON_BESSELJ0_ROOTS[jj]
end
@inbounds for jj = 11:min(m, 15)
ak = π * (jj - .25)
Expand Down
28 changes: 22 additions & 6 deletions src/constants.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
@doc raw"""
First twenty roots of Bessel funcion ``J_0`` in Float64.
https://mathworld.wolfram.com/BesselFunctionZeros.html

# Examples
```jldoctest
julia> zeros = besselj0.(FastGaussQuadrature.BESSELJ0_ROOTS);

julia> all(zeros .< 1e-14)
true
"""
const J0_roots = @SVector [
const BESSELJ0_ROOTS = @SVector [
2.4048255576957728,
5.5200781102863106,
8.6537279129110122,
Expand Down Expand Up @@ -33,7 +40,7 @@ j_{\nu, s} \approx \sum_{k}^{n} C_{k,s} T_k(\frac{\nu-2}{3})
```
where $j_{\nu, s}$ is a ``s``-th zero of Bessel function ``J_\nu``, ``\{T_k\}`` are Chebyshev polynomials and ``C_{k, s}`` is the coefficients.
"""
const Piessens_C = @SMatrix [
const PIESSENS_C = @SMatrix [
2.883975316228 8.263194332307 11.493871452173 14.689036505931 17.866882871378 21.034784308088
0.767665211539 4.209200330779 4.317988625384 4.387437455306 4.435717974422 4.471319438161
-0.086538804759 -0.164644722483 -0.130667664397 -0.109469595763 -0.094492317231 -0.083234240394
Expand Down Expand Up @@ -74,11 +81,11 @@ Values of Bessel function ``J_1`` on first ten roots of Bessel function `J_0`.
```jldoctest
julia> roots = approx_besselroots(0,10);

julia> (besselj1.(roots)).^2 ≈ FastGaussQuadrature.besselJ1_10
julia> (besselj1.(roots)).^2 ≈ FastGaussQuadrature.BESSELJ1_ON_BESSELJ0_ROOTS
true
```
"""
const besselJ1_10 = @SVector [
const BESSELJ1_ON_BESSELJ0_ROOTS = @SVector [
0.2695141239419169,
0.1157801385822037,
0.07368635113640822,
Expand All @@ -94,14 +101,23 @@ const besselJ1_10 = @SVector [

@doc raw"""
The first 11 roots of the Airy function in Float64 precision
https://mathworld.wolfram.com/AiryFunctionZeros.html

# Examples
```jldoctest
julia> zeros = airy.(FastGaussQuadrature.AIRY_ROOTS);

julia> all(zeros .< 1e-14)
true
```
"""
const airy_roots = @SVector [
const AIRY_ROOTS = @SVector [
-2.338107410459767,
-4.08794944413097,
-5.520559828095551,
-6.786708090071759,
-7.944133587120853,
-9.02265085340981,
-9.022650853340981,
-10.04017434155809,
-11.00852430373326,
-11.93601556323626,
Expand Down
Loading