4

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?

Community
  • 1
  • 1
tBuLi
  • 2,295
  • 2
  • 16
  • 16

1 Answers1

4

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.

David Z
  • 128,184
  • 27
  • 255
  • 279
  • Thanks for your answer! This works, with the slight caveat that replace does not work in-place so I needed an additional `G = ...` (took me longer to figure out than it might seem ;)). Thanks for pointing out that it still needs to be implemented, if I end up using this in my project I might as well submit a PR to implement this. – tBuLi Jan 10 '17 at 16:50
  • Sure, I didn't want to assume whether you wanted to assign the result of the replacement to `G` or not. Sorry I didn't clarify that. If you can properly implement FTs of derivatives I'm sure that would be much appreciated by the Sympy community - but I would imagine the reason it hasn't been done is that it's somehow tricky! So good luck ;-) – David Z Jan 10 '17 at 18:42