Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fresnel integrals #24212

Closed
rwst opened this issue Nov 13, 2017 · 72 comments
Closed

Fresnel integrals #24212

rwst opened this issue Nov 13, 2017 · 72 comments

Comments

@rwst
Copy link
Contributor

rwst commented Nov 13, 2017

The SymPy-Sage interface raises an error because there are no Fresnel integral functions in Sage:

sage: integrate(sin(x^2), x, algorithm='sympy')
...
AttributeError: 

see:

sage: import sympy
sage: x = sympy.Symbol('x')
sage: sympy.integrate(sympy.sin(x^2), x)
3*sqrt(2)*sqrt(pi)*fresnels(sqrt(2)*x/sqrt(pi))*gamma(3/4)/(8*gamma(7/4))

They are holonomic so they should be in Sage.

Depends on #24425

CC: @mforets

Component: symbolics

Author: Marcelo Forets

Branch/Commit: f49ce18

Reviewer: Ralf Stephan

Issue created by migration from https://trac.sagemath.org/ticket/24212

@rwst rwst added this to the sage-8.2 milestone Nov 13, 2017
@rwst

This comment has been minimized.

@mforets
Copy link
Mannequin

mforets mannequin commented Nov 19, 2017

Commit: e52fb2e

@mforets
Copy link
Mannequin

mforets mannequin commented Nov 19, 2017

Branch: u/mforets/fresnel_integrals

@mforets
Copy link
Mannequin

mforets mannequin commented Nov 19, 2017

comment:2

This is a tentative implementation of sine Fresnel integral. The numerical evaluation relies on mpmath. I doubted about how to write the custom evaluation _eval_ method. In fact I have two failing doctests. I expect:

sage: fresnel_sin(0)
0
sage: fresnel_sin(x).subs(x==0)
0

whereas i get fresnel_sin(0) in both cases. Any hints?

@mforets
Copy link
Mannequin

mforets mannequin commented Nov 19, 2017

comment:3

Oh, and the beta(... --> beta... is because the missing parentheses were confusing my text editor, so that the entire file from that line on was shown as comments. I should remember to undo this change :)

@rwst
Copy link
Contributor Author

rwst commented Nov 20, 2017

comment:4

Returning None (or just passing) in _eval_ amounts to returning a held expression. _evalf_ is only used for inexact arguments or .n():

sage: fresnel_sin(0.)
0.000000000000000
sage: fresnel_sin(0).n()
0.000000000000000

For results to exact or symbolic arguments you need to implement them in _eval_.

@rwst
Copy link
Contributor Author

rwst commented Nov 20, 2017

comment:5

You would just need to handle 0 and oo in _eval_, and handle oddness before it, i.e. if arg.is_negative(): return -fresnel_sin(-arg).

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Nov 21, 2017

Branch pushed to git repo; I updated commit sha1. New commits:

f158660symbolics in fresnel_sin eval

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Nov 21, 2017

Changed commit from e52fb2e to f158660

@mforets
Copy link
Mannequin

mforets mannequin commented Nov 21, 2017

comment:7

ok, that fixed the 0, oo and -oo evaluations. i added two new tests for the I*oo cases, but this is still wrong. since

sage: SR(I*oo).is_infinity()
True

probably i could use x.is_real() too.

@rwst
Copy link
Contributor Author

rwst commented Nov 21, 2017

comment:8

You mean unsigned_infinity?

@mforets
Copy link
Mannequin

mforets mannequin commented Nov 21, 2017

comment:9

i should relate unsigned_infinity to test if the argument is complex and infinite? the doc of unsigned_infinity is precarious:

sage: unsigned_infinity?
Type:           UnsignedInfinity
String form:    Infinity
File:           ~/Tools/sage-master/local/lib/python2.7/site-packages/sage/rings/infinity.py
Docstring:         Initialize "self".
Init docstring:    Initialize "self". 

i'm tempted to add a ticket to explain this object more.

@rwst
Copy link
Contributor Author

rwst commented Nov 21, 2017

comment:10

Replying to @mforets:

i should relate unsigned_infinity to test if the argument is complex and infinite?

No, I was not sure what you had in mind. If you want to test if the argument is complex and infinite then do: if arg.is_infinity() and not arg.is_real(). Technically a False for arg.is_real() just means "I don't know" so you get True for SR(unsigned_infinity).is_real(), but the correct behaviour must wait until we have is_complex(). Just use not arg.is_real() for now.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Nov 22, 2017

Branch pushed to git repo; I updated commit sha1. New commits:

ada47e4handle complex infinities

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Nov 22, 2017

Changed commit from f158660 to ada47e4

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Nov 22, 2017

Changed commit from ada47e4 to 869020b

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Nov 22, 2017

Branch pushed to git repo; I updated commit sha1. New commits:

869020badd cosine Fresnel integral

@mforets
Copy link
Mannequin

mforets mannequin commented Nov 22, 2017

Author: Marcelo Forets

@mforets mforets mannequin added the s: needs review label Nov 22, 2017
@mforets
Copy link
Mannequin

