JuliaMath / HypergeometricFunctions.jl

A Julia package for calculating hypergeometric functions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not compatible with TaylorSeries package

edwardcao3026 opened this issue · comments

I tried to use HypergeometricFunctions and TaylorSeries at the same time as follows.

using TaylorSeries, Plots
using HypergeometricFunctions

x = set_variables("x", order=100);
_₂F₁(1.0,2.0,3.0,(x-1))

However, I got the error:
ERROR: LoadError: MethodError: no method matching -(::Array{TaylorN{Float64},1}, ::Int64)
Closest candidates are:
-(::Complex{Bool}, ::Real) at complex.jl:298
-(::Missing, ::Number) at missing.jl:93
-(::Base.CoreLogging.LogLevel, ::Integer) at logging.jl:107
...
Stacktrace:
[1] top-level scope at none:0

Is there anyone to help? Thanks.

I don't think the code was designed with non-numeric Number types in mind. The implementation uses the group of six variable transformations (see the DLMF) to analytically continue Gauss' power series outside the disk |z| < 1, and in every case relates one evaluation to at most two further evaluations within the disk. With a symbolic-like input, it's not clear what should be expected. (Do you expect the series to terminate after some point?)

Isn’t that an error before you even get to HypergeometricFunctiobs since it’s erroring on x-1 ?

Isn’t that an error before you even get to HypergeometricFunctiobs since it’s erroring on x-1 ?

Thanks for the reply. However, x-1 works fine, and is not an error.

What versions of Julia and TalorSeries are you using? I ask because x-1 errors for me

julia> using TaylorSeries

julia> x = set_variables("x, order=100")
2-element Array{TaylorN{Float64},1}:
         1.0 x, + 𝒪(‖x‖⁷)
  1.0 order=100 + 𝒪(‖x‖⁷)

julia> x-1
ERROR: MethodError: no method matching -(::Array{TaylorN{Float64},1}, ::Int64)
Closest candidates are:
  -(::Complex{Bool}, ::Real) at complex.jl:298
  -(::Missing, ::Number) at missing.jl:97
  -(::Base.CoreLogging.LogLevel, ::Integer) at logging.jl:107
  ...
Stacktrace:
 [1] top-level scope at none:0

Failing that, did you mean x .- 1? Because that doesn't error, but unfortunately

julia> _₂F₁(1.0, 2.0, 3.0, (x .- 1))
ERROR: MethodError: no method matching isless(::TaylorN{Float64}, ::Float64)
Closest candidates are:
  isless(::Float64, ::Float64) at float.jl:459
  isless(::Missing, ::Any) at missing.jl:70
  isless(::InfiniteArrays.Infinity, ::AbstractFloat) at ~/.julia/packages/InfiniteArrays/24ELy/src/Infinity.jl:46
  ...
Stacktrace:
 [1] <(::TaylorN{Float64}, ::Float64) at ./operators.jl:260
 [2] <=(::TaylorN{Float64}, ::Float64) at ./operators.jl:309
 [3] _₂F₁general(::Float64, ::Float64, ::Float64, ::TaylorN{Float64}) at ~/.julia/packages/HypergeometricFunctions/JaGGn/src/Gauss.jl:86
 [4] _₂F₁(::Float64, ::Float64, ::Float64, ::TaylorN{Float64}) at ~/.julia/packages/HypergeometricFunctions/JaGGn/src/Gauss.jl:53
 [5] _₂F₁(::Float64, ::Float64, ::Float64, ::Array{TaylorN{Float64},1}) at ~/.julia/packages/HypergeometricFunctions/JaGGn/src/Gauss.jl:72
 [6] top-level scope at none:0

which is the same error as

julia> x .< 0.0
ERROR: MethodError: no method matching isless(::TaylorN{Float64}, ::Float64)
Closest candidates are:
  isless(::Float64, ::Float64) at float.jl:459
  isless(::Missing, ::Any) at missing.jl:70
  isless(::InfiniteArrays.Infinity, ::AbstractFloat) at ~/.julia/packages/InfiniteArrays/24ELy/src/Infinity.jl:46
  ...
Stacktrace:
 [1] <(::TaylorN{Float64}, ::Float64) at ./operators.jl:260
 [2] _broadcast_getindex_evalf at ./broadcast.jl:578 [inlined]
 [3] _broadcast_getindex at ./broadcast.jl:551 [inlined]
 [4] getindex at ./broadcast.jl:511 [inlined]
 [5] copy at ./broadcast.jl:787 [inlined]
 [6] materialize(::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1},Nothing,typeof(<),Tuple{Array{TaylorN{Float64},1},Float64}}) at ./broadcast.jl:753
 [7] top-level scope at none:0

Versions

Version 1.1.1-pre.45 (2019-05-08)
release-1.1/d9c5405702* (fork: 115 commits, 167 days)
[6aa5eb33] TaylorSeries v0.9.2

I see. I reproduced your error for the command x = set_variables("x, order=100"). I use x, y = set_variables("x y", order=100), then x-1 works fine. However, the hypergeometric error persists.

My version is v"1.0.0".

First: x above is a vector. I think you mean x = set_variables("x, order=100")[1]. We can get it working by adding the missing functionality:

julia> x = set_variables("x", order=100)[1];

julia> Base.isless(y::Number, x::TaylorN) = isless(y, x.coeffs[1].coeffs[1])

julia> Base.log1p(x::TaylorN) = log(1+x)

