| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <cmath> | ||
| 4 | #include <cstdint> | ||
| 5 | #include <string> | ||
| 6 | #include <tuple> | ||
| 7 | |||
| 8 | #include "task/include/task.hpp" | ||
| 9 | |||
| 10 | namespace krasnopevtseva_v_monte_carlo_integration { | ||
| 11 | |||
| 12 | using InType = std::tuple<double, double, int, std::uint8_t>; | ||
| 13 | using OutType = double; | ||
| 14 | using TestType = std::tuple<std::tuple<double, double, int, std::uint8_t>, std::string>; | ||
| 15 | using BaseTask = ppc::task::Task<InType, OutType>; | ||
| 16 | |||
| 17 | enum class FuncIndex : std::uint8_t { | ||
| 18 | kCosX3 = 0, // cos(x) * x^3 | ||
| 19 | kSinX2 = 1, // sin(x) * x^2 | ||
| 20 | kExpX = 2, // exp(-x) * x | ||
| 21 | kPolyX = 3 // x^4 - 2*x^2 + 1 | ||
| 22 | }; | ||
| 23 | |||
| 24 | class FuncSystem { | ||
| 25 | public: | ||
| 26 | 6486246 | static double GetFunc(std::uint8_t index, double x) { | |
| 27 |
2/2✓ Branch 0 taken 1299087 times.
✓ Branch 1 taken 5187159 times.
|
6486246 | if (index == 0) { |
| 28 | 1299087 | return std::cos(x) * x * x * x; | |
| 29 | } | ||
| 30 |
2/2✓ Branch 0 taken 1899081 times.
✓ Branch 1 taken 3288078 times.
|
5187159 | if (index == 1) { |
| 31 | 1899081 | return std::sin(x) * x * x; | |
| 32 | } | ||
| 33 |
2/2✓ Branch 0 taken 1299087 times.
✓ Branch 1 taken 1988991 times.
|
3288078 | if (index == 2) { |
| 34 | 1299087 | return std::exp(-x) * x; | |
| 35 | } | ||
| 36 | 1988991 | return (x * x * x * x) - (2 * x * x) + 1; | |
| 37 | } | ||
| 38 | |||
| 39 | 200 | static double AnalyticIntegral(std::uint8_t index, double a, double b) { | |
| 40 |
2/2✓ Branch 0 taken 50 times.
✓ Branch 1 taken 150 times.
|
200 | if (index == 0) { |
| 41 | 50 | return AnalyticCosX3(a, b); | |
| 42 | } | ||
| 43 |
2/2✓ Branch 0 taken 50 times.
✓ Branch 1 taken 100 times.
|
150 | if (index == 1) { |
| 44 | 50 | return AnalyticSinX2(a, b); | |
| 45 | } | ||
| 46 |
2/2✓ Branch 0 taken 50 times.
✓ Branch 1 taken 50 times.
|
100 | if (index == 2) { |
| 47 | 50 | return AnalyticExpX(a, b); | |
| 48 | } | ||
| 49 | 50 | return AnalyticPolyX(a, b); | |
| 50 | } | ||
| 51 | |||
| 52 | private: | ||
| 53 | 100 | static double FCos(double x) { | |
| 54 | 100 | return ((x * x * x - 6 * x) * std::sin(x)) + ((3 * x * x - 6) * std::cos(x)); | |
| 55 | } | ||
| 56 | static double AnalyticCosX3(double a, double b) { | ||
| 57 | 50 | return FCos(b) - FCos(a); | |
| 58 | } | ||
| 59 | |||
| 60 | 100 | static double FSin(double x) { | |
| 61 | 100 | return (2 * std::sin(x) * x) - ((x * x - 2) * std::cos(x)); | |
| 62 | } | ||
| 63 | |||
| 64 | static double AnalyticSinX2(double a, double b) { | ||
| 65 | 50 | return FSin(b) - FSin(a); | |
| 66 | } | ||
| 67 | |||
| 68 | static double FExp(double x) { | ||
| 69 | 50 | return -(x + 1) * std::exp(-x); | |
| 70 | } | ||
| 71 | 50 | static double AnalyticExpX(double a, double b) { | |
| 72 | 50 | return FExp(b) - FExp(a); | |
| 73 | } | ||
| 74 | |||
| 75 | static double FPoly(double x) { | ||
| 76 | 50 | return ((x * x * x * x * x) / 5.0) - ((2 * x * x * x) / 3.0) + x; | |
| 77 | } | ||
| 78 | |||
| 79 | 50 | static double AnalyticPolyX(double a, double b) { | |
| 80 | 50 | return FPoly(b) - FPoly(a); | |
| 81 | } | ||
| 82 | }; | ||
| 83 | |||
| 84 | } // namespace krasnopevtseva_v_monte_carlo_integration | ||
| 85 |