I want to create a computational rule like, $ \frac{\partial}{\partial h_{i}}\int f\left(h_{i}\right)di:=\frac{\partial f\left(h_{i}\right)}{\partial h_{i}}$ . This rule is somehow useful when doing models of heterogeneous agents.
To achieve this, I use the code,
Unprotect[D] D[Integrate[x_, i_], p_] := D[x, p] /; ! FreeQ[p, i]
This works for codes like,
D[Integrate[f[h[i]/p a], i], h[i]]
which returns, $ \frac{a f’\left(\frac{a h(i)}{p}\right)}{p}$ .
But inexplicably, it does not work for codes like,
D[Integrate[a f[h[i]/p ], i], h[i]]
which returns, $ \frac{a \int f’\left(\frac{h(i)}{p}\right) \, di}{p}$ .
The position of a trivial constant “a” does determine whether the rule applies.
I am confused because I think by definition, x_
represents “anything” in mathematica. And !FreeQ[a f[h[i]/p , i]
is obviously True, which means the the rule should apply. What is wrong here?