JuliaMath / HypergeometricFunctions.jl

A Julia package for calculating hypergeometric functions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug in U?

ivanamelio opened this issue · comments

Hi, running with v0.3.11 of HypergeometricFunctions

for j in 0:6
println(HypergeometricFunctions.U(1+j/2,0,1/3))
end

gives me

0.6143979878634537
0.38435741104660415
0.0
0.0
0.0
0.024547568953281675
0.0

instead of positive decreasing values (also checked with Mathematica)...

Hi @ivanamelio, thanks for this issue. This issue is actually something I'm working on at the moment, but note that BigFloat output seems to have the correct properties:

julia> for j in 0:20
           println(HypergeometricFunctions.U(1+big(j)/2,big(0),big(1)/3))
       end
0.6143979878633059930529986481946891395464018460444936519115011813014985992155978
0.3843574110466951556143610366815030076307366734382481164385086415837863330929593
0.2167976525071903252284984228938039961374688203852425938967513781850816991311835
0.1123403698855282852369185302792773132580642921578511100987013871423972576891848
0.05417641772241979160063797516863247395266050704859293138462579847230923842512515
0.02454756895346160369324241426376868530425975825565232046718842931531417589962462
0.0105266383112334740201840627645168060191150881324316087393787787894064010986274
0.004296834017345405831546614242647177500942260426471909417609339333539049517106234
0.001677278410226291261711460726783712143664928036083523738843201238637204831748533
0.0006285339478153071003848882963342075974896163929192794921413631433421003570379826
0.0002268412864812734116944788248527184266251944969032712187333655781059354354119804
7.906435593178763560322945778481609148550280727123332848464642305840511665702684e-05
2.667692356450986069493122491428131233442390696167034822702319582546241396141889e-05
8.731435171456985456235989212923219603085559740796544704012085417503878568281929e-06
2.777284844226808183325036885452030657765741122869114985487504084376648769915993e-06
8.598847063616126754361680023007572668519075883029598480032243661861008268799029e-07
2.595193827480741615654311696495628019780073802572943963324912623262831378145913e-07
7.644870677578081632186901333692350492071213774763375844842687631173803232776881e-08
2.20063389572727938374948284235920819833080835020142475623129895289531571562579e-08
6.196728066534500652831741910239904711263429321483303077691180348400850723459843e-09
1.708571297422478604214821287546753318326578645002987613041268329237504212240463e-09

Thanks a lot, this fix solves my problems:) However, with this trick the evaluation is pretty slow, as you probably already know. Thanks again!

On master, your problem can now be done in 64-bit floating-point with about 11 correct digits:

julia> for j in 0:6
           println(Float64(abs(U(1+j/2,0,1/3) - U(1+j/2,0,big(1)/3))/U(1+j/2,0,big(1)/3)))
       end
7.567546759701554e-14
1.5602403648400533e-11
2.9867028861393172e-12
2.5346581410409292e-11
1.9442932867656743e-11
3.3192636884057e-12
4.959431974253592e-12

and the BigFloat version (which I would still recommend using at this point) is faster due to an algorithmic backend change:

julia> @time for j in 0:6
           println(Float64(U(1+j/2,0,big(1)/3)))
       end
0.614397987863306
0.38435741104669513
0.21679765250719032
0.11234036988552829
0.05417641772241979
0.024547568953461604
0.010526638311233474
  0.222503 seconds (6.14 M allocations: 327.703 MiB, 14.62% gc time)

julia> @time for j in 0:6
           println(Float64(U(1+j/2,0,big(1)/3)))
       end
0.614397987863306
0.38435741104669513
0.21679765250719032
0.11234036988552829
0.05417641772241979
0.024547568953461604
0.010526638311233474
  1.723295 seconds (43.99 M allocations: 2.294 GiB, 6.85% gc time, 0.94% compilation time)

I'll tag a minor release soon.

Thanks for the update. For j till around 20 the new version works very well, for larger values there is still some issue.