<blockquote>
  <p>If you treat $c_2$ as if it is a random variable, then the derivative of
  $E[u(c_2)]$ with respect to $c_2$ gives zero.</p>
</blockquote>

<p>Why? Such an assertion doesn't follow from anywhere. The subtleties lie elsewhere. The problem with the Lagrangian considered by the OP </p>

<p>$$\mathcal{L} = u(c_1) + \mathbb{E}[u(c_2)] + \lambda(c_2 - f(c_1,Z))$$</p>

<p>is that it <em>also</em> is a random variable since now $Z$ appears <em>outside</em> the expected value (The direct substitution approach followed by maximization with respect to $c_1$ only, does not create any such issues).</p>

<p>Now, do we /  can we maximize a random variable? Well, no, because the essential characteristic of a random variable is that it is a function whose value cannot be set by command and control.</p>

<p>But one could say "ok, let's pretend that this Lagrangian is not a random variable, and just write down the conditions for maximization, even though we know that we can't force the solution".</p>

<p>But this won't work: if one attempts to do it one will eventually obtain</p>

<p>$$u'(c_1) + \mathbb{E}\left[u'(f(c_1,Z))\right] \cdot  \frac{\partial f(c_1,Z)}{\partial c_1} = 0 $$</p>

<p>which is <em>not</em> the same as the condition obtained through direct substitution, because here the partial derivative is <em>outside</em> the expected value.</p>

<p>(for those who may think "hey, then how do we apply maximization procedures in the maximum likelihood approach" the answer is that there, nothing is random anymore when we get to apply the maximization steps).</p>

CC BY-SA 3.0
2016-09-24T17:33:41.683Z
2016-09-24T17:33:41.683Z
Alecos Papadopoulos
<p>This is not an answer, for that see <a href="https://economics.stackexchange.com/a/13521/1601">Alecos's answer</a>. The point of this post is to clarify that the question relies on the false assumption
$$
\frac{d \ E(c_2)}{d \ c_2} = 0 
$$
by way of an example. Consider the random variable that I get by rolling a six sided die and multiplying the result $X$ by a positive integer $n$. The expected value of this is
$$
E(n \cdot X) = n \cdot \frac{7}{2}.
$$
Would you claim that
$$
\frac{d \ E(n \cdot X)}{d \ n} = 0
$$
because "Taking the derivative of the expectation [...] with respect to anything gives zero, since the expectation [...] is just a constant"?</p>

CC BY-SA 3.0
2016-09-25T11:06:14.607Z
2016-09-25T12:50:37.837Z
2017-04-13T12:51:38.253Z
Giskard
<p>To solve this with the exact constraint given in the question, one could set up the following Lagrangian:</p>

<p><span class="math-container">$\mathcal{L}(c_{1},\lambda(\cdot))=u\left(c_{1}\right)+\int u\left(c_{2}\left(z\right)\right)g(z)\mathrm{d}z-\int\lambda(z)\left\{ f\left(c_{1},z\right)-c_{2}\left(z\right)\right\} \mathrm{d}z,$</span></p>

<p>where <span class="math-container">$g(z)$</span> is the probability density function for the random variable <span class="math-container">$Z$</span>, and <span class="math-container">$\lambda(z)$</span> is the Lagrange multiplier corresponding to any value <span class="math-container">$z$</span>.</p>

<p>First-order conditions for the functions <span class="math-container">$c_2$</span> and <span class="math-container">$\lambda$</span> and for the scalar <span class="math-container">$c_1$</span> then are:</p>

<ul>
<li><span class="math-container">$\forall z:\lambda(z)=-u^\prime (c_2(z))g(z)$</span></li>
<li><span class="math-container">$\forall z: f(c_1,z)=c_2(z)$</span></li>
<li><span class="math-container">$u^\prime(c_1)-\int\lambda(z)\frac{\partial{f}}{\partial{c_1}}g(z)\mathrm{d}z=0\Leftrightarrow u^\prime(c_1)+\int u^\prime(c_2(z))\frac{\partial{f}}{\partial{c_1}}g(z)\mathrm{d}z$</span></li>
</ul>

<p>The last condition corresponds to what bobhawke found using the substitution method. Steven finds the same solution, but imposing equality of the distribution functions does not correspond exactly to what is asked.</p>

CC BY-SA 4.0
2020-04-17T10:43:15.897Z
2020-04-17T10:43:15.897Z
Scindapsus
<p>Answer first:</p>

