davjam / HaskellNumericsTestsFixes

Tests, fixes and illustrations for Haskell floating point (real & complex) functions. The intention is to integrate the fixes back into core Haskell.
0 stars 0 forks source link
haskell

HaskellNumericsTestsFixes

Whilst trying to understand numbers in Haskell(*), I discovered some issues:

This repo is work-in-progress, and has code to test and fix these problems. I'm trying to develop a more complete set of tests that can become part of the Haskell CI test suite. I intend to integrate the fixes back into core Haskell. (With some help!)

It also has illustrations of the complex functions as they are and as they should be when fixed. These are based on the diagrams in "Common Lisp The Language (2nd Edition)" by Guy Steele Jr, wih some modifications:

The diagrams are explained well in the book, but briefly: Each diagram shows a decorated complex plane with axes that have markers at +/- 1, 2, 3 & 4 and slightly smaller markers at pi/2 and pi. The "id" graph shows an initial decoration of lines and rings. The other graphs show how these same decorations are mapped under the different functions.

An illustration of the incorrect branch cuts with sqrt, for example, become quite visible:

Similar "open edges" can be seen in the other functions, and these all get closed with the new code. An additional issue is visible in e.g. asin, where the mapped lines along the negative real axis wobble between 0 and -0. Again, this is fixed in the new functions (with the solid and dashed lines being straight). (However, I'm not sure they're yet quite in the right places, so more work is needed to validate/correct.)

The main files in the repo are:

(*): As part of trying to understand, I thought I'd write a wiki page on them (the draft is here, and it still needs quite a lot of work).