4
$\begingroup$

I found something odd in MMA 12.1 when symbolically integrating DiracDelta and Piecewise. These functions are integrated individually but not their sum. The following code

f[x_] = DiracDelta[x - 12.0];
Integrate[f[x], x]
g[x_] = Piecewise[{{2 x, x < 1}, {4 x, 1 <= x < 2}, {0, True}}];
Integrate[g[x], x]
Integrate[f[x] + g[x], x]

produces evaluated integrals in the first two cases but not in the third case. Why?

$$\theta (x-12.)$$

$$\begin{cases} x^2 & x\leq 1 \\ 2 x^2-1 & 1<x\leq 2 \\ 7 & \text{True} \\ \end{cases}$$

$$\int \left(\left( \begin{cases} 2 x & x<1 \\ 4 x & 1\leq x<2 \\ \end{cases} \right)+\delta (x-12.)\right) \, dx$$


By the way, symbolic Python works as expected.

from sympy import *
x=var('x') 
f=DiracDelta(x)
g=Piecewise((1,x<3), (2,x<10),(0,True))
integrate(f+g,x)
$\endgroup$
1
  • 1
    $\begingroup$ I would be super careful about computing indefinite integrals where the integrand is a delta function. I'm not sure that even makes any sense. Instead, you should be using definite integrals. For instance, consider the result of Integrate[f[x], {x, a, b}, Assumptions -> {a < b}]. $\endgroup$
    – march
    Commented Feb 25, 2022 at 18:23

1 Answer 1

5
$\begingroup$

Try this:

Distribute[Integrate[f[x] + g[x], x]]
$\endgroup$
3
  • 2
    $\begingroup$ Thanks, that kind of patches the issue. But still I find the behavior of Integrate[...] unusual. $\endgroup$ Commented Feb 25, 2022 at 14:09
  • 1
    $\begingroup$ It probably has to due with the fact that while g[x] is piecewise continuous, it is not smooth at the transitions, i.e., it is not differentiable at the transitions. Look at D[g[x], x]. Consequently, D[Integrate[g[x], x], x] == g[x] // PiecewiseExpand is a condition rather than True. In the more complicated context, Integrate balks. $\endgroup$
    – Bob Hanlon
    Commented Feb 25, 2022 at 14:25
  • $\begingroup$ I would like to point out that symbolic Python has absolutely no problems with this. from sympy import * x=var('x') f=DiracDelta(x) g=Piecewise((1,x<3), (2,x<10),(0,True)) integrate(f+g,x) $\endgroup$ Commented Feb 25, 2022 at 15:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.