Skip to content

Commit 26de0e1

Browse files
authored
simplify jacobi conversion (#189)
* simplify jacobi conversion * fix Ultraspherical conversion
1 parent 067b3d6 commit 26de0e1

File tree

3 files changed

+34
-21
lines changed

3 files changed

+34
-21
lines changed

src/Spaces/Jacobi/JacobiOperators.jl

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,18 @@ function Conversion(L::Jacobi,M::Jacobi)
149149
elseif (isapprox(M.b,L.b+1) && isapprox(M.a,L.a)) ||
150150
(isapprox(M.b,L.b) && isapprox(M.a,L.a+1))
151151
ConcreteConversion(L,M)
152-
elseif M.b > L.b+1
153-
ConversionWrapper(
154-
TimesOperator(
155-
ConcreteConversion(Jacobi(M.b-1,M.a,dm),M),
156-
Conversion(L,Jacobi(M.b-static(1),M.a,dm))))
157-
else #if M.a >= L.a+1
158-
ConversionWrapper(
159-
TimesOperator(
160-
ConcreteConversion(Jacobi(M.b,M.a-1,dm),M),
161-
Conversion(L,Jacobi(M.b,M.a-static(1),dm))))
152+
elseif M.b >= L.b && M.a >= L.a
153+
# We split this into steps where a and b are changed by 1:
154+
# Define the intermediate space J = Jacobi(M.b, L.a, dm)
155+
# Conversion(L, M) == Conversion(J, M) * Conversion(L, J)
156+
# Conversion(L, J) = Conversion(Jacobi(L.b, L.a, dm), Jacobi(M.b, L.a, dm))
157+
# Conversion(J, M) = Conversion(Jacobi(M.b, L.a, dm), Jacobi(M.b, M.a, dm))
158+
CLJ = [ConcreteConversion(Jacobi(b-1,L.a,dm), Jacobi(b, L.a, dm)) for b in M.b:-1:L.b+1]
159+
CJM = [ConcreteConversion(Jacobi(M.b,a-1,dm), Jacobi(M.b, a, dm)) for a in M.a:-1:L.a+1]
160+
C = [CJM; CLJ]
161+
ConversionWrapper(TimesOperator(C))
162+
else
163+
error("Implement for $L$M")
162164
end
163165
elseif L.a L.b 0 && M.a M.b 0.5
164166
Conversion(L,Ultraspherical(L),Ultraspherical(M),M)

src/Spaces/Ultraspherical/UltrasphericalOperators.jl

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,22 @@ function Conversion(A::Ultraspherical,B::Ultraspherical)
156156
a=order(A); b=order(B)
157157
if b==a
158158
ConversionWrapper(Operator(I,A))
159-
elseif -1 b-a 1 && (a,b) (2,1)
160-
ConcreteConversion(A,B)
161-
elseif b-a > 1
162-
d=domain(A)
163-
US=Ultraspherical(b-static(1),d)
164-
v = [ConcreteConversion(Ultraspherical(i-1,d), Ultraspherical(i,d)) for i in b:-1:a+1]
165-
ConversionWrapper(TimesOperator(v))
159+
elseif isapproxinteger(b-a) || isapproxinteger_addhalf(b-a)
160+
if -1 b-a 1 && (a,b) (2,1)
161+
ConcreteConversion(A,B)
162+
elseif b-a > 1
163+
d=domain(A)
164+
US=Ultraspherical(b-static(1),d)
165+
r = b:-1:a+1
166+
v = [ConcreteConversion(Ultraspherical(i-1,d), Ultraspherical(i,d)) for i in r]
167+
if !(last(r) a+1)
168+
vlast = ConcreteConversion(A, Ultraspherical(last(r)-1, d))
169+
v = [v; vlast]
170+
end
171+
ConversionWrapper(TimesOperator(v))
172+
else
173+
throw(ArgumentError("Cannot convert from $A to $B"))
174+
end
166175
else
167176
throw(ArgumentError("Cannot convert from $A to $B"))
168177
end

test/UltrasphericalTest.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,12 @@ using Static
6969
@test g Fun(x->x^2, Ultraspherical(0.5))
7070

7171
f = Fun(x->x^2, Ultraspherical(0.5)) # Legendre
72-
CLU = Conversion(Ultraspherical(0.5), Ultraspherical(2.5))
73-
@test !isdiag(CLU)
74-
g = CLU * f
75-
@test g Fun(x->x^2, Ultraspherical(2.5))
72+
for n in (2.5, 3)
73+
CLU = Conversion(Ultraspherical(0.5), Ultraspherical(n))
74+
@test !isdiag(CLU)
75+
g = CLU * f
76+
@test g Fun(x->x^2, Ultraspherical(n))
77+
end
7678
end
7779

7880
@testset "Normalized space" begin

0 commit comments

Comments
 (0)