I'm struggling to find out some basic maximization problem associated to the first order condition of a problem. The problem is an insurance example, where there's an strictly risk-adverse decision maker which has an initial wealth of $w$ but runs in a risk of a loss of $D$ dollars. The probability of loss is $\pi$ and it is possible to the decision maker to buy the insurance.
One unit of insurance cost $q$ dollars, and pays 1 dollar if the loss occurs, this if $\alpha$ units of insurance are bought, the wealth of the individual will be:
$w - \alpha q$ if there is no loss.
$w - \alpha q - D+ \alpha$ if the loss occurs.
And the decision maker expected wealth is $w - \pi D + \alpha (\pi -q)$
The decision maker problem is to choose the optimal level of $\alpha$. and we got:
$$Max : (1-\pi) u (w-\alpha q)+ \pi u(w-\alpha q -D + \alpha)$$
I'm struggling to understand how to get the following first order condition:
$$-q (1- \pi) u'(w - \alpha q) +\pi (1-q) u'(w-D+\alpha (1-q)) \leq 0$$
I assume we're taking partial derivates of the maximization problem above respect to $\alpha$, and from there we somehow pull out $q$ from $u(.)$ and I totally missed this part $\pi (1-q) u'(w-D+\alpha (1-q))$ how we get that result?
Thank you for the help in advance.
Thanks to @Snoop comments, I've noticed that such a first-order condition derives from the use of the chain rule with a slight modification in the $u(.)$ functions.
If we express
$$Max : (1-\pi) u (w-\alpha q)+ \pi u(w-\alpha q -D + \alpha)$$
as
$$Max : (1-\pi) u (w-\alpha q)+ \pi u(w - D +\alpha (1-q))$$
because we have factor of $\alpha$ in $u(w-\alpha q -D + \alpha)$ therefore it can bere expressed as $u(w - D +\alpha (1-q))$
From that, if we take partial derivates respect $\alpha$ we can derive into the same result of:
$$-q (1- \pi) u'(w - \alpha q) +\pi (1-q) u'(w-D+\alpha (1-q)) \leq 0$$
Simply because $(1-\pi) u (w-\alpha q)$ partial derivative respect $\alpha$ is in fact $-q (1-\pi) u' (w-\alpha q)$ where $u'$ is the partial derivative of the function $u$ respect to $\alpha$ but we leave it general expressed without any transformation.
The same goes for $\pi u(w - D +\alpha (1-q))$ where the factor $(1-q)$ is multiplication $\alpha$ therefore it comes out of the function and then it's multiplied by the derivative of $u$ respect to $\alpha$ in the sense of the chain rule. The partial derivative is in fact $(1-q) \pi u'(w - D +\alpha (1-q))$