1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
%**<title>The Haskell 98 Library Report: Complex Numbers</title>
%**~header
\section{Complex Numbers}
\label{lib-num}
\outline{
\inputHS{headers/Complex}
}
Complex numbers are an algebraic type.
The constructor @(:+)@\indextt{:+} forms a complex number from its
real and imaginary rectangular components. This constructor is
strict: if either the real part or the imaginary part of the number is
$\bot$, the entire number is $\bot$. A complex number may also
be formed from polar components of magnitude and phase by the function
@mkPolar@\indextt{mkPolar}. The function @cis@\indextt{polar}
produces a complex number from an angle "t".
Put another way, @cis@ "t" is a complex value with magnitude "1"
and phase "t" (modulo "2\pi").
The function @polar@\indextt{polar} takes a complex number and
returns a (magnitude, phase) pair in canonical form: The magnitude is
nonnegative, and the phase, in the range $(- \pi , \pi ]$; if the
magnitude is zero, then so is the phase.
The functions @realPart@\indextt{realPart} and
@imagPart@\indextt{imagPart} extract the rectangular components of a
complex number and the functions @magnitude@\indextt{magnitude} and
@phase@\indextt{phase} extract the polar components of a complex
number. The function @conjugate@\indextt{conjugate} computes the
conjugate of a complex number in the usual way.
The magnitude and sign of a complex number are defined as follows:
\bprog
@
abs z = magnitude z :+ 0
signum 0 = 0
signum z@@(x:+y) = x/r :+ y/r where r = magnitude z
@
\eprog
That is, @abs@ $z$ is a number with the magnitude of $z$, but oriented
in the positive real direction, whereas @signum@ $z$ has the phase of
$z$, but unit magnitude.
\subsection{Library {\tt Complex}}
\inputHS{code/Complex}
%**~footer
|