diff --git a/.gitignore b/.gitignore index 9bea433..99dee2c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .DS_Store +Manifest.toml diff --git a/Project.toml b/Project.toml index 896f625..df39b92 100644 --- a/Project.toml +++ b/Project.toml @@ -1,33 +1,12 @@ name = "RiemannHilbert" uuid = "79305c5b-9889-52e9-bdbd-56f883c71fe0" -version = "0.1" +version = "0.1.0" [deps] -ApproxFun = "28f2ccd6-bb30-5033-b560-165f7b14dc2f" -ApproxFunBase = "fbd15aa5-315a-5a7d-a8a4-24992e37be05" -ApproxFunFourier = "59844689-9c9d-51bf-9583-5b794ec66d30" -ApproxFunOrthogonalPolynomials = "b70543e2-c0d9-56b8-a290-0d4d6d4de211" -ApproxFunSingularities = "f8fcb915-6b99-5be2-b79a-d6dbef8e6e7e" -DomainSets = "5b8099bc-c8ec-5219-889f-1d9e522a28bf" -DualNumbers = "fa6b7ba4-c1ee-5f82-b5fc-ecf0adba8f74" -FastTransforms = "057dd010-8810-581a-b7be-e3fc3b93f78c" -FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b" -LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" -SingularIntegralEquations = "e094c991-5a90-5477-8896-c1e4c9552a1a" -SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" -SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b" -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +ClassicalOrthogonalPolynomials = "b30e2e7b-c4ee-47da-9d5f-2c5c27239acd" +PowerNumbers = "7635a310-babe-11e9-2fde-a3dff3ddcf26" +SingularIntegrals = "d7440221-8b5e-42fc-909c-0567823f424a" [compat] -ApproxFun = "0.11.8" -ApproxFunBase = "0.2.3" -ApproxFunFourier = "0.2" -ApproxFunOrthogonalPolynomials = "0.3" -ApproxFunSingularities = "0.1.6" -DomainSets = "0.1" -DualNumbers = "0.6" -FastTransforms = "0.8" -FillArrays = "0.6,0.7,0.8" -SingularIntegralEquations = "0.6, 0.7" -SpecialFunctions = "0.7,0.8,0.9" -julia = "1.3" +ClassicalOrthogonalPolynomials = "0.13.9" +SingularIntegrals = "0.3.3" diff --git a/examples/semiclassicalrhproblem.jl b/examples/semiclassicalrhproblem.jl new file mode 100644 index 0000000..902d872 --- /dev/null +++ b/examples/semiclassicalrhproblem.jl @@ -0,0 +1,23 @@ +using SingularIntegrals, SemiclassicalOrthogonalPolynomials, ClassicalOrthogonalPolynomials + +P = SemiclassicalJacobi(2, 1/2, 0, 1/2) + +z = 1+im +W = Weighted(Jacobi(0, 1/2)) +x = axes(W,1) +@test (inv.(z .- x') * W)[3] ≈ stieltjes(W, z)[3] ≈ sum(W[:,3] ./ (z .- x)) + +P = Jacobi(0, 1/2) +W = Weighted(P) +x = axes(W,1) +@test (inv.(z .- x') * W)[3] ≈ stieltjes(W, z)[3] + +Y = (n,z) -> [Base.unsafe_getindex(P, z, n+1) stieltjes(W, z)[n+1]/(-2π*im)] + +w = JacobiWeight(0, 1/2) +n = 5; @test Y(n,0.1+0im) ≈ Y(n,0.1-0im) * [1 w[0.1]; 0 1] + + + + + diff --git a/src/LogNumber.jl b/src/LogNumber.jl index fe3ae80..8e447a1 100644 --- a/src/LogNumber.jl +++ b/src/LogNumber.jl @@ -57,7 +57,7 @@ function exp(l::LogNumber)::ComplexF64 end end -# This is a relative version of dual number, in the sense that its realpart*(1+epsilon) +# This is a relative version of dual number, in the sense that its realpart*(1+epsilon*ε) struct RiemannDual{T} <: Number realpart::T epsilon::T @@ -141,7 +141,7 @@ end log1p(z::RiemannDual) = log(z+1) -SingularIntegralEquations.HypergeometricFunctions.speciallog(x::RiemannDual) = +HypergeometricFunctions.speciallog(x::RiemannDual) = (s = sqrt(x); 3(atanh(s)-realpart(s))/realpart(s)^3) diff --git a/src/RiemannHilbert.jl b/src/RiemannHilbert.jl index 9e57911..a80b9c5 100644 --- a/src/RiemannHilbert.jl +++ b/src/RiemannHilbert.jl @@ -1,486 +1,486 @@ module RiemannHilbert -using Base, ApproxFun, SingularIntegralEquations, DualNumbers, LinearAlgebra, - SpecialFunctions, FillArrays, DomainSets, FastTransforms, SparseArrays +# using Base, ApproxFun, SingularIntegralEquations, DualNumbers, LinearAlgebra, +# SpecialFunctions, FillArrays, DomainSets, FastTransforms, SparseArrays -import DomainSets: UnionDomain, TypedEndpointsInterval +# import DomainSets: UnionDomain, TypedEndpointsInterval -import FastTransforms: ichebyshevtransform! +# import FastTransforms: ichebyshevtransform! -import SingularIntegralEquations: stieltjesforward, stieltjesbackward, undirected, Directed, stieltjesmoment!, JacobiQ, istieltjes, ComplexPlane, ℂ, - mxa_₂F₁, _₂F₁general, directed_mxa_₂F₁, directed_₂F₁general +# import SingularIntegralEquations: stieltjesforward, stieltjesbackward, undirected, Directed, stieltjesmoment!, JacobiQ, istieltjes, ComplexPlane, ℂ, +# mxa_₂F₁, _₂F₁general, directed_mxa_₂F₁, directed_₂F₁general -import ApproxFunBase: mobius, pieces, npieces, piece, BlockInterlacer, interlacer, pieces_npoints, - ArraySpace, tocanonical, components_npoints, ScalarFun, VectorFun, MatrixFun, - dimension, evaluate, prectype, cfstype, Space, SumSpace, spacescompatible, - pieces -import ApproxFunOrthogonalPolynomials: PolynomialSpace, recA, recB, recC, IntervalOrSegmentDomain, IntervalOrSegment +# import ApproxFunBase: mobius, pieces, npieces, piece, BlockInterlacer, interlacer, pieces_npoints, +# ArraySpace, tocanonical, components_npoints, ScalarFun, VectorFun, MatrixFun, +# dimension, evaluate, prectype, cfstype, Space, SumSpace, spacescompatible, +# pieces +# import ApproxFunOrthogonalPolynomials: PolynomialSpace, recA, recB, recC, IntervalOrSegmentDomain, IntervalOrSegment -import Base: values, convert, getindex, setindex!, *, +, -, ==, <, <=, >, |, !, !=, eltype, - >=, /, ^, \, ∪, size, reindex, tail, broadcast, broadcast!, - isinf, in +# import Base: values, convert, getindex, setindex!, *, +, -, ==, <, <=, >, |, !, !=, eltype, +# >=, /, ^, \, ∪, size, reindex, tail, broadcast, broadcast!, +# isinf, in -# we need to import all special functions to use Calculus.symbolic_derivatives_1arg -# we can't do importall Base as we replace some Base definitions -import Base: sinpi, cospi, exp, - asinh, acosh,atanh, - sin, cos, sinh, cosh, - exp2, exp10, log2, log10, - tan, tanh, csc, asin, acsc, sec, acos, asec, - cot, atan, acot, sinh, csch, asinh, acsch, - sech, acosh, asech, tanh, coth, atanh, acoth, - expm1, log1p, sinc, cosc, - abs, sign, log, expm1, tan, abs2, sqrt, angle, max, min, cbrt, log, - atan, acos, asin, inv, real, imag, abs, conj +# # we need to import all special functions to use Calculus.symbolic_derivatives_1arg +# # we can't do importall Base as we replace some Base definitions +# import Base: sinpi, cospi, exp, +# asinh, acosh,atanh, +# sin, cos, sinh, cosh, +# exp2, exp10, log2, log10, +# tan, tanh, csc, asin, acsc, sec, acos, asec, +# cot, atan, acot, sinh, csch, asinh, acsch, +# sech, acosh, asech, tanh, coth, atanh, acoth, +# expm1, log1p, sinc, cosc, +# abs, sign, log, expm1, tan, abs2, sqrt, angle, max, min, cbrt, log, +# atan, acos, asin, inv, real, imag, abs, conj -import LinearAlgebra: conj, transpose +# import LinearAlgebra: conj, transpose -import SpecialFunctions: airy, besselh, erfcx, dawson, erf, erfi, - airyai, airybi, airyaiprime, airybiprime, - hankelh1, hankelh2, besselj, bessely, besseli, besselk, - besselkx, hankelh1x, hankelh2x, lfact, - erfinv, erfcinv, erfc, beta, lbeta, - eta, zeta, gamma, lgamma, polygamma, invdigamma, digamma, trigamma +# import SpecialFunctions: airy, besselh, erfcx, dawson, erf, erfi, +# airyai, airybi, airyaiprime, airybiprime, +# hankelh1, hankelh2, besselj, bessely, besseli, besselk, +# besselkx, hankelh1x, hankelh2x, lfact, +# erfinv, erfcinv, erfc, beta, lbeta, +# eta, zeta, gamma, lgamma, polygamma, invdigamma, digamma, trigamma -import DualNumbers: Dual, realpart, epsilon, dual -import FillArrays: AbstractFill +# import DualNumbers: Dual, realpart, epsilon, dual +# import FillArrays: AbstractFill -export cauchymatrix, rhmatrix, rhsolve, ℂ, istieltjes, KdV +# export cauchymatrix, rhmatrix, rhsolve, ℂ, istieltjes, KdV -include("LogNumber.jl") +# include("LogNumber.jl") -function component_indices(it::BlockInterlacer, N::Int, kr::UnitRange) - ret = Vector{Int}() - ind = 1 - k_end = last(kr) - for (M,j) in it - N == M && j > k_end && return ret - N == M && j ∈ kr && push!(ret, ind) - ind += 1 - end - ret -end - +# function component_indices(it::BlockInterlacer, N::Int, kr::UnitRange) +# ret = Vector{Int}() +# ind = 1 +# k_end = last(kr) +# for (M,j) in it +# N == M && j > k_end && return ret +# N == M && j ∈ kr && push!(ret, ind) +# ind += 1 +# end +# ret +# end -function component_indices(it::BlockInterlacer{NTuple{N,<:AbstractFill{Bool}}}, k::Int, kr::AbstractUnitRange) where N - b = length(it.blocks) - k + (first(kr)-1)*b:b:k + (last(kr)-1)*b -end -component_indices(sp::Space, k...) = component_indices(interlacer(sp), k...) +# function component_indices(it::BlockInterlacer{NTuple{N,<:AbstractFill{Bool}}}, k::Int, kr::AbstractUnitRange) where N +# b = length(it.blocks) +# k + (first(kr)-1)*b:b:k + (last(kr)-1)*b +# end -# # function fpstieltjes(f::Fun,z::Dual) -# # x = mobius(domain(f),z) -# # if !isinf(mobius(domain(f),Inf)) -# # error("Not implemented") -# # end -# # cfs = coefficients(f,Chebyshev) -# # if realpart(x) ≈ 1 -# # c = -(log(dualpart(x))-log(2)) * sum(cfs) -# # r = 0.0 -# # for k=2:2:length(cfs)-1 -# # r += 1/(k-1) -# # c += -r*4*cfs[k+1] -# # end -# # r = 1.0 -# # for k=1:2:length(cfs)-1 -# # r += 1/(k-2) -# # c += -(r+1/(2k))*4*cfs[k+1] -# # end -# # c -# # elseif realpart(x) ≈ -1 -# # v = -(log(-dualpart(x))-log(2)) -# # if !isempty(cfs) -# # c = -v*cfs[1] -# # end -# # r = 0.0 -# # for k=2:2:length(cfs)-1 -# # r += 1/(k-1) -# # c += r*4*cfs[k+1] -# # c += -v*cfs[k+1] -# # end -# # r = 1.0 -# # for k=1:2:length(cfs)-1 -# # r += 1/(k-2) -# # c += -(r+1/(2k))*4*cfs[k+1] -# # c += v*cfs[k+1] -# # end -# # c -# # else -# # error("Not implemented") +# component_indices(sp::Space, k...) = component_indices(interlacer(sp), k...) + +# # # function fpstieltjes(f::Fun,z::Dual) +# # # x = mobius(domain(f),z) +# # # if !isinf(mobius(domain(f),Inf)) +# # # error("Not implemented") +# # # end +# # # cfs = coefficients(f,Chebyshev) +# # # if realpart(x) ≈ 1 +# # # c = -(log(dualpart(x))-log(2)) * sum(cfs) +# # # r = 0.0 +# # # for k=2:2:length(cfs)-1 +# # # r += 1/(k-1) +# # # c += -r*4*cfs[k+1] +# # # end +# # # r = 1.0 +# # # for k=1:2:length(cfs)-1 +# # # r += 1/(k-2) +# # # c += -(r+1/(2k))*4*cfs[k+1] +# # # end +# # # c +# # # elseif realpart(x) ≈ -1 +# # # v = -(log(-dualpart(x))-log(2)) +# # # if !isempty(cfs) +# # # c = -v*cfs[1] +# # # end +# # # r = 0.0 +# # # for k=2:2:length(cfs)-1 +# # # r += 1/(k-1) +# # # c += r*4*cfs[k+1] +# # # c += -v*cfs[k+1] +# # # end +# # # r = 1.0 +# # # for k=1:2:length(cfs)-1 +# # # r += 1/(k-2) +# # # c += -(r+1/(2k))*4*cfs[k+1] +# # # c += v*cfs[k+1] +# # # end +# # # c +# # # else +# # # error("Not implemented") +# # # end +# # # end +# # # +# # # fpcauchy(x...) = fpstieltjes(x...)/(-2π*im) +# # +# # +# # +# # function stieltjesmatrix(space,pts::Vector,s::Bool) +# # n=length(pts) +# # C=Array(ComplexF64,n,n) +# # for k=1:n +# # C[k,:] = stieltjesforward(s,space,n,pts[k]) # # end +# # C # # end # # -# # fpcauchy(x...) = fpstieltjes(x...)/(-2π*im) -# -# -# -# function stieltjesmatrix(space,pts::Vector,s::Bool) -# n=length(pts) -# C=Array(ComplexF64,n,n) -# for k=1:n -# C[k,:] = stieltjesforward(s,space,n,pts[k]) +# # function stieltjesmatrix(space,pts::Vector) +# # n=length(pts) +# # C=zeros(ComplexF64,n,n) +# # for k=1:n +# # cfs = stieltjesbackward(space,pts[k]) +# # C[k,1:min(length(cfs),n)] = cfs +# # end +# # +# # C +# # end + + +# # stieltjesmatrix(space,n::Integer,s::Bool)=stieltjesmatrix(space,points(space,n),s) +# # stieltjesmatrix(space,space2,n::Integer)=stieltjesmatrix(space,points(space2,n)) + + + +# orientedleftendpoint(d::IntervalOrSegment) = RiemannDual(leftendpoint(d), sign(d)) +# orientedrightendpoint(d::IntervalOrSegment) = RiemannDual(rightendpoint(d), -sign(d)) + + +# # use 2nd kind to include endpoints +# collocationpoints(d::IntervalOrSegmentDomain, m::Int) = points(d, m; kind=2) +# collocationpoints(d::UnionDomain, ms::AbstractVector{Int}) = vcat(collocationpoints.(pieces(d), ms)...) +# collocationpoints(d::UnionDomain, m::Int) = collocationpoints(d, pieces_npoints(d,m)) + +# collocationpoints(sp::Space, m) = collocationpoints(domain(sp), m) + + +# collocationvalues(f::ScalarFun, n) = f.(collocationpoints(space(f), n)) +# collocationvalues(f::Fun{<:Chebyshev}, n) = ichebyshevtransform!(coefficients(pad(f,n)); kind=2) +# function collocationvalues(f::VectorFun, n) +# m = n÷size(f,1) +# mapreduce(f̃ -> collocationvalues(f̃,m), vcat, f) +# end +# function collocationvalues(f::MatrixFun, n) +# M = size(f,2) +# ret = Array{cfstype(f)}(undef, n, M) +# for J=1:M +# ret[:,J] = collocationvalues(f[:,J], n) +# end +# ret +# end + +# collocationvalues(f::Fun{<:PiecewiseSpace}, n) = vcat(collocationvalues.(components(f), pieces_npoints(domain(f),n))...) + +# function evaluationmatrix!(E, sp::PolynomialSpace, x) +# x .= real(tocanonical.(Ref(sp), x)) + +# E[:,1] .= 1 +# E[:,2] .= (recA(Float64,sp,0) .* x .+ recB(Float64,sp,0)) .* view(E,:,1) +# for j = 3:size(E,2) +# E[:,j] .= (recA(Float64,sp,j-2) .* x .+ recB(Float64,sp,j-2)) .* view(E,:,j-1) .- recC(Float64,sp,j-2).*view(E,:,j-2) +# end +# E +# end + + +# evaluationmatrix!(E, sp::PolynomialSpace) = +# evaluationmatrix!(E, sp, collocationpoints(sp, size(E,1))) + +# evaluationmatrix(sp::PolynomialSpace, x, n) = +# evaluationmatrix!(Array{Float64}(undef, length(x), n), sp,copy(x)) + + +# function evaluationmatrix!(C, sp::PiecewiseSpace, ns::AbstractVector{Int}, ms::AbstractVector{Int}) +# N, M = length(ns), length(ms) +# @assert N == M == npieces(sp) +# n, m = sum(ns), sum(ms) +# @assert size(C) == (n,m) + +# C .= 0 + +# for J = 1:M +# jr = component_indices(sp, J, 1:ms[J]) +# k_start = sum(view(ns,1:J-1))+1 +# kr = k_start:k_start+ns[J]-1 +# evaluationmatrix!(view(C, kr, jr), component(sp, J)) +# end + +# C +# end + + +# function evaluationmatrix!(C, sp::ArraySpace, ns::AbstractVector{Int}, ms::AbstractVector{Int}) +# @assert length(ns) == length(ms) == length(sp) +# N = length(ns) + +# n, m = sum(ns), sum(ms) +# @assert size(C) == (n,m) + +# C .= 0 + +# for J = 1:N +# jr = component_indices(sp, J, 1:ms[J]) ∩ (1:m) +# k_start = sum(view(ns,1:J-1))+1 +# kr = k_start:k_start+ns[J]-1 +# evaluationmatrix!(view(C, kr, jr), sp[J]) # end + # C # end -# -# function stieltjesmatrix(space,pts::Vector) -# n=length(pts) -# C=zeros(ComplexF64,n,n) -# for k=1:n -# cfs = stieltjesbackward(space,pts[k]) -# C[k,1:min(length(cfs),n)] = cfs + +# evaluationmatrix!(C, sp::PiecewiseSpace) = +# evaluationmatrix!(C, sp, pieces_npoints(sp, size(C,1)), pieces_npoints(sp, size(C,2))) + +# evaluationmatrix!(C, sp::ArraySpace) = +# evaluationmatrix!(C, sp, components_npoints(sp, size(C,1)), components_npoints(sp, size(C,2))) + + +# evaluationmatrix(sp::Space, n::Int) = evaluationmatrix!(Array{Float64}(undef,n,n), sp) + +# fprightstieltjesmoment!(V, sp) = stieltjesmoment!(V, sp, Directed{false}(orientedrightendpoint(domain(sp))), finitepart) +# fpleftstieltjesmoment!(V, sp) = stieltjesmoment!(V, sp, Directed{false}(orientedleftendpoint(domain(sp))), finitepart) +# fprightstieltjesmoment!(V, sp, d) = stieltjesmoment!(V, sp, orientedrightendpoint(d), finitepart) +# fpleftstieltjesmoment!(V, sp, d) = stieltjesmoment!(V, sp, orientedleftendpoint(d), finitepart) + +# function fpstieltjesmatrix!(C, sp, d) +# m, n = size(C) +# pts = collocationpoints(d, m) +# if d == domain(sp) +# fprightstieltjesmoment!(view(C,1,:), sp) +# for k=2:m-1 +# stieltjesmoment!(view(C,k,:), sp, Directed{false}(pts[k])) +# end +# fpleftstieltjesmoment!(view(C,m,:), sp) +# elseif leftendpoint(d) ∈ domain(sp) && rightendpoint(d) ∈ domain(sp) +# fprightstieltjesmoment!(view(C,1,:), sp, d) +# for k=2:m-1 +# stieltjesmoment!(view(C,k,:), sp, pts[k]) +# end +# fpleftstieltjesmoment!(view(C,m,:), sp, d) +# elseif leftendpoint(d) ∈ domain(sp) +# for k=1:m-1 +# stieltjesmoment!(view(C,k,:), sp, pts[k]) +# end +# fpleftstieltjesmoment!(view(C,m,:), sp, d) +# elseif rightendpoint(d) ∈ domain(sp) +# fprightstieltjesmoment!(view(C,1,:), sp, d) +# for k=2:m +# stieltjesmoment!(view(C,k,:), sp, pts[k]) +# end +# else +# for k=1:m +# stieltjesmoment!(view(C,k,:), sp, pts[k]) +# end # end -# # C # end +# fpstieltjesmatrix!(C, sp) = fpstieltjesmatrix!(C, sp, domain(sp)) -# stieltjesmatrix(space,n::Integer,s::Bool)=stieltjesmatrix(space,points(space,n),s) -# stieltjesmatrix(space,space2,n::Integer)=stieltjesmatrix(space,points(space2,n)) +# fpstieltjesmatrix(sp::Space, d::Domain, n::Int, m::Int) = +# fpstieltjesmatrix!(Array{ComplexF64}(undef, n, m), sp, d) +# fpstieltjesmatrix(sp::Space, n::Int, m::Int) = +# fpstieltjesmatrix!(Array{ComplexF64}(undef, n, m), sp, domain(sp)) -orientedleftendpoint(d::IntervalOrSegment) = RiemannDual(leftendpoint(d), sign(d)) -orientedrightendpoint(d::IntervalOrSegment) = RiemannDual(rightendpoint(d), -sign(d)) +# # we group points together by piece +# function fpstieltjesmatrix!(C, sp::PiecewiseSpace, ns::AbstractVector{Int}, ms::AbstractVector{Int}) +# N, M = length(ns), length(ms) +# @assert N == M == npieces(sp) +# n, m = sum(ns), sum(ms) +# @assert size(C) == (n,m) +# for J = 1:M +# jr = component_indices(sp, J, 1:ms[J]) +# k_start = 1 +# for K = 1:N +# k_end = k_start + ns[K] - 1 +# kr = k_start:k_end +# fpstieltjesmatrix!(view(C, kr, jr), component(sp, J), domain(component(sp, K))) +# k_start = k_end+1 +# end +# end -# use 2nd kind to include endpoints -collocationpoints(d::IntervalOrSegmentDomain, m::Int) = points(d, m; kind=2) -collocationpoints(d::UnionDomain, ms::AbstractVector{Int}) = vcat(collocationpoints.(pieces(d), ms)...) -collocationpoints(d::UnionDomain, m::Int) = collocationpoints(d, pieces_npoints(d,m)) +# C +# end + + +# fpstieltjesmatrix(sp::PiecewiseSpace, ns::AbstractVector{Int}, ms::AbstractVector{Int}) = +# fpstieltjesmatrix!(Array{ComplexF64}(undef, sum(ns), sum(ms)), sp, ns, ms) -collocationpoints(sp::Space, m) = collocationpoints(domain(sp), m) +# fpstieltjesmatrix!(C, sp::PiecewiseSpace) = fpstieltjesmatrix!(C, sp, pieces_npoints(sp, size(C,1)), pieces_npoints(sp, size(C,2))) +# fpstieltjesmatrix(sp::PiecewiseSpace, n::Int, m::Int) = fpstieltjesmatrix(sp, pieces_npoints(sp, n), pieces_npoints(sp, m)) -collocationvalues(f::ScalarFun, n) = f.(collocationpoints(space(f), n)) -collocationvalues(f::Fun{<:Chebyshev}, n) = ichebyshevtransform!(coefficients(pad(f,n)); kind=2) -function collocationvalues(f::VectorFun, n) - m = n÷size(f,1) - mapreduce(f̃ -> collocationvalues(f̃,m), vcat, f) -end -function collocationvalues(f::MatrixFun, n) - M = size(f,2) - ret = Array{cfstype(f)}(undef, n, M) - for J=1:M - ret[:,J] = collocationvalues(f[:,J], n) - end - ret -end +# # we group indices together by piece +# function fpstieltjesmatrix(sp::ArraySpace, ns::AbstractArray{Int}, ms::AbstractArray{Int}) +# @assert size(ns) == size(ms) == size(sp) +# N = length(ns) -collocationvalues(f::Fun{<:PiecewiseSpace}, n) = vcat(collocationvalues.(components(f), pieces_npoints(domain(f),n))...) - -function evaluationmatrix!(E, sp::PolynomialSpace, x) - x .= real(tocanonical.(Ref(sp), x)) - - E[:,1] .= 1 - E[:,2] .= (recA(Float64,sp,0) .* x .+ recB(Float64,sp,0)) .* view(E,:,1) - for j = 3:size(E,2) - E[:,j] .= (recA(Float64,sp,j-2) .* x .+ recB(Float64,sp,j-2)) .* view(E,:,j-1) .- recC(Float64,sp,j-2).*view(E,:,j-2) - end - E -end +# n, m = sum(ns), sum(ms) +# C = zeros(ComplexF64, n, m) + +# for J = 1:N +# jr = component_indices(sp, J, 1:ms[J]) ∩ (1:m) +# k_start = sum(view(ns,1:J-1))+1 +# kr = k_start:k_start+ns[J]-1 +# fpstieltjesmatrix!(view(C, kr, jr), sp[J]) +# end +# C +# end -evaluationmatrix!(E, sp::PolynomialSpace) = - evaluationmatrix!(E, sp, collocationpoints(sp, size(E,1))) +# fpstieltjesmatrix(sp::ArraySpace, n::Int, m::Int) = +# fpstieltjesmatrix(sp, reshape(pieces_npoints(sp, n), size(sp)), reshape(pieces_npoints(sp, m), size(sp))) -evaluationmatrix(sp::PolynomialSpace, x, n) = - evaluationmatrix!(Array{Float64}(undef, length(x), n), sp,copy(x)) +# cauchymatrix(x...) = stieltjesmatrix(x...)/(-2π*im) +# function fpcauchymatrix(x...) +# C = fpstieltjesmatrix(x...) +# C ./= (-2π*im) +# C +# end -function evaluationmatrix!(C, sp::PiecewiseSpace, ns::AbstractVector{Int}, ms::AbstractVector{Int}) - N, M = length(ns), length(ms) - @assert N == M == npieces(sp) - n, m = sum(ns), sum(ms) - @assert size(C) == (n,m) - - C .= 0 - - for J = 1:M - jr = component_indices(sp, J, 1:ms[J]) - k_start = sum(view(ns,1:J-1))+1 - kr = k_start:k_start+ns[J]-1 - evaluationmatrix!(view(C, kr, jr), component(sp, J)) - end - - C -end - +# ## riemannhilbert +# function multiplicationmatrix(G, n) +# N, M = size(G) +# @assert N == M +# sp = space(G) +# ret = spzeros(cfstype(G), n, n) +# m = n ÷ N +# pts = collocationpoints(sp, m) +# for K=1:N,J=1:M +# kr = (K-1)*m .+ (1:m) +# jr = (J-1)*m .+ (1:m) +# V = view(ret, kr, jr) +# view(V, diagind(V)) .= collocationvalues(G[K,J],m) +# end +# ret +# end -function evaluationmatrix!(C, sp::ArraySpace, ns::AbstractVector{Int}, ms::AbstractVector{Int}) - @assert length(ns) == length(ms) == length(sp) - N = length(ns) +# function rhmatrix(g::ScalarFun, n) +# sp = rhspace(g) +# C₋ = fpcauchymatrix(sp, n, n) +# g_v = collocationvalues(g-1, n) +# E = evaluationmatrix(sp, n) +# C₋ .= g_v .* C₋ +# E .- C₋ +# end - n, m = sum(ns), sum(ms) - @assert size(C) == (n,m) +# function rhmatrix(g::MatrixFun, n) +# sp = vector_rhspace(g) +# C₋ = fpcauchymatrix(sp, n, n) +# G = multiplicationmatrix(g-I, n) +# E = evaluationmatrix(sp, n) +# E .- G*C₋ +# end - C .= 0 +# function rh_sie_solve(G::MatrixFun, n) +# sp = vector_rhspace(G) +# cfs = rhmatrix(G, n) \ (collocationvalues(G-I, n)) +# U = hcat([Fun(sp, cfs[:,J]) for J=1:size(G,2)]...) +# end - for J = 1:N - jr = component_indices(sp, J, 1:ms[J]) ∩ (1:m) - k_start = sum(view(ns,1:J-1))+1 - kr = k_start:k_start+ns[J]-1 - evaluationmatrix!(view(C, kr, jr), sp[J]) - end +# struct RHProblem{GTyp,CM,RHMTyp} +# G::GTyp +# C₋::CM +# RP::RHMTyp +# end - C -end +# # function RHProblem(G) +# # RHProblem(G, -evaluationmatrix!(C, sp::PiecewiseSpace) = - evaluationmatrix!(C, sp, pieces_npoints(sp, size(C,1)), pieces_npoints(sp, size(C,2))) +# scalar_rhspace(d::AbstractInterval) = Legendre(d) +# scalar_rhspace(d::UnionDomain) = PiecewiseSpace(Legendre.(components(d))) +# array_rhspace(sz, d::Domain) = ArraySpace(scalar_rhspace(d), sz) +# vector_rhspace(sz1, d::Domain) = ArraySpace(scalar_rhspace(d), sz1) +# vector_rhspace(f::Fun) = vector_rhspace(size(f,1), domain(f)) -evaluationmatrix!(C, sp::ArraySpace) = - evaluationmatrix!(C, sp, components_npoints(sp, size(C,1)), components_npoints(sp, size(C,2))) +# rhspace(g::Fun{<:ArraySpace}) = array_rhspace(size(g), domain(g)) +# rhspace(g::Fun) = scalar_rhspace(domain(g)) +# rhsolve(g::ScalarFun, n) = 1+cauchy(Fun(rhspace(g), rhmatrix(g, n) \ (collocationvalues(g-1, n)))) +# function rhsolve(G::MatrixFun, n) +# U = rh_sie_solve(G, n) +# I+cauchy(U) +# end -evaluationmatrix(sp::Space, n::Int) = evaluationmatrix!(Array{Float64}(undef,n,n), sp) -fprightstieltjesmoment!(V, sp) = stieltjesmoment!(V, sp, Directed{false}(orientedrightendpoint(domain(sp))), finitepart) -fpleftstieltjesmoment!(V, sp) = stieltjesmoment!(V, sp, Directed{false}(orientedleftendpoint(domain(sp))), finitepart) -fprightstieltjesmoment!(V, sp, d) = stieltjesmoment!(V, sp, orientedrightendpoint(d), finitepart) -fpleftstieltjesmoment!(V, sp, d) = stieltjesmoment!(V, sp, orientedleftendpoint(d), finitepart) - -function fpstieltjesmatrix!(C, sp, d) - m, n = size(C) - pts = collocationpoints(d, m) - if d == domain(sp) - fprightstieltjesmoment!(view(C,1,:), sp) - for k=2:m-1 - stieltjesmoment!(view(C,k,:), sp, Directed{false}(pts[k])) - end - fpleftstieltjesmoment!(view(C,m,:), sp) - elseif leftendpoint(d) ∈ domain(sp) && rightendpoint(d) ∈ domain(sp) - fprightstieltjesmoment!(view(C,1,:), sp, d) - for k=2:m-1 - stieltjesmoment!(view(C,k,:), sp, pts[k]) - end - fpleftstieltjesmoment!(view(C,m,:), sp, d) - elseif leftendpoint(d) ∈ domain(sp) - for k=1:m-1 - stieltjesmoment!(view(C,k,:), sp, pts[k]) - end - fpleftstieltjesmoment!(view(C,m,:), sp, d) - elseif rightendpoint(d) ∈ domain(sp) - fprightstieltjesmoment!(view(C,1,:), sp, d) - for k=2:m - stieltjesmoment!(view(C,k,:), sp, pts[k]) - end - else - for k=1:m - stieltjesmoment!(view(C,k,:), sp, pts[k]) - end - end - C -end - -fpstieltjesmatrix!(C, sp) = fpstieltjesmatrix!(C, sp, domain(sp)) - -fpstieltjesmatrix(sp::Space, d::Domain, n::Int, m::Int) = - fpstieltjesmatrix!(Array{ComplexF64}(undef, n, m), sp, d) - -fpstieltjesmatrix(sp::Space, n::Int, m::Int) = - fpstieltjesmatrix!(Array{ComplexF64}(undef, n, m), sp, domain(sp)) - - -# we group points together by piece -function fpstieltjesmatrix!(C, sp::PiecewiseSpace, ns::AbstractVector{Int}, ms::AbstractVector{Int}) - N, M = length(ns), length(ms) - @assert N == M == npieces(sp) - n, m = sum(ns), sum(ms) - @assert size(C) == (n,m) - - for J = 1:M - jr = component_indices(sp, J, 1:ms[J]) - k_start = 1 - for K = 1:N - k_end = k_start + ns[K] - 1 - kr = k_start:k_end - fpstieltjesmatrix!(view(C, kr, jr), component(sp, J), domain(component(sp, K))) - k_start = k_end+1 - end - end - - C -end - - -fpstieltjesmatrix(sp::PiecewiseSpace, ns::AbstractVector{Int}, ms::AbstractVector{Int}) = - fpstieltjesmatrix!(Array{ComplexF64}(undef, sum(ns), sum(ms)), sp, ns, ms) - -fpstieltjesmatrix!(C, sp::PiecewiseSpace) = fpstieltjesmatrix!(C, sp, pieces_npoints(sp, size(C,1)), pieces_npoints(sp, size(C,2))) -fpstieltjesmatrix(sp::PiecewiseSpace, n::Int, m::Int) = fpstieltjesmatrix(sp, pieces_npoints(sp, n), pieces_npoints(sp, m)) - - -# we group indices together by piece -function fpstieltjesmatrix(sp::ArraySpace, ns::AbstractArray{Int}, ms::AbstractArray{Int}) - @assert size(ns) == size(ms) == size(sp) - N = length(ns) - - n, m = sum(ns), sum(ms) - C = zeros(ComplexF64, n, m) - - for J = 1:N - jr = component_indices(sp, J, 1:ms[J]) ∩ (1:m) - k_start = sum(view(ns,1:J-1))+1 - kr = k_start:k_start+ns[J]-1 - fpstieltjesmatrix!(view(C, kr, jr), sp[J]) - end - - C -end - -fpstieltjesmatrix(sp::ArraySpace, n::Int, m::Int) = - fpstieltjesmatrix(sp, reshape(pieces_npoints(sp, n), size(sp)), reshape(pieces_npoints(sp, m), size(sp))) - - -cauchymatrix(x...) = stieltjesmatrix(x...)/(-2π*im) -function fpcauchymatrix(x...) - C = fpstieltjesmatrix(x...) - C ./= (-2π*im) - C -end - -## riemannhilbert -function multiplicationmatrix(G, n) - N, M = size(G) - @assert N == M - sp = space(G) - ret = spzeros(cfstype(G), n, n) - m = n ÷ N - pts = collocationpoints(sp, m) - for K=1:N,J=1:M - kr = (K-1)*m .+ (1:m) - jr = (J-1)*m .+ (1:m) - V = view(ret, kr, jr) - view(V, diagind(V)) .= collocationvalues(G[K,J],m) - end - ret -end - -function rhmatrix(g::ScalarFun, n) - sp = rhspace(g) - C₋ = fpcauchymatrix(sp, n, n) - g_v = collocationvalues(g-1, n) - E = evaluationmatrix(sp, n) - C₋ .= g_v .* C₋ - E .- C₋ -end - -function rhmatrix(g::MatrixFun, n) - sp = vector_rhspace(g) - C₋ = fpcauchymatrix(sp, n, n) - G = multiplicationmatrix(g-I, n) - E = evaluationmatrix(sp, n) - E .- G*C₋ -end - -function rh_sie_solve(G::MatrixFun, n) - sp = vector_rhspace(G) - cfs = rhmatrix(G, n) \ (collocationvalues(G-I, n)) - U = hcat([Fun(sp, cfs[:,J]) for J=1:size(G,2)]...) -end - -struct RHProblem{GTyp,CM,RHMTyp} - G::GTyp - C₋::CM - RP::RHMTyp -end - -# function RHProblem(G) -# RHProblem(G, - -scalar_rhspace(d::AbstractInterval) = Legendre(d) -scalar_rhspace(d::UnionDomain) = PiecewiseSpace(Legendre.(components(d))) -array_rhspace(sz, d::Domain) = ArraySpace(scalar_rhspace(d), sz) -vector_rhspace(sz1, d::Domain) = ArraySpace(scalar_rhspace(d), sz1) -vector_rhspace(f::Fun) = vector_rhspace(size(f,1), domain(f)) - -rhspace(g::Fun{<:ArraySpace}) = array_rhspace(size(g), domain(g)) -rhspace(g::Fun) = scalar_rhspace(domain(g)) - -rhsolve(g::ScalarFun, n) = 1+cauchy(Fun(rhspace(g), rhmatrix(g, n) \ (collocationvalues(g-1, n)))) -function rhsolve(G::MatrixFun, n) - U = rh_sie_solve(G, n) - I+cauchy(U) -end - - - -## AffineSpace - -struct AffineSpace{DD,RR} <: Space{DD,RR} - domain::DD -end - -AffineSpace(d::Domain) = AffineSpace{typeof(d),prectype(d)}(d) -spacescompatible(::AffineSpace, ::AffineSpace) = true - - -dimension(::AffineSpace) = 2 - -function evaluate(v::AbstractVector{T}, s::AffineSpace, x::V) where {T,V} - @assert length(v) ≤ 2 - (isempty(v) || x ∉ domain(s)) && return zero(promote_type(T,V)) - length(v) == 1 && return v[1] + zero(x) - v[1] + v[2]*x -end - -Fun(::typeof(identity), S::AffineSpace) = Fun(S, [0.0,1.0]) -Fun(::typeof(identity), S::ComplexPlane) = Fun(Space(S), [0.0,1.0]) - -Space(d::ComplexPlane) = AffineSpace(d) - -*(φ::Fun, z::Fun{<:AffineSpace}) = z*φ - -function *(z::Fun{<:AffineSpace}, φ::Fun{<:JacobiQ}) - a = coefficient(z,1) - b = coefficient(z,2) - u = istieltjes(φ) - x = Fun(domain(u)) - b*sum(u)+stieltjes(a*u + b*x*u) -end - -*(z::Fun{<:AffineSpace}, φ::Fun{<:ConstantSpace}) = Fun(space(z),Number(φ)*coefficients(z)) -*(z::Fun{<:AffineSpace}, Φ::Fun{<:SumSpace}) = mapreduce(f -> z*f, +, components(Φ)) -*(z::Fun{<:AffineSpace}, Φ::Fun{<:ArraySpace}) = Fun(z.*Array(Φ)) - -include("KdV.jl") - -function unorientedangles(ds, z₀) - ret = Vector{Float64}() - for d in ds - if z₀ ≈ leftendpoint(d) - push!(ret, angle(rightendpoint(d)-z₀)) - elseif z₀ ≈ rightendpoint(d) - push!(ret, angle(leftendpoint(d)-z₀)) - else - throw(ArgumentError("Must contain")) - end - end - ret -end - -function productcondition(G, z₀) - Gs = filter(g -> z₀ ∈ domain(g), pieces(G)) - p = sortperm( unorientedangles(domain.(Gs), z₀)) - - g₀ = Matrix{ComplexF64}(I, size(G)) - for g in Gs[p] - if leftendpoint(domain(g)) ≈ z₀ - g₀ = g₀ * first(g) - else - g₀ = g₀ * inv(last(g)) - end - end - g₀ -end - -function productcondition(G) - error("Implement") -end + +# ## AffineSpace + +# struct AffineSpace{DD,RR} <: Space{DD,RR} +# domain::DD +# end + +# AffineSpace(d::Domain) = AffineSpace{typeof(d),prectype(d)}(d) +# spacescompatible(::AffineSpace, ::AffineSpace) = true + + +# dimension(::AffineSpace) = 2 + +# function evaluate(v::AbstractVector{T}, s::AffineSpace, x::V) where {T,V} +# @assert length(v) ≤ 2 +# (isempty(v) || x ∉ domain(s)) && return zero(promote_type(T,V)) +# length(v) == 1 && return v[1] + zero(x) +# v[1] + v[2]*x +# end + +# Fun(::typeof(identity), S::AffineSpace) = Fun(S, [0.0,1.0]) +# Fun(::typeof(identity), S::ComplexPlane) = Fun(Space(S), [0.0,1.0]) + +# Space(d::ComplexPlane) = AffineSpace(d) + +# *(φ::Fun, z::Fun{<:AffineSpace}) = z*φ + +# function *(z::Fun{<:AffineSpace}, φ::Fun{<:JacobiQ}) +# a = coefficient(z,1) +# b = coefficient(z,2) +# u = istieltjes(φ) +# x = Fun(domain(u)) +# b*sum(u)+stieltjes(a*u + b*x*u) +# end + +# *(z::Fun{<:AffineSpace}, φ::Fun{<:ConstantSpace}) = Fun(space(z),Number(φ)*coefficients(z)) +# *(z::Fun{<:AffineSpace}, Φ::Fun{<:SumSpace}) = mapreduce(f -> z*f, +, components(Φ)) +# *(z::Fun{<:AffineSpace}, Φ::Fun{<:ArraySpace}) = Fun(z.*Array(Φ)) + +# include("KdV.jl") + +# function unorientedangles(ds, z₀) +# ret = Vector{Float64}() +# for d in ds +# if z₀ ≈ leftendpoint(d) +# push!(ret, angle(rightendpoint(d)-z₀)) +# elseif z₀ ≈ rightendpoint(d) +# push!(ret, angle(leftendpoint(d)-z₀)) +# else +# throw(ArgumentError("Must contain")) +# end +# end +# ret +# end + +# function productcondition(G, z₀) +# Gs = filter(g -> z₀ ∈ domain(g), pieces(G)) +# p = sortperm( unorientedangles(domain.(Gs), z₀)) + +# g₀ = Matrix{ComplexF64}(I, size(G)) +# for g in Gs[p] +# if leftendpoint(domain(g)) ≈ z₀ +# g₀ = g₀ * first(g) +# else +# g₀ = g₀ * inv(last(g)) +# end +# end +# g₀ +# end + +# function productcondition(G) +# error("Implement") +# end end #module diff --git a/test/runtests.jl b/test/runtests.jl index 89e407d..c03c775 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,760 +1,785 @@ -using ApproxFun, SingularIntegralEquations, DualNumbers, RiemannHilbert, LinearAlgebra, FastTransforms, SpecialFunctions, Test -import ApproxFunBase: ArraySpace, pieces, dotu, interlace -import RiemannHilbert: RiemannDual, LogNumber, fpstieltjesmatrix!, fpstieltjesmatrix, orientedleftendpoint, orientedrightendpoint, finitepart, fpcauchymatrix, collocationvalues, collocationpoints -import SingularIntegralEquations: stieltjesmoment, stieltjesmoment!, undirected, Directed, ⁺, ⁻, istieltjes -import SingularIntegralEquations.HypergeometricFunctions: speciallog - - -@testset "RiemannDual" begin - for h in (0.1,0.01), a in (2exp(0.1im),1.1) - @test log(RiemannDual(0,a))(h) ≈ log(h*a) - @test log(RiemannDual(Inf,a))(h) ≈ log(a/h) - end - - for h in (0.1,0.01), a in (2exp(0.1im),1.1) - @test log1p(RiemannDual(-1,a))(h) ≈ log(h*a) - @test log1p(RiemannDual(Inf,a))(h) ≈ log(a/h) - end - - - h = 0.0000001 - for z in (RiemannDual(-1,-1), RiemannDual(1,1), RiemannDual(-1,2exp(0.1im)), RiemannDual(1,2exp(0.1im))), - k = 0:1 - l = stieltjesjacobimoment(0,0,k,z) - @test l(h) ≈ stieltjesjacobimoment(0,0,k,realpart(z)+epsilon(z)h) atol=1E-5 - end - - h=0.0001 - for z in (RiemannDual(1,3exp(0.2im)), RiemannDual(1,0.5exp(-1.3im)), - RiemannDual(-1,3exp(0.2im)), RiemannDual(-1,0.5exp(-1.3im)), - RiemannDual(-1,1), RiemannDual(1,-1)) - @test atanh(z)(h) ≈ atanh(realpart(z)+epsilon(z)h) atol = 1E-4 - end - - z = RiemannDual(1,-0.25) - h = 0.0000001 - @test speciallog(z)(h) ≈ speciallog(realpart(z)+epsilon(z)h) atol=1E-4 - - h = 0.00001 - for z in (RiemannDual(-1,-1), RiemannDual(-1,exp(0.1im)), RiemannDual(-1,exp(-0.1im))) - @test stieltjesjacobimoment(0.5,0,0,z)(h) ≈ stieltjesjacobimoment(0.5,0,0,realpart(z)+epsilon(z)h) atol=1E-4 - end -end - -@testset "Legendre Cauchy" begin - f = Fun(exp,Legendre()) - - h = 0.00001 - for z in (RiemannDual(-1,-1), RiemannDual(-1,1+im), RiemannDual(-1,1-im)) - @test cauchy(f, z)(h) ≈ cauchy(f, realpart(z) + epsilon(z)h) atol=1E-4 - end -end - -@testset "Directed and RiemannDual" begin - @test undirected(Directed{false}(RiemannDual(0,-1))) == 0 - - @test real(LogNumber(2im,im+1)) == LogNumber(0,1) - @test imag(LogNumber(2im,im+1)) == LogNumber(2,1) - @test conj(LogNumber(2im,im+1)) == LogNumber(-2im,1-im) - - @test log(Directed{false}(RiemannDual(0,-1))) == LogNumber(1,π*im) - @test log(Directed{true}(RiemannDual(0,-1))) == LogNumber(1,-π*im) - - @test log(Directed{false}(RiemannDual(0,-1-eps()*im))) == LogNumber(1,π*im) - @test log(Directed{false}(RiemannDual(0,-1+eps()*im))) == LogNumber(1,π*im) - - @test log(Directed{true}(RiemannDual(0,-1-eps()*im))) == LogNumber(1,-π*im) - @test log(Directed{true}(RiemannDual(0,-1+eps()*im))) == LogNumber(1,-π*im) - - - z = Directed{false}(RiemannDual(1,-2)) - - for k=0:1, s=(false,true) - z = Directed{s}(RiemannDual(-1,2)) - l = stieltjesmoment(Legendre(),k,z) - h = 0.00000001 - @test l(h) ≈ stieltjesmoment(Legendre(),k,-1 + epsilon(z.x)h + (s ? 1 : -1)*eps()*im) atol=1E-5 - end +using PowerNumbers, SingularIntegrals, ClassicalOrthogonalPolynomials, Test - @test RiemannHilbert.orientedleftendpoint(ChebyshevInterval()) == RiemannDual(-1.0,1) - @test RiemannHilbert.orientedrightendpoint(ChebyshevInterval()) == RiemannDual(1.0,-1) -end +ε = PowerNumber(1, 1) +w = LegendreWeight() +@test stieltjes(w, 2+ε) isa LogNumber +@test stieltjes(w, 2+ε) ≈ stieltjes(w, 2) +@test stieltjes(w, 1+ε) == LogNumber(-1, log(2)) -@testset "Interval FPStieltjes" begin - Γ = ChebyshevInterval() - f = Fun(x->exp(-40(x-0.1)^2), Legendre()) - C = Array{ComplexF64}(undef, ncoefficients(f), ncoefficients(f)) - d = Segment(im,2im) - - fpstieltjesmatrix!(C, space(f), d) - c = Fun(d, chebyshevtransform(C*coefficients(f); kind=2)) - @test c(1.5im) ≈ stieltjes(f,1.5im) - - d = Segment(-1,-1+im) - fpstieltjesmatrix!(C, space(f), d) - @test norm(C) ≤ 100 - c = Fun(d, chebyshevtransform(C*coefficients(f); kind=2)) - @test c(-1+0.5im) ≈ stieltjes(f,-1+0.5im) - - d = Segment(1,1+im) - fpstieltjesmatrix!(C, space(f), d) - @test norm(C) ≤ 200 - c = Fun(d, chebyshevtransform(C*coefficients(f); kind=2)) - @test c(1+0.5im) ≈ stieltjes(f,1+0.5im) - - d = ChebyshevInterval() - fpstieltjesmatrix!(C, space(f), d) - @test norm(C) ≤ 200 - c = Fun(d, chebyshevtransform(C*coefficients(f); kind=2)) - @test c(0.5) ≈ stieltjes(f,0.5⁻) - - - d = Segment(0,1) - f = Fun(x->exp(-200(x-0.6)^2), Legendre(d)) - C = fpstieltjesmatrix(space(f), ncoefficients(f), ncoefficients(f)) - @test norm(C) ≤ 200 - c = Fun(d, chebyshevtransform(C*coefficients(f); kind=2)) - @test c(0.5) ≈ stieltjes(f,0.5⁻) +let h = 0.0000001 + @test stieltjes(w, 1+ε)(h) == -log(h) + log(2) end -@testset "finitepart stieltjes" begin - f = Fun(exp,Legendre()) - f1 = Fun(exp,Legendre(-1..0)) - f2 = Fun(exp,Legendre(0..1)) - fp = f1+f2 - @test stieltjes(f,0.0⁻) ≈ finitepart(stieltjes(f1,RiemannDual(0.0,-im)) + stieltjes(f2,RiemannDual(0.0,-im))) - @test stieltjes(f,0.0⁻) ≈ finitepart(stieltjes(f1,RiemannDual(0.0,exp(-0.1im))) + stieltjes(f2,RiemannDual(0.0,exp(-0.1im)))) - @test stieltjes(f,0.0⁻) ≈ finitepart(stieltjes(f1,Directed{false}(RiemannDual(0.0,-1.0))) + stieltjes(f2,RiemannDual(0.0,-1.0))) +w = ChebyshevTWeight() +@test stieltjes(w, 2+ε) isa PowerNumber +@test_broken stieltjes(w, 2+ε) ≈ stieltjes(w, 2) +@test stieltjes(w, 1+ε) == PowerNumber(π/sqrt(2), -1/2 +@test stieltjes(w, 1+ε)+2 == PowerNumber(π/sqrt(2), 2, -1/2, 0) # TODO: This should include constant term. Need to fix in PowerNumbers.jl - @test stieltjes(fp,RiemannDual(0.0,-im)) ≈ stieltjes(f1,RiemannDual(0.0,-im)) + stieltjes(f2,RiemannDual(0.0,-im)) - @test stieltjes(f,0.0⁻) ≈ finitepart(stieltjes(fp,RiemannDual(0.0,-im))) -end +stieltjes(Legendre(), 2+ε) ## TODO: make work +stieltjes(Weighted(ChebyshevT()), 2+ε) ## TODO: make work (probably too hard) +stieltjes(Weighted(ChebyshevT()), 1+ε) ## TODO: Add tests to see if it worked -@testset "Two interval" begin - @testset "-1..0 and 0..1" begin - sp = Legendre(-1 .. 0) ⊕ Legendre(0 .. 1) - f = Fun(x->exp(-40(x-0.1)^2), sp) - v = components(f) - ns = ncoefficients.(v) - C11 = fpstieltjesmatrix(space(v[1]), ncoefficients(v[1]), ncoefficients(v[1])) - c_vals11 = C11*v[1].coefficients - h = 0.00000001; @test stieltjes(v[1],h*im) ≈ stieltjes(v[1],RiemannDual(0.0,im))(h) atol=1E-6 - @test finitepart(stieltjes(v[1],Directed{false}(RiemannDual(0.0,-1)))) ≈ c_vals11[1] - C22 = fpstieltjesmatrix(space(v[2]), ncoefficients(v[2]), ncoefficients(v[2])) - c_vals22 = C22*v[2].coefficients - h = 0.00000001; @test stieltjes(v[2],h*im) ≈ stieltjes(v[2],RiemannDual(0.0,im))(h) atol=1E-6 - @test finitepart(stieltjes(v[2],Directed{false}(RiemannDual(0.0,1)))) ≈ c_vals22[end] +# using ApproxFun, SingularIntegralEquations, DualNumbers, RiemannHilbert, LinearAlgebra, FastTransforms, SpecialFunctions, Test +# import ApproxFunBase: ArraySpace, pieces, dotu, interlace +# import RiemannHilbert: RiemannDual, LogNumber, fpstieltjesmatrix!, fpstieltjesmatrix, orientedleftendpoint, orientedrightendpoint, finitepart, fpcauchymatrix, collocationvalues, collocationpoints +# import SingularIntegralEquations: stieltjesmoment, stieltjesmoment!, undirected, Directed, ⁺, ⁻, istieltjes +# import SingularIntegralEquations.HypergeometricFunctions: speciallog - C12 = fpstieltjesmatrix(space(v[2]), domain(v[1]), ncoefficients(v[1]), ncoefficients(v[2])) - c_vals12 = C12*v[2].coefficients - h = 0.00000001; @test stieltjes(v[2],-h) ≈ stieltjes(v[2],RiemannDual(0.0,-1))(h) atol=1E-6 - @test finitepart(stieltjes(v[2],RiemannDual(0.0,-1))) ≈ c_vals12[1] - C = fpstieltjesmatrix(space(f), ns, ns) - @test norm(C) ≤ 200 +# @testset "RiemannDual" begin +# for h in (0.1,0.01), a in (2exp(0.1im),1.1) +# @test log(RiemannDual(0,a))(h) ≈ log(h*a) +# @test log(RiemannDual(Inf,a))(h) ≈ log(a/h) +# end - @test C[1:ns[1],1:2:end] == C11 +# for h in (0.1,0.01), a in (2exp(0.1im),1.1) +# @test log1p(RiemannDual(-1,a))(h) ≈ log(h*a) +# @test log1p(RiemannDual(Inf,a))(h) ≈ log(a/h) +# end - c_vals = C*coefficients(f) - pts = RiemannHilbert.collocationpoints(space(f), ns) - f_ex = Fun(x->exp(-40(x-0.1)^2), Legendre()) - @test stieltjes(f_ex, Directed{false}(0.0)) ≈ finitepart(stieltjes(f,Directed{false}(RiemannDual(0.0,-im)))) - @test finitepart(stieltjes(v[1],RiemannDual(0.0,-im))+stieltjes(v[2],RiemannDual(0.0,-im))) ≈ stieltjes(f_ex,Directed{false}(0.0)) +# h = 0.0000001 +# for z in (RiemannDual(-1,-1), RiemannDual(1,1), RiemannDual(-1,2exp(0.1im)), RiemannDual(1,2exp(0.1im))), +# k = 0:1 +# l = stieltjesjacobimoment(0,0,k,z) +# @test l(h) ≈ stieltjesjacobimoment(0,0,k,realpart(z)+epsilon(z)h) atol=1E-5 +# end + +# h=0.0001 +# for z in (RiemannDual(1,3exp(0.2im)), RiemannDual(1,0.5exp(-1.3im)), +# RiemannDual(-1,3exp(0.2im)), RiemannDual(-1,0.5exp(-1.3im)), +# RiemannDual(-1,1), RiemannDual(1,-1)) +# @test atanh(z)(h) ≈ atanh(realpart(z)+epsilon(z)h) atol = 1E-4 +# end + +# z = RiemannDual(1,-0.25) +# h = 0.0000001 +# @test speciallog(z)(h) ≈ speciallog(realpart(z)+epsilon(z)h) atol=1E-4 + +# h = 0.00001 +# for z in (RiemannDual(-1,-1), RiemannDual(-1,exp(0.1im)), RiemannDual(-1,exp(-0.1im))) +# @test stieltjesjacobimoment(0.5,0,0,z)(h) ≈ stieltjesjacobimoment(0.5,0,0,realpart(z)+epsilon(z)h) atol=1E-4 +# end +# end + +# @testset "Legendre Cauchy" begin +# f = Fun(exp,Legendre()) + +# h = 0.00001 +# for z in (RiemannDual(-1,-1), RiemannDual(-1,1+im), RiemannDual(-1,1-im)) +# @test cauchy(f, z)(h) ≈ cauchy(f, realpart(z) + epsilon(z)h) atol=1E-4 +# end +# end + +# @testset "Directed and RiemannDual" begin +# @test undirected(Directed{false}(RiemannDual(0,-1))) == 0 + +# @test real(LogNumber(2im,im+1)) == LogNumber(0,1) +# @test imag(LogNumber(2im,im+1)) == LogNumber(2,1) +# @test conj(LogNumber(2im,im+1)) == LogNumber(-2im,1-im) + +# @test log(Directed{false}(RiemannDual(0,-1))) == LogNumber(1,π*im) +# @test log(Directed{true}(RiemannDual(0,-1))) == LogNumber(1,-π*im) + +# @test log(Directed{false}(RiemannDual(0,-1-eps()*im))) == LogNumber(1,π*im) +# @test log(Directed{false}(RiemannDual(0,-1+eps()*im))) == LogNumber(1,π*im) + +# @test log(Directed{true}(RiemannDual(0,-1-eps()*im))) == LogNumber(1,-π*im) +# @test log(Directed{true}(RiemannDual(0,-1+eps()*im))) == LogNumber(1,-π*im) + + +# z = Directed{false}(RiemannDual(1,-2)) + +# for k=0:1, s=(false,true) +# z = Directed{s}(RiemannDual(-1,2)) +# l = stieltjesmoment(Legendre(),k,z) +# h = 0.00000001 +# @test l(h) ≈ stieltjesmoment(Legendre(),k,-1 + epsilon(z.x)h + (s ? 1 : -1)*eps()*im) atol=1E-5 +# end + + +# @test RiemannHilbert.orientedleftendpoint(ChebyshevInterval()) == RiemannDual(-1.0,1) +# @test RiemannHilbert.orientedrightendpoint(ChebyshevInterval()) == RiemannDual(1.0,-1) +# end + +# @testset "Interval FPStieltjes" begin +# Γ = ChebyshevInterval() +# f = Fun(x->exp(-40(x-0.1)^2), Legendre()) +# C = Array{ComplexF64}(undef, ncoefficients(f), ncoefficients(f)) +# d = Segment(im,2im) + +# fpstieltjesmatrix!(C, space(f), d) +# c = Fun(d, chebyshevtransform(C*coefficients(f); kind=2)) +# @test c(1.5im) ≈ stieltjes(f,1.5im) + +# d = Segment(-1,-1+im) +# fpstieltjesmatrix!(C, space(f), d) +# @test norm(C) ≤ 100 +# c = Fun(d, chebyshevtransform(C*coefficients(f); kind=2)) +# @test c(-1+0.5im) ≈ stieltjes(f,-1+0.5im) - @test c_vals[1] ≈ finitepart(stieltjes(f,Directed{false}(RiemannDual(0.0,-im)))) - @test c_vals[1] ≈ finitepart(stieltjes(f,Directed{false}(RiemannDual(0.0,exp(-0.1im))))) - @test c_vals[1] ≈ finitepart(stieltjes(f,RiemannDual(0.0,-im))) - @test c_vals[2:ns[1]-1] ≈ stieltjes.(f,pts[2:ns[1]-1]⁻) - @test c_vals[ns[1]] ≈ finitepart(stieltjes(f,RiemannDual(-1.0,-1.0))) +# d = Segment(1,1+im) +# fpstieltjesmatrix!(C, space(f), d) +# @test norm(C) ≤ 200 +# c = Fun(d, chebyshevtransform(C*coefficients(f); kind=2)) +# @test c(1+0.5im) ≈ stieltjes(f,1+0.5im) - @test c_vals[ns[1]+1] ≈ finitepart(stieltjes(f,RiemannDual(1.0,1.0))) - @test c_vals[ns[1]+2:end-1] ≈ stieltjes.(f,pts[ns[1]+2:end-1]⁻) - @test c_vals[end] ≈ finitepart(stieltjes(f,RiemannDual(0.0,-im))) +# d = ChebyshevInterval() +# fpstieltjesmatrix!(C, space(f), d) +# @test norm(C) ≤ 200 +# c = Fun(d, chebyshevtransform(C*coefficients(f); kind=2)) +# @test c(0.5) ≈ stieltjes(f,0.5⁻) - h =0.00001 - @test stieltjes(v[1], Directed{false}(RiemannDual(0.0,-1.0))) ≈ stieltjes(v[1], RiemannDual(0.0,-1.0-eps()*im)) - @test finitepart(stieltjes(v[1], Directed{false}(RiemannDual(0.0,-1.0)))+ stieltjes(v[2], RiemannDual(0.0,-1.0))) ≈ - stieltjes(v[1], -0.00000000001im)+stieltjes(v[2], -0.00000000001im) +# d = Segment(0,1) +# f = Fun(x->exp(-200(x-0.6)^2), Legendre(d)) +# C = fpstieltjesmatrix(space(f), ncoefficients(f), ncoefficients(f)) +# @test norm(C) ≤ 200 +# c = Fun(d, chebyshevtransform(C*coefficients(f); kind=2)) +# @test c(0.5) ≈ stieltjes(f,0.5⁻) +# end + +# @testset "finitepart stieltjes" begin +# f = Fun(exp,Legendre()) +# f1 = Fun(exp,Legendre(-1..0)) +# f2 = Fun(exp,Legendre(0..1)) +# fp = f1+f2 + +# @test stieltjes(f,0.0⁻) ≈ finitepart(stieltjes(f1,RiemannDual(0.0,-im)) + stieltjes(f2,RiemannDual(0.0,-im))) +# @test stieltjes(f,0.0⁻) ≈ finitepart(stieltjes(f1,RiemannDual(0.0,exp(-0.1im))) + stieltjes(f2,RiemannDual(0.0,exp(-0.1im)))) +# @test stieltjes(f,0.0⁻) ≈ finitepart(stieltjes(f1,Directed{false}(RiemannDual(0.0,-1.0))) + stieltjes(f2,RiemannDual(0.0,-1.0))) + +# @test stieltjes(fp,RiemannDual(0.0,-im)) ≈ stieltjes(f1,RiemannDual(0.0,-im)) + stieltjes(f2,RiemannDual(0.0,-im)) +# @test stieltjes(f,0.0⁻) ≈ finitepart(stieltjes(fp,RiemannDual(0.0,-im))) +# end +# @testset "Two interval" begin +# @testset "-1..0 and 0..1" begin +# sp = Legendre(-1 .. 0) ⊕ Legendre(0 .. 1) +# f = Fun(x->exp(-40(x-0.1)^2), sp) +# v = components(f) +# ns = ncoefficients.(v) +# C11 = fpstieltjesmatrix(space(v[1]), ncoefficients(v[1]), ncoefficients(v[1])) +# c_vals11 = C11*v[1].coefficients +# h = 0.00000001; @test stieltjes(v[1],h*im) ≈ stieltjes(v[1],RiemannDual(0.0,im))(h) atol=1E-6 +# @test finitepart(stieltjes(v[1],Directed{false}(RiemannDual(0.0,-1)))) ≈ c_vals11[1] - @test finitepart(stieltjes(v[1], Directed{false}(RiemannDual(0.0,-1.0)))+ stieltjes(v[2], RiemannDual(0.0,-1.0))) ≈ - stieltjes(f, -0.00000000001im) +# C22 = fpstieltjesmatrix(space(v[2]), ncoefficients(v[2]), ncoefficients(v[2])) +# c_vals22 = C22*v[2].coefficients +# h = 0.00000001; @test stieltjes(v[2],h*im) ≈ stieltjes(v[2],RiemannDual(0.0,im))(h) atol=1E-6 +# @test finitepart(stieltjes(v[2],Directed{false}(RiemannDual(0.0,1)))) ≈ c_vals22[end] - @test c_vals[1] ≈ stieltjes(f, -0.0000000001im) - @test c_vals[end] ≈ stieltjes(f, -0.0000000001im) +# C12 = fpstieltjesmatrix(space(v[2]), domain(v[1]), ncoefficients(v[1]), ncoefficients(v[2])) +# c_vals12 = C12*v[2].coefficients +# h = 0.00000001; @test stieltjes(v[2],-h) ≈ stieltjes(v[2],RiemannDual(0.0,-1))(h) atol=1E-6 +# @test finitepart(stieltjes(v[2],RiemannDual(0.0,-1))) ≈ c_vals12[1] - @test finitepart(stieltjes(f, RiemannDual(0.0,-im))) ≈ - finitepart(stieltjes(v[1], RiemannDual(0.0,-im))+stieltjes(v[2], RiemannDual(0.0,-im))) +# C = fpstieltjesmatrix(space(f), ns, ns) +# @test norm(C) ≤ 200 +# @test C[1:ns[1],1:2:end] == C11 - C11 = fpstieltjesmatrix(space(v[1]), ncoefficients(v[1]), ncoefficients(v[1])) - C12 = fpstieltjesmatrix(space(v[2]), domain(v[1]), ncoefficients(v[1]), ncoefficients(v[2])) +# c_vals = C*coefficients(f) +# pts = RiemannHilbert.collocationpoints(space(f), ns) - @test finitepart(stieltjes(v[1], Directed{false}(RiemannDual(0.0,-1.0)))) ≈ (C11*coefficients(v[1]))[1] - @test finitepart(stieltjes(v[2], RiemannDual(0.0,-1.0))) ≈ dotu(stieltjesmoment!(Array{ComplexF64}(undef,ncoefficients(v[2])), space(v[2]), orientedrightendpoint(domain(v[1])), finitepart), - coefficients(v[2])) +# f_ex = Fun(x->exp(-40(x-0.1)^2), Legendre()) +# @test stieltjes(f_ex, Directed{false}(0.0)) ≈ finitepart(stieltjes(f,Directed{false}(RiemannDual(0.0,-im)))) +# @test finitepart(stieltjes(v[1],RiemannDual(0.0,-im))+stieltjes(v[2],RiemannDual(0.0,-im))) ≈ stieltjes(f_ex,Directed{false}(0.0)) - @test C12[1,:] ≈ stieltjesmoment!(Array{ComplexF64}(undef,ncoefficients(v[2])), space(v[2]), orientedrightendpoint(domain(v[1])), finitepart) +# @test c_vals[1] ≈ finitepart(stieltjes(f,Directed{false}(RiemannDual(0.0,-im)))) +# @test c_vals[1] ≈ finitepart(stieltjes(f,Directed{false}(RiemannDual(0.0,exp(-0.1im))))) +# @test c_vals[1] ≈ finitepart(stieltjes(f,RiemannDual(0.0,-im))) +# @test c_vals[2:ns[1]-1] ≈ stieltjes.(f,pts[2:ns[1]-1]⁻) +# @test c_vals[ns[1]] ≈ finitepart(stieltjes(f,RiemannDual(-1.0,-1.0))) + +# @test c_vals[ns[1]+1] ≈ finitepart(stieltjes(f,RiemannDual(1.0,1.0))) +# @test c_vals[ns[1]+2:end-1] ≈ stieltjes.(f,pts[ns[1]+2:end-1]⁻) +# @test c_vals[end] ≈ finitepart(stieltjes(f,RiemannDual(0.0,-im))) - @test finitepart(stieltjes(v[2], RiemannDual(0.0,-1.0))) ≈ (C12*coefficients(v[2]))[1] - @test C[1,:] ≈ interlace(C11[1,:], C12[1,:]) - end +# h =0.00001 +# @test stieltjes(v[1], Directed{false}(RiemannDual(0.0,-1.0))) ≈ stieltjes(v[1], RiemannDual(0.0,-1.0-eps()*im)) + +# @test finitepart(stieltjes(v[1], Directed{false}(RiemannDual(0.0,-1.0)))+ stieltjes(v[2], RiemannDual(0.0,-1.0))) ≈ +# stieltjes(v[1], -0.00000000001im)+stieltjes(v[2], -0.00000000001im) + + +# @test finitepart(stieltjes(v[1], Directed{false}(RiemannDual(0.0,-1.0)))+ stieltjes(v[2], RiemannDual(0.0,-1.0))) ≈ +# stieltjes(f, -0.00000000001im) + +# @test c_vals[1] ≈ stieltjes(f, -0.0000000001im) +# @test c_vals[end] ≈ stieltjes(f, -0.0000000001im) + +# @test finitepart(stieltjes(f, RiemannDual(0.0,-im))) ≈ +# finitepart(stieltjes(v[1], RiemannDual(0.0,-im))+stieltjes(v[2], RiemannDual(0.0,-im))) + + +# C11 = fpstieltjesmatrix(space(v[1]), ncoefficients(v[1]), ncoefficients(v[1])) +# C12 = fpstieltjesmatrix(space(v[2]), domain(v[1]), ncoefficients(v[1]), ncoefficients(v[2])) - @testset "0..1 and 0..1" begin - sp = Legendre(Segment(0 , -1)) ⊕ Legendre(0 .. 1) +# @test finitepart(stieltjes(v[1], Directed{false}(RiemannDual(0.0,-1.0)))) ≈ (C11*coefficients(v[1]))[1] +# @test finitepart(stieltjes(v[2], RiemannDual(0.0,-1.0))) ≈ dotu(stieltjesmoment!(Array{ComplexF64}(undef,ncoefficients(v[2])), space(v[2]), orientedrightendpoint(domain(v[1])), finitepart), +# coefficients(v[2])) - f = Fun(x->sign(x)*exp(-40(x-0.1)^2), sp) - v = components(f) - ns = ncoefficients.(v) - C = fpstieltjesmatrix(space(f), ns, ns) - @test norm(C) ≤ 200 - c_vals = C*coefficients(f) - pts = RiemannHilbert.collocationpoints(space(f), ns) +# @test C12[1,:] ≈ stieltjesmoment!(Array{ComplexF64}(undef,ncoefficients(v[2])), space(v[2]), orientedrightendpoint(domain(v[1])), finitepart) - @test stieltjes(f,-1-eps()) ≈ stieltjes(f,RiemannDual(-1.0,-1.0)).c - @test c_vals[1] ≈ finitepart(stieltjes(f,RiemannDual(-1.0,-1.0))) - @test c_vals[2:ns[1]-1] ≈ stieltjes.(f,pts[2:ns[1]-1]⁻) - @test c_vals[ns[1]] ≈ finitepart(stieltjes(f,RiemannDual(0.0,+im))) - @test c_vals[ns[1]+1] ≈ finitepart(stieltjes(f,RiemannDual(1.0,1.0))) - @test c_vals[ns[1]+2:end-1] ≈ stieltjes.(f,pts[ns[1]+2:end-1]⁻) - @test c_vals[end] ≈ finitepart(stieltjes(f,RiemannDual(0.0,-im))) +# @test finitepart(stieltjes(v[2], RiemannDual(0.0,-1.0))) ≈ (C12*coefficients(v[2]))[1] +# @test C[1,:] ≈ interlace(C11[1,:], C12[1,:]) +# end +# @testset "0..1 and 0..1" begin +# sp = Legendre(Segment(0 , -1)) ⊕ Legendre(0 .. 1) - h =0.00001 - @test stieltjes(v[1], Directed{false}(RiemannDual(0.0,-1.0))) ≈ stieltjes(v[1], RiemannDual(0.0,-1.0+eps()*im)) - @test stieltjes(v[1], Directed{true}(RiemannDual(0.0,-1.0))) ≈ stieltjes(v[1], RiemannDual(0.0,-1.0-eps()*im)) +# f = Fun(x->sign(x)*exp(-40(x-0.1)^2), sp) +# v = components(f) +# ns = ncoefficients.(v) +# C = fpstieltjesmatrix(space(f), ns, ns) +# @test norm(C) ≤ 200 +# c_vals = C*coefficients(f) +# pts = RiemannHilbert.collocationpoints(space(f), ns) - @test stieltjes(v[2], RiemannDual(0.0,-1.0))(h) ≈ stieltjes(v[2], -h) atol=1E-3 +# @test stieltjes(f,-1-eps()) ≈ stieltjes(f,RiemannDual(-1.0,-1.0)).c +# @test c_vals[1] ≈ finitepart(stieltjes(f,RiemannDual(-1.0,-1.0))) +# @test c_vals[2:ns[1]-1] ≈ stieltjes.(f,pts[2:ns[1]-1]⁻) +# @test c_vals[ns[1]] ≈ finitepart(stieltjes(f,RiemannDual(0.0,+im))) +# @test c_vals[ns[1]+1] ≈ finitepart(stieltjes(f,RiemannDual(1.0,1.0))) +# @test c_vals[ns[1]+2:end-1] ≈ stieltjes.(f,pts[ns[1]+2:end-1]⁻) +# @test c_vals[end] ≈ finitepart(stieltjes(f,RiemannDual(0.0,-im))) - @test stieltjes(v[1], Directed{true}(RiemannDual(0.0,-1.0)))(h) ≈ stieltjes(v[1], -h-eps()*im) atol=1E-3 +# h =0.00001 +# @test stieltjes(v[1], Directed{false}(RiemannDual(0.0,-1.0))) ≈ stieltjes(v[1], RiemannDual(0.0,-1.0+eps()*im)) +# @test stieltjes(v[1], Directed{true}(RiemannDual(0.0,-1.0))) ≈ stieltjes(v[1], RiemannDual(0.0,-1.0-eps()*im)) - @test finitepart(stieltjes(v[1], Directed{true}(RiemannDual(0.0,-1.0)))+ stieltjes(v[2], RiemannDual(0.0,-1.0))) ≈ - stieltjes(v[1], -0.00000000001im)+stieltjes(v[2], -0.00000000001im) +# @test stieltjes(v[2], RiemannDual(0.0,-1.0))(h) ≈ stieltjes(v[2], -h) atol=1E-3 +# @test stieltjes(v[1], Directed{true}(RiemannDual(0.0,-1.0)))(h) ≈ stieltjes(v[1], -h-eps()*im) atol=1E-3 - @test finitepart(stieltjes(v[1], Directed{true}(RiemannDual(0.0,-1.0)))+ stieltjes(v[2], RiemannDual(0.0,-1.0))) ≈ - stieltjes(f, -0.00000000001im) - @test c_vals[ns[1]] ≈ stieltjes(f, +0.0000000001im) - @test c_vals[end] ≈ stieltjes(f, -0.0000000001im) - end +# @test finitepart(stieltjes(v[1], Directed{true}(RiemannDual(0.0,-1.0)))+ stieltjes(v[2], RiemannDual(0.0,-1.0))) ≈ +# stieltjes(v[1], -0.00000000001im)+stieltjes(v[2], -0.00000000001im) - @testset "-1..0 and 0..1" begin - sp = Legendre(-1 .. 0) ⊕ Legendre(0 .. 1) - f = Fun(x->exp(-40(x-0.1)^2), sp) - v = components(f) - ns = ncoefficients.(v) - C = fpstieltjesmatrix(space(f), ns, ns) - @test norm(C) ≤ 200 - c_vals = C*coefficients(f) - pts = RiemannHilbert.collocationpoints(space(f), ns) +# @test finitepart(stieltjes(v[1], Directed{true}(RiemannDual(0.0,-1.0)))+ stieltjes(v[2], RiemannDual(0.0,-1.0))) ≈ +# stieltjes(f, -0.00000000001im) - @test c_vals[1] ≈ finitepart(stieltjes(f,RiemannDual(0.0,-im))) - @test c_vals[2:ns[1]-1] ≈ stieltjes.(f,pts[2:ns[1]-1]⁻) - @test c_vals[ns[1]] ≈ finitepart(stieltjes(f,RiemannDual(-1.0,-1.0))) - @test c_vals[ns[1]+1] ≈ finitepart(stieltjes(f,RiemannDual(1.0,1.0))) - @test c_vals[ns[1]+2:end-1] ≈ stieltjes.(f,pts[ns[1]+2:end-1]⁻) - @test c_vals[end] ≈ finitepart(stieltjes(f,RiemannDual(0.0,-im))) - end -end +# @test c_vals[ns[1]] ≈ stieltjes(f, +0.0000000001im) +# @test c_vals[end] ≈ stieltjes(f, -0.0000000001im) +# end -@testset "ArraySpace" begin - sp = ArraySpace(Legendre() ,2) - f = Fun(x->[exp(-40(x-0.1)^2); cos(x-0.1)*exp(-40(x-0.1)^2)], sp) - ns = ncoefficients.(Array(f)) - C = fpstieltjesmatrix(sp, ns, ns) - C1 = fpstieltjesmatrix(sp[1], ns[1], ns[1]) - C2 = fpstieltjesmatrix(sp[2], ns[2], ns[2]) +# @testset "-1..0 and 0..1" begin +# sp = Legendre(-1 .. 0) ⊕ Legendre(0 .. 1) +# f = Fun(x->exp(-40(x-0.1)^2), sp) +# v = components(f) +# ns = ncoefficients.(v) +# C = fpstieltjesmatrix(space(f), ns, ns) +# @test norm(C) ≤ 200 - @test C*coefficients(f) ≈ [C1*coefficients(f[1]) ; C2*coefficients(f[2])] +# c_vals = C*coefficients(f) +# pts = RiemannHilbert.collocationpoints(space(f), ns) - sp = ArraySpace(Legendre(), 2, 2) - f = Fun(x->[exp(-40(x-0.1)^2) sin(x-0.1)exp(-40(x-0.1)^2); cos(x-0.1)*exp(-40(x-0.1)^2) airyai(x-0.1)*exp(-40(x-0.1)^2)], sp) - ns = ncoefficients.(Array(f)) - C = fpstieltjesmatrix(sp, ns, ns) - C11 = fpstieltjesmatrix(sp[1,1], ns[1,1], ns[1,1]) - C21 = fpstieltjesmatrix(sp[2,1], ns[2,1], ns[2,1]) - C12 = fpstieltjesmatrix(sp[1,2], ns[1,2], ns[1,2]) - C22 = fpstieltjesmatrix(sp[2,2], ns[2,2], ns[2,2]) +# @test c_vals[1] ≈ finitepart(stieltjes(f,RiemannDual(0.0,-im))) +# @test c_vals[2:ns[1]-1] ≈ stieltjes.(f,pts[2:ns[1]-1]⁻) +# @test c_vals[ns[1]] ≈ finitepart(stieltjes(f,RiemannDual(-1.0,-1.0))) +# @test c_vals[ns[1]+1] ≈ finitepart(stieltjes(f,RiemannDual(1.0,1.0))) +# @test c_vals[ns[1]+2:end-1] ≈ stieltjes.(f,pts[ns[1]+2:end-1]⁻) +# @test c_vals[end] ≈ finitepart(stieltjes(f,RiemannDual(0.0,-im))) +# end +# end - @test C[1:ns[1], 1:4:end] ≈ C11 - @test norm(C[1:ns[1], 2:4:end]) ≤ 100eps() - @test norm(C[1:ns[1], 3:4:end]) ≤ 100eps() - @test norm(C[1:ns[1], 4:4:end]) ≤ 100eps() +# @testset "ArraySpace" begin +# sp = ArraySpace(Legendre() ,2) +# f = Fun(x->[exp(-40(x-0.1)^2); cos(x-0.1)*exp(-40(x-0.1)^2)], sp) +# ns = ncoefficients.(Array(f)) +# C = fpstieltjesmatrix(sp, ns, ns) +# C1 = fpstieltjesmatrix(sp[1], ns[1], ns[1]) +# C2 = fpstieltjesmatrix(sp[2], ns[2], ns[2]) - @test C[ns[1]+1:ns[1]+ns[2], 2:4:end] ≈ C21 +# @test C*coefficients(f) ≈ [C1*coefficients(f[1]) ; C2*coefficients(f[2])] - @test C*coefficients(f) ≈ [C11*coefficients(f[1,1]) ; C21*coefficients(f[2,1]) ; C12*coefficients(f[1,2]) ; C22*coefficients(f[2,2])] +# sp = ArraySpace(Legendre(), 2, 2) +# f = Fun(x->[exp(-40(x-0.1)^2) sin(x-0.1)exp(-40(x-0.1)^2); cos(x-0.1)*exp(-40(x-0.1)^2) airyai(x-0.1)*exp(-40(x-0.1)^2)], sp) +# ns = ncoefficients.(Array(f)) +# C = fpstieltjesmatrix(sp, ns, ns) +# C11 = fpstieltjesmatrix(sp[1,1], ns[1,1], ns[1,1]) +# C21 = fpstieltjesmatrix(sp[2,1], ns[2,1], ns[2,1]) +# C12 = fpstieltjesmatrix(sp[1,2], ns[1,2], ns[1,2]) +# C22 = fpstieltjesmatrix(sp[2,2], ns[2,2], ns[2,2]) +# @test C[1:ns[1], 1:4:end] ≈ C11 +# @test norm(C[1:ns[1], 2:4:end]) ≤ 100eps() +# @test norm(C[1:ns[1], 3:4:end]) ≤ 100eps() +# @test norm(C[1:ns[1], 4:4:end]) ≤ 100eps() - sp = ArraySpace(Legendre(-1 .. 0) ∪ Legendre(0 .. 1), 2) - f = Fun(x->[exp(-40(x-0.1)^2); cos(x-0.1)*exp(-40(x-0.1)^2)], sp) - ns = ncoefficients.(Array(f)) - C = fpstieltjesmatrix(sp, ns, ns) +# @test C[ns[1]+1:ns[1]+ns[2], 2:4:end] ≈ C21 - C1 = fpstieltjesmatrix(sp[1], ns[1], ns[1]) - C2 = fpstieltjesmatrix(sp[2], ns[2], ns[2]) +# @test C*coefficients(f) ≈ [C11*coefficients(f[1,1]) ; C21*coefficients(f[2,1]) ; C12*coefficients(f[1,2]) ; C22*coefficients(f[2,2])] - @test C*coefficients(f) ≈ [C1*coefficients(f[1]) ; C2*coefficients(f[2])] +# sp = ArraySpace(Legendre(-1 .. 0) ∪ Legendre(0 .. 1), 2) +# f = Fun(x->[exp(-40(x-0.1)^2); cos(x-0.1)*exp(-40(x-0.1)^2)], sp) +# ns = ncoefficients.(Array(f)) +# C = fpstieltjesmatrix(sp, ns, ns) - sp = ArraySpace(Legendre(-1 .. 0) ∪ Legendre(0 .. 1), 2, 2) - f = Fun(x->[exp(-40(x-0.1)^2) sin(x-0.1)exp(-40(x-0.1)^2); cos(x-0.1)*exp(-40(x-0.1)^2) airyai(x-0.1)*exp(-40(x-0.1)^2)], sp) - ns = ncoefficients.(Array(f)) - C = fpstieltjesmatrix(sp, ns, ns) +# C1 = fpstieltjesmatrix(sp[1], ns[1], ns[1]) +# C2 = fpstieltjesmatrix(sp[2], ns[2], ns[2]) - C11 = fpstieltjesmatrix(sp[1,1], ns[1,1], ns[1,1]) - C21 = fpstieltjesmatrix(sp[2,1], ns[2,1], ns[2,1]) - C12 = fpstieltjesmatrix(sp[1,2], ns[1,2], ns[1,2]) - C22 = fpstieltjesmatrix(sp[2,2], ns[2,2], ns[2,2]) - @test C*coefficients(f) ≈ [C11*coefficients(f[1,1]) ; C21*coefficients(f[2,1]) ; C12*coefficients(f[1,2]) ; C22*coefficients(f[2,2])] -end +# @test C*coefficients(f) ≈ [C1*coefficients(f[1]) ; C2*coefficients(f[2])] -@testset "rhsolve" begin - sp = Legendre() - g = 1-0.3Fun(x->exp(-40x^2), sp) - n = 2ncoefficients(g) - g_v = RiemannHilbert.collocationvalues(g-1, n) - u = Fun(sp, rhmatrix(g,n) \ g_v) +# sp = ArraySpace(Legendre(-1 .. 0) ∪ Legendre(0 .. 1), 2, 2) +# f = Fun(x->[exp(-40(x-0.1)^2) sin(x-0.1)exp(-40(x-0.1)^2); cos(x-0.1)*exp(-40(x-0.1)^2) airyai(x-0.1)*exp(-40(x-0.1)^2)], sp) +# ns = ncoefficients.(Array(f)) +# C = fpstieltjesmatrix(sp, ns, ns) - @testset "-1 .. 1" begin - n = 2ncoefficients(g) - g = pad(g,n) - C₋ = fpcauchymatrix(sp, n, n) - pts = RiemannHilbert.collocationpoints(sp, n) - @test C₋[2:end-1,:]*coefficients(g) ≈ cauchy.(g, pts[2:end-1]⁻) - g_v = RiemannHilbert.collocationvalues(g-1, n) - @test g_v ≈ g.(pts).-1 - G = Diagonal(g_v) +# C11 = fpstieltjesmatrix(sp[1,1], ns[1,1], ns[1,1]) +# C21 = fpstieltjesmatrix(sp[2,1], ns[2,1], ns[2,1]) +# C12 = fpstieltjesmatrix(sp[1,2], ns[1,2], ns[1,2]) +# C22 = fpstieltjesmatrix(sp[2,2], ns[2,2], ns[2,2]) - @test G*g_v ≈ (g.(pts) .- 1).^2 +# @test C*coefficients(f) ≈ [C11*coefficients(f[1,1]) ; C21*coefficients(f[2,1]) ; C12*coefficients(f[1,2]) ; C22*coefficients(f[2,2])] +# end - E = RiemannHilbert.evaluationmatrix(sp, pts, length(pts)) - @test E*coefficients(g) ≈ g.(pts) +# @testset "rhsolve" begin +# sp = Legendre() +# g = 1-0.3Fun(x->exp(-40x^2), sp) +# n = 2ncoefficients(g) +# g_v = RiemannHilbert.collocationvalues(g-1, n) +# u = Fun(sp, rhmatrix(g,n) \ g_v) - @test (g.(pts).-1).*(C₋*coefficients(g)) ≈ (g.(pts).-1).*cauchy.(g, pts.-0.000000001im) - @test G*(C₋*coefficients(g)) ≈ (g.(pts).-1).*cauchy.(g, pts.-0.000000001im) +# @testset "-1 .. 1" begin +# n = 2ncoefficients(g) +# g = pad(g,n) +# C₋ = fpcauchymatrix(sp, n, n) +# pts = RiemannHilbert.collocationpoints(sp, n) +# @test C₋[2:end-1,:]*coefficients(g) ≈ cauchy.(g, pts[2:end-1]⁻) +# g_v = RiemannHilbert.collocationvalues(g-1, n) +# @test g_v ≈ g.(pts).-1 +# G = Diagonal(g_v) - L = E - G*C₋ - @test L*coefficients(g) ≈ g.(pts) - (g.(pts).-1).*cauchy.(g, pts.-0.000000001im) +# @test G*g_v ≈ (g.(pts) .- 1).^2 - @test L == rhmatrix(g,n) +# E = RiemannHilbert.evaluationmatrix(sp, pts, length(pts)) +# @test E*coefficients(g) ≈ g.(pts) + +# @test (g.(pts).-1).*(C₋*coefficients(g)) ≈ (g.(pts).-1).*cauchy.(g, pts.-0.000000001im) +# @test G*(C₋*coefficients(g)) ≈ (g.(pts).-1).*cauchy.(g, pts.-0.000000001im) + +# L = E - G*C₋ +# @test L*coefficients(g) ≈ g.(pts) - (g.(pts).-1).*cauchy.(g, pts.-0.000000001im) + +# @test L == rhmatrix(g,n) - φ = z -> 1 + cauchy(u,z) - @test φ(0.1⁺) ≈ g(0.1)φ(0.1⁻) - - - @test 1+cauchy(u)(0.1+0.2im) ≈ φ(0.1+0.2im) - @test (1+cauchy(u) )(0.1+0.2im) ≈ φ(0.1+0.2im) - @test (1+cauchy(u) )(0.1⁻) ≈ φ(0.1⁻) - end +# φ = z -> 1 + cauchy(u,z) +# @test φ(0.1⁺) ≈ g(0.1)φ(0.1⁻) - @testset "-1 .. 0 and 0 .. 1" begin - sp = Legendre(-1 .. 0) ∪ Legendre(0 .. 1) - u_1 = u - u_ex = Fun(x->u_1(x), sp) - g_1 = 1-0.3Fun(x->exp(-40x^2), Legendre()) - g = 1-0.3Fun(x->exp(-40x^2), sp) +# @test 1+cauchy(u)(0.1+0.2im) ≈ φ(0.1+0.2im) +# @test (1+cauchy(u) )(0.1+0.2im) ≈ φ(0.1+0.2im) +# @test (1+cauchy(u) )(0.1⁻) ≈ φ(0.1⁻) +# end - n = 2ncoefficients(g) - g = pad(g,n) - u_ex = pad(u_ex,n) - @test (1+cauchy(u_ex,0.1⁺)) ≈ g(0.1)*(1+cauchy(u_ex,0.1⁻)) +# @testset "-1 .. 0 and 0 .. 1" begin +# sp = Legendre(-1 .. 0) ∪ Legendre(0 .. 1) +# u_1 = u +# u_ex = Fun(x->u_1(x), sp) +# g_1 = 1-0.3Fun(x->exp(-40x^2), Legendre()) - C₋ = fpcauchymatrix(sp, n, n) - pts = RiemannHilbert.collocationpoints(sp, n) +# g = 1-0.3Fun(x->exp(-40x^2), sp) - @test transpose(C₋[1,:])*coefficients(u_ex) ≈ cauchy(u_ex,pts[1]-eps()im) - @test transpose(C₋[5,:])*coefficients(u_ex) ≈ cauchy(u_ex,pts[5]-eps()im) - @test transpose(C₋[end,:])*coefficients(u_ex) ≈ cauchy(u_ex, 0.0-eps()im) - @test transpose(C₋[end-1,:])*coefficients(u_ex) ≈ cauchy(u_ex,pts[end-1]-eps()im) - @test transpose(C₋[n÷2,:])*coefficients(u_ex) ≈ cauchy(u_ex,-1.0-eps()) - @test transpose(C₋[(n÷2)+1,:])*coefficients(u_ex) ≈ cauchy(u_ex,1.0+eps()) +# n = 2ncoefficients(g) +# g = pad(g,n) +# u_ex = pad(u_ex,n) +# @test (1+cauchy(u_ex,0.1⁺)) ≈ g(0.1)*(1+cauchy(u_ex,0.1⁻)) - @test C₋*coefficients(u_ex) ≈ cauchy.(u_ex, pts.-eps()im) - g_v = RiemannHilbert.collocationvalues(g-1, n) - @test g_v ≈ g.(pts).-1 - G = Diagonal(g_v) +# C₋ = fpcauchymatrix(sp, n, n) +# pts = RiemannHilbert.collocationpoints(sp, n) - @test G*g_v ≈ (g.(pts) .- 1).^2 +# @test transpose(C₋[1,:])*coefficients(u_ex) ≈ cauchy(u_ex,pts[1]-eps()im) +# @test transpose(C₋[5,:])*coefficients(u_ex) ≈ cauchy(u_ex,pts[5]-eps()im) +# @test transpose(C₋[end,:])*coefficients(u_ex) ≈ cauchy(u_ex, 0.0-eps()im) +# @test transpose(C₋[end-1,:])*coefficients(u_ex) ≈ cauchy(u_ex,pts[end-1]-eps()im) +# @test transpose(C₋[n÷2,:])*coefficients(u_ex) ≈ cauchy(u_ex,-1.0-eps()) +# @test transpose(C₋[(n÷2)+1,:])*coefficients(u_ex) ≈ cauchy(u_ex,1.0+eps()) - g1 = component(g,2) - pts1 = RiemannHilbert.collocationpoints(component(sp,2), n÷2) - E1=RiemannHilbert.evaluationmatrix(component(sp,1), length(pts1)) +# @test C₋*coefficients(u_ex) ≈ cauchy.(u_ex, pts.-eps()im) +# g_v = RiemannHilbert.collocationvalues(g-1, n) +# @test g_v ≈ g.(pts).-1 +# G = Diagonal(g_v) - @test E1*g1.coefficients ≈ g1.(pts1) +# @test G*g_v ≈ (g.(pts) .- 1).^2 - E = RiemannHilbert.evaluationmatrix(sp, n) - @test E*coefficients(g) ≈ g.(pts) +# g1 = component(g,2) +# pts1 = RiemannHilbert.collocationpoints(component(sp,2), n÷2) +# E1=RiemannHilbert.evaluationmatrix(component(sp,1), length(pts1)) - @test (g.(pts).-1).*(C₋*coefficients(g)) ≈ (g.(pts).-1).*cauchy.(g, pts.-0.000000001im) - @test G*(C₋*coefficients(g)) ≈ (g.(pts).-1).*cauchy.(g, pts.-0.000000001im) +# @test E1*g1.coefficients ≈ g1.(pts1) - L = E - G*C₋ - @test L*coefficients(g) ≈ g.(pts) - (g.(pts).-1).*cauchy.(g, pts.-0.000000001im) - - @test L == rhmatrix(g,n) - - u = Fun(sp, rhmatrix(g,n) \ g_v) - φ = z -> 1 + cauchy(u,z) - @test φ(0.1⁺) ≈ g(0.1)φ(0.1⁻) - - @test 1+cauchy(u)(0.1+0.2im) ≈ φ(0.1+0.2im) - @test (1+cauchy(u) )(0.1+0.2im) ≈ φ(0.1+0.2im) - @test (1+cauchy(u) )(0.1⁻) ≈ φ(0.1⁻) - - @time φ = rhsolve(g, 2ncoefficients(g)) - @test φ(0.1⁺) ≈ g(0.1)φ(0.1⁻) - end - - @testset "0..-1 and 0..1" begin - sp = Legendre(Segment(0 , -1)) ∪ Legendre(0 .. 1) - g = Fun(x->x ≥ 0 ? 1-0.3exp(-40x^2) : inv(1-0.3exp(-40x^2)), sp) - u_1 = u - u_ex = Fun(x->sign(x)u_1(x), sp) - - n = 2ncoefficients(g) - g = pad(g,n) - u_ex = pad(u_ex,n) - @test (1+cauchy(u_ex,0.1⁺)) ≈ g(0.1)*(1+cauchy(u_ex,0.1⁻)) - - C₋ = fpcauchymatrix(sp, n, n) - pts = RiemannHilbert.collocationpoints(sp, n) - - @test transpose(C₋[1,:])*coefficients(u_ex) ≈ cauchy(u_ex,pts[1]+eps()im) - @test transpose(C₋[5,:])*coefficients(u_ex) ≈ cauchy(u_ex,pts[5]+eps()im) - @test transpose(C₋[n÷2,:])*coefficients(u_ex) ≈ cauchy(u_ex,0.0+eps()im) - @test transpose(C₋[(n÷2)+1,:])*coefficients(u_ex) ≈ cauchy(u_ex,1.0+eps()) - @test transpose(C₋[end,:])*coefficients(u_ex) ≈ cauchy(u_ex, pts[end]-eps()im) - @test transpose(C₋[end,:])*coefficients(u_ex) ≈ cauchy(u_ex, 0.0-eps()im) - @test transpose(C₋[end-1,:])*coefficients(u_ex) ≈ cauchy(u_ex,pts[end-1]-eps()im) - - @test C₋*coefficients(u_ex) ≈ [cauchy.(u_ex, pts[1:n÷2].+eps()im); cauchy.(u_ex, pts[(n÷2)+1:end].-eps()im)] - g_v = RiemannHilbert.collocationvalues(g-1, n) - - g1 = component(g,1) - pts1 = RiemannHilbert.collocationpoints(component(sp,1), n÷2) - E1=RiemannHilbert.evaluationmatrix(component(sp,1), length(pts1)) - - @test E1*g1.coefficients ≈ g1.(pts1) - - g2 = component(g,2) - pts2 = RiemannHilbert.collocationpoints(component(sp,2), n÷2) +# E = RiemannHilbert.evaluationmatrix(sp, n) +# @test E*coefficients(g) ≈ g.(pts) - @test g_v ≈ [g1.(pts1).-1; g2.(pts2).-1] - G = Diagonal(g_v) - - @test g1.(pts1) ≈ g.(pts1) - @test_broken g2.(pts2) ≈ g.(pts2) # evaluation at 0 - @test_broken G*g_v ≈ (g.(pts) .- 1).^2 - - E = RiemannHilbert.evaluationmatrix(sp, n) - @test E[1:end-1,:]*coefficients(g) ≈ g.(pts[1:end-1]) - @test transpose(E[end,:])*coefficients(g) ≈ component(g,2)(0.0) - - @test (g2.(pts2).-1).*(C₋[(n÷2)+1:end,:]*coefficients(u_ex)) ≈ - (g2.(pts2).-1).*cauchy.(u_ex, pts2.-eps()im) - @test (g.(pts1).-1).*(C₋[1:n÷2,:]*coefficients(u_ex)) ≈ - (g.(pts1).-1).*cauchy.(u_ex, pts1.+0.000000001im) - @test (g.(pts2).-1).*(C₋[(n÷2)+1:end,:]*coefficients(u_ex)) ≈ - (g.(pts2).-1).*cauchy.(u_ex, pts2.-0.000000001im) - - u_ex1,u_ex2 = components(u_ex) - @test (C₋*coefficients(u_ex))[ncoefficients(u_ex1)+1:end] ≈ cauchy.(u_ex, pts2.-eps()im) - @test G*C₋*coefficients(u_ex) ≈ [(g1.(pts1).-1).*cauchy.(u_ex, pts1.+eps()im); - (g2.(pts2).-1).*cauchy.(u_ex, pts2.-eps()im)] - - L = E - G*C₋ - @test L*coefficients(u_ex) ≈ [u_ex1.(pts1) - (g1.(pts1).-1).*cauchy.(u_ex, pts1.+eps()im); - u_ex2.(pts2) - (g2.(pts2).-1).*cauchy.(u_ex, pts2.-eps()im)] - - @test L == rhmatrix(g,n) +# @test (g.(pts).-1).*(C₋*coefficients(g)) ≈ (g.(pts).-1).*cauchy.(g, pts.-0.000000001im) +# @test G*(C₋*coefficients(g)) ≈ (g.(pts).-1).*cauchy.(g, pts.-0.000000001im) - u = Fun(sp, rhmatrix(g,n) \ g_v) - φ1 = z -> 1 + cauchy(u,z) - @test φ1(0.1⁺) ≈ g(0.1)φ1(0.1⁻) - @test φ1(-0.1⁺) ≈ g(-0.1)φ1(-0.1⁻) +# L = E - G*C₋ +# @test L*coefficients(g) ≈ g.(pts) - (g.(pts).-1).*cauchy.(g, pts.-0.000000001im) - @test 1+cauchy(u)(0.1+0.2im) ≈ φ1(0.1+0.2im) - @test (1+cauchy(u) )(0.1+0.2im) ≈ φ1(0.1+0.2im) - @test (1+cauchy(u) )(0.1⁻) ≈ φ1(0.1⁻) - @test (1+cauchy(u) )(0.1⁺) ≈ φ1(0.1⁺) - @test (1+cauchy(u) )(-0.1⁻) ≈ φ1(-0.1⁻) - @test (1+cauchy(u) )(-0.1⁺) ≈ φ1(-0.1⁺) +# @test L == rhmatrix(g,n) + +# u = Fun(sp, rhmatrix(g,n) \ g_v) +# φ = z -> 1 + cauchy(u,z) +# @test φ(0.1⁺) ≈ g(0.1)φ(0.1⁻) + +# @test 1+cauchy(u)(0.1+0.2im) ≈ φ(0.1+0.2im) +# @test (1+cauchy(u) )(0.1+0.2im) ≈ φ(0.1+0.2im) +# @test (1+cauchy(u) )(0.1⁻) ≈ φ(0.1⁻) + +# @time φ = rhsolve(g, 2ncoefficients(g)) +# @test φ(0.1⁺) ≈ g(0.1)φ(0.1⁻) +# end - @time φ = rhsolve(g, 2ncoefficients(g)) - @test φ(0.1⁺) ≈ g(0.1)φ(0.1⁻) - end - - @testset "Chebyshev g" begin - G = Fun(x -> 1 + exp(-30x^2), -1..1) - Φ = rhsolve(G, 200) - @test Φ(0.1⁺) ≈ G(0.1)Φ(0.1⁻) - end -end - -@testset "Matrix rhsolve" begin - sp = ArraySpace(Legendre(), 2) - f = Fun(Fun(x->[cos(x);sin(x)], Chebyshev()), ArraySpace(Legendre(), 2)) - G = Fun(Fun(x->[1 exp(-40x^2); 0.1exp(-40x^2) 1], Chebyshev()), ArraySpace(Legendre(), 2, 2)) +# @testset "0..-1 and 0..1" begin +# sp = Legendre(Segment(0 , -1)) ∪ Legendre(0 .. 1) +# g = Fun(x->x ≥ 0 ? 1-0.3exp(-40x^2) : inv(1-0.3exp(-40x^2)), sp) +# u_1 = u +# u_ex = Fun(x->sign(x)u_1(x), sp) - n = 2ncoefficients(G) - E = RiemannHilbert.evaluationmatrix(sp, n) - pts = RiemannHilbert.collocationpoints(sp, n÷2) +# n = 2ncoefficients(g) +# g = pad(g,n) +# u_ex = pad(u_ex,n) +# @test (1+cauchy(u_ex,0.1⁺)) ≈ g(0.1)*(1+cauchy(u_ex,0.1⁻)) - @test E*coefficients(pad(f,n)) ≈ [f[1].(pts); f[2].(pts)] +# C₋ = fpcauchymatrix(sp, n, n) +# pts = RiemannHilbert.collocationpoints(sp, n) +# @test transpose(C₋[1,:])*coefficients(u_ex) ≈ cauchy(u_ex,pts[1]+eps()im) +# @test transpose(C₋[5,:])*coefficients(u_ex) ≈ cauchy(u_ex,pts[5]+eps()im) +# @test transpose(C₋[n÷2,:])*coefficients(u_ex) ≈ cauchy(u_ex,0.0+eps()im) +# @test transpose(C₋[(n÷2)+1,:])*coefficients(u_ex) ≈ cauchy(u_ex,1.0+eps()) +# @test transpose(C₋[end,:])*coefficients(u_ex) ≈ cauchy(u_ex, pts[end]-eps()im) +# @test transpose(C₋[end,:])*coefficients(u_ex) ≈ cauchy(u_ex, 0.0-eps()im) +# @test transpose(C₋[end-1,:])*coefficients(u_ex) ≈ cauchy(u_ex,pts[end-1]-eps()im) - M = RiemannHilbert.multiplicationmatrix(G-I, n) - @test M*(E*coefficients(pad(f,n))) ≈ mapreduce(f -> f.(pts), vcat, (G-I)*f) +# @test C₋*coefficients(u_ex) ≈ [cauchy.(u_ex, pts[1:n÷2].+eps()im); cauchy.(u_ex, pts[(n÷2)+1:end].-eps()im)] +# g_v = RiemannHilbert.collocationvalues(g-1, n) - L = E - M*fpcauchymatrix(sp, n,n) - u1 = L \ mapreduce(f -> f.(pts), vcat, (G-I)[:,1]) - u2 = L \ mapreduce(f -> f.(pts), vcat, (G-I)[:,2]) - z=2+I - Φ = z -> I + [cauchy(Fun(sp, u1),z) cauchy(Fun(sp, u2),z)] +# g1 = component(g,1) +# pts1 = RiemannHilbert.collocationpoints(component(sp,1), n÷2) +# E1=RiemannHilbert.evaluationmatrix(component(sp,1), length(pts1)) - @test Φ(0.1+eps()im) ≈ G(0.1)*Φ(0.1-eps()im) +# @test E1*g1.coefficients ≈ g1.(pts1) - @test RiemannHilbert.rhmatrix(G, n) == L +# g2 = component(g,2) +# pts2 = RiemannHilbert.collocationpoints(component(sp,2), n÷2) - @test RiemannHilbert.collocationvalues(G-I, n) ≈ - [RiemannHilbert.collocationvalues((G-I)[:,1], n) RiemannHilbert.collocationvalues((G-I)[:,2], n)] +# @test g_v ≈ [g1.(pts1).-1; g2.(pts2).-1] +# G = Diagonal(g_v) - Φ = rhsolve(G,n) - @test G(0.1)*Φ(0.1⁻) ≈ Φ(0.1⁺) -end +# @test g1.(pts1) ≈ g.(pts1) +# @test_broken g2.(pts2) ≈ g.(pts2) # evaluation at 0 +# @test_broken G*g_v ≈ (g.(pts) .- 1).^2 -@testset "Matrix rhsolve two interval" begin - sp = ArraySpace(Legendre(-1 .. 0) ∪ Legendre(0 .. 1), 2) - G = Fun(x->[1 exp(-40x^2); 0.1exp(-40x^2) 1], ArraySpace(sp[1], 2, 2)) +# E = RiemannHilbert.evaluationmatrix(sp, n) +# @test E[1:end-1,:]*coefficients(g) ≈ g.(pts[1:end-1]) +# @test transpose(E[end,:])*coefficients(g) ≈ component(g,2)(0.0) - n=2ncoefficients(G) - Φ = rhsolve(G,n) +# @test (g2.(pts2).-1).*(C₋[(n÷2)+1:end,:]*coefficients(u_ex)) ≈ +# (g2.(pts2).-1).*cauchy.(u_ex, pts2.-eps()im) +# @test (g.(pts1).-1).*(C₋[1:n÷2,:]*coefficients(u_ex)) ≈ +# (g.(pts1).-1).*cauchy.(u_ex, pts1.+0.000000001im) +# @test (g.(pts2).-1).*(C₋[(n÷2)+1:end,:]*coefficients(u_ex)) ≈ +# (g.(pts2).-1).*cauchy.(u_ex, pts2.-0.000000001im) - @test G(0.1)*Φ(0.1⁻) ≈ Φ(0.1⁺) - U = RiemannHilbert.rh_sie_solve(G,n) +# u_ex1,u_ex2 = components(u_ex) +# @test (C₋*coefficients(u_ex))[ncoefficients(u_ex1)+1:end] ≈ cauchy.(u_ex, pts2.-eps()im) +# @test G*C₋*coefficients(u_ex) ≈ [(g1.(pts1).-1).*cauchy.(u_ex, pts1.+eps()im); +# (g2.(pts2).-1).*cauchy.(u_ex, pts2.-eps()im)] - U1 = U[:,1] - g = G - sp = space(g)[:,1] - C₋ = fpcauchymatrix(sp, n, n) - G = RiemannHilbert.multiplicationmatrix(g-I, n) - E = RiemannHilbert.evaluationmatrix(sp, n) +# L = E - G*C₋ +# @test L*coefficients(u_ex) ≈ [u_ex1.(pts1) - (g1.(pts1).-1).*cauchy.(u_ex, pts1.+eps()im); +# u_ex2.(pts2) - (g2.(pts2).-1).*cauchy.(u_ex, pts2.-eps()im)] - pts = RiemannHilbert.collocationpoints(sp, n÷2) - @test last(E*coefficients(U1)) ≈ U1(0.00000000001)[2] - @test last(C₋*coefficients(U1)) ≈ cauchy(U1[2], 0.00000000001-eps()*im) - @test cauchy(U1[1], 0.00000000001-eps()*im) ≈ (C₋*coefficients(U1))[n÷2] - @test last(G*C₋*coefficients(U1)) ≈ ((g(0.00000000001)-I)*cauchy(U1, 0.00000000001-eps()*im))[2] +# @test L == rhmatrix(g,n) +# u = Fun(sp, rhmatrix(g,n) \ g_v) +# φ1 = z -> 1 + cauchy(u,z) +# @test φ1(0.1⁺) ≈ g(0.1)φ1(0.1⁻) +# @test φ1(-0.1⁺) ≈ g(-0.1)φ1(-0.1⁻) - @test RiemannHilbert.collocationvalues((g-I)[:,1], n)[end] ≈ 0.1 +# @test 1+cauchy(u)(0.1+0.2im) ≈ φ1(0.1+0.2im) +# @test (1+cauchy(u) )(0.1+0.2im) ≈ φ1(0.1+0.2im) +# @test (1+cauchy(u) )(0.1⁻) ≈ φ1(0.1⁻) +# @test (1+cauchy(u) )(0.1⁺) ≈ φ1(0.1⁺) +# @test (1+cauchy(u) )(-0.1⁻) ≈ φ1(-0.1⁻) +# @test (1+cauchy(u) )(-0.1⁺) ≈ φ1(-0.1⁺) - sp = ArraySpace(Legendre(Segment(0 , -1)) ∪ Legendre(0 .. 1), 2) - G = g = Fun(x-> x ≥ 0 ? [1 exp(-40x^2); 0.1exp(-40x^2) 1] : inv([1 exp(-40x^2); 0.1exp(-40x^2) 1]), ArraySpace(sp[1], 2, 2)) - n=2ncoefficients(G) - Ũ1 = Fun(x-> x ≥ 0 ? U1(x) : -U1(x), sp, n÷2) - @test cauchy(Ũ1, 0.1⁻) ≈ cauchy(Ũ1, 0.1-eps()im) - @test cauchy(Ũ1, 0.1+eps()im) ≈ cauchy(U1, 0.1+eps()im) - @test cauchy(Ũ1, -0.1+eps()im) ≈ cauchy(U1, -0.1+eps()im) +# @time φ = rhsolve(g, 2ncoefficients(g)) +# @test φ(0.1⁺) ≈ g(0.1)φ(0.1⁻) +# end - L = rhmatrix(G, n) - rhs = RiemannHilbert.collocationvalues((g-I)[:,1], n) - @test rhs[end] ≈ 0.1 +# @testset "Chebyshev g" begin +# G = Fun(x -> 1 + exp(-30x^2), -1..1) +# Φ = rhsolve(G, 200) +# @test Φ(0.1⁺) ≈ G(0.1)Φ(0.1⁻) +# end +# end - Φ = rhsolve(G,n) +# @testset "Matrix rhsolve" begin +# sp = ArraySpace(Legendre(), 2) +# f = Fun(Fun(x->[cos(x);sin(x)], Chebyshev()), ArraySpace(Legendre(), 2)) +# G = Fun(Fun(x->[1 exp(-40x^2); 0.1exp(-40x^2) 1], Chebyshev()), ArraySpace(Legendre(), 2, 2)) - g = G - sp = space(g)[:,1] - C₋ = fpcauchymatrix(sp, n, n) - G = RiemannHilbert.multiplicationmatrix(g-I, n) - E = RiemannHilbert.evaluationmatrix(sp, n) +# n = 2ncoefficients(G) +# E = RiemannHilbert.evaluationmatrix(sp, n) +# pts = RiemannHilbert.collocationpoints(sp, n÷2) + +# @test E*coefficients(pad(f,n)) ≈ [f[1].(pts); f[2].(pts)] + + +# M = RiemannHilbert.multiplicationmatrix(G-I, n) +# @test M*(E*coefficients(pad(f,n))) ≈ mapreduce(f -> f.(pts), vcat, (G-I)*f) + +# L = E - M*fpcauchymatrix(sp, n,n) +# u1 = L \ mapreduce(f -> f.(pts), vcat, (G-I)[:,1]) +# u2 = L \ mapreduce(f -> f.(pts), vcat, (G-I)[:,2]) +# z=2+I +# Φ = z -> I + [cauchy(Fun(sp, u1),z) cauchy(Fun(sp, u2),z)] + +# @test Φ(0.1+eps()im) ≈ G(0.1)*Φ(0.1-eps()im) + +# @test RiemannHilbert.rhmatrix(G, n) == L - pts = RiemannHilbert.collocationpoints(sp, n÷2) +# @test RiemannHilbert.collocationvalues(G-I, n) ≈ +# [RiemannHilbert.collocationvalues((G-I)[:,1], n) RiemannHilbert.collocationvalues((G-I)[:,2], n)] - @test last(E*coefficients(Ũ1)) ≈ Ũ1(0.00000000001)[2] - @test last(C₋*coefficients(Ũ1)) ≈ cauchy(Ũ1[2], 0.00000000001-eps()*im) - @test cauchy(Ũ1[1], 0.00000000001-eps()*im) ≈ (C₋*coefficients(Ũ1))[n÷2] - @test G[[n÷2,n],[n÷2,n]] ≈ (g(0.00000000001)-I) +# Φ = rhsolve(G,n) +# @test G(0.1)*Φ(0.1⁻) ≈ Φ(0.1⁺) +# end + +# @testset "Matrix rhsolve two interval" begin +# sp = ArraySpace(Legendre(-1 .. 0) ∪ Legendre(0 .. 1), 2) +# G = Fun(x->[1 exp(-40x^2); 0.1exp(-40x^2) 1], ArraySpace(sp[1], 2, 2)) + +# n=2ncoefficients(G) +# Φ = rhsolve(G,n) + +# @test G(0.1)*Φ(0.1⁻) ≈ Φ(0.1⁺) +# U = RiemannHilbert.rh_sie_solve(G,n) + +# U1 = U[:,1] +# g = G +# sp = space(g)[:,1] +# C₋ = fpcauchymatrix(sp, n, n) +# G = RiemannHilbert.multiplicationmatrix(g-I, n) +# E = RiemannHilbert.evaluationmatrix(sp, n) + +# pts = RiemannHilbert.collocationpoints(sp, n÷2) +# @test last(E*coefficients(U1)) ≈ U1(0.00000000001)[2] +# @test last(C₋*coefficients(U1)) ≈ cauchy(U1[2], 0.00000000001-eps()*im) +# @test cauchy(U1[1], 0.00000000001-eps()*im) ≈ (C₋*coefficients(U1))[n÷2] +# @test last(G*C₋*coefficients(U1)) ≈ ((g(0.00000000001)-I)*cauchy(U1, 0.00000000001-eps()*im))[2] + + +# @test RiemannHilbert.collocationvalues((g-I)[:,1], n)[end] ≈ 0.1 + +# sp = ArraySpace(Legendre(Segment(0 , -1)) ∪ Legendre(0 .. 1), 2) +# G = g = Fun(x-> x ≥ 0 ? [1 exp(-40x^2); 0.1exp(-40x^2) 1] : inv([1 exp(-40x^2); 0.1exp(-40x^2) 1]), ArraySpace(sp[1], 2, 2)) +# n=2ncoefficients(G) +# Ũ1 = Fun(x-> x ≥ 0 ? U1(x) : -U1(x), sp, n÷2) +# @test cauchy(Ũ1, 0.1⁻) ≈ cauchy(Ũ1, 0.1-eps()im) +# @test cauchy(Ũ1, 0.1+eps()im) ≈ cauchy(U1, 0.1+eps()im) +# @test cauchy(Ũ1, -0.1+eps()im) ≈ cauchy(U1, -0.1+eps()im) - @test last(G*C₋*coefficients(Ũ1)) ≈ transpose((g(0.00000000001)-I)[2,:])*cauchy(Ũ1, 0.00000000001-eps()*im) +# L = rhmatrix(G, n) +# rhs = RiemannHilbert.collocationvalues((g-I)[:,1], n) +# @test rhs[end] ≈ 0.1 - @test transpose(L[end,:])*coefficients(Ũ1) ≈ Ũ1(0.00000000001)[2] - transpose((g(0.00000000001)-I)[2,:])*cauchy(Ũ1, 0.00000000001-eps()*im) +# Φ = rhsolve(G,n) + +# g = G +# sp = space(g)[:,1] +# C₋ = fpcauchymatrix(sp, n, n) +# G = RiemannHilbert.multiplicationmatrix(g-I, n) +# E = RiemannHilbert.evaluationmatrix(sp, n) + +# pts = RiemannHilbert.collocationpoints(sp, n÷2) + +# @test last(E*coefficients(Ũ1)) ≈ Ũ1(0.00000000001)[2] +# @test last(C₋*coefficients(Ũ1)) ≈ cauchy(Ũ1[2], 0.00000000001-eps()*im) +# @test cauchy(Ũ1[1], 0.00000000001-eps()*im) ≈ (C₋*coefficients(Ũ1))[n÷2] +# @test G[[n÷2,n],[n÷2,n]] ≈ (g(0.00000000001)-I) + +# @test last(G*C₋*coefficients(Ũ1)) ≈ transpose((g(0.00000000001)-I)[2,:])*cauchy(Ũ1, 0.00000000001-eps()*im) + +# @test transpose(L[end,:])*coefficients(Ũ1) ≈ Ũ1(0.00000000001)[2] - transpose((g(0.00000000001)-I)[2,:])*cauchy(Ũ1, 0.00000000001-eps()*im) - @test U1(0.00000000001)[2] - transpose((g(0.00000000001)-I)[2,:])*cauchy(U1, 0.00000000001-eps()*im) ≈ 0.1 - @test g(0.1)*Φ(0.1⁻) ≈ Φ(0.1⁺) -end +# @test U1(0.00000000001)[2] - transpose((g(0.00000000001)-I)[2,:])*cauchy(U1, 0.00000000001-eps()*im) ≈ 0.1 +# @test g(0.1)*Φ(0.1⁻) ≈ Φ(0.1⁺) +# end -@testset "4 rays" begin - Γ = Segment(0, 2.5exp(im*π/6)) ∪ Segment(0, 2.5exp(5im*π/6)) ∪ - Segment(0, 2.5exp(-5im*π/6)) ∪ Segment(0, 2.5exp(-im*π/6)) - sp = ArraySpace(PiecewiseSpace(Legendre.(components(Γ))), 2,2) - - s₁ = im - s₃ = -im - - G = Fun( z -> if angle(z) ≈ π/6 - [1 0; s₁*exp(8im/3*z^3) 1] - elseif angle(z) ≈ 5π/6 - [1 0; s₃*exp(8im/3*z^3) 1] - elseif angle(z) ≈ -π/6 - [1 -s₃*exp(-8im/3*z^3); 0 1] - elseif angle(z) ≈ -5π/6 - [1 -s₁*exp(-8im/3*z^3); 0 1] - end - , sp) - - Φ = transpose(rhsolve(transpose(G), 2*4*100)) - - s=exp(im*π/6) - @test Φ((s)⁻)*G(s) ≈ Φ((s)⁺) - @test map(g->first(components(g)[1]), G)*map(g->first(components(g)[2]), G)* - map(g->first(components(g)[3]), G)*map(g->first(components(g)[4]), G) ≈ Matrix(I,2,2) - - for _=1:5 - @test RiemannHilbert.evaluationmatrix(sp[:,1], 32) ≈ RiemannHilbert.evaluationmatrix(sp[:,1], 32) - @test RiemannHilbert.rhmatrix(G, 32) ≈ RiemannHilbert.rhmatrix(G, 32) - end - - @test RiemannHilbert.rhmatrix(transpose(G), 900) ≈ RiemannHilbert.rhmatrix(transpose(G), 900) - U = RiemannHilbert.rh_sie_solve(transpose(G), 2*4*100) - @test -0.36706155154807807 ≈ sum(U[1,2])/(-π*im) - - G̃ = Fun( z -> if angle(z) ≈ π/6 - [1 0; s₁*exp(8im/3*z^3) 1] - elseif angle(z) ≈ 5π/6 - [1 0; s₃*exp(8im/3*z^3) 1] - elseif angle(z) ≈ -π/6 - [1 -s₃*exp(-8im/3*z^3); 0 1] - elseif angle(z) ≈ -5π/6 - [1 -s₁*exp(-8im/3*z^3); 0 1] - end - , Γ) - - Ũ = RiemannHilbert.rh_sie_solve(transpose(G̃), 2*4*100) - - @test rhmatrix(transpose(G), 2*4*100) ≈ rhmatrix(transpose(G̃), 2*4*100) - @test -0.36706155154807807 ≈ sum(Ũ[1,2])/(-π*im) - - V = istieltjes(Φ) - x = Fun(domain(V)) - - @test 10.0I + sum.(Array(V)) + stieltjes(x*V, 10.0) ≈ 10.0Φ(10.0) - - - # check rhmatrix relationship for below - U = V*(-2π*im) - U1 = U[1,:] - n= ncoefficients(U1) - L = rhmatrix(transpose(G),n) - vals = collocationvalues(transpose(G)-I, n) - @test L*coefficients(U1) ≈ vals[:,1] -end +# @testset "4 rays" begin +# Γ = Segment(0, 2.5exp(im*π/6)) ∪ Segment(0, 2.5exp(5im*π/6)) ∪ +# Segment(0, 2.5exp(-5im*π/6)) ∪ Segment(0, 2.5exp(-im*π/6)) +# sp = ArraySpace(PiecewiseSpace(Legendre.(components(Γ))), 2,2) +# s₁ = im +# s₃ = -im -@testset "6 rays" begin - @testset "HM on 6 rays" begin - s₁,s₂,s₃ = -im,0,im - @assert s₁ - s₂ + s₃ + s₁*s₂*s₃ ≈ 0 - - # construct true solution using 4 rays - Γ = Segment(0, 2.5exp(im*π/6)) ∪ Segment(0, 2.5exp(5im*π/6)) ∪ - Segment(0, 2.5exp(-5im*π/6)) ∪ Segment(0, 2.5exp(-im*π/6)) - sp = ArraySpace(PiecewiseSpace(Legendre.(components(Γ))), 2,2) - - G = Fun( z -> if angle(z) ≈ π/6 - [1 0; s₁*exp(8im/3*z^3) 1] - elseif angle(z) ≈ 5π/6 - [1 0; s₃*exp(8im/3*z^3) 1] - elseif angle(z) ≈ -π/6 - [1 -s₃*exp(-8im/3*z^3); 0 1] - elseif angle(z) ≈ -5π/6 - [1 -s₁*exp(-8im/3*z^3); 0 1] - end - , sp) - - Φ = transpose(rhsolve(transpose(G), 2*6*100)) - - - # debug - V4 = istieltjes(Φ) - x = 0.0 - - @test stieltjes(V4,1+im)+I == Φ(1+im) - - - Γ = Segment(0, 2.5exp(im*π/6)) ∪ - Segment(0, 2.5exp(im*π/2)) ∪ - Segment(0, 2.5exp(5im*π/6)) ∪ - Segment(0, 2.5exp(-5im*π/6)) ∪ - Segment(0, 2.5exp(-im*π/2)) ∪ - Segment(0, 2.5exp(-im*π/6)); - - G = Fun( z -> if angle(z) ≈ π/6 - [1 0; - s₁*exp(8im/3*z^3+2im*x*z) 1] - elseif angle(z) ≈ π/2 - [1 s₂*exp(-8im/3*z^3-2im*x*z); - 0 1] - elseif angle(z) ≈ 5π/6 - [1 0; - s₃*exp(8im/3*z^3+2im*x*z) 1] - elseif angle(z) ≈ -π/6 - [1 -s₃*exp(-8im/3*z^3-2im*x*z); - 0 1] - elseif angle(z) ≈ -π/2 - [1 0; - -s₂*exp(8im/3*z^3+2im*x*z) 1] - elseif angle(z) ≈ -5π/6 - [1 -s₁*exp(-8im/3*z^3-2im*x*z); - 0 1] - end - , Γ); - sp = ArraySpace(PiecewiseSpace(Legendre.(components(Γ))), 2,2) - V = Fun(V4, sp) - - @test stieltjes(V,1+im)+I ≈ Φ(1+im) +# G = Fun( z -> if angle(z) ≈ π/6 +# [1 0; s₁*exp(8im/3*z^3) 1] +# elseif angle(z) ≈ 5π/6 +# [1 0; s₃*exp(8im/3*z^3) 1] +# elseif angle(z) ≈ -π/6 +# [1 -s₃*exp(-8im/3*z^3); 0 1] +# elseif angle(z) ≈ -5π/6 +# [1 -s₁*exp(-8im/3*z^3); 0 1] +# end +# , sp) + +# Φ = transpose(rhsolve(transpose(G), 2*4*100)) + +# s=exp(im*π/6) +# @test Φ((s)⁻)*G(s) ≈ Φ((s)⁺) +# @test map(g->first(components(g)[1]), G)*map(g->first(components(g)[2]), G)* +# map(g->first(components(g)[3]), G)*map(g->first(components(g)[4]), G) ≈ Matrix(I,2,2) + +# for _=1:5 +# @test RiemannHilbert.evaluationmatrix(sp[:,1], 32) ≈ RiemannHilbert.evaluationmatrix(sp[:,1], 32) +# @test RiemannHilbert.rhmatrix(G, 32) ≈ RiemannHilbert.rhmatrix(G, 32) +# end + +# @test RiemannHilbert.rhmatrix(transpose(G), 900) ≈ RiemannHilbert.rhmatrix(transpose(G), 900) +# U = RiemannHilbert.rh_sie_solve(transpose(G), 2*4*100) +# @test -0.36706155154807807 ≈ sum(U[1,2])/(-π*im) + +# G̃ = Fun( z -> if angle(z) ≈ π/6 +# [1 0; s₁*exp(8im/3*z^3) 1] +# elseif angle(z) ≈ 5π/6 +# [1 0; s₃*exp(8im/3*z^3) 1] +# elseif angle(z) ≈ -π/6 +# [1 -s₃*exp(-8im/3*z^3); 0 1] +# elseif angle(z) ≈ -5π/6 +# [1 -s₁*exp(-8im/3*z^3); 0 1] +# end +# , Γ) + +# Ũ = RiemannHilbert.rh_sie_solve(transpose(G̃), 2*4*100) + +# @test rhmatrix(transpose(G), 2*4*100) ≈ rhmatrix(transpose(G̃), 2*4*100) +# @test -0.36706155154807807 ≈ sum(Ũ[1,2])/(-π*im) + +# V = istieltjes(Φ) +# x = Fun(domain(V)) + +# @test 10.0I + sum.(Array(V)) + stieltjes(x*V, 10.0) ≈ 10.0Φ(10.0) + + +# # check rhmatrix relationship for below +# U = V*(-2π*im) +# U1 = U[1,:] +# n= ncoefficients(U1) +# L = rhmatrix(transpose(G),n) +# vals = collocationvalues(transpose(G)-I, n) +# @test L*coefficients(U1) ≈ vals[:,1] +# end + + +# @testset "6 rays" begin +# @testset "HM on 6 rays" begin +# s₁,s₂,s₃ = -im,0,im +# @assert s₁ - s₂ + s₃ + s₁*s₂*s₃ ≈ 0 + +# # construct true solution using 4 rays +# Γ = Segment(0, 2.5exp(im*π/6)) ∪ Segment(0, 2.5exp(5im*π/6)) ∪ +# Segment(0, 2.5exp(-5im*π/6)) ∪ Segment(0, 2.5exp(-im*π/6)) +# sp = ArraySpace(PiecewiseSpace(Legendre.(components(Γ))), 2,2) + +# G = Fun( z -> if angle(z) ≈ π/6 +# [1 0; s₁*exp(8im/3*z^3) 1] +# elseif angle(z) ≈ 5π/6 +# [1 0; s₃*exp(8im/3*z^3) 1] +# elseif angle(z) ≈ -π/6 +# [1 -s₃*exp(-8im/3*z^3); 0 1] +# elseif angle(z) ≈ -5π/6 +# [1 -s₁*exp(-8im/3*z^3); 0 1] +# end +# , sp) + +# Φ = transpose(rhsolve(transpose(G), 2*6*100)) + + +# # debug +# V4 = istieltjes(Φ) +# x = 0.0 + +# @test stieltjes(V4,1+im)+I == Φ(1+im) + + +# Γ = Segment(0, 2.5exp(im*π/6)) ∪ +# Segment(0, 2.5exp(im*π/2)) ∪ +# Segment(0, 2.5exp(5im*π/6)) ∪ +# Segment(0, 2.5exp(-5im*π/6)) ∪ +# Segment(0, 2.5exp(-im*π/2)) ∪ +# Segment(0, 2.5exp(-im*π/6)); + +# G = Fun( z -> if angle(z) ≈ π/6 +# [1 0; +# s₁*exp(8im/3*z^3+2im*x*z) 1] +# elseif angle(z) ≈ π/2 +# [1 s₂*exp(-8im/3*z^3-2im*x*z); +# 0 1] +# elseif angle(z) ≈ 5π/6 +# [1 0; +# s₃*exp(8im/3*z^3+2im*x*z) 1] +# elseif angle(z) ≈ -π/6 +# [1 -s₃*exp(-8im/3*z^3-2im*x*z); +# 0 1] +# elseif angle(z) ≈ -π/2 +# [1 0; +# -s₂*exp(8im/3*z^3+2im*x*z) 1] +# elseif angle(z) ≈ -5π/6 +# [1 -s₁*exp(-8im/3*z^3-2im*x*z); +# 0 1] +# end +# , Γ); +# sp = ArraySpace(PiecewiseSpace(Legendre.(components(Γ))), 2,2) +# V = Fun(V4, sp) + +# @test stieltjes(V,1+im)+I ≈ Φ(1+im) - U = V*(-2π*im) +# U = V*(-2π*im) - U1 = U[1,:] - @test cauchy(U1,1+im)+[1,0] ≈ Φ(1+im)[1,:] - @test abs(sum(first.(components(U1[1])))) ≤ 100eps() - @test abs(sum(first.(components(U1[2])))) ≤ 100eps() +# U1 = U[1,:] +# @test cauchy(U1,1+im)+[1,0] ≈ Φ(1+im)[1,:] +# @test abs(sum(first.(components(U1[1])))) ≤ 100eps() +# @test abs(sum(first.(components(U1[2])))) ≤ 100eps() - U11 = U1[1] - n = ncoefficients(U11) - C₋ = fpcauchymatrix(space(U11), n, n) - pts = collocationpoints(space(U11), n) - c = C₋*coefficients(U11) +# U11 = U1[1] +# n = ncoefficients(U11) +# C₋ = fpcauchymatrix(space(U11), n, n) +# pts = collocationpoints(space(U11), n) +# c = C₋*coefficients(U11) - @test c[1] ≈ finitepart(cauchy(U11,orientedrightendpoint(component(Γ,1)))) - @test c[2] ≈ cauchy(U11,pts[2]) - @test c[150] ≈ finitepart(cauchy(U11,orientedleftendpoint(component(Γ,1))⁻)) - @test c[151] ≈ finitepart(cauchy(U11,orientedrightendpoint(component(Γ,2)))) +# @test c[1] ≈ finitepart(cauchy(U11,orientedrightendpoint(component(Γ,1)))) +# @test c[2] ≈ cauchy(U11,pts[2]) +# @test c[150] ≈ finitepart(cauchy(U11,orientedleftendpoint(component(Γ,1))⁻)) +# @test c[151] ≈ finitepart(cauchy(U11,orientedrightendpoint(component(Γ,2)))) - n = ncoefficients(U1) - L = rhmatrix(transpose(G),n) - vals = collocationvalues(transpose(G)-I, n) - pts = collocationpoints(space(U1),n) +# n = ncoefficients(U1) +# L = rhmatrix(transpose(G),n) +# vals = collocationvalues(transpose(G)-I, n) +# pts = collocationpoints(space(U1),n) - c = L*coefficients(U1) - @test c ≈ vals[:,1] +# c = L*coefficients(U1) +# @test c ≈ vals[:,1] - @test coefficients(U1) ≈ L \ vals[:,1] - end -end +# @test coefficients(U1) ≈ L \ vals[:,1] +# end +# end -include("test_nls.jl") \ No newline at end of file +# include("test_nls.jl") \ No newline at end of file