<p>The `objective function' is in fact a functional. The task is to find a pdf $g(y)$ folowed by $c_2$ and a real number $c_1$ that maximise the following Lagrangian</p>

<p>$$ \mathcal{L}(c_1, g) = u(c_1) + \int u(x)g(x) \mathrm{d}x + \int \lambda(y)  \left[ g(y) - \eta(c_1, y)  \right] \mathrm{d}y. $$</p>

<p>Here, $\eta(c_1, y)$ is the pdf followed by the random variable $f(c_1, Z)$. $\lambda(y)$ is a Lagrange multiplier, used to enforce the constraint $g(y)=\eta(c_1,y)$. All integrals are over $\mathbb{R}$. The first order conditions are</p>

<p>$$ u'(c_1) - \frac{\partial}{\partial c_1} \int \lambda(y) \eta(c_1,y) \mathrm{d} y =0, \\
u(y) + \lambda(y) =0, \\
g(y) - \eta(c_1, y) = 0.  \\
   $$</p>

<p>Combining the first two gives</p>

<p>$$ u'(c_1) + \frac{\partial}{\partial c_1} \int u(y) \eta(c_1,y) \mathrm{d} y =0. $$</p>

<p>Now using the 'law of the unconscious statistician' gives</p>

<p>$$ u'(c_1) + \frac{\partial}{\partial c_1} \int u(f(c_1,z)) \phi(z) \mathrm{d} z =0 \\
\Rightarrow u'(c_1) + \int u'(f(c_1,z)) \frac{\partial f(c_1,z)}{\partial c_1} \phi(z) \mathrm{d} z =0 .$$
Here, $\phi(z)$ is the pdf followed by the random variable $Z$. This is equivalent to the solution given by OP.</p>

<hr>

<p>Now I want to address a few other things. I would ideally do this in the comments, but I don't have enough reputation to comment.</p>

<p>First of all, I am OP. I really am at a loss as to why I couldn't log in with original credentials. Still trying to figure that one out.</p>

<p>As denesp points out, I wrote an answer not so long ago which I immediately deleted. I did this for a few reasons:</p>

<ol>
<li>I didn't actually answer the question in that post.</li>
<li>I was on the bus at the time, typing on my phone. The formatting I had wasn't correct, and the wording was very loose. I wanted to take more time over it and give a better and more precise answer. So, for example, some of denesp's comments are directed at imprecise wording in a post I deleted.</li>
</ol>

<p>To address denesp's comments on the original post: I commented briefly that things don't work because</p>

<ol>
<li>I thought it was very obvious why the suggested things don't work.</li>
<li>I didn't think a detailed post explaining exactly why they don't work with lots of maths was appropriate for the comments</li>
</ol>

<p>Alecos' 'answer' isn't an answer at all. It may better be read as an expansion upon why the naive approach in the original post doesn't work. </p>

<p>Now let me address the matter of differentiation. It's true that I wasn't precise in the original post, but this was to illustrate the naive approach I was taking and why it wasn't working.</p>

<p>The confusion here stems from the following. Say I have a differentiable function $f: \mathbb{R} \rightarrow \mathbb{R}$. I can certainly talk meaningfully about the function that is the derivative of $f$, that I will denote by $f'$. </p>

<p>On the other hand, sometimes people 'allow the argument to be a random, $\mathbb{R}$-valued variable'. When they do this, they should probably call the resulting random variables something other than $f$ and $f'$. All the confusion has arisen from this. I did not make this distinction in the original post, because my thinking on the question was not clear, and this has been confounded by other comments not recognising this base cause of the confusion.</p>

CC BY-SA 3.0
2016-09-29T20:38:11.570Z
Here you set a different constraint on $c_2$ than in the original question. You say that $c_2$ must be equal to the probability density function of $f(c_1,Z)$. In the original question you say that $c_2$ must be equal to $f(c_1,Z)$ and not to the latter's pdf. What is the correct one? Also: a random variable is a function, usually a real-valued measurable function.
Alecos Papadopoulos
CC BY-SA 3.0
2016-09-29T21:34:50.313Z
I think you've misread. Above, the constraint is that the pdf $g(y)$ followed by $c_2$ must be equal to the pdf $\eta(c_1, y)$ followed by $f(c_1, Z)$. There is no difference. You're correct on the second point, I did not speak precisely. Small edit has been made.
Steven
CC BY-SA 3.0
2016-09-29T22:50:05.960Z
Let two random variables $X, Z$ with respective pdf's $f_X$ and $f_Z$.  If $X=Z$ it follows that $f_X = f_Z$. But if $f_X = f_Z$ it does _not_ follow that $X=Z$. So the constraint in the original question is stronger than the constraint in the answer above, and so a different constraint.
Alecos Papadopoulos
CC BY-SA 3.0
2016-09-29T23:57:09.040Z
This objection is different to your first comment. Yes, the above answer provides a necessary condition for solution to the original problem. Which is true in general for the method of Lagrange multipliers anyway.
Steven
CC BY-SA 3.0
2016-10-04T16:31:34.320Z
I love the fact that two 'answers' that aren't even answers have 3 upvotes each, meanwhile the correct answer has nil. The system works!
Steven
CC BY-SA 3.0
2016-10-04T17:09:09.667Z
Indeed the system appears to work. Your answer answers a different question than the one posted, so even though closely connected, it is not an answer to the question asked. My answer is an answer because it explains why we cannot use the Lagrangian in the circumstances specified in the question.
Alecos Papadopoulos
CC BY-SA 3.0
2016-10-04T20:34:20.617Z
No, I answered the question. The constraint I have imposed is implied by the constraint in the original question. My answer plainly demonstrates that you can use Lagrangian multiplier methods to solve the problem.
Steven
CC BY-SA 3.0
2016-10-04T20:38:59.547Z
The constraint you have imposed in your answer is indeed _implied by_ the original one, but it _does not imply_ the original one. So the solution in your answer does not guarantee that $c_2 = f(c_1, Z)$, only that their probability densities are the same. This in no way is enough to have $c_2 = f(c_1, Z)$.
Alecos Papadopoulos
CC BY-SA 3.0
2016-10-04T20:45:00.830Z
I asked for a Lagrangian whose extrema correspond to the answer to the original problem. I carefully said correspond because you can get a stationary point of the Lagrangian that is not a solution to the original problem in any case. I have provided what is asked for in answer above.
Steven
CC BY-SA 3.0
2016-10-04T21:53:20.077Z
Ok, so let's just make certain that this correspondence holds. If you can find the time, it would be helpful to enhance this answer with the detailed steps of deriving the second first-order condition, the one with respect to $g$.
Alecos Papadopoulos
CC BY-SA 3.0
2016-10-04T22:11:50.773Z
I won't do it in detail, because I don't want to enter into a discussion of functional differentiation. Informally, it is:
$\frac{\partial \mathcal{L}}{\partial g(y)} =  \int u(x) \delta(x-y) \mathrm{d} x + \int \lambda(x) \delta(x-y) \mathrm{d} x  = u(y) + \lambda(y)  = 0 $, where $\delta$ is the delta function.
Steven
CC BY-SA 3.0
2016-09-25T08:46:25.743Z
2016-09-29T21:35:37.473Z
2016-09-29T21:35:37.473Z
Steven
<p>I'll illustrate the issue I'm having with a simple problem.</p>

<p>Let $c_1, c_2 \in \mathbb{R}$, and $Z$ a real-valued random variable. Let $u:\mathbb{R} \rightarrow \mathbb{R} $ be a differentiable function, and $f(c_1,Z)$ be a real-valued function that is differentiable with respect to $c_1$.</p>

<p>The problem is:
Maximise: $u(c_1) + \mathbb{E}[u(c_2)]$ 
such that $c_2=f(c_1, Z)$</p>

<p>This problem is easily solved by direct substitution, and the answer is</p>

<p>$u'(c_1) + \mathbb{E}\left[u'(f(c_1,Z)) \frac{\partial f(c_1,Z)}{\partial c_1}\right] = 0 \label{answer}$</p>

<p>The issue is how to write down a Lagrangian whose extrema correspond to the solution of this problem in the normal way.</p>

<p>My first instinct was to write
$\mathcal{L} = u(c_1) + \mathbb{E}[u(c_2)] + \lambda(c_2 - f(c_1,Z))$. </p>

<p>However, this doesn't seem to make sense.
If you treat $c_2$ as if it is a random variable, then the derivative of  $\mathbb{E}[u(c_2)]$ with respect to $c_2$ gives zero, and this can't possibly give the right answer.
On the other hand, it doesn't make sense to treat it as non-stochastic either, since it is 'forced' to be stochastic by the constraint.</p>

<p><strong>Question: How do I write a Lagrangian whose extrema correpond to the solution of the above optimisation problem?</strong> </p>

CC BY-SA 3.0
2016-09-15T14:00:37.167Z
You could take the expectation of everything.
VCG
CC BY-SA 3.0
2016-09-15T14:02:39.913Z
I'm afraid that doesn't work either.
bobhawke
CC BY-SA 3.0
2016-09-15T17:12:48.113Z
The expectation can be written as an integral perhaps, and then Leibniz's integral rule can be applied.
Kitsune Cavalry
CC BY-SA 3.0
2016-09-15T17:28:21.520Z
That also doesn't work.
bobhawke
CC BY-SA 3.0
2016-09-25T11:01:00.947Z
For future repliers: In a deleted answer the OP says he forgot his login. Hence no answer's will be accepted. Another unfortunate instance is that the OP keeps repeating "doesn't work" instead of explaining why he thinks so. This is unfortunate because I for one think Alecos's answer is the correct one and that the OP treats derivates w.r.t. random variables in a rather peculiar way.
Giskard
<optimization>
Method of Lagrange multipliers with random variables
bobhawke
# Method of Lagrange multipliers with random variables

(Asked by: username_0 on 2016-09-15)

I'll illustrate the issue I'm having with a simple problem.

Let $c\_1, c\_2 \in \mathbb{R}$, and $Z$ a real-valued random variable. Let $u:\mathbb{R} \rightarrow \mathbb{R} $ be a differentiable function, and $f(c\_1,Z)$ be a real-valued function that is differentiable with respect to $c\_1$.

The problem is:
Maximise: $u(c\_1) + \mathbb{E}[u(c\_2)]$
such that $c\_2=f(c\_1, Z)$

This problem is easily solved by direct substitution, and the answer is

$u'(c\_1) + \mathbb{E}\left[u'(f(c\_1,Z)) \frac{\partial f(c\_1,Z)}{\partial c\_1}\right] = 0 \label{answer}$

The issue is how to write down a Lagrangian whose extrema correspond to the solution of this problem in the normal way.

My first instinct was to write
$\mathcal{L} = u(c\_1) + \mathbb{E}[u(c\_2)] + \lambda(c\_2 - f(c\_1,Z))$.

However, this doesn't seem to make sense.
If you treat $c\_2$ as if it is a random variable, then the derivative of $\mathbb{E}[u(c\_2)]$ with respect to $c\_2$ gives zero, and this can't possibly give the right answer.
On the other hand, it doesn't make sense to treat it as non-stochastic either, since it is 'forced' to be stochastic by the constraint.

**Question: How do I write a Lagrangian whose extrema correpond to the solution of the above optimisation problem?**

**Tags:** optimization
> **Comments:**
> **username_1**: You could take the expectation of everything.  
> **username_0**: I'm afraid that doesn't work either.  
> **username_2**: The expectation can be written as an integral perhaps, and then Leibniz's integral rule can be applied.  
> **username_0**: That also doesn't work.  
> **username_3**: For future repliers: In a deleted answer the OP says he forgot his login. Hence no answer's will be accepted. Another unfortunate instance is that the OP keeps repeating "doesn't work" instead of explaining why he thinks so. This is unfortunate because I for one think Alecos's answer is the correct one and that the OP treats derivates w.r.t. random variables in a rather peculiar way.  

---

## 4 answers

### Answer by username_4 on 2016-09-24. Score: 3

> If you treat $c\_2$ as if it is a random variable, then the derivative of
> $E[u(c\_2)]$ with respect to $c\_2$ gives zero.

Why? Such an assertion doesn't follow from anywhere. The subtleties lie elsewhere. The problem with the Lagrangian considered by the OP

$$\mathcal{L} = u(c\_1) + \mathbb{E}[u(c\_2)] + \lambda(c\_2 - f(c\_1,Z))$$

is that it *also* is a random variable since now $Z$ appears *outside* the expected value (The direct substitution approach followed by maximization with respect to $c\_1$ only, does not create any such issues).

Now, do we / can we maximize a random variable? Well, no, because the essential characteristic of a random variable is that it is a function whose value cannot be set by command and control.

But one could say "ok, let's pretend that this Lagrangian is not a random variable, and just write down the conditions for maximization, even though we know that we can't force the solution".

But this won't work: if one attempts to do it one will eventually obtain

$$u'(c\_1) + \mathbb{E}\left[u'(f(c\_1,Z))\right] \cdot \frac{\partial f(c\_1,Z)}{\partial c\_1} = 0 $$

which is *not* the same as the condition obtained through direct substitution, because here the partial derivative is *outside* the expected value.

(for those who may think "hey, then how do we apply maximization procedures in the maximum likelihood approach" the answer is that there, nothing is random anymore when we get to apply the maximization steps).


---

### Answer by username_3 on 2016-09-25. Score: 3

This is not an answer, for that see [Alecos's answer](https://economics.stackexchange.com/a/13521/1601). The point of this post is to clarify that the question relies on the false assumption
$$
\frac{d \ E(c\_2)}{d \ c\_2} = 0
$$
by way of an example. Consider the random variable that I get by rolling a six sided die and multiplying the result $X$ by a positive integer $n$. The expected value of this is
$$
E(n \cdot X) = n \cdot \frac{7}{2}.
$$
Would you claim that
$$
\frac{d \ E(n \cdot X)}{d \ n} = 0
$$
because "Taking the derivative of the expectation [...] with respect to anything gives zero, since the expectation [...] is just a constant"?


---

### Answer by username_5 on 2020-04-17. Score: 1

To solve this with the exact constraint given in the question, one could set up the following Lagrangian:

$\mathcal{L}(c\_{1},\lambda(\cdot))=u\left(c\_{1}\right)+\int u\left(c\_{2}\left(z\right)\right)g(z)\mathrm{d}z-\int\lambda(z)\left\{ f\left(c\_{1},z\right)-c\_{2}\left(z\right)\right\} \mathrm{d}z,$

where $g(z)$ is the probability density function for the random variable $Z$, and $\lambda(z)$ is the Lagrange multiplier corresponding to any value $z$.

First-order conditions for the functions $c\_2$ and $\lambda$ and for the scalar $c\_1$ then are:

* $\forall z:\lambda(z)=-u^\prime (c\_2(z))g(z)$
* $\forall z: f(c\_1,z)=c\_2(z)$
* $u^\prime(c\_1)-\int\lambda(z)\frac{\partial{f}}{\partial{c\_1}}g(z)\mathrm{d}z=0\Leftrightarrow u^\prime(c\_1)+\int u^\prime(c\_2(z))\frac{\partial{f}}{\partial{c\_1}}g(z)\mathrm{d}z$

The last condition corresponds to what bobhawke found using the substitution method. Steven finds the same solution, but imposing equality of the distribution functions does not correspond exactly to what is asked.


---

### Answer by username_6 on 2016-09-25. Score: 0

Answer first:

The `objective function' is in fact a functional. The task is to find a pdf $g(y)$ folowed by $c\_2$ and a real number $c\_1$ that maximise the following Lagrangian

