Skip to content

Commit 4675b10

Browse files
committed
porting some code for complex lgamma, beta, eta, and zeta functions
1 parent ac1ca5d commit 4675b10

File tree

1 file changed

+165
-0
lines changed

1 file changed

+165
-0
lines changed

examples/specfun.j

+165
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
function angle_restrict_symm(theta)
2+
P1 = 4 * 7.8539812564849853515625e-01
3+
P2 = 4 * 3.7748947079307981766760e-08
4+
P3 = 4 * 2.6951514290790594840552e-15
5+
6+
y = 2*floor(theta/(2*pi))
7+
r = ((theta - y*P1) - y*P2) - y*P3
8+
if (r > pi)
9+
r -= (2*pi)
10+
end
11+
return r
12+
end
13+
14+
const clg_coeff = [76.18009172947146,
15+
-86.50532032941677,
16+
24.01409824083091,
17+
-1.231739572450155,
18+
0.1208650973866179e-2,
19+
-0.5395239384953e-5]
20+
21+
function clgamma_lanczos(z)
22+
sqrt2pi = 2.5066282746310005
23+
24+
y = x = z
25+
temp = x + 5.5
26+
zz = log(temp)
27+
zz = zz * (x+0.5)
28+
temp -= zz
29+
ser = complex(1.000000000190015, 0)
30+
for j=1:6
31+
y += 1.0
32+
zz = clg_coeff[j]/y
33+
ser += zz
34+
end
35+
zz = sqrt2pi*ser / x
36+
return log(zz) - temp
37+
end
38+
39+
function lgamma(z::Complex)
40+
if real(z) <= 0.5
41+
a = clgamma_lanczos(1-z)
42+
b = log(sin(pi * z))
43+
logpi = 1.14472988584940017
44+
z = logpi - b - a
45+
else
46+
z = clgamma_lanczos(z)
47+
end
48+
complex(real(z), angle_restrict_symm(imag(z)))
49+
end
50+
51+
beta(x::Number, w::Number) = exp(lgamma(x)+lgamma(w)-lgamma(x+w))
52+
53+
const eta_coeffs =
54+
[.99999999999999999997,
55+
-.99999999999999999821,
56+
.99999999999999994183,
57+
-.99999999999999875788,
58+
.99999999999998040668,
59+
-.99999999999975652196,
60+
.99999999999751767484,
61+
-.99999999997864739190,
62+
.99999999984183784058,
63+
-.99999999897537734890,
64+
.99999999412319859549,
65+
-.99999996986230482845,
66+
.99999986068828287678,
67+
-.99999941559419338151,
68+
.99999776238757525623,
69+
-.99999214148507363026,
70+
.99997457616475604912,
71+
-.99992394671207596228,
72+
.99978893483826239739,
73+
-.99945495809777621055,
74+
.99868681159465798081,
75+
-.99704078337369034566,
76+
.99374872693175507536,
77+
-.98759401271422391785,
78+
.97682326283354439220,
79+
-.95915923302922997013,
80+
.93198380256105393618,
81+
-.89273040299591077603,
82+
.83945793215750220154,
83+
-.77148960729470505477,
84+
.68992761745934847866,
85+
-.59784149990330073143,
86+
.50000000000000000000,
87+
-.40215850009669926857,
88+
.31007238254065152134,
89+
-.22851039270529494523,
90+
.16054206784249779846,
91+
-.10726959700408922397,
92+
.68016197438946063823e-1,
93+
-.40840766970770029873e-1,
94+
.23176737166455607805e-1,
95+
-.12405987285776082154e-1,
96+
.62512730682449246388e-2,
97+
-.29592166263096543401e-2,
98+
.13131884053420191908e-2,
99+
-.54504190222378945440e-3,
100+
.21106516173760261250e-3,
101+
-.76053287924037718971e-4,
102+
.25423835243950883896e-4,
103+
-.78585149263697370338e-5,
104+
.22376124247437700378e-5,
105+
-.58440580661848562719e-6,
106+
.13931171712321674741e-6,
107+
-.30137695171547022183e-7,
108+
.58768014045093054654e-8,
109+
-.10246226511017621219e-8,
110+
.15816215942184366772e-9,
111+
-.21352608103961806529e-10,
112+
.24823251635643084345e-11,
113+
-.24347803504257137241e-12,
114+
.19593322190397666205e-13,
115+
-.12421162189080181548e-14,
116+
.58167446553847312884e-16,
117+
-.17889335846010823161e-17,
118+
.27105054312137610850e-19]
119+
120+
function eta(z)
121+
if z == 0
122+
return complex(0.5)
123+
end
124+
re, im = reim(z)
125+
if im==0 && re < 0 && integer_valued(re) && re==round(re/2)*2
126+
return complex(0.0)
127+
end
128+
reflect = false
129+
if re < 0.5
130+
re = 1-re
131+
im = -im
132+
reflect = true
133+
end
134+
dn = float64(length(eta_coeffs))
135+
sr = 0.0
136+
si = 0.0
137+
for n = length(eta_coeffs):-1:1
138+
p = (dn^-re) * eta_coeffs[n]
139+
lnn = -im * log(dn)
140+
sr += p * cos(lnn)
141+
si += p * sin(lnn)
142+
dn -= 1
143+
end
144+
if reflect
145+
z = complex(re, im)
146+
b = 2.0 - 2.0^complex(re+1,im)
147+
148+
f = 2.0^z - 2
149+
piz = pi^z
150+
151+
b = b/f/piz
152+
153+
return complex(sr,si) * exp(lgamma(z)) * b * cos(pi/2*z)
154+
end
155+
return complex(sr, si)
156+
end
157+
158+
eta(x::Real) = real(eta(complex(float64(x))))
159+
160+
function zeta(z::Complex)
161+
zz = 2.0^z
162+
eta(z) * zz/(zz-2)
163+
end
164+
165+
zeta(x::Real) = real(zeta(complex(float64(x))))

0 commit comments

Comments
 (0)