Theoretica
Scientific Computing
Loading...
Searching...
No Matches
complex_analysis.h
Go to the documentation of this file.
1
5
6#ifndef THEORETICA_COMPLEX_FUNCTIONS
7#define THEORETICA_COMPLEX_FUNCTIONS
8
9#include "./complex.h"
10#include "../core/real_analysis.h"
11
12
13namespace theoretica {
14
15
18 template<typename T>
20 return z;
21 }
22
23
26 template<typename T>
28 return complex<T>(z.a, -z.b);
29 }
30
31
34 template<typename T>
36 return conjugate(z) / z.sqr_norm();
37 }
38
39
42 template<typename T>
44 return complex<T>(
45 z.Re() * z.Re() - z.Im() * z.Im(),
46 2 * z.Re() * z.Im()
47 );
48 }
49
50
53 template<typename T>
55 return z * z * z;
56 }
57
58
64 template<typename T>
66 return exp(p * ln(z));
67 }
68
69
72 template<typename T>
74 return complex<T>(cos(z.Im()), sin(z.Im())) * exp(z.Re());
75 }
76
77
80 template<typename T>
81 inline real abs(complex<T> z) {
82 return z.norm();
83 }
84
85
88 template<typename T>
90
91 const complex<T> t = z * complex<>::i();
92 return (exp(t) - exp(-t)) * complex<T>(0, -0.5);
93 }
94
95
98 template<typename T>
100
101 const complex<T> t = z * complex<>::i();
102 return (exp(t) + exp(-t)) / 2.0;
103 }
104
105
108 template<typename T>
110
111 const complex<T> t = exp(z * complex<T>(0, 2));
112 return (t - complex<T>(1, 0)) / (t + complex<T>(1, 0)) * complex<T>(0, -1);
113 }
114
115
118 template<typename T>
120
121 if(abs(z.a) < MACH_EPSILON && abs(z.b) < MACH_EPSILON)
122 return complex<T>(0);
123
124
125 // Left-sided sign function for continuity along the negative real axis
126 const T imag_sign = (z.Im() < 0) ? T(-1.0) : T(1.0);
127
128 return complex<T>(
129 INVSQR2 * sqrt((z.norm() + z.Re())),
130 INVSQR2 * sqrt((z.norm() - z.Re())) * imag_sign);
131 }
132
133
136 template<typename T>
138 return complex<T>(ln(z.norm()), z.arg());
139 }
140
141
144 template<typename T>
146
147 // For real z in [-1, 1], use real asin
148 if(abs(z.Im()) < MACH_EPSILON && abs(z.Re()) <= 1.0 + MACH_EPSILON) {
149 T real_part = (z.Re() > 1.0) ? 1.0 : ((z.Re() < -1.0) ? -1.0 : z.Re());
150 return complex<T>(asin(real_part), 0);
151 }
152
153 // General formula with better stability
154 return ln(complex<>::i() * z + sqrt(complex<T>(1, 0) - square(z))) * complex<T>(0, -1);
155 }
156
157
160 template<typename T>
162
163 // For real z in [-1, 1], use real acos
164 if(abs(z.Im()) < MACH_EPSILON && abs(z.Re()) <= 1.0 + MACH_EPSILON) {
165 const T real_part = (z.Re() > 1.0) ? 1.0 : ((z. Re() < -1.0) ? -1.0 : z.Re());
166 return complex<T>(acos(real_part), 0);
167 }
168
169 // General formula
170 return ln(z + sqrt(square(z) - complex<T>(1, 0))) * complex<T>(0, -1);
171 }
172
173
176 template<typename T>
178
179 return ln((complex<>::i() - z) / (complex<>::i() + z)) * complex<T>(0, -0.5);
180 }
181
182}
183
184#endif
Complex number in algebraic form .
Definition complex.h:26
static constexpr complex i()
Imaginary unit.
Definition complex.h:336
Complex number class.
Main namespace of the library which contains all functions and objects.
Definition algebra.h:27
double real
A real number, defined as a floating point type.
Definition constants.h:207
dual2 sqrt(dual2 x)
Compute the square root of a second order dual number.
Definition dual2_functions.h:54
dual2 ln(dual2 x)
Compute the natural logarithm of a second order dual number.
Definition dual2_functions.h:195
dual2 abs(dual2 x)
Compute the absolute value of a second order dual number.
Definition dual2_functions.h:242
dual2 asin(dual2 x)
Compute the arcsine of a second order dual number.
Definition dual2_functions.h:248
complex< T > identity(complex< T > z)
Complex identity.
Definition complex_analysis.h:19
dual2 exp(dual2 x)
Compute the exponential of a second order dual number.
Definition dual2_functions.h:138
complex< T > inverse(complex< T > z)
Compute the conjugate of a complex number.
Definition complex_analysis.h:35
constexpr real INVSQR2
The inverse of the square root of 2.
Definition constants.h:273
Vector make_error()
Create a vector representing an error state, with all NaN values.
Definition algebra.h:103
dual2 conjugate(dual2 x)
Return the conjugate of a second order dual number.
Definition dual2_functions.h:35
dual2 cos(dual2 x)
Compute the cosine of a second order dual number.
Definition dual2_functions.h:86
constexpr real MACH_EPSILON
Machine epsilon for the real type.
Definition constants.h:216
dual2 tan(dual2 x)
Compute the tangent of a second order dual number.
Definition dual2_functions.h:100
dual2 acos(dual2 x)
Compute the arcosine of a second order dual number.
Definition dual2_functions.h:267
complex< T > powf(complex< T > z, real p)
Compute a complex number raised to a real power.
Definition complex_analysis.h:65
dual2 sin(dual2 x)
Compute the sine of a second order dual number.
Definition dual2_functions.h:72
dual2 square(dual2 x)
Return the square of a second order dual number.
Definition dual2_functions.h:23
dual2 atan(dual2 x)
Compute the arctangent of a second order dual number.
Definition dual2_functions.h:286
dual2 cube(dual2 x)
Return the cube of a second order dual number.
Definition dual2_functions.h:29