Opened 22 months ago
Closed 13 months ago
#14996 closed enhancement (fixed)
Improve support for Jacobi elliptic functions
Reported by: | eviatarbach | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | sage-6.3 |
Component: | symbolics | Keywords: | |
Cc: | burcin, kcrisman, benjaminfjones, fredrik.johansson | Merged in: | |
Authors: | Eviatar Bach | Reviewers: | Ralf Stephan, Travis Scrimshaw |
Report Upstream: | N/A | Work issues: | |
Branch: | 6df0d14 (Commits) | Commit: | 6df0d14c474715ac2565c2a9abea51022fc945dd |
Dependencies: | Stopgaps: |
Description
Currently, all evaluation (numeric and symbolic) of the Jacobi elliptic functions is done through Maxima. No derivatives or arbitrary-precision numeric evaluation are defined. Worse still, the Maxima numerical evaluation is wrong for some of the inverse Jacobi functions; see https://sourceforge.net/p/maxima/bugs/2615/.
Attachments (4)
Change History (25)
Changed 22 months ago by eviatarbach
comment:1 Changed 22 months ago by eviatarbach
- Status changed from new to needs_review
comment:2 Changed 22 months ago by eviatarbach
- Cc burcin added
comment:3 Changed 22 months ago by kcrisman
- Cc kcrisman benjaminfjones added
comment:4 Changed 22 months ago by eviatarbach
- Cc fredrik.johansson added
I hope you don't mind me CC'ing you.
In this patch I add the functions inverse_jacobi_f and jacobi_amplitude_f which use mpmath. Do you think these could be added to a future version? I know I'm not smart about increasing the context precision for successive computations but it seems to work.
comment:5 Changed 22 months ago by fredrik.johansson
Sure, they could be added to a future version. I never even tried to implement them because it seemed like too much work to figure out all the case distinctions and writing test code for branch cuts. You seem to restrict the code to real arguments, which makes things easier and probably makes a good enough start.
comment:6 Changed 22 months ago by eviatarbach
Ah, good. Should I submit a pull request on GitHub? or something?
The reason I used real numbers for the inverse Jacobi is because it was a pain to get continuity otherwise. For the amplitude function, it's defined in the DLMF for real numbers (http://dlmf.nist.gov/22.16).
comment:7 Changed 22 months ago by fredrik.johansson
Sure, you're very welcome to supply a patch if you have time.
Better put this code in Sage now though, and then perhaps replace it with calls to mpmath in the future (can't guarantee when the next release of mpmath will happen, regrettably).
comment:8 Changed 22 months ago by eviatarbach
Thanks, I will do so when I have time.
New patch fixes two bugs.
Changed 22 months ago by eviatarbach
comment:9 Changed 21 months ago by eviatarbach
New patch rebases to Sage 5.11, gets coverage to 100%, adds tons of new tests, and makes all Python ints in simplifications and derivatives Sage integers.
Please don't be worried about the length of the patch, much of it derives from identities and tests. Since there are 12 Jacobi elliptic functions and all their inverses, this adds up to a lot.
Patchbot apply trac14996_3.patch
Changed 21 months ago by eviatarbach
comment:10 Changed 21 months ago by mjd
I did some tests, and the doctest for plot/line.py failed (it tries to plot a Jacobi elliptic function at line 413 and this goes awry in trying to convert a complex number which is very close into a real number to a real number).
A small issue is that perhaps jacobi should complain if one passes to it as the first argument a string which is not of the form 'pq' with p, q one of s, c, n, d. Moreover, if the argument is 'pp' then it could perhaps use the convention used in the documentation and return 1?
I'm new to sage, apologies for the inanity of my comments.
comment:11 Changed 21 months ago by eviatarbach
No, they're not inane at all! Thanks for the comments, they bring up important issues to fix.
You're right about the doctest and the need to raise an error; the Jacobi class raises an error but I forgot to add it for the jacobi function. Fix coming up shortly.
As for the pp=1 convention, it could be done but I don't see how it would be useful. In all sources I've seen they're called the "12 Jacobi functions". Also, it might give users the impression that Sage is actually calculating the ratios of the functions and simplifying. To remain consistent with the other functions we would also have to add the aliases jacobi_nn, jacobi_ss, etc., which amounts to just adding four constants that equal 1 to the global namespace.
comment:12 Changed 21 months ago by eviatarbach
New patch fixes doctests, adds errors when an invalid Jacobi function name is given, and updates LaTeX conversions to follow the convention of using | as the parameter delimiter.
Patchbot apply trac14996_4.patch
Changed 21 months ago by eviatarbach
comment:13 Changed 16 months ago by vbraun_spam
- Milestone changed from sage-6.1 to sage-6.2
comment:14 Changed 15 months ago by rws
- Branch set to u/rws/ticket/14996
- Created changed from 08/02/13 21:09:33 to 08/02/13 21:09:33
- Modified changed from 01/30/14 13:20:52 to 01/30/14 13:20:52
comment:15 Changed 15 months ago by rws
- Commit set to a6ab7a4bde8b2ebe8e6b51a4fec7ff8828e033e3
- Reviewers set to Ralf Stephan
- Status changed from needs_review to positive_review
I think this is fine. It tests --long OK in functions/ and builds all docs. The docs look good too. The branch is on top of 6.2.beta2.
Author copied from patch header.
New commits:
a6ab7a4 | Trac #14996: Rewriting Jacobi elliptic function code, new numeric evaluation, Jacobi amplitude function |
comment:16 Changed 15 months ago by rws
comment:17 Changed 15 months ago by vbraun
Fails with
sage -t src/sage/functions/jacobi.py ********************************************************************** File "src/sage/functions/jacobi.py", line 210, in sage.functions.jacobi.Jacobi._eval_ Failed example: almosteq(n(jacobi_nd(8, 0, hold=True)), n(jacobi_nd(8, 0))) Exception raised: Traceback (most recent call last): File "/home/release/Sage/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 480, in _run self.execute(example, compiled, test.globs) File "/home/release/Sage/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 839, in execute exec compiled in globs File "<doctest sage.functions.jacobi.Jacobi._eval_[1]>", line 1, in <module> almosteq(n(jacobi_nd(Integer(8), Integer(0), hold=True)), n(jacobi_nd(Integer(8), Integer(0)))) File "/home/release/Sage/local/lib/python2.7/site-packages/sage/misc/functional.py", line 1413, in numerical_approx return x._numerical_approx(prec, algorithm=algorithm) File "expression.pyx", line 4704, in sage.symbolic.expression.Expression._numerical_approx (sage/symbolic/expression.cpp:23432) File "expression.pyx", line 1036, in sage.symbolic.expression.Expression._convert (sage/symbolic/expression.cpp:7216) TypeError: _evalf_() got an unexpected keyword argument 'algorithm'
Possibly due to the pynac update which I merged first #15198
comment:18 Changed 15 months ago by kcrisman
Presumably due to the simultaneously-merged and related #14778, but same difference - I am sure Eviatar can update for this very easily.
comment:19 Changed 14 months ago by tscrim
- Branch changed from u/rws/ticket/14996 to u/tscrim/14996
- Commit changed from a6ab7a4bde8b2ebe8e6b51a4fec7ff8828e033e3 to 6df0d14c474715ac2565c2a9abea51022fc945dd
- Reviewers changed from Ralf Stephan to Ralf Stephan, Travis Scrimshaw
I've fixed the failing doctests and doc did not build, so I fixed that as well. I also did some formatting cleanup of the doc (while I was reading it over trying to find the docbuild issues).
New commits:
db1980b | Merge branch 'u/rws/ticket/14996' of trac.sagemath.org:sage into u/tscrim/14996 |
6df0d14 | Fixed doctests and documentation. Additional doc cleanup. |
comment:20 Changed 13 months ago by vbraun_spam
- Milestone changed from sage-6.2 to sage-6.3
comment:21 Changed 13 months ago by vbraun
- Branch changed from u/tscrim/14996 to 6df0d14c474715ac2565c2a9abea51022fc945dd
- Resolution set to fixed
- Status changed from positive_review to closed
The patch rewrites the Jacobi functions as standard symbolic functions. I wrote a new numerical routine for the inverse Jacobi functions, since it didn't seem to be available elsewhere. I've also added the Jacobi amplitude function.