# How can I numerically implement $\delta(f(x,y))$

I would like to numerically implement a Dirac Delta function whose argument is another 2 variable function. I know that I can model a Dirac Delta numerically using a Gaussian. What can I do if I want to implement $$\delta(f(x,y))$$. Will using a function like $$e^{-f(x,y)^2/\sigma^2}$$ work? Edit: $$\sigma$$ is a parameter I can control to make the peak of the Gaussian sharper. By 'implement', I mean generate numerically, that is to generate a 2 variable Delta function over a 2D grid.

• What meaning do you give to implement ? And what is $\sigma$ ? – Yves Daoust Jun 20 '19 at 7:27
• Provide more background and context, please. – Rodrigo de Azevedo Jun 20 '19 at 7:48
• It would be best to avoid explicitly implementing distributions. Use partial integration or other methods to integrate them up to at least regular functions. For ODE this could look like math.stackexchange.com/a/2023312/115115 or math.stackexchange.com/a/2834640/115115. Of course, here with the composite distribution things are a little more involved. – Lutz Lehmann Jun 20 '19 at 7:48
• You are aware that in this formulation you get a delta "wall" along a curve $f(x,y)=0$? // For any non-negative function $\phi$ with integral one, the delta approximation is $\phi(x/σ)/σ$ for $σ\to 0$, leading to the composition $\phi(f(x,y)/σ)/σ$ for the "delta wall". // It is not clear if what you are doing is well-defined. For any smooth test function, what would you expect $\int g(x,y)\delta(f(x,y))d(x,y)$ to be? To compare, for one-dimensional functions with simple roots we know $\delta(f(x))=\sum_{a:f(a)=0}\frac{\delta(x-a)}{|f'(a)|}$. – Lutz Lehmann Jun 21 '19 at 9:14
• If the goal is to integrate $\delta(f(x, y)) \phi(x, y)$, you can reduce the problem to a line integral. If you know how to parametrize $f(x, y) = 0$, you get a one-dimensional definite integral. – Maxim Jul 1 '19 at 11:36

The Dirac delta function $$\delta$$ is a linear functional which maps your functions into your scalars. To be precise, suppose $$V$$ is a vector space over $$\mathbb{R}$$ consisting of continuous functions $$f : \mathbb{R}^n \rightarrow \mathbb{R}$$ and $$x_0 \in \mathbb{R}^n$$, then the functional $$T : V \rightarrow \mathbb{R}$$ given by $$T(f) = f(x_0)$$ is the Dirac delta function with respect to the point $$x_0$$. The term functional rather than function is used to emphasize that the codomain of $$T$$ is your set of scalars. It is clear that $$T$$ is linear, because $$T(af + bg) = a f(x_0) + b g(x_0) = a T(f) + b T(g)$$ for all $$a,b \in \mathbb{R}$$ and $$f, g \in V$$.
Many, many functionals $$S : V \rightarrow \mathbb{R}$$ can be written exactly as $$S(f) = \int_{\mathbb{R}^n} f(x) s(x)dx$$ for a suitable choice of $$s$$. Dirac's delta function is an exception. It can be approximated using such functionals or you can simply implement it using the definition.
Yes, exactly: if the delta function $$\delta$$ can be well-approximated by a gaussian function $$N$$, then $$\delta(f(x,y)) \approx N(f(x,y)) = \frac{1}{Z_0}\exp{(-f(x,y)^2/\sigma^2)}$$, with $$Z_0$$ a normalizing factor.
The only difficulty I can see is that depending on the possible values of $$f$$, it may be important for your application to have a sharper gaussian function $$N$$.