Theoretica
Mathematical Library
Loading...
Searching...
No Matches
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
16#ifndef THEORETICA_DISABLE_X86
17
18#ifndef THEORETICA_X86
19#if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) \
20 || defined(_M_AMD64) || defined(_M_X64) || defined(i386) \
21 || defined(__i386) || defined(__i386__) || defined(_M_IX86) \
22 || defined(_X86_) || defined(_M_I86) || defined(__X86__)
23
27#define THEORETICA_X86
28#endif
29#endif
30#endif
31
32
34#ifndef THEORETICA_DISABLE_CPP20
35#ifndef THEORETICA_USE_CPP20
36#if (__cplusplus >= 202002L)
38#define THEORETICA_USE_CPP20
39#endif
40#endif
41#endif
42
45#ifndef THEORETICA_ALGEBRA_ELEMENT_TOL
46#define THEORETICA_ALGEBRA_ELEMENT_TOL (10*MACH_EPSILON)
47#endif
48
49
51#ifndef THEORETICA_ALGEBRA_EIGEN_TOL
52#define THEORETICA_ALGEBRA_EIGEN_TOL 1E-08
53#endif
54
55
57#ifndef THEORETICA_ALGEBRA_EIGEN_ITER
58#define THEORETICA_ALGEBRA_EIGEN_ITER 100
59#endif
60
61
63#ifndef THEORETICA_CORE_TAYLOR_ORDER
64#define THEORETICA_CORE_TAYLOR_ORDER 12
65#endif
66
68#ifndef THEORETICA_CALCULUS_INTEGRAL_STEPS
69#define THEORETICA_CALCULUS_INTEGRAL_STEPS 100
70#endif
71
72// Default tolerance for integral approximation
73#ifndef THEORETICA_CALCULUS_INTEGRAL_TOL
74#define THEORETICA_CALCULUS_INTEGRAL_TOL 1E-08
75#endif
76
78#ifndef THEORETICA_OPTIMIZATION_TOL
79#define THEORETICA_OPTIMIZATION_TOL 1E-08
80#endif
81
83#ifndef THEORETICA_OPTIMIZATION_BISECTION_ITER
84#define THEORETICA_OPTIMIZATION_BISECTION_ITER 100
85#endif
86
88#ifndef THEORETICA_OPTIMIZATION_GOLDENSECTION_ITER
89#define THEORETICA_OPTIMIZATION_GOLDENSECTION_ITER 100
90#endif
91
93#ifndef THEORETICA_OPTIMIZATION_HALLEY_ITER
94#define THEORETICA_OPTIMIZATION_HALLEY_ITER 100
95#endif
96
98#ifndef THEORETICA_OPTIMIZATION_NEWTON_ITER
99#define THEORETICA_OPTIMIZATION_NEWTON_ITER 100
100#endif
101
103#ifndef THEORETICA_OPTIMIZATION_STEFFENSEN_ITER
104#define THEORETICA_OPTIMIZATION_STEFFENSEN_ITER 100
105#endif
106
108#ifndef THEORETICA_OPTIMIZATION_CHEBYSHEV_ITER
109#define THEORETICA_OPTIMIZATION_CHEBYSHEV_ITER 100
110#endif
111
113#ifndef THEORETICA_OPTIMIZATION_OSTROWSKI_ITER
114#define THEORETICA_OPTIMIZATION_OSTROWSKI_ITER 100
115#endif
116
118#ifndef THEORETICA_OPTIMIZATION_JARRAT_ITER
119#define THEORETICA_OPTIMIZATION_JARRAT_ITER 100
120#endif
121
123#ifndef THEORETICA_STATISTICS_TRYANDCATCH_ITER
124#define THEORETICA_STATISTICS_TRYANDCATCH_ITER 100
125#endif
126
128#ifndef THEORETICA_CALCULUS_DERIV_STEP
129#define THEORETICA_CALCULUS_DERIV_STEP 1E-3
130#endif
131
133#ifndef THEORETICA_OPTIMIZATION_MINGRAD_GAMMA
134#define THEORETICA_OPTIMIZATION_MINGRAD_GAMMA -0.005
135#endif
136
138#ifndef THEORETICA_OPTIMIZATION_MINGRAD_TOLERANCE
139#define THEORETICA_OPTIMIZATION_MINGRAD_TOLERANCE 1E-3
140#endif
141
143#ifndef THEORETICA_OPTIMIZATION_MINGRAD_ITER
144#define THEORETICA_OPTIMIZATION_MINGRAD_ITER 50000
145#endif
146
147
148#ifndef THEORETICA_STATISTICS_RAND_PREC
149
151#ifdef THEORETICA_FLOAT_PREC
152#define THEORETICA_STATISTICS_RAND_PREC (uint64_t(1) << 23)
153#else
154#define THEORETICA_STATISTICS_RAND_PREC (uint64_t(1) << 31)
155#endif
156
157#endif
158
159
161#ifndef THEORETICA_STATISTICS_METROPOLIS_DEPTH
162#define THEORETICA_STATISTICS_METROPOLIS_DEPTH 16
163#endif
164
165
167#if (__cplusplus >= 201402L)
168#define TH_CONSTEXPR constexpr
169#else
170#define TH_CONSTEXPR
171#endif
172
173
175#if (__cplusplus >= 201703L)
176#define TH_CONSTIF constexpr
177#else
178#define TH_CONSTIF
179#endif
180
181
183namespace theoretica {
184
192
193#ifdef THEORETICA_LONG_DOUBLE_PREC
194
195 using real = long double;
196
197#elif defined(THEORETICA_FLOAT_PREC)
198
199 using real = float;
200
201#elif defined(THEORETICA_ARBITRARY_PREC)
202
203// TO-DO bigfloat arbitrary precision
204
205#else
206
207 using real = double;
208
209#endif
210
211
212 // Mathematical constants and default algorithm parameters.
213
214
216 constexpr real MACH_EPSILON = std::numeric_limits<real>::epsilon();
217
219 constexpr real PHI = 1.6180339887498948482045868;
220
222 constexpr real INVPHI = 0.6180339887498948482045868;
223
225 constexpr real PI = 3.141592653589793238462643;
226
228 constexpr real PI2 = 1.57079632679489655799898;
229
231 constexpr real PI4 = PI / 4.0;
232
234 constexpr real PIDOUBLE = PI * 2;
235
237 constexpr real TAU = PI * 2;
238
240 constexpr real INVPI = 1.0 / PI;
241
243 constexpr real SQRTPI = 1.7724538509055159927;
244
246 constexpr real E = 2.718281828459045235360287;
247
249 constexpr real LOG2E = 1.44269504088896338700465094;
250
252 constexpr real LOG210 = 3.32192809488736218170856773213;
253
255 constexpr real LOG10E = 0.434294481903;
256
258 constexpr real LN2 = 0.69314718056;
259
261 constexpr real LN10 = 2.30258509299;
262
264 constexpr real DEG2RAD = 0.017453292519943295474371680598;
265
267 constexpr real RAD2DEG = 57.2957795130823228646477218717;
268
270 constexpr real SQRT2 = 1.4142135623730950488;
271
273 constexpr real INVSQR2 = 0.7071067811865475;
274
276 constexpr real SQRT3 = 1.732050807568877;
277
280
283
286
289
292
293 // Default tolerance for integral approximation
294 constexpr real CALCULUS_INTEGRAL_TOL = THEORETICA_CALCULUS_INTEGRAL_TOL;
295
298
301
304
307
310
313
316
319
322
325
328
331
334
337
340
343
344}
345
346// Define THEORETICA_NO_NAMESPACE_ALIAS to prevent
347// defining the alias "th" for "theoretica"
348#ifndef THEORETICA_NO_NAMESPACE_ALIAS
350namespace th = theoretica;
351#endif
352
353#endif
#define THEORETICA_OPTIMIZATION_TOL
Approximation tolerance for root finding.
Definition constants.h:79
#define THEORETICA_OPTIMIZATION_MINGRAD_ITER
Maximum number of iterations for gradient descent minimization.
Definition constants.h:144
#define THEORETICA_STATISTICS_METROPOLIS_DEPTH
Default depth of the Metropolis algorithm.
Definition constants.h:162
#define THEORETICA_OPTIMIZATION_STEFFENSEN_ITER
Maximum number of iterations for Steffensen root finding.
Definition constants.h:104
#define THEORETICA_ALGEBRA_EIGEN_ITER
Maximum number of iterations for eigensolvers.
Definition constants.h:58
#define THEORETICA_OPTIMIZATION_GOLDENSECTION_ITER
Maximum number of iterations for golden section search.
Definition constants.h:89
#define THEORETICA_OPTIMIZATION_CHEBYSHEV_ITER
Maximum number of iterations for Chebyshev root finding.
Definition constants.h:109
#define THEORETICA_STATISTICS_RAND_PREC
Default precision for random number generation using rand_uniform()
Definition constants.h:154
#define THEORETICA_ALGEBRA_EIGEN_TOL
Tolerance for eigensolvers.
Definition constants.h:52
#define THEORETICA_OPTIMIZATION_HALLEY_ITER
Maximum number of iterations for Halley's method.
Definition constants.h:94
#define THEORETICA_CORE_TAYLOR_ORDER
Order of Taylor series approximations.
Definition constants.h:64
#define THEORETICA_OPTIMIZATION_OSTROWSKI_ITER
Maximum number of iterations for Ostrowski root finding.
Definition constants.h:114
#define THEORETICA_OPTIMIZATION_MINGRAD_TOLERANCE
Default tolerance for gradient descent minimization.
Definition constants.h:139
#define THEORETICA_STATISTICS_TRYANDCATCH_ITER
Maximum number of failed iterations for the Try-and-Catch algorithm.
Definition constants.h:124
#define THEORETICA_OPTIMIZATION_JARRAT_ITER
Maximum number of iterations for Jarrat root finding.
Definition constants.h:119
#define THEORETICA_ALGEBRA_ELEMENT_TOL
THEORETICA_DISABLE_X86 Define this macro to disable Assembly x86 optimizations.
Definition constants.h:46
#define THEORETICA_OPTIMIZATION_MINGRAD_GAMMA
Default step size for gradient descent minimization.
Definition constants.h:134
#define THEORETICA_CALCULUS_DERIV_STEP
Default variation for derivative approximation.
Definition constants.h:129
#define THEORETICA_OPTIMIZATION_NEWTON_ITER
Maximum number of iterations for Newton-Raphson root finding.
Definition constants.h:99
#define THEORETICA_CALCULUS_INTEGRAL_STEPS
Default number of steps for integral approximation.
Definition constants.h:69
#define THEORETICA_OPTIMIZATION_BISECTION_ITER
Maximum number of iterations for bisection.
Definition constants.h:84
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
constexpr unsigned int OPTIMIZATION_JARRAT_ITER
Maximum number of iterations for the Jarrat algorithm.
Definition constants.h:321
constexpr unsigned int STATISTICS_METROPOLIS_DEPTH
Default depth of the Metropolis algorithm.
Definition constants.h:342
constexpr real PI2
Half of Pi.
Definition constants.h:228
constexpr uint64_t STATISTICS_RAND_PREC
Default precision for random number generation using rand_uniform()
Definition constants.h:339
constexpr real SQRTPI
The square root of Pi.
Definition constants.h:243
constexpr real LN10
The natural logarithm of 10.
Definition constants.h:261
constexpr real LOG210
The binary logarithm of 10.
Definition constants.h:252
constexpr real INVSQR2
The inverse of the square root of 2.
Definition constants.h:273
constexpr real ALGEBRA_ELEMENT_TOL
Tolerance for the elements of matrices.
Definition constants.h:279
constexpr real INVPI
The inverse of Pi.
Definition constants.h:240
constexpr real OPTIMIZATION_MINGRAD_TOLERANCE
Default tolerance for gradient descent minimization.
Definition constants.h:333
constexpr real OPTIMIZATION_TOL
Approximation tolerance for root finding.
Definition constants.h:297
constexpr real CALCULUS_DERIV_STEP
Default variation for derivative approximation.
Definition constants.h:327
constexpr real LOG10E
The base-10 logarithm of e.
Definition constants.h:255
constexpr unsigned int STATISTICS_TRYANDCATCH_ITER
Maximum number of failed iterations for the Try-and-Catch algorithm.
Definition constants.h:324
constexpr real INVPHI
The inverse of the Golden Section mathematical constant.
Definition constants.h:222
constexpr unsigned int OPTIMIZATION_OSTROWSKI_ITER
Maximum number of iterations for the Ostrowski algorithm.
Definition constants.h:318
constexpr real LN2
The natural logarithm of 2.
Definition constants.h:258
constexpr real LOG2E
The binary logarithm of e.
Definition constants.h:249
constexpr unsigned int OPTIMIZATION_GOLDENSECTION_ITER
Maximum number of iterations for the golden section search algorithm.
Definition constants.h:303
constexpr unsigned int OPTIMIZATION_MINGRAD_ITER
Maximum number of iterations for gradient descent minimization.
Definition constants.h:336
constexpr int CALCULUS_INTEGRAL_STEPS
Default number of steps for integral approximation.
Definition constants.h:291
constexpr real PIDOUBLE
Pi multiplied by 2.
Definition constants.h:234
constexpr real MACH_EPSILON
Machine epsilon for the real type.
Definition constants.h:216
constexpr real E
The Euler mathematical constant (e)
Definition constants.h:246
constexpr unsigned int OPTIMIZATION_CHEBYSHEV_ITER
Maximum number of iterations for the Chebyshev algorithm.
Definition constants.h:315
constexpr unsigned int OPTIMIZATION_BISECTION_ITER
Maximum number of iterations for the bisection algorithm.
Definition constants.h:300
constexpr unsigned int OPTIMIZATION_STEFFENSEN_ITER
Maximum number of iterations for the Steffensen algorithm.
Definition constants.h:312
constexpr int CORE_TAYLOR_ORDER
Order of Taylor series approximations.
Definition constants.h:288
constexpr real PI4
A quarter of Pi.
Definition constants.h:231
constexpr unsigned int OPTIMIZATION_NEWTON_ITER
Maximum number of iterations for the Newton-Raphson algorithm.
Definition constants.h:309
constexpr real PHI
The Phi (Golden Section) mathematical constant.
Definition constants.h:219
constexpr real SQRT3
The square root of 3.
Definition constants.h:276
constexpr real DEG2RAD
The scalar conversion factor from degrees to radians.
Definition constants.h:264
constexpr real ALGEBRA_EIGEN_ITER
Maximum number of iterations for eigensolvers.
Definition constants.h:285
constexpr real SQRT2
The square root of 2.
Definition constants.h:270
constexpr unsigned int OPTIMIZATION_HALLEY_ITER
Maximum number of iterations for Halley's method.
Definition constants.h:306
constexpr real RAD2DEG
The scalar conversion factor from radians to degrees.
Definition constants.h:267
constexpr real PI
The Pi mathematical constant.
Definition constants.h:225
constexpr real TAU
The Tau mathematical constant (Pi times 2)
Definition constants.h:237
constexpr real OPTIMIZATION_MINGRAD_GAMMA
Default step size for gradient descent minimization.
Definition constants.h:330
constexpr real ALGEBRA_EIGEN_TOL
Tolerance for eigensolvers.
Definition constants.h:282