Skip to content

Commit bf9034b

Browse files
committed
Cosmetic improvements
1 parent 407c12a commit bf9034b

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

src/wrightbessel.jl

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#
3939
# First, different functions are implemented valid for certain domains of the
4040
# three arguments.
41-
# Finally they are put together in `wrightbessel``.
41+
# Finally they are put together in `wrightbessel`.
4242

4343
# rgamma_zero: smallest value x for which rgamma(x) == 0 as x gets large
4444
const rgamma_zero = 178.47241115886637
@@ -48,16 +48,13 @@ const exp_inf = 709.7827128933841
4848
# Compute reciprocal gamma via loggamma
4949
@inline rgamma(y::Real) = exp(-loggamma(y))
5050

51-
# Compute exp(x) / gamma(y) safely via loggamma
52-
@inline function _exp_rgamma(x::Real, y::Real)
53-
# Compute exp(x) / Γ(y) = exp(x - loggamma(y)) to avoid overflow
54-
return exp(x - loggamma(y))
55-
end
51+
# Compute exp(x) / Γ(y) safely via loggamma to avoid overflow
52+
@inline _exp_rgamma(x::Real, y::Real) = exp(x - loggamma(y))
5653

5754

5855
# 1. Taylor series expansion in x=0, for x <= 1
59-
# Phi(a, b, x) = sum_k x^k / k! / Gamma(a*k+b)
60-
# Note that every term, and therefore also Phi(a, b, x), is monotone
56+
# Φ(a, b, x) = sum_k x^k / k! / Γ(a*k+b)
57+
# Note that every term, and therefore also Φ(a, b, x), is monotone
6158
# decreasing with increasing a or b.
6259
function _wb_series(a::Float64, b::Float64, x::Float64, nstart::Int, nstop::Int)
6360
xk_k = x^nstart * rgamma(nstart + 1) # x^k/k!
@@ -79,7 +76,7 @@ end
7976

8077

8178
# 2. Taylor series expansion in x=0, for large a.
82-
# Phi(a, b, x) = sum_k x^k / k! / Gamma(a*k+b)
79+
# Φ(a, b, x) = sum_k x^k / k! / Γ(a*k+b)
8380
# Use Stirling formula to find k=k_max, the maximum term.
8481
# Then use n terms of Taylor series around k_max.
8582
function _wb_large_a(a::Float64, b::Float64, x::Float64, n::Int)
@@ -100,22 +97,22 @@ end
10097

10198
# 3. Taylor series in a=0 up to order 5, for tiny a and not too large x
10299
#
103-
# Phi(a, b, x) = exp(x)/Gamma(b)
104-
# * (1 - a*x * Psi(b) + a^2/2*x*(1+x) * (Psi(b)^2 - Psi'(b)
105-
# + ... )
106-
# + O(a^6))
100+
# Φ(a, b, x) = exp(x)/Γ(b)
101+
# * (1 - a*x * Ψ(b) + a^2/2*x*(1+x) * (Ψ(b)^2 - Ψ'(b)
102+
# + ... )
103+
# + O(a^6))
107104
#
108-
# where Psi is the digamma function.
105+
# where Ψ is the digamma function.
109106
#
110107
# Parameter order takes effect only when b > 1e-3 and 2 <= order <= 5,
111108
# otherwise it defaults to 2 or, if b <= 1e-3, to 5. The lower order is, the
112109
# less polygamma functions have to be computed.
113110
#
114-
# For small b, i.e. b <= 1e-3, cancellation of poles of digamma(b)/Gamma(b)
111+
# For small b, i.e. b <= 1e-3, cancellation of poles of Ψ(b)/Γ(b)
115112
# and polygamma needs to be carried out => series expansion in a=0 to order 5
116113
# and in b=0 to order 4.
117114
function _wb_small_a(a::Float64, b::Float64, x::Float64, order::Int)
118-
# A: coefficients of a^k (1, -x * Psi(b), ...)
115+
# A: coefficients of a^k (1, -x * Ψ(b), ...)
119116
# B: powers of b^k/k! or terms in polygamma functions
120117
# C: coefficients of a^k1 * b^k2
121118
# X: polynomials in x
@@ -149,7 +146,7 @@ function _wb_small_a(a::Float64, b::Float64, x::Float64, order::Int)
149146
)
150147
res = exp(x) * evalpoly(a, A)
151148
else
152-
# Φ(a, b, x) = exp(x)/gamma(b) * sum(A[i] * X[i] * B[i], i=0..5)
149+
# Φ(a, b, x) = exp(x)/Γ(b) * sum(A[i] * X[i] * B[i], i=0..5)
153150
# A[n] = a^n/n!
154151
# But here, we repurpose A[n] = X[n] * B[n] / n!
155152
dg = digamma(b)
@@ -210,7 +207,7 @@ end
210207

211208
# 4. Asymptotic expansion for large x up to order 8
212209
#
213-
# Phi(a, b, x) ~ Z^(1/2-b) * exp((1+a)/a * Z) * sum_k (-1)^k * C_k / Z^k
210+
# Φ(a, b, x) ~ Z^(1/2-b) * exp((1+a)/a * Z) * sum_k (-1)^k * C_k / Z^k
214211
#
215212
# with Z = (a*x)^(1/(1+a)).
216213
function _wb_asymptotic(a::Float64, b::Float64, x::Float64)

0 commit comments

Comments
 (0)