21 #ifndef RFFGEN_MATHEMATICAL_OPERATIONS_SUM_HH
22 #define RFFGEN_MATHEMATICAL_OPERATIONS_SUM_HH
24 #include <type_traits>
27 #include "../Util/base.hh"
28 #include "../Util/computeSum.hh"
29 #include "../Util/derivativeWrappers.hh"
30 #include "../Util/indexedType.hh"
37 template <
class>
struct Chainer;
42 namespace MathematicalOperations
47 template <
class>
struct FunctionConceptCheck;
57 template <
class F,
class G,
58 class CheckF = FunctionConceptCheck<F> ,
59 class CheckG = FunctionConceptCheck<G> >
60 struct Sum :
Base , Chainer< Sum<F,G,CheckF,CheckG> >
62 using Chainer< Sum<F,G,CheckF,CheckG> >::operator ();
70 template <
class InitF,
class InitG>
71 Sum(
const InitF& f_,
const InitG& g_)
87 template <
int index,
class Arg>
90 f.template updateVariable<index>(x);
91 g.template updateVariable<index>(x);
95 const auto&
d0() const noexcept
104 template <
int id ,
class Arg ,
105 class IndexedArg = IndexedType<Arg,id> ,
106 class = std::enable_if_t< ComputeSum< D1<F,IndexedArg>, D1<G,IndexedArg> >::present > >
107 auto d1(
const Arg& dx)
const
109 return ComputeSum< D1<F,IndexedArg>, D1<G,IndexedArg> >( f,g,dx )();
117 template <
int idx ,
int idy ,
class ArgX ,
class ArgY ,
118 class IndexedArgX = IndexedType<ArgX,idx> ,
119 class IndexedArgY = IndexedType<ArgY,idy> ,
120 class = std::enable_if_t< ComputeSum< D2<F,IndexedArgX,IndexedArgY>, D2<G,IndexedArgX,IndexedArgY> >::present > >
121 auto d2(
const ArgX& dx,
const ArgY& dy)
const
123 return ComputeSum< D2<F,IndexedArgX,IndexedArgY>, D2<G,IndexedArgX,IndexedArgY> >( f,g,dx,dy )();
132 template <
int idx ,
int idy ,
int idz ,
class ArgX,
class ArgY,
class ArgZ ,
133 class IndexedArgX = IndexedType<ArgX,idx> ,
134 class IndexedArgY = IndexedType<ArgY,idy> ,
135 class IndexedArgZ = IndexedType<ArgZ,idz> ,
136 class = std::enable_if_t< ComputeSum< D3<F,IndexedArgX,IndexedArgY,IndexedArgZ>, D3<G,IndexedArgX,IndexedArgY,IndexedArgZ> >::present > >
137 auto d3(
const ArgX& dx,
const ArgY& dy,
const ArgZ& dz)
const
139 return ComputeSum< D3<F,IndexedArgX,IndexedArgY,IndexedArgZ>, D3<G,IndexedArgX,IndexedArgY,IndexedArgZ> >( f,g,dx,dy,dz )();
143 void updateResultOfD0()
145 resultOfD0 = f.d0() + g.d0();
151 using type = std::conditional_t<std::is_same<decltype(std::declval<F>().
d0()),decltype(std::declval<G>().d0())>::value,
152 decltype(std::declval<F>().d0()),
153 decltype(std::declval<F>().d0() + std::declval<G>().
d0())>;
154 std::decay_t<type> resultOfD0;
159 #endif // RFFGEN_MATHEMATICAL_OPERATIONS_SUM_HH
void update(Arg const &x)
Reset point of evaluation.
Definition: sum.hh:79
auto d3(const ArgX &dx, const ArgY &dy, const ArgZ &dz) const
Third directional derivative.
Definition: sum.hh:137
Sum(const InitF &f_, const InitG &g_)
Constructor passing arguments to function constructors.
Definition: sum.hh:71
auto d2(const ArgX &dx, const ArgY &dy) const
Second directional derivative.
Definition: sum.hh:121
auto d1(const Arg &dx) const
First directional derivative.
Definition: sum.hh:107
Base class for functions satisfying FunctionConcept. Required for enabling the operators in generate...
Definition: base.hh:27
Sum of functions of type F and G (F and G must satisfy the requirements of Concepts::FunctionConcept)...
Definition: sum.hh:60
const auto & d0() const noexcept
Function value.
Definition: sum.hh:95
void updateVariable(const Arg &x)
Propagate call to updateVariable() to f and g.
Definition: sum.hh:88