CppAD: A C++ Algorithmic Differentiation Package  20171217
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
unary_minus.hpp
Go to the documentation of this file.
1 # ifndef CPPAD_CORE_UNARY_MINUS_HPP
2 # define CPPAD_CORE_UNARY_MINUS_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 $begin UnaryMinus$$
17 $spell
18  Vec
19  const
20  inline
21 $$
22 
23 
24 $section AD Unary Minus Operator$$
25 $mindex -$$
26 
27 $head Syntax$$
28 
29 $icode%y% = - %x%$$
30 
31 
32 $head Purpose$$
33 Computes the negative of $icode x$$.
34 
35 $head Base$$
36 The operation in the syntax above must be supported for the case where
37 the operand is a $code const$$ $icode Base$$ object.
38 
39 $head x$$
40 The operand $icode x$$ has one of the following prototypes
41 $codei%
42  const AD<%Base%> &%x%
43  const VecAD<%Base%>::reference &%x%
44 %$$
45 
46 $head y$$
47 The result $icode y$$ has type
48 $codei%
49  AD<%Base%> %y%
50 %$$
51 It is equal to the negative of the operand $icode x$$.
52 
53 $head Operation Sequence$$
54 This is an AD of $icode Base$$
55 $cref/atomic operation/glossary/Operation/Atomic/$$
56 and hence is part of the current
57 AD of $icode Base$$
58 $cref/operation sequence/glossary/Operation/Sequence/$$.
59 
60 $head Derivative$$
61 If $latex f$$ is a
62 $cref/Base function/glossary/Base Function/$$,
63 $latex \[
64  \D{[ - f(x) ]}{x} = - \D{f(x)}{x}
65 \] $$
66 
67 $head Example$$
68 $children%
69  example/general/unary_minus.cpp
70 %$$
71 The file
72 $cref unary_minus.cpp$$
73 contains an example and test of this operation.
74 
75 $end
76 -------------------------------------------------------------------------------
77 */
78 
79 // BEGIN CppAD namespace
80 namespace CppAD {
81 
82 // Broken g++ compiler inhibits declaring unary minus a member or friend
83 template <class Base>
84 inline AD<Base> AD<Base>::operator - (void) const
85 { // should make a more efficient version by adding unary minus to
86  // Operator.h (some day)
87  AD<Base> result(0);
88 
89  result -= *this;
90 
91  return result;
92 }
93 
94 
95 template <class Base>
97 { return - right.ADBase(); }
98 
99 }
100 // END CppAD namespace
101 
102 
103 # endif
AD operator-(void) const
Definition: unary_minus.hpp:84
Definition: ad.hpp:34
AD< Base > ADBase(void) const
Conversion from VecAD_reference to AD&lt;Base&gt;. puts the correspond vecad load instruction in the tape...
Definition: vec_ad.hpp:392
AD< Base > operator-(const AD< Base > &left, const AD< Base > &right)
Definition: sub.hpp:20
Class used to hold a reference to an element of a VecAD object.
Definition: vec_ad.hpp:352