Re: [sympy] diff ∘ integrate = Identity ?

23 views
Skip to first unread message

Chris Smith

unread,
Jun 26, 2012, 9:40:22 AM6/26/12
to sy...@googlegroups.com
>>>> print J.diff(x)
> f(x) + Integral(0, (t, 0, x))

>>> J.diff(x).doit()
f(x)

/c

krastano...@gmail.com

unread,
Jun 26, 2012, 9:59:29 AM6/26/12
to sy...@googlegroups.com
A few days ago it was mentioned that it makes sense for simplify() to
also call doit() internally.

Pierre H

unread,
Jun 26, 2012, 10:01:23 AM6/26/12
to sy...@googlegroups.com

>>> J.diff(x).doit()
f(x)

Thanks, it indeed does the job. I just didn't know this method... 

Now, I have a second problem wich a slight modification :
>>> J1 = f(x-t).integrate((t,0,x))

>>> print J1.diff(x)
f(0) + Integral(Subs(Derivative(f(_xi_1), _xi_1), (_xi_1,), (-t + x,)), (t, 0, x))

This result, even with the nice MathJax rendering in IPython Notebook is pretty difficult to understand and the "doit" trick doesn't help.
I did a separate pen and paper derivation and came to the conclusion that J1.diff(x) is actually f(x)

However, I do not trust my integration skills which is the reason why I asked sympy for this case. Is it a kind of symbolic integration that is not supported by current sympy ? Or is just me doing bad integration  ;-) ...

Best,
Pierre



krastano...@gmail.com

unread,
Jun 26, 2012, 10:08:50 AM6/26/12
to sy...@googlegroups.com
The problem is that Subs is not smart enough to know that it contains
only a derivative. Changing the variables will help as it will remove
the need for Subs (substituting t-x -> y). Maybe it would be
appropriate to file a bug report with this.

Concerning the latex printer, there is a fix currently waiting as a
pull request.

Pierre H

unread,
Jun 26, 2012, 10:19:44 AM6/26/12
to sy...@googlegroups.com
Thanks for the feedback
Le mardi 26 juin 2012 16:08:50 UTC+2, Stefan Krastanov a écrit :
The problem is that Subs is not smart enough to know that it contains
only a derivative. Changing the variables will help as it will remove
the need for Subs (substituting t-x -> y). Maybe it would be
appropriate to file a bug report with this.

 I didn't get exactly what the bug report should be file against ?

Pierre

Aaron Meurer

unread,
Jun 26, 2012, 10:19:45 AM6/26/12
to sy...@googlegroups.com
On Jun 26, 2012, at 8:01 AM, Pierre H <pierre.etie...@gmail.com> wrote:


>>> J.diff(x).doit()
f(x)

Thanks, it indeed does the job. I just didn't know this method... 

Now, I have a second problem wich a slight modification :
>>> J1 = f(x-t).integrate((t,0,x))

>>> print J1.diff(x)
f(0) + Integral(Subs(Derivative(f(_xi_1), _xi_1), (_xi_1,), (-t + x,)), (t, 0, x))

This result, even with the nice MathJax rendering in IPython Notebook is pretty difficult to understand and the "doit" trick doesn't help.
I did a separate pen and paper derivation and came to the conclusion that J1.diff(x) is actually f(x)

The Subs object is just SymPy's way of representing the derivative of f evaluated at x - t (that is, f'(x - t)). We could probably pretty print this nicer. 

I believe your derivation is correct. Unfortunately, SymPy's integrate is not so good at applying general rules. In this case, it doesn't know that the Subs object is just a derivative, and after a substitution, can be evaluated by the fundamental theorem of calculus. 

However, we know that, and we can tell this to SymPy.  If you take just the integral part and use .transform() to do a change of variables, it can be simplified. In other words,

(f(0) + Integral(Subs(Derivative(f(_xi_1), _xi_1), (_xi_1,), (-t + x,)), (t, 0, x)).transform(x - t, t)).doit()

will give f(x). 

(you will need to create the Symbol _xi_1)

Feel free to open issues in our issue tracker at http://code.google.com/p/sympy/issues/list for both of these problems (printing of Subs and the inability to do the integral), as well as for any other problems you find in SymPy. 

Aaron Meurer


However, I do not trust my integration skills which is the reason why I asked sympy for this case. Is it a kind of symbolic integration that is not supported by current sympy ? Or is just me doing bad integration  ;-) ...

Best,
Pierre



--
You received this message because you are subscribed to the Google Groups "sympy" group.
To view this discussion on the web visit https://groups.google.com/d/msg/sympy/-/zDVV1g-b-LQJ.
To post to this group, send email to sy...@googlegroups.com.
To unsubscribe from this group, send email to sympy+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sympy?hl=en.

krastano...@gmail.com

unread,
Jun 26, 2012, 10:23:24 AM6/26/12
to sy...@googlegroups.com
A partial solution to the subs printing issue can be seen here
https://github.com/sympy/sympy/pull/1386

It solves the fact that the latex printing of subs is broken, however
it does not make the change towards f'(t-x) type of printing.

Aaron Meurer

unread,
Jun 26, 2012, 10:25:53 AM6/26/12
to sy...@googlegroups.com
The bug is that integrate should be able to do the integral
(integrate(subs(f(x).diff(x), x), x, x - t), (t, 0, x))), because the
answer is computable (f(x) - f(0)).

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/sympy/-/3XmDtWxrU0wJ.

Pierre H

unread,
Jun 26, 2012, 11:55:19 AM6/26/12
to sy...@googlegroups.com

Le mardi 26 juin 2012 16:19:45 UTC+2, Aaron Meurer a écrit :

Feel free to open issues in our issue tracker at http://code.google.com/p/sympy/issues/list for both of these problems (printing of Subs and the inability to do the integral), as well as for any other problems you find in SymPy. 

I hope I managed to make a clear enough description.

Stefan's pull request is indeed a good move towards better readability of Subs instances.

Thank you again for your feedback !

Pierre
Reply all
Reply to author
Forward
0 new messages