The Elements of Differentiable Programming

Chapter 11Differentiating through optimization

In this chapter, we study how to differentiate through optimization problems, and more generally through nonlinear systems of equations.

11.1 Implicit functions

Implicit functions are functions that do not enjoy an explicit decomposition into elementary functions, for which automatic differentiation, as studied in Chapter 8, can therefore not be directly applied. We describe in this chapter techniques to differentiate through such functions and how to integrate them into an autodiff framework.

Formally, we will denote an implicit function by w⋆(λ)\wv^\star(\lambdav), where w⋆ ⁣:Λ→W\wv^\star \colon \Lambda \to \cW. One question is then how to compute the Jacobian ∂w⋆(λ)\partial \wv^\star(\lambdav). As a first application one can consider sensitivity analysis of a system. For example, w⋆(λ)\wv^\star(\lambdav) could correspond to the equilibrium state of a physical system and in this case, ∂w⋆(λ)\partial \wv^\star(\lambdav) would tell us about the sensitivity of the system to some parameters λ∈Λ\lambdav \in \Lambda.

11.1.1 Optimization problems

Another example is a function implicitly defined as the solution (assumed unique) of an optimization problem w⋆(λ)≔arg max⁡w∈Wf(w,λ), \wv^\star(\lambdav) \coloneqq \argmax_{\wv \in \cW} f(\wv, \lambdav), where f ⁣:W×Λ→Rf \colon \cW \times \Lambda \to \RR and W\cW denotes a constraint set. Note that we use an arg max⁡\argmax for convenience, but the same applies when using an arg min⁡\argmin.

11.1.2 Nonlinear equations

More generally, w⋆(λ)\wv^\star(\lambdav) can be defined as the root of some function F ⁣:W×Λ→WF \colon \cW \times \Lambda \to \cW, i.e., w⋆(λ)\wv^\star(\lambdav) is implicitly defined as the value satisfying the (potentially nonlinear) system of equations F(w,λ)=0 F(\w, \lambdav) = \zeros for all λ∈Λ\lambdav \in \Lambda.

11.1.3 Application to bilevel optimization

Besides sensitivity analysis, another example of application is bilevel optimization. Many times, we want to minimize a function defined as the composition of a fixed function and the solution of an optimization problem. Formally, let f,g ⁣:W×Λ→Rf, g \colon \cW \times \Lambda \to \RR. We consider the composition h(λ)h(\lambdav) defined as h(λ)≔g(w⋆(λ),λ),wherew⋆(λ)≔arg max⁡w∈Wf(w,λ).(11.1) h(\lambdav) \coloneqq g(\wv^\star(\lambdav), \lambdav), \quad \text{where} \quad \wv^\star(\lambdav) \coloneqq \argmax_{\wv \in \cW} f(\wv, \lambdav). \tag{11.1} This includes for instance hyperparameter optimization, where ff is an inner log-likelihood objective, gg is an outer validation loss, w∈W\wv \in \cW are model parameters and λ∈Λ\lambdav \in \Lambda are model hyperparameters, such as regularization strength, as illustrated in Fig. 11.1. To minimize h(λ)h(\lambdav), one generally resorts to a gradient descent scheme w.r.t.  λ\lambdav, which requires computing ∇h(λ)\nabla h(\lambdav). Assuming that w⋆(λ)\wv^\star(\lambdav) is differentiable at λ\lambdav, by the chain rule, we obtain the Jacobian ∂h(λ)=∂1g(w⋆(λ),λ)∂w⋆(λ)+∂2g(w⋆(λ),λ). \partial h(\lambdav) = \partial_1 g(\wv^\star(\lambdav), \lambdav) \partial \wv^\star(\lambdav) + \partial_2 g(\wv^\star(\lambdav), \lambdav). Using ∂h(λ)⊤=∇h(λ)\partial h(\lambdav)^\top = \nabla h(\lambdav) (see Remark 2.4), we obtain the gradient ∇h(λ)=∂w⋆(λ)⊤∇1g(w⋆(λ),λ)+∇2g(w⋆(λ),λ). \nabla h(\lambdav) = \partial \wv^\star(\lambdav)^\top \nabla_1 g(\wv^\star(\lambdav), \lambdav) + \nabla_2 g(\wv^\star(\lambdav), \lambdav). The only problematic term is ∂w⋆(λ)\partial \wv^\star(\lambdav), as it requires argmax differentiation. Indeed, most of the time, there is no explicit formula for w⋆(λ)\wv^\star(\lambdav) and it does not decompose into elementary functions.

Figure 11.1: Hyperparameter optimization in nonlinear regression can be cast as a bi-level optimization problem. Each line corresponds to the estimator obtained by fitting some training data (in blue circles) using a different hyperparameter λ\lambda. Formally, denoting ff the training objective, the estimators are w⋆(λ)≔arg min⁡wf(w;λ)w^\star(\lambda) \coloneqq \argmin_w f(w; \lambda). The goal is to find the best hyperparameter that fits some validation data (here in cyan diamonds), that is, minimizing h(λ)≔g(w⋆(λ),λ)h(\lambda) \coloneqq g(w^\star(\lambda), \lambda), where gg is the validation objective. A too small λ1\lambda_1 leads to overfitting the training objective and performs badly on validation objective. Conversely, a larger λ2\lambda_2 underfits both training and validation objectives. The optimal parameter λ⋆\lambda^\star minimizes the validation objective and may be obtained by iterating gradient descent w.r.t. λ\lambda. This requires gradients of h(λ)=g(w⋆(λ),λ)h(\lambda) = g(w^\star(\lambda), \lambda) w.r.t. λ\lambda.

11.2 Envelope theorems

In the special case g=fg = f, the composition hh defined in Eq. (11.1) is simply given by h(λ)=f(w⋆(λ),λ)=max⁡w∈Wf(w,λ). h(\lambdav) = f(\wv^\star(\lambdav), \lambdav) = \max_{\wv \in \cW} f(\wv, \lambdav). That is, we no longer need argmax differentiation, but only max differentiation, which, as we shall now see is much easier. The function hh is often called a value function (Fleming and Rishel, 2012). The reason for the name “envelope” is illustrated in Fig. 11.2. We emphasize that there is not one, but several envelope theorems, depending on the assumptions on ff.

Figure 11.2: The graph of h(λ)=max⁡w∈Wf(w,λ)h(\lambdav)= \max_{\wv \in \cW} f(\wv, \lambdav) is the upper-envelope of the graphs of the functions λ↦f(w,λ)\lambdav \mapsto f(\wv, \lambdav) for all w∈W\wv \in \cW.

11.2.1 Bertsekas’ theorem

The following theorem is due to Bertsekas (1997, Proposition B.25).

Theorem 11.1 (Bertsekas’ theorem)

Let h(λ)≔max⁡w∈Wf(w,λ) h(\lambdav) \coloneqq \max_{\wv \in \cW} f(\wv, \lambdav) and w⋆(λ)≔arg max⁡w∈Wf(w,λ), \wv^\star(\lambdav) \coloneqq \argmax_{\wv \in \cW} f(\wv, \lambdav), where f ⁣:W×Λ→Rf \colon \cW \times \Lambda \to \R is concave in w\w and W\cW is a compact convex set. If the maximum w⋆(λ)\wv^\star(\lambdav) is unique, then the function hh is differentiable with gradient ∇h(λ)=∇2f(w⋆(λ),λ). \nabla h(\lambdav) = \nabla_2 f(\wv^\star(\lambdav), \lambdav). If furthermore ff is convex in λ\lambdav, then h(λ)h(\lambdav) is convex.

