[GHC] #8532: Hyperbolic arc cosine fails on (-1) :: Complex r.

#8532: Hyperbolic arc cosine fails on (-1) :: Complex r. -------------------------------------+------------------------------------- Reporter: leftaroundabout | Owner: Type: bug | Status: new Priority: low | Milestone: Component: libraries/base | Version: 7.6.3 Keywords: | Operating System: Unknown/Multiple Architecture: Unknown/Multiple | Type of failure: Incorrect result Difficulty: Easy (less than 1 | at runtime hour) | Test Case: acosh(-1) :: Blocked By: | Complex Double Related Tickets: | Blocking: -------------------------------------+------------------------------------- When allowing for complex results, the hyperbolic arc cosine is continuously defined on all ℝ. In the {{{(x < (-1))}}} real ray of the complex plane, {{{acosh}}} equals {{{\z -> i * pi + acosh(abs z)}}}, which works fine for almost all arguments. Thus, {{{acosh (-1)}}} should equal {{{i * pi}}}; however due to the implementation as {{{ acosh z = log (z + (z+1) * sqrt ((z-1)/(z+1))) }}} where the denominator in the root becomes zero at {{{z = -1}}}, this comes out as {{{NaN :+ NaN}}}. Could be fixed trivially by adding a special case {{{ acosh ((-1):+0) = 0:+pi }}} to the {{{instance (RealFloat a) => Floating (Complex a)}}} in {{{Data.Complex}}}. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8532 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8532: Hyperbolic arc cosine fails on (-1) :: Complex r. -------------------------------------+------------------------------------- Reporter: leftaroundabout | Owner: Type: bug | Status: new Priority: low | Milestone: Component: libraries/base | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: Incorrect result | Difficulty: Easy (less than 1 at runtime | hour) Test Case: acosh(-1) :: | Blocked By: Complex Double | Related Tickets: Blocking: | -------------------------------------+------------------------------------- Comment (by carter): does this behave as expected in the a small radius around -1? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8532#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8532: Hyperbolic arc cosine fails on (-1) :: Complex r. -------------------------------------+------------------------------------- Reporter: leftaroundabout | Owner: Type: bug | Status: new Priority: low | Milestone: Component: libraries/base | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: Incorrect result | Difficulty: Easy (less than 1 at runtime | hour) Test Case: acosh(-1) :: | Blocked By: Complex Double | Related Tickets: Blocking: | -------------------------------------+------------------------------------- Comment (by leftaroundabout): Replying to [comment:1 carter]:
does this behave as expected in the a small radius around -1? (worth at least plotting it out)
For real arguments, it sure enough works. {{{ GHCi, version 7.4.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Prelude> :m +Data.Complex Prelude Data.Complex> :m +Graphics.Rendering.Chart.Simple Prelude Data.Complex Graphics.Rendering.Chart.Simple> :set prompt "> "
let re f = realPart . f . realToFrac let im f = imagPart . f . realToFrac plotPNG "acosh-on-reals.png" [-2, -1.99 .. 2] (re acosh) (im acosh) }}}
If you put in complex numbers, there's a problem anyway: the imaginary part jumps from {{{+π}}} to {{{-π}}} as {{{Im z}}} becomes negative. Still, ([http://www.wolframalpha.com/input/?i=acosh]) it's apparently convention that for {{{Im z = 0}}}, we always have {{{Im (acosh(z)) ≥ 0)}}}, including {{{z = -1}}}. At any rate, the real part is 0 there; but in the current implementation that is also {{{NaN}}}. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8532#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8532: Hyperbolic arc cosine fails on (-1) :: Complex r. -------------------------------------+------------------------------------- Reporter: leftaroundabout | Owner: Type: bug | Status: new Priority: low | Milestone: Component: libraries/base | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: Incorrect result | Difficulty: Easy (less than 1 at runtime | hour) Test Case: acosh(-1) :: | Blocked By: Complex Double | Related Tickets: Blocking: | -------------------------------------+------------------------------------- Changes (by carter): * cc: hvr, ekmett (added) Comment: hrmm, so one issue with complex functions in general is that there (is always) a "branch cut" http://mathworld.wolfram.com/BranchCut.html http://en.wikipedia.org/wiki/Branch_point http://math.stackexchange.com/questions/245579/how-does-a-branch-cut- define-a-branch are some of the first few decent hits on google for this topic. So do we standardize on the "common" branch cut choice? I'm not sure. If we don't enrich the complex function apis to be somehow parameterized by the branchcut choice, thats probably the "right" thing to do. ("right" being of course not quite the right term) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8532#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8532: Hyperbolic arc cosine fails on (-1) :: Complex r. -------------------------------------+------------------------------------- Reporter: leftaroundabout | Owner: Type: bug | Status: new Priority: low | Milestone: Component: libraries/base | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: Incorrect result | Difficulty: Easy (less than 1 at runtime | hour) Test Case: acosh(-1) :: | Blocked By: Complex Double | Related Tickets: Blocking: | -------------------------------------+------------------------------------- Comment (by ekmett): We do pick the standard branch cut location. That said, it is possible to give a more general form with a specified branch cut. I do so for all of these functions and more for quaternions in http://hackage.haskell.org/package/linear-1.10.1.1/docs/Linear- Quaternion.html You pick the location of the branch cut by supplying a unit quaternion. Adapting this logic to a choice of point on the unit circle could be done, but I confess I'd rather hash that out in libraries before asserting it is the right approach for something like base. Almost nobody knows how to use the more exotic cuts, but importantly they can be formed from the standard cut and identities by somone with sufficient background to be aware of the issue. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8532#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8532: Hyperbolic arc cosine fails on (-1) :: Complex r. -------------------------------------+------------------------------------- Reporter: leftaroundabout | Owner: alekzcb Type: bug | Status: new Priority: low | Milestone: Component: Core Libraries | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Incorrect result | Test Case: acosh(-1) :: at runtime | Complex Double Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by alekzcb): * owner: (none) => alekzcb -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8532#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8532: Hyperbolic arc cosine fails on (-1) :: Complex r. -------------------------------------+------------------------------------- Reporter: leftaroundabout | Owner: alekzcb Type: bug | Status: new Priority: low | Milestone: Component: Core Libraries | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Incorrect result | Test Case: acosh(-1) :: at runtime | Complex Double Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): Do let me know if you encounter trouble, alekzcb. Thanks for picking this up! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8532#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

