Complex Numbers | Extreme Optimization Numerical Libraries for .NET Professional |

Complex numbers arise in algebra in the solution of quadratic equations.
The equation
x^{2} = -1
does not have
any real solutions. However, if we define a new number, i
as the square root of -1, then we have two solutions: i
and -i. This, in turn, gives rise to an entirely new class
of numbers of the form a + ib with a and
b real, and i defined as above.
These are the complex numbers.

The **Extreme Optimization Mathematics Library for .NET**
provides one generic type for complex numbers of any type:
The Complex

The Complex

The first constructor takes two arguments: the real and imaginary parts of the complex number.

The second constructor takes one real argument. It constructs a complex number whose imaginary part is zero.

Complex numbers can also be created from the polar form:
the static FromPolar

Finally, the static
RootOfUnity
method constructs a complex number that is one of the solutions
to the equation
x^{n} = 1
.
The solutions to this equation are n complex numbers
spaced equally on the unit circle. The first parameter of the method
is the degree, n, of the root. The second parameter
is the index of the root in the series, counting counter-clockwise
on the unit circle. An index of 0 corresponds to the root
x = 1.

The complex structure provides several read-only fields for commonly used and special complex numbers. These are listed in the following table:

Field | Description |
---|---|

The number i, the square root of 1. | |

Complex`1 zero: 0 + 0i. | |

Complex`1 one: 1 + 0i. | |

Infinity | Complex`1 infinity. |

NaN | Complex`1 Not-a-Number. |