A variant of the theorem can be stated when W=RP\cW = \RR^P.

Theorem 11.2 (Unbounded case)

Suppose W=RP\cW = \RR^P. If ff is strongly concave in w\wv, then the function hh is differentiable with gradient ∇h(λ)=∇2f(w⋆(λ),λ). \nabla h(\lambdav) = \nabla_2 f(\wv^\star(\lambdav), \lambdav). If furthermore ff is convex in λ\lambdav, then h(λ)h(\lambdav) is convex.

Informally, Theorem 11.1 and Theorem 11.2 mean that we can treat w⋆(λ)\wv^\star(\lambdav) as if it were a constant of λ\lambdav. In other words, we do not need to differentiate through w⋆(λ)\wv^\star(\lambdav), even though it depends on λ\lambdav.

Remark 11.1 (Historical note)

Bertsekas’ theorem or its unbounded variant are often incorrectly cited as Danskin’s theorem in the machine learning literature, because Bertsekas himself called it that way (Bertsekas, 1997, Proposition B.25). However, because the assumptions differ, they should rather be thought as variants or corollaries of Danskin’s original theorem. See Section 11.2.3 for more details.

We now illustrate Theorem 11.2, to differentiate through a minimum, h(λ)=min⁡w∈Wf(w,λ)h(\lambdav) = \min_{\wv \in \cW} f(\wv, \lambdav), assuming f(w,λ)f(\wv, \lambdav) is strongly convex in w\wv.

Example 11.1 (Differentiating the minimum of a convex quadratic)

Let us define h(λ)≔min⁡w∈Rf(w,λ)h(\lambda) \coloneqq \min_{w \in \R} f(w, \lambda), where f(w,λ)≔λ2w2+bw+cf(w, \lambda) \coloneqq \frac{\lambda}{2} w^2 + b w + c and λ>0\lambda > 0. The derivative of ff w.r.t. ww is ∇1f(w,λ)=λw+b\nabla_1 f(w, \lambda) = \lambda w + b. The second derivative of ff w.r.t. ww is ∇12f(w,λ)=λ\nabla_1^2 f(w, \lambda) = \lambda. Therefore ff is strongly convex in ww. Let w⋆(λ)w^\star(\lambda) be the minimum of ff in ww. Setting ∇1f(w,λ)\nabla_1 f(w, \lambda) to zero, we get w⋆(λ)=−bλw^\star(\lambda) = -\frac{b}{\lambda}. The derivative of ff w.r.t. λ\lambda is ∇2f(w,λ)=12w2\nabla_2 f(w, \lambda) = \frac{1}{2} w^2. From Theorem 11.2, we have h′(λ)=∇2f(w⋆(λ),λ)=12(w⋆(λ))2=12b2λ2h'(\lambda) = \nabla_2 f(w^\star(\lambda), \lambda) = \frac{1}{2} (w^\star(\lambda))^2 = \frac{1}{2} \frac{b^2}{\lambda^2}. Let us check that the derivative is indeed correct. Plugging w⋆(λ)w^\star(\lambda) back into f(w,λ)f(w, \lambda), we get the analytical formula h(λ)=−12b2λ+ch(\lambda) = -\frac{1}{2} \frac{b^2}{\lambda} + c. Using (1λ)′=−1λ2(\frac{1}{\lambda})' = -\frac{1}{\lambda^2}, we indeed obtain the same expression for h′(λ)h'(\lambda).

Theorem 11.1 has a simple interpretation for functions that are affine in λ\lambdav as shown below.

Example 11.2 (Convex conjugate)

Let f(w,λ)≔⟨w,λ⟩−Ω(w)f(\wv, \lambdav) \coloneqq \langle \wv, \lambdav \rangle - \Omega(\wv) with Ω\Omega convex. We then have h(λ)=max⁡w∈W ⟨w,λ⟩−Ω(w)≕Ω∗(λ)h(\lambdav) = \max_{\wv \in \cW} ~ \langle \wv, \lambdav \rangle - \Omega(\wv) \eqqcolon \Omega^*(\lambdav), where Ω∗\Omega^* denotes the convex conjugate of Ω\Omega. Since ff is convex and assuming W\cW is convex compact, the conditions of Theorem 11.1 are met. Since ∇2f(w,λ)=w\nabla_2 f(\wv, \lambdav) = \wv, we obtain ∇h(λ)=∇Ω∗(λ)=w⋆(λ)\nabla h(\lambdav) = \nabla \Omega^*(\lambdav) = \wv^\star(\lambdav). In other words, in this special case, the gradient of the max is equal to the argmax. This is due to the fact that f(w,λ)f(\wv, \lambdav) is affine in λ\lambdav.

Another application is saddle point optimization.

Example 11.3 (Saddle point problem)

Consider the saddle point problem min⁡λ∈Λmax⁡w∈Wf(w,λ)\min_{\lambdav \in \Lambda} \max_{\wv \in \cW} f(\wv, \lambdav). If it is difficult to minimize w.r.t. λ\lambdav but easy to maximize w.r.t. w\wv, we can rewrite the problem as min⁡λ∈Λh(λ)\min_{\lambdav \in \Lambda} h(\lambdav), where h(λ)≔max⁡w∈Wf(w,λ)h(\lambdav) \coloneqq \max_{\wv \in \cW} f(\wv, \lambdav), and use ∇h(λ)\nabla h(\lambdav) to perform (projected) gradient descent w.r.t. λ\lambdav.

11.2.2 Rockafellar’s theorem

A related theorem (Rockafellar and Wets, 2009, Theorem 10.31) can be proved under different assumptions on ff.

Theorem 11.3 (Rockafellar’s envelope theorem)

Let f ⁣:W×Λ→Rf \colon \cW \times \Lambda \to \R and W\cW be a compact convex set. Let h(λ)≔max⁡w∈Wf(w,λ) h(\lambdav) \coloneqq \max_{\wv \in \cW} f(\wv, \lambdav) and w⋆(λ)≔arg max⁡w∈Wf(w,λ). \wv^\star(\lambdav) \coloneqq \argmax_{\wv \in \cW} f(\wv, \lambdav). If ff is continuously differentiable in λ\lambdav for all w∈W\wv \in \cW, ∇1f\nabla_1 f is continuous and the maximum w⋆(λ)\wv^\star(\lambdav) is unique, then the function hh is differentiable with gradient ∇h(λ)=∇2f(w⋆(λ),λ). \nabla h(\lambdav) = \nabla_2 f(\wv^\star(\lambdav), \lambdav).

Compared to Bertsekas’ theorem, Rockafellar’s theorem does not require ff to be concave in w\w, but it requires stronger assumptions on the differentiability of ff.

11.2.3 Danskin’s theorem

Finally, we state Danskin’s original theorem (Danskin, 1966).

Theorem 11.4 (Danskin’s theorem)

