RFFGen
 All Classes Namespaces Files Functions Typedefs Enumerations Groups
arcsine.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_ARCSINE_HH
22 #define RFFGEN_CMATH_ARCSINE_HH
23 
24 #include <cmath>
25 #include "../Util/base.hh"
26 #include "../Util/chainer.hh"
27 #include "../Util/exceptions.hh"
28 
29 namespace RFFGen
30 {
31  namespace CMath
32  {
41  struct ASin : Base , Chainer<ASin>
42  {
43  using Chainer<ASin>::operator ();
48  explicit ASin(double x=0.)
49  {
50  update(x);
51  }
52 
54  void update(double x)
55  {
56 #ifdef RFFGEN_ENABLE_EXCEPTIONS
57  if( x < -1 || x > 1 ) throw OutOfDomainException("ASin","[-1,1]",x,__FILE__,__LINE__);
58 #endif
59  value = ::asin(x);
60  firstDerivative = 1/::sqrt(1-(x*x));
61  firstDerivative3 = firstDerivative * firstDerivative * firstDerivative;
62  x_ = x;
63  }
64 
66  double d0() const noexcept
67  {
68  return value;
69  }
70 
72  template < int = -1 >
73  double d1(double dx=1) const
74  {
75  return firstDerivative * dx;
76  }
77 
79  template < int = -1 , int = -1 >
80  double d2(double dx=1, double dy=1) const
81  {
82  return x_ * firstDerivative3 * dx * dy;
83  }
84 
86  template < int = -1 , int = -1 , int = -1>
87  double d3(double dx=1, double dy=1, double dz=1) const
88  {
89  return firstDerivative3 * ( 1 + ( 3 * x_ * x_ /(firstDerivative*firstDerivative) ) ) * dx * dy * dz;
90  }
91 
92  private:
93  double value = 0., firstDerivative = 1., firstDerivative3 = 1., x_ = 0.;
94  };
95 
100  template <class Function, class = std::enable_if_t<std::is_base_of<Base,Function>::value> >
101  auto asin(const Function& f)
102  {
103  return ASin()(f);
104  }
105  }
106 }
107 
108 #endif // RFFGEN_CMATH_ARCSINE_HH
double d1(double dx=1) const
First (directional) derivative.
Definition: arcsine.hh:73
Base class for functions satisfying FunctionConcept. Required for enabling the operators in generate...
Definition: base.hh:27
Sine function including first three derivatives (based on sin(double) in <cmath>).
Definition: arcsine.hh:41
ASin(double x=0.)
Constructor.
Definition: arcsine.hh:48
Exception for scalar function arguments that are outside the domain of the function.
Definition: exceptions.hh:40
double d2(double dx=1, double dy=1) const
Second (directional) derivative.
Definition: arcsine.hh:80
double d3(double dx=1, double dy=1, double dz=1) const
Third (directional) derivative.
Definition: arcsine.hh:87
void update(double x)
Reset point of evaluation.
Definition: arcsine.hh:54
double d0() const noexcept
Function value.
Definition: arcsine.hh:66