CppAD: A C++ Algorithmic Differentiation Package  20171217
unary_minus.hpp
Go to the documentation of this file.
3
4 /* --------------------------------------------------------------------------
6
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.
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
28
29 \$icode%y% = - %x%\$\$
30
31
33 Computes the negative of \$icode x\$\$.
34
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
40 The operand \$icode x\$\$ has one of the following prototypes
41 \$codei%
44 %\$\$
45
47 The result \$icode y\$\$ has type
48 \$codei%
50 %\$\$
51 It is equal to the negative of the operand \$icode x\$\$.
52
54 This is an AD of \$icode Base\$\$
55 \$cref/atomic operation/glossary/Operation/Atomic/\$\$
56 and hence is part of the current
58 \$cref/operation sequence/glossary/Operation/Sequence/\$\$.
59
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
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
81
82 // Broken g++ compiler inhibits declaring unary minus a member or friend
83 template <class Base>
85 { // should make a more efficient version by adding unary minus to
86  // Operator.h (some day)
88
89  result -= *this;
90
91  return result;
92 }
93
94
95 template <class Base>
97 { return - right.ADBase(); }
98
99 }