Let W\cW be a compact topological space. Let f ⁣:W×Λ→Rf \colon \cW \times \Lambda \to \R be continuous and continuously differentiable with respect to λ∈Λ\lambdav \in \Lambda. Let the value function and the set of maximizers be defined as h(λ)≔max⁡w∈Wf(w,λ)andW⋆(λ)≔arg max⁡w∈Wf(w,λ). h(\lambdav) \coloneqq \max_{\wv \in \cW} f(\wv, \lambdav) \quad \text{and} \quad \cW^\star(\lambdav) \coloneqq \argmax_{\wv \in \cW} f(\wv, \lambdav). Then, the directional derivative of hh at λ∈Λ\lambdav \in \Lambda in direction d∈Λ\dv \in \Lambda, denoted h′(λ;d)h'(\lambdav; \dv), exists and is given by h′(λ;d)=max⁡w∈W⋆(λ)⟨∇2f(w,λ),d⟩. h'(\lambdav; \dv) = \max_{\wv \in \cW^\star(\lambdav)} \langle \nabla_2 f(\wv, \lambdav), \dv \rangle.

We sum up envelope theorems and their assumptions in Table 11.1.

Table 11.1: Comparison of different envelope theorems.

Theorem Unique w⋆\wv^\star? Concave in w\w? Smooth in w\wv? Result
Danskin No No No Dir. Deriv.
Bertsekas Yes Yes No Gradient
Rockafellar Yes No Yes Gradient

11.3 Implicit function theorem

11.3.1 Univariate functions

The implicit function theorem (IFT) provides conditions under which an implicit relationship of the form F(w,λ)=0F(w, \lambda) = 0 can be rewritten as a function w=w⋆(λ)w = w^\star(\lambda) locally, and provides a way to compute its derivative w.r.t. λ\lambda.

Theorem 11.5 (Implicit function theorem, univariate case)

Let
F ⁣:R×R→RF \colon \R \times \R \to \R. Assume F(w,λ)F(w, \lambda) is a continuously differentiable function in a neighborhood U\cU of (w0,λ0)(w_0, \lambda_0) such that F(w0,λ0)=0F(w_0, \lambda_0) = 0 and ∂1F(w0,λ0)≠0\partial_1 F(w_0, \lambda_0) \neq 0. Then there exists a neighborhood V⊆U\cV \subseteq \cU of (w0,λ0)(w_0, \lambda_0) in which there is a function w⋆(λ)w^\star(\lambda) such that

  • w⋆(λ0)=w0w^\star(\lambda_0) = w_0,

  • F(w⋆(λ),λ)=0F(w^\star(\lambda), \lambda) = 0 for all λ\lambda in the neighborhood V\cV,

  • ∂w⋆(λ)=−∂2F(w⋆(λ),λ)∂1F(w⋆(λ),λ)\partial w^\star(\lambda) = -\frac{\partial_2 F(w^\star(\lambda), \lambda)}{ \partial_1 F(w^\star(\lambda), \lambda)}.

We postpone the proof to the multivariate case and begin with a classical example of application of the theorem.

Figure 11.3: The circle equation F(x,y)≔x2+y2−1=0F(x, y) \coloneqq x^2 + y^2 - 1 = 0 is not a function from y∈[−1,1]y \in [-1, 1] to x∈[−1,1]x \in [-1, 1], as there are always two possible xx values, x=1−y2x = \sqrt{1 - y^2} or x=−1−y2x = -\sqrt{1 - y^2}. However, locally around some point (x0,y0)(x_0, y_0), e.g., such that x0>0x_0 > 0 and y0>0y_0 > 0 (upper-right quadrant), the function x=x⋆(y)=1−y2x = x^\star(y) = \sqrt{1 - y^2} is well-defined. The implicit function theorem gives conditions for such a function to exist locally and provides a way to compute its derivative.

Example 11.4 (Equation of the unit circle)

We use w≡xw \equiv x and λ≡y\lambda \equiv y for clarity. Let F(x,y)≔x2+y2−1F(x, y) \coloneqq x^2 + y^2 - 1. In general, we cannot rewrite the unit circle equation F(x,y)=0F(x, y) = 0 as a function from yy to xx, because for every y∈[−1,1]y \in [-1, 1], there are always two possible xx values, namely, x=1−y2x = \sqrt{1 - y^2} or x=−1−y2x = -\sqrt{1 - y^2}. However, locally around some point (x0,y0)(x_0, y_0), e.g., such that x0>0x_0 > 0 and y0>0y_0 > 0 (upper-right quadrant), the function x=x⋆(y)=1−y2x = x^\star(y) = \sqrt{1 - y^2} is well-defined. Using ∂1F(x,y)=2x\partial_1 F(x, y) = 2x and ∂2F(x,y)=2y\partial_2 F(x, y) = 2y, we get ∂x⋆(y)=−∂2F(x⋆(y),y)∂1F(x⋆(y),y)=−2y2x⋆(y)=−y1−y2\partial x^\star(y) = -\frac{\partial_2 F(x^\star(y), y)}{\partial_1 F(x^\star(y), y)} = - \frac{2y}{2 x^\star(y)} = -\frac{y}{\sqrt{1 - y^2}} in that neighborhood (the upper right quadrant in this case). This is indeed the same derivative expression as if we used the chain rule on 1−y2\sqrt{1 - y^2} and is well-defined on y∈[0,1)y \in [0, 1).

In the above simple example, we can easily derive an explicit function relating yy to xx in a given neighborhood, but this is not always the case. The IFT gives us conditions guaranteeing that such function exists and a way to differentiate it, but not a way to construct such a function. In fact, finding w⋆(λ)w^\star(\lambda) such that F(w⋆(λ),λ)=0F(w^\star(\lambda), \lambda) = 0 typically involves a root finding algorithm, an optimization algorithm, a nonlinear system solver, etc.

Example 11.5 (Polynomial)

Let F(w,λ)=w5+w3+w−λF(w, \lambda) = w^5 + w^3 + w - \lambda. According to the Abel-Ruffini theorem (Tignol, 2015), quintics (polynomials of degree 55) do not enjoy roots in terms of radicals and one must resort to numerical root finding. In addition, odd-degree polynomials have real roots. Moreover, ∂1F(w,λ)=5w4+3w2+1\partial_1 F(w, \lambda) = 5w^4 + 3w^2 + 1 is strictly positive. Therefore, by the intermediate value theorem, there must be only one root w⋆(λ)w^\star(\lambda) such that F(w⋆(λ),λ)=0F(w^\star(\lambda), \lambda) = 0. This unique root can for example be found by bisection. Using the IFT, its derivative is found to be ∂w⋆(λ)=(5w⋆(λ)4+3w⋆(λ)2+1)−1\partial w^\star(\lambda) = (5w^\star(\lambda)^4 + 3 w^\star(\lambda)^2 + 1)^{-1}.

While an implicit function is differentiable at a point if the assumptions of the IFT hold in a neighborhood of that point, the reciprocal is not true: failure of the IFT assumptions does not necessarily mean that the implicit function is not differentiable, as we now illustrate.

Example 11.6 (IFT conditions are not necessary for differentiability)

