I’m trying to write this expression

in Mathematica, and calculate the following quantity

However, when I tried the following

`Clear[g, n, v,T,P,B,r,i,j,k,l,t,w,Q,g,a,f] g = B*(Sum[Indexed[n, k]*Log[Indexed[n, k]*Indexed[v, k]],k])+ Sum[Indexed[n, f]*Indexed[w, f],f] + Sum[Sum[0.5*Indexed[Indexed[Q, l], j]*Indexed[n, l]*Indexed[n, j],j],l] + P; a = Indexed[v, r] * (g - Sum[D[g, Indexed[n, t]]*Indexed[n, t],t]) + D[g,Indexed[n, r]] Collect[a,B] //Simplify `

I basically get

$ $ v_r * g$ $

as a result of the computation and the reason is that it calculates the derivatives of $ g$ wrt $ n_k$ s as exactly zero. Meaning that it doesn’t recognise the summation indices as dummy indices.

How can I correct my code such that the dummy summation variables will be a dummy and hence I’ll be able to perform the above calculation correctly?