# Formal Differentiation

I'm trying to formally differentiate an expression. (I am aware of how to differentiate formally?, but am unable to generalize the idea)

For example:

tmp1 = Sum[Product[MyVal[i, j]^(1/n), {j, 1, n}], {i, 1, n}]


I would like to take the derivative with respect to some i in 1...n and j in 1...n . I thought I could specify something like

MyVal /: D[MyVal[i_, j_], MyVal[k_, l_], NonConstants -> {MyVal}] :=
KroneckerDelta[i, k]*KroneckerDelta[j, l]


Then take the derivative

D[tmp1, MyVal[i, j]]


But this turns out not to work as expected. Any help in the right direction is appreciated. Thanks.

Unfortunately, I think formal differentiation of Product only works if you specify a numerical value for the limit n:
tmp = With[{n = 3},