/home/coin/SVN-release/CoinAll-1.1.0/cppad/cppad/local/equal_op_seq.hpp

Go to the documentation of this file.
00001 # ifndef CPPAD_EQUAL_OP_SEQ_INCLUDED
00002 # define CPPAD_EQUAL_OP_SEQ_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 EqualOpSeq$$ 
00018 $spell
00019         Op
00020         inline
00021         const
00022         bool
00023 $$
00024 
00025 $index EqualOpSeq$$
00026 $index operation, equal sequence$$
00027 $index sequence, equal operation$$
00028 $index equal, operation sequence$$
00029 
00030 $section Check if Equal and Correspond to Same Operation Sequence$$
00031 
00032 $head Syntax$$
00033 $syntax%%b% = EqualOpSeq(%x%, %y%)%$$
00034 
00035 $head Purpose$$
00036 Determine if two $italic x$$ and $italic y$$ are equal, and
00037 if they are $cref/variables/glossary/Variable/$$,
00038 determine if they correspond to the same
00039 $cref/operation sequence/glossary/Operation/Sequence/$$.
00040 
00041 $head Motivation$$
00042 Sometimes it is useful to cache information
00043 and only recalculate when a function's arguments change.
00044 In the case of AD variables, 
00045 it may be important not only when the argument values are equal,
00046 but when they are related to the
00047 $cref/independent variables/glossary/Tape/Independent Variable/$$ 
00048 by the same operation sequence.
00049 After the assignment
00050 $syntax%
00051         %y% = %x%
00052 %$$
00053 these two AD objects would not only have equal values,
00054 but would also correspond to the same operation sequence.
00055 
00056 $head x$$
00057 The argument $italic x$$ has prototype
00058 $syntax%
00059         const AD<%Base%> &%x%
00060 %$$
00061 
00062 $head y$$
00063 The argument $italic y$$ has prototype
00064 $syntax%
00065         const AD<%Base%> &%y%
00066 %$$
00067 
00068 $head b$$
00069 The result $italic b$$ has prototype
00070 $syntax%
00071         bool %b%
00072 %$$
00073 The result is true if and only if one of the following cases holds:
00074 
00075 $list number$$
00076 Both $italic x$$ and $italic y$$ are variables 
00077 and correspond to the same operation sequence.
00078 $lnext
00079 Both $italic x$$ and $italic y$$ are parameters,
00080 $italic Base$$ is an AD type,
00081 and $syntax%EqualOpSeq( Value(%x%) , Value(%y%) )%$$ is true.
00082 $lnext
00083 Both $italic x$$ and $italic y$$ are parameters,
00084 $italic Base$$ is not an AD type,
00085 and $syntax%%x% == %y%%$$ is true.
00086 $lend
00087 
00088 
00089 $head Example$$
00090 $children%
00091         example/equal_op_seq.cpp
00092 %$$
00093 The file
00094 $xref/EqualOpSeq.cpp/$$
00095 contains an example and test of $code EqualOpSeq$$.
00096 It returns true if it succeeds and false otherwise.
00097 
00098 
00099 $end 
00100 ------------------------------------------------------------------------------
00101 */
00102 
00103 
00104 namespace CppAD {
00105         inline bool EqualOpSeq(const float &x, const float &y)
00106         {       return x == y; }
00107         inline bool EqualOpSeq(const double &x, const double &y)
00108         {       return x == y; }
00109         template <class Base>
00110         inline bool EqualOpSeq(const AD<Base> &x, const AD<Base> &y)
00111         {       
00112                 if( Parameter(x) )
00113                 {       if( Parameter(y) )
00114                                 return EqualOpSeq(x.value_, y.value_);
00115                         else    return false;
00116                 }
00117                 else if( Parameter(y) )
00118                         return false;
00119 
00120                 return (x.taddr_ == y.taddr_);
00121         }
00122                 
00123 }
00124 
00125 # endif

Generated on Sun Nov 14 14:06:33 2010 for Coin-All by  doxygen 1.4.7