Skip to content

Commit b1dce33

Browse files
add in/de-crementαβ!
and toline! and fromline!
1 parent 4f893c6 commit b1dce33

File tree

2 files changed

+62
-37
lines changed

2 files changed

+62
-37
lines changed

src/cjt.jl

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ function cjt(c::AbstractVector,plan::ChebyshevJacobiPlan)
99
elseif α == 0.5 && β == -0.5
1010
decrementα!(ret,α,β)
1111
elseif α == 0.5 && β == 0.5
12-
N > 1 && (ret[N] *= (4N-2)/N)
13-
N > 2 && (ret[N-1] *= (4N-6)/(N-1))
14-
@inbounds for i=N-2:-1:2 ret[i] = (4i-2)/i*(ret[i]+(2i+1)/(8i+8)*ret[i+2]) end
15-
N > 2 && (ret[1] += 0.1875ret[3])
12+
decrementαβ!(ret,α,β)
1613
end
1714
for i=1:N ret[i] *= Cx(i-1.0)/sqrtpi end
1815
return ret
@@ -30,17 +27,13 @@ function cjt(c::AbstractVector,plan::ChebyshevUltrasphericalPlan)
3027
N 1 && return c
3128
if λ == 0 || λ == 1
3229
ret = copy(c)
33-
if λ == 1
34-
N > 1 && (ret[N] *= (4N-2)/N)
35-
N > 2 && (ret[N-1] *= (4N-6)/(N-1))
36-
@inbounds for i=N-2:-1:2 ret[i] = (4i-2)/i*(ret[i]+(2i+1)/(8i+8)*ret[i+2]) end
37-
N > 2 && (ret[1] += 0.1875ret[3])
38-
end
30+
λ == 1 && decrementαβ!(ret,λ-one(λ)/2-one(λ)/2)
3931
for i=1:N ret[i] *= Cx(i-1.0)/sqrtpi end
4032
return ret
4133
else
4234
# Ultraspherical line
43-
ret = ultra2cheb(c,λ,plan)
35+
ret = toline!(copy(c),λ-one(λ)/2-one(λ)/2)
36+
ret = ultra2cheb(ret,modλ(λ),plan)
4437
return ret
4538
end
4639
end
@@ -59,10 +52,7 @@ function icjt(c::AbstractVector,plan::ChebyshevJacobiPlan)
5952
incrementα!(ret,α-1,β)
6053
return ret
6154
elseif α == 0.5 && β == 0.5
62-
N > 2 && (ret[1] -= 0.1875ret[3])
63-
@inbounds for i=2:N-2 ret[i] = i/(4i-2)*ret[i] - (2i+1)/(8i+8)*ret[i+2] end
64-
N > 2 && (ret[N-1] *= (N-1)/(4N-6))
65-
N > 1 && (ret[N] *= N/(4N-2))
55+
incrementαβ!(ret,α-1-1)
6656
return ret
6757
else
6858
return ret
@@ -82,18 +72,12 @@ function icjt(c::AbstractVector,plan::ChebyshevUltrasphericalPlan)
8272
if λ == 0 || λ == 1
8373
ret = copy(c)
8474
for i=1:N ret[i] *= sqrtpi/Cx(i-1.0) end
85-
if λ == 1
86-
N > 2 && (ret[1] -= 0.1875ret[3])
87-
@inbounds for i=2:N-2 ret[i] = i/(4i-2)*ret[i] - (2i+1)/(8i+8)*ret[i+2] end
88-
N > 2 && (ret[N-1] *= (N-1)/(4N-6))
89-
N > 1 && (ret[N] *= N/(4N-2))
90-
return ret
91-
else
92-
return ret
93-
end
75+
λ == 1 && incrementαβ!(ret,λ-3one(λ)/2-3one(λ)/2)
76+
return ret
9477
else
9578
# Ultraspherical line
96-
ret = cheb2ultra(c,λ,plan)
79+
ret = cheb2ultra(c,modλ(λ),plan)
80+
fromline!(ret,λ-one(λ)/2-one(λ)/2)
9781
return ret
9882
end
9983
end
@@ -114,12 +98,12 @@ function plan_icjt(c::AbstractVector,α,β;M::Int=7)
11498
end
11599

116100
function plan_cjt(c::AbstractVector,λ;M::Int=7)
117-
P = ForwardChebyshevUltrasphericalPlan(c,λ,M)
101+
P = ForwardChebyshevUltrasphericalPlan(c,modλ(λ),M)
118102
P.CUC.λ = λ
119103
P
120104
end
121105
function plan_icjt(c::AbstractVector,λ;M::Int=7)
122-
P = BackwardChebyshevUltrasphericalPlan(c,λ,M)
106+
P = BackwardChebyshevUltrasphericalPlan(c,modλ(λ),M)
123107
P.CUC.λ = λ
124108
P
125109
end