Consider F(w,λ)=(w−λ)2F(w, \lambda) = (w - \lambda)^2. We clearly have that F(w⋆(λ),λ)=0F(w^\star(\lambda), \lambda) = 0 if we define w⋆(λ)=λw^\star(\lambda) = \lambda, the identity function. It is clearly differentiable for all λ\lambda, yet the assumptions of the IFT fail, since we have ∂1F(w,λ)=2(w−λ)\partial_1 F(w, \lambda) = 2(w-\lambda) and therefore ∂1F(0,0)=0\partial_1 F(0, 0) = 0.

11.3.2 Multivariate functions

We now present the IFT in the general multivariate setting. Informally, if F(w⋆(λ),λ)=0F(\w^\star(\lambdav), \lambdav) = \zeros, then by the chain rule, we have ∂1F(w⋆(λ),λ)∂w⋆(λ)+∂2F(w⋆(λ),λ)=0, \partial_1 F(\w^\star(\lambdav), \lambdav) \partial \w^\star(\lambdav) + \partial_2 F(\w^\star(\lambdav), \lambdav) = \zeros, meaning that the Jacobian ∂w⋆(λ)\partial \w^\star(\lambdav), assuming that it exists, satisfies −∂1F(w⋆(λ),λ)∂w⋆(λ)=∂2F(w⋆(λ),λ). -\partial_1 F(\w^\star(\lambdav), \lambdav) \partial \w^\star(\lambdav) = \partial_2 F(\w^\star(\lambdav), \lambdav). The IFT gives us conditions for the existence of ∂w⋆(λ)\partial \w^\star(\lambdav).

Theorem 11.6 (Implicit function theorem, multivariate case)

Let us define F ⁣:W×Λ→WF \colon \cW \times \Lambda \to \cW. Assume F(w,λ)F(\wv, \lambdav) is a continuously differentiable function in a neighborhood of (w0,λ0)(\wv_0, \lambdav_0) such that F(w0,λ0)=0F(\wv_0, \lambdav_0) = \zeros and ∂1F(w0,λ0)\partial_1 F(\wv_0, \lambdav_0) is invertible, i.e., its determinant is nonzero. Then there exists a neighborhood of λ0\lambdav_0 in which there is a function w⋆(λ)\wv^\star(\lambdav) such that

  • w⋆(λ0)=w0\wv^\star(\lambdav_0) = \wv_0,

  • F(w⋆(λ),λ)=0F(\wv^\star(\lambdav), \lambdav) = \zeros for all λ\lambdav in the neighborhood,

  • −∂1F(w⋆(λ),λ)∂w⋆(λ)=∂2F(w⋆(λ),λ)-\partial_1 F(\wv^\star(\lambdav), \lambdav) \partial \wv^\star(\lambdav) = \partial_2 F(\wv^\star(\lambdav),\lambdav)

      ⟺  ∂w⋆(λ)=−∂1F(w⋆(λ),λ)−1∂2F(w⋆(λ),λ). \iff \partial \wv^\star(\lambdav) = -\partial_1 F(\wv^\star(\lambdav), \lambdav)^{-1} \partial_2 F(\wv^\star(\lambdav), \lambdav).

We begin with a simple unconstrained optimization algorithm.

Example 11.7 (Unconstrained optimization)

Assume we want to differentiate through w⋆(λ)=arg min⁡w∈RPf(w,λ)\wv^\star(\lambdav) = \argmin_{\wv \in \R^P} f(\wv, \lambdav), where ff is strictly convex in w\wv, which ensures that the solution is unique. From the stationary conditions, if we define F(w,λ)≔∇1f(w,λ)F(\wv, \lambdav) \coloneqq \nabla_1 f(\wv, \lambdav), then w⋆(λ)\wv^\star(\lambdav) is uniquely characterized as the root of FF in the first argument, i.e., F(w⋆(λ),λ)=0F(\wv^\star(\lambdav), \lambdav) = \zeros. We have ∂1F(w,λ)=∇12f(w,λ)\partial_1 F(\wv, \lambdav) = \nabla^2_1 f(\wv, \lambdav), the Hessian of ff in w\wv, and ∂2F(w,λ)=∂2∇1f(w,λ)\partial_2 F(\wv, \lambdav) = \partial_2 \nabla_1 f(\wv, \lambdav), the cross derivatives of ff in w\wv and λ\lambdav. Therefore, assuming that the Hessian is well-defined and invertible at (w⋆(λ),λ)(\wv^\star(\lambdav), \lambdav), we can use the IFT to differentiate through w⋆(λ)\wv^\star(\lambdav) and obtain ∂w⋆(λ)=−(∇12f(w⋆(λ),λ))−1∂2∇1f(w⋆(λ),λ)\partial \wv^\star(\lambdav) = -(\nabla^2_1 f(\wv^\star(\lambdav), \lambdav))^{-1} \partial_2 \nabla_1 f(\wv^\star(\lambdav), \lambdav).

Next, we generalize the previous example, by allowing constraints in the optimization problem.

Example 11.8 (Constrained optimization)

Now, assume we want to differentiate through w⋆(λ)=arg min⁡w∈Cf(w,λ)\wv^\star(\lambdav) = \argmin_{\wv \in \cC} f(\wv, \lambdav), where ff is strictly convex in w\wv and C⊆W\cC \subseteq \cW is a convex set. A solution is characterized by the fixed point equation w⋆(λ)=PC(w⋆(λ)−η∇1f(w⋆(λ),λ))\wv^\star(\lambdav) = P_\cC(\wv^\star(\lambdav) - \eta \nabla_1 f(\wv^\star(\lambdav), \lambdav)), for any η>0\eta > 0, where P(y)≔arg min⁡x∈C∥x−y∥22P(\yv) \coloneqq \argmin_{\xv \in \cC} \|\xv - \yv\|_2^2 is the Euclidean projection of y\yv onto C\cC. Therefore, w⋆(λ)\wv^\star(\lambdav) is the root of F(w,λ)=w−PC(w−η∇1f(w,λ))F(\wv, \lambdav) = \wv - P_\cC(\wv - \eta \nabla_1 f(\wv, \lambdav)) (see Chapter 16). We can differentiate through w⋆(λ)\wv^\star(\lambdav) using the IFT, assuming that the conditions of the theorem apply. Note that ∂1F(w,λ)\partial_1 F(\wv, \lambdav) requires the expression of the Jacobian ∂PC(y)\partial P_\cC(\yv). Fortunately, PC(y)P_\cC(\yv) and its Jacobian are easy to compute for many sets C\cC (Blondel et al., 2021).

11.3.3 JVP and VJP of implicit functions

To integrate an implicit function w⋆(λ)\w^\star(\lambdav) in an autodiff framework, we need to be able to compute its JVP or VJP. This is the purpose of the next proposition.

Proposition 11.1 (JVP and VJP of implicit functions)

