21 #ifndef RFFGEN_GENERATE_HH
22 #define RFFGEN_GENERATE_HH
26 #include <type_traits>
28 #include "constant.hh"
29 #include "operations.hh"
30 #include "Util/addMissingOperators.hh"
31 #include "Util/base.hh"
32 #include "variable.hh"
39 namespace GenerateDetail
41 template <
class F,
class G,
42 bool = std::is_base_of<Base,F>::value,
43 bool = std::is_base_of<Base,G>::value>
46 template <
class F,
class G>
47 struct SumGenerator<F,G,true,true>
49 static auto apply(
const F& f,
const G& g)
51 return MathematicalOperations::Sum<F,G>(f,g);
55 template <
class F,
class G>
56 struct SumGenerator<F,G,true,false>
58 static auto apply(
const F& f,
const G& g)
60 return MathematicalOperations::Sum< F , Constant<G> >( f ,
constant(g) );
64 template <
class F,
class G>
65 struct SumGenerator<F,G,false,true>
67 static auto apply(
const F& f,
const G& g)
69 return MathematicalOperations::Sum< Constant<F> , G >(
constant(f) , g );
73 template <
class F,
class G,
74 bool = std::is_base_of<Base,F>::value,
75 bool = std::is_base_of<Base,G>::value,
76 bool = std::is_arithmetic<F>::value,
77 bool = std::is_arithmetic<G>::value>
78 struct ProductGenerator;
80 template <
class F,
class G>
81 struct ProductGenerator<F,G,true,true,false,false>
83 static auto apply(
const F& f,
const G& g)
85 return MathematicalOperations::Product<F,G>(f,g);
89 template <
class F,
class G>
90 struct ProductGenerator<F,G,false,true,true,false>
92 static auto apply(F f,
const G& g)
94 return MathematicalOperations::Scale<G>(f,g);
98 template <
class F,
class G>
99 struct ProductGenerator<F,G,true,false,false,true>
101 static auto apply(
const F& f, G g)
103 return ProductGenerator<G,F,false,true,true,false>(g,f);
107 template <
class F,
class G>
108 struct ProductGenerator<F,G,false,true,false,false>
110 static auto apply(
const F& f,
const G& g)
112 return MathematicalOperations::Product<Constant<F>,G>(Constant<F>(f),g);
116 template <
class F,
class G>
117 struct ProductGenerator<F,G,true,false,false,false>
119 static auto apply(
const F& f,
const G& g)
121 return MathematicalOperations::Product< F,Constant<G> >( f , Constant<G>(g) );
135 template <
class F,
class G,
136 class = std::enable_if_t< std::is_base_of<Base,F>::value ||
137 std::is_base_of<Base,G>::value > >
140 return GenerateDetail::SumGenerator<F,G>::apply(f,g);
149 template <
class F,
class G,
150 class = std::enable_if_t< std::is_base_of<Base,F>::value || std::is_base_of<Base,G>::value > >
153 return GenerateDetail::ProductGenerator<F,G>::apply(f,g);
164 class = std::enable_if_t< std::is_base_of<Base,F>::value > >
170 std::cerr <<
"operator^ only defined for k=2. Terminating." << std::endl;
183 template <
class F,
class G,
184 class = std::enable_if_t<std::is_base_of<Base,F>::value &&
185 std::is_base_of<Base,G>::value> >
188 static_assert(!Checks::hasVariable<F>(),
"Independent variables can not be on the left side of the chain operator.");
198 template <
class F,
class T,
199 class = std::enable_if_t<std::is_convertible<T,decltype(std::declval<F>().d0())>::value &&
200 std::is_base_of<Base,F>::value> >
201 auto operator-(
const F& f,
const T& t)
203 return f + ( -1 * t );
212 template <
class F,
class T,
213 class = std::enable_if_t<std::is_convertible<T,decltype(std::declval<F>().d0())>::value &&
214 std::is_base_of<Base,F>::value> >
215 auto operator-(
const T& t,
const F& f)
217 return t + ( -1 * f );
221 #endif // RFFGEN_GENERATE_HH
auto operator*(const F &f, const G &g)
overload of "*"-operator for the generation of functions.
Definition: generate.hh:151
auto operator^(const F &f, int k)
overload of "^"-operator for the generation of functions.
Definition: generate.hh:165
auto constant(const Arg &x)
Wrap a constant.
Definition: constant.hh:75
Chain of functions and of type F resp. G (F and G must satisfy the requirements of Concepts::Funct...
Definition: chain.hh:61
Squared function (F must satisfy the requirements of Concepts::FunctionConcept).
Definition: squared.hh:59
auto operator<<(const F &f, const G &g)
overload of "<<"-operator for chaining functions and to .
Definition: generate.hh:186
auto operator+(const F &f, const G &g)
overload of "+"-operator for the generation of functions.
Definition: generate.hh:138