Skip to content

Commit ef991f8

Browse files
authored
Fix bug in colsupport for Hilbert (#66)
* Fix bug in colsupport for Hilbert * add comments * add comments * Fix within interval stieltjes evaluation * Use ChebyshevT * Update test_stieltjes.jl * Update test_interlace.jl * Update Project.toml
1 parent 94d5843 commit ef991f8

File tree

4 files changed

+165
-130
lines changed

4 files changed

+165
-130
lines changed

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
2828
ArrayLayouts = "0.7"
2929
BandedMatrices = "0.16.5"
3030
BlockArrays = "0.16"
31-
BlockBandedMatrices = "0.10"
31+
BlockBandedMatrices = "0.10.9"
3232
ContinuumArrays = "0.9.1"
3333
DomainSets = "0.5"
3434
FFTW = "1.1"
@@ -39,8 +39,8 @@ HypergeometricFunctions = "0.3.4"
3939
InfiniteArrays = "0.11.1"
4040
InfiniteLinearAlgebra = "0.5.8"
4141
IntervalSets = "0.5"
42-
LazyArrays = "0.21.15"
43-
LazyBandedMatrices = "0.6.5"
42+
LazyArrays = "0.21.16"
43+
LazyBandedMatrices = "0.6.6"
4444
QuasiArrays = "0.7"
4545
SpecialFunctions = "1.0"
4646
julia = "1.6"

src/stieltjes.jl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ associated(::ChebyshevT{T}) where T = ChebyshevU{T}()
5757
associated(::ChebyshevU{T}) where T = ChebyshevU{T}()
5858

5959

60-
const StieltjesPoint{T,V,D} = BroadcastQuasiMatrix{T,typeof(inv),Tuple{BroadcastQuasiMatrix{T,typeof(-),Tuple{T,QuasiAdjoint{V,Inclusion{V,D}}}}}}
60+
const StieltjesPoint{T,W<:Number,V,D} = BroadcastQuasiMatrix{T,typeof(inv),Tuple{BroadcastQuasiMatrix{T,typeof(-),Tuple{W,QuasiAdjoint{V,Inclusion{V,D}}}}}}
6161
const ConvKernel{T,D1,D2} = BroadcastQuasiMatrix{T,typeof(-),Tuple{D1,QuasiAdjoint{T,D2}}}
6262
const Hilbert{T,D1,D2} = BroadcastQuasiMatrix{T,typeof(inv),Tuple{ConvKernel{T,Inclusion{T,D1},Inclusion{T,D2}}}}
6363
const LogKernel{T,D1,D2} = BroadcastQuasiMatrix{T,typeof(log),Tuple{BroadcastQuasiMatrix{T,typeof(abs),Tuple{ConvKernel{T,Inclusion{T,D1},Inclusion{T,D2}}}}}}
@@ -203,8 +203,8 @@ end
203203
P = wP.P
204204
w = orthogonalityweight(P)
205205
X = jacobimatrix(P)
206-
z, x = parent(S).args[1].args
207-
z in axes(P,1) && transpose((inv.(x .- x') * wP)[z,:])
206+
z, xc = parent(S).args[1].args
207+
z in axes(P,1) && return transpose(view(inv.(xc' .- xc) * wP,z,:))
208208
transpose((X'-z*I) \ [-sum(w)*_p0(P); zeros(∞)])
209209
end
210210

@@ -213,8 +213,8 @@ sqrtx2(x::Real) = sign(x)*sqrt(x^2-1)
213213

214214
@simplify function *(S::StieltjesPoint, wP::Weighted{<:Any,<:ChebyshevU})
215215
T = promote_type(eltype(S), eltype(wP))
216-
z, x = parent(S).args[1].args
217-
z in axes(wP,1) && transpose((inv.(x .- x') * wP)[z,:])
216+
z, xc = parent(S).args[1].args
217+
z in axes(wP,1) && return (convert(T,π)*ChebyshevT()[z,2:end])'
218218
ξ = inv(z + sqrtx2(z))
219219
transpose(convert(T,π) * ξ.^oneto(∞))
220220
end
@@ -231,7 +231,7 @@ mutable struct HilbertVandermonde{T,MM} <: AbstractCachedMatrix{T}
231231
colsupport::Vector{Int}
232232
end
233233

234-
HilbertVandermonde(M, data::Matrix) = HilbertVandermonde(M, data, size(data), Int[])
234+
HilbertVandermonde(M, data::Matrix) = HilbertVandermonde(M, data, size(data), fill(size(data,1), size(data,2)))
235235
size(H::HilbertVandermonde) = (ℵ₀,ℵ₀)
236236
function colsupport(H::HilbertVandermonde, j)
237237
resizedata!(H, H.datasize[1], maximum(j))
@@ -256,8 +256,9 @@ end
256256
@simplify function *(H::Hilbert{<:Any,<:Any,<:ChebyshevInterval}, W::Weighted{<:Any,<:ChebyshevU})
257257
x = axes(H,1)
258258
= chebyshevt(x)
259-
ψ_1 =\ inv.(x .+ sqrtx2.(x))
259+
ψ_1 =\ inv.(x .+ sqrtx2.(x)) # same ψ_1 = x .- sqrt(x^2 - 1) but with relative accuracy as x -> ∞
260260
data = convert(eltype(H),π) * Matrix(reshape(paddeddata(ψ_1),:,1))
261+
# Operator has columns π * ψ_1^k
261262
* HilbertVandermonde(Clenshaw(T̃ * ψ_1, T̃), data)
262263
end
263264

test/test_interlace.jl

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using ClassicalOrthogonalPolynomials, BlockArrays, LazyBandedMatrices, Test
1+
using ClassicalOrthogonalPolynomials, BlockArrays, LazyBandedMatrices, FillArrays, Test
22
import ClassicalOrthogonalPolynomials: PiecewiseInterlace
33

44
@testset "Piecewise" begin
@@ -36,12 +36,37 @@ import ClassicalOrthogonalPolynomials: PiecewiseInterlace
3636
@testset "two-interval Hilbert" begin
3737
T1,T2 = chebyshevt((-2)..(-1)), chebyshevt(0..2)
3838
U1,U2 = chebyshevu((-2)..(-1)), chebyshevu(0..2)
39-
W = PiecewiseInterlace(Weighted(U1), Weighted(U2))
39+
W = PiecewiseInterlace(Weighted(U1), Weighted(U2))
4040
T = PiecewiseInterlace(T1, T2)
41+
U = PiecewiseInterlace(U1, U2)
4142
x = axes(W,1)
4243
H = T \ inv.(x .- x') * W;
4344

45+
@test maximum(BlockArrays.blockcolsupport(H,Block(5)))  Block(50)
46+
4447
c = W \ broadcast(x -> exp(x)* (0  x  2 ? sqrt(2-x)*sqrt(x) : sqrt(-1-x)*sqrt(x+2)), x)
4548
@test T[0.5,1:200]'*(H*c)[1:200] -6.064426633490422
49+
50+
@testset "inversion" begin
51+
= BlockHcat(Eye((axes(H,1),))[:,Block(1)], H)
52+
@test BlockArrays.blockcolsupport(H̃,1) == Block.(1:1)
53+
@test BlockArrays.blockcolsupport(H̃,2) == Block.(1:22)
54+
55+
UT = U \ T
56+
D = U \ Derivative(x) * T
57+
V = x -> x^4 - 10x^2
58+
V_cfs = T \ V.(x)
59+
Vp_cfs_U = D * V_cfs
60+
61+
N = 100
62+
Vp_cfs_N = UT[Block.(1:N),Block.(1:N)] \ Vp_cfs_U[Block.(1:N)]
63+
64+
= H̃[Block.(1:N), Block.(1:N)] \ Vp_cfs_N;
65+
c1,c2 = cμ[Block(1)]
66+
μ = W[:,Block.(1:N-1)] * cμ[Block.(2:N)]/2;
67+
68+
# H * μ == Vp(x) + c1 on first interval
69+
# H * μ == Vp(x) + c2 on second interval
70+
end
4671
end
4772
end

0 commit comments

Comments
 (0)