# Lagrange with expectation: Why can we "ignore" the expectation operator?

I am considering a maximization problem:

\begin{align} \max_{p(\theta),K} \mathbb E[S(p(\theta),\theta) - c D(p(\theta),\theta)] \end{align}

subject to the constraint

\begin{align} D(p(\theta),\theta)\leq K \ \ \forall\theta \ \ \ (\lambda(\theta)). \end{align} For which it is stated that the Lagrangian is

$$\mathcal L = \mathbb E[S(p(\theta),\theta) - c D(p(\theta),\theta) + \lambda(\theta)(K - D(p(\theta),\theta))] - rK.$$

It is then stated that the first-order conditions are

\begin{align} (1) &\ \ \frac{\partial \mathcal L}{\partial p(\theta)} = \frac{\partial S(p(\theta),\theta)}{\partial p(\theta)} - (c + \lambda(\theta)) \frac{\partial D(p(\theta),\theta)}{\partial p(\theta)}=0 \\[8pt] (2) &\ \ \frac{\partial \mathcal L}{\partial K} = \mathbb E[\lambda(\theta)] - r= 0. \end{align}

It is assumed that $$\theta$$ is random hence the expectation and $$\theta \in (0,\infty)$$ for some distribution $$\theta \sim F(\theta)$$.

My question is:

Why can the expectation operator be "ignored" for deriving (1) but not for (2)?

Also, it would be nice to get an explanation for

Why the constraint is included within the expectation operator?

and perhaps being pointed to some good references for some lecture notes teaching these techniques. I am currently reading this note to see if that solves the problem for me.

The source of the maximization problem is Thomas-Olivier Léautier (2018) 'Imperfect Markets and Imperfect Regulation. An Introduction to the Microeconomics and Political Economy of Power Markets' page 65

• The expression in (1) is a point-wise maximisation whilst the condition in (2) is not point-wise. Additionally, the constraint holds for all $\theta$, not just one, which is why we need to integrate over all of the constraints, i.e, why we need to take the expectation over the constraint. Commented Jul 12 at 17:50
• Yes, that makes sense ... So being point-wise the choice of maximizing $p(\theta)$ for some $\theta$ does not depend on how the function behaves elsewhere - read in any other $\theta$. And similarly in a discrete analogue with only two values of $\theta$ - $\theta_1$ and $\theta_2$ - differentiating with respect to $p(\theta_1)$ nullifies the part of the expectation concerned with $p(\theta_2)$?! - if I get what you are saying. Commented Jul 12 at 18:25
• That is the "bite" of the Lagrange multiplier method; all the dependency of $p(\theta_1)$ on $p(\theta_2)$ (and vice versa) is moved to the co-state $\lambda(\theta)$. The $\lambda(\theta)$ term is effectively a penalty for the effect that changing one $p(\theta_i)$ value has on the other $p(\theta_j)$'s. Commented Jul 13 at 7:02
• Hi Joseph: Do you know of anything that expounds on your comment immediately above. I've read about lagrange multipliers ( over the years, off and on ) but never saw it described that way and it's interesting. Thanks. Oh, textbook or reference is great. Commented Jul 18 at 19:38
• Can you provide the source of the maximization problem? The note you link to is also not accessible (link expired). Commented Jul 18 at 21:56

I think the problem you’re having is that you’re solving for the optimal $$p$$ as a standard multivariable optimisation problem. There is a noticeable difference between functional optimisation compared with multivariate optimisation, but this difference is often ignored in economics in favour of heuristic methods.

In the problem you stated, we need to find the optimal $$\textit{function}$$ $$p:(0,\infty)\to \mathbb{R}$$ along with an optimal value of a $$\textit{variable}$$ $$K$$. Your first question likely stems from this difference.

