product rule in differentiate_finite in sympy 1.0.1

65 views
Skip to first unread message

Federico Halpern

unread,
Feb 15, 2017, 8:31:27 PM2/15/17
to sympy
Hi everyone,

I just started using sympy. I expect that I will use the finite differencing routines to automatically generate arbitrary precision operators (for example, the Arakawa bracket). This is for use in a plasma turbulence / stability code.

My thanks go to the developers for creating this package, it will save me tons of effort and blood in developing my code.

I wanted to raise an issue that I noticed in an example from the documentation:

>>> x = symbols('x')
>>> f, g = symbols('f g', cls=Function)
>>> differentiate_finite(f(x)*g(x))
(-f(x - 1/2) + f(x + 1/2))⋅g(x) + (-g(x - 1/2) + g(x + 1/2))⋅f(x)

Although it could be useful in some situations, this expression is not valid for finite differences. The reason for this is that the continuous version of the product rule 

d/dx(f(x)g(x)) = g(x)d/dx(f(x) + f(x)d/dx(g(x) 

does not apply in discrete systems. So one cannot just expand the expression and then use the product rule. A large part of the applied mathematics literature is devoted to designing numerical schemes that preserve a "discrete product rule." Examples of this are summation-by-parts and mimetic finite differences.

A more reasonable behavior was also given in the documentation:

>>> differentiate_finite(f(x)*g(x), evaluate=False)
-f(x - 1/2)⋅g(x - 1/2) + f(x + 1/2)⋅g(x + 1/2)

In the last version, we get a finite difference of the product f(x)g(x), which is correct. This should be the default behavior.

Thanks again everyone, I look forward to creating some crazy numerical schemes using this symbolic toolbox. Best,

Federico

Aaron Meurer

unread,
Feb 15, 2017, 8:36:07 PM2/15/17
to sy...@googlegroups.com
Can you open an issue for this in the issue tracker?
https://github.com/sympy/sympy/issues

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/6646a62e-1895-4c15-b2b7-bc634fca6ea5%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages