21 #ifndef RFFGEN_MATHEMATICAL_OPERATIONS_SQUARED_HH
22 #define RFFGEN_MATHEMATICAL_OPERATIONS_SQUARED_HH
24 #include <type_traits>
27 #include "../Util/base.hh"
28 #include "../Util/computeSum.hh"
29 #include "../Util/computeProduct.hh"
30 #include "../Util/derivativeWrappers.hh"
31 #include "../Util/indexedType.hh"
38 template <
class>
struct Chainer;
43 namespace MathematicalOperations
48 template <
class>
struct FunctionConceptCheck;
58 template <
class F,
class = FunctionConceptCheck<F> >
59 struct Squared :
Base , Chainer< Squared< F , FunctionConceptCheck<F> > >
61 using Chainer< Squared< F , FunctionConceptCheck<F> > >::operator();
63 template <
class IndexedArgX ,
class IndexedArgY >
64 using D2Sum = ComputeSum< ComputeProduct< D0<F> , D2<F,IndexedArgX,IndexedArgY> >,
65 ComputeProduct< D1<F,IndexedArgY> , D1<F,IndexedArgX> > >;
67 template <
class IndexedArgX ,
class IndexedArgY ,
class IndexedArgZ >
68 using D3Sum = ComputeSum< ComputeProduct< D0<F> , D3<F,IndexedArgX,IndexedArgY,IndexedArgZ> > ,
69 ComputeProduct< D1<F,IndexedArgZ> , D2<F,IndexedArgX,IndexedArgY> > ,
70 ComputeProduct< D1<F,IndexedArgY> , D2<F,IndexedArgX,IndexedArgZ> > ,
71 ComputeProduct< D2<F,IndexedArgY,IndexedArgZ> , D1<F,IndexedArgX> > >;
81 template <
class InitF>
97 template <
int index,
class Arg>
100 f.template updateVariable<index>(x);
104 const auto&
d0() const noexcept
113 template <
int id ,
class Arg ,
class IndexedArg = IndexedType<Arg,
id> ,
class = std::enable_if_t< ComputeProduct< D0<F> , D1<F,IndexedArg> >::present > >
114 auto d1(Arg
const& dx)
const
116 return 2 * f.d0() * f.template d1<id>(dx);
124 template <
int idx ,
int idy ,
class ArgX ,
class ArgY ,
125 class IndexedArgX = IndexedType<ArgX,idx> ,
126 class IndexedArgY = IndexedType<ArgY,idy> ,
127 class = std::enable_if_t< D2Sum<IndexedArgX,IndexedArgY>::present > >
128 auto d2(ArgX
const& dx, ArgY
const& dy)
const
130 return 2 * D2Sum<IndexedArgX,IndexedArgY>( ComputeProduct< D0<F> , D2<F,IndexedArgX,IndexedArgY> >( D0<F>(f) , D2<F,IndexedArgX,IndexedArgY>(f,dx,dy) ),
131 ComputeProduct< D1<F,IndexedArgY> , D1<F,IndexedArgX> >( D1<F,IndexedArgY>(f,dy) , D1<F,IndexedArgX>(f,dx) )
141 template <
int idx ,
int idy ,
int idz ,
class ArgX ,
class ArgY ,
class ArgZ ,
142 class IndexedArgX = IndexedType<ArgX,idx> ,
143 class IndexedArgY = IndexedType<ArgY,idy> ,
144 class IndexedArgZ = IndexedType<ArgZ,idz> ,
145 class = std::enable_if_t< D3Sum<IndexedArgX,IndexedArgY,IndexedArgZ>::present > >
146 auto d3(ArgX
const& dx, ArgY
const& dy, ArgZ
const& dz)
const
148 return 2 * D3Sum<IndexedArgX,IndexedArgY,IndexedArgZ>
149 ( ComputeProduct< D0<F> , D3<F,IndexedArgX,IndexedArgY,IndexedArgZ> > ( D0<F>(f) , D3<F,IndexedArgX,IndexedArgY,IndexedArgZ>(f,dx,dy,dz) ),
150 ComputeProduct< D1<F,IndexedArgZ> , D2<F,IndexedArgX,IndexedArgY> > ( D1<F,IndexedArgZ>(f,dz) , D2<F,IndexedArgX,IndexedArgY>(f,dx,dy) ),
151 ComputeProduct< D1<F,IndexedArgY> , D2<F,IndexedArgX,IndexedArgZ> > ( D1<F,IndexedArgY>(f,dy) , D2<F,IndexedArgX,IndexedArgZ>(f,dx,dz) ),
152 ComputeProduct< D2<F,IndexedArgY,IndexedArgZ> , D1<F,IndexedArgX> > ( D2<F,IndexedArgY,IndexedArgZ>(f,dy,dz) , D1<F,IndexedArgX>(f,dx) )
157 void updateResultOfD0()
159 resultOfD0 = f.d0() * f.d0();
163 std::remove_const_t<std::remove_reference_t<decltype(std::declval<F>().
d0())> > resultOfD0;
168 #endif // RFFGEN_MATHEMATICAL_OPERATIONS_SQUARED_HH
void update(Arg const &x)
Reset point of evaluation.
Definition: squared.hh:90
auto d2(ArgX const &dx, ArgY const &dy) const
Second directional derivative.
Definition: squared.hh:128
Base class for functions satisfying FunctionConcept. Required for enabling the operators in generate...
Definition: base.hh:27
Squared function (F must satisfy the requirements of Concepts::FunctionConcept).
Definition: squared.hh:59
auto d3(ArgX const &dx, ArgY const &dy, ArgZ const &dz) const
Third directional derivative.
Definition: squared.hh:146
Squared(const InitF &f_)
Constructor passing arguments to function constructor.
Definition: squared.hh:82
void updateVariable(const Arg &x)
Propagate call to updateVariable() to f.
Definition: squared.hh:98
auto d1(Arg const &dx) const
First directional derivative.
Definition: squared.hh:114
const auto & d0() const noexcept
Function value.
Definition: squared.hh:104
Squared()=default
Default constructor. May leave member variables uninitialized! Call update before using evaluation...