Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit 6df0d14

Browse files
author
Travis Scrimshaw
committed
Fixed doctests and documentation. Additional doc cleanup.
1 parent db1980b commit 6df0d14

File tree

1 file changed

+75
-76
lines changed

1 file changed

+75
-76
lines changed

src/sage/functions/jacobi.py

Lines changed: 75 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
r"""
2-
Jacobi elliptic functions
2+
Jacobi Elliptic Functions
33
44
This module implements the 12 Jacobi elliptic functions, along with their
55
inverses and the Jacobi amplitude function.
@@ -21,7 +21,7 @@
2121
``c``, ``d``, and ``n``. The rectangle is understood to be lying on the complex
2222
plane, so that ``s`` is at the origin, ``c`` is on the real axis, and ``n`` is
2323
on the imaginary axis. The twelve Jacobian elliptic functions are
24-
then $\operatorname{pq}(x)$, where ``p`` and ``q`` are one of the letters
24+
then `\operatorname{pq}(x)`, where ``p`` and ``q`` are one of the letters
2525
``s``, ``c``, ``d``, ``n``.
2626
2727
The Jacobian elliptic functions are then the unique
@@ -36,45 +36,45 @@
3636
from ``p`` to ``q``. `\operatorname{pq}(x)` is periodic in the other two
3737
directions as well, with a period such that the distance from ``p`` to one
3838
of the other corners is a quarter period.
39-
#. If the function $\operatorname{pq}(x)$ is expanded in terms of $x$ at one of
39+
#. If the function `\operatorname{pq}(x)` is expanded in terms of `x` at one of
4040
the corners, the leading term in the expansion has a coefficient of 1.
4141
In other words, the leading term of the expansion of `\operatorname{pq}(x)`
42-
at the corner ``p`` is $x$; the leading term of the expansion at the corner
43-
``q`` is $1/x$, and the leading term of an expansion at the other two
42+
at the corner ``p`` is `x`; the leading term of the expansion at the corner
43+
``q`` is `1/x`, and the leading term of an expansion at the other two
4444
corners is 1.
4545
4646
We can write
4747
48-
.. math::
48+
.. MATH::
4949
50-
\operatorname{pq}(x)=\frac{\operatorname{pr}(x)}{\operatorname{qr}(x)}
50+
\operatorname{pq}(x) = \frac{\operatorname{pr}(x)}{\operatorname{qr}(x)}
5151
5252
where ``p``, ``q``, and ``r`` are any of the
5353
letters ``s``, ``c``, ``d``, ``n``, with
54-
the understanding that `\mathrm{ss}=\mathrm{cc}=\mathrm{dd}=\mathrm{nn}=1`.
54+
the understanding that `\mathrm{ss} = \mathrm{cc} = \mathrm{dd}
55+
= \mathrm{nn} = 1`.
5556
5657
Let
5758
58-
.. math::
59+
.. MATH::
5960
60-
u=\int_0^\phi \frac{d\theta} {\sqrt {1-m \sin^2 \theta}}
61+
u = \int_0^{\phi} \frac{d\theta} {\sqrt {1-m \sin^2 \theta}},
6162
63+
then the *Jacobi elliptic function* `\operatorname{sn}(u)` is given by
6264
63-
Then the *Jacobi elliptic function* `\operatorname{sn}(u)` is given by
64-
65-
.. math::
65+
.. MATH::
6666
6767
\operatorname{sn}{u} = \sin{\phi}
6868
6969
and `\operatorname{cn}(u)` is given by
7070
71-
.. math::
71+
.. MATH::
7272
7373
\operatorname{cn}{u} = \cos{\phi}
7474
7575
and
7676
77-
.. math::
77+
.. MATH::
7878
7979
\operatorname{dn}{u} = \sqrt{1 - m\sin^2 \phi}.
8080
@@ -86,40 +86,35 @@
8686
solutions to the following nonlinear ordinary differential
8787
equations:
8888
89-
- `\operatorname{sn}\,(x;k)` solves the differential equations
90-
91-
.. math::
92-
93-
\frac{d^2 y}{dx^2} + (1+k^2) y - 2 k^2 y^3 = 0,
94-
95-
and
96-
97-
.. math::
98-
99-
\left(\frac{dy}{dx}\right)^2 = (1-y^2) (1-k^2 y^2).
89+
- `\operatorname{sn}\,(x;k)` solves the differential equations
10090
101-
- `\operatorname{cn}(x;k)` solves the differential equations
91+
.. MATH::
10292
93+
\frac{d^2 y}{dx^2} + (1+k^2) y - 2 k^2 y^3 = 0
94+
\quad \text{ and } \quad
95+
\left(\frac{dy}{dx}\right)^2 = (1-y^2) (1-k^2 y^2).
10396
104-
.. math::
97+
- `\operatorname{cn}(x;k)` solves the differential equations
10598
106-
\frac{d^2 y}{dx^2} + (1-2k^2) y + 2 k^2 y^3 = 0,
99+
.. MATH::
107100
108-
and `\left(\frac{dy}{dx}\right)^2 = (1-y^2)(1-k^2 + k^2 y^2)`.
101+
\frac{d^2 y}{dx^2} + (1-2k^2) y + 2 k^2 y^3 = 0
102+
\quad \text{ and } \quad
103+
\left(\frac{dy}{dx}\right)^2 = (1-y^2)(1-k^2 + k^2 y^2).
109104
110-
- `\operatorname{dn}(x;k)` solves the differential equations
105+
- `\operatorname{dn}(x;k)` solves the differential equations
111106
112-
.. math::
107+
.. MATH::
113108
114-
\frac{d^2 y}{dx^2} - (2 - k^2) y + 2 y^3 = 0,
115-
116-
and `\left(\frac{dy}{dx}\right)^2= y^2 (1 - k^2 - y^2)`.
109+
\frac{d^2 y}{dx^2} - (2 - k^2) y + 2 y^3 = 0
110+
\quad \text{ and } \quad
111+
\left(\frac{dy}{dx}\right)^2 = y^2 (1 - k^2 - y^2).
117112
118113
If `K(m)` denotes the complete elliptic integral of the
119114
first kind (named ``elliptic_kc`` in Sage), the elliptic functions
120115
`\operatorname{sn}(x|m)` and `\operatorname{cn}(x|m)` have real periods
121116
`4K(m)`, whereas `\operatorname{dn}(x|m)` has a period
122-
`2K(m)`. The limit `m\rightarrow 0` gives
117+
`2K(m)`. The limit `m \rightarrow 0` gives
123118
`K(0) = \pi/2` and trigonometric functions:
124119
`\operatorname{sn}(x|0) = \sin{x}`, `\operatorname{cn}(x|0) = \cos{x}`,
125120
`\operatorname{dn}(x|0) = 1`. The limit `m \rightarrow 1` gives
@@ -130,17 +125,17 @@
130125
131126
REFERENCES:
132127
133-
- http://en.wikipedia.org/wiki/Jacobi's_elliptic_functions
128+
- :wikipedia:`Jacobi's_elliptic_functions`
134129
135-
- A. Khare, U. Sukhatme, "Cyclic Identities Involving
136-
Jacobi Elliptic Functions", Math ArXiv, math-ph/0201004
130+
.. [KhaSuk04] A. Khare and U. Sukhatme. "Cyclic Identities Involving
131+
Jacobi Elliptic Functions". :arxiv:`math-ph/0201004`
137132
138133
AUTHORS:
139134
140135
- David Joyner (2006): initial version
141136
142-
- Eviatar Bach (2013): complete rewrite, new numerical evaluation, and addition
143-
of the Jacobi amplitude function
137+
- Eviatar Bach (2013): complete rewrite, new numerical evaluation, and
138+
addition of the Jacobi amplitude function
144139
"""
145140

