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

Make Airy functions symbolic #12455

Closed
sagetrac-olazo mannequin opened this issue Feb 7, 2012 · 112 comments
Closed

Make Airy functions symbolic #12455

sagetrac-olazo mannequin opened this issue Feb 7, 2012 · 112 comments

Comments

@sagetrac-olazo
Copy link
Mannequin

sagetrac-olazo mannequin commented Feb 7, 2012

As discussed in sage-support.

Currently sage can evaluate airy functions numerically:

sage: airy_ai(1.4)
0.0820380498076

but it doesn't work symbolically

sage: airy_ai(x)
...
TypeError: Cannot evaluate symbolic expression to a numeric value.

We should make it symbolical for both airy_ai and airy_bi, as well as their derivatives.

Depends on #12289
Depends on #17130

CC: @kcrisman @burcin @benjaminfjones @fredrik-johansson @eviatarbach

Component: symbolics

Keywords: Airy functions sd40.5 sd48

Author: Oscar Gerardo Lazo Arjona, Benjamin Jones, Douglas McNeil, Eviatar Bach, Ralf Stephan

Branch: 2f6945a

Reviewer: Eviatar Bach, Karl-Dieter Crisman, Burcin Erocal, Ralf Stephan, Jeroen Demeyer, Marc Mezzarobba

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

@sagetrac-olazo sagetrac-olazo mannequin added this to the sage-5.11 milestone Feb 7, 2012
@sagetrac-olazo sagetrac-olazo mannequin assigned burcin Feb 7, 2012
@sagetrac-olazo sagetrac-olazo mannequin added the c: symbolics label Feb 7, 2012
@sagetrac-olazo sagetrac-olazo mannequin assigned sagetrac-olazo and unassigned burcin Feb 7, 2012
@sagetrac-olazo

This comment has been minimized.

@sagetrac-olazo
Copy link
Mannequin Author

sagetrac-olazo mannequin commented Feb 7, 2012

comment:4

Attachment: trac_12455-symbolic_airy.patch.gz

I've added a patch, which should do the job, but it has a few shortcomings:

1.-The resulting symbolic functions seem to remain on hold:

sage: airy_ai(1.0)
airy_ai(1.00000000000000)

You need to force it to evaluate:

sage: airy_ai(1.0).n()
0.135292416313

2.- This doesn't work:

sage: airy_ai(2.0).n(digits=100)
0.0349241304233

3.- There is no evaluation for airy_ai_prime or airy_bi_prime

4.- I'm not sure about how should the functions be called, some possible schemes are

{ai,bi,aip,bip}
{ai,bai,aip,baip}
{airy_ai,airy_bi,airy_ai_prime,airy_bi_prime}

And also whether the latex representation should be capitalized or not. I chose the third scheme, and capitalized typesetting.

@sagetrac-olazo sagetrac-olazo mannequin added the s: needs review label Feb 7, 2012
@kcrisman
Copy link
Member

kcrisman commented Feb 7, 2012

comment:6

Good start. A few responses.

  • You'll need to have more methods. We should probably use mpmath to evaluate these functions in general, though using the SciPy version could be useful over RDF. See Sage is missing the lambert_w function #11888 for a very recent example of this kind of thing and how to implement it.
  • That should also fix precision issues, if properly done, I think.
  • SciPy has evaluation for the airy primes. I think that Maxima has these too. (Cc:ing FJ in case he has plans to add these to mpmath.)
  • We should have translations of these to Maxima and friends. That will probably help us name them. What do Mathematica and Maple call them?
  • All methods, including initialization methods, need doctests. Many of the new symbolic functions added at symbolics/functions will have nice models to follow.

Thanks for getting us a start on this! That's great.

@kcrisman kcrisman changed the title Make Airy functions symbolical Make Airy functions symbolic Feb 7, 2012
@fredrik-johansson
Copy link
Contributor

comment:7

mpmath has the derivatives (as well as integrals) -- just use the optional 'derivative' parameter.

@kcrisman
Copy link
Member

kcrisman commented Feb 7, 2012

comment:8

mpmath has the derivatives (as well as integrals) -- just use the optional 'derivative' parameter.

Ok, I didn't realize that was what that parameter was about. Though in retrospect it seems obvious!

@sagetrac-olazo
Copy link
Mannequin Author

sagetrac-olazo mannequin commented Feb 7, 2012

comment:9

On second thought, I think it would be better to use the airy equation to calculate derivatives or order higher than 1. Like

sage: airy_ai(2,x)
x*airy_ai(x)
sage: airy_ai(3,x)
airy_ai(x)+x*airy_ai_prime(x)
sage: diff(airy_ai(x),x,2)
x*airy_ai(x)
sage: diff(airy_ai(x),x,3)
airy_ai(x)+x*airy_ai_prime(x)

which is very likey to be the way mpmath calculates higher order derivatives. Integrals however, would be returned as:

sage: airy_ai(-1,x)
airy_ai(-1,x)
sage: integral(airy_ai(x),x)
airy_ai(-1,x)

what do you think?

@sagetrac-olazo
Copy link
Mannequin Author

sagetrac-olazo mannequin commented Feb 19, 2012

