I have a summation function, for which I have defined derivation via
Custom`sum /: D[Custom`sum[idx_, a_, b_, exprs_], y_] := Custom`sum[idx, a, b D[expr, y]]; where idx is the index with bounds a and b. This does not seem to work, though when the sum is inside another function. For example, I get
D[Sqrt[Custom`sum[idx, 1, 2, func[idx, y]]], y] where via chain rule I would expect
1/Sqrt[Custom`sum[idx, 1, 2, func[idx, y]]]*1/2*Custom`sum[idx, 1, 2, Derivative[0,1][func][idx, y]]] To give an even simpler example, look what happens with Plus
D[f[g[x,1]+g[x,2]],x] (* (f^′)[g[x,1]+g[x,2]] ((g^(1,0))[x,1]+(g^(1,0))[x,2]) *) How can I achieve the same with
D[f[sum[g[x,i]]],x] (* (f^′)[sum[g[x,i]]] (sum^′)[g[x,i]] (g^(1,0))[x,i] *) Is there a way to get the chain rule to work for these cases?

UpValuestosumwithDwill not work. If you have a wrapping function like yourSqrt, then the intermediate expressions only consist ofDerivativeand there is noDanymore that matches AFAIK. But I might of course be wrong. $\endgroup$