Let w⋆ ⁣:Λ→W\wv^\star \colon \Lambda \to \cW be a function implicitly defined as the solution of F(w⋆(λ),λ)=0F(\wv^\star(\lambdav), \lambdav) = \zeros, for some function F ⁣:W×Λ→WF \colon \cW \times \Lambda \to \cW. Define A≔−∂1F(w⋆(λ),λ)B≔∂2F(w⋆(λ),λ).\begin{align*} A & \coloneqq -\partial_1 F(\w^\star(\lambdav), \lambdav) \\ B & \coloneqq \partial_2 F(\w^\star(\lambdav),\lambdav). \end{align*} Assume the assumptions of the IFT hold. The JVP t≔∂w⋆(λ)v\t \coloneqq \partial \wv^\star(\lambdav) \v in the input direction v∈Λ\v \in \Lambda is obtained by solving the linear system At=Bv. A \t = B \v. The VJP ∂w⋆(λ)∗u\partial \wv^\star(\lambdav)^* \u in the output direction u∈W\u \in \cW is obtained by solving the linear system A∗r=u. A^* \r = \u. Using the solution r\r, we get ∂w⋆(λ)∗u=∂w⋆(λ)∗A∗r=B∗r. \partial \wv^\star(\lambdav)^* \u = \partial \wv^\star(\lambdav)^* A^* \r = B^*\r.

Note that in the above linear systems, we can access AA and BB as linear maps, the JVPs of FF. Their adjoints, A∗A^* and B∗B^*, correspond to the VJPs of FF. To solve these systems, we can therefore use matrix-free solvers as detailed in Section 9.4. For example, when AA is symmetric positive semi-definite, we can use the conjugate gradient method (Hestenes et al., 1952). When AA is not symmetric positive definite, we can use GMRES (Saad and Schultz, 1986) or BiCGSTAB (Vorst and Vorst, 1992).

11.3.4 Proof of the implicit function theorem

We prove the theorem using the inverse function theorem presented in Theorem 11.7. Define f(λ,w)=(λ,F(w,λ)) f(\lambdav, \w) = (\lambdav, F(\w, \lambdav)) which goes from RQ×RP\RR^Q \times \RR^P onto RQ×RP\RR^Q \times \RR^P. The Jacobian of ff is ∂f(λ,w)=(I⁡0∂2F(w,λ)∂1F(w,λ)). \jac f(\lambdav, \w) = \begin{pmatrix} \idm & 0 \\ \jac_2 F(\w, \lambdav) & \jac_1 F(\w, \lambdav) \end{pmatrix}. So at w0,λ0\w_0, \lambdav_0, we have det⁡(∂f(λ0,w0))=det⁡(I⁡)det⁡(∂1F(w0,λ0))≠0\det(\jac f(\lambdav_0, \w_0)) = \det(\idm)\det( \jac_1 F(\w_0, \lambdav_0)) \neq 0 since we assumed ∂1F(w0,λ0)\partial_1 F(\wv_0, \lambdav_0) invertible. By the inverse function theorem, the function ff is then invertible in a neighborhood NN of f(λ0,w0)=(λ0,0)f(\lambdav_0, \w_0) = (\lambdav_0, \zeros). In particular, it is invertible in N∩{(λ,0),λ∈RQ}N \cap \{(\lambdav, \zeros), \lambdav \in \RR^Q\}. The solution of the implicit equation in a neighborhood of λ0\lambdav_0 is then (λ,w∗(λ))=f−1(λ,0)( \lambdav, \w^*(\lambdav)) = f^{-1}(\lambdav, \zeros). By the inverse function theorem, f−1f^{-1} is continuously differentiable inverse and so is w∗(λ)\w^*(\lambdav). The derivative ∂w∗(λ)\partial \w^*(\lambdav) is obtained from the differential of the inverse as (∼∼∂w∗(λ)∼)=∂f−1(λ,0), \begin{pmatrix} \sim & \sim \\ \partial \w^*(\lambdav) & \sim \end{pmatrix} = \partial f^{-1}(\lambdav, \zeros), and by the inverse function theorem, we have ∂f−1(λ,0)=(∂f(λ,w∗(λ)))−1. \partial f^{-1}(\lambdav, \zeros) = (\partial f(\lambdav, \w^*(\lambdav)))^{-1}. Using the block matrix inversion formula, we therefore obtain (ABCD)−1=(∼∼−(D−CA−1B)−1CA−1∼), \begin{pmatrix} \A & \B \\ \C & \D \end{pmatrix}^{-1} = \begin{pmatrix} \sim & \sim \\ -(\D - \C\A^{-1}\B)^{-1}\C\A^{-1} & \sim \end{pmatrix}, we get the claimed expression. Though we expressed the proof in terms of Jacobians and matrices, the result naturally holds for the corresponding linear operators, JVPs, VJPs, and their inverses.

11.4 Adjoint state method

11.4.1 Differentiating nonlinear equations

We describe in this section the adjoint state method (a.k.a. adjoint method, method of adjoints, adjoint sensitivity method). The method can be used to compute the gradient of the composition of an explicit function and an implicit function, defined through an equality constraint (e.g., a nonlinear equation). The method dates back to Céa (1986).

Suppose a variable s∈S\s \in \cS (which corresponds to a state in optimal control) is implicitly defined given some parameters w∈W\w \in \cW through the (potentially nonlinear) equation c(s,w)=0c(\s, \w) = \zeros, where c ⁣:S×W→Sc \colon \cS \times \cW \to \cS. Assuming s\s is uniquely determined for all w∈W\w \in \cW, this defines an implicit function s⋆(w)\s^\star(\w) from W\cW to S\cS such that c(s⋆(w),w)=0c(\s^\star(\w), \w) = \zeros. Given an objective function L ⁣:S×W→RL \colon \cS \times \cW \to \RR, the goal of the adjoint state method is then to compute the gradient of L(w)≔L(s⋆(w),w). L(\w) \coloneqq L(\s^\star(\w), \w). However, this is not trivial as s⋆(w)\s^\star(\w) is an implicit function. For instance, this can be used to convert the equality-constrained problem min⁡w∈WL(s,w)s.t.c(s,w)=0.\begin{align*} \min_{\w \in \cW} L(\s, \w) \quad \text{s.t.} \quad c(\s, \w) = \zeros. \end{align*} into the unconstrained problem min⁡w∈WL(s⋆(w),w).\begin{align*} \min_{\w \in \cW} L(\s^\star(\w), \w). \end{align*} Access to ∇L(w)\nabla L(\w) allows us to solve this problem by gradient descent.

Proposition 11.2 (Adjoint state method)

Let c:S×W→Sc:\cS \times \cW \rightarrow \cS be a mapping defining constraints of the form c(s,w)c(\s, \w). Assume that for each w∈W\w \in \cW, there exists a unique s⋆(w)\s^\star(\w) satisfying c(s⋆(w),w)=0c(\s^\star(\w), \w)= \zeros and that s⋆(w)\s^\star(\w) is differentiable. The gradient of L(w)≔L(s⋆(w),w), L(\w) \coloneqq L(\s^\star(\w), \w), for some differentiable function L:S×W→RL:\cS \times \cW \rightarrow \RR, is given by ∇L(w)=∇2L(s⋆(w),w)+∂2c(s⋆(w),w)∗r⋆(w), \nabla L(\w) = \nabla_2 L(\s^\star(\w), \w) + \partial_2 c(\s^\star(\w), \w)^* \r^\star(\w), where r⋆(w)\r^\star(\w) is the solution of the linear system ∂1c(s⋆(w),w)∗r=−∇1L(s⋆(w),w). \partial_1 c(\s^\star(\w), \w)^* \r = -\nabla_1 L(\s^\star(\w), \w).

