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

Improve support for Jacobi elliptic functions #14996

Closed
eviatarbach opened this issue Aug 3, 2013 · 24 comments
Closed

Improve support for Jacobi elliptic functions #14996

eviatarbach opened this issue Aug 3, 2013 · 24 comments

Comments

@eviatarbach
Copy link

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/.

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

Component: symbolics

Author: Eviatar Bach

Branch/Commit: 6df0d14

Reviewer: Ralf Stephan, Travis Scrimshaw

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

@eviatarbach eviatarbach added this to the sage-6.1 milestone Aug 3, 2013
@eviatarbach
Copy link
Author

comment:1

Attachment: trac14996.patch.gz

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.

@eviatarbach
Copy link
Author

comment:4

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.

@fredrik-johansson
Copy link

comment:5

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.

@eviatarbach
Copy link
Author

comment:6

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).

@fredrik-johansson
Copy link

comment:7

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).

@eviatarbach
Copy link
Author

comment:8

Thanks, I will do so when I have time.

New patch fixes two bugs.

@eviatarbach
Copy link
Author

Attachment: trac14996_2.patch.gz

@eviatarbach
Copy link
Author

comment:9

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

@sagetrac-mjd
Copy link
Mannequin

sagetrac-mjd mannequin commented Sep 3, 2013

comment:10

Attachment: trac14996_3.patch.gz

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.

@eviatarbach
Copy link
Author

comment:11

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.

@eviatarbach
Copy link
Author

comment:12

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

@eviatarbach
Copy link
Author

Attachment: trac14996_4.patch.gz

@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.1, sage-6.2 Jan 30, 2014
@rwst
Copy link

rwst commented Feb 22, 2014

Branch: u/rws/ticket/14996

@rwst
Copy link

rwst commented Feb 22, 2014

Commit: a6ab7a4

@rwst
Copy link

rwst commented Feb 22, 2014

comment:15

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:

a6ab7a4Trac #14996: Rewriting Jacobi elliptic function code, new numeric evaluation, Jacobi amplitude function

@rwst
Copy link

rwst commented Feb 22, 2014

Reviewer: Ralf Stephan

@rwst
Copy link

rwst commented Feb 22, 2014

Author: Eviatar Bach

@vbraun
Copy link
Member

vbraun commented Mar 4, 2014

comment:17

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

@kcrisman
Copy link
Member

kcrisman commented Mar 4, 2014

comment:18

Presumably due to the simultaneously-merged and related #14778, but same difference - I am sure Eviatar can update for this very easily.

@tscrim
Copy link
Collaborator

tscrim commented Apr 10, 2014

comment:19

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:

db1980bMerge branch 'u/rws/ticket/14996' of trac.sagemath.org:sage into u/tscrim/14996
6df0d14Fixed doctests and documentation. Additional doc cleanup.

@tscrim
Copy link
Collaborator

tscrim commented Apr 10, 2014

Changed commit from a6ab7a4 to 6df0d14

@tscrim
Copy link
Collaborator

tscrim commented Apr 10, 2014

Changed reviewer from Ralf Stephan to Ralf Stephan, Travis Scrimshaw

@tscrim
Copy link
Collaborator

tscrim commented Apr 10, 2014

Changed branch from u/rws/ticket/14996 to u/tscrim/14996

@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@vbraun
Copy link
Member

vbraun commented May 6, 2014

Changed branch from u/tscrim/14996 to 6df0d14

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

6 participants