RFFGen
 All Classes Namespaces Files Functions Typedefs Enumerations Groups
exp.hh
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the C++-library RFFGen. */
4 /* Copyright 2015 Lars Lubkoll */
5 /* */
6 /* RFFGen is free software: you can redistribute it and/or modify */
7 /* it under the terms of the GNU General Public License as published by */
8 /* the Free Software Foundation, either version 3 of the License, or */
9 /* (at your option) any later version. */
10 /* */
11 /* RFFGen is distributed in the hope that it will be useful, */
12 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
13 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
14 /* GNU General Public License for more details. */
15 /* */
16 /* You should have received a copy of the GNU General Public License */
17 /* along with RFFGen. If not, see <http://www.gnu.org/licenses/>. */
18 /* */
19 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
20 
21 #ifndef RFFGEN_CMATH_EXP_HH
22 #define RFFGEN_CMATH_EXP_HH
23 
24 #include <cmath>
25 #include "../Util/base.hh"
26 #include "../Util/chainer.hh"
27 
28 namespace RFFGen
29 {
30  namespace CMath
31  {
40  struct Exp : Base , Chainer<Exp>
41  {
42  using Chainer<Exp>::operator ();
47  explicit Exp(double x=0.) { update(x); }
48 
50  void update(double x)
51  {
52  e_x = ::exp(x);
53  }
54 
56  double d0() const noexcept
57  {
58  return e_x;
59  }
60 
62  template < int = -1 >
63  double d1(double dx = 1.) const
64  {
65  return e_x * dx;
66  }
67 
69  template < int = -1 , int = -1 >
70  double d2(double dx = 1., double dy = 1.) const
71  {
72  return e_x * dx * dy;
73  }
74 
76  template < int = -1 , int = -1 , int = -1 >
77  double d3(double dx = 1., double dy = 1., double dz = 1.) const
78  {
79  return e_x * dx * dy * dz;
80  }
81 
82  private:
83  double e_x = 1.;
84  };
85 
94  struct Exp2 : Base , Chainer<Exp2>
95  {
96  using Chainer<Exp2>::operator ();
101  explicit Exp2(double x=0.) { update(x); }
102 
104  void update(double x)
105  {
106  value = exp2(x);
107  }
108 
110  double d0() const noexcept
111  {
112  return value;
113  }
114 
116  template < int = -1 >
117  double d1(double dx = 1.) const
118  {
119  return value * ln2 * dx;
120  }
121 
123  template < int = -1 , int = -1 >
124  double d2(double dx = 1., double dy = 1.) const
125  {
126  return value * ln2 * ln2 * dx * dy;
127  }
128 
130  template < int = -1 , int = -1 , int = -1 >
131  double d3(double dx = 1., double dy = 1., double dz = 1.) const
132  {
133  return value * ln2 * ln2 * ln2 * dx * dy * dz;
134  }
135 
136  private:
137  double value = 1., ln2 = log(2.);
138  };
139 
144  template <class Function, class = std::enable_if_t<std::is_base_of<Base,Function>::value> >
145  auto exp(const Function& f)
146  {
147  return Exp()(f);
148  }
149 
154  template <class Function, class = std::enable_if_t<std::is_base_of<Base,Function>::value> >
155  auto ex2p(const Function& f)
156  {
157  return Exp2()(f);
158  }
159  }
160 }
161 
162 #endif // RFFGEN_CMATH_EXP_HH
double d3(double dx=1., double dy=1., double dz=1.) const
Third (directional) derivative.
Definition: exp.hh:131
Function including first three derivatives.
Definition: exp.hh:94
void update(double x)
Reset point of evaluation.
Definition: exp.hh:104
double d1(double dx=1.) const
First (directional) derivative.
Definition: exp.hh:117
Base class for functions satisfying FunctionConcept. Required for enabling the operators in generate...
Definition: base.hh:27
Exp2(double x=0.)
Constructor.
Definition: exp.hh:101
double d0() const noexcept
Function value.
Definition: exp.hh:56
Exponential function including first three derivatives.
Definition: exp.hh:40
double d2(double dx=1., double dy=1.) const
Second (directinal) derivative.
Definition: exp.hh:70
Exp(double x=0.)
Constructor.
Definition: exp.hh:47
double d3(double dx=1., double dy=1., double dz=1.) const
Third (directional) derivative.
Definition: exp.hh:77
double d1(double dx=1.) const
First (directional) derivative.
Definition: exp.hh:63
void update(double x)
Reset point of evaluation.
Definition: exp.hh:50
double d0() const noexcept
Function value.
Definition: exp.hh:110
double d2(double dx=1., double dy=1.) const
Second (directinal) derivative.
Definition: exp.hh:124