As shown in the proof below, r⋆(w)\r^\star(\w) corresponds to a Lagrange multiplier. The linear system can be solved using matrix-free solvers.

11.4.2 Relation with envelope theorems

Because s\s is uniquely determined for any w∈W\w \in \cW by c(s,w)=0c(\s, \w) = \zeros, we can alternatively rewrite L(w)L(\w) as the trivial minimization or maximization, L(w)=min⁡s∈SL(s,w)s.t.c(s,w)=0=max⁡s∈SL(s,w)s.t.c(s,w)=0.\begin{align*} L(\w) &= \min_{\s \in \cS} L(\s, \w) \quad \text{s.t.} \quad c(\s, \w) = \zeros\\ &= \max_{\s \in \cS} L(\s, \w) \quad \text{s.t.} \quad c(\s, \w) = \zeros. \end{align*} Therefore, the adjoint state method can be seen as an envelope theorem for computing ∇L(w)\nabla L(\w), for the case when w\w is involved in both the objective function and in the equality constraint.

11.4.3 Proof using the method of Lagrange multipliers

Classically, the adjoint state method is derived using the method of Lagrange multipliers. Let us introduce the Lagrangian associated with LL and cc, L(s,w,r)≔L(s,w)+⟨r,c(s,w)⟩, \cL(\s, \w, \r) \coloneqq L(\s, \w) + \langle \r, c(\s, \w) \rangle, where r∈S\r \in \cS is the Lagrange multiplier associated with the equality constraint c(s,w)=0c(\s, \w) = \zeros. In the optimal control literature, r\r is often called the adjoint variable or adjoint state. The gradients of the Lagrangian are ∇sL(s,w,r)=∇1L(s,w)+∂1c(s,w)∗r∇wL(s,w,r)=∇2L(s,w)+∂2c(s,w)∗r∇rL(s,w,r)=c(s,w),\begin{align*} \nabla_\s \cL(\s, \w, \r) &= \nabla_1 L(\s, \w) + \partial_1 c(\s, \w)^* \r \\ \nabla_\w \cL(\s, \w, \r) &= \nabla_2 L(\s, \w) + \partial_2 c(\s, \w)^* \r \\ \nabla_\r \cL(\s, \w, \r) &= c(\s, \w), \end{align*} where ∂ic(s,w)∗\partial_i c(\s, \w)^* are the adjoint operators. Setting ∇rL(s,w,r)\nabla_\r \cL(\s, \w, \r) to zero gives the constraint c(s,w)=0c(\s, \w) = \zeros. Setting ∇sL(s,w,r)\nabla_\s \cL(\s, \w, \r) to zero gives the so-called adjoint state equation ∂1c(s,w)∗r=−∇1L(s,w). \partial_1 c(\s, \w)^* \r = -\nabla_1 L(\s, \w). Solving this linear system w.r.t. r\r at s=s⋆(w)\s = \s^\star(\w) gives the adjoint variable r⋆(w)\r^\star(\w). We then get ∇L(w)=∇2L(s⋆(w),w,r⋆(w))=∇2L(s⋆(w),w)+∂2c(s⋆(w),w)∗r⋆(w),\begin{align*} \nabla L(\w) &= \nabla_2 \cL(\s^\star(\w), \w, \r^\star(\w)) \\ &= \nabla_2 L(\s^\star(\w), \w) + \partial_2 c(\s^\star(\w), \w)^* \r^\star(\w), \end{align*} which concludes the proof.

11.4.4 Proof using the implicit function theorem

A more direct proof is possible thanks to the implicit function theorem (Section 11.3). Using the chain rule, we get ∇L(w)=∇2L(s⋆(w),w)+∂s⋆(w)∗∇1L(s⋆(w),w), \nabla L(\w) = \nabla_2 L(\s^\star(\w), \w) + \partial \s^\star(\w)^* \nabla_1 L(\s^\star(\w), \w), where ∂s⋆(w)∗\partial \s^\star(\w)^* is the VJP of s⋆\s^\star, a linear map from S\cS to W\cW.

Computationally, the main difficulty is to apply ∂s⋆(w)∗\partial \s^\star(\w)^* to the vector u=∇1L(s⋆(w),w)∈S\u = \nabla_1 L(\s^\star(\w), \w) \in \cS. Using the implicit function theorem (Section 11.3) on the implicit function c(s⋆(w),w)=0c(\s^\star(\w), \w) = \zeros, and Proposition 11.1, we get the linear system A∗r=uA^* \r = \u, where A∗≔∂1c(s⋆(w),w)∗A^* \coloneqq \partial_1 c(\s^\star(\w), \w)^* is a linear map from S\cS to S\cS. After solving for r\r, we get ∂s⋆(w)∗u=B∗r\partial \s^\star(\w)^* \u = B^* \r, where B∗≔∂2c(s⋆(w),w)∗B^* \coloneqq \partial_2 c(\s^\star(\w), \w)^* is a linear map from S\cS to W\cW. Putting everything together, we get ∇L(w)=∇2L(s⋆(w),w)+∂2c(s⋆(w),w)∗r. \nabla L(\w) = \nabla_2 L(\s^\star(\w), \w) + \partial_2 c(\s^\star(\w), \w)^* \r.

11.4.5 Reverse mode as adjoint method with backsubstitution

In this section, we revisit reverse-mode autodiff from the perspective of the adjoint state method. For clarity, we focus our exposition on feedforward networks with input x∈X\x \in \cX and network weights w=(w1,…,wk)∈W1×…×WK\w = (\w_1, \ldots, \w_k) \in \cW_1 \times \ldots \times \cW_K, defined by s0≔x∈Xs1≔f1(s0,w1)∈S1⋮sK≔fK(sK−1,wK)∈SKf(w)≔sK.\begin{align*} \s_0 &\coloneqq \x \in \cX \\ \s_1 &\coloneqq f_1(\s_0, \w_1) \in \cS_1 \\ & \hspace{6pt} \vdots \\ \s_K &\coloneqq f_K(\s_{K-1}, \w_K) \in \cS_K \\ f(\w) &\coloneqq \s_K. \tag{11.2}\end{align*} Here we focus on gradients with respect to the parameters w\w, hence the notation f(w)f(\w). We can use the adjoint state method to recover reverse-mode autodiff, and prove its correctness in the process. While we focus for simplicity on feedforward networks, our exposition can be generalized to computation graphs.

Feedforward networks as the solution of a nonlinear equation

While we defined the set of intermediate computations s=(s1,…,sK)∈S1×…×SK\s = (\s_1, \ldots, \s_K) \in \cS_1 \times \ldots \times \cS_K as a sequence of operations, they can also be defined as the unique solution of the nonlinear equation c(s,w)=0c(\s, \w) = \zeros, where c(s,w)≔(s1−f1(x,w1)s2−f2(s1,w2)⋮sK−fK(sK−1,wK)). c(\s, \w) \coloneqq \begin{pmatrix} \s_1 - f_1(\x, \w_1) \\ \s_2 - f_2(\s_1, \w_2) \\ \vdots \\ \s_K - f_K(\s_{K-1}, \w_K) \end{pmatrix}. This defines an implicit function s⋆(w)=(s1⋆(w),…,sK⋆(w))\s^\star(\w) = (\s_1^\star(\w), \ldots, \s_K^\star(\w)), the solution of this nonlinear system, which is given by the variables s1,…,sK\s_1, \ldots, \s_K defined in Eq. (11.2). The output of the feedforward network is then f(w)=sK⋆(w)f(\w) = \s_K^\star(\w).

