Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // innermost function
- double g(double x, vector<double> pars){
- return x * pars[0] * pars[0];
- }
- // some intermediate function
- template <typename F>
- auto f0(F const & f, double x, vector<double> pars) {
- return [f, pars](double x, vector<double> pars) {
- vector<double> pars_0(pars);
- pars_0[0] = 0;
- return f(x, pars_0);
- };
- }
- // another intermediate function
- template <typename F>
- auto f1(F const & f, double x, vector<double> pars) {
- return [f, pars](double x, vector<double> pars) {
- vector<double> pars_1(pars);
- pars_1[0] = 1;
- return f(x, pars_1);
- };
- }
- // selector function
- template <typename F>
- auto D(F const & f, double x, vector<double> pars, int degree) {
- if(0 == degree) {
- return f0(f, x, pars)(x, pars);
- } else {
- return f1(f, x, pars)(x, pars);
- }
- }
- template <typename F>
- auto D(F const & f, double x, vector<double> pars, int degree) {
- if(0 == degree) {
- return [f, x, pars](F const & f, int x, vector<double> pars) {
- return D(f0(f, x, pars)(x, pars)); // <<< ?
- };
- } else {
- return // same stuff for the other function(s)
- }
- }
- int sum = 0;
- for(int i = 0; i < 3; ++i ){
- for(int j = 0; j < 3; ++j ){
- for(int k = 0; k < 3; ++k ){
- ...
- sum += D(...(D(g, i), j)...,k) (pars of the lambdas);
- // number of for loops depends on size of pars passed to f
- }
- }
- }
Add Comment
Please, Sign In to add comment