bugGNU Scientific Library - Bugs: bug #54998, Bugs in gsl_sf_hyperg_2F1

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #54998: Bugs in gsl_sf_hyperg_2F1

Submitter:  Ludvig af Klinteberg <ludvigak>
Submitted:  Sat 10 Nov 2018 12:42:24 AM UTC
   
 
Category:  Accuracy problem Severity:  3 - Normal
Priority:  5 - Normal Operating System: 
Status:  None Assigned to:  None
Open/Closed:  Open Release:  2.5

Discussion

Mon 10 Nov 2025 04:57:52 PM UTC, comment #2: 

The patch would be to replace the calls to gsl_sf_lngamma_e() by calls to gsl_sf_lngamma_sgn_e()
and to multiply F1 and F2 by the product of the signs of the Gamma-prefactors.
More important would be to flag gsl_sf_lngamma_e() with an error if the sign is negative.
Currently the sign is actually computed in gsl_sf_lngamma_e()
but this effect is hidden in the gsl_sf_result.

R. J. Mathar <rjmathar>
Mon 10 Nov 2025 04:36:11 PM UTC, comment #1: 

The Moshier reference is in https://www.moshi ... .net/methprog.pdf .
The problem within the GSL implementation is that F_2 is returned with
the wrong sign. This is triggered by a=-0.25 being negative, d_2=0 such that GAMMA(a+d_2)
in the denominator of the prefactor of F_2 is negative. Because the
implementation actually implements the Gamma(c)*(1-x)^d_1 /GAMMA(a+d2)/GAMMA(b+d2)
by computing the logarithm of this, it actually computes the logarithm of an
negative factor and gets the wrong branch.
GSL returns is F_1+(-1)*F_2 (with |d|=1) so
it returns 0.90031631-0.02027 but should have returned 0.90031+0.02027.

R. J. Mathar <rjmathar>
Sat 10 Nov 2018 12:42:24 AM UTC, original submission:  

For some reason hyperg_2F1_reflect computes the wrong value when c-a-b is integer, and a and b are of opposite signs, e.g.

gsl_sf_hyperg_2F1_e(-0.25, 0.25, 1.0, 0.9, &r)
=> 0.8800433809321181 (should be 0.92058925138209276)

I don't have access to Moshier, so I can't tell if it's due to the "reflection" method or just a bug. However, hyperg_2F1_series appears to compute the correct value for these cases, so a workaround is to use that when a and b are of opposite signs:
https://github.co ... c9c6343bfd8ba5438

This appears to fix some of the issues mentioned in bugs #39056, #32306, #21835.

In addition, the fix introduced in commit 9163448f5e0bfa3591a2535c16a2e37386b91171 could use some amendment. First, it uses a stopping criterion of two terms, not the three that Pearson recommends. Second, the new stopping criterion doesn't associate an error estimate with the new termination criteria. This gives an error estimate of O(1) when it's used:

gsl_sf_hyperg_2F1_e(-0.25, 0.25, 1, 0.25, &r)
=> val=0.9833426507751653, err=1.0000000000000049

This can be fixed as:
https://github.co ... 5c7c6ef88e60486d0

Ludvig af Klinteberg <ludvigak>

 

Attached Files

This item currently has no attached files.

 

Dependencies

This item does not depend on any other items.

No items depend on this one.

 

Mail Notification Carbon-Copy List

Carbon-Copy List
  • -email is unavailable- added by rjmathar (Posted a comment)
  • -email is unavailable- added by ludvigak (Submitted the item)
  •  

    History

    No changes have been made to this item

    Back to the top

    Powered by Savane 3.16-598c.
    Corresponding source code