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
Errors in complex hyp2f1 values (Trac #1034) #1561
Comments
Milestone changed to |
There's still some issue for real values as well:
Here's a plot showing the region of inputs for which nans are returned:
This was found by investigating gh-1285 in more detail. |
Issue for hyp2f1 that is worked around is discussed in scipygh-1561.
In the original complex example, HYGFZ is making use of http://dlmf.nist.gov/15.8#E8 together with http://dlmf.nist.gov/5.5#E4. If
|
The HYGFZ implementation in SPECFUN may be lacking also in other respects, I'm a bit worried about its behavior for large It may be faster to rewrite the routine from scratch (in C or C++) following some systematic approach to 2F1 evaluation, than to try to address the problems in the F77 code. I believe this problem has been extensively studied in the literature. I'm not aware of license-compatible 2F1 implementations that we could use. |
It's been studied indeed: Somebody even wrote an MSc thesis on exactly this. http://people.maths.ox.ac.uk/porterm/research/pearson_final.pdf |
I've implemented a tiny part of this, and it seems to work well enough to solve #3479. A newer publication http://arxiv.org/pdf/1407.7786v1.pdf has more details, but it has some typos in the formulas that could be annoying if you are just directly transcribing it -- there are fencepost errors in the indexing and at least one of the yN should be y0. The arxiv links to some code http://datashare.is.ed.ac.uk/handle/10283/607 which is in a repository marked as http://opendatacommons.org/licenses/by/. I'm not sure whether that code is actually licensed under that license, and if so, I'm not sure whether that license is compatible with scipy. from __future__ import print_function, division
import numpy as np
import scipy.linalg
from scipy.special import hyp2f1
def recurrence_00p(a, b, c, z, n):
denom = (c-a+n)*(c-b+n)*z
an = (c+n)*(c+n-1)*(z-1) / denom
bn = (c+n)*(c+n-1-(2*(c+n)-a-b-1)*z) / denom
return an, bn
def solve_recurrence(a, b, c, z, N, recurrence):
# This could be improved in a couple of ways.
# First, this uses an upper triangular matrix with
# small bandwidth that doesn't need to be constructed
# and solved naively. Second, it could be solved using
# Olver's Algorithm instead of Miller's Algorithm
# to avoid using arbitary N.
M = np.identity(N+1)
for i in range(N-1):
an, bn = recurrence(a, b, c, z, i+1)
M[i, i+0] = an
M[i, i+1] = bn
M[i, i+2] = 1
v = np.zeros(N+1)
v[-2] = 1
return scipy.linalg.solve(M, v)
def main():
a = 10
b = 5
c = -300.5
k = 300 # We want a recursion reducing |c| by this amount.
z = 0.5
N = 400 # An arbitrary number a bit bigger than k.
y = solve_recurrence(a, b, c, z, N, recurrence_00p)
fk = hyp2f1(a, b, c+k, z) # Base case.
f0_approx = fk * (y[0] / y[k])
print(f0_approx)
main()
|
There is also http://arxiv.org/abs/0708.0116. The code is very safe in http://www.cpc.cs.qub.ac.uk/ where Elsevier has top men working on it right now. |
CPC - amazing website! Code apparently has license http://www.cpc.cs.qub.ac.uk/licence/licence.html. C++ and Fortran 90 code. I guess we could ask the authors to relicense. |
The real-valued cephes
One probably should add something like |
This is a bit off-topic, but here's a recent 2F1 blog post by the mpmath author who is now developing a C arbitrary precision library http://fredrikj.net/blog/2015/10/the-2f1-bites-the-dust/. |
Still relevant as of 1.10, unfortunately not fixed by @steppi's work in the 1.8 cycle. |
I’m going to start working on this again shortly. There’s still a couple of other cases where the Fortran needs to be replaced and then I’ll implement Miller’s algorithm or Olver’s algorithm to handle large |
Original ticket http://projects.scipy.org/scipy/ticket/1034 on 2009-10-25 by @pv, assigned to @pv.
Complex-valued stuff from gh-1286:
The text was updated successfully, but these errors were encountered: