4.6 Complex special functions
The following functions are specific to complex numbers other than absolute value, which has a specific meaning for complex numbers.
real
abs
(complex z)
Return the absolute value of z, also known as the modulus or
magnitude, which for \(z = x + yi\) is
\[
\textrm{abs}(z) = \sqrt{x^2 + y^2}.
\]
This function works elementwise over containers, returning the same shape and
kind of the input container but holding reals. For example, a
complex_vector[n]
input will return a vector[n]
output, with each element
transformed by the above equation.
Available since 2.28, vectorized in 2.30
real
arg
(complex z)
Return the phase angle (in radians) of z, which for \(z = x + yi\) is
\[
\textrm{arg}(z) = \textrm{atan2}(y, x) = \textrm{atan}(y / x).
\]
Available since 2.28
real
norm
(complex z)
Return the Euclidean norm of z, which is its absolute value squared,
and which for \(z = x + yi\) is
\[
\textrm{norm}(z) = \textrm{abs}^2(z) = x^2 + y^2.
\]
Available since 2.28
complex
conj
(complex z)
Return the complex conjugate of z, which negates the imaginary component,
so that if \(z = x + yi\),
\[
\textrm{conj}(z) = x - yi.
\]
Available since 2.28
complex
proj
(complex z)
Return the projection of z
onto the Riemann sphere, which for \(z = x + yi\) is
\[
\textrm{proj}(z)
= \begin{cases}
z & \textrm{if} \ z \ \textrm{is finite, and} \\
0 + \textrm{sign}(y)i & \textrm{otherwise,}
\end{cases}
\]
where \(\textrm{sign}(y)\) is -1 if \(y\) is negative and 1 otherwise.
Available since 2.28
complex
polar
(real r, real theta)
Return the complex number with magnitude (absolute value) r
and
phase angle theta
.
Available since 2.28