146141
#*****************************************************************************
@@ -172,9 +167,12 @@
172167

173168

174169
class Jacobi(BuiltinFunction):
170+
"""
171+
Base class for the Jacobi elliptic functions.
172+
"""
175173
def __init__(self, kind):
176174
r"""
177-
Base class for the Jacobi elliptic functions
175+
Initialize ``self``.
178176
179177
EXAMPLES::
180178
@@ -354,24 +352,24 @@ def _eval_(self, x, m):
354352
return csch(x)
355353
return
356354

357-
def _evalf_(self, x, m, parent):
355+
def _evalf_(self, x, m, parent, algorithm=None):
358356
r"""
359357
TESTS::
360358
361359
sage: jacobi_sn(3, 4).n(100)
362360
-0.33260000892770027112809652714 + 1.7077912301715219199143891076e-33*I
363361
sage: jacobi_dn(I, I).n()
364362
0.874189950651018 + 0.667346865048825*I
365-
"""
363+
"""
366364
from mpmath import ellipfun
367365
return utils.call(ellipfun, self.kind, x, m, parent=parent)
368366

369367
def _derivative_(self, x, m, diff_param):
370368
r"""
371369
TESTS:
372370
373-
sn, cn, and dn are analytic for all real x, so we can check that the
374-
derivatives are correct by computing the series::
371+
sn, cn, and dn are analytic for all real ``x``, so we can check
372+
that the derivatives are correct by computing the series::
375373
376374
sage: from mpmath import almosteq
377375
sage: a = 0.9327542442482303
@@ -532,9 +530,12 @@ def _print_latex_(self, x, m):
532530

533531

534532
class InverseJacobi(BuiltinFunction):
533+
r"""
534+
Base class for the inverse Jacobi elliptic functions.
535+
"""
535536
def __init__(self, kind):
536537
r"""
537-
Base class for the inverse Jacobi elliptic functions
538+
Initialize ``self``.
538539
539540
EXAMPLES::
540541
@@ -718,7 +719,7 @@ def _eval_(self, x, m):
718719
return Integer(0)
719720
return
720721