In machine learning, the final layer sK⋆(w)\s^\star_K(\w) is typically fed into a loss ℓ\ell, to define L(w)≔ℓ(sK⋆(w);y). L(\w) \coloneqq \ell(\s_K^\star(\w); \y). Note that an alternative is to write L(w)L(\w) as L(w)=min⁡s∈Sℓ(s;y)s.t.c(s,w)=0. L(\w) = \min_{\s \in \cS} \ell(\s; \y) \quad \text{s.t.} \quad c(\s, \w) = \zeros.

More generally, if we just want to compute the VJP of sK⋆(w)\s_K^\star(\w) in some direction uK∈SK\u_K \in \cS_K, we can define the scalar-valued function L(w)≔ℓ(sK⋆(w);uK)≔⟨sK⋆(w),uK⟩ L(\w) \coloneqq \ell(\s_K^\star(\w); \u_K) \coloneqq \langle \s_K^\star(\w), \u_K \rangle so that ∂f(w)∗uK=∇L(w). \partial f(\w)^* \u_K = \nabla L(\w). Let us define u∈S1×⋯×SK−1×SK\u \in \cS_1 \times \dots \times \cS_{K-1} \times \cS_K as u≔(0,…,0,∇1ℓ(f(w);y))\u \coloneqq (\zeros, \ldots, \zeros, \nabla_1 \ell(f(\w); \y)) (gradient of the loss ℓ\ell case) or u≔(0,…,0,uK)\u \coloneqq (\zeros, \ldots, \zeros, \u_K) (VJP of ff in the direction uK\u_K case). Using the adjoint state method, we know that the gradient of this objective is obtained as ∇L(w)=∂2c(s(w),w)∗r⋆(w), \nabla L(\w) = \partial_2 c(\s(\w), \w)^* \r^\star(\w), for r⋆(w)\r^\star(\w) the solution of the linear system ∂1c(s(w),w)∗r=−u. \partial_1 c(\s(\w), \w)^* \r = -\u.

Solving the linear system using backsubtitution

The JVP of the constraint function cc at s⋆(w)\s^\star(\w), materialized as a matrix, takes the form of a block lower-triangular matrix ∂1c(s⋆(w),w)=(I⁡0……0−A1I⁡⋱⋮0−A2I⁡⋱⋮⋮⋱⋱⋱00…0−AKI⁡), \jac_1 c(\s^\star(\w), \w) = \begin{pmatrix} \idm & 0 & \dots & \dots & 0 \\ - A_1 & \idm & \ddots & & \vdots\\ 0 & -A_2 & \idm & \ddots & \vdots \\ \vdots & \ddots & \ddots & \ddots & 0 \\ 0 & \dots & 0 & -A_K & \idm \end{pmatrix}, where Ak≔∂1fk(sk−1,wk)A_k \coloneqq \jac_1 f_k(\s_{k-1}, \w_k). Crucially the triangular structure of the JVP stems from the fact that each intermediate activation only depends on the past intermediate activations. Therefore, the constraints, corresponding to the lines of the Jacobian, cannot introduce non-zero values beyond its diagonal. The VJP takes the form of a block upper-triangular matrix ∂1c(s⋆(w),w)∗=(I⁡−A1∗0…00I⁡−A2∗⋱⋮⋮⋱I⁡⋱0⋮⋱⋱−AK∗0……0I⁡). \jac_1 c(\s^\star(\w), \w)^* = \begin{pmatrix} \idm & - A_1^* & 0 & \dots & 0 \\ 0 & \idm & -A_2^* & \ddots & \vdots\\ \vdots & \ddots & \idm & \ddots & 0 \\ \vdots & & \ddots & \ddots & -A_K^* \\ 0 & \dots & \dots & 0 & \idm \end{pmatrix}. Solving an upper triangular system like ∂1c(s(w),w)∗r=u\partial_1 c(\s(\w), \w)^*\r = \u can then be done efficiently by backsubstitution. Starting from the last adjoint state rK=u\r_K = \u, we can compute each adjoint state rk\r_k from that computed at k+1k+1. Namely, for k∈(K−1,…,1)k \in (K-1,\dots,1), we have rk−Ak+1∗rk+1=0  ⟺  rk=∂fk+1(sk,wk+1)∗rk+1.\begin{align*} \r_k - A_{k+1}^*\r_{k+1} = \zeros \iff \r_k = \partial f_{k+1}(\s_k, \w_{k+1})^*\r_{k+1}. \end{align*} The VJPs with respect to the parameters are then obtained by ∂2c(s(w),w)∗r=(∂2f1(x,w1)∗r1∂2f2(s1(w),w2)∗r2⋮∂2fK(sK−1(w),wK)∗rK), \partial_2 c(\s(\w), \w)^* \r = \begin{pmatrix} \partial_2 f_1(\x, \w_1)^* \r_1 \\ \partial_2 f_2(\s_1(\w), \w_2)^* \r_2 \\ \vdots \\ \partial_2 f_K(\s_{K-1}(\w), \w_K)^* \r_K \end{pmatrix}, recovering reverse-mode autodiff.

The Lagrangian perspective of backpropagation for networks with separate parameters w=(w1,…,wK)\w = (\w_1, \dots, \w_K) is well-known; see for instance LeCun (1988) or Recht (2016). The Lagrangian perspective of backpropagation through time (Werbos, 1990) for networks with shared parameter w\w is discussed for instance by Franceschi et al. (2017). Our exposition uses the adjoint state method, which can itself be proved either using the method of Lagrange multipliers (Section 11.4.3) or by the implicit function theorem (Section 11.4.4), combined with backsubtitution for solving the upper-triangular linear system. Past works often minimize over w\w but we do not require this, as gradients are not necessarily used for optimization. Our exposition also supports computing the VJP of any vector-valued function ff, while existing works derive the gradient of a scalar-valued loss function.

11.5 Inverse function theorem

11.5.1 Differentiating inverse functions

In some cases (see for instance Section 12.4.4), it is useful to compute the Jacobian of an inverse function f−1f^{-1}. The inverse function theorem below allows us to relate the Jacobian of f−1f^{-1} with the Jacobian of ff.

Theorem 11.7 (Inverse function theorem)

Assume f ⁣:W→Wf \colon \cW \to \cW is continuously differentiable with invertible Jacobian ∂f(w0)\partial f(\wv_0) at w0\wv_0. Then ff is bijective from a neighborhood of w0\wv_0 to a neighborhood of f(w0)f(\w_0). Moreover, the inverse f−1f^{-1} is continuously differentiable near ω0=f(w0)\omegav_0 = f(\wv_0) and the Jacobian of the inverse ∂f−1(ω)\partial f^{-1}(\omegav) is ∂f(w)∂f−1(ω)=I⇔∂f−1(ω)=(∂f(w))−1, \partial f(\wv) \partial f^{-1}(\omegav)= I \Leftrightarrow \partial f^{-1}(\omegav) = (\partial f(\wv))^{-1}, with w=f−1(ω)\wv = f^{-1}(\omegav).

