strange behavior with Integral.diff

18 views
Skip to first unread message

Carsten Knoll

unread,
May 24, 2016, 3:32:09 AM5/24/16
to sy...@googlegroups.com
Hi all,

I've encountered an error when deriving an integral expression which
contains a derivative and has variable bounds. My setup looks like this:

> In [1]: from sympy import *
> In [2]: init_printing()
> In [3]: x, xi = symbols("x, xi"); k = Function("k")
> In [4]: exp = Integral(k(x, xi).diff(x), (xi, 0, x)); exp
> Out[4]:
> x
> ⌠
> ⎮ ∂
> ⎮ ──(k(x, ξ)) dξ .
> ⎮ ∂x
> ⌡
> 0

For testing purposes I substituted the expression

> In [5]: k_test = x**2*xi + x*xi**2 ,

leading to

> In [6]: exp.subs(k(x, xi), k_test).doit()
> Out[6]:
> 3
> 4⋅x
> ──── ,
> 3

which is correct from my point of view.

The problem arises when I differentiate the expression:

> In [9]: exp_dx = exp.diff(x); exp_dx
> Out[9]:
> x
> ⌠
> ⎮ 2
> d ⎮ ∂
> ──(k(x, x)) + ⎮ ───(k(x, ξ)) dξ .
> dx ⎮ 2
> ⎮ ∂x
> ⌡
> 0

According to the Leibniz integral rule
<https://en.wikipedia.org/wiki/Leibniz_integral_rule> I would expect the
first term to be the derivative of k(x, x) in favour of its first
argument instead of the total derivative.
Substituting the text expression thus leads to

> In [9]: exp_dx.subs([(k(x, xi), k_test), (k(x, x), k_test.subs(xi, x))]).doit()
> Out[9]:
> 2
> 7⋅x ,

which differs from my manual computation that would evaluate to 4x².

Any thoughts on what I could have done wrong, or how to circumvent this
problem?

Thanks in advance,
Stefan (c/o Carsten)
Reply all
Reply to author
Forward
0 new messages