Code-Eli  0.3.6
dual_operators.hpp
Go to the documentation of this file.
1 /*********************************************************************************
2 * Copyright (c) 2013 David D. Marshall <ddmarsha@calpoly.edu>
3 *
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * David D. Marshall - initial code and implementation
11 ********************************************************************************/
12 
13 #ifndef eli_mutil_ad_dual_operators_hpp
14 #define eli_mutil_ad_dual_operators_hpp
15 
16 #include "eli/code_eli.hpp"
17 
18 #include "eli/util/traits.hpp"
19 
21 
22 //
23 // start add operation
24 //
25 namespace eli
26 {
27  namespace mutil
28  {
29  namespace ad
30  {
31  namespace dual_number
32  {
33  template <typename left__, typename right__>
34  class add
35  {
36  public:
37  typedef typename left__::data_type left_data_type;
38  typedef typename right__::data_type right_data_type;
40 
41  private:
44 
45  public:
46  add(const left__ &l, const right__ &r) : l_val(l), r_val(r) {}
47 
48  data_type real() const
49  {
50  return l_val.real()+r_val.real();
51  }
52 
53  data_type nonreal() const
54  {
55  return l_val.nonreal()+r_val.nonreal();
56  }
57  };
58  }
59  }
60  }
61 }
62 
63 // dual + dual
64 template <typename left__, typename right__, bool comp_real_only>
68 {
71 
73 }
74 
75 // dual + constant
76 template <typename left__, typename right__, bool comp_real_only>
80 {
83 
85 }
86 
87 // constant + dual
88 template <typename left__, typename right__, bool comp_real_only>
92 {
95 
97 }
98 
99 // expression + dual
100 template <typename left__, typename right__, bool comp_real_only>
104 {
107 
109 }
110 
111 // dual + expression
112 template <typename left__, typename right__, bool comp_real_only>
116 {
119 
121 }
122 
123 // expression + constant
124 template <typename left__, typename right__, bool comp_real_only>
128 {
131 
133 }
134 
135 // constant + expression
136 template <typename left__, typename right__, bool comp_real_only>
140 {
143 
145 }
146 
147 // expression + expression
148 template <typename left__, typename right__, bool comp_real_only>
152 {
155 
157 }
158 //
159 // end add operation
160 //
161 
162 //
163 // start subtract operation
164 //
165 namespace eli
166 {
167  namespace mutil
168  {
169  namespace ad
170  {
171  namespace dual_number
172  {
173  template <typename left__, typename right__>
174  class subtract
175  {
176  public:
177  typedef typename left__::data_type left_data_type;
178  typedef typename right__::data_type right_data_type;
180 
181  private:
184 
185  public:
186  subtract(const left__ &l, const right__ &r) : l_val(l), r_val(r) {}
187 
188  data_type real() const
189  {
190  return l_val.real()-r_val.real();
191  }
192 
193  data_type nonreal() const
194  {
195  return l_val.nonreal()-r_val.nonreal();
196  }
197  };
198  }
199  }
200  }
201 }
202 
203 // dual - dual
204 template <typename left__, typename right__, bool comp_real_only>
208 {
211 
213 }
214 
215 // dual - constant
216 template <typename left__, typename right__, bool comp_real_only>
220 {
223 
225 }
226 
227 // constant - dual
228 template <typename left__, typename right__, bool comp_real_only>
232 {
235 
237 }
238 
239 // expression - dual
240 template <typename left__, typename right__, bool comp_real_only>
244 {
247 
249 }
250 
251 // dual - expression
252 template <typename left__, typename right__, bool comp_real_only>
256 {
259 
261 }
262 
263 // expression - constant
264 template <typename left__, typename right__, bool comp_real_only>
268 {
271 
273 }
274 
275 // constant - expression
276 template <typename left__, typename right__, bool comp_real_only>
280 {
283 
285 }
286 
287 // expression - expression
288 template <typename left__, typename right__, bool comp_real_only>
292 {
295 
297 }
298 //
299 // end subtract operation
300 //
301 
302 //
303 // start multiply operation
304 //
305 namespace eli
306 {
307  namespace mutil
308  {
309  namespace ad
310  {
311  namespace dual_number
312  {
313  template <typename left__, typename right__>
314  class multiply
315  {
316  public:
317  typedef typename left__::data_type left_data_type;
318  typedef typename right__::data_type right_data_type;
320 
321  private:
324 
325  public:
326  multiply(const left__ &l, const right__ &r) : l_val(l), r_val(r) {}
327 
328  data_type real() const
329  {
330  return l_val.real()*r_val.real();
331  }
332 
333  data_type nonreal() const
334  {
335  return l_val.real()*r_val.nonreal()+l_val.nonreal()*r_val.real();
336  }
337  };
338  }
339  }
340  }
341 }
342 
343 // dual * dual
344 template <typename left__, typename right__, bool comp_real_only>
348 {
351 
353 }
354 
355 // dual * constant
356 template <typename left__, typename right__, bool comp_real_only>
360 {
363 
365 }
366 
367 // constant * dual
368 template <typename left__, typename right__, bool comp_real_only>
372 {
375 
377 }
378 
379 // expression * dual
380 template <typename left__, typename right__, bool comp_real_only>
384 {
387 
389 }
390 
391 // dual * expression
392 template <typename left__, typename right__, bool comp_real_only>
396 {
399 
401 }
402 
403 // expression * constant
404 template <typename left__, typename right__, bool comp_real_only>
408 {
411 
413 }
414 
415 // constant * expression
416 template <typename left__, typename right__, bool comp_real_only>
420 {
423 
425 }
426 
427 // expression * expression
428 template <typename left__, typename right__, bool comp_real_only>
432 {
435 
437 }
438 //
439 // end multiply operation
440 //
441 
442 //
443 // start divide operation
444 //
445 namespace eli
446 {
447  namespace mutil
448  {
449  namespace ad
450  {
451  namespace dual_number
452  {
453  template <typename left__, typename right__>
454  class divide
455  {
456  public:
457  typedef typename left__::data_type left_data_type;
458  typedef typename right__::data_type right_data_type;
460 
461  private:
464 
465  public:
466  divide(const left__ &l, const right__ &r) : l_val(l), r_val(r) {}
467 
468  data_type real() const
469  {
470  return l_val.real()/r_val.real();
471  }
472 
473  data_type nonreal() const
474  {
475  right_data_type c(r_val.real());
476  return (l_val.nonreal()*c-l_val.real()*r_val.nonreal())/c/c;
477  }
478  };
479  }
480  }
481  }
482 }
483 
484 // dual / dual
485 template <typename left__, typename right__, bool comp_real_only>
489 {
492 
494 }
495 
496 // dual / constant
497 template <typename left__, typename right__, bool comp_real_only>
501 {
504 
506 }
507 
508 // constant / dual
509 template <typename left__, typename right__, bool comp_real_only>
513 {
516 
518 }
519 
520 // expression / dual
521 template <typename left__, typename right__, bool comp_real_only>
525 {
528 
530 }
531 
532 // dual / expression
533 template <typename left__, typename right__, bool comp_real_only>
537 {
540 
542 }
543 
544 // expression / constant
545 template <typename left__, typename right__, bool comp_real_only>
549 {
552 
554 }
555 
556 // constant / expression
557 template <typename left__, typename right__, bool comp_real_only>
561 {
564 
566 }
567 
568 // expression / expression
569 template <typename left__, typename right__, bool comp_real_only>
573 {
576 
578 }
579 //
580 // end divide operation
581 //
582 #endif
Definition: math.hpp:20
eli::util::traits< left__ >::const_expr_ref l_val
Definition: dual_operators.hpp:322
eli::util::traits< right__ >::const_expr_ref r_val
Definition: dual_operators.hpp:183
Definition: dual_number.hpp:55
eli::util::traits< left__ >::const_expr_ref l_val
Definition: dual_operators.hpp:42
data_type nonreal() const
Definition: dual_operators.hpp:473
eli::util::promote_traits< left_data_type, right_data_type >::promote_t data_type
Definition: dual_operators.hpp:459
right__::data_type right_data_type
Definition: dual_operators.hpp:38
eli::util::promote_traits< left_data_type, right_data_type >::promote_t data_type
Definition: dual_operators.hpp:319
subtract(const left__ &l, const right__ &r)
Definition: dual_operators.hpp:186
eli::mutil::ad::dual_number::expression< eli::mutil::ad::dual_number::subtract< eli::mutil::ad::dual< left__, comp_real_only >, eli::mutil::ad::dual< right__, comp_real_only > >, comp_real_only > operator-(const eli::mutil::ad::dual< left__, comp_real_only > &l, const eli::mutil::ad::dual< right__, comp_real_only > &r)
Definition: dual_operators.hpp:207
eli::util::traits< right__ >::const_expr_ref r_val
Definition: dual_operators.hpp:43
Definition: dual_number.hpp:36
left__::data_type left_data_type
Definition: dual_operators.hpp:177
Definition: traits.hpp:51
left__::data_type left_data_type
Definition: dual_operators.hpp:317
eli::util::traits< left__ >::const_expr_ref l_val
Definition: dual_operators.hpp:182
data_type real() const
Definition: dual_operators.hpp:468
data_type nonreal() const
Definition: dual_operators.hpp:53
eli::mutil::ad::dual_number::expression< eli::mutil::ad::dual_number::add< eli::mutil::ad::dual< left__, comp_real_only >, eli::mutil::ad::dual< right__, comp_real_only > >, comp_real_only > operator+(const eli::mutil::ad::dual< left__, comp_real_only > &l, const eli::mutil::ad::dual< right__, comp_real_only > &r)
Definition: dual_operators.hpp:67
eli::mutil::ad::dual_number::expression< eli::mutil::ad::dual_number::divide< eli::mutil::ad::dual< left__, comp_real_only >, eli::mutil::ad::dual< right__, comp_real_only > >, comp_real_only > operator/(const eli::mutil::ad::dual< left__, comp_real_only > &l, const eli::mutil::ad::dual< right__, comp_real_only > &r)
Definition: dual_operators.hpp:488
eli::util::traits< right__ >::const_expr_ref r_val
Definition: dual_operators.hpp:323
divide(const left__ &l, const right__ &r)
Definition: dual_operators.hpp:466
right__::data_type right_data_type
Definition: dual_operators.hpp:318
right__::data_type right_data_type
Definition: dual_operators.hpp:458
data_type nonreal() const
Definition: dual_operators.hpp:333
eli::util::promote_traits< left_data_type, right_data_type >::promote_t data_type
Definition: dual_operators.hpp:39
data_type real() const
Definition: dual_operators.hpp:328
const data__ & const_expr_ref
Definition: traits.hpp:45
Definition: dual_operators.hpp:174
data_type real() const
Definition: dual_operators.hpp:48
Definition: dual_number.hpp:28
data_type real() const
Definition: dual_operators.hpp:188
eli::util::traits< right__ >::const_expr_ref r_val
Definition: dual_operators.hpp:463
multiply(const left__ &l, const right__ &r)
Definition: dual_operators.hpp:326
add(const left__ &l, const right__ &r)
Definition: dual_operators.hpp:46
Definition: dual_operators.hpp:454
right__::data_type right_data_type
Definition: dual_operators.hpp:178
Definition: dual_operators.hpp:34
left__::data_type left_data_type
Definition: dual_operators.hpp:457
eli::util::traits< left__ >::const_expr_ref l_val
Definition: dual_operators.hpp:462
data_type nonreal() const
Definition: dual_operators.hpp:193
Definition: dual_operators.hpp:314
eli::mutil::ad::dual_number::expression< eli::mutil::ad::dual_number::multiply< eli::mutil::ad::dual< left__, comp_real_only >, eli::mutil::ad::dual< right__, comp_real_only > >, comp_real_only > operator*(const eli::mutil::ad::dual< left__, comp_real_only > &l, const eli::mutil::ad::dual< right__, comp_real_only > &r)
Definition: dual_operators.hpp:347
eli::util::promote_traits< left_data_type, right_data_type >::promote_t data_type
Definition: dual_operators.hpp:179
left__::data_type left_data_type
Definition: dual_operators.hpp:37