Simplify

11 views
Skip to first unread message

Mani Chandra

unread,
Jun 19, 2011, 2:51:05 PM6/19/11
to sy...@googlegroups.com
Hi,

Is it possible to tell simplify that the partial derivatives with respect to two different variable commute so that it can simplify further? For ex:

d^2 f/dxdy + d^2 f/dydx

The above expression is left as it is by simplify(), but it would be nice if there were some way to tell it about the commutation so that it can simplify further.

Thanks,
Mani Chandra

Renato Coutinho

unread,
Jun 19, 2011, 8:05:58 PM6/19/11
to sy...@googlegroups.com
Hello,

This is fixed in current development version, so that

>>> f(x, y).diff(x, y) - f(x, y).diff(y, x)
0

If you don't want this to happen, you have to use unevaluated
derivatives (diff() always evaluates them):

>>> Derivative(f(x, y), x, y) - Derivative(f(x, y), y, x)
D(f(x, y), x, y) - D(f(x, y), y, x)

Cheers,
Renato

Chris Smith

unread,
Jun 19, 2011, 8:30:05 PM6/19/11
to sy...@googlegroups.com
 
Notice that he used "+" not "-" -- does he want `2*D(f(x,y), x, y)` to be returned?

Chris Smith

unread,
Jun 19, 2011, 8:39:48 PM6/19/11
to sy...@googlegroups.com


On Sun, Jun 19, 2011 at 7:34 PM, Renato Coutinho <renato....@gmail.com> wrote:
Yes, I think that's what he meant, and it works too, returning
2*D(f(x, y), x, y).

Then, Mani, it would be good if you showed the actual input (not ASCII math) for what you entered and what you got. Just copy and paste like Renato did in his examples.

Renato Coutinho

unread,
Jun 19, 2011, 8:34:20 PM6/19/11
to sy...@googlegroups.com
On Sun, Jun 19, 2011 at 9:30 PM, Chris Smith <smi...@gmail.com> wrote:
>
>

Yes, I think that's what he meant, and it works too, returning
2*D(f(x, y), x, y).

Julien Rioux

unread,
Jun 20, 2011, 11:01:22 AM6/20/11
to sympy
On Jun 19, 8:34 pm, Renato Coutinho <renato.couti...@gmail.com> wrote:
> On Sun, Jun 19, 2011 at 9:30 PM, Chris Smith <smi...@gmail.com> wrote:
>
> > On Sun, Jun 19, 2011 at 7:05 PM, Renato Coutinho <renato.couti...@gmail.com>
> > wrote:
>
> >> Hello,
>
> >> On Sun, Jun 19, 2011 at 3:51 PM, Mani Chandra <mc0...@gmail.com> wrote:
> >> > Hi,
> >> > Is it possible to tell simplify that the partial derivatives with
> >> > respect to
> >> > two different variable commute so that it can simplify further? For ex:
> >> > d^2 f/dxdy + d^2 f/dydx
> >> > The above expression is left as it is by simplify(), but it would be
> >> > nice if
> >> > there were some way to tell it about the commutation so that it can
> >> > simplify
> >> > further.
>
> >> This is fixed in current development version, so that
>
> >> >>> f(x, y).diff(x, y) - f(x, y).diff(y, x)
> >> 0
>
> >> If you don't want this to happen, you have to use unevaluated
> >> derivatives (diff() always evaluates them):
>
> >> >>> Derivative(f(x, y), x, y) - Derivative(f(x, y), y, x)
> >> D(f(x, y), x, y) - D(f(x, y), y, x)
>
> > Notice that he used "+" not "-" -- does he want `2*D(f(x,y), x, y)` to be
> > returned?
>
> Yes, I think that's what he meant, and it works too, returning
> 2*D(f(x, y), x, y).

With current git I get the behavior

In [1]: x=Symbol('x')

In [2]: y=Symbol('y')

In [3]: f=Function('f')

In [4]: f(x,y).diff(x,y)-f(x,y).diff(y,x)
Out[4]: 0

In [5]: f(x,y).diff(x,y)+f(x,y).diff(y,x)
Out[5]:
2
d
2⋅─────(f(x, y))
dy dx

In [6]:

However, this is a new behavior compared to just a couple weeks ago (I
could not say when exactly was the last time I used git pull). The new
behavior assumes that the partial derivatives of the function f(x,y)
are continuous everywhere. See e.g.
http://en.wikipedia.org/wiki/Symmetry_of_second_derivatives#Non-symmetry
Is this change intended?

Cheers,
Julien

Renato Coutinho

unread,
Jun 20, 2011, 11:09:40 AM6/20/11
to sy...@googlegroups.com
On Mon, Jun 20, 2011 at 12:01 PM, Julien Rioux <julien...@gmail.com> wrote:
> However, this is a new behavior compared to just a couple weeks ago (I
> could not say when exactly was the last time I used git pull). The new
> behavior assumes that the partial derivatives of the function f(x,y)
> are continuous everywhere. See e.g.
> http://en.wikipedia.org/wiki/Symmetry_of_second_derivatives#Non-symmetry
> Is this change intended?

Yes, it is. See commit 53fbd255 [0] and issue 1435 [1]. We assume by
default continuity of derivatives to the order needed, if the
Derivatives are evaluated. It's planned to implement an assumption to
allow the user to assume discontinuity of derivatives instead - issue
2471 [2].

Renato

[0] https://github.com/sympy/sympy/commit/53fbd25510f0294d89398c5f9d0bee2f88492232
[1] http://code.google.com/p/sympy/issues/detail?id=1435
[2] http://code.google.com/p/sympy/issues/detail?id=2471

Julien Rioux

unread,
Jun 20, 2011, 11:32:26 AM6/20/11
to sympy
On Jun 20, 11:09 am, Renato Coutinho <renato.couti...@gmail.com>
wrote:
> On Mon, Jun 20, 2011 at 12:01 PM, Julien Rioux <julien.ri...@gmail.com> wrote:
> > However, this is a new behavior compared to just a couple weeks ago (I
> > could not say when exactly was the last time I used git pull). The new
> > behavior assumes that the partial derivatives of the function f(x,y)
> > are continuous everywhere. See e.g.
> >http://en.wikipedia.org/wiki/Symmetry_of_second_derivatives#Non-symmetry
> > Is this change intended?
>
> Yes, it is. See commit 53fbd255 [0] and issue 1435 [1]. We assume by
> default continuity of derivatives to the order needed, if the
> Derivatives are evaluated. It's planned to implement an assumption to
> allow the user to assume discontinuity of derivatives instead - issue
> 2471 [2].
>
> Renato
>
> [0]https://github.com/sympy/sympy/commit/53fbd25510f0294d89398c5f9d0bee2...
Thanks for the pointers. That's fine, except for one nitpick.
Paraphrasing, you say: what is missing is a way to assume
discontinuity of derivatives. But, in fact, what is missing is a way
to remove the assumption on continuity of derivatives, i.e., don't
assume anything about derivatives.

I think of it like commutativity of Symbol. When you create a symbol
it is assumed commutative by default. That's fine, that's the decision
of the sympy devs. Internally, Symbol('x') carries the assumption
commutative=True. You can remove this assumption by
Symbol('x',commutative=False). A similar construct for Function would
be nice.

Cheers,
Julien

Mani Chandra

unread,
Jun 21, 2011, 3:22:10 AM6/21/11
to sy...@googlegroups.com
Thank you, this is exactly what I wanted. Sorry for the late reply.

Regards,
Mani
Reply all
Reply to author
Forward
0 new messages