Theoretica
A C++ numerical and automatic mathematical library
quasirandom.h
Go to the documentation of this file.
1 
5 
6 #ifndef THEORETICA_QUASIRANDOM_H
7 #define THEORETICA_QUASIRANDOM_H
8 
9 #include "../core/real_analysis.h"
10 #include "../algebra/algebra_types.h"
11 
12 
13 namespace theoretica {
14 
15 
24  inline real qrand_weyl(unsigned int n, real alpha = INVPHI) {
25  return fract(n * alpha);
26  }
27 
28 
38  inline real qrand_weyl_recurr(real prev = 0, real alpha = INVPHI) {
39 
40  if(prev == 0) {
41  prev = qrand_weyl(1, alpha);
42  return prev;
43  }
44 
45  return fract(prev + alpha);
46  }
47 
48 
54  template<unsigned int N>
55  inline vec<real, N> qrand_weyl_multi(unsigned int n, real alpha) {
56 
57  vec<real, N> r;
58  for (unsigned int i = 0; i < N; ++i)
59  r[i] = fract(n * pow(alpha, i + 1));
60 
61  return r;
62  }
63 
64 
70  inline vec2 qrand_weyl2(unsigned int n, real alpha = 0.7548776662466927) {
71  return {fract(n * alpha), fract(n * square(alpha))};
72  }
73 
74 
75 }
76 
77 #endif
A statically allocated N-dimensional vector with elements of the given type.
Definition: vec.h:88
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
vec< real, N > qrand_weyl_multi(unsigned int n, real alpha)
Weyl quasi-random sequence in N dimensions.
Definition: quasirandom.h:55
constexpr real INVPHI
The inverse of the Golden Section mathematical constant.
Definition: constants.h:203
real qrand_weyl_recurr(real prev=0, real alpha=INVPHI)
Weyl quasi-random sequence (computed with recurrence relation)
Definition: quasirandom.h:38
real fract(real x)
Compute the fractional part of a real number.
Definition: real_analysis.h:288
real qrand_weyl(unsigned int n, real alpha=INVPHI)
Weyl quasi-random sequence.
Definition: quasirandom.h:24
vec2 qrand_weyl2(unsigned int n, real alpha=0.7548776662466927)
Weyl quasi-random sequence in 2 dimensions.
Definition: quasirandom.h:70
dual2 square(dual2 x)
Return the square of a second order dual number.
Definition: dual2_functions.h:23
dual2 pow(dual2 x, int n)
Compute the n-th power of a second order dual number.
Definition: dual2_functions.h:41