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