# Differentiate the product of some terms

How can I compute the following derivative,

$$\frac{\partial}{\partial \lambda_j} \prod_{i=1}^k (1+\lambda_i)e^{\lambda_i} \quad \text{for }\; 1\le j \le k$$

for some positive integer $k$ which is not known? Note that it is simple to compute the derivative by hand, but I just wonder how such equations can be input in Mathematica.

Edit: After halirutan's answer, I decided to update the question. What I understand from his answer is that: there is no simple straight forward way to express such an example. Now, my question is that: is it possible to add some rewriting rules to Mathematica's built-in D and Simplify functions such that, running

Assuming[1<=j<=k&&j\[Element]Integers,
Simplify[D[Product[(1 + l[i]) Exp[l[i]], {i, k}], l[j]]]
]


Returns the desired output:

$$\frac{2+\lambda_i}{1+\lambda_i}\prod_{i=1}^k (1+\lambda_i)e^{\lambda_i}$$

-
A smaller example of this kind would be to calculated the part. derivative of Sum[l[i], {i, k}] wrt some l[j]. To solve this you need to imagine the sum expanded and then you see that it's always 1. The step of imagination does not work in Mma because it needs to consider all possible cases. –  halirutan Oct 11 '12 at 23:57
Regarding your edit: No, this is not possible without substantially changing the system. Simplify does not Hold the expression to simplify. This means, your expression D[Product[(1 + l[i]) Exp[l[i]], {i, k}], l[j]] is first evaluated to 0 before Simplify can do anything. –  halirutan Oct 13 '12 at 2:13

As stated in my comment, the hard thing here is, that Mathematica cannot expand your Product for an unknown k. What you know is, that $1\leq j \leq k$ but I don't how I could help Mathematica, that it expands your Product with this knowledge. What we want to do is the following:

$$\prod_{i=1}^k (1+\lambda_i)e^{\lambda_i} \rightarrow \\\left(\prod_{i=1}^{j-1} (1+\lambda_i)e^{\lambda_i}\right) \cdot \left((1+\lambda_j)e^{\lambda_j}\right)\cdot \left(\prod_{i=j+1}^k (1+\lambda_i)e^{\lambda_i}\right)$$

Let's try to do this small part manually

expr = Product[(1 + l[i]) Exp[l[i]], {i, k}];
exprExpanded = expr /. Product[f_, {i_, k_}] :>
Product[f, {i, 1, j - 1}]*(f /. i :> j)*Product[f, {i, j + 1, k}]


$$e^{l[j]} (1+l[j]) \left(\prod _{i=1}^{-1+j} e^{l[i]} (1+l[i])\right) \prod _{i=1+j}^k e^{l[i]} (1+l[i])$$

In this form we can derive the expression with D because everything which depends on l[j] is extracted

dexpr = D[exprExpanded, l[j]]


$$e^{l[j]} \left(\prod _{i=1}^{-1+j} e^{l[i]} (1+l[i])\right) \prod _{i=1+j}^k e^{l[i]} (1+l[i])+e^{l[j]} (1+l[j]) \left(\prod _{i=1}^{-1+j} e^{l[i]} (1+l[i])\right) \prod _{i=1+j}^k e^{l[i]} (1+l[i])$$

This is the general analytic form of your derivative. Now you can check whether it is equivalent to calculated derivative when you insert special values for j and k

(dexpr /. {j :> 3, k :> 5}) == D[Product[(1 + l[i]) Exp[l[i]], {i, 5}], l[3]]
(*
True
*)

-
Thanks, that's a nice answer halirutan. I updated the question. Could you let me know your thoughts about it. –  Helium Oct 12 '12 at 5:05
@Mohsen Have you seen the TransformationFunctions option for Simplify? –  halirutan Oct 12 '12 at 16:15