CppAD: A C++ Algorithmic Differentiation Package  20171217
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
sinh_op.hpp
Go to the documentation of this file.
1 # ifndef CPPAD_LOCAL_SINH_OP_HPP
2 # define CPPAD_LOCAL_SINH_OP_HPP
3 
4 /* --------------------------------------------------------------------------
5 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
6 
7 CppAD is distributed under multiple licenses. This distribution is under
8 the terms of the
9  Eclipse Public License Version 1.0.
10 
11 A copy of this license is included in the COPYING file of this distribution.
12 Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
13 -------------------------------------------------------------------------- */
14 
15 
16 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
17 /*!
18 \file sinh_op.hpp
19 Forward and reverse mode calculations for z = sinh(x).
20 */
21 
22 
23 /*!
24 Compute forward mode Taylor coefficient for result of op = SinhOp.
25 
26 The C++ source code corresponding to this operation is
27 \verbatim
28  z = sinh(x)
29 \endverbatim
30 The auxillary result is
31 \verbatim
32  y = cosh(x)
33 \endverbatim
34 The value of y, and its derivatives, are computed along with the value
35 and derivatives of z.
36 
37 \copydetails CppAD::local::forward_unary2_op
38 */
39 template <class Base>
40 inline void forward_sinh_op(
41  size_t p ,
42  size_t q ,
43  size_t i_z ,
44  size_t i_x ,
45  size_t cap_order ,
46  Base* taylor )
47 {
48  // check assumptions
51  CPPAD_ASSERT_UNKNOWN( q < cap_order );
52  CPPAD_ASSERT_UNKNOWN( p <= q );
53 
54  // Taylor coefficients corresponding to argument and result
55  Base* x = taylor + i_x * cap_order;
56  Base* s = taylor + i_z * cap_order;
57  Base* c = s - cap_order;
58 
59 
60  // rest of this routine is identical for the following cases:
61  // forward_sin_op, forward_cos_op, forward_sinh_op, forward_cosh_op
62  // (except that there is a sign difference for hyperbolic case).
63  size_t k;
64  if( p == 0 )
65  { s[0] = sinh( x[0] );
66  c[0] = cosh( x[0] );
67  p++;
68  }
69  for(size_t j = p; j <= q; j++)
70  {
71  s[j] = Base(0.0);
72  c[j] = Base(0.0);
73  for(k = 1; k <= j; k++)
74  { s[j] += Base(double(k)) * x[k] * c[j-k];
75  c[j] += Base(double(k)) * x[k] * s[j-k];
76  }
77  s[j] /= Base(double(j));
78  c[j] /= Base(double(j));
79  }
80 }
81 /*!
82 Compute forward mode Taylor coefficient for result of op = SinhOp.
83 
84 The C++ source code corresponding to this operation is
85 \verbatim
86  z = sinh(x)
87 \endverbatim
88 The auxillary result is
89 \verbatim
90  y = cosh(x)
91 \endverbatim
92 The value of y, and its derivatives, are computed along with the value
93 and derivatives of z.
94 
95 \copydetails CppAD::local::forward_unary2_op_dir
96 */
97 template <class Base>
98 inline void forward_sinh_op_dir(
99  size_t q ,
100  size_t r ,
101  size_t i_z ,
102  size_t i_x ,
103  size_t cap_order ,
104  Base* taylor )
105 {
106  // check assumptions
109  CPPAD_ASSERT_UNKNOWN( 0 < q );
110  CPPAD_ASSERT_UNKNOWN( q < cap_order );
111 
112  // Taylor coefficients corresponding to argument and result
113  size_t num_taylor_per_var = (cap_order-1) * r + 1;
114  Base* x = taylor + i_x * num_taylor_per_var;
115  Base* s = taylor + i_z * num_taylor_per_var;
116  Base* c = s - num_taylor_per_var;
117 
118 
119  // rest of this routine is identical for the following cases:
120  // forward_sin_op, forward_cos_op, forward_sinh_op, forward_cosh_op
121  // (except that there is a sign difference for the hyperbolic case).
122  size_t m = (q-1) * r + 1;
123  for(size_t ell = 0; ell < r; ell++)
124  { s[m+ell] = Base(double(q)) * x[m + ell] * c[0];
125  c[m+ell] = Base(double(q)) * x[m + ell] * s[0];
126  for(size_t k = 1; k < q; k++)
127  { s[m+ell] += Base(double(k)) * x[(k-1)*r+1+ell] * c[(q-k-1)*r+1+ell];
128  c[m+ell] += Base(double(k)) * x[(k-1)*r+1+ell] * s[(q-k-1)*r+1+ell];
129  }
130  s[m+ell] /= Base(double(q));
131  c[m+ell] /= Base(double(q));
132  }
133 }
134 
135 /*!
136 Compute zero order forward mode Taylor coefficient for result of op = SinhOp.
137 
138 The C++ source code corresponding to this operation is
139 \verbatim
140  z = sinh(x)
141 \endverbatim
142 The auxillary result is
143 \verbatim
144  y = cosh(x)
145 \endverbatim
146 The value of y is computed along with the value of z.
147 
148 \copydetails CppAD::local::forward_unary2_op_0
149 */
150 template <class Base>
151 inline void forward_sinh_op_0(
152  size_t i_z ,
153  size_t i_x ,
154  size_t cap_order ,
155  Base* taylor )
156 {
157  // check assumptions
160  CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
161 
162  // Taylor coefficients corresponding to argument and result
163  Base* x = taylor + i_x * cap_order;
164  Base* s = taylor + i_z * cap_order; // called z in documentation
165  Base* c = s - cap_order; // called y in documentation
166 
167  s[0] = sinh( x[0] );
168  c[0] = cosh( x[0] );
169 }
170 /*!
171 Compute reverse mode partial derivatives for result of op = SinhOp.
172 
173 The C++ source code corresponding to this operation is
174 \verbatim
175  z = sinh(x)
176 \endverbatim
177 The auxillary result is
178 \verbatim
179  y = cosh(x)
180 \endverbatim
181 The value of y is computed along with the value of z.
182 
183 \copydetails CppAD::local::reverse_unary2_op
184 */
185 
186 template <class Base>
187 inline void reverse_sinh_op(
188  size_t d ,
189  size_t i_z ,
190  size_t i_x ,
191  size_t cap_order ,
192  const Base* taylor ,
193  size_t nc_partial ,
194  Base* partial )
195 {
196  // check assumptions
199  CPPAD_ASSERT_UNKNOWN( d < cap_order );
200  CPPAD_ASSERT_UNKNOWN( d < nc_partial );
201 
202  // Taylor coefficients and partials corresponding to argument
203  const Base* x = taylor + i_x * cap_order;
204  Base* px = partial + i_x * nc_partial;
205 
206  // Taylor coefficients and partials corresponding to first result
207  const Base* s = taylor + i_z * cap_order; // called z in doc
208  Base* ps = partial + i_z * nc_partial;
209 
210  // Taylor coefficients and partials corresponding to auxillary result
211  const Base* c = s - cap_order; // called y in documentation
212  Base* pc = ps - nc_partial;
213 
214 
215  // rest of this routine is identical for the following cases:
216  // reverse_sin_op, reverse_cos_op, reverse_sinh_op, reverse_cosh_op.
217  size_t j = d;
218  size_t k;
219  while(j)
220  {
221  ps[j] /= Base(double(j));
222  pc[j] /= Base(double(j));
223  for(k = 1; k <= j; k++)
224  {
225  px[k] += Base(double(k)) * azmul(ps[j], c[j-k]);
226  px[k] += Base(double(k)) * azmul(pc[j], s[j-k]);
227 
228  ps[j-k] += Base(double(k)) * azmul(pc[j], x[k]);
229  pc[j-k] += Base(double(k)) * azmul(ps[j], x[k]);
230 
231  }
232  --j;
233  }
234  px[0] += azmul(ps[0], c[0]);
235  px[0] += azmul(pc[0], s[0]);
236 }
237 
238 } } // END_CPPAD_LOCAL_NAMESPACE
239 # endif
AD< Base > cosh(const AD< Base > &x)
AD< Base > azmul(const AD< Base > &x, const AD< Base > &y)
Definition: azmul.hpp:94
void forward_sinh_op_0(size_t i_z, size_t i_x, size_t cap_order, Base *taylor)
Compute zero order forward mode Taylor coefficient for result of op = SinhOp.
Definition: sinh_op.hpp:151
AD< Base > sinh(const AD< Base > &x)
size_t NumArg(OpCode op)
Number of arguments for a specified operator.
Definition: op_code.hpp:175
size_t NumRes(OpCode op)
Number of variables resulting from the specified operation.
Definition: op_code.hpp:281
#define CPPAD_ASSERT_UNKNOWN(exp)
Check that exp is true, if not terminate execution.
void forward_sinh_op(size_t p, size_t q, size_t i_z, size_t i_x, size_t cap_order, Base *taylor)
Compute forward mode Taylor coefficient for result of op = SinhOp.
Definition: sinh_op.hpp:40
void forward_sinh_op_dir(size_t q, size_t r, size_t i_z, size_t i_x, size_t cap_order, Base *taylor)
Compute forward mode Taylor coefficient for result of op = SinhOp.
Definition: sinh_op.hpp:98
void reverse_sinh_op(size_t d, size_t i_z, size_t i_x, size_t cap_order, const Base *taylor, size_t nc_partial, Base *partial)
Compute reverse mode partial derivatives for result of op = SinhOp.
Definition: sinh_op.hpp:187