$$ \mathcal{L}(c\_1, g) = u(c\_1) + \int u(x)g(x) \mathrm{d}x + \int \lambda(y) \left[ g(y) - \eta(c\_1, y) \right] \mathrm{d}y. $$

Here, $\eta(c\_1, y)$ is the pdf followed by the random variable $f(c\_1, Z)$. $\lambda(y)$ is a Lagrange multiplier, used to enforce the constraint $g(y)=\eta(c\_1,y)$. All integrals are over $\mathbb{R}$. The first order conditions are

$$ u'(c\_1) - \frac{\partial}{\partial c\_1} \int \lambda(y) \eta(c\_1,y) \mathrm{d} y =0, \\
u(y) + \lambda(y) =0, \\
g(y) - \eta(c\_1, y) = 0. \\
$$

Combining the first two gives

$$ u'(c\_1) + \frac{\partial}{\partial c\_1} \int u(y) \eta(c\_1,y) \mathrm{d} y =0. $$

Now using the 'law of the unconscious statistician' gives

$$ u'(c\_1) + \frac{\partial}{\partial c\_1} \int u(f(c\_1,z)) \phi(z) \mathrm{d} z =0 \\
\Rightarrow u'(c\_1) + \int u'(f(c\_1,z)) \frac{\partial f(c\_1,z)}{\partial c\_1} \phi(z) \mathrm{d} z =0 .$$
Here, $\phi(z)$ is the pdf followed by the random variable $Z$. This is equivalent to the solution given by OP.

