bugGNU Scientific Library - Bugs: bug #66862, Bug: duplicate functions in GSL...

 
 

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

bug #66862: Bug: duplicate functions in GSL produce differing results

Submitter:  Fermé le Lundi <fermelelundi>
Submitted:  Sun 02 Mar 2025 09:01:17 PM UTC
   
 
Category:  None Severity:  3 - Normal
Priority:  5 - Normal Operating System: 
Status:  None Assigned to:  None
Open/Closed:  Open Release:  2.8

Discussion

Sat 08 Mar 2025 10:57:34 PM UTC, comment #1: 

The findings were due to rounding errors and both implementations ultimately rely on the identities:
\sin(x+iy)=\frac{1}{2}\left(\sin(x)\left(e^y+e^{-y}\right)+i\cos(x)\left(e^y-e^{-y}\right)\right) \\
\cos(x+iy)=\frac{1}{2}\left(\cos(x)\left(e^y+e^{-y}\right)-i\sin(x)\left(e^y-e^{-y}\right)\right)

Specifically finding 3 can be ignored.

Still, it would make sense to rationalise the functions, for example have complex/gsl_complex_sin() point to specfunc/gsl_sf_complex_sin_e(). The former relies on the native implementations sinh() / cosh(h), while the latter on sinh_series() / cosh_series(), which are under our control and allow for arbitrary precision.

Some additional test cases have been added. Where they fail, it is down to accuracy at 10^-14 or smaller. Results have been checked against Julia and Mathematica.

Further areas for improvement for specfunc/trig.c and can be added to specfunc/TODO file:
1- naming conventions of variables could be made more consistent, for example a_r instead of R for the real part of the argument.
2- there are gsl_sf_complex_sin_e() and gsl_sf_complex_cos_e(), but no gsl_sf_complex_sin() or gsl_sf_complex_cos().
3- there is a gsl_sf_complex_logsin_e(), but no gsl_sf_complex_logcos_e().
4- these functions should be called gsl_sf_complex_lnsin_e() etc, to match with naming convention of similar logarithm functions.


(file #56988)

Fermé le Lundi <fermelelundi>
Sun 02 Mar 2025 09:01:17 PM UTC, original submission:  

Some functions are duplicated within GSL, notably complex sine and complex cosine:
- gsl_complex_sin() from module complex versus gsl_sf_complex_sin_e() from specfunc
- gsl_complex_cos() from module complex versus gsl_sf_complex_cos_e() from specfunc

Attached is a self-contained test program that calculates the results of these functions within a square around the origin and only reports a line when the deviation in either the real part or imaginary part exceeds a tolerance level. The following observations can be made:
1- Results across function implementations vary: although the deviation is mostly at machine-precision tolerance level, the implementations themselves also vary, which may be a factor. Large deviations apparently only occur for an imaginary part larger than pi.
2- Possibly related is the observation that the deviations are not necessarily symmetrical: sin(-5.7 -6.2 i) prints a line, but sin(5.7 -6.2 i) does not.
3- The results are incorrect: for an even function like cos(), the following should not occur:

gsl_complex_cos (-6.2 -5.3 i) = 98.008630 +9.833157 i
gsl_complex_cos ( 6.2 -5.3 i) = 98.283853 -6.532418 i

gsl_sf_complex_cos_e (-6.2 -5.3 i) = 98.008630 +9.833157 i
gsl_sf_complex_cos_e ( 6.2 -5.3 i) = 98.283853 -6.532418 i

Analogous examples can be found for sin().

Fermé le Lundi <fermelelundi>

 

Attached Files

Attached Files
file #56988:  specfunc_test_sf.diff added by fermelelundi (5.7KiB - text/x-patch)
file #56965:  test_complex.c added by fermelelundi (1.8KiB - text/x-csrc)

 

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 fermelelundi (Submitted the item)
  •  

    History

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2025-03-08 fermelelundi Attached File- Added specfunc_test_sf.diff, #56988
    2025-03-02 fermelelundi Attached File- Added test_complex.c, #56965

    Back to the top

    Powered by Savane 3.16-a7ba.
    Corresponding source code