2013-07-17 19:24:07 +02:00
|
|
|
#include <triqs/clef.hpp>
|
|
|
|
|
2013-09-07 15:27:10 +02:00
|
|
|
template<typename Domain> struct sum_impl {
|
2013-07-17 19:24:07 +02:00
|
|
|
Domain d;
|
|
|
|
|
2013-09-07 15:27:10 +02:00
|
|
|
// C++14
|
|
|
|
// double operator() (NotClefExpression const & f) const { double s=0; for (int u=0; u<10; ++u) s += f(u/10.0); return s;}
|
|
|
|
|
|
|
|
// C++11 form
|
2013-07-17 19:24:07 +02:00
|
|
|
template <typename F>
|
2013-09-07 15:27:10 +02:00
|
|
|
typename std::enable_if< !triqs::clef::is_clef_expression <F>::value, double >::type
|
2013-07-17 19:24:07 +02:00
|
|
|
operator() (F const & f) const { double s=0; for (int u=0; u<10; ++u) s += f(u/10.0); return s;}
|
|
|
|
|
2013-09-07 15:27:10 +02:00
|
|
|
TRIQS_CLEF_IMPLEMENT_LAZY_CALL(sum_impl);
|
2013-07-17 19:24:07 +02:00
|
|
|
|
|
|
|
friend std::ostream & operator<<(std::ostream & out, sum_impl const & x) { return out<<"sum";}
|
|
|
|
};
|
|
|
|
|
2013-09-07 15:27:10 +02:00
|
|
|
// a little factory ...
|
|
|
|
template<typename Domain> sum_impl<Domain> sum_functional (Domain d) {return {d};}
|
2013-07-17 19:24:07 +02:00
|
|
|
|
|
|
|
struct DOM{};
|
|
|
|
|
|
|
|
int main() {
|
2013-09-07 15:27:10 +02:00
|
|
|
triqs::clef::placeholder <1> x_; triqs::clef::placeholder <2> y_;
|
|
|
|
DOM d;
|
2013-07-17 19:24:07 +02:00
|
|
|
|
2013-09-07 15:27:10 +02:00
|
|
|
// integrate_on_d is the integration functional
|
|
|
|
auto integrate_on_d = sum_functional(d);
|
2013-07-17 19:24:07 +02:00
|
|
|
|
2013-09-07 15:27:10 +02:00
|
|
|
// This is a simple application of the sum to a function
|
|
|
|
std::cout<< integrate_on_d( x_ >> 2*x_ + 1 ) << std::endl;
|
2013-07-17 19:24:07 +02:00
|
|
|
|
2013-09-07 15:27:10 +02:00
|
|
|
// A function y -> y_ + integrate (x -> 2*x + y)
|
|
|
|
auto e1 = y_ + integrate_on_d( x_ >> 2*x_ + y_ );
|
|
|
|
std::cout<< e1 << std::endl;
|
|
|
|
std::cout<< eval (e1 ,y_ =0) << std::endl;
|
2013-07-17 19:24:07 +02:00
|
|
|
}
|
|
|
|
|