The Lagrangian is $$\mathcal{L}=\mathbb{E}[S(p(\theta),\theta)-cD(p(\theta),\theta)+\lambda(\theta)(K-D(p(\theta),\theta))]-rK$$ The reason we have $$\lambda(\theta)$$ inside the expectation is that we have the constraint $$D(p(\theta),\theta)\leq K$$ holding for all $$\theta$$. If $$\theta$$ were drawn from some finite set $$\Theta$$, we would have the Lagrangian as $$\mathcal{L}=\sum_{\theta'\in \Theta}[S(p(\theta'),\theta')-cD(p(\theta'),\theta')+\lambda(\theta')(K-D(p(\theta'),\theta'))]\mathbb{P}(\theta=\theta')-rK$$ which may be more familiar. The integral simply generalises this to the case when $$\Theta$$ is a continuum. It is also intuitive that the constraint should be within the expectation operator as it is a stochastic constraint. We know that for any $$\theta$$ realisation the constraint will bind, but since we don't know what value $$\theta$$ will take we consider an expectation over the possible realisations of the constraint.

Now we can move on to the optimisation problem.

Consider the variable optimisation problem, i.e., the choice of $$K$$. Taking the FOC of $$\mathcal{L}$$ w.r.t. $$K$$, we find (assuming regularity conditions on $$S$$ and $$D$$ allowing us to differentiate under the integral) that \begin{align*} \frac{\partial \mathcal{L}}{\partial K} &=\frac{\partial }{\partial K}[\mathbb{E}[S(p(\theta),\theta)-cD(p(\theta),\theta)+\lambda(\theta)(K-D(p(\theta),\theta))]-rK] \\ &= \mathbb{E}\left[\frac{\partial }{\partial K}(S(p(\theta),\theta)-cD(p(\theta),\theta)+\lambda(\theta)(K-D(p(\theta),\theta)))\right]-r \\ &= \mathbb{E}[\lambda(\theta)]-r \end{align*}

Second, for the functional optimisation problem, we should really take a variational approach. This answer by tdm gives a good overview of the methodology: FOCs for the Dixit-Stiglitz aggregator: derivative of an integral w.r.t. integrand at one point . Suppose we are given an optimal function choice $$p^*$$. Consider perturbing this optimal choice by any other $$C^1$$ function $$g$$ to $$p^*+\varepsilon g$$. Define $$\mathcal{L}(f)=\mathbb{E}[S(f(\theta),\theta)-cD(f(\theta),\theta)+\lambda(\theta)(K-D(f(\theta),\theta))]-rK$$ Since $$p^*$$ is optimal, we must have that $$\frac{\partial}{\partial \varepsilon} \mathcal{L}(p^*+\varepsilon g)\Bigg|_{\varepsilon=0}=0$$ Evaluation of this gives \begin{align*} 0 &= \frac{\partial}{\partial \varepsilon} \mathcal{L}(p^*+\varepsilon g)\Bigg|_{\varepsilon=0} \\ &=\frac{\partial}{\partial \varepsilon} [\mathbb{E}[S(p^*(\theta)+\varepsilon g(\theta),\theta)-cD(p^*(\theta)+\varepsilon g(\theta),\theta)+\lambda(\theta)(K-D(p^*(\theta)+\varepsilon g(\theta),\theta))]-rK]\Bigg|_{\varepsilon=0} \\ &=\frac{\partial}{\partial \varepsilon} [\mathbb{E}[S(p^*(\theta)+\varepsilon g(\theta),\theta)-cD(p^*(\theta)+\varepsilon g(\theta),\theta)+\lambda(\theta)(K-D(p^*(\theta)+\varepsilon g(\theta),\theta))]]\Bigg|_{\varepsilon=0}\\ &=\mathbb{E}\left[\frac{\partial}{\partial \varepsilon}(S(p^*(\theta)+\varepsilon g(\theta),\theta)-cD(p^*(\theta)+\varepsilon g(\theta),\theta)+\lambda(\theta)(K-D(p^*(\theta)+\varepsilon g(\theta),\theta)))\right]\Bigg|_{\varepsilon=0} \\ &=\mathbb{E}\left[\frac{\partial S}{\partial p}(p^*(\theta)+\varepsilon g(\theta),\theta)g(\theta)-(c+\lambda(\theta))\frac{\partial D}{\partial p}(p^*(\theta)+\varepsilon g(\theta),\theta)g(\theta) \right]\Bigg|_{\varepsilon=0} \\ &= \mathbb{E}\left[\left(\frac{\partial S}{\partial p}(p^*(\theta)+\varepsilon g(\theta),\theta)-(c+\lambda(\theta))\frac{\partial D}{\partial p}(p^*(\theta)+\varepsilon g(\theta),\theta)\right)g(\theta) \right]\Bigg|_{\varepsilon=0} \\ &= \mathbb{E}\left[\left(\frac{\partial S}{\partial p}(p^*(\theta),\theta)-(c+\lambda(\theta))\frac{\partial D}{\partial p}(p^*(\theta),\theta)\right)g(\theta) \right] \end{align*}

The above is equal to zero for any $$g\in C^1$$. Hence, assuming $$S$$ and $$D$$ are continuous (and that the optimal $$p^*$$ is continuous), by the Fundamental Lemma of the Calculus of Variations, we must have $$\frac{\partial S}{\partial p}(p^*(\theta),\theta)-(c+\lambda(\theta))\frac{\partial D}{\partial p}(p^*(\theta),\theta)=0$$

What I meant in the comments about this being pointwise is that we can get the exact same result if we ignore the the expectation operator in $$\mathcal{L}$$ and take the derivative w.r.t. $$p(\theta)$$ for a fixed $$\theta$$. Generally this is acceptable if derivatives of $$p(\theta)$$ are not included in $$\mathcal{L}$$. If the first derivative is included, we can use the Euler-Lagrange equation to get a first-order condition.

• Thank you for the answer. It makes sense and the argumentation is convincing to me. Just like your comments. I am, however, not the one to judge whether this constitutes a mathematically sound proof. If no one else has anything to add on the matter I will definitely accept your answer. Thx. again for taking the time to write this up. Commented Jul 22 at 8:20
• No problem. One last bother on this: Do you know of a reference that talks about where Joseph mentions: "That is the "bite" of the Lagrange Multiplier method in the comments at the top. It sounds like an interesting way to think about it especially because I'm used to the standard marginal cost-shadow price argument. Thanks. Commented Jul 22 at 15:07
• This answer (and also the question, +1 both) is very interesting, as it points out a distinction that in mathematics is far from trivial, the difference between optimization in usual calculus and the optimizations problems in which we must choose not the value of a variable, but a whole function, as in the calculus of variations. Commented Jul 22 at 16:11
• In addition, we have here a stochastic context, that is stochastic processes, and therefore we are talking about stochastic calculus of variations, which it is also called Mallavin calculus en.wikipedia.org ams.org/journals/bull/2007-44-03/S0273-0979-07-01146-9/…. And also this is not a trivial generalization of calculus of variations. I wonder if @Joseph Basford could suggest an introductory text to this part of the theory of stochastic processes. Commented Jul 22 at 16:13
• @BakerStreet thank you for your comments. What you’ve said betrays an assumption I’d accidentally hidden in my answer. I had assumed that $\theta$ was drawn from an absolutely continuous distribution, such that it admitted a probability density function, $f$ which was everywhere strictly positive. This fact is crucial for the derivation. If F admits no density, differentiation under the integral is not direct. Also, if the density is not everywhere positive, the FOC is multiplied by $f(\theta)$, so that when it is zero, we can pick $p(\theta)$ arbitrarily. Commented Jul 22 at 18:16