NAG Library Manual, Mark 28.5
```/* nag::ad::c05ay Adjoint Example Program.
*/

#include <dco.hpp>
#include <iostream>

// Function which calls NAG AD Library routines.
template <typename T> void func(T r, T &x);

// Driver with the adjoint calls.
// Finds the zero point f(xv) = 0 for the function
// f(x) =  exp(-x) - r*x.
// Also, computes the gradient dxdr = dxv/dr.
void driver(const double &rv, double &xv, double &dxdr);

int main()
{

// Set problem parameters
double rv = 2.0;
// Solution x
double xv;
// Derivative of x
double dxdr;

// Call driver
driver(rv, xv, dxdr);

// Print outputs
std::cout << "\n Derivatives calculated: First order adjoints\n";
std::cout << " Computational mode    : algorithmic\n";

// Print derivatives
std::cout.setf(std::ios::scientific, std::ios::floatfield);
std::cout.precision(12);
std::cout << "\n Solution:\n";
std::cout << " x = " << xv << std::endl;
std::cout << "\n Derivative of solution x w.r.t. parameter r:\n";
std::cout << " dx/dr(x) = " << dxdr << std::endl;

return 0;
}

// Driver with the adjoint calls.
// Finds the zero point f(xv) = 0 for the function
// f(x) =  exp(-x) - r*x.
// Also, computes the gradient dxdr = dxv/dr.
void driver(const double &rv, double &xv, double &dxdr)
{
using T = dco::ga1s<double>::type;

dco::ga1s<double>::global_tape = dco::ga1s<double>::tape_t::create();

// Function parameter r
T r = rv;

// Register variable to differentiate w.r.t.
dco::ga1s<double>::global_tape->register_variable(r);

// Variable to differentiate
T x;

// Call the NAG AD Lib functions
func(r, x);
// Extract the computed solution
xv = dco::value(x);

dco::ga1s<double>::global_tape->register_output_variable(x);
dco::derivative(x) = 1.0;

// Extract the derivatives
dxdr = dco::derivative(r);

// Remove tape
dco::ga1s<double>::tape_t::remove(dco::ga1s<double>::global_tape);
}

// Function which calls NAG AD Library routines.
template <typename T> void func(T r, T &x)
{
// Active variables
T a = 0.0, b = 1.0;
T eps = 1.0e-5, eta = 0.0;
// Create AD configuration data object
Integer           ifail = 0;