Admin message

Due to a large amount of spam we do not allow new users to create repositories, they are "external" users. If you are a new user and want to create a repository, for example for forking GHC, open a new issue on ghc/ghc using the "get-verified" issue template

Hyperbolic area sine is unstable for (even moderately) big negative arguments.
`asinh` is supposed to be the inverse of `sinh`, and this works pretty reliable for positive arguments. However, for negative arguments, the [currently used formula](http://hackage.haskell.org/package/base-4.10.1.0/docs/src/GHC.Float.html#line-473) ``` asinh x = log (x + sqrt (1.0+x*x)) ``` gets unstable much earlier than necessary, namely when the summands in the logarithm cancel almost to zero, dominated by the numerical error of the square root. This is particularly troubling because mathematically \*\*a)\*\* `asinh` is a very “inert” function (i.e. you can carelessly put in huge numbers and – as long as they're not outright `Infinity` – always get a somewhat sane result), pseudo-sigmoidal as it were \*\*b)\*\* it is an *odd function*, fulfilling `asinh (-x) = -asinh x`. Both is reflected in other implementations, e.g. Python, but not in GHC Haskell: ``` GHCi, version 8.2.1 Python 3.5.2 (default, Nov 23 2017, 16:37:01) In [1]: from math import * Prelude> asinh 1e6 In [2]: asinh(1e6) 14.50865773852447 Out[2]: 14.50865773852447 Prelude> asinh (-1e6) In [3]: asinh(-1e6) -14.50865012405984 Out[3]: -14.50865773852447 Prelude> asinh 1e9 In [4]: asinh(1e9) 21.416413017506358 Out[4]: 21.416413017506354 Prelude> asinh (-1e9) In [5]: asinh(-1e9) -Infinity Out[5]: -21.416413017506354 Prelude> asinh 1e76 In [6]: asinh(1e76) 175.6896142481074 Out[6]: 175.68961424810743 Prelude> asinh (-1e76) In [7]: asinh(-1e76) -Infinity Out[7]: -175.68961424810743 ``` Demo of non-inverse property: ``` Prelude> [(x, asinh $ sinh x) | x <- [-25..25]] [(-25.0,-Infinity) ,(-24.0,-Infinity) ,(-23.0,-Infinity) ,(-22.0,-Infinity) ,(-21.0,-Infinity) ,(-20.0,-Infinity) ,(-19.0,-18.021826694558577) ,(-18.0,-18.021826694558577) ,(-17.0,-17.0102257828801) ,(-16.0,-15.998624871201619) ,(-15.0,-14.999878578873695) ,(-14.0,-13.999968823323222) ,(-13.0,-12.999991335176079) ,(-12.0,-12.000000137072186) ,(-11.0,-10.999999903206444) ,(-10.0,-10.000000013503529) ,(-9.0,-9.000000000551713) ,(-8.0,-8.00000000017109) ,(-7.0,-7.000000000036329) ,(-6.0,-5.999999999998066) ,(-5.0,-5.000000000000641) ,(-4.0,-4.000000000000046) ,(-3.0,-2.999999999999989) ,(-2.0,-1.9999999999999991) ,(-1.0,-1.0) ,(0.0,0.0) ,(1.0,1.0) ,(2.0,2.0) ,(3.0,3.0) ,(4.0,4.0) ,(5.0,5.0) ,(6.0,6.0) ,(7.0,7.0) ,(8.0,8.0) ,(9.0,9.0) ,(10.0,10.0) ,(11.0,11.0) ,(12.0,12.0) ,(13.0,13.0) ,(14.0,14.0) ,(15.0,15.0) ,(16.0,16.0) ,(17.0,17.0) ,(18.0,18.0) ,(19.0,19.0) ,(20.0,20.0) ,(21.0,21.0) ,(22.0,22.0) ,(23.0,23.0) ,(24.0,24.0) ,(25.0,25.0)] ``` Those results are less than satisfying, even for inputs that aren't astronomically big at all. A simple fix would be to “copy” the sane positive-number behaviour to the negative side: ``` asinh x | x < 0 = -asinh (-x) | otherwise = log (x + sqrt (1.0+x*x)) ``` <details><summary>Trac metadata</summary> | Trac field | Value | | ---------------------- | -------------- | | Version | 8.2.1 | | Type | Bug | | TypeOfFailure | OtherFailure | | Priority | normal | | Resolution | Unresolved | | Component | libraries/base | | Test case | | | Differential revisions | | | BlockedBy | | | Related | | | Blocking | | | CC | | | Operating system | | | Architecture | | </details> <!-- {"blocked_by":[],"summary":"Hyperbolic area sine is unstable for (even moderately) big negative arguments.","status":"New","operating_system":"","component":"libraries/base","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.2.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"`asinh` is supposed to be the inverse of `sinh`, and this works pretty reliable for positive arguments. However, for negative arguments, the [http://hackage.haskell.org/package/base-4.10.1.0/docs/src/GHC.Float.html#line-473 currently used formula]\r\n{{{\r\nasinh x = log (x + sqrt (1.0+x*x))\r\n}}}\r\ngets unstable much earlier than necessary, namely when the summands in the logarithm cancel almost to zero, dominated by the numerical error of the square root.\r\n\r\nThis is particularly troubling because mathematically **a)** `asinh` is a very “inert” function (i.e. you can carelessly put in huge numbers and – as long as they're not outright `Infinity` – always get a somewhat sane result), pseudo-sigmoidal as it were **b)** it is an ''odd function'', fulfilling `asinh (-x) = -asinh x`.\r\n\r\nBoth is reflected in other implementations, e.g. Python, but not in GHC Haskell:\r\n{{{\r\nGHCi, version 8.2.1 Python 3.5.2 (default, Nov 23 2017, 16:37:01) \r\n\r\n In [1]: from math import *\r\n\r\nPrelude> asinh 1e6 In [2]: asinh(1e6)\r\n14.50865773852447 Out[2]: 14.50865773852447\r\n\r\nPrelude> asinh (-1e6) In [3]: asinh(-1e6)\r\n-14.50865012405984 Out[3]: -14.50865773852447\r\n\r\nPrelude> asinh 1e9 In [4]: asinh(1e9)\r\n21.416413017506358 Out[4]: 21.416413017506354\r\n\r\nPrelude> asinh (-1e9) In [5]: asinh(-1e9)\r\n-Infinity Out[5]: -21.416413017506354\r\n\r\nPrelude> asinh 1e76 In [6]: asinh(1e76)\r\n175.6896142481074 Out[6]: 175.68961424810743\r\n\r\nPrelude> asinh (-1e76) In [7]: asinh(-1e76)\r\n-Infinity Out[7]: -175.68961424810743\r\n}}}\r\n\r\nDemo of non-inverse property:\r\n{{{\r\nPrelude> [(x, asinh $ sinh x) | x <- [-25..25]]\r\n[(-25.0,-Infinity)\r\n,(-24.0,-Infinity)\r\n,(-23.0,-Infinity)\r\n,(-22.0,-Infinity)\r\n,(-21.0,-Infinity)\r\n,(-20.0,-Infinity)\r\n,(-19.0,-18.021826694558577)\r\n,(-18.0,-18.021826694558577)\r\n,(-17.0,-17.0102257828801)\r\n,(-16.0,-15.998624871201619)\r\n,(-15.0,-14.999878578873695)\r\n,(-14.0,-13.999968823323222)\r\n,(-13.0,-12.999991335176079)\r\n,(-12.0,-12.000000137072186)\r\n,(-11.0,-10.999999903206444)\r\n,(-10.0,-10.000000013503529)\r\n,(-9.0,-9.000000000551713)\r\n,(-8.0,-8.00000000017109)\r\n,(-7.0,-7.000000000036329)\r\n,(-6.0,-5.999999999998066)\r\n,(-5.0,-5.000000000000641)\r\n,(-4.0,-4.000000000000046)\r\n,(-3.0,-2.999999999999989)\r\n,(-2.0,-1.9999999999999991)\r\n,(-1.0,-1.0)\r\n,(0.0,0.0)\r\n,(1.0,1.0)\r\n,(2.0,2.0)\r\n,(3.0,3.0)\r\n,(4.0,4.0)\r\n,(5.0,5.0)\r\n,(6.0,6.0)\r\n,(7.0,7.0)\r\n,(8.0,8.0)\r\n,(9.0,9.0)\r\n,(10.0,10.0)\r\n,(11.0,11.0)\r\n,(12.0,12.0)\r\n,(13.0,13.0)\r\n,(14.0,14.0)\r\n,(15.0,15.0)\r\n,(16.0,16.0)\r\n,(17.0,17.0)\r\n,(18.0,18.0)\r\n,(19.0,19.0)\r\n,(20.0,20.0)\r\n,(21.0,21.0)\r\n,(22.0,22.0)\r\n,(23.0,23.0)\r\n,(24.0,24.0)\r\n,(25.0,25.0)]\r\n}}}\r\nThose results are less than satisfying, even for inputs that aren't astronomically big at all.\r\n\r\nA simple fix would be to “copy” the sane positive-number behaviour to the negative side:\r\n{{{\r\n asinh x\r\n | x < 0 = -asinh (-x)\r\n | otherwise = log (x + sqrt (1.0+x*x))\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->
issue