CppAD: A C++ Algorithmic Differentiation Package  20171217
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
equal_op_seq.hpp
Go to the documentation of this file.
1 # ifndef CPPAD_CORE_EQUAL_OP_SEQ_HPP
2 # define CPPAD_CORE_EQUAL_OP_SEQ_HPP
3 
4 /* --------------------------------------------------------------------------
5 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
6 
7 CppAD is distributed under multiple licenses. This distribution is under
8 the terms of the
9  Eclipse Public License Version 1.0.
10 
11 A copy of this license is included in the COPYING file of this distribution.
12 Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
13 -------------------------------------------------------------------------- */
14 
15 /*
16 ------------------------------------------------------------------------------
17 $begin EqualOpSeq$$
18 $spell
19  Op
20  const
21  bool
22 $$
23 
24 
25 $section Check if Two Value are Identically Equal$$
26 $mindex EqualOpSeq operation sequence$$
27 
28 $head Syntax$$
29 $icode%b% = EqualOpSeq(%x%, %y%)%$$
30 
31 $head Purpose$$
32 Determine if two $icode x$$ and $icode y$$ are identically equal; i.e.,
33 not only is $icode%x% == %y%$$ true, but
34 if they are $cref/variables/glossary/Variable/$$,
35 they correspond have the same
36 $cref/operation sequence/glossary/Operation/Sequence/$$.
37 
38 $head Motivation$$
39 Sometimes it is useful to cache information
40 and only recalculate when a function's arguments change.
41 In the case of AD variables,
42 it may be important not only when the argument values are equal,
43 but when they are related to the
44 $cref/independent variables/glossary/Tape/Independent Variable/$$
45 by the same operation sequence.
46 After the assignment
47 $codei%
48  %y% = %x%
49 %$$
50 these two AD objects would not only have equal values,
51 but would also correspond to the same operation sequence.
52 
53 $head x$$
54 The argument $icode x$$ has prototype
55 $codei%
56  const AD<%Base%> &%x%
57 %$$
58 
59 $head y$$
60 The argument $icode y$$ has prototype
61 $codei%
62  const AD<%Base%> &%y%
63 %$$
64 
65 $head b$$
66 The result $icode b$$ has prototype
67 $codei%
68  bool %b%
69 %$$
70 The result is true if and only if one of the following cases holds:
71 
72 $list number$$
73 Both $icode x$$ and $icode y$$ are variables
74 and correspond to the same operation sequence.
75 $lnext
76 Both $icode x$$ and $icode y$$ are parameters,
77 $icode Base$$ is an AD type,
78 and $codei%EqualOpSeq( Value(%x%) , Value(%y%) )%$$ is true.
79 $lnext
80 Both $icode x$$ and $icode y$$ are parameters,
81 $icode Base$$ is not an AD type,
82 and $icode%x% == %y%%$$ is true.
83 $lend
84 
85 
86 $head Example$$
87 $children%
88  example/general/equal_op_seq.cpp
89 %$$
90 The file
91 $cref equal_op_seq.cpp$$
92 contains an example and test of $code EqualOpSeq$$.
93 It returns true if it succeeds and false otherwise.
94 
95 
96 $end
97 ------------------------------------------------------------------------------
98 */
99 
100 
101 namespace CppAD {
102  template <class Base>
104  bool EqualOpSeq(const AD<Base> &x, const AD<Base> &y)
105  {
106  if( Parameter(x) )
107  { if( Parameter(y) )
108  return EqualOpSeq(x.value_, y.value_);
109  else return false;
110  }
111  else if( Parameter(y) )
112  return false;
113 
114  return (x.taddr_ == y.taddr_);
115  }
116 
117 }
118 
119 # endif
Base value_
Definition: ad.hpp:38
Definition: ad.hpp:34
#define CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION
A version of the inline command that works with MC compiler.
Definition: define.hpp:43
bool EqualOpSeq(const std::complex< double > &x, const std::complex< double > &y)
CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION bool Parameter(const AD< Base > &x)
Definition: par_var.hpp:80
addr_t taddr_
Definition: ad.hpp:44