# Teaching Mathematica more about DiracDelta and KroneckerDelta

As the documentation and some experimentation indicates, Mathematica contains little information about representations of the DiracDelta and KroneckerDelta functions.

Some examples which are not recognized in Mathematica include the identities:

1. Limit[a/(x^2 + a^2), a -> 0] = DiracDelta[x]
2. Integrate[Exp[I k x], {x, -∞, ∞}, Assumptions -> k ∈ Reals]
3. Sum[Exp[I k n], {n, -∞, ∞}] = KroneckerDelta[k]
4. Integrate[h[n, x] h[m, x], {x, -∞, ∞}] = KroneckerDelta[n, m]
5. Sum[h[n, x] h[n, y], {n, 0, ∞}] = DiracDelta[x - y]

Where the set of functions h[n, x] is orthonormal.

I want to implement these kinds of relations in Mathematica. What would be the programmatic way to do this?

• You may be interested in Leonid's answer to this old question on SO: How to implement an integration rule? Commented Mar 17, 2016 at 14:55
• For numbers 1 and 2, you can use Fourier transforms instead of integrals, and the result comes out correctly. Specifically, for 1: InverseFourierTransform[ Limit[ FourierTransform[a/(x^2+a^2),x,y], a->0], y,x] yields $\pi \delta(x)$. See Laplacian and DiracDelta. This also works with additional relations, not in your list, e.g., InverseFourierTransform[ Limit[ FourierTransform[Sin[ω t]^2/(π t ω^2),ω,τ], t->∞], τ,ω]
– Jens
Commented Mar 17, 2016 at 16:06
• The outcomes containing KroneckerDelta can't be valid in general because Mathematica doesn't know that the arguments in those results are supposed to be integers. It generically assumes complex variables, but adds some reality assumptions in FourierTransform. So for point 3, you would in general expect something involving DiracComb instead of KroneckerDelta.
– Jens
Commented Mar 17, 2016 at 16:34
• I want to be able to avoid using FourierTransform because I get these representations (mainly points 4 and 5) automatically in the course of other calculations. I want to be able to use Integrate and assumptions. How can I extend Integrate using assumptions? Also I need to avoid the results it currently gives which are either infinity or 0. Commented Mar 17, 2016 at 19:13

Since the main goal of the question appears to be dealing with general functions h that are assumed to be a complete orthonormal set, I'll deal specifically only with that case.

The idea is to use TagSetDelayed as a way of stating the assumptions for the function h. To do this, we have to distinguish between the two types of products as they arise in the orthogonality relation (Integrate) and the completeness relation (Sum). Because the function h itself is too deep inside the integral or sum, I define an intermediate function for each of the two types of product first. For them, I then specify what the result of the operation should be.

h /: h[n_, x_] h[m_, x_] := hOrthoProduct[n, m, x]
hOrthoProduct /:
Integrate[
hOrthoProduct[n_, m_, x_], {x_, -Infinity, Infinity}] :=  KroneckerDelta[m, n]
h /: h[n_, x_] h[n_, y_] := hCompleteProduct[n, x, y]
hCompleteProduct /:
Sum[hCompleteProduct[n_, x_, y_], {n_, 0, Infinity | DirectedInfinity[1]}] :=
DiracDelta[x - y]


Here I test the results:

Integrate[h[n, x] h[m, x], {x, -Infinity, Infinity}]
(* ==> KroneckerDelta[m, n] *)

Sum[h[n, x] h[n, y], {n, 0, Infinity}]
(* ==> DiracDelta[x - y] *)


Edit working with built-in functions, in Limit, Sum or Integrate

As I mentioned in the comments, many known expressions for the delta function can be obtained by wrapping the required limit in Fourier transforms. The point is that the limit (or infinite integration boundary) can then be interpreted in terms of a generalized function because the intended integration variables are made explicit in FourierTransform.

But in Limit, Sum and Integrate, this information is not provided explicitly. So here is a possible way of fixing this lack of information: Whenever we want to perform a limit in the special way that leads to a Dirac delta function, let's just require that in all those cases the variable in the limit should have a special name. This name should also include the symbol that's intended to be used as the free integration variable in the conversion to a delta function later.

I decided to call this special variable ℒ but give it an argument x that stands for the free variable. So you will be using variables like ℒ[x] or ℒ[z] in the calculation. Here are the definitions for this "variable":

ℒ /:
HoldPattern[
Rule[ℒ[x_],
lim : (0 | Infinity |
DirectedInfinity[1])]] := ℒlimit[lim, x]

ℒ /: {ℒ[x_], -Infinity, Infinity} := ℒinterval[x]

ℒlimit /:
Limit[expr_, ℒlimit[lim_, x_]] :=
Module[{y, ϵ},
InverseFourierTransform[
Limit[FourierTransform[expr /. ℒ[x] -> ϵ,
x, y], ϵ -> lim, Direction -> Sign[lim - 1]], y, x]]

ℒinterval /:
op_[expr_, ℒinterval[x_]] := Module[{y, z},
InverseFourierTransform[
op[FourierTransform[expr /. ℒ[x] -> z, x,
y], {z, -Infinity, Infinity}], y, x]]


Now some tests:

Limit[ℒ[x]/(x^2 + ℒ[x]^2), ℒ[x] -> 0]

(* ==> Pi DiracDelta[x] *)

Sum[
Exp[I k ℒ[k]], {ℒ[k], -Infinity, Infinity}]

(* ==> DiracComb[k/(2 Pi)] *)

Integrate[
Exp[I k ℒ[k]], {ℒ[k], -Infinity, Infinity}]

(* ==> 2 Pi DiracDelta[k] *)

Limit[
Sin[ω ℒ[ω]]^2/(Pi ℒ[ω] ω^2), ℒ[ω] -> Infinity]

(* ==> DiracDelta[ω] *)


So the variable starting with ℒ will cause any Limit, Sum or Integrate in which it appears in the second argument to be sandwiched between InverseFourierTransform and FourierTransform with the additional information about what the desired final variable is.

• That is a very good starting point, thank you! Could there be a way to do something similar using something like 'Regularization'? (the option for 'Sum' and Product') How is something like that implemented? Commented Mar 18, 2016 at 1:09
• I don't think so, because you're looking for generalized functions as output, and neither Integrate nor Sum are intended for those kinds of output. Regularizations don't give you generalized functions. The desired delta function output has ambiguities, depending on what is identified as the intended integration variable in the result. In my definitions for h, this is made explicit. But in Integrate or Sum, the first argument is just an expression and there's not enough information to easily identify the intended variables that should appear in DiracDelta.
– Jens
Commented Mar 18, 2016 at 4:38