[SciPy-Dev] Fixing a bug with scipy's hypergeometric function hyp2f1

Adam Former at physicist.net
Thu Oct 19 14:58:59 EDT 2017


Okay cool; thanks for the helpful reply!

I'll look at Gosper's method and see how it compares with Buhring's method. 
For now I'll plan on doing a PR that implements one of these two methods.  I 
was just worried that I might end up doing a lot of work on a PR that 
implements Buhring's series only to have a reviewer reject it saying "Well, 
you should have used such-and-such's algorithm which is must faster, much 
more accurate, etc."

I'll also hold off on adding a latex doc to the repo of the actual formulas 
used for the b-a=integer special case (unless I hear otherwise).

Thanks again!

--Adam

-----Original Message----- 
From: Joshua Wilson
Sent: Thursday, October 19, 2017 9:35 AM
To: SciPy Developers List
Subject: Re: [SciPy-Dev] Fixing a bug with scipy's hypergeometric function 
hyp2f1

Hey Adam,

> Does this sound like a worthwhile PR?

Yes, definitely

> Does the implementation sound reasonable?

It's been a while since I've thought about this, but if I recall
correctly the problematic region you've found is one that comes up
quite frequently--see e.g. page 14 in

http://fredrikj.net/math/hypgeom.pdf

Floating around in the ether is a method credited to Bill Gosper for
handling that region which also uses a recurrence relation (maybe
related to/the same as in the paper you cited)? I can never seem to
find the original reference (dead link), but I've attached someone's
writeup of it.

So, your implementation sounds reasonable, but if you really want to
dig into it you could check out the Gosper stuff and see how they
compare.

> Can the PR implement formulas/methods that don't appear in the literature?
> Is it going to be a problem if I implement this limit case in the PR?

It's implicit in the literature, so I think it's fine.

> I don't what reference I would place hyp2f1's doc string

The Buhring paper. The formula is something that an informed reader
could figure out after reading it.

> I would be wiling to maybe add a latex doc to the PR (placed somewhere in 
> the doc folder?)

If I recall correctly people were opposed to adding LaTeX docs. (But
maybe I recall incorrectly; if so please someone correct me.) I also
have various special function write ups that might be handy for future
devs... maybe in a separate repo?

On Wed, Oct 18, 2017 at 6:47 PM, Adam <Former at physicist.net> wrote:
> Hello guys,
>
> I've found a small region in the complex plane where scipy's 
> implementation
> of the hypergeometric function hyp2f1 fails. I've documented this error in
> issue 8054 on github.
>
> I am willing to submit a PR that fixes this issue. My PR would basically
> implement the analytic continuation formula given in this paper: (Buhring,
> An Analytic Continuation of the Hypergeometric Series). I've already
> implemented this series in some prototype code written in Fortran and it
> agrees well with the values returned by mpmath's implementation of hyp2f1.
>
> Before I attempt a PR, I just wanted to touch base and ask the group the
> following:
>
> 1) Does this sound like a worthwhile PR? The failure region is somewhat
> small and I don't know with what urgency people would want this fixed.
>
> 2) Does the implementation sound reasonable? My background is physics and 
> so
> I haven't done a complete literature search looking for the *fastest*
> algorithm. All I can say that the Buhring's formula works and my
> implementation only seems to be about %50 slower than the current hyp2f1 
> (at
> points in the complex plane where both methods converge). I would only 
> apply
> Buhring's series in the region where hyp2f1 currently diverges.
>
> 3) Can the PR implement formulas/methods that don't appear in the
> literature? Buhring's paper *only* gives the analytic continuation for the
> case where the difference between the a/b parameters is NOT an integer. 
> When
> a-b=m, the limit case of his series can be derived using a method 
> described
> in "The Special Functions and Their Approximations" by Y. Luke (as Buhling
> mentions in his paper). I've derived the formula for this limit case and
> have an implementation of it that produces values in agreement with 
> mpmath.
> Is it going to be a problem if I implement this limit case in the PR? I 
> ask
> because I don't what reference I would place hyp2f1's doc string. I would 
> be
> wiling to maybe add a latex doc to the PR (placed somewhere in the doc
> folder?) that contains the formula so that future scipy devs have 
> something
> to reference when reviewing hyp2f1's source code.
>
> Anyways, let me know if my idea for a PR sounds like a good idea! I
> apologize for the longish email, but this is my first time trying to
> contribute to scipy...
>
> --Adam
>
> _______________________________________________
> SciPy-Dev mailing list
> SciPy-Dev at python.org
> https://mail.python.org/mailman/listinfo/scipy-dev
>






_______________________________________________
SciPy-Dev mailing list
SciPy-Dev at python.org
https://mail.python.org/mailman/listinfo/scipy-dev 



More information about the SciPy-Dev mailing list