Two values in the above list deserve special attention. The Infinity field represents complex infinity. It is the result of dividing any non-zero complex number by zero. Complex infinity does not have a sign. Because the complex numbers do not have a natural ordering, is does not make sense to speak of positive or negative numbers. Directed infinities, where the magnitude of the complex number is infinite, but its argument is not, are not supported. The static [M:Extreme.Mathematics.Complex`1.IsInfinity(Extreme.Mathematics.Complex`1)] method verifies whether a complex number equals Complex`1.Infinity.

The NaN field represents complex Not-a-Number. It is a special value that is the result of dividing zero by zero. The static [M:Extreme.Mathematics.Complex`1.IsNaN(Extreme.Mathematics.Complex`1)] method verifies whether a complex number equals Complex`1.NaN. You can not use the equality operator for this purpose, as it always returns false.

Working with complex numbers is easy. The Re property gets the real part of the complex number, while Im gets the imaginary part. The Magnitude property returns the square root of the magnitude (absolute value, modulus). The Phase property returns the phase (argument of the complex number: the angle between the positive real axis and a line from the origin to the complex number, measured counter-clockwise.

The magnitude is computed every time the magnitude property is called. The same is true for the Argument property. If you use these values multiple times, you should consider caching them in a variable.

When performing binary operations,
if one of the operands is a complex number,
then the other operand is required to be either a complex number
of the same type, or a real number that can be converted to
or a floating-point type (Double or
Single) or a complex type (Complex

The **Extreme Optimization Mathematics Library for .NET** extends the IEEE-754 standard definition of NaN's
for real numbers to complex numbers as follows.

The floating-point operators, including the assignment operators, do not throw exceptions. Instead, in exceptional situations, the result of a floating-point operation is zero, Infinity, or NaN, as described below:

- If the result of a complex floating-point operation is too small for the destination format, the result of the operation is zero.
- If the magnitude of the complex result of a floating-point operation is too large for the destination format, the result of the operation is Complex`1.Infinity.
- If a complex floating-point operation on complex numbers is invalid, the result of the operation is Complex`1.NaN.
- If one or both operands of a complex floating-point operation are NaN (real or complex), the result of the operation is Complex`1.NaN.

Overloaded operators for all basic arithmetic operators on complex numbers are available. Most contain overloads for cases where one of the operands is real. Corresponding static methods are provided for languages that don't support operator overloading.

For example, here is some C# code:

[C#] var a = Complex<double>(1, 2); var b = Complex<double>(-3, 4); var c = 2 - 1 / (a + b);and here is the equivalent Visual Basic.NET code:

[Visual Basic] a Complex( Double)(1, 2) b Complex( Double)(-3, 4) c ComplexSpecific to complex numbers is the static Conjugate method. This method returns the conjugate of a complex number, leaving the original unchanged.

Operator | Static method equivalent | Description |
---|---|---|

+z | (no equivalent) | Returns the complex number z. |

-z | [M:Extreme.Mathematics.Complex`1.Negate(Extreme.Mathematics.Complex`1)] | Returns the negation of the complex number z. |

z1 + z2 | Complex`1.Add(z1, z2) | Adds the complex numbers z1 and z2. |

z + a | Complex`1.Add(z, a) | Adds the complex number z and the real number a. |

a + z | Complex`1.Add(a, z) | Adds the real number a to the complex number z. |

z++ | (no equivalent) | Increments the complex number z by one. |

z1 - z2 | Complex`1.Subtract(z1, z2) | Subtracts the complex numbers z1 and z2. |

z - a | Complex`1.Subtract(z, a) | Subtracts the real number a from the complex number z. |

a - z | Complex`1.Subtract(a, z) | Subtracts the complex number z from the real number a. |

z-- | (no equivalent) | Decrements the complex number z by one. |

z1 * z2 | Complex`1.Multiply(z1, z2) | Multiplies the complex numbers z1 and z2. |

z * a | Complex`1.Multiply(z, a) | Multiplies the complex number z and the real number a. |

a * z | Complex`1.Multiply(a, z) | Multiplies the real number a and the complex number z. |

z1 / z2 | Complex`1.Divide(z1, z2) | Divides the complex number z1 by z2. |

z / a | Complex`1.Divide(z, a) | Divides the complex number z by the real number a. |

a / z | Complex`1.Divide(a, z) | Divides the real number a by the complex number z. |

~z | Returns the complex conjugate of the complex number z. |

There is one other static method that does not have
an operator equivalent. The
ConjugateMultiply

Because the complex numbers don't have a natural ordering, only equality and inequality operators are available. No other comparison operators are available.

TheComplex

Some functions of real numbers have a limited domain
when the result is restricted to be real, but are defined for
all real numbers if the result can be complex. Examples of this are
the inverse sine and cosine, which are real only for arguments
between -1 and +1. The
Complex

These functions are often discontinuous along the part of the real axis where they are complex-valued. Which of the two limit values is chosen is arbitrary. However, the most consistent choice is the one that preserves any symmetry or anti-symmetry about the origin. For example, the function Arcsin(x) satisfies Arcsin(-x) = -Arcsin(x) when x is within the interval [-1, 1]. The Arcsin method with real argument also satisfies this identity.

Most elementary functions have been extended to cover the entire complex plane. Once again, many of them are multi-valued, and a suitable choice has to be made regarding which of the two possible limit values is returned. The choice is made easier by the fact that the discontinuities lie along the real or imaginary axis. This makes it possible to distinguish between the 'limit from above' and the 'limit from below' by using the value of negative zero for the limit from below. The situation is somewhat simplified by the fact that any analytic function satisfies the identity f(conj(z) = conj(f(z)).

The tables below summarize these methods, and their meaning. Special functions with complex argument may be available from the Special class.

Method | Description |
---|---|

[M:Extreme.Mathematics.Complex`1.Exp(Extreme.Mathematics.Complex`1)] | The number E raised to the complex power z. |

ExpI(Double) | |

[M:Extreme.Mathematics.Complex`1.Sqrt(Extreme.Mathematics.Complex`1)] | The first square root of the complex number number z. |

Sqrt(Double) | The first square root of the real number number a, which may be negative. |

[M:Extreme.Mathematics.Complex`1.Pow(Extreme.Mathematics.Complex`1,Extreme.Mathematics.Complex`1)] | The complex number z1 raised to the complex power z2. |

[M:Extreme.Mathematics.Complex`1.Pow(Extreme.Mathematics.Complex`1,System.Double)] | The complex number z raised to the real power a. |

[M:Extreme.Mathematics.Complex`1.Pow(Extreme.Mathematics.Complex`1,System.Int32)] | The complex number z raised to the integer power n. |

[M:Extreme.Mathematics.Complex`1.Log(Extreme.Mathematics.Complex`1)] | Natural logarithm of the complex number z. |

[M:Extreme.Mathematics.Complex`1.Log(Extreme.Mathematics.Complex`1,Extreme.Mathematics.Complex`1)] | Base z1 logarithm of the complex number z2. |

[M:Extreme.Mathematics.Complex`1.Log10(Extreme.Mathematics.Complex`1)] | Base 10 (common) logarithm of the complex number z. |

Method | Description |
---|---|

[M:Extreme.Mathematics.Complex`1.Sin(Extreme.Mathematics.Complex`1)] | Sine of the complex number z. |

[M:Extreme.Mathematics.Complex`1.Cos(Extreme.Mathematics.Complex`1)] | Cosine of the complex number z. |

[M:Extreme.Mathematics.Complex`1.Tan(Extreme.Mathematics.Complex`1)] | Tangent of the complex number z. |

[M:Extreme.Mathematics.Complex`1.Asin(Extreme.Mathematics.Complex`1)] | Inverse sine of the complex number z. |

Asin(Double) | Inverse sine of the real number a. |

[M:Extreme.Mathematics.Complex`1.Acos(Extreme.Mathematics.Complex`1)] | Inverse cosine of the complex number z. |

Acos(Double) | Inverse cosine of the real number a. |

[M:Extreme.Mathematics.Complex`1.Atan(Extreme.Mathematics.Complex`1)] | Inverse tangent of the complex number z. |

Method | Description |
---|---|

[M:Extreme.Mathematics.Complex`1.Sinh(Extreme.Mathematics.Complex`1)] | Hyperbolic sine of the complex number z. |

[M:Extreme.Mathematics.Complex`1.Cosh(Extreme.Mathematics.Complex`1)] | Hyperbolic cosine of the complex number z. |

[M:Extreme.Mathematics.Complex`1.Tanh(Extreme.Mathematics.Complex`1)] | Hyperbolic tangent of the complex number z. |

[M:Extreme.Mathematics.Complex`1.Asinh(Extreme.Mathematics.Complex`1)] | Inverse hyperbolic sine of the complex number z. |

[M:Extreme.Mathematics.Complex`1.Acosh(Extreme.Mathematics.Complex`1)] | Inverse hyperbolic cosine of the complex number z. |

[M:Extreme.Mathematics.Complex`1.Atanh(Extreme.Mathematics.Complex`1)] | Inverse hyperbolic tangent of the complex number z. |

Copyright Â© 2004-2015,
Extreme Optimization. All rights reserved.

*Extreme Optimization,* *Complexity made simple*, *M#*, and *M
Sharp* are trademarks of ExoAnalytics Inc.

*Microsoft*, *Visual C#, Visual Basic, Visual Studio*, *Visual
Studio.NET*, and the *Optimized for Visual Studio* logo

are
registered trademarks of Microsoft Corporation.