numeric-prelude-0.3.0.2: An experimental alternative hierarchy of numeric type classes

Portability portable (?) provisional numericprelude@henning-thielemann.de Safe-Infered

Number.Complex

Description

Complex numbers.

Synopsis

# Cartesian form

data T a Source

Complex numbers are an algebraic type.

Instances

 Functor T C T C a b => C a (T b) The '(*>)' method can't replace `scale` because it requires the Algebra.Module constraint C a b => C a (T b) (C a, Sqr a b) => C a (T b) Sqr a b => Sqr a (T b) (Ord a, C a v) => C a (T v) (C a, C a v) => C a (T v) (Show v, C v, C v, C a v) => C a (T v) C a v => C a (T v) Eq a => Eq (T a) (C a, Eq a, Show a) => Fractional (T a) (C a, Eq a, Show a) => Num (T a) Read a => Read (T a) Show a => Show (T a) Arbitrary a => Arbitrary (T a) Storable a => Storable (T a) 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) (C a, C a, C a) => C (T a) C a => C (T a) (C a, C a, Power a) => C (T a) (C a, C a, C a, Power a) => C (T a) Zero a => Zero (T a)

fromReal :: C a => a -> T aSource

(+:) :: a -> a -> T aSource

Construct a complex number from real and imaginary part.

(-:) :: C a => a -> a -> T aSource

Construct a complex number with negated imaginary part.

scale :: C a => a -> T a -> T aSource

Scale a complex number by a real number.

exp :: C a => T a -> T aSource

Exponential of a complex number with minimal type class constraints.

quarterRight, quarterLeft :: C a => T a -> T aSource

Turn the point one quarter to the right.

# Polar form

fromPolar :: C a => a -> a -> T aSource

Form a complex number from polar components of magnitude and phase.

cis :: C a => a -> T aSource

`cis t` is a complex value with magnitude `1` and phase `t` (modulo `2*pi`).

signum :: (C a, C a) => T a -> T aSource

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.

signumNorm :: (C a, C a a, C a) => T a -> T aSource

toPolar :: (C a, C a) => T a -> (a, a)Source

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 :: C a => T a -> aSource

magnitudeSqr :: C a => T a -> aSource

phase :: (C a, C a) => T a -> aSource

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 aSource

The conjugate of a complex number.

# Properties

propPolar :: (C a, C a) => T a -> BoolSource

# Auxiliary classes

class C a => Power a whereSource

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 aSource

Instances

 Power Double Power Float Power T

defltPow :: (C a, C a) => Rational -> T a -> T aSource