comment:10

Attachment: trac_12455-symbolic_airy2.patch.gz

I just added a new patch. The new version includes generalized derivatives, evaluation with mpmath, and special values of the functions and their derivatives. Just a one doubt, the coverage is:

oscar@oscar-netbook:~$ sage -coverage airy.py
SCORE /home/oscar/sage/my_patches/airy.py: 76% (20 of 26)

Missing documentation:
	 * __init__(self):
	 * __init__(self):
	 * __init__(self):
	 * __init__(self):
	 * __init__(self):
	 * __init__(self):


Possibly wrong (function name doesn't occur in doctests):
	 * _derivative_(self, x, diff_param=None):
	 * _eval_(self, x):
	 * _evalf_(self, x, parent=None):
	 * _derivative_(self, x, diff_param=None):
	 * _eval_(self, x):
	 * _evalf_(self, x, parent=None):
	 * _derivative_(self, alpha, *args, **kwds):
	 * _eval_(self, alpha, *args):
	 * _evalf_(self, alpha, x, parent=None):
	 * _derivative_(self, x, diff_param=None):
	 * _eval_(self, x):
	 * _evalf_(self, x, parent=None):
	 * _derivative_(self, x, diff_param=None):
	 * _eval_(self, x):
	 * _evalf_(self, x, parent=None):
	 * _derivative_(self, alpha, *args, **kwds):
	 * _eval_(self, alpha, *args):
	 * _evalf_(self, alpha, x, parent=None):

Is that important?

@kcrisman
Copy link
Member

comment:11

Is that important?

The second part isn't, as you are implicitly testing these 'hidden' functions. By the way,

Examples::

should be

EXAMPLES::

However, the first part (the initialization methods) is important for our coverage. You can just do a couple from the big examples that you have.

Do these pass doctests? I'm surprised that

sage: airy_ai_simple= FunctionAiryAiSimple()

would work when you run tests, assuming you didn't import FunctionAiryAiSimple into the global namespace.

Anyway, overall on a quick glance this looks great; unfortunately, I won't have time to review it properly soon - hopefully someone else will, because you put a lot of great work into it and we should totally have these symbolic. Thanks!

@sagetrac-olazo
Copy link
Mannequin Author

sagetrac-olazo mannequin commented Feb 19, 2012

comment:12

Do these pass doctests? I'm surprised that

sage: airy_ai_simple= FunctionAiryAiSimple()

would work when you run tests, assuming you didn't import FunctionAiryAiSimple into the global namespace.

It looks like they do:

oscar@oscar-netbook:~$ sage -coverage airy.py
sage -t  "/home/oscar/sage/my_patches/airy.py"              
	 [51.5 s]
 
----------------------------------------------------------------------
All tests passed!
Total time for all tests: 51.7 seconds

Why shouldn't they? I'll take care of the __init__ functions.

@sagetrac-olazo
Copy link
Mannequin Author

sagetrac-olazo mannequin commented Feb 19, 2012

comment:13

I'm sorry, that should be:

oscar@oscar-netbook:~$ sage -t airy.py
sage -t  "/home/oscar/sage/my_patches/airy.py"              
	 [51.5 s]
 
----------------------------------------------------------------------
All tests passed!
Total time for all tests: 51.7 seconds

(the command was sage -t)

@kcrisman
Copy link
Member

comment:14
sage: airy_ai_simple= FunctionAiryAiSimple()

would work when you run tests, assuming you didn't import FunctionAiryAiSimple into the global namespace.

I'm just surprised this doesn't cause trouble.

On another note, this apparently does something weird when applied to 5.0.beta4. Namely, Sage won't start:

---> 65 from sage.functions.all import sin, cos

ImportError: cannot import name sin
Error importing ipy_profile_sage - perhaps you should run %upgrade?
WARNING: Loading of ipy_profile_sage failed.

I'll spare you the rest of the traceback. I think there is some kind of circular import thing going on here, but I don't understand imports that well. Perhaps moving the import of airy to further down (after trig functions) would help - that's a totally uninformed guess, of course.

@sagetrac-olazo
Copy link
Mannequin Author

sagetrac-olazo mannequin commented Feb 21, 2012

comment:15

Attachment: trac_12455-symbolic_airy3.patch.gz

I just added a new patch, now with 100 % test coverage, but I still get this message:

oscar@oscar-netbook:~$ sage -coverage /home/oscar/sage/my_patches/airy.py ----------------------------------------------------------------------
/home/oscar/sage/my_patches/airy.py
ERROR: Please add a `TestSuite(s).run()` doctest.
SCORE /home/oscar/sage/my_patches/airy.py: 100% (26 of 26)
----------------------------------------------------------------------

What is this TestSuite thing? I also changed the order in which functions are initialized, so that airy_ai_general is initialized first. Doing it last made some symbolic operations, such as simplify not work (It said something about airy_ai requiring 2 arguments).

@sagetrac-olazo
Copy link
Mannequin Author

sagetrac-olazo mannequin commented Feb 21, 2012

Author: Oscar Gerardo Lazo Arjona

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Mar 11, 2015

Changed commit from aac86a2 to 070e728

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Mar 11, 2015

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

3cac775Merge branch 'develop' into t/12455/public/ticket/12455
070e72812455: doc typos

@rwst rwst assigned rwst and unassigned sagetrac-olazo Mar 11, 2015
@rwst rwst modified the milestones: sage-6.4, sage-6.6 Mar 11, 2015
@mezzarobba
Copy link
Member

comment:78

x should be z in the differential equation

@mezzarobba
Copy link
Member

comment:79

What exactly still needs review here?

The code looks pretty good to me overall, but there are lots of things I don't understand in detail. (For a simple example, what is the motivation for splitting the implementation in so many unrelated classes?) And yet I'm tempted to give this ticket positive review (leaving possible remaining issues for later), since many other people have looked at it and it is clearly an improvement over what sage currently has.

@mezzarobba
Copy link
Member

comment:80

More nitpicking, not necessarily for this ticket:

  • Raising a ValueError in FunctionAiryAiGeneral._derivative_ when diff_param == 0 may not be the most appropriate, since (if I'm not mistaken) the partial derivative would make sense mathematically.
  • Is it necessary to special-case alpha == 0 etc. in FunctionAiryAiGeneral._evalf_?

@mezzarobba
Copy link
Member

comment:81

Replying to @mezzarobba:

  • Is it necessary to special-case alpha == 0 etc. in FunctionAiryAiGeneral._evalf_?

Scratch that, I misread the code.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Mar 12, 2015

Changed commit from 070e728 to 91530d0

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Mar 12, 2015

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

91530d0Ai/Bi: doc fixes and clarifications

@mezzarobba
Copy link
Member

comment:83

One last thing: IMO hold_derivative should be True by default in airy_ai and airy_bi, except perhaps when the differentiation order is one. But I don't know if that's consistent with the way things are done in other parts of sage symbolics. Thoughts?

@rwst
Copy link
Contributor

rwst commented Mar 12, 2015

comment:84

Replying to @mezzarobba:

x should be z in the differential equation

Strange typo.

  • Raising a ValueError in FunctionAiryAiGeneral._derivative_ when diff_param == 0 may not be the most appropriate, since (if I'm not mistaken) the partial derivative would make sense mathematically.

A quick look at old and new code shows 1. ValueError, 2. NotImplementedError, 3. assert. So, this needs to be unified to NotImplementedError.

One last thing: IMO hold_derivative should be True by default in airy_ai and airy_bi, except perhaps when the differentiation order is one. But I don't know if that's consistent with the way things are done in other parts of sage symbolics. Thoughts?

I believe the code of this ticket is the only one that has such a parameter, so please feel free to improve it.

I have looked at your patch and it's fine, so if you think the rest is OK please set positive.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Mar 12, 2015

Changed commit from 91530d0 to 2f6945a

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Mar 12, 2015

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

347cd08#12455 Airy functions: doc fixes and clarifications
6aaf2da#12455 Airy funs: raise NotImplementedError on diff(airy_?i(α,x),α)
c80be63#12455 Airy funs: hold_derivative by default
2f6945a#12455 Airy functions: avoid calling deprecated function

@mezzarobba
Copy link
Member

comment:86

Replying to @rwst:

  • Raising a ValueError in FunctionAiryAiGeneral._derivative_ when diff_param == 0 may not be the most appropriate, since (if I'm not mistaken) the partial derivative would make sense mathematically.

A quick look at old and new code shows 1. ValueError, 2. NotImplementedError, 3. assert. So, this needs to be unified to NotImplementedError.

One last thing: IMO hold_derivative should be True by default in airy_ai and airy_bi, except perhaps when the differentiation order is one. But I don't know if that's consistent with the way things are done in other parts of sage symbolics. Thoughts?

I believe the code of this ticket is the only one that has such a parameter, so please feel free to improve it.

Both done (now rather than later to avoid breaking the interface).

I have looked at your patch and it's fine, so if you think the rest is OK please set positive.

I'm okay with everything prior to my commits. Could you (or someone else) have a quick look at my last changes and set the ticket to positive review? Thanks!

@mezzarobba
Copy link
Member

Changed reviewer from Eviatar Bach, Karl-Dieter Crisman, Burcin Erocal, Ralf Stephan to Eviatar Bach, Karl-Dieter Crisman, Burcin Erocal, Ralf Stephan, Jeroen Demeyer, Marc Mezzarobba

@mezzarobba

This comment has been minimized.

@rwst
Copy link
Contributor

rwst commented Mar 12, 2015

comment:87

Is fine and passes tests in functions/. Thank you too.

@vbraun
Copy link
Member

vbraun commented Mar 12, 2015

Changed branch from public/ticket/12455 to 2f6945a

@kcrisman
Copy link
Member

Changed author from Oscar Gerardo Lazo Arjona, Benjamin Jones, D. S. McNeil, Eviatar Bach, Ralf Stephan to Oscar Gerardo Lazo Arjona, Benjamin Jones, Douglas McNeil, Eviatar Bach, Ralf Stephan

@kcrisman
Copy link
Member

Changed commit from 2f6945a to none

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

10 participants