NumericPrelude-0.0: An experimental alternative hierarchy of numeric type classesContentsIndex
Number.Complex
Portabilityportable (?)
Stabilityprovisional
Maintainernumericprelude@henning-thielemann.de
Contents
Cartesian form
Polar form
Conjugate
Properties
Auxiliary classes
Description
Complex numbers.
Synopsis
data T a
fromReal :: C a => a -> T a
(+:) :: a -> a -> T a
fromPolar :: C a => a -> a -> T a
cis :: C a => a -> T a
signum :: (C a a, C a) => T a -> T a
toPolar :: Polar a => T a -> (a, a)
magnitude :: Polar a => T a -> a
phase :: Polar a => T a -> a
class C a => Polar a where
toPolar :: T a -> (a, a)
magnitude :: T a -> a
phase :: T a -> a
defltMagnitude :: C a => T a -> a
defltPhase :: (C a, C a) => T a -> a
conjugate :: C a => T a -> T a
propPolar :: (Polar a, C a) => T a -> Bool
class C a => Divisible a where
divide :: T a -> T a -> T a
defltDiv :: C a => T a -> T a -> T a
class C a => Power a where
power :: Rational -> T a -> T a
defltPow :: (Polar a, C a) => Rational -> T a -> T a
Cartesian form
data T a
Complex numbers are an algebraic type.
show/hide Instances
C T
C a b => C a (T b)
C a b => C a (T b)
C a b => C a (T b)
(C a, C a v) => C a (T v)
(Ord a, C a v) => C a (T v)
(Show v, C v, C v, C a v) => C a (T v)
C a => C (T a)
C a => C (T a)
C a => C (T a)
C a => C (T a)
C a => C (T a)
(Ord a, C a) => C (T a)
(Ord a, C a, C a) => C (T a)
Divisible a => C (T a)
(Polar a, Real a, C a, Divisible a, Power a) => C (T a)
(Polar a, Real a, C a, Divisible a, Power a) => C (T a)
Eq a => Eq (T a)
(C a, Eq a, Show a, Divisible a) => Fractional (T a)
(C a, Eq a, Show a) => Num (T a)
Read a => Read (T a)
Show a => Show (T a)
fromReal :: C a => a -> T a
(+:) :: a -> a -> T a
Construct a complex number from real and imaginary part.
Polar form
fromPolar :: C a => a -> a -> T a
Form a complex number from polar components of magnitude and phase.
cis :: C a => a -> T a
cis t is a complex value with magnitude 1 and phase t (modulo 2*pi).
signum :: (C a a, C a) => T a -> T a

Scale a complex number to magnitude 1.

For a complex number z, 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.

toPolar :: Polar a => T a -> (a, a)
The function toPolar 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.
magnitude :: Polar a => T a -> a
phase :: Polar a => T a -> a
class C a => Polar a where

Minimal implementation: toPolar or (magnitude and phase), usually the instance definition

magnitude = defltMagnitude
phase     = defltPhase

is enough.

This class requires transcendent number types although magnitude can be computed algebraically.

Methods
toPolar :: T a -> (a, a)
The function toPolar 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.
magnitude :: T a -> a
phase :: T a -> a
show/hide Instances
defltMagnitude :: C a => T a -> a
defltPhase :: (C a, C a) => T a -> a
The phase of a complex number, in the range (-pi, pi]. If the magnitude is zero, then so is the phase.
Conjugate
conjugate :: C a => T a -> T a
The conjugate of a complex number.
Properties
propPolar :: (Polar a, C a) => T a -> Bool
Auxiliary classes
class C a => Divisible a where
In order to have an efficient implementation for both complex floats and exact complex numbers, we define the intermediate class Complex.Divisible which in fact implements the complex division. This way we avoid overlapping and undecidable instances. In most cases it should suffice to define an instance of Complex.Divisible with no method implementation for each instance of Fractional.
Methods
divide :: T a -> T a -> T a
show/hide Instances
defltDiv :: C a => T a -> T a -> T a
class C a => Power a where
We like to build the Complex Algebraic instance on top of the Algebraic instance of the scalar type. This poses no problem to sqrt. However, root requires computing the complex argument which is a transcendent operation. In order to keep the type class dependencies clean for more sophisticated algebraic number types, we introduce a type class which actually performs the radix operation.
Methods
power :: Rational -> T a -> T a
show/hide Instances
defltPow :: (Polar a, C a) => Rational -> T a -> T a
Produced by Haddock version 0.7