r-k-b / complex / Complex

The complex module allows you to work with complex numbers. There is not much else to say. We have basic constructors, basic operations, trig, exponentials, and logarithms. More may be added in the future.

Basics


type alias Complex =
{ re : Basics.Float, im : Basics.Float }

A complex number is a record of a real part and an imaginary part.

complex : Basics.Float -> Basics.Float -> Complex

Generates a complex number.

complex 1 2 == 1 + 2 i

i : Complex

The number i

i == complex 0 1

one : Complex

The number 1.

complex 1 0 == one

zero : Complex

The number 0.

complex 0 0 == zero

fromReal : Basics.Float -> Complex

Creates a complex number from one real numer.

fromReal 5 == 5 + 0 i

Basic Unary Operations

real : Complex -> Basics.Float

Provides the real part of a complex number.

real 2 + 3 i == 2

imaginary : Complex -> Basics.Float

Provides the imaginary part of a complex number.

imaginary 2 + 3 i == 3

abs : Complex -> Basics.Float

Takes the absolute value of a complex number.

abs 2 + 2 i == sqrt 8

abs -2 - 2 i == sqrt 8

abs 0 + 0 i == 0

conjugate : Complex -> Complex

Returns the conjugate of a complex number

conjugate 2 + 3 i == 2 - 3 i

conjugate 2 - 3 i == 2 + 3 i

negation : Complex -> Complex

Negates a complex number.

negation 1 + 2 i == -1 - 2 i

negation -1 - 2 i == 1 + 2 i

negation -1 + 2 i == 1 - 2 i

sgn : Complex -> Basics.Float

Returns the sign of a complex number.

sgn 0 + 0 i == 0

sgn 0 + 2 i == 0

sgn 1 + -10 i == 1

sgn -1 + 10 i == -1

sgn -1 + -10 i == -1

arg : Complex -> Basics.Float

The argument of a complex number. It is in radians. This is also known as the phase or angle.

arg 0 + 0 i == 0

arg 0 + i == pi / 2

sqrt : Complex -> Complex

Square root of a complex number. Returns only one of two possibilites.

sqrt (2+2i) == (1.55...) + i0.6435..

Basic Binary Operations

add : Complex -> Complex -> Complex

Adds two complex numbers by adding the real and imaginary parts.

sub : Complex -> Complex -> Complex

Subtacts two complex numbers by negating and adding.

mult : Complex -> Complex -> Complex

Multiplies two complex numbers so that

mult (a + bi) (c + di) == (ac - bd) + (ad + bc)

div : Complex -> Complex -> Complex

Divides two complex numbers.

div 2 + 2 i 1 + 1 i == 2 + 0

div 2 + 2 i 0 + 0 i == NaN + NaNi

Trig

sin : Complex -> Complex

Complex sine.

cos : Complex -> Complex

Complex cosine.

tan : Complex -> Complex

Complex tangent.

asin : Complex -> Complex

Complex inverse sine.

acos : Complex -> Complex

Complex inverse cosine.

atan : Complex -> Complex

Complex inverse tan.

euler : Basics.Float -> Complex

Euler's formula.

       euler 2 == e^{i*2} == cos 2 + i*sin 2

Exponents and Logarithms

ln : Complex -> Complex

The natrual log of a complex number.

exp : Complex -> Complex

The exponent of a complex number.

pow : Complex -> Complex -> Complex

Take a complex number to a complex power.

pow 1+0i 2+2i == (1)^{2+2i} == 1