mforets mannequin commented Nov 22, 2017

comment:14

oh, there's no conversion back to sage:

sage: fresnel_sin(x)._sympy_() # ok
fresnels(x)
sage: fresnel_sin(x)._sympy_()._sage_() # not working!

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Nov 22, 2017

Branch pushed to git repo; I updated commit sha1. New commits:

e930137add sympy -> sage conversion, and doctest

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Nov 22, 2017

Changed commit from 869020b to e930137

@rwst
Copy link
Contributor Author

rwst commented Nov 22, 2017

comment:16

See how easy it is to add conversions now.

@mforets
Copy link
Mannequin

mforets mannequin commented Nov 22, 2017

comment:17

See how easy it is to add conversions now.

awesome! it took me what, 15 minutes? and it was the first time i was doing that.

@rwst
Copy link
Contributor Author

rwst commented Nov 26, 2017

comment:18

Patchbot has relevant doctest errors.

@rwst
Copy link
Contributor Author

rwst commented Dec 24, 2017

Dependencies: #24425

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Dec 26, 2017

Branch pushed to git repo; I updated commit sha1. New commits:

a17755c24425: Fix inherently failing random_expr doctest
96521a4Merge branch 't/24425/fix_inherently_failing_random_expr_doctest' into t/24212/24212-2

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Dec 26, 2017

Changed commit from e3cd31a to 96521a4

@rwst
Copy link
Contributor Author

rwst commented Dec 26, 2017

comment:44

Dependency needs review.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Feb 24, 2018

Changed commit from 96521a4 to e4f1592

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Feb 24, 2018

Branch pushed to git repo; I updated commit sha1. New commits:

e4f1592Merge branch 'develop' into t/24212/24212-2

@mforets
Copy link
Mannequin

mforets mannequin commented Jun 5, 2018

comment:46

The dependency has been approved and merged. Thanks.

I've merged with the latest development version and now i'm checking if the branch applies.

@mforets
Copy link
Mannequin

mforets mannequin commented Jun 5, 2018

Changed commit from e4f1592 to none

@mforets
Copy link
Mannequin

mforets mannequin commented Jun 5, 2018

Changed branch from u/rws/24212-2 to t/rws/24212-2

@mforets
Copy link
Mannequin

mforets mannequin commented Jun 5, 2018

Changed branch from t/rws/24212-2 to u/mforets/24212-2

@mforets
Copy link
Mannequin

mforets mannequin commented Jun 5, 2018

Commit: 61b2f76

@mforets
Copy link
Mannequin

mforets mannequin commented Jun 5, 2018

New commits:

e3cd31a24212: Fresnel integrals
96521a4Merge branch 't/24425/fix_inherently_failing_random_expr_doctest' into t/24212/24212-2
e4f1592Merge branch 'develop' into t/24212/24212-2
61b2f76Merge branch 'develop' into t/24212/24212-2

@mforets
Copy link
Mannequin

mforets mannequin commented Jun 6, 2018

comment:48
$ ./sage -t src/sage/calculus/calculus.py src/sage/functions/*
...
Git branch: t/24212/24212-2
Using --optional=mpir,python2,sage
...
----------------------------------------------------------------------
All tests passed!
----------------------------------------------------------------------
Total time for all tests: 106.7 seconds
    cpu time: 111.3 seconds
    cumulative wall time: 104.6 seconds

@tscrim
Copy link
Collaborator

tscrim commented Jun 6, 2018

comment:49

Quick question: do you want to change the test in calculus.py? In particular, do you still want to test that Sage handles the case when something in sympy gives something Sage doesn't know how to handle?

@mforets
Copy link
Mannequin

mforets mannequin commented Jun 6, 2018

comment:50

Alright. I found this one:

sage: laplace(cos(-1/t), t, s, algorithm='sympy')
...
AttributeError: Unable to convert SymPy result (=meijerg(((), ()), ((-1/2, 0, 1/2), (0,)), s**2/16)/4) into Sage

(side note: i didn't read the syntax of sympy's meijerg function, but here is a quick comparison to WA's answer)

@rwst
Copy link
Contributor Author

rwst commented Jun 6, 2018

comment:51

Replying to @mforets:

sage: laplace(cos(-1/t), t, s, algorithm='sympy')
...
AttributeError: Unable to convert SymPy result (=meijerg(((), ()), ((-1/2, 0, 1/2), (0,)), s**2/16)/4) into Sage

For that, there is #17970.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 6, 2018

Changed commit from 61b2f76 to f49ce18

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 6, 2018

Branch pushed to git repo; I updated commit sha1. New commits:

f49ce18add doctest with attributeerror

@rwst
Copy link
Contributor Author

rwst commented Jun 6, 2018

comment:54

When we have #17970 we'll likely convert the G expression to the Fresnel expression in Sage.

@vbraun
Copy link
Member

vbraun commented Jun 7, 2018

Changed branch from u/mforets/24212-2 to f49ce18

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants