Skip to content

Commit 4ad55a5

Browse files
committed
add cispi and fix 3/2
1 parent 3e2e295 commit 4ad55a5

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/airy.jl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function _airyai(z::ComplexOrReal{T}) where T <: Union{Float32, Float64}
4747

4848
if x > zero(T)
4949
# use relation to besselk (http://dlmf.nist.gov/9.6.E1)
50-
zz = 2 * z^(T(3)/2) / 3
50+
zz = 2 * z * sqrt(z) / 3
5151
return sqrt(z / 3) * besselk_continued_fraction_shift(one(T)/3, zz) / π
5252
else
5353
# z is close to the negative real axis
@@ -56,12 +56,12 @@ function _airyai(z::ComplexOrReal{T}) where T <: Union{Float32, Float64}
5656
# for imag(z) != 0 use rotation identity (http://dlmf.nist.gov/9.2.E14)
5757
if iszero(y)
5858
xabs = abs(x)
59-
xx = 2 * xabs^(T(3)/2) / 3
59+
xx = 2 * xabs * sqrt(xabs) / 3
6060
Jv, Yv = besseljy_positive_args(one(T)/3, xx)
6161
Jmv = (Jv - sqrt(T(3)) * Yv) / 2
6262
return convert(eltype(z), sqrt(xabs) * (Jmv + Jv) / 3)
6363
else
64-
return exp(pi*im/3) * _airyai(-z*exp(pi*im/3)) + exp(-pi*im/3) * _airyai(-z*exp(-pi*im/3))
64+
return cispi(one(T)/3) * _airyai(-z*cispi(one(T)/3)) + cispi(-one(T)/3) * _airyai(-z*cispi(-one(T)/3))
6565
end
6666
end
6767
end
@@ -92,7 +92,7 @@ function _airyaiprime(z::ComplexOrReal{T}) where T <: Union{Float32, Float64}
9292

