Complex numbers

Complex numbers are catered for in the Haskell 98 and Haskell 2010 Language Reports. The former specifies library Complex exposing module Complex and the latter (which introduced hierarchical modules names) specifies module Data.Complex. Both modules define:

The RealFloat a context also implies that the type a is an instance of typeclasses Eq, Floating, Fractional, Num, Ord, Real, RealFrac and Show. The typeclass RealFloat promises atan2 (among other functions). The typeclass Floating promises exp, log, sqrt, sin, cos, tan, asin, sinh, and asinh (among other functions).

The types Float and Double are instances of typeclass RealFloat.

base

The package base provides an implementation of module Data.Complex. For base >= 4.4.0.0 (GHC 7.2.1 came with base-4.4.0.0), the module defines (without the context RealFloat a):

GHC 7.0.1 had introduced language extension DatatypeContexts which was “on by default“. GHC 7.2.1 changed that to “off by default“, although it was enabled by languages Haskell98 and Haskell2010 and GHC defaulted to Haskell98 and, from GHC 7.0.1, Haskell2010. (However, GHC did not document Haskell98 and Haskell2020 as language extensions until GHC 8.10.1.)

GHC 7.2.1 documented that data Complex had lost its previous context because DatatypeContexts had been ‘removed’ “from the language“.

However, the context is present in the instance of the Num typeclass:

abs :: Complex a -> Complex a is purposed to equate to magnitude (\left| z \right|) and signum :: Complex a -> Complex a is (except for 0 :+ 0) purposed to equate to z / \left| z \right|.

Multivalued functions

\sqrt z, \ln z, \arcsin z (etc) and \operatorname{arcsinh} z (etc) are multivalued functions.

For:

z = r e^{i\theta}, \quad r \gt 0, \quad -\pi \lt \theta \le \pi

the principal value of \sqrt z is defined as:

\sqrt r e^{i\theta / 2}

the principal value of \ln z is defined as:

\ln r + i\theta

the principal value of \arcsin z is defined as:

-i \ln \left( iz + \sqrt {1 - z^2} \right)

and the principal value of \operatorname{arcsinh} z is defined as:

\ln \left( z + \sqrt {1 + z^2} \right)

where the logarithm and square root refer to the principal values.

sqrt, log, asin and asinh are implemented accordingly.