Theoretica
A C++ numerical and automatic mathematical library
constants.h
Go to the documentation of this file.
1 
7 
8 #ifndef THEORETICA_CONSTANTS_H
9 #define THEORETICA_CONSTANTS_H
10 
11 
12 #include <limits>
13 #include <cstdint>
14 
17 #ifndef THEORETICA_DISABLE_X86
18 
19 #ifndef THEORETICA_X86
20 #if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) \
21  || defined(_M_AMD64) || defined(_M_X64) || defined(i386) \
22  || defined(__i386) || defined(__i386__) || defined(_M_IX86) \
23  || defined(_X86_) || defined(_M_I86) || defined(__X86__)
24 
28 #define THEORETICA_X86
29 #endif
30 #endif
31 #endif
32 
33 
36 #ifndef THEORETICA_ALGEBRA_ELEMENT_TOL
37 #define THEORETICA_ALGEBRA_ELEMENT_TOL (10*MACH_EPSILON)
38 #endif
39 
40 
42 #ifndef THEORETICA_ALGEBRA_EIGEN_TOL
43 #define THEORETICA_ALGEBRA_EIGEN_TOL 1E-08
44 #endif
45 
46 
48 #ifndef THEORETICA_ALGEBRA_EIGEN_ITER
49 #define THEORETICA_ALGEBRA_EIGEN_ITER 100
50 #endif
51 
52 
54 #ifndef THEORETICA_CORE_TAYLOR_ORDER
55 #define THEORETICA_CORE_TAYLOR_ORDER 12
56 #endif
57 
59 #ifndef THEORETICA_CALCULUS_INTEGRAL_STEPS
60 #define THEORETICA_CALCULUS_INTEGRAL_STEPS 100
61 #endif
62 
63 // Default tolerance for integral approximation
64 #ifndef THEORETICA_CALCULUS_INTEGRAL_TOL
65 #define THEORETICA_CALCULUS_INTEGRAL_TOL 1E-08
66 #endif
67 
69 #ifndef THEORETICA_OPTIMIZATION_TOL
70 #define THEORETICA_OPTIMIZATION_TOL 1E-08
71 #endif
72 
74 #ifndef THEORETICA_OPTIMIZATION_BISECTION_ITER
75 #define THEORETICA_OPTIMIZATION_BISECTION_ITER 100
76 #endif
77 
79 #ifndef THEORETICA_OPTIMIZATION_GOLDENSECTION_ITER
80 #define THEORETICA_OPTIMIZATION_GOLDENSECTION_ITER 100
81 #endif
82 
84 #ifndef THEORETICA_OPTIMIZATION_HALLEY_ITER
85 #define THEORETICA_OPTIMIZATION_HALLEY_ITER 100
86 #endif
87 
89 #ifndef THEORETICA_OPTIMIZATION_NEWTON_ITER
90 #define THEORETICA_OPTIMIZATION_NEWTON_ITER 100
91 #endif
92 
94 #ifndef THEORETICA_OPTIMIZATION_STEFFENSEN_ITER
95 #define THEORETICA_OPTIMIZATION_STEFFENSEN_ITER 100
96 #endif
97 
99 #ifndef THEORETICA_OPTIMIZATION_CHEBYSHEV_ITER
100 #define THEORETICA_OPTIMIZATION_CHEBYSHEV_ITER 100
101 #endif
102 
104 #ifndef THEORETICA_STATISTICS_TRYANDCATCH_ITER
105 #define THEORETICA_STATISTICS_TRYANDCATCH_ITER 100
106 #endif
107 
109 #ifndef THEORETICA_CALCULUS_DERIV_STEP
110 #define THEORETICA_CALCULUS_DERIV_STEP 1E-3
111 #endif
112 
114 #ifndef THEORETICA_OPTIMIZATION_MINGRAD_GAMMA
115 #define THEORETICA_OPTIMIZATION_MINGRAD_GAMMA -0.005
116 #endif
117 
119 #ifndef THEORETICA_OPTIMIZATION_MINGRAD_TOLERANCE
120 #define THEORETICA_OPTIMIZATION_MINGRAD_TOLERANCE 1E-3
121 #endif
122 
124 #ifndef THEORETICA_OPTIMIZATION_MINGRAD_ITER
125 #define THEORETICA_OPTIMIZATION_MINGRAD_ITER 50000
126 #endif
127 
128 
129 #ifndef THEORETICA_STATISTICS_RAND_PREC
130 
132 #ifdef THEORETICA_FLOAT_PREC
133 #define THEORETICA_STATISTICS_RAND_PREC (uint64_t(1) << 23)
134 #else
135 #define THEORETICA_STATISTICS_RAND_PREC (uint64_t(1) << 31)
136 #endif
137 
138 #endif
139 
140 
142 #ifndef THEORETICA_STATISTICS_METROPOLIS_DEPTH
143 #define THEORETICA_STATISTICS_METROPOLIS_DEPTH 16
144 #endif
145 
146 
148 #if (__cplusplus >= 201402L)
149 #define TH_CONSTEXPR constexpr
150 #else
151 #define TH_CONSTEXPR
152 #endif
153 
154 
156 #if (__cplusplus >= 201703L)
157 #define TH_CONSTIF constexpr
158 #else
159 #define TH_CONSTIF
160 #endif
161 
162 
164 namespace theoretica {
165 
173 
174 #ifdef THEORETICA_LONG_DOUBLE_PREC
175 
176  using real = long double;
177 
178 #elif defined(THEORETICA_FLOAT_PREC)
179 
180  using real = float;
181 
182 #elif defined(THEORETICA_ARBITRARY_PREC)
183 
184 // TO-DO bigfloat arbitrary precision
185 
186 #else
187 
188  using real = double;
189 
190 #endif
191 
192 
193  // Mathematical constants and default algorithm parameters.
194 
195 
197  constexpr real MACH_EPSILON = std::numeric_limits<real>::epsilon();
198 
200  constexpr real PHI = 1.6180339887498948482045868;
201 
203  constexpr real INVPHI = 0.6180339887498948482045868;
204 
206  constexpr real PI = 3.141592653589793238462643;
207 
209  constexpr real PI2 = 1.57079632679489655799898;
210 
212  constexpr real PI4 = PI / 4.0;
213 
215  constexpr real PIDOUBLE = PI * 2;
216 
218  constexpr real TAU = PI * 2;
219 
221  constexpr real INVPI = 1.0 / PI;
222 
224  constexpr real SQRTPI = 1.7724538509055159927;
225 
227  constexpr real E = 2.718281828459045235360287;
228 
230  constexpr real LOG2E = 1.44269504088896338700465094;
231 
233  constexpr real LOG210 = 3.32192809488736218170856773213;
234 
236  constexpr real LOG10E = 0.434294481903;
237 
239  constexpr real LN2 = 0.69314718056;
240 
242  constexpr real LN10 = 2.30258509299;
243 
245  constexpr real DEG2RAD = 0.017453292519943295474371680598;
246 
248  constexpr real RAD2DEG = 57.2957795130823228646477218717;
249 
251  constexpr real SQRT2 = 1.4142135623730950488;
252 
254  constexpr real INVSQR2 = 0.7071067811865475;
255 
257  constexpr real SQRT3 = 1.732050807568877;
258 
261 
264 
267 
270 
273 
274  // Default tolerance for integral approximation
275  constexpr real CALCULUS_INTEGRAL_TOL = THEORETICA_CALCULUS_INTEGRAL_TOL;
276 
279 
282 
285 
288 
291 
294 
297 
300 
303 
306 
309 
312 
315 
318 
319 }
320 
321 // Define THEORETICA_NO_NAMESPACE_ALIAS to prevent
322 // defining the alias "th" for "theoretica"
323 #ifndef THEORETICA_NO_NAMESPACE_ALIAS
325 namespace th = theoretica;
326 #endif
327 
328 #endif
#define THEORETICA_OPTIMIZATION_TOL
Approximation tolerance for root finding.
Definition: constants.h:70
#define THEORETICA_OPTIMIZATION_MINGRAD_ITER
Maximum number of iterations for gradient descent minimization.
Definition: constants.h:125
#define THEORETICA_STATISTICS_METROPOLIS_DEPTH
Default depth of the Metropolis algorithm.
Definition: constants.h:143
#define THEORETICA_OPTIMIZATION_STEFFENSEN_ITER
Maximum number of iterations for Steffensen root finding.
Definition: constants.h:95
#define THEORETICA_ALGEBRA_EIGEN_ITER
Maximum number of iterations for eigensolvers.
Definition: constants.h:49
#define THEORETICA_OPTIMIZATION_GOLDENSECTION_ITER
Maximum number of iterations for golden section search.
Definition: constants.h:80
#define THEORETICA_OPTIMIZATION_CHEBYSHEV_ITER
Maximum number of iterations for Chebyshev root finding.
Definition: constants.h:100
#define THEORETICA_STATISTICS_RAND_PREC
Default precision for random number generation using rand_uniform()
Definition: constants.h:135
#define THEORETICA_ALGEBRA_EIGEN_TOL
Tolerance for eigensolvers.
Definition: constants.h:43
#define THEORETICA_OPTIMIZATION_HALLEY_ITER
Maximum number of iterations for Halley's method.
Definition: constants.h:85
#define THEORETICA_CORE_TAYLOR_ORDER
Order of Taylor series approximations.
Definition: constants.h:55
#define THEORETICA_OPTIMIZATION_MINGRAD_TOLERANCE
Default tolerance for gradient descent minimization.
Definition: constants.h:120
#define THEORETICA_STATISTICS_TRYANDCATCH_ITER
Maximum number of failed iterations for the Try-and-Catch algorithm.
Definition: constants.h:105
#define THEORETICA_ALGEBRA_ELEMENT_TOL
THEORETICA_DISABLE_X86 Define this macro to disable Assembly x86 optimizations.
Definition: constants.h:37
#define THEORETICA_OPTIMIZATION_MINGRAD_GAMMA
Default step size for gradient descent minimization.
Definition: constants.h:115
#define THEORETICA_CALCULUS_DERIV_STEP
Default variation for derivative approximation.
Definition: constants.h:110
#define THEORETICA_OPTIMIZATION_NEWTON_ITER
Maximum number of iterations for Newton-Raphson root finding.
Definition: constants.h:90
#define THEORETICA_CALCULUS_INTEGRAL_STEPS
Default number of steps for integral approximation.
Definition: constants.h:60
#define THEORETICA_OPTIMIZATION_BISECTION_ITER
Maximum number of iterations for bisection.
Definition: constants.h:75
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:188
constexpr unsigned int STATISTICS_METROPOLIS_DEPTH
Default depth of the Metropolis algorithm.
Definition: constants.h:317
constexpr real PI2
Half of Pi.
Definition: constants.h:209
constexpr uint64_t STATISTICS_RAND_PREC
Default precision for random number generation using rand_uniform()
Definition: constants.h:314
constexpr real SQRTPI
The square root of Pi.
Definition: constants.h:224
constexpr real LN10
The natural logarithm of 10.
Definition: constants.h:242
constexpr real LOG210
The binary logarithm of 10.
Definition: constants.h:233
constexpr real INVSQR2
The inverse of the square root of 2.
Definition: constants.h:254
constexpr real ALGEBRA_ELEMENT_TOL
Tolerance for the elements of matrices.
Definition: constants.h:260
constexpr real INVPI
The inverse of Pi.
Definition: constants.h:221
constexpr real OPTIMIZATION_MINGRAD_TOLERANCE
Default tolerance for gradient descent minimization.
Definition: constants.h:308
constexpr real OPTIMIZATION_TOL
Approximation tolerance for root finding.
Definition: constants.h:278
constexpr real CALCULUS_DERIV_STEP
Default variation for derivative approximation.
Definition: constants.h:302
constexpr real LOG10E
The base-10 logarithm of e.
Definition: constants.h:236
constexpr unsigned int STATISTICS_TRYANDCATCH_ITER
Maximum number of failed iterations for the Try-and-Catch algorithm.
Definition: constants.h:299
constexpr real INVPHI
The inverse of the Golden Section mathematical constant.
Definition: constants.h:203
constexpr real LN2
The natural logarithm of 2.
Definition: constants.h:239
constexpr real LOG2E
The binary logarithm of e.
Definition: constants.h:230
constexpr unsigned int OPTIMIZATION_GOLDENSECTION_ITER
Maximum number of iterations for the golden section search algorithm.
Definition: constants.h:284
constexpr unsigned int OPTIMIZATION_MINGRAD_ITER
Maximum number of iterations for gradient descent minimization.
Definition: constants.h:311
constexpr int CALCULUS_INTEGRAL_STEPS
Default number of steps for integral approximation.
Definition: constants.h:272
constexpr real PIDOUBLE
Pi multiplied by 2.
Definition: constants.h:215
constexpr real MACH_EPSILON
Machine epsilon for the real type.
Definition: constants.h:197
constexpr real E
The Euler mathematical constant (e)
Definition: constants.h:227
constexpr unsigned int OPTIMIZATION_CHEBYSHEV_ITER
Maximum number of iterations for the Chebyshev algorithm.
Definition: constants.h:296
constexpr unsigned int OPTIMIZATION_BISECTION_ITER
Maximum number of iterations for the bisection algorithm.
Definition: constants.h:281
constexpr unsigned int OPTIMIZATION_STEFFENSEN_ITER
Maximum number of iterations for the Steffensen algorithm.
Definition: constants.h:293
constexpr int CORE_TAYLOR_ORDER
Order of Taylor series approximations.
Definition: constants.h:269
constexpr real PI4
A quarter of Pi.
Definition: constants.h:212
constexpr unsigned int OPTIMIZATION_NEWTON_ITER
Maximum number of iterations for the Newton-Raphson algorithm.
Definition: constants.h:290
constexpr real PHI
The Phi (Golden Section) mathematical constant.
Definition: constants.h:200
constexpr real SQRT3
The square root of 3.
Definition: constants.h:257
constexpr real DEG2RAD
The scalar conversion factor from degrees to radians.
Definition: constants.h:245
constexpr real ALGEBRA_EIGEN_ITER
Maximum number of iterations for eigensolvers.
Definition: constants.h:266
constexpr real SQRT2
The square root of 2.
Definition: constants.h:251
constexpr unsigned int OPTIMIZATION_HALLEY_ITER
Maximum number of iterations for Halley's method.
Definition: constants.h:287
constexpr real RAD2DEG
The scalar conversion factor from radians to degrees.
Definition: constants.h:248
constexpr real PI
The Pi mathematical constant.
Definition: constants.h:206
constexpr real TAU
The Tau mathematical constant (Pi times 2)
Definition: constants.h:218
constexpr real OPTIMIZATION_MINGRAD_GAMMA
Default step size for gradient descent minimization.
Definition: constants.h:305
constexpr real ALGEBRA_EIGEN_TOL
Tolerance for eigensolvers.
Definition: constants.h:263