src/specialfunctions.jl

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -405,16 +405,17 @@ function incrementβ!(c::AbstractVector,α,β)
405405
N > 1 && (c[N] *= (αβ+N)/(αβ+2N-1))
406406
c
407407
end
408-
#=
408+
409409
function incrementαβ!(c::AbstractVector,α,β)
410410
@assert α == β
411411
N = length(c)
412-
@inbounds for i=1:N-2 c[i] = (2α+i-2)*(2α+i-1)/(2α+2i-1)/(2α+2i)*c[i] - (α+i+1)/(4α+4i+2)*c[i+2] end
413-
N > 1 && (c[N-1] *= (2α+N-3)*(2α+N-2)/(2α+2N-3)/(2α+2N-2))
414-
N > 2 && (c[N] *= (2α+N-2)*(2α+N-1)/(2α+2N-1)/(2α+2N))
412+
N > 2 && (c[1] -=+2)/(4α+10)*c[3])
413+
@inbounds for i=2:N-2 c[i] = (2α+i)*(2α+i+1)/(2α+2i-1)/(2α+2i)*c[i] -+i+1)/(4α+4i+6)*c[i+2] end
414+
N > 1 && (c[N-1] *= (2α+N-1)*(2α+N)/(2α+2N-3)/(2α+2N-2))
415+
N > 0 && (c[N] *= (2α+N)*(2α+N+1)/(2α+2N-1)/(2α+2N))
415416
c
416417
end
417-
=#
418+
418419
function decrementα!(c::AbstractVector,α,β)
419420
αβ,N = α+β,length(c)
420421
N > 1 && (c[N] *= (αβ+2N-2)/(αβ+N-1))
@@ -430,16 +431,17 @@ function decrementβ!(c::AbstractVector,α,β)
430431
N > 1 && (c[1] -=+1)/(αβ+2)*c[2])
431432
c
432433
end
433-
#=
434+
434435
function decrementαβ!(c::AbstractVector,α,β)
435436
@assert α == β
436437
N = length(c)
437-
N > 1 && (c[N-1] *= (2α+2N-5)*(2α+2N-4)/(2α+N-5)/(2α+N-4))
438-
N > 2 && (c[N] *= (2α+2N-3)*(2α+2N-2)/(2α+N-4)/(2α+N-3))
439-
@inbounds for i=N-2:-1:1 c[i] = (2α+2i-3)*(2α+2i-2)/(2α+i-4)/(2α+i-3)*(c[i] + (α+i)/(4α+4i-2)*c[i+2]) end
438+
N > 0 && (c[N] *= (2α+2N-3)*(2α+2N-2)/(2α+N-2)/(2α+N-1))
439+
N > 1 && (c[N-1] *= (2α+2N-5)*(2α+2N-4)/(2α+N-3)/(2α+N-2))
440+
@inbounds for i=N-2:-1:2 c[i] = (2α+2i-3)*(2α+2i-2)/(2α+i-2)/(2α+i-1)*(c[i] ++i)/(4α+4i+2)*c[i+2]) end
441+
N > 2 && (c[1] +=+1)/(4α+6)*c[3])
440442
c
441443
end
442-
=#
444+
443445

444446
function modαβ(α)
445447
if -0.5 < α 0.5
@@ -452,6 +454,16 @@ function modαβ(α)
452454
a
453455
end
454456

457+
function modλ(λ)
458+
if 0 λ < 1
459+
l = λ
460+
else
461+
l = λ%1
462+
l < 0 && (l+=1)
463+
end
464+
l
465+
end
466+
455467
function tosquare!(ret::AbstractVector,α,β)
456468
a,b = modαβ(α),modαβ(β)
457469
A,B = α-a,β-b
@@ -505,3 +517,32 @@ function fromsquare!(ret::AbstractVector,α,β)
505517
end
506518
ret
507519
end
520+
521+
522+
function toline!(ret::AbstractVector,α,β)
523+
@assert α == β
524+
a,b = modαβ(α),modαβ(β)
525+
A,B = α-a,β-b
526+
if α -0.5
527+
incrementαβ!(ret,α,β)
528+
else
529+
for i=A:-1:1
530+
decrementαβ!(ret,i+a,i+a)
531+
end
532+
end
533+
ret
534+
end
535+
536+
function fromline!(ret::AbstractVector,α,β)
537+
@assert α == β
538+
a,b = modαβ(α),modαβ(β)
539+
A,B = α-a,β-b
540+
if α -0.5
541+
decrementαβ!(ret,a,b)
542+
else
543+
for i=0:A-1
544+
incrementαβ!(ret,i+a,i+a)
545+
end
546+
end
547+
ret
548+
end

0 commit comments

Comments
 (0)