[RFC] change in Piecewise integration behavior

37 views
Skip to first unread message

Chris Smith

unread,
Jun 20, 2017, 8:37:33 AM6/20/17
to sympy
Currently, indefinite integration of Piecewise gives the discontinuous Piecewise result obtained by simply integrating the pieces of the Piecewise. I propose (in PR #12587) that the `integrate` method give the continuous result and a method `piecewise_integrate` be used to return the old behavior. Are there other ideas? Do we need a deprecation of the old behavior?

Aaron Meurer

unread,
Jun 21, 2017, 10:21:44 AM6/21/17
to sy...@googlegroups.com
Can you give an example of old vs. new behavior? Are they mathematically equivalent (up to pievewise constant)?

Aaron Meurer 

On Tue, Jun 20, 2017 at 8:37 AM Chris Smith <smi...@gmail.com> wrote:
Currently, indefinite integration of Piecewise gives the discontinuous Piecewise result obtained by simply integrating the pieces of the Piecewise. I propose (in PR #12587) that the `integrate` method give the continuous result and a method `piecewise_integrate` be used to return the old behavior. Are there other ideas? Do we need a deprecation of the old behavior?

--
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/95872e1e-ac0e-4b3d-b1c2-43520fa88158%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Chris Smith

unread,
Jun 21, 2017, 8:47:28 PM6/21/17
to sympy
The following comes from my current `lts` branch:


>>> var('A:C')
(A, B, C)
>>> i = Piecewise((A, x<1), (B, x>2), (C, True)).integrate(x); i  # new continuous result
Piecewise((A*x, x <= 1), (A + C*x - C, x <= 2), (A + B*x - 2*B + C, True))
>>> for j in range(0,6):
...  j,i.subs(x,j)
...
(0, 0)
(1, A)
(2, A + C)
(3, A + B + C)
(4, A + 2*B + C)
(5, A + 3*B + C)
>>> pwi = Piecewise((A, x<1), (B, x>2), (C, True)).piecewise_integrate(x)  # old discontinuous result
>>> pwi
Piecewise((A*x, x < 1), (B*x, x > 2), (C*x, True))
>>> for j in range(0,6):
...  j,pwi.subs(x,j)
...
(0, 0)
(1, C)
(2, 2*C)
(3, 3*B)
(4, 4*B)
(5, 5*B)

The inequalities changing to equalities represents a corner case that I haven't addressed yet. It especially shows up when the derivatives of the integral are computed:

>>> i.diff(x)
Piecewise((A, x <= 1), (C, x <= 2), (B, True))
>>> pwi.diff(x)
Piecewise((A, x < 1), (B, x > 2), (C, True))

The reversal of args is correct in the first case: the args are ordered according to spatial appearance along the x-axis.

Aaron Meurer

unread,
Jun 22, 2017, 1:48:24 PM6/22/17
to sy...@googlegroups.com
This looks fine. Indefinite integration is only ever defined up to a
piecewise constant, so it isn't necessary to deprecate anything when
changing the mathematical form a result.

Aaron Meurer
> https://groups.google.com/d/msgid/sympy/23828d79-5a21-4961-9e84-977916751c64%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages