00001 # ifndef CPPAD_IDENTICAL_INCLUDED 00002 # define CPPAD_IDENTICAL_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 IdenticalPar$$ $comment CppAD Developer Documentation$$ 00018 $spell 00019 inline 00020 const 00021 bool 00022 $$ 00023 00024 $index identical, parameter$$ 00025 $index parameter, identical$$ 00026 00027 $section Check if a Value is Identically a Parameter$$ 00028 00029 $head Syntax$$ 00030 $syntax%inline bool IdenticalPar(const %Type% &%x%)%$$ 00031 00032 $head Description$$ 00033 If $italic x$$ is not of type $syntax%AD<%Base%>%$$, 00034 this function returns true. 00035 Otherwise, it returns true if and only if 00036 the sequence of values 00037 $syntax% 00038 %x%, %x%.value_, %x%.value_.value , ... 00039 %$$ 00040 are all parameters. 00041 00042 $end 00043 ------------------------------------------------------------------------------ 00044 $begin IdenticalZero$$ $comment CppAD Developer Documentation$$ 00045 $spell 00046 inline 00047 const 00048 bool 00049 $$ 00050 00051 $index identical, zero$$ 00052 $index zero, identical$$ 00053 00054 $section Check if a Value is Identically Zero$$ 00055 00056 $head Syntax$$ 00057 $syntax%inline bool IdenticalZero(const %Type% &%x%)%$$ 00058 00059 $head Description$$ 00060 If $italic x$$ is not of type $syntax%AD<%Base%>%$$, 00061 this function returns true if and only if 00062 $italic x$$ is equal to zero. 00063 Otherwise, it returns true if and only if it is equal to zero 00064 and the sequence of values 00065 $syntax% 00066 %x%, %x%.value_, %x%.value_.value , ... 00067 %$$ 00068 are all parameters. 00069 00070 $end 00071 ------------------------------------------------------------------------------ 00072 00073 00074 $begin IdenticalOne$$ $comment CppAD Developer Documentation$$ 00075 $spell 00076 inline 00077 const 00078 bool 00079 $$ 00080 00081 $index identical, one$$ 00082 $index one, identical$$ 00083 00084 $section Check if a Value is Identically One$$ 00085 00086 $head Syntax$$ 00087 $syntax%inline bool IdenticalOne(const %Type% &%x%)%$$ 00088 00089 $head Description$$ 00090 If $italic x$$ is not of type $syntax%AD<%Base%>%$$, 00091 this function returns true if and only if 00092 $italic x$$ is equal to zero. 00093 Otherwise, it returns true if and only if it is equal to zero 00094 and the sequence of values 00095 $syntax% 00096 %x%, %x%.value_, %x%.value_.value , ... 00097 %$$ 00098 are all parameters. 00099 00100 $end 00101 ------------------------------------------------------------------------------ 00102 $begin IdenticalEqualPar$$ $comment CppAD Developer Documentation$$ 00103 $spell 00104 inline 00105 const 00106 bool 00107 $$ 00108 00109 $index identical, equal$$ 00110 $index equal, identical$$ 00111 00112 $section Check if a Value is Identically Equal Another$$ 00113 00114 $head Syntax$$ 00115 $syntax%inline bool IdenticalEqualPar(const %Type% &%x%, const %Type%)%$$ 00116 00117 $head Description$$ 00118 If $italic Type$$ is $syntax%AD<%Base%>%$$ for some $italic Base$$, 00119 $italic x$$ is identically equal $italic y$$ if and only if 00120 both $italic x$$ and $italic y$$ are parameters 00121 and $syntax%%x%.value_%$$ is identically equal $syntax%%y%.value_%$$. 00122 If $italic Type$$ is not $syntax%AD<%Base%>%$$ for some $italic Base$$, 00123 $italic x$$ is identically equal $italic y$$ if and only if 00124 $syntax% 00125 %x% == %y% 00126 %$$ 00127 00128 $end 00129 ------------------------------------------------------------------------------ 00130 */ 00131 00132 00133 namespace CppAD { 00134 // Parameter ------------------------------------------- 00135 inline bool IdenticalPar(const float &x) 00136 { return true; } 00137 inline bool IdenticalPar(const double &x) 00138 { return true; } 00139 template <class Base> 00140 inline bool IdenticalPar(const AD<Base> &x) 00141 { return Parameter(x) && IdenticalPar(x.value_); } 00142 00143 // Zero ----------------------------------------------- 00144 inline bool IdenticalZero(const float &x) 00145 { return (x == 0.); } 00146 inline bool IdenticalZero(const double &x) 00147 { return (x == 0.); } 00148 template <class Base> 00149 inline bool IdenticalZero(const AD<Base> &x) 00150 { return Parameter(x) && IdenticalZero(x.value_); } 00151 00152 // One ----------------------------------------------- 00153 inline bool IdenticalOne(const float &x) 00154 { return (x == 1.); } 00155 inline bool IdenticalOne(const double &x) 00156 { return (x == 1.); } 00157 template <class Base> 00158 inline bool IdenticalOne(const AD<Base> &x) 00159 { return Parameter(x) && IdenticalOne(x.value_); } 00160 00161 // Equal ----------------------------------------------- 00162 inline bool IdenticalEqualPar(const float &x, const float &y) 00163 { return (x == y); } 00164 inline bool IdenticalEqualPar(const double &x, const double &y) 00165 { return (x == y); } 00166 template <class Base> 00167 inline bool IdenticalEqualPar(const AD<Base> &x, const AD<Base> &y) 00168 { bool parameter; 00169 parameter = ( Parameter(x) & Parameter(y) ); 00170 return parameter && IdenticalEqualPar(x.value_, y.value_); 00171 } 00172 } 00173 00174 # endif