Ask Your Question
2

does sagemath support fresnels function?

asked 2018-08-01 20:50:46 -0600

Nasser gravatar image

I am trying to run integration on file that contains problems using fresnels functions. I am not even able to load the file, since sagemath complains that it does not know fresnels.

This function is there in sympy http://docs.sympy.org/latest/modules/...

>python
Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56) 
>>> from sympy import *
>>> fresnels(x)
fresnels(x)

But in Sagemath

sage: var('x')
x
sage: fresnels(x)
NameError                                 Traceback (most recent call last)
<ipython-input-10-08120c00ce46> in <module>()
----> 1 fresnels(x)

NameError: name 'fresnels' is not defined

It is no problem for this to fail, as I can capture the exception. But the problem is that I can't even load the file itself to begin with. The sage script I have starts by reading a plain text file, which contains a list of the problems. Like this

 var('a b c d e m n x ')
 lst=[[x^7*fresnels(b*x),x,6,],
  [x^6*fresnels(b*x),x,6,],
  [x^5*fresnels(b*x),x,5,],
  [x^4*fresnels(b*x),x,5,]]

The sage script does this

        load(currentTestFile)

Where the currentTestFile is as shown above.

And once loaded, it iterates over each integral in the list and run it. But it seems sage parses the file during loading:

>./build_giac.sage 
Test starting.....
    load(currentTestName) #read the problems. This also contains the var('') statement.
  File "sage/misc/persist.pyx", line 136, in sage.misc.persist.load (build/cythonized/sage/misc/persist.c:2440)
  File "/usr/lib/python2.7/site-packages/sage/repl/load.py", line 263, in load
    exec(preparse_file(f.read()) + "\n", globals)
  File "<string>", line 3, in <module>
NameError: name 'fresnels' is not defined

So I am not able to even load the file. If I can even load the file, then if the integral fails afterwords, it is OK, since I can trap the exception, mark it as failed, and go to the next integral.

First question is: Does Sagemath have no support for fresnels? And in this case, how could one bypass this error during reading of the input file to give me a change to run the integrals?

Using SageMath version 8.3.rc2, Release Date: 2018-07-22

Thank you

--Nasser

edit retag flag offensive close merge delete

Comments

1

Hey! It seems that the support to Fresnel integrals starts with Sagemath 8.3 beta4.

https://trac.sagemath.org/ticket/24212

I didn’t read all the ticket, but if it is correct, it is very nice!

joaoff gravatar imagejoaoff ( 2018-08-02 01:58:28 -0600 )edit

If you could try the fresnel_sin() command, tell me if it works. I’m still using Sagemath 7.5 :/

joaoff gravatar imagejoaoff ( 2018-08-02 02:05:16 -0600 )edit

I confirm that 8.3.rc3 has fresne_sin and fresnel_cos.

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2018-08-02 12:56:26 -0600 )edit

2 answers

Sort by » oldest newest most voted
7

answered 2018-08-05 02:40:04 -0600

Emmanuel Charpentier gravatar image

updated 2018-08-06 10:45:28 -0600

Time to make it a "real" answer :

As of Sage 8.3 (released Aug, 3, 2018), Sage implements :

  • fresnel_sin (i. e. $\displaystyle\int_0^x \sin\frac{\pi t^2}{2} dt$), and

  • fresnel_cos (i. e. $\displaystyle\int_0^x \cos\frac{\pi t^2}{2} dt$).

Note that Sage follows DLMF's (a. k. a. Abramowitz & Stegun) definitions rather that the simpler ones quoted by (the start of the) Wikipedia article. Note also that this does not implement Fresnel's $\cal{F}(z)=\displaystyle\int_z^\infty \textrm{e}^{\frac{1}{2}\pi i t^2} \textrm{d}t $ (left as an exercise to the reader ?).

edit flag offensive delete link more
5

answered 2018-08-05 17:36:21 -0600

slelievre gravatar image

In order to use SymPy's fresnelc and fresnels functions in Sage, one should import them.

This is done as follows.

sage: from sympy import fresnelc, fresnels

Then one can do for instance

sage: fresnels(x)
fresnels(x)
sage: integrate(fresnels(x), (x, 0, 1))
-1/pi + fresnel_sin(1)

The above is run using Sage 8.3.rc3.

sage: version()
'SageMath version 8.3.rc3, Release Date: 2018-07-28'
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-08-01 20:50:46 -0600

Seen: 110 times

Last updated: Aug 06