721-
def _evalf_(self, x, m, parent):
722+
def _evalf_(self, x, m, parent, algorithm=None):
722723
r"""
723724
TESTS::
724725
@@ -727,15 +728,14 @@ def _evalf_(self, x, m, parent):
727728
sage: inverse_jacobi_cd(3, 4).n(100)
728729
-0.67214752201235862490069823239 + 2.1565156474996432354386749988*I
729730
"""
730-
return utils.call(inverse_jacobi_f, self.kind, x, m,
731-
parent=parent)
731+
return utils.call(inverse_jacobi_f, self.kind, x, m, parent=parent)
732732

733733
def _derivative_(self, x, m, diff_param):
734734
r"""
735735
TESTS:
736736
737-
Check that dy/dx * dx/dy == 1, where y = jacobi_pq(x, m) and
738-
x = inverse_jacobi_pq(y, m)::
737+
Check that ``dy/dx * dx/dy == 1``, where ``y = jacobi_pq(x, m)`` and
738+
``x = inverse_jacobi_pq(y, m)``::
739739
740740
sage: from mpmath import almosteq
741741
sage: a = 0.130103220857094
@@ -932,15 +932,15 @@ def _print_latex_(self, x, m):
932932

933933
def jacobi(kind, z, m, **kwargs):
934934
r"""
935-
The 12 Jacobi elliptic functions
935+
The 12 Jacobi elliptic functions.
936936
937937
INPUT:
938938
939939
- ``kind`` -- a string of the form ``'pq'``, where ``p``, ``q`` are in
940940
``c``, ``d``, ``n``, ``s``
941941
- ``z`` -- a complex number
942-
- ``m`` -- a complex number. Note that `m=k^2`, where `k` is the elliptic
943-
modulus.
942+
- ``m`` -- a complex number; note that `m = k^2`, where `k` is
943+
the elliptic modulus
944944
945945
EXAMPLES::
946946
@@ -985,11 +985,12 @@ def jacobi(kind, z, m, **kwargs):
985985
"'ds', 'dc', 'sn', 'sd', 'sc', 'cn', 'cd', 'cs'.")
986986

