Symbolic Fourier transform in sagemath.

289 views
Skip to first unread message

Hongyi Zhao

unread,
May 22, 2021, 9:22:06 PM5/22/21
to sage-support
It seems that all the Fourier transform methods implemented in sagemath is numeric, instead of symbolic/analytic.

I want to know whether there are some symbolic/analytic Fourier transform functions, just as we can do in mathematica, in sagemath?

I want to know if there are some symbolic/analytical Fourier transform functions available in sagemath, just as the ones in mathematica?

Regards,
HY

Emmanuel Charpentier

unread,
May 28, 2021, 8:19:07 AM5/28/21
to sage-support

This can be computed “by hand” using (one of) the textbook definition(s) :

sage: var("omega, s")
(omega, s)
sage: integrate(sin(x^2)*e^(-I*s*x), x, -oo, oo)
1/2*sqrt(2)*sqrt(pi)*cos(1/4*s^2) - 1/2*sqrt(2)*sqrt(pi)*sin(1/4*s^2)

Both sympy and giac have implementations of this transform :

sage: from sympy import fourier_transform, sympify
sage: fourier_transform(*map(sympify, (sin(x^2),x, s)))._sage_()
1/2*sqrt(2)*sqrt(pi)*(cos(pi^2*s^2) - sin(pi^2*s^2))
sage: libgiac.fourier(*map(lambda u:u._giac_(), (sin(x^2), x, s))).sage()
1/2*sqrt(2)*sqrt(pi)*(cos(1/4*s^2) - sin(1/4*s^2))

which do not follow the same definitions… But beware : they may be more or less wrong :

sage: integrate(sin(x)*e^(-I*s*x), x, -oo, oo).factor()
undef                                             # Wrong
sage: fourier_transform(*map(sympify, (sin(x),x, s)))._sage_()
0                                                 # Wrong AND misleading
sage: libgiac.fourier(*map(lambda u:u._giac_(), (sin(x), x, s))).sage()
I*pi*dirac_delta(s + 1) - I*pi*dirac_delta(s - 1) # Better...

BTW:

sage: mathematica.FourierTransform(sin(x^2), x, s).sage().factor()
1/2*cos(1/4*s^2) - 1/2*sin(1/4*s^2)
sage: mathematica.FourierTransform(sin(x), x, s).sage().factor()
-1/2*I*sqrt(2)*sqrt(pi)*(dirac_delta(s + 1) - dirac_delta(s - 1))

HTH,

Hongyi Zhao

unread,
May 28, 2021, 12:38:04 PM5/28/21
to sage-support
On Friday, May 28, 2021 at 8:19:07 PM UTC+8 Emmanuel Charpentier wrote:

This can be computed “by hand” using (one of) the textbook definition(s) :

sage: var("omega, s")
(omega, s)
sage: integrate(sin(x^2)*e^(-I*s*x), x, -oo, oo)
1/2*sqrt(2)*sqrt(pi)*cos(1/4*s^2) - 1/2*sqrt(2)*sqrt(pi)*sin(1/4*s^2)

Both sympy and giac have implementations of this transform :

sage: from sympy import fourier_transform, sympify
sage: fourier_transform(*map(sympify, (sin(x^2),x, s)))._sage_()
1/2*sqrt(2)*sqrt(pi)*(cos(pi^2*s^2) - sin(pi^2*s^2))
sage: libgiac.fourier(*map(lambda u:u._giac_(), (sin(x^2), x, s))).sage()
1/2*sqrt(2)*sqrt(pi)*(cos(1/4*s^2) - sin(1/4*s^2))

which do not follow the same definitions… But beware : they may be more or less wrong :

sage: integrate(sin(x)*e^(-I*s*x), x, -oo, oo).factor()
undef                                             # Wrong
sage: fourier_transform(*map(sympify, (sin(x),x, s)))._sage_()
0                                                 # Wrong AND misleading
sage: libgiac.fourier(*map(lambda u:u._giac_(), (sin(x), x, s))).sage()
I*pi*dirac_delta(s + 1) - I*pi*dirac_delta(s - 1) # Better...

BTW:

sage: mathematica.FourierTransform(sin(x^2), x, s).sage().factor()
1/2*cos(1/4*s^2) - 1/2*sin(1/4*s^2)
sage: mathematica.FourierTransform(sin(x), x, s).sage().factor()
-1/2*I*sqrt(2)*sqrt(pi)*(dirac_delta(s + 1) - dirac_delta(s - 1))

But what I got is different from yours:

sage: sage: var("omega, s")                                                                    
(omega, s)
sage: mathematica.FourierTransform(sin(x), x, s).sage().factor()                               
-I*(dirac_delta(s + 1) - dirac_delta(s - 1))*Sqrt(1/2*pi)

 BTW:

How to input the sage computation representation as the code style just like what you've posted?

HY

Dima Pasechnik

unread,
May 28, 2021, 1:01:38 PM5/28/21
to sage-support
this depends of a version of Mathematica

>
> BTW:
>
> How to input the sage computation representation as the code style just like what you've posted?
>
> HY
>
>>
>> HTH,
>>
>> Le dimanche 23 mai 2021 à 03:22:06 UTC+2, hongy...@gmail.com a écrit :
>>>
>>> It seems that all the Fourier transform methods implemented in sagemath is numeric, instead of symbolic/analytic.
>>>
>>> I want to know whether there are some symbolic/analytic Fourier transform functions, just as we can do in mathematica, in sagemath?
>>>
>>> I want to know if there are some symbolic/analytical Fourier transform functions available in sagemath, just as the ones in mathematica?
>>>
>>> Regards,
>>> HY
>>>
> --
> You received this message because you are subscribed to the Google Groups "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sage-support...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/84095de0-8726-4194-a84f-f2f0c5c876c3n%40googlegroups.com.

Hongyi Zhao

unread,
May 28, 2021, 7:16:21 PM5/28/21
to sage-support
Is there a convenient way to prove they are the equivalent forms in sage?

HY

Emmanuel Charpentier

unread,
Jun 4, 2021, 9:54:16 AM6/4/21
to sage-support

This also depends on Trac#31756 , not in 9.3 but in 9.4.beta0 : up to 9.3, mathematica("Sqrt[x]").sage() would give you Sqrt(x) (and not sqrt(x) as expected)…

HTH, 

Emmanuel Charpentier

unread,
Jun 4, 2021, 10:03:47 AM6/4/21
to sage-support

Yep, with a bit of cut’n paste (since both foms can’t be obtained from the same Mathematica installation) :

sage: var("x, s")
(x, s)
sage: a="-I*(dirac_delta(s + 1) - dirac_delta(s - 1))*sqrt(1/2*pi)"         # text representatin of yours.
sage: b="-1/2*I*sqrt(2)*sqrt(pi)*(dirac_delta(s + 1) - dirac_delta(s - 1))" # text representation of mine.
sage: bool(eval(a)==eval(b))
True

This should do it...

Hongyi Zhao

unread,
Jun 5, 2021, 1:02:40 AM6/5/21
to sage-support
Thanks a lot. It does the trick.

HY
Reply all
Reply to author
Forward
0 new messages