ApproxFun.jl icon indicating copy to clipboard operation
ApproxFun.jl copied to clipboard

Division by Fun with root fails: `setdomain(::PiecewiseSpace,::ClosedInterval)` not implement

Open LucasAschenbach opened this issue 10 months ago • 0 comments

For a Fun with roots in its domain, division fails with the error message:

ERROR: MethodError: no method matching setdomain(::PiecewiseSpace{Tuple{Chebyshev{ChebyshevInterval{Float64}, Float64}, JacobiWeight{Chebyshev{IntervalSets.ClosedInterval{Float64}, Float64}, IntervalSets.ClosedInterval{Float64}, Float64, Int64}, JacobiWeight{Chebyshev{IntervalSets.ClosedInterval{Float64}, Float64}, IntervalSets.ClosedInterval{Float64}, Float64, Int64}}, DomainSets.UnionDomain{Float64, Tuple{ChebyshevInterval{Float64}, IntervalSets.ClosedInterval{Float64}, IntervalSets.ClosedInterval{Float64}}}, Float64}, ::IntervalSets.ClosedInterval{Int64})

Closest candidates are:
  setdomain(!Matched::LogWeight, ::Domain)
   @ ApproxFunSingularities ~/.julia/packages/ApproxFunSingularities/Qxudt/src/LogWeight.jl:26
  setdomain(!Matched::Chebyshev, ::Domain)
   @ ApproxFunOrthogonalPolynomials ~/.julia/packages/ApproxFunOrthogonalPolynomials/hVSG5/src/Spaces/Chebyshev/Chebyshev.jl:55
  setdomain(!Matched::ApproxFunBase.ArraySpace, ::Domain)
   @ ApproxFunBase ~/.julia/packages/ApproxFunBase/sNMxQ/src/Spaces/ArraySpace.jl:66
  ...

Stacktrace:

1. setdomain(f::Fun{PiecewiseSpace{Tuple{Chebyshev{ChebyshevInterval{Float64}, Float64}, JacobiWeight{Chebyshev{IntervalSets.ClosedInterval{Float64}, Float64}, IntervalSets.ClosedInterval{Float64}, Float64, Int64}, JacobiWeight{Chebyshev{IntervalSets.ClosedInterval{Float64}, Float64}, IntervalSets.ClosedInterval{Float64}, Float64, Int64}}, DomainSets.UnionDomain{Float64, Tuple{ChebyshevInterval{Float64}, IntervalSets.ClosedInterval{Float64}, IntervalSets.ClosedInterval{Float64}}}, Float64}, Float64, Vector{Float64}}, d::IntervalSets.ClosedInterval{Int64}) at 

2. /(c::Fun{Chebyshev{IntervalSets.ClosedInterval{Int64}, Float64}, Float64, Vector{Float64}}, f::Fun{Chebyshev{IntervalSets.ClosedInterval{Int64}, Float64}, Float64, Vector{Float64}}) at 

3. top-level scope

Here is a minimal example for reproducing the error

using ApproxFun

g = Fun(exp, Chebyshev(0..1))
f = Fun(x -> x-0.5, Chebyshev(0..1))
h = g/f

ApproxFun transforms the domain of f to the canonical domain of the space, splits the space domain at the roots and then attempts to call setdomain(space(f), d) where space(f) is a PiecewiseSpace and d the original domain. This is where the error occurs. It seems what is needed is a function which will map the PiecewiseSpace on the canonical domain to the original domain. While implementing such a transformation is not complicated, I currently lack the overview of the JuliaApproximation ecosystem and future plans to know where to best put this logic and which interfaces it needs to plug into. If you could point me into the right direction, I am happy to make a PR for this.

Remark: For the caseg = 1, the splitting of the domain of f is performed on the original domain without converting to the canonical space and no exception is thrown.


Temporary Fix

For anyone else encountering this issue: A temporary fix is to transform the problem to the canonical domain of your function space by hand.

LucasAschenbach avatar Aug 28 '23 20:08 LucasAschenbach