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