1 @cindex complex numbers
3 The functions described in this chapter provide support for complex
4 numbers. The algorithms take care to avoid unnecessary intermediate
5 underflows and overflows, allowing the functions to be evaluated over
6 as much of the complex plane as possible.
8 @comment FIXME: this still needs to be
9 @comment done for the csc,sec,cot,csch,sech,coth functions
11 For multiple-valued functions the branch cuts have been chosen to follow
12 the conventions of Abramowitz and Stegun in the @cite{Handbook of
13 Mathematical Functions}. The functions return principal values which are
14 the same as those in GNU Calc, which in turn are the same as those in
15 @cite{Common Lisp, The Language (Second Edition)}@footnote{Note that the
16 first edition uses different definitions.} and the HP-28/48 series of
19 The complex types are defined in the header file @file{gsl_complex.h},
20 while the corresponding complex functions and arithmetic operations are
21 defined in @file{gsl_complex_math.h}.
25 * Properties of complex numbers::
26 * Complex arithmetic operators::
27 * Elementary Complex Functions::
28 * Complex Trigonometric Functions::
29 * Inverse Complex Trigonometric Functions::
30 * Complex Hyperbolic Functions::
31 * Inverse Complex Hyperbolic Functions::
32 * Complex Number References and Further Reading::
36 @section Complex numbers
37 @cindex representations of complex numbers
38 @cindex polar form of complex numbers
41 Complex numbers are represented using the type @code{gsl_complex}. The
42 internal representation of this type may vary across platforms and
43 should not be accessed directly. The functions and macros described
44 below allow complex numbers to be manipulated in a portable way.
46 For reference, the default form of the @code{gsl_complex} type is
47 given by the following struct,
57 The real and imaginary part are stored in contiguous elements of a two
58 element array. This eliminates any padding between the real and
59 imaginary parts, @code{dat[0]} and @code{dat[1]}, allowing the struct to
60 be mapped correctly onto packed complex arrays.
62 @deftypefun gsl_complex gsl_complex_rect (double @var{x}, double @var{y})
63 This function uses the rectangular cartesian components
64 (@var{x},@var{y}) to return the complex number @math{z = x + i y}. @inlinefn{}
67 @deftypefun gsl_complex gsl_complex_polar (double @var{r}, double @var{theta})
68 This function returns the complex number @math{z = r \exp(i \theta) = r
69 (\cos(\theta) + i \sin(\theta))} from the polar representation
70 (@var{r},@var{theta}).
73 @defmac GSL_REAL (@var{z})
74 @defmacx GSL_IMAG (@var{z})
75 These macros return the real and imaginary parts of the complex number
79 @defmac GSL_SET_COMPLEX (@var{zp}, @var{x}, @var{y})
80 This macro uses the cartesian components (@var{x},@var{y}) to set the
81 real and imaginary parts of the complex number pointed to by @var{zp}.
85 GSL_SET_COMPLEX(&z, 3, 4)
89 sets @var{z} to be @math{3 + 4i}.
92 @defmac GSL_SET_REAL (@var{zp},@var{x})
93 @defmacx GSL_SET_IMAG (@var{zp},@var{y})
94 These macros allow the real and imaginary parts of the complex number
95 pointed to by @var{zp} to be set independently.
98 @node Properties of complex numbers
99 @section Properties of complex numbers
101 @deftypefun double gsl_complex_arg (gsl_complex @var{z})
102 @cindex argument of complex number
103 This function returns the argument of the complex number @var{z},
104 @math{\arg(z)}, where @c{$-\pi < \arg(z) \leq \pi$}
105 @math{-\pi < \arg(z) <= \pi}.
108 @deftypefun double gsl_complex_abs (gsl_complex @var{z})
109 @cindex magnitude of complex number
110 This function returns the magnitude of the complex number @var{z}, @math{|z|}.
113 @deftypefun double gsl_complex_abs2 (gsl_complex @var{z})
114 This function returns the squared magnitude of the complex number
115 @var{z}, @math{|z|^2}.
118 @deftypefun double gsl_complex_logabs (gsl_complex @var{z})
119 This function returns the natural logarithm of the magnitude of the
120 complex number @var{z}, @math{\log|z|}. It allows an accurate
121 evaluation of @math{\log|z|} when @math{|z|} is close to one. The direct
122 evaluation of @code{log(gsl_complex_abs(z))} would lead to a loss of
123 precision in this case.
127 @node Complex arithmetic operators
128 @section Complex arithmetic operators
129 @cindex complex arithmetic
131 @deftypefun gsl_complex gsl_complex_add (gsl_complex @var{a}, gsl_complex @var{b})
132 This function returns the sum of the complex numbers @var{a} and
133 @var{b}, @math{z=a+b}.
136 @deftypefun gsl_complex gsl_complex_sub (gsl_complex @var{a}, gsl_complex @var{b})
137 This function returns the difference of the complex numbers @var{a} and
138 @var{b}, @math{z=a-b}.
141 @deftypefun gsl_complex gsl_complex_mul (gsl_complex @var{a}, gsl_complex @var{b})
142 This function returns the product of the complex numbers @var{a} and
143 @var{b}, @math{z=ab}.
146 @deftypefun gsl_complex gsl_complex_div (gsl_complex @var{a}, gsl_complex @var{b})
147 This function returns the quotient of the complex numbers @var{a} and
148 @var{b}, @math{z=a/b}.
152 @deftypefun gsl_complex gsl_complex_add_real (gsl_complex @var{a}, double @var{x})
153 This function returns the sum of the complex number @var{a} and the
154 real number @var{x}, @math{z=a+x}.
157 @deftypefun gsl_complex gsl_complex_sub_real (gsl_complex @var{a}, double @var{x})
158 This function returns the difference of the complex number @var{a} and the
159 real number @var{x}, @math{z=a-x}.
162 @deftypefun gsl_complex gsl_complex_mul_real (gsl_complex @var{a}, double @var{x})
163 This function returns the product of the complex number @var{a} and the
164 real number @var{x}, @math{z=ax}.
167 @deftypefun gsl_complex gsl_complex_div_real (gsl_complex @var{a}, double @var{x})
168 This function returns the quotient of the complex number @var{a} and the
169 real number @var{x}, @math{z=a/x}.
172 @deftypefun gsl_complex gsl_complex_add_imag (gsl_complex @var{a}, double @var{y})
173 This function returns the sum of the complex number @var{a} and the
174 imaginary number @math{i}@var{y}, @math{z=a+iy}.
177 @deftypefun gsl_complex gsl_complex_sub_imag (gsl_complex @var{a}, double @var{y})
178 This function returns the difference of the complex number @var{a} and the
179 imaginary number @math{i}@var{y}, @math{z=a-iy}.
182 @deftypefun gsl_complex gsl_complex_mul_imag (gsl_complex @var{a}, double @var{y})
183 This function returns the product of the complex number @var{a} and the
184 imaginary number @math{i}@var{y}, @math{z=a*(iy)}.
187 @deftypefun gsl_complex gsl_complex_div_imag (gsl_complex @var{a}, double @var{y})
188 This function returns the quotient of the complex number @var{a} and the
189 imaginary number @math{i}@var{y}, @math{z=a/(iy)}.
192 @deftypefun gsl_complex gsl_complex_conjugate (gsl_complex @var{z})
193 @cindex conjugate of complex number
194 This function returns the complex conjugate of the complex number
195 @var{z}, @math{z^* = x - i y}.
198 @deftypefun gsl_complex gsl_complex_inverse (gsl_complex @var{z})
199 This function returns the inverse, or reciprocal, of the complex number
200 @var{z}, @math{1/z = (x - i y)/(x^2 + y^2)}.
203 @deftypefun gsl_complex gsl_complex_negative (gsl_complex @var{z})
204 This function returns the negative of the complex number
205 @var{z}, @math{-z = (-x) + i(-y)}.
209 @node Elementary Complex Functions
210 @section Elementary Complex Functions
212 @deftypefun gsl_complex gsl_complex_sqrt (gsl_complex @var{z})
213 @cindex square root of complex number
214 This function returns the square root of the complex number @var{z},
215 @math{\sqrt z}. The branch cut is the negative real axis. The result
216 always lies in the right half of the complex plane.
219 @deftypefun gsl_complex gsl_complex_sqrt_real (double @var{x})
220 This function returns the complex square root of the real number
221 @var{x}, where @var{x} may be negative.
225 @deftypefun gsl_complex gsl_complex_pow (gsl_complex @var{z}, gsl_complex @var{a})
226 @cindex power of complex number
227 @cindex exponentiation of complex number
228 The function returns the complex number @var{z} raised to the complex
229 power @var{a}, @math{z^a}. This is computed as @math{\exp(\log(z)*a)}
230 using complex logarithms and complex exponentials.
233 @deftypefun gsl_complex gsl_complex_pow_real (gsl_complex @var{z}, double @var{x})
234 This function returns the complex number @var{z} raised to the real
235 power @var{x}, @math{z^x}.
239 @deftypefun gsl_complex gsl_complex_exp (gsl_complex @var{z})
240 This function returns the complex exponential of the complex number
241 @var{z}, @math{\exp(z)}.
244 @deftypefun gsl_complex gsl_complex_log (gsl_complex @var{z})
245 @cindex logarithm of complex number
246 This function returns the complex natural logarithm (base @math{e}) of
247 the complex number @var{z}, @math{\log(z)}. The branch cut is the
251 @deftypefun gsl_complex gsl_complex_log10 (gsl_complex @var{z})
252 This function returns the complex base-10 logarithm of
253 the complex number @var{z}, @c{$\log_{10}(z)$}
257 @deftypefun gsl_complex gsl_complex_log_b (gsl_complex @var{z}, gsl_complex @var{b})
258 This function returns the complex base-@var{b} logarithm of the complex
259 number @var{z}, @math{\log_b(z)}. This quantity is computed as the ratio
260 @math{\log(z)/\log(b)}.
264 @node Complex Trigonometric Functions
265 @section Complex Trigonometric Functions
266 @cindex trigonometric functions of complex numbers
268 @deftypefun gsl_complex gsl_complex_sin (gsl_complex @var{z})
269 @cindex sin, of complex number
270 This function returns the complex sine of the complex number @var{z},
271 @math{\sin(z) = (\exp(iz) - \exp(-iz))/(2i)}.
274 @deftypefun gsl_complex gsl_complex_cos (gsl_complex @var{z})
275 @cindex cosine of complex number
276 This function returns the complex cosine of the complex number @var{z},
277 @math{\cos(z) = (\exp(iz) + \exp(-iz))/2}.
280 @deftypefun gsl_complex gsl_complex_tan (gsl_complex @var{z})
281 @cindex tangent of complex number
282 This function returns the complex tangent of the complex number @var{z},
283 @math{\tan(z) = \sin(z)/\cos(z)}.
286 @deftypefun gsl_complex gsl_complex_sec (gsl_complex @var{z})
287 This function returns the complex secant of the complex number @var{z},
288 @math{\sec(z) = 1/\cos(z)}.
291 @deftypefun gsl_complex gsl_complex_csc (gsl_complex @var{z})
292 This function returns the complex cosecant of the complex number @var{z},
293 @math{\csc(z) = 1/\sin(z)}.
296 @deftypefun gsl_complex gsl_complex_cot (gsl_complex @var{z})
297 This function returns the complex cotangent of the complex number @var{z},
298 @math{\cot(z) = 1/\tan(z)}.
302 @node Inverse Complex Trigonometric Functions
303 @section Inverse Complex Trigonometric Functions
304 @cindex inverse complex trigonometric functions
306 @deftypefun gsl_complex gsl_complex_arcsin (gsl_complex @var{z})
307 This function returns the complex arcsine of the complex number @var{z},
308 @math{\arcsin(z)}. The branch cuts are on the real axis, less than @math{-1}
309 and greater than @math{1}.
312 @deftypefun gsl_complex gsl_complex_arcsin_real (double @var{z})
313 This function returns the complex arcsine of the real number @var{z},
314 @math{\arcsin(z)}. For @math{z} between @math{-1} and @math{1}, the
315 function returns a real value in the range @math{[-\pi/2,\pi/2]}. For
316 @math{z} less than @math{-1} the result has a real part of @math{-\pi/2}
317 and a positive imaginary part. For @math{z} greater than @math{1} the
318 result has a real part of @math{\pi/2} and a negative imaginary part.
321 @deftypefun gsl_complex gsl_complex_arccos (gsl_complex @var{z})
322 This function returns the complex arccosine of the complex number @var{z},
323 @math{\arccos(z)}. The branch cuts are on the real axis, less than @math{-1}
324 and greater than @math{1}.
327 @deftypefun gsl_complex gsl_complex_arccos_real (double @var{z})
328 This function returns the complex arccosine of the real number @var{z},
329 @math{\arccos(z)}. For @math{z} between @math{-1} and @math{1}, the
330 function returns a real value in the range @math{[0,\pi]}. For @math{z}
331 less than @math{-1} the result has a real part of @math{\pi} and a
332 negative imaginary part. For @math{z} greater than @math{1} the result
333 is purely imaginary and positive.
336 @deftypefun gsl_complex gsl_complex_arctan (gsl_complex @var{z})
337 This function returns the complex arctangent of the complex number
338 @var{z}, @math{\arctan(z)}. The branch cuts are on the imaginary axis,
339 below @math{-i} and above @math{i}.
342 @deftypefun gsl_complex gsl_complex_arcsec (gsl_complex @var{z})
343 This function returns the complex arcsecant of the complex number @var{z},
344 @math{\arcsec(z) = \arccos(1/z)}.
347 @deftypefun gsl_complex gsl_complex_arcsec_real (double @var{z})
348 This function returns the complex arcsecant of the real number @var{z},
349 @math{\arcsec(z) = \arccos(1/z)}.
352 @deftypefun gsl_complex gsl_complex_arccsc (gsl_complex @var{z})
353 This function returns the complex arccosecant of the complex number @var{z},
354 @math{\arccsc(z) = \arcsin(1/z)}.
357 @deftypefun gsl_complex gsl_complex_arccsc_real (double @var{z})
358 This function returns the complex arccosecant of the real number @var{z},
359 @math{\arccsc(z) = \arcsin(1/z)}.
362 @deftypefun gsl_complex gsl_complex_arccot (gsl_complex @var{z})
363 This function returns the complex arccotangent of the complex number @var{z},
364 @math{\arccot(z) = \arctan(1/z)}.
368 @node Complex Hyperbolic Functions
369 @section Complex Hyperbolic Functions
370 @cindex hyperbolic functions, complex numbers
372 @deftypefun gsl_complex gsl_complex_sinh (gsl_complex @var{z})
373 This function returns the complex hyperbolic sine of the complex number
374 @var{z}, @math{\sinh(z) = (\exp(z) - \exp(-z))/2}.
377 @deftypefun gsl_complex gsl_complex_cosh (gsl_complex @var{z})
378 This function returns the complex hyperbolic cosine of the complex number
379 @var{z}, @math{\cosh(z) = (\exp(z) + \exp(-z))/2}.
382 @deftypefun gsl_complex gsl_complex_tanh (gsl_complex @var{z})
383 This function returns the complex hyperbolic tangent of the complex number
384 @var{z}, @math{\tanh(z) = \sinh(z)/\cosh(z)}.
388 @deftypefun gsl_complex gsl_complex_sech (gsl_complex @var{z})
389 This function returns the complex hyperbolic secant of the complex
390 number @var{z}, @math{\sech(z) = 1/\cosh(z)}.
393 @deftypefun gsl_complex gsl_complex_csch (gsl_complex @var{z})
394 This function returns the complex hyperbolic cosecant of the complex
395 number @var{z}, @math{\csch(z) = 1/\sinh(z)}.
398 @deftypefun gsl_complex gsl_complex_coth (gsl_complex @var{z})
399 This function returns the complex hyperbolic cotangent of the complex
400 number @var{z}, @math{\coth(z) = 1/\tanh(z)}.
404 @node Inverse Complex Hyperbolic Functions
405 @section Inverse Complex Hyperbolic Functions
406 @cindex inverse hyperbolic functions, complex numbers
408 @deftypefun gsl_complex gsl_complex_arcsinh (gsl_complex @var{z})
409 This function returns the complex hyperbolic arcsine of the
410 complex number @var{z}, @math{\arcsinh(z)}. The branch cuts are on the
411 imaginary axis, below @math{-i} and above @math{i}.
414 @deftypefun gsl_complex gsl_complex_arccosh (gsl_complex @var{z})
415 This function returns the complex hyperbolic arccosine of the complex
416 number @var{z}, @math{\arccosh(z)}. The branch cut is on the real
417 axis, less than @math{1}. Note that in this case we use the negative
418 square root in formula 4.6.21 of Abramowitz & Stegun giving
419 @c{$\arccosh(z)=\log(z-\sqrt{z^2-1})$}
420 @math{\arccosh(z)=\log(z-\sqrt@{z^2-1@})}.
423 @deftypefun gsl_complex gsl_complex_arccosh_real (double @var{z})
424 This function returns the complex hyperbolic arccosine of
425 the real number @var{z}, @math{\arccosh(z)}.
428 @deftypefun gsl_complex gsl_complex_arctanh (gsl_complex @var{z})
429 This function returns the complex hyperbolic arctangent of the complex
430 number @var{z}, @math{\arctanh(z)}. The branch cuts are on the real
431 axis, less than @math{-1} and greater than @math{1}.
434 @deftypefun gsl_complex gsl_complex_arctanh_real (double @var{z})
435 This function returns the complex hyperbolic arctangent of the real
436 number @var{z}, @math{\arctanh(z)}.
439 @deftypefun gsl_complex gsl_complex_arcsech (gsl_complex @var{z})
440 This function returns the complex hyperbolic arcsecant of the complex
441 number @var{z}, @math{\arcsech(z) = \arccosh(1/z)}.
444 @deftypefun gsl_complex gsl_complex_arccsch (gsl_complex @var{z})
445 This function returns the complex hyperbolic arccosecant of the complex
446 number @var{z}, @math{\arccsch(z) = \arcsin(1/z)}.
449 @deftypefun gsl_complex gsl_complex_arccoth (gsl_complex @var{z})
450 This function returns the complex hyperbolic arccotangent of the complex
451 number @var{z}, @math{\arccoth(z) = \arctanh(1/z)}.
454 @node Complex Number References and Further Reading
455 @section References and Further Reading
457 The implementations of the elementary and trigonometric functions are
458 based on the following papers,
462 T. E. Hull, Thomas F. Fairgrieve, Ping Tak Peter Tang,
463 ``Implementing Complex Elementary Functions Using Exception
464 Handling'', @cite{ACM Transactions on Mathematical Software}, Volume 20
465 (1994), pp 215--244, Corrigenda, p553
468 T. E. Hull, Thomas F. Fairgrieve, Ping Tak Peter Tang,
469 ``Implementing the complex arcsin and arccosine functions using exception
470 handling'', @cite{ACM Transactions on Mathematical Software}, Volume 23
475 The general formulas and details of branch cuts can be found in the
480 Abramowitz and Stegun, @cite{Handbook of Mathematical Functions},
481 ``Circular Functions in Terms of Real and Imaginary Parts'', Formulas
483 ``Inverse Circular Functions in Terms of Real and Imaginary Parts'',
485 ``Hyperbolic Functions in Terms of Real and Imaginary Parts'',
487 ``Inverse Hyperbolic Functions---relation to Inverse Circular Functions'',
491 Dave Gillespie, @cite{Calc Manual}, Free Software Foundation, ISBN