00001 # ifndef CPPAD_UNARY_MINUS_INCLUDED 00002 # define CPPAD_UNARY_MINUS_INCLUDED 00003 00004 /* -------------------------------------------------------------------------- 00005 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-06 Bradley M. Bell 00006 00007 CppAD is distributed under multiple licenses. This distribution is under 00008 the terms of the 00009 Common Public License Version 1.0. 00010 00011 A copy of this license is included in the COPYING file of this distribution. 00012 Please visit http://www.coin-or.org/CppAD/ for information on other licenses. 00013 -------------------------------------------------------------------------- */ 00014 00015 /* 00016 $begin UnaryMinus$$ 00017 $spell 00018 Vec 00019 const 00020 inline 00021 $$ 00022 00023 $index unary, AD minus operator$$ 00024 $index AD, unary minus operator$$ 00025 $index minus, AD unary operator$$ 00026 $index -, AD unary operator$$ 00027 00028 $section AD Unary Minus Operator$$ 00029 00030 $head Syntax$$ 00031 00032 $syntax%%y% = - %x%$$ 00033 00034 00035 $head Purpose$$ 00036 Computes the negative of $italic x$$. 00037 00038 $head Base$$ 00039 The operation in the syntax above must be supported for the case where 00040 the operand is a $code const$$ $italic Base$$ object. 00041 00042 $head x$$ 00043 The operand $italic x$$ has one of the following prototypes 00044 $syntax% 00045 const AD<%Base%> &%x% 00046 const VecAD<%Base%>::reference &%x% 00047 %$$ 00048 00049 $head y$$ 00050 The result $italic y$$ has type 00051 $syntax% 00052 AD<%Base%> %y% 00053 %$$ 00054 It is equal to the negative of the operand $italic x$$. 00055 00056 $head Operation Sequence$$ 00057 This is an AD of $italic Base$$ 00058 $xref/glossary/Operation/Atomic/atomic operation/1/$$ 00059 and hence is part of the current 00060 AD of $italic Base$$ 00061 $xref/glossary/Operation/Sequence/operation sequence/1/$$. 00062 00063 $head Derivative$$ 00064 If $latex f$$ is a 00065 $xref/glossary/Base Function/Base function/$$, 00066 $latex \[ 00067 \D{[ - f(x) ]}{x} = - \D{f(x)}{x} 00068 \] $$ 00069 00070 $head Example$$ 00071 $children% 00072 example/unary_minus.cpp 00073 %$$ 00074 The file 00075 $xref/UnaryMinus.cpp/$$ 00076 contains an example and test of this operation. 00077 00078 $end 00079 ------------------------------------------------------------------------------- 00080 */ 00081 00082 // BEGIN CppAD namespace 00083 namespace CppAD { 00084 00085 // Broken g++ compiler inhibits declaring unary minus a member or friend 00086 template <class Base> 00087 inline AD<Base> AD<Base>::operator - (void) const 00088 { // should make a more efficient version by adding unary minus to 00089 // Operator.h (some day) 00090 AD<Base> result(0); 00091 00092 result -= *this; 00093 00094 return result; 00095 } 00096 00097 00098 template <class Base> 00099 inline AD<Base> operator - (const VecAD_reference<Base> &right) 00100 { return - right.ADBase(); } 00101 00102 } 00103 // END CppAD namespace 00104 00105 00106 # endif