julia> Base.eps(::Type{TaylorN{T}}) where T = eps(T)

julia> Base.isless(x::TaylorN, y::Number) = isless(x.coeffs[1].coeffs[1], y)

julia> _₂F₁(1.0,2.0,3.0,(x-1))
 0.6137056388801087 + 0.22741127776023898 x + 0.09111691664014213 x² + 0.03815588885481866 x³ + 0.016444861063214 x⁴ + 0.007233833291493177 x⁵ + 0.003231138806309342 x⁶ + 0.0014605872604416172 x⁷ + 0.000666598108984577 x⁸ + 0.00030663682865957726 x⁹ + 0.00014198800183346362 x¹⁰ + 6.61175831375729e-5 x¹¹ + 3.0937284901315815e-5 x¹² + 1.4537030067464611e-5 x¹³ + 6.856078195624316e-6 x¹⁴ + 3.244138814946803e-6 x¹⁵ + 1.5395500556889938e-6 x¹⁶ + 7.325365567743256e-7 x¹⁷ + 3.4937741952650163e-7 x¹⁸ + 1.669918137650735e-7 x¹⁹ + 7.997399515112675e-8 x²⁰ + 3.8369378241164586e-8 x²¹ + 1.8439091439531812e-8 x²² + 8.874730907546905e-9 x²³ + 4.277408653697482e-9 x²⁴ + 2.064305243595276e-9 x²⁵ + 9.974712684076268e-10 x²⁶ + 4.825345651032184e-10 x²⁷ + 2.336803285122648e-10 x²⁸ + 1.1327664717625831e-10 x²⁹ + 5.495981038395394e-11 x³⁰ + 2.6688027662909334e-11 x³¹ + 1.2970572243188646e-11 x³² + 6.309438715257751e-12 x³³ + 3.071904695721014e-12 x³⁴ + 1.4967552080750751e-12 x³⁵ + 7.296290393609026e-13 x³⁶ + 3.557466214493406e-13 x³⁷ + 1.734781742062317e-13 x³⁸ + 8.4641167744794e-14 x³⁹ + 4.1351988664342396e-14 x⁴⁰ + 2.0245607188192277e-14 x⁴¹ + 9.933435583249127e-15 x⁴² + 4.87745577266054e-15 x⁴³ + 2.3898424070298422e-15 x⁴⁴ + 1.164730557369523e-15 x⁴⁵ + 5.638532846273414e-16 x⁴⁶ + 2.7201988011610697e-16 x⁴⁷ + 1.3204809121747408e-16 x⁴⁸ + 6.541814035827748e-17 x⁴⁹ + 3.3413699485305246e-17 x⁵⁰ + 1.750131222506521e-17 x⁵¹ + 9.158752144614354e-18 x⁵² + 4.592589955603457e-18 x⁵³ + 2.092072012797721e-18 x⁵⁴ + 8.029050207486038e-19 x⁵⁵ + 2.2317192379005413e-19 x⁵⁶ + 2.5459451555342405e-20 x⁵⁷ - 5.194425770307503e-22 x⁵⁸ + 2.508218649398269e-20 x⁵⁹ + 4.726277522731426e-20 x⁶⁰ + 5.099591855430971e-20 x⁶¹ + 4.0237927900139253e-20 x⁶² + 2.4012059810360116e-20 x⁶³ + 9.464022285185436e-21 x⁶⁴ - 8.560789937190647e-23 x⁶⁵ - 4.4530982758298455e-21 x⁶⁶ - 5.0935311392342046e-21 x⁶⁷ - 3.811703326348834e-21 x⁶⁸ - 2.0285756003983875e-21 x⁶⁹ - 5.543686046038847e-22 x⁷⁰ + 3.2889317600861456e-22 x⁷¹ + 6.678686505189806e-22 x⁷² + 6.466364352208879e-22 x⁷³ + 4.578004331394191e-22 x⁷⁴ + 2.410193593061127e-22 x⁷⁵ + 7.056801258420997e-23 x⁷⁶ - 3.118640628674264e-23 x⁷⁷ - 7.253314824525695e-23 x⁷⁸ - 7.383671851819276e-23 x⁷⁹ - 5.553094701417065e-23 x⁸⁰ - 3.2534231869591845e-23 x⁸¹ - 1.3172312889958448e-23 x⁸² - 4.6537002481632535e-25 x⁸³ + 5.852887338436875e-24 x⁸⁴ + 7.526522169523832e-24 x⁸⁵ + 6.5491773946846995e-24 x⁸⁶ + 4.527660619681191e-24 x⁸⁷ + 2.484347522530125e-24 x⁸⁸ + 9.128664351625636e-25 x⁸⁹ - 6.364263035599112e-26 x⁹⁰ - 5.26940020289893e-25 x⁹¹ - 6.36132983252991e-25 x⁹² - 5.492753722287055e-25 x⁹³ - 3.869126645659105e-25 x⁹⁴ - 2.2388952296311785e-25 x⁹⁵ - 9.622509299690597e-26 x⁹⁶ - 1.334906115815213e-26 x⁹⁷ + 3.0045944188318423e-26 x⁹⁸ + 4.508518096605067e-26 x⁹⁹ + 4.3209257579636724e-26 x¹⁰⁰ + 𝒪(‖x‖¹⁰¹)

Rather remarkably it worked!

I'm going to close this as the issue is in TaylorSeries.jl, not here.