Search code examples
pythonsympycontinuous-fourier

Why doesn't sympy simplify the Fourier Transform of a derivative?


We know that the Fourier Transform of a derivative is

Fourier transform of a derivative

where k is the fourier variable. Explanation here

My question is, why doesn't sympy use this knowledge? For example:

from sympy import Function, symbols, fourier_transform, Derivative

f = Function('f')
x, k= symbols('x, k')

G = fourier_transform(Derivative(f(x), x, x) + f(x), x, k)
print(G)

This prints

FourierTransform(f(x), x, k) + FourierTransform(Derivative(f(x), x, x), x, k)

But I expected it to print (up to some factors of 2 pi i)

FourierTransform(f(x), x, k) + k**2 FourierTransform(f(x), x, k)

Is there a way to tell sympy it's save to make this simplification because I expect f(x) -> 0 as x goes to infinity?

If not, what would be the cleanest way to make the substitution?


Solution

  • The simple reason Sympy doesn't do this is that it's not implemented yet. As a workaround for now, you can manually replace the FourierTransform of the derivative with a multiplication:

    from sympy import Wild, FourierTransform, Derivative
    a, b, c = symbols('a b c', cls=Wild)
    G.replace(
        FourierTransform(Derivative(a, b, b), b, c),
        c**2 * FourierTransform(a, b, c)
    )
    

    As far as I know, Sympy doesn't offer a pattern that matches an arbitrary number of arguments, so you can't have a single pattern that matches Derivative(f(x), x), Derivative(f(x), x, x), Derivative(f(x), x, x, x), and so on. You could get around that by using the function-function form of replace(), but if you know what order of derivative you're dealing with, it's probably simpler to just put in that many bs explicitly, as I did in the example.