Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pFq falsely evaluates to NaN #73

Open
mauricelanghinrichs opened this issue Sep 27, 2023 · 2 comments
Open

pFq falsely evaluates to NaN #73

mauricelanghinrichs opened this issue Sep 27, 2023 · 2 comments

Comments

@mauricelanghinrichs
Copy link

mauricelanghinrichs commented Sep 27, 2023

Thanks for this great package. Has been really useful, however I noticed a potential bug when evaluating a specific value:

I got

julia> pFq((-4, -3, 151), (2, -153), -1.0)
NaN

while nearby values are computed correctly, such as

julia> pFq((-4, -3, 151), (2, -154), -1.0)
13.708301502419149

Mathematica would compute values

In[1]:= HypergeometricPFQ[{-4, -3, 151}, {2, -153}, -1.0]

Out[1]= 13.8431

In[2]:= HypergeometricPFQ[{-4, -3, 151}, {2, -154}, -1.0]

Out[2]= 13.7083

so matching the second value and providing a numerical value instead of NaN for the first case.

Increasing precision does not help

julia> pFq((-4, -3, 151), (2, -153), big(-1.0))
NaN

Julia version v"1.8.5", SpecialFunctions v2.3.0, HypergeometricFunctions v0.3.23.

@MikaelSlevinsky
Copy link
Collaborator

Hi @mauricelanghinrichs, thanks for the bug report! In fact, 3F2 has the special method here, which is a rational approximation. I think the explanation is that it's exactly hitting a pole/pole.

Looking at your parameters, you are computing terminating functions, so they're actually polynomials. It would be arguably safe to use

julia> HypergeometricFunctions.pFqmaclaurin((-4, -3, 151), (2, -153), -1.0)
13.843137254901961

just for the moment. (I generally discourage calling internals, but I don't have a bug fix available right now.)

Or you can perturb the argument

julia> (pFq((-4, -3, 151), (2, -153), -1.0+eps()) + pFq((-4, -3, 151), (2, -153), -1.0-eps()))/2
13.843137254901961

More generally, it looks like pFq((-4, -3, k-2), (2, -k), -1.0) also fails...

@mauricelanghinrichs
Copy link
Author

Thanks for the fast response!

Yes, I think all my cases are terminating hypergeometric functions, as the pFq came up from a finite sum over an expression. So generally the HypergeometricFunctions.pFqmaclaurin could work. However, am I correct to assume that pFqmaclaurin will be typically slower than pFqweniger (default call of pFq here)? As pFqmaclaurin approximates by adding up series elements?

just for the moment. (I generally discourage calling internals, but I don't have a bug fix available right now.)

Agree on this, the interface with simply pFq is perfect for relative non-experts (like me)!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants