00001 # ifndef CPPAD_AD_BINARY_INCLUDED 00002 # define CPPAD_AD_BINARY_INCLUDED 00003 00004 /* -------------------------------------------------------------------------- 00005 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-07 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 ------------------------------------------------------------------------------- 00017 $begin ad_binary$$ 00018 $spell 00019 Op 00020 VecAD 00021 const 00022 $$ 00023 00024 $section AD Binary Arithmetic Operators$$ 00025 00026 $index binary, operator$$ 00027 $index operator, binary$$ 00028 00029 $index +, binary operator$$ 00030 $index add, binary operator$$ 00031 $index plus, binary operator$$ 00032 00033 $index -, binary operator$$ 00034 $index subtract, binary operator$$ 00035 $index minus, binary operator$$ 00036 00037 $index *, binary operator$$ 00038 $index multiply, binary operator$$ 00039 $index times, binary operator$$ 00040 00041 $index /, binary operator$$ 00042 $index divide, binary operator$$ 00043 00044 00045 $head Syntax$$ 00046 $syntax%%z% = %x% %Op% %y%$$ 00047 00048 $head Purpose$$ 00049 Performs arithmetic operations where either $italic x$$ or $italic y$$ 00050 has type 00051 $syntax%AD<%Base%>%$$ or 00052 $cref%VecAD<Base>::reference%VecAD%VecAD<Base>::reference%$$. 00053 00054 $head Op$$ 00055 The operator $italic Op$$ is one of the following 00056 $table 00057 $bold Op$$ $cnext $bold Meaning$$ $rnext 00058 $code +$$ $cnext $italic z$$ is $italic x$$ plus $italic y$$ $rnext 00059 $code -$$ $cnext $italic z$$ is $italic x$$ minus $italic y$$ $rnext 00060 $code *$$ $cnext $italic z$$ is $italic x$$ times $italic y$$ $rnext 00061 $code /$$ $cnext $italic z$$ is $italic x$$ divided by $italic y$$ 00062 $tend 00063 00064 $head Base$$ 00065 The type $italic Base$$ is determined by the operand that 00066 has type $syntax%AD<%Base%>%$$ or $syntax%VecAD<%Base%>::reference%$$. 00067 00068 $head x$$ 00069 The operand $italic x$$ has the following prototype 00070 $syntax% 00071 const %Type% &%x% 00072 %$$ 00073 where $italic Type$$ is 00074 $syntax%VecAD<%Base%>::reference%$$, 00075 $syntax%AD<%Base%>%$$, 00076 $italic Base$$, or 00077 $code double$$. 00078 00079 $head y$$ 00080 The operand $italic y$$ has the following prototype 00081 $syntax% 00082 const %Type% &%y% 00083 %$$ 00084 where $italic Type$$ is 00085 $syntax%VecAD<%Base%>::reference%$$, 00086 $syntax%AD<%Base%>%$$, 00087 $italic Base$$, or 00088 $code double$$. 00089 00090 00091 $head z$$ 00092 The result $italic z$$ has the following prototype 00093 $syntax% 00094 %Type% %z% 00095 %$$ 00096 where $italic Type$$ is 00097 $syntax%AD<%Base%>%$$. 00098 00099 $head Operation Sequence$$ 00100 This is an $cref/atomic/glossary/Operation/Atomic/$$ 00101 $cref/AD of Base/glossary/AD of Base/$$ operation 00102 and hence it is part of the current 00103 AD of $italic Base$$ 00104 $cref/operation sequence/glossary/Operation/Sequence/$$. 00105 00106 $children% 00107 example/add.cpp% 00108 example/sub.cpp% 00109 example/mul.cpp% 00110 example/div.cpp 00111 %$$ 00112 00113 $head Example$$ 00114 The following files contain examples and tests of these functions. 00115 Each test returns true if it succeeds and false otherwise. 00116 $table 00117 $rref Add.cpp$$ 00118 $rref Sub.cpp$$ 00119 $rref Mul.cpp$$ 00120 $rref Div.cpp$$ 00121 $tend 00122 00123 $head Derivative$$ 00124 If $latex f$$ and $latex g$$ are 00125 $xref/glossary/Base Function/Base functions/$$ 00126 00127 $subhead Addition$$ 00128 $latex \[ 00129 \D{[ f(x) + g(x) ]}{x} = \D{f(x)}{x} + \D{g(x)}{x} 00130 \] $$ 00131 00132 $subhead Subtraction$$ 00133 $latex \[ 00134 \D{[ f(x) - g(x) ]}{x} = \D{f(x)}{x} - \D{g(x)}{x} 00135 \] $$ 00136 00137 $subhead Multiplication$$ 00138 $latex \[ 00139 \D{[ f(x) * g(x) ]}{x} = g(x) * \D{f(x)}{x} + f(x) * \D{g(x)}{x} 00140 \] $$ 00141 00142 $subhead Division$$ 00143 $latex \[ 00144 \D{[ f(x) / g(x) ]}{x} = 00145 [1/g(x)] * \D{f(x)}{x} - [f(x)/g(x)^2] * \D{g(x)}{x} 00146 \] $$ 00147 00148 $end 00149 ----------------------------------------------------------------------------- 00150 */ 00151 # include <cppad/local/add.hpp> 00152 # include <cppad/local/sub.hpp> 00153 # include <cppad/local/mul.hpp> 00154 # include <cppad/local/div.hpp> 00155 00156 # endif