---

Now I want to address a few other things. I would ideally do this in the comments, but I don't have enough reputation to comment.

First of all, I am OP. I really am at a loss as to why I couldn't log in with original credentials. Still trying to figure that one out.

As denesp points out, I wrote an answer not so long ago which I immediately deleted. I did this for a few reasons:

1. I didn't actually answer the question in that post.
2. I was on the bus at the time, typing on my phone. The formatting I had wasn't correct, and the wording was very loose. I wanted to take more time over it and give a better and more precise answer. So, for example, some of denesp's comments are directed at imprecise wording in a post I deleted.

To address denesp's comments on the original post: I commented briefly that things don't work because

1. I thought it was very obvious why the suggested things don't work.
2. I didn't think a detailed post explaining exactly why they don't work with lots of maths was appropriate for the comments

Alecos' 'answer' isn't an answer at all. It may better be read as an expansion upon why the naive approach in the original post doesn't work.

Now let me address the matter of differentiation. It's true that I wasn't precise in the original post, but this was to illustrate the naive approach I was taking and why it wasn't working.

The confusion here stems from the following. Say I have a differentiable function $f: \mathbb{R} \rightarrow \mathbb{R}$. I can certainly talk meaningfully about the function that is the derivative of $f$, that I will denote by $f'$.

