## Introduction

We consider implementations of multivariate vector functions
$f:{D}^{n}×{D}^{{n}^{\prime }}\to {D}^{m}×{D}^{{m}^{\prime }}:\left(\mathbf{y},{\mathbf{y}}^{\prime }\right)=f\left(\mathbf{x},{\mathbf{x}}^{\prime }\right)$
as computer programs over some base data type $D$$D$ (for example, single or higher precision floating-point data, intervals, convex/concave relaxations, vectors/ensembles). (We assume that the arithmetic inside $f$$f$ is completely defined (through overloading of the elemental functions; see below.) The $n$$n$ active (also: independent) and ${n}^{\prime }$$n'$ passive inputs are mapped onto $m$$m$ active (also: dependent) and ${m}^{\prime }$$m'$ passive outputs. The given implementation is assumed to be $k$$k$ times continuously differentiable at all points of interest implying the existence and finiteness of the Jacobian
$\mathrm{\nabla }f={\mathrm{\nabla }}_{\mathbf{x}}f\left(\mathbf{x},{\mathbf{x}}^{\prime }\right)\equiv \frac{\mathrm{\partial }\mathbf{y}}{\mathrm{\partial }\mathbf{x}}\left(\mathbf{x},{\mathbf{x}}^{\prime }\right)\in {D}^{m×n},$
the Hessian
${\mathrm{\nabla }}^{2}f={\mathrm{\nabla }}^{2}f\left(\mathbf{x},{\mathbf{x}}^{\prime }\right)\equiv \frac{{\mathrm{\partial }}^{2}\mathbf{y}}{\mathrm{\partial }{\mathbf{x}}^{2}}\left(\mathbf{x},{\mathbf{x}}^{\prime }\right)\in {D}^{m×n×n},$
if $k\ge 2,$$k\geq2,$ and of potentially higher derivative tensors
${\mathrm{\nabla }}^{k}f={\mathrm{\nabla }}^{k}f\left(\mathbf{x},{\mathbf{x}}^{\prime }\right)\equiv \frac{{\mathrm{\partial }}^{k}\mathbf{y}}{\mathrm{\partial }{\mathbf{x}}^{k}}\left(\mathbf{x},{\mathbf{x}}^{\prime }\right)\in {D}^{m×\stackrel{k}{\underset{l=1}{×}}n}.$
We denote
${\mathrm{\nabla }}^{k}f={\left({\left[{\mathrm{\nabla }}^{k}f\right]}_{i}^{{j}_{1},\dots ,{j}_{k}}\right)}_{i=0,\dots ,m-1}^{{j}_{1},\dots ,{j}_{k}=0,\dots ,n-1},$
and we use $\ast$$*$ to denote the entire range of an index. For example, ${\left[\mathrm{\nabla }f\right]}_{i}^{\ast }$$\left [\nabla f \right ]_i^*$ denotes the $i$$i$th row and ${\left[\mathrm{\nabla }f\right]}_{\ast }^{j}$$\left [\nabla f \right ]_*^j$ the $j$$j$th column of the Jacobian, respectively. Algorithmic differentiation is implemented by the overloading of elemental functions including the built-in functions and operators of C++ as well as user-defined higher-level elemental functions.

## 1 First-Order Tangent Mode

### 1.1 Generic first-order scalar tangents

Generic first-order scalar tangent mode enables the computation of products of the Jacobian with vectors ${\mathbf{x}}^{\left(1\right)}\in {D}^{n}$$\mathbf{x}^{(1)} \in D^n$
${\mathbf{y}}^{\left(1\right)}=\mathrm{\nabla }f\cdot {\mathbf{x}}^{\left(1\right)}\in {D}^{m}$
through provision of a generic first-order scalar tangent data type over arbitrary base data types $D$$D$.

### 1.2 Generic first-order vector tangents

Generic first-order vector tangent mode enables the computation of products of the Jacobian with matrices ${X}^{\left(1\right)}\in {D}^{n×l}$$X^{(1)} \in D^{n \times l}$
${Y}^{\left(1\right)}=\mathrm{\nabla }f\cdot {X}^{\left(1\right)}\in {D}^{m×l}$
through provision of a generic first-order vector tangent data type over arbitrary base data types $D.$$D.$

### 1.3 Preaccumulation through use of expression templates

Expression templates enable the generation of statically optimized gradient code at the level of individual assignments which can be beneficial for vector tangent mode.

### 2.1 Generic first-order scalar adjoints

Generic first-order scalar adjoint mode enables the computation of products of the transposed Jacobian with vectors ${\mathbf{y}}_{\left(1\right)}\in {D}^{m}$$\mathbf{y}_{(1)} \in D^m$
${\mathbf{x}}_{\left(1\right)}=\mathrm{\nabla }{f}^{T}\cdot {\mathbf{y}}_{\left(1\right)}\in {D}^{n}$
through provision of a generic first-order scalar adjoint data type over arbitrary base data types $D.$$D.$

### 2.2 Generic first-order vector adjoints

Generic first-order vector adjoint mode enables the computation of products of the transposed Jacobian with matrices ${Y}_{\left(1\right)}\in {D}^{m×l}$$Y_{(1)} \in D^{m \times l}$
${X}_{\left(1\right)}=\mathrm{\nabla }{f}^{T}\cdot {Y}_{\left(1\right)}\in {D}^{n×l}$
through provision of a generic first-order scalar adjoint data type over arbitrary base data types $D.$$D.$

### 2.3 Global “blob” tape

Memory of the specified size is allocated and used for storing the tape without bound checks.

### 2.4 Global “chunk” tape

The tape grows in chunks up to the physical memory bound.

### 2.5 Global “file” tape (v3.2)

Chunks are written to and read from disk.

### 2.6 Distinct data types for values, partial derivatives and adjoints with all kinds of tapes (v3.2)

Data types for values, partial derivatives and adjoints can be set individually when defining the differentiation mode.

Multiple “blob” or “chunk” tapes can be allocated, for example, to implement thread-safe adjoints.

### 2.8 Preaccumulation through use of expression templates

Expression templates enable the generation of statically optimized gradient code at the level of individual assignments. This preaccumulation can result in a decrease in tape memory requirement.

### 2.9 Repeated evaluation of tape

Tapes can be recorded at a given point and interpreted repeatedly.

• checkpointing
• symbolic adjoints of numerical methods
• combinations of tangent and adjoint modes
• preaccumulation of local derivative tensors
• creation of collections of domain-specific higher-level elemental functions

### 2.11 User-defined local Jacobians interface

Externally preaccumulated partial derivatives can be inserted directly into the tape for use within subsequent interpretations.

### 2.12 User-driven preaccumulation of local Jacobians (v3.2)

An easy-to-use interface for robust preaccumulation of local Jacobians is provided. Aggressive reduction of the tape size is facilitated.

### 2.13 Multiple adjoint vectors for a single tape (v3.2)

Several (concurrent) interpretations of the same tape are enabled through separate (thread-local) adjoint vectors.

### 2.14 Modulo Adjoint Propagation (v3.3)

The vector of adjoints is compressed by analysing the maximum number of required distinct adjoint memory locations.

### 2.15 Sparse tape interpretation (v3.3)

The adjoint interpretation of the tape can omit propagation along edges when the corresponding adjoint to be propagated is zero.

## 3 Second- and Higher-order Tangent Mode

### 3.1 Generic second-order scalar tangents

Instantiation of the generic first-order scalar tangent data type with the generic first-order scalar tangent data type over a non-derivative base data type yields the second-order scalar tangent data type. It enables the computation of scalar projections of the Hessian ${\mathrm{\nabla }}^{2}f\in {D}^{m×n×n}$$\nabla^2 f \in D^{m \times n \times n}$ in its two domain dimensions of length $n$$n$ as
${\mathbf{y}}^{\left(1,2\right)}=⟨{\mathrm{\nabla }}^{2}f,{\mathbf{x}}^{\left(1\right)},{\mathbf{x}}^{\left(2\right)}⟩\equiv {\left({\mathbf{x}}^{{\left(1\right)}^{T}}\cdot {\left[{\mathrm{\nabla }}^{2}f\right]}_{i}^{\ast ,\ast }\cdot {\mathbf{x}}^{\left(2\right)}\right)}_{i=0,\dots ,m-1}\in {D}^{m}$
for ${\mathbf{x}}^{\left(1\right)},{\mathbf{x}}^{\left(2\right)}\in {D}^{n}$$\mathbf{x}^{(1)}, \mathbf{x}^{(2)} \in D^n$ over arbitrary base data types $D$$D$. The computational cost of accumulating the whole Hessian over $D$$D$ becomes $O\left({n}^{2}\right)\cdot \text{Cost}\left(f\right)$$O(n^2) \cdot \text{Cost}(f)$ with both ${\mathbf{x}}^{\left(1\right)}$$\mathbf{x}^{(1)}$ and ${\mathbf{x}}^{\left(2\right)}$$\mathbf{x}^{(2)}$ ranging independently over the Cartesian basis vectors in ${D}^{n}.$$D^n.$

### 3.2 Generic second-order vector tangents

Instantiation of the generic first-order vector tangent data type with the generic first-order vector tangent data type over a non-derivative base data type yields the second-order scalar tangent data type. It enables the computation of vector projections of the Hessian ${\mathrm{\nabla }}^{2}f\in {D}^{m×n×n}$$\nabla^2 f \in D^{m \times n \times n}$ in its two domain dimensions of length $n$$n$ as
${Y}^{\left(1,2\right)}=⟨{\mathrm{\nabla }}^{2}f,{X}^{\left(1\right)},{X}^{\left(2\right)}⟩\equiv {\left({X}^{{\left(1\right)}^{T}}\cdot {\left[{\mathrm{\nabla }}^{2}f\right]}_{i}^{\ast ,\ast }\cdot {X}^{\left(2\right)}\right)}_{i=0,\dots ,m-1}\in {D}^{m×{l}_{1}×{l}_{2}}$
for ${X}^{\left(1\right)}\in {D}^{n×{l}_{1}},$$X^{(1)} \in D^{n \times l_1},$ ${X}^{\left(2\right)}\in {D}^{n×{l}_{2}}$$X^{(2)} \in D^{n \times l_2}$ over arbitrary base data types $D$$D$. The computational cost of accumulating the whole Hessian over $D$$D$ remains equal to $O\left({n}^{2}\right)\cdot \text{Cost}\left(f\right)$$O(n^2) \cdot \text{Cost}(f)$ with both ${X}^{\left(1\right)}$$X^{(1)}$ and ${X}^{\left(2\right)}$$X^{(2)}$ set equal to the identities in ${D}^{n}.$$D^n.$

### 3.3 Other generic second-order tangents

Instantiation of the generic first-order vector tangent data type with the generic first-order scalar tangent data type over a non-derivative base data type yields a second-order tangent data type. Similarly, instantiation of the generic first-order scalar tangent data type with the generic first-order vector tangent data type over a non-derivative base data type yields a second-order tangent data type.

### 3.4 Generic third- and higher-order tangents

Instantiation of tangent types with $k$$k$th-order tangent types yields $\left(k+1\right)$$(k+1)$th-order tangent types.

## 4 Second- and Higher-order Adjoint Mode

### 4.1 Generic second-order scalar adjoints

Instantiation of the generic first-order scalar adjoint data type with the generic first-order scalar tangent data type over a non-derivative base data type yields a second-order scalar adjoint data type. It enables the computation of scalar projections of the Hessian ${\mathrm{\nabla }}^{2}f\in {D}^{m×n×n}$$\nabla^2 f \in D^{m \times n \times n}$ in its image and one of its domain dimensions as

${\mathbf{x}}_{\left(1\right)}^{\left(2\right)}=⟨{\mathbf{y}}_{\left(1\right)},{\mathrm{\nabla }}^{2}f,{\mathbf{x}}^{\left(2\right)}⟩\equiv {\left({\mathbf{y}}_{\left(1\right)}^{T}\cdot {\left[{\mathrm{\nabla }}^{2}f\right]}_{\ast }^{j,\ast }\cdot {\mathbf{x}}^{\left(2\right)}\right)}_{j=0,\dots ,n-1}\in {D}^{n}$
for ${\mathbf{y}}_{\left(1\right)}\in {D}^{m}$$\mathbf{y}_{(1)} \in D^m$ and ${\mathbf{x}}^{\left(2\right)}\in {D}^{n}$$\mathbf{x}^{(2)} \in D^n$ over arbitrary base data types $D$$D$. The computational cost of accumulating the whole Hessian over $D$$D$ becomes $O\left(m\cdot n\right)\cdot \text{Cost}\left(f\right)$$O(m\cdot n) \cdot \text{Cost}(f)$ with ${\mathbf{y}}_{\left(1\right)}$$\mathbf{y}_{(1)}$ and ${\mathbf{x}}^{\left(2\right)}$$\mathbf{x}^{(2)}$ ranging over the Cartesian basis vectors in ${D}^{m}$$D^m$ and ${D}^{n}$$D^n$, respectively.

### 4.2 Generic second-order vector adjoints

Instantiation of the generic first-order vector adjoint data type with the generic first-order vector tangent data type over a non-derivative base data type yields a second-order vector adjoint data type. It enables the computation of vector projections of the Hessian ${\mathrm{\nabla }}^{2}f\in {D}^{m×n×n}$$\nabla^2 f \in D^{m \times n \times n}$ in its image and one of its domain dimensions as

${X}_{\left(1\right)}^{\left(2\right)}=⟨{Y}_{\left(1\right)},{\mathrm{\nabla }}^{2}f,{X}^{\left(2\right)}⟩\equiv {\left({Y}_{\left(1\right)}^{T}\cdot {\left[{\mathrm{\nabla }}^{2}f\right]}_{\ast }^{j,\ast }\cdot {X}^{\left(2\right)}\right)}_{j=0,\dots ,n-1}\in {D}^{{l}_{1}×n×{l}_{2}}$
for ${Y}_{\left(1\right)}\in {D}^{m×{l}_{1}}$$Y_{(1)} \in D^{m \times l_1}$ and ${X}^{\left(2\right)}\in {D}^{n×{l}_{2}}$$X^{(2)} \in D^{n \times l_2}$ over arbitrary base data types $D$$D$. The computational cost of accumulating the whole Hessian over $D$$D$ remains equal to $O\left(m\cdot n\right)\cdot \text{Cost}\left(f\right)$$O(m\cdot n) \cdot \text{Cost}(f)$ with ${Y}_{\left(1\right)}$$Y_{(1)}$ and ${X}^{\left(2\right)}$$X^{(2)}$ set equal to the identities in ${D}^{m}$$D^m$ and ${D}^{n}$$D^n$, respectively.

### 4.3 Other generic second-order adjoints

Instantiation of the generic first-order vector adjoint data type with the generic first-order scalar tangent data type over a non-derivative base data type yields a second-order adjoint data type. Similarly, instantiation of the generic first-order scalar adjoint data type with the generic first-order vector tangent data type over a non-derivative base data type yields a second-order adjoint data type.

Symmetry of the Hessian in its two domain dimensions yields the following additional second-order adjoint data types: instantiation of a generic first-order tangent data type with a generic first-order adjoint data type over a non-derivative base data type yields a second-order adjoint data type for computing

$⟨{\mathbf{y}}_{\left(2\right)}^{\left(1\right)},{\mathrm{\nabla }}^{2}f,{\mathbf{x}}^{\left(1\right)}⟩\equiv {\left({\mathbf{y}}_{\left(2\right)}^{\left(1{\right)}^{T}}\cdot {\left[{\mathrm{\nabla }}^{2}f\right]}_{\ast }^{j,\ast }\cdot {\mathbf{x}}^{\left(1\right)}\right)}_{j=0,\dots ,n-1}\in {D}^{n}.$
Similarly, instantiation of a generic first-order adjoint data type with a generic first-order adjoint data type over a non-derivative base data type yields a second-order adjoint data type for computing
$⟨{\mathbf{x}}_{\left(1,2\right)},{\mathbf{y}}_{\left(1\right)},{\mathrm{\nabla }}^{2}f⟩\equiv {\left({\mathbf{y}}_{\left(1\right)}^{T}\cdot {\left[{\mathrm{\nabla }}^{2}f\right]}_{\ast }^{j,\ast }\cdot {\mathbf{x}}_{\left(1,2\right)}\right)}_{j=0,\dots ,n-1}\in {D}^{n}.$

### 4.4 Generic third- and higher-order adjoints

Instantiation of tangent types with $k$$k$th-order adjoint types yields $\left(k+1\right)$$(k+1)$th-order adjoint types. Similarly, instantiation of adjoint types with $k$$k$th-order tangent or adjoint types yields $\left(k+1\right)$$(k+1)$th-order adjoint types.