JuliaApproximation / ApproxFun.jl

Julia package for function approximation
http://juliaapproximation.github.io/ApproxFun.jl/
Other
541 stars 70 forks source link

Support broadcast notation with singularities #472

Open dlfivefifty opened 7 years ago

dlfivefifty commented 7 years ago

In 0.6 calls like 1./f no longer fall back to 1/f, as it is broadcasted, and hence currently uses the constructor with the domain of f, regardless of the singularities introduced.

Apart from improving the constructor, I think we need an auto-differentiation-like method for determining singularities. This would work something like:

d = Smooth(0..1)
1/d == JacobiSingularity(1,0,0..1)
dlfivefifty commented 7 years ago

I think we can do this but just using Spaces:

function ^{DD<:Segment}(s::PolynomialSpace{DD},k) 
    d = domain(s)
    a,b = d.a,d.b
    0 == a && return JacobiWeight(k,0,s)
    0 == b && return JacobiWeight(0,k,s)
    a < 0 < b && return JacobiWeight(0,k,a..0) ∪ JacobiWeight(k,0,0..b)
    return s  # 0 is not in the interval
end

Base.sqrt(s::Space) = s^0.5

Unfortunately it's not possible to add a default (::Function)(s::Space) = s, but I think this can be worked around by using try, catch.