does this Piecewise integration look right?

65 views
Skip to first unread message

Chris Smith

unread,
Feb 2, 2018, 6:26:10 PM2/2/18
to sympy
I'm also wondering if the following behavior is right:

```
>>> Piecewise((1, x < 1), (2, Eq(x, 3) & (y < x)), (3, True)).integrate((x, 0, 3))
7
>>> Piecewise((1, x < 1), (2, y < 3), (3, True)).integrate((x, 0, 3))
Piecewise((5, (y >= -oo) & (y < 3)), (7, True))
```

In the first case, the 2nd condition depends on x and y whereas in the 2nd case it only 
depends on y...and in the first case since it depends on x and x's range for the 2nd expression 
is from 3 to 3 (zero width) it can't contribute to the integration. So is it right to ignore the value
of y?

And what if there were a DiracDelta function there instead of 2 and the integration went to 4 instead
of 3...then there *would* be a contribution...but this is presently ignored by the current routine:

```
>>> integrate( Piecewise((DiracDelta(x),x<2),(0,True)), (x,-1,1))
1
>>> integrate( Piecewise((DiracDelta(x),Eq(x,0)),(0,True)), (x,-1,1))
0
```

/c

Aaron Meurer

unread,
Feb 2, 2018, 7:29:19 PM2/2/18
to sy...@googlegroups.com
The condition is an And, so it requires both to be true. Thus, it is
only 2 at one value, x=3, which means it doesn't contribute to the
integral.

I'm not really sure how to interpret the Dirac Delta integral. It
seems to me that it should be the same as integrate(DiracDelta(x), (x,
0, 0)), which gives 0.

I think it makes sense, both mathematically and from a practical point
of view, to always make integrals over zero-measure domains equal to
0.

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/f0588adf-0e7f-44fd-b880-d60795f5424c%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Leonid Kovalev

unread,
Feb 2, 2018, 9:53:05 PM2/2/18
to sy...@googlegroups.com
By definition (e.g.,
https://en.wikipedia.org/wiki/Dirac_delta_function#As_a_measure),
DiracDelta would have integral one over any set that contains 0, even
if that set has only one point.
So one has to ask, when we integrate over (x, a, b), do we mean closed
interval [a, b], open (a, b), or half-open [a, b).

With either of two former choices we run into trouble with additivity
over intervals: the integral of DiracDelta over [-1, 0] plus its
integral over [0, 1] is 2, while the integral over [-1, 1] is 1.
Similarly for open.
(SymPy currently sidesteps this issue by returning answers in terms of
Heaviside(0) which is left undefined.)

So I think we should treat the intervals of integration as half-open:
a <= x < b. Then an interval such as (0, 0) is empty set, and the
integral of anything over an empty set is zero.

I would also say that things like Piecewise with DiracDelta inside are
not necessarily well-defined. Since DiracDelta is not a function, one
should not define an integrand as "something when x != 3, and
DiracDelta when x is 3". By implementing DiracDelta as a function,
SymPy allows some expressions, like DiracDelta(x)**2, which have no
mathematical meaning; and then the output is meaningless too.

>>> integrate(DiracDelta(x)**2, (x, -1, 1))
DiracDelta(0) # garbage in, garbage out

Boris Ettinger

unread,
Feb 13, 2018, 3:12:20 AM2/13/18
to sympy
I agree with Leonid, there is no consistent way to define integral [0,anything) of the delta function. It is a theorem, in fact.

Aaron, Sympy seniors,
What was the reasoning to define DiracDelta as a function? How difficult would it be to insert GeneralizedFunction class above the Function class? 
Reply all
Reply to author
Forward
0 new messages