987987
def inverse_jacobi(kind, x, m, **kwargs):
988-
"""
988+
r"""
989989
The inverses of the 12 Jacobi elliptic functions. They have the property
990990
that
991991
992-
.. math::
992+
.. MATH::
993+
993994
\operatorname{pq}(\operatorname{arcpq}(x|m)|m) =
994995
\operatorname{pq}(\operatorname{pq}^{-1}(x|m)|m) = x.
995996
@@ -998,8 +999,8 @@ def inverse_jacobi(kind, x, m, **kwargs):
998999
- ``kind`` -- a string of the form ``'pq'``, where ``p``, ``q`` are in
9991000
``c``, ``d``, ``n``, ``s``
10001001
- ``x`` -- a real number
1001-
- ``m`` -- a real number. Note that `m=k^2`, where `k` is the elliptic
1002-
modulus.
1002+
- ``m`` -- a real number; note that `m = k^2`, where `k` is the elliptic
1003+
modulus
10031004
10041005
EXAMPLES::
10051006
@@ -1062,8 +1063,8 @@ def inverse_jacobi(kind, x, m, **kwargs):
10621063
class JacobiAmplitude(BuiltinFunction):
10631064
r"""
10641065
The Jacobi amplitude function
1065-
`\operatorname{am}(x|m)=\int_0^x \operatorname{dn}(t|m) dt`. For
1066-
`-K(m) \leq x \leq K(m)`, `F(\operatorname{am}(x|m)|m)=x.`
1066+
`\operatorname{am}(x|m) = \int_0^x \operatorname{dn}(t|m) dt` for
1067+
`-K(m) \leq x \leq K(m)`, `F(\operatorname{am}(x|m)|m) = x`.
10671068
"""
10681069
def __init__(self):
10691070
r"""
@@ -1100,7 +1101,7 @@ def _eval_(self, x, m):
11001101
return Integer(0)
11011102
return
11021103

1103-
def _evalf_(self, x, m, parent):
1104+
def _evalf_(self, x, m, parent, algorithm=None):
11041105
r"""
11051106
TESTS::
11061107
@@ -1149,17 +1150,16 @@ def _print_latex_(self, x, m):
11491150

11501151

11511152
def inverse_jacobi_f(kind, x, m):
1152-
"""
1153+
r"""
11531154
Internal function for numerical evaluation of a continous complex branch
1154-
of each inverse Jacobi function, as described in [Tee]_. Only accepts real
1155-
arguments.
1155+
of each inverse Jacobi function, as described in [Tee97]_. Only accepts
1156+
real arguments.
11561157
11571158
REFERENCES:
11581159
1159-
.. [Tee] Tee, Garry J. "Continuous branches of inverses of the 12 Jacobi
1160-
elliptic functions for real argument". 1997.
1161-
https://researchspace.auckland.ac.nz/bitstream/handle/2292/5042/\
1162-
390.pdf.
1160+
.. [Tee97] Tee, Garry J. "Continuous branches of inverses of the 12 Jacobi
1161+
elliptic functions for real argument". 1997.
1162+
https://researchspace.auckland.ac.nz/bitstream/handle/2292/5042/390.pdf.
11631163
11641164
TESTS::
11651165
@@ -1287,7 +1287,6 @@ def inverse_jacobi_f(kind, x, m):
12871287
12881288
sage: chop(ellipfun('ds', inverse_jacobi_f('ds', 4, 0.25), 0.25))
12891289
mpf('4.0')
1290-
12911290
"""
12921291
from mpmath import mp
12931292

@@ -1626,16 +1625,15 @@ def inverse_jacobi_f(kind, x, m):
16261625

16271626

16281627
def jacobi_am_f(x, m):
1629-
"""
1628+
r"""
16301629
Internal function for numeric evaluation of the Jacobi amplitude function
1631-
for real arguments. Procedure described in [Ehrhardt]_.
1630+
for real arguments. Procedure described in [Ehrhardt13]_.
16321631
16331632
REFERENCES:
16341633
1635-
.. [Ehrhardt] Ehrhardt, Wolfgang. "The AMath and DAMath Special Functions:
1636-
Reference Manual and Implementation Notes, Version 1.3".
1637-
2013. http://www.wolfgang-ehrhardt.de/specialfunctions.pdf.
1638-
1634+
.. [Ehrhardt13] Ehrhardt, Wolfgang. "The AMath and DAMath Special
1635+
Functions: Reference Manual and Implementation Notes, Version 1.3".
1636+
2013. http://www.wolfgang-ehrhardt.de/specialfunctions.pdf.
16391637
16401638
TESTS::
16411639
@@ -1707,3 +1705,4 @@ def jacobi_am_f(x, m):
17071705
return ctx.atan2(snz, cnz) + npi
17081706
finally:
17091707
ctx.prec = prec
1708+

0 commit comments

Comments
 (0)