Do let me know if you encounter trouble, alekzcb. Thanks for picking
#8532: Hyperbolic arc cosine fails on (-1) :: Complex r. -------------------------------------+------------------------------------- Reporter: leftaroundabout | Owner: alekzcb Type: bug | Status: new Priority: low | Milestone: Component: Core Libraries | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Incorrect result | Test Case: acosh(-1) :: at runtime | Complex Double Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by alekzcb): Replying to [comment:8 bgamari]: this up! I believe I have a simple fix for this, but have been wrangling with arcanist for the past day! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8532#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8532: Hyperbolic arc cosine fails on (-1) :: Complex r. -------------------------------------+------------------------------------- Reporter: leftaroundabout | Owner: alekzcb Type: bug | Status: new Priority: low | Milestone: Component: Core Libraries | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Incorrect result | Test Case: acosh(-1) :: at runtime | Complex Double Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): Oh no! What are the symptoms? Feel free to drop by `#ghc` on `irc.freenode.net` if you want help. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8532#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8532: Hyperbolic arc cosine fails on (-1) :: Complex r. -------------------------------------+------------------------------------- Reporter: leftaroundabout | Owner: alekzcb Type: bug | Status: new Priority: low | Milestone: Component: Core Libraries | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Incorrect result | Test Case: acosh(-1) :: at runtime | Complex Double Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by alekzcb): Cheers bgamari. Just having a bit of trouble submitting my commit. Not sure if it's an Arcanist or a Windows issue. Or an "ID 10T" issue... -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8532#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8532: Hyperbolic arc cosine fails on (-1) :: Complex r. -------------------------------------+------------------------------------- Reporter: leftaroundabout | Owner: alekzcb Type: bug | Status: new Priority: low | Milestone: Component: Core Libraries | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Incorrect result | Test Case: acosh(-1) :: at runtime | Complex Double Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): For the record, I suspect the issue was that alekzcb didn't have an editor in his `PATH`. Unfortunately it seems that arcanist doesn't deal with this terribly gracefully. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8532#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8532: Hyperbolic arc cosine fails on (-1) :: Complex r. -------------------------------------+------------------------------------- Reporter: leftaroundabout | Owner: alekzcb Type: bug | Status: new Priority: low | Milestone: 8.4.1 Component: Core Libraries | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: numrun016 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3916 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * testcase: acosh(-1) :: Complex Double => numrun016 * differential: => Phab:D3916 * milestone: => 8.4.1 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8532#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8532: Hyperbolic arc cosine fails on (-1) :: Complex r.
-------------------------------------+-------------------------------------
Reporter: leftaroundabout | Owner: alekzcb
Type: bug | Status: new
Priority: low | Milestone: 8.4.1
Component: Core Libraries | Version: 7.6.3
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Incorrect result | Unknown/Multiple
at runtime | Test Case: numrun016
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D3916
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#8532: Hyperbolic arc cosine fails on (-1) :: Complex r. -------------------------------------+------------------------------------- Reporter: leftaroundabout | Owner: alekzcb Type: bug | Status: closed Priority: low | Milestone: 8.4.1 Component: Core Libraries | Version: 7.6.3 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: numrun016 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3916 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: new => closed * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8532#comment:15 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC