I am trying to get Mathematica to automatically do simplifications like the following:
$$\sum\limits_{q}^{q\in qV}\sum\limits_{q'}^{q'\in q'V}{f(q)g(q')\delta(q-q')}=\sum_{q}^{q\in qV}{f(q)g(q)}.$$
Where the range of values that $q$ and $q'$ are denoted by $qV$ and $q'V$ respectively and are the same. With pen an paper it is really easy to do that kind of simplifications because I know that both variables $q$ and $q'$ have the same range and that the Discrete Delta function $\delta(q-q')$ kills one of the sums.
I have solved it, but it seems to me that I haven't done it in the most elegant/efficient way. My solution is:
Clear[qV, qpV, f,g, MyDiscreteDelta]
a = Sum[f[q] Sum[g[qp] MyDiscreteDelta[q, qp], {qp, qpV}], {q, qV}]
b = % /. {qpV -> {q, q1, q2, q3, q4}}
c = % /. {MyDiscreteDelta[x_, y_] -> HoldForm[If[x =!= y, 0, 1]]}
d = ReleaseHold[%]
$a$ defines the sum and I deliberately leave the sum range undefined as even though I know the real range of number I will be summing, it's too large to be put directly and more importantly, at this stage of the calculation I don't care about it, I am just interested in simplifying the result as much as possible, i.e., get rid of one of the sums by using the delta function. I am not using Mathematica defined function DiscreteDelta because a) it takes too long and b) when used symbolically it is left unevaluated.
First thing I need to do to get rid of one of the sums is to give it a range to sum through, in doing so, I am actually giving it a list of possible variables that it could take(assuming that in the general case I will be having more than two summations and I will have more than one delta function in many of the variables). That's done in $b$.
$c$ changes the empty definition of MyDiscreteDelta but I need to hold it as if I don't do so, it will all be evaluated to $0$. The last step, $d$ evaluates the expression and gives the results I want.
This works, but I was wondering if there is a simpler way of doing it.
Thanks in advance.
KroneckerDelta
? $\endgroup$code
MyDiscreetDelta[q,qp]code
tocode
KroneckerDelta[q,qp]code
in (a) and only evaluating (a) and (b). It is very slow. It does simplify to 1 when q==qp but on the other cases, it is just left unevaluated, the same as DiscreteDelta. I can individually reproduce the expected behaviour if I writecode
Assuming[q != qp, Simplify[KroneckerDelta[q, qp]]]code
orcode
Assuming[q != qp, Simplify[DiscreteDelta[q, qp]]]code
. But it doesn't work if I do something likecode
Assuming[q != q1, Simplify[b]]code
. $\endgroup$code
! $\endgroup$