9393
if x > zero(T)
9494
# use relation to besselk (http://dlmf.nist.gov/9.6.E2)
95-
zz = 2 * z^(T(3)/2) / 3
95+
zz = 2 * z * sqrt(z) / 3
9696
return -z * besselk_continued_fraction_shift(T(2)/3, zz) /* sqrt(T(3)))
9797
else
9898
# z is close to the negative real axis
@@ -101,12 +101,12 @@ function _airyaiprime(z::ComplexOrReal{T}) where T <: Union{Float32, Float64}
101101
# for imag(z) != 0 use rotation identity (http://dlmf.nist.gov/9.2.E14)
102102
if iszero(y)
103103
xabs = abs(x)
104-
xx = 2 * xabs^(T(3)/2) / 3
104+
xx = 2 * xabs * sqrt(xabs) / 3
105105
Jv, Yv = besseljy_positive_args(T(2)/3, xx)
106106
Jmv = -(Jv + sqrt(T(3))*Yv) / 2
107107
return convert(eltype(z), xabs * (Jv - Jmv) / 3)
108108
else
109-
return -(exp(2pi*im/3)*_airyaiprime(-z*exp(pi*im/3)) + exp(-2pi*im/3)*_airyaiprime(-z*exp(-pi*im/3)))
109+
return -(cispi(T(2)/3) * _airyaiprime(-z * cispi(one(T)/3)) + cispi(-T(2)/3) * _airyaiprime(-z * cispi(-one(T)/3)))
110110
end
111111
end
112112
end
@@ -137,7 +137,7 @@ function _airybi(z::ComplexOrReal{T}) where T <: Union{Float32, Float64}
137137
airybi_power_series_cutoff(x, y) && return airybi_power_series(z)
138138

139139
if x > zero(T)
140-
zz = 2 * z^(T(3)/2) / 3
140+
zz = 2 * z * sqrt(z) / 3
141141
shift = 20
142142
order = one(T)/3
143143
inu, inum1 = besseli_power_series_inu_inum1(order + shift, zz)
@@ -149,12 +149,12 @@ function _airybi(z::ComplexOrReal{T}) where T <: Union{Float32, Float64}
149149
else
150150
if iszero(y)
151151
xabs = abs(x)
152-
xx = 2 * xabs^(T(3)/2) / 3
152+
xx = 2 * xabs * sqrt(xabs) / 3
153153
Jv, Yv = besseljy_positive_args(one(T)/3, xx)
154154
Jmv = (Jv - sqrt(T(3)) * Yv) / 2
155155
return convert(eltype(z), sqrt(xabs/3) * (Jmv - Jv))
156156
else
157-
return exp(pi*im/3) * _airybi(-z*exp(pi*im/3)) + exp(-pi*im/3) * _airybi(-z*exp(-pi*im/3))
157+
return cispi(one(T)/3) * _airybi(-z * cispi(one(T)/3)) + cispi(-one(T)/3) * _airybi(-z*cispi(-one(T)/3))
158158
end
159159
end
160160
end
@@ -186,7 +186,7 @@ function _airybiprime(z::ComplexOrReal{T}) where T <: Union{Float32, Float64}
186186
airybi_power_series_cutoff(x, y) && return airybiprime_power_series(z)
187187

188188
if x > zero(T)
189-
zz = 2 * z^(T(3)/2) / 3
189+
zz = 2 * z * sqrt(z) / 3
190190
shift = 20
191191
order = T(2)/3
192192
inu, inum1 = besseli_power_series_inu_inum1(order + shift, zz)
@@ -198,12 +198,12 @@ function _airybiprime(z::ComplexOrReal{T}) where T <: Union{Float32, Float64}
198198
else
199199
if iszero(y)
200200
xabs = abs(x)
201-
xx = 2 * xabs^(T(3)/2) / 3
201+
xx = 2 * xabs * sqrt(xabs) / 3
202202
Jv, Yv = besseljy_positive_args(T(2)/3, xx)
203203
Jmv = -(Jv + sqrt(T(3))*Yv) / 2
204204
return convert(eltype(z), xabs * (Jv + Jmv) / sqrt(T(3)))
205205
else
206-
return -(exp(2pi*im/3)*_airybiprime(-z*exp(pi*im/3)) + exp(-2pi*im/3)*_airybiprime(-z*exp(-pi*im/3)))
206+
return -(cispi(T(2)/3) * _airybiprime(-z*cispi(one(T)/3)) + cispi(-T(2)/3) * _airybiprime(-z*cispi(-one(T)/3)))
207207
end
208208
end
209209
end
@@ -443,7 +443,7 @@ function airy_large_arg_a(x::ComplexOrReal{T}; tol=eps(T)*40) where T
443443
abs(t) < tol*abs(out) && break
444444
t *= -3*(i + one(T)/6) * (i + T(5)/6) / (a*(i + one(T)))
445445
end
446-
return out * exp(-a / 6) / (π^(T(3)/2) * sqrt(xsqr))
446+
return out * exp(-a / 6) / (sqrt(T(π)^3) * sqrt(xsqr))
447447
end
448448

449449
function airy_large_arg_b(x::ComplexOrReal{T}; tol=eps(T)*40) where T
@@ -459,7 +459,7 @@ function airy_large_arg_b(x::ComplexOrReal{T}; tol=eps(T)*40) where T
459459
abs(t) < tol*abs(out) && break
460460
t *= 3*(i + one(T)/6) * (i + T(5)/6) / (a*(i + one(T)))
461461
end
462-
return out * exp(a / 6) / (π^(T(3)/2) * sqrt(xsqr))
462+
return out * exp(a / 6) / (sqrt(T(π)^3) * sqrt(xsqr))
463463
end
464464

465465
function airy_large_arg_c(x::ComplexOrReal{T}; tol=eps(T)*40) where T
@@ -477,7 +477,7 @@ function airy_large_arg_c(x::ComplexOrReal{T}; tol=eps(T)*40) where T
477477
abs(t) < tol*abs(out) && break
478478
t *= -3*(i - one(T)/6) * (i + T(7)/6) / (a*(i + one(T)))
479479
end
480-
return out * exp(-a / 6) * sqrt(xsqr) / π^(T(3)/2)
480+
return out * exp(-a / 6) * sqrt(xsqr) / sqrt(T(π)^3)
481481
end
482482

483483
function airy_large_arg_d(x::ComplexOrReal{T}; tol=eps(T)*40) where T
@@ -495,7 +495,7 @@ function airy_large_arg_d(x::ComplexOrReal{T}; tol=eps(T)*40) where T
495495
abs(t) < tol*abs(out) && break
496496
t *= 3*(i - one(T)/6) * (i + T(7)/6) / (a*(i + one(T)))
497497
end
498-
return -out * exp(a / 6) * sqrt(xsqr) / π^(T(3)/2)
498+
return -out * exp(a / 6) * sqrt(xsqr) / sqrt(T(π)^3)
499499
end
500500

501501
# negative arguments of airy functions oscillate around zero so as x -> -Inf it is more prone to cancellation

0 commit comments

Comments
 (0)