# include <cppad/cppad.hpp>
namespace { // isolate items below to this fileusing CppAD::vector; // abbreviate as vectorclass atomic_get_started : public CppAD::atomic_base<double> {
public:
// constructor (could use const char* for name)atomic_get_started(const std::string& name) :
// this example does not use any sparsity patterns
CppAD::atomic_base<double>(name)
{ }
private:
// Create the function f(x)//// domain space vector
size_t n = 1;
double x0 = 0.5;
vector< AD<double> > ax(n);
ax[0] = x0;
// declare independent variables and start tape recording
CppAD::Independent(ax);
// range space vector
size_t m = 1;
vector< AD<double> > ay(m);
// call user function and store get_started(x) in au[0]
vector< AD<double> > au(m);
afun(ax, au); // u = 1 / x// now use AD division to invert to invert the operation
ay[0] = 1.0 / au[0]; // y = 1 / u = x// create f: x -> y and stop tape recording
CppAD::ADFun<double> f;
f.Dependent (ax, ay); // f(x) = x