On the other hand, sometimes people 'allow the argument to be a random, $\mathbb{R}$-valued variable'. When they do this, they should probably call the resulting random variables something other than $f$ and $f'$. All the confusion has arisen from this. I did not make this distinction in the original post, because my thinking on the question was not clear, and this has been confounded by other comments not recognising this base cause of the confusion.

> **Comments:**
> **username_4**: Here you set a different constraint on $c_2$ than in the original question. You say that $c_2$ must be equal to the probability density function of $f(c_1,Z)$. In the original question you say that $c_2$ must be equal to $f(c_1,Z)$ and not to the latter's pdf. What is the correct one? Also: a random variable is a function, usually a real-valued measurable function.  
> **username_6**: I think you've misread. Above, the constraint is that the pdf $g(y)$ followed by $c_2$ must be equal to the pdf $\eta(c_1, y)$ followed by $f(c_1, Z)$. There is no difference. You're correct on the second point, I did not speak precisely. Small edit has been made.  
> **username_4**: Let two random variables $X, Z$ with respective pdf's $f_X$ and $f_Z$.  If $X=Z$ it follows that $f_X = f_Z$. But if $f_X = f_Z$ it does _not_ follow that $X=Z$. So the constraint in the original question is stronger than the constraint in the answer above, and so a different constraint.  
> **username_6**: This objection is different to your first comment. Yes, the above answer provides a necessary condition for solution to the original problem. Which is true in general for the method of Lagrange multipliers anyway.  
> **username_6**: I love the fact that two 'answers' that aren't even answers have 3 upvotes each, meanwhile the correct answer has nil. The system works!  
> **username_4**: Indeed the system appears to work. Your answer answers a different question than the one posted, so even though closely connected, it is not an answer to the question asked. My answer is an answer because it explains why we cannot use the Lagrangian in the circumstances specified in the question.  
> **username_6**: No, I answered the question. The constraint I have imposed is implied by the constraint in the original question. My answer plainly demonstrates that you can use Lagrangian multiplier methods to solve the problem.  
> **username_4**: The constraint you have imposed in your answer is indeed _implied by_ the original one, but it _does not imply_ the original one. So the solution in your answer does not guarantee that $c_2 = f(c_1, Z)$, only that their probability densities are the same. This in no way is enough to have $c_2 = f(c_1, Z)$.  
> **username_6**: I asked for a Lagrangian whose extrema correspond to the answer to the original problem. I carefully said correspond because you can get a stationary point of the Lagrangian that is not a solution to the original problem in any case. I have provided what is asked for in answer above.  
> **username_4**: Ok, so let's just make certain that this correspondence holds. If you can find the time, it would be helpful to enhance this answer with the detailed steps of deriving the second first-order condition, the one with respect to $g$.  
> **username_6**: I won't do it in detail, because I don't want to enter into a discussion of functional differentiation. Informally, it is: $\frac{\partial \mathcal{L}}{\partial g(y)} =  \int u(x) \delta(x-y) \mathrm{d} x + \int \lambda(x) \delta(x-y) \mathrm{d} x  = u(y) + \lambda(y)  = 0 $, where $\delta$ is the delta function.  

---

