CppAD: A C++ Algorithmic Differentiation Package  20171217
sign.hpp
Go to the documentation of this file.
3
4 /* --------------------------------------------------------------------------
6
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.
13 -------------------------------------------------------------------------- */
14
15 /*
16 $begin sign$$17 spell 18 CppAD 19 Dirac 20$$ 21$section The Sign: sign$$22 23 head Syntax$$
24 $icode%y% = sign(%x%)%$$25 26 head Description$$ 27 Evaluates the$code sign$$function which is defined by 28 latex $29 {\rm sign} (x) = 30 \left\{ \begin{array}{rl} 31 +1 & {\rm if} \; x > 0 \\ 32 0 & {\rm if} \; x = 0 \\ 33 -1 & {\rm if} \; x < 0 34 \end{array} \right. 35$$$
36
37 $head x, y$$38 See the cref/possible types/unary_standard_math/Possible Types/$$ 39 for a unary standard math function. 40 41$head Atomic$$42 This is an cref/atomic operation/glossary/Operation/Atomic/$$.
43
44 $head Derivative$$45 CppAD computes the derivative of the code sign$$ function as zero for all 46 argument values$icode x$$. 47 The correct mathematical derivative is different and 48 is given by 49 latex $50 {\rm sign}^{(1)} (x) = 2 \delta (x) 51$$$
52 where $latex \delta (x)$$is the Dirac Delta function. 53 54 head Example$$ 55$children%
56  example/general/sign.cpp
57 %$$58 The file 59 cref sign.cpp$$
60 contains an example and test of this function.
61 It returns true if it succeeds and false otherwise.
62
63 \$end
64 -------------------------------------------------------------------------------
65 */
66
69
70 template <class Base>
72 {
74  result.value_ = sign(value_);
76
77  if( Variable(*this) )
78  { // add this operation to the tape
82
85  // put operator in the tape
87  // make result a variable
88  result.tape_id_ = tape->id_;
89  }
90  return result;
91 }
92
93 template <class Base>
95 { return x.sign_me(); }
96
97 template <class Base>
100
101 } // END CppAD namespace
102
103 # endif
Base value_
Definition: sign.hpp:71
size_t NumArg(OpCode op)
Number of arguments for a specified operator.
Definition: op_code.hpp:175
size_t NumRes(OpCode op)
Number of variables resulting from the specified operation.
Definition: op_code.hpp:281
Definition: par_var.hpp:99
Check that exp is true, if not terminate execution.
std::complex< double > sign(const std::complex< double > &x)
local::recorder< Base > Rec_
This is where the information is recorded.