Theoretica
A C++ numerical and automatic mathematical library
prec_structures.h
Go to the documentation of this file.
1 
5 
6 #ifndef CHEBYSHEV_PREC_STRUCTURES_H
7 #define CHEBYSHEV_PREC_STRUCTURES_H
8 
9 #include <string>
10 #include <vector>
11 #include <functional>
12 
13 #include "../core/common.h"
14 #include "./interval.h"
15 #include "./distance.h"
16 
17 
18 namespace chebyshev {
19 
20  namespace prec {
21 
22 
25  struct estimate_result {
26 
28  std::string name = "unknown";
29 
31  std::vector<interval> domain {};
32 
34  long double tolerance = 0;
35 
37  long double maxErr = get_nan<long double>();
38 
40  long double meanErr = get_nan<long double>();
41 
43  long double rmsErr = get_nan<long double>();
44 
46  long double relErr = get_nan<long double>();
47 
49  long double absErr = get_nan<long double>();
50 
52  std::map<std::string, long double> additionalFields {};
53 
55  bool failed = false;
56 
58  bool quiet = false;
59 
61  unsigned int iterations {0};
62  };
63 
64 
66  using FailFunction = std::function<bool(const estimate_result&)>;
67 
68 
70  template<typename Type>
71  using DistanceFunction = std::function<long double(Type, Type)>;
72 
73 
76  template<typename R, typename ...Args>
78 
79  using Estimator_t = std::function<
81  std::function<R(Args...)>,
82  std::function<R(Args...)>,
84 
86  std::vector<interval> domain {};
87 
90  Estimator_t estimator = [](
91  std::function<R(Args...)> f1,
92  std::function<R(Args...)> f2,
93  estimate_options opt) {
94  return estimate_result();
95  };
96 
99 
102 
106  return (r.maxErr > r.tolerance) || (r.maxErr != r.maxErr);
107  };
108 
110  bool quiet = false;
111 
112 
117 
118 
122  estimate_options(interval omega, Estimator_t estimator)
123  : domain({omega}), estimator(estimator) {}
124 
125 
130  interval omega,
131  Estimator_t estimator,
132  long double tolerance,
133  bool quiet = false)
135 
136 
140  estimate_options(std::vector<interval> omega, Estimator_t estimator)
141  : domain(omega), estimator(estimator) {}
142 
147  std::vector<interval> omega,
148  Estimator_t estimator,
149  long double tolerance,
150  bool quiet = false)
152 
153  };
154 
155 
157  template<typename R, typename ...Args>
158  using Estimator = typename estimate_options<R, Args...>::Estimator_t;
159 
160 
164 
166  std::string name = "unknown";
167 
169  long double evaluated = get_nan<long double>();
170 
172  long double expected = get_nan<long double>();
173 
175  long double difference = get_nan<long double>();
176 
179  std::map<std::string, long double> additionalFields {};
180 
182  long double tolerance = 0;
183 
185  bool failed = true;
186 
188  bool quiet = false;
189  };
190 
191 
194  template<typename T>
196 
199 
202  DistanceFunction<T> distance = [](T x, T y) {
203  const auto diff = x - y;
204  return (long double) (diff > 0 ? diff : -diff);
205  };
206 
208  bool quiet = false;
209 
210 
213 
214 
218 
219 
222  equation_options(long double tolerance, DistanceFunction<T> dist, bool quiet = false)
223  : tolerance(tolerance), distance(dist), quiet(quiet) {}
224  };
225 
226  }
227 }
228 
229 #endif
#define CHEBYSHEV_PREC_ITER
Default number of function evaluations in precision testing.
Definition: common.h:12
#define CHEBYSHEV_PREC_TOLERANCE
Default tolerance in precision testing.
Definition: common.h:17
Interval over the real numbers.
std::function< long double(Type, Type)> DistanceFunction
Distance function between two elements.
Definition: prec_structures.h:71
std::function< bool(const estimate_result &)> FailFunction
A function which determines whether an estimation failed.
Definition: prec_structures.h:66
typename estimate_options< R, Args... >::Estimator_t Estimator
Generic precision estimator function signature.
Definition: prec_structures.h:158
std::string string(size_t length)
Generate a random string made of human-readable ASCII characters.
Definition: random.h:102
General namespace of the framework.
Definition: benchmark_structures.h:16
Structure holding options for equivalence evaluation.
Definition: prec_structures.h:195
bool quiet
Print to standard output or not.
Definition: prec_structures.h:208
equation_options(long double tolerance, DistanceFunction< T > dist, bool quiet=false)
Construct equation options from the tolerance, the distance function and the quiet flag (defaults to ...
Definition: prec_structures.h:222
long double tolerance
Tolerance on the absolute difference.
Definition: prec_structures.h:198
equation_options()
Default constructor for equation options.
Definition: prec_structures.h:212
DistanceFunction< T > distance
Distance function to measure the distance between the expected and evaluated value.
Definition: prec_structures.h:202
equation_options(long double tolerance)
Construct equation options from the tolerance, setting the distance function to a simple Euclidean di...
Definition: prec_structures.h:217
A structure holding the result of an evaluation.
Definition: prec_structures.h:163
long double tolerance
Tolerance on the absolute difference.
Definition: prec_structures.h:182
bool failed
Whether the test failed.
Definition: prec_structures.h:185
bool quiet
Print to standard output or not.
Definition: prec_structures.h:188
std::string name
Identifying name of the function or test case.
Definition: prec_structures.h:166
long double difference
Evaluated difference between expected and evaluated values.
Definition: prec_structures.h:175
std::map< std::string, long double > additionalFields
Additional fields by name, as a floating point value.
Definition: prec_structures.h:179
long double evaluated
Evaluated value.
Definition: prec_structures.h:169
long double expected
Expected value.
Definition: prec_structures.h:172
A structure holding the options for precision estimation.
Definition: prec_structures.h:77
FailFunction fail
The function to determine whether the test failed (defaults to fail::fail_on_max_err).
Definition: prec_structures.h:105
unsigned int iterations
Number of function evaluations to use.
Definition: prec_structures.h:101
estimate_options(interval omega, Estimator_t estimator)
Construct estimate options from a one-dimensional interval domain and an estimator,...
Definition: prec_structures.h:122
estimate_options(interval omega, Estimator_t estimator, long double tolerance, bool quiet=false)
Construct estimate options from a one-dimensional interval domain, an estimator, a tolerance and an o...
Definition: prec_structures.h:129
estimate_options(std::vector< interval > omega, Estimator_t estimator)
Construct estimate options from a multidimensional interval domain and an estimator,...
Definition: prec_structures.h:140
std::vector< interval > domain
The domain of estimation.
Definition: prec_structures.h:86
Estimator_t estimator
The precision estimator to use (defaults to a dummy estimator)
Definition: prec_structures.h:90
estimate_options(std::vector< interval > omega, Estimator_t estimator, long double tolerance, bool quiet=false)
Construct estimate options from a multidimensional interval domain, an estimator, a tolerance and an ...
Definition: prec_structures.h:146
long double tolerance
The tolerance to use to determine whether the test failed.
Definition: prec_structures.h:98
bool quiet
Whether to show the test result or not.
Definition: prec_structures.h:110
estimate_options()
Construct estimate options with all default values.
Definition: prec_structures.h:116
A structure holding the result of precision estimation.
Definition: prec_structures.h:25
std::string name
Identifying name of the function or test case.
Definition: prec_structures.h:28
std::map< std::string, long double > additionalFields
Additional fields by name, as a floating point value.
Definition: prec_structures.h:52
bool quiet
Print to standard output or not.
Definition: prec_structures.h:58
long double meanErr
Estimated mean error on interval.
Definition: prec_structures.h:40
long double relErr
Estimated relative error on interval.
Definition: prec_structures.h:46
long double maxErr
Estimated maximum absolute error on interval.
Definition: prec_structures.h:37
bool failed
Whether the test failed.
Definition: prec_structures.h:55
std::vector< interval > domain
Interval of estimation.
Definition: prec_structures.h:31
long double rmsErr
Estimated RMS error on interval.
Definition: prec_structures.h:43
unsigned int iterations
Total number of iterations for integral quadrature.
Definition: prec_structures.h:61
long double absErr
Estimated absolute error on interval.
Definition: prec_structures.h:49
long double tolerance
Tolerance on the max absolute error.
Definition: prec_structures.h:34
An interval on the real numbers.
Definition: interval.h:16
Distance functions.