11.5.2 Link with the implicit function theorem

The inverse function theorem can be used to prove the implicit function theorem; see proof of Theorem 11.6. Conversely, recall that, in order to use the implicit function theorem, we need to choose a root objective F ⁣:W×Λ→WF \colon \cW \times \Lambda \to \cW. If we set W=Λ=RQ\cW=\Lambda=\RR^Q and F(w,ω)=f(w)−ωF(\wv, \omegav) = f(\wv) - \omegav, with f ⁣:RQ→RQf \colon \R^Q \to \R^Q, then we have that the root w⋆(ω)\wv^\star(\omegav) satisfying F(w⋆(ω),ω)=0F(\wv^\star(\omegav), \omegav) = \zeros is exactly w⋆(ω)=f−1(ω)\wv^\star(\omegav) = f^{-1}(\omegav). Moreover, ∂1F(w,ω)=∂f(w)\partial_1 F(\wv, \omegav) = \partial f(\wv) and ∂2F(w,ω)=−I\partial_2 F(\wv, \omegav) = -I. By applying the implicit function theorem with this FF, we indeed recover the inverse function theorem.

11.5.3 Proof of inverse function theorem

We first give a proof of the formula assuming that f−1f^{-1} is well-defined and continuously differentiable in a neighborhood of f(w0)f(\w_0). In that case, we have for any ω\omegav in a neighborhood of f(w0)f(\w_0), f∘f−1(ω)=ω. f \circ f^{-1}(\omegav) = \omegav. Differentiating both sides w.r.t. ω\omegav, we get ∂f(f−1(ω))∂f−1(ω)=I⁡, \partial f(f^{-1}(\omegav)) \partial f^{-1}(\omegav) = \idm, where I⁡\idm is the identity function in RQ\RR^Q. In particular, for w=f−1(ω)\w = f^{-1}(\omegav) we recover the formula presented in the statement.

Now, it remains to show that invertibility of the JVP ensures that the function is invertible in a neighborhood of f(w0)f(\w_0) and that the inverse is continuously differentiable. For that, denote l=∂f(w0)\l=\partial f(\w_0) such that l−1\l^{-1} is well-defined by definition. ff is invertible with continuously differentiable inverse, if and only if l−1(f(w))−f(w0)\l^{-1}(f(\w)) - f(\w_0) is invertible with continuously differentiable inverse. So without loss of generality, we consider ∂f(w0)=I⁡\partial f(\w_0) = \idm, f(w0)=0f(\w_0) = \zeros, w0=0\w_0=\zeros.

As ff is continuously differentiable, there exists a neighborhood N≔{w:∥w−w0∥2≤δ}\cN \coloneqq \{\w: \|\w-\w_0\|_2\leq \delta\} on which we have ∥∂f(w)−I⁡∥2≤1/2\|\partial f(\w) - \idm\|_2\leq 1/2. In this neighborhood, the function g(w)=f(w)−wg(\w) = f(\w) - \w is contractive by the mean value theorem with contraction factor 1/21/2. For any ω\omegav such that ∥ω−f(w0)∥2≤δ/2\|\omegav-f(\w_0)\|_2 \leq \delta/2, the sequence wk+1=wk−f(wk)−ω′\w_{k+1} = \w_k - f(\w_k) - \omegav' remains in N\mathcal{N} and converges (since it is a Cauchy sequence by the contraction of gg) to a unique fixed point w∞\w_\infty satisfying w∞=w∞−f(w∞)−ω  ⟺  f(w∞)=ω\w_\infty = \w_\infty - f(\w_\infty) - \omegav \iff f(\w_\infty) = \omegav. This shows the existence of the inverse in the neighborhood M≔{ω:∥ω−ω0∥2≤δ/2}\cM \coloneqq \{\omegav: \|\omegav-\omegav_0\|_2\leq \delta/2\} of ω0=f(w0)\omegav_0 = f(\w_0) onto N\cN.

We tackle now the differentiability (hence the continuity) of f−1f^{-1}. For any ω\omegav in the neighborhood of ω0\omegav_0 with inverse w≔f−1(ω)∈N\w \coloneqq f^{-1}(\omegav) \in N, the JVP of ff at w\w satisfies by assumption ∥∂f(w)−I⁡∥2≤1/2\|\partial f(\w) - \idm\|_2 \leq 1/2. Hence, a=∂f(w)−I⁡\a = \partial f(\w) -\idm defines a convergent series b=∑k=0+∞ak\b = \sum_{k=0}^{+\infty} \a^k and one verifies easily that b=∂f(w)−1\b = \partial f(\w)^{-1}, that is ∂f(w)\partial f(\w) is invertible and ∥∂f(w)−1∥≤2\|\partial f(\w)^{-1}\|\leq 2. To compute the JVP of the inverse, we consider then ∂f(w)−1 \partial f(\w)^{-1} as the candidate JVP and examine ∥f−1(ω+η)−f(ω)−(∂f(w))−1η∥2∥η∥2. \frac{\|f^{-1}(\omegav + \etav) - f(\omegav) - (\partial f(\w))^{-1}\etav\|_2} {\|\etav\|_2}. Denote then v\v such that f−1(ω+η)=w+vf^{-1}(\omegav + \etav) = \w + \v. As g(w)=f(w)−wg(\w) = f(\w) - \w is 1/21/2-contractive in N\cN, we have ∥v−η∥2=∥g(w+v)−g(w)∥2≤1/2∥v∥2\|\v -\etav\|_2 = \|g(\w + \v) - g(\w)\|_2 \leq 1/2\|\v\|_2. So ∥v∥2≥∥η∥/2\|\v\|_2 \geq \|\etav\|/2. We then get ∥f−1(ω+η)−f(ω)−(∂f(w))−1η∥2∥η∥2=∥v−(∂f(w))−1(f(w+v)−f(w))∥2∥η∥2≤4∥f(w+v)−f(w)−∂f(w)v∥2∥v∥2\begin{align*} & \frac{\|f^{-1}(\omegav + \etav) - f(\omegav) - (\partial f(\w))^{-1}\etav\|_2} {\|\etav\|_2} \\ & = \frac{\|\v - (\partial f(\w))^{-1}(f(\w + \v) - f(\w))\|_2} {\|\etav\|_2} \\ & \leq 4 \frac{\|f(\w+\v) - f(\w) - \partial f(\w)\v\|_2}{\|\v\|_2} \end{align*} As ∥η∥2→0\|\etav\|_2 \rightarrow 0, we have ∥v∥2→0\|\v\|_2 \rightarrow 0 and so ∥f(w+v)−f(w)−∂f(w)v∥2/∥v∥2→0\|f(\w+\v) - f(\w) - \partial f(\w)\v\|_2/\|\v\|_2 \rightarrow 0. Hence, f−1f^{-1} is differentiable with JVP ∂f−1(ω)=(∂f(w))−1=(∂f(f−1(ω)))−1\partial f^{-1}(\omegav) = (\partial f(\w))^{-1} = (\partial f(f^{-1}(\omegav)))^{-1}. This shows that f−1f^{-1} is continuous and so ∂f−1(ω)\partial f^{-1}(\omegav) is continuous as a composition of continuous functions.

11.6 Summary