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