Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Jacobi Elliptic SN, CN and DN

Synopsis
#include <boost/math/special_functions/jacobi_elliptic.hpp>
namespace boost { namespace math {

 template <class T, class U, class V>
 calculated-result-type jacobi_elliptic(T k, U u, V* pcn, V* pdn);

 template <class T, class U, class V, class Policy>
 calculated-result-type jacobi_elliptic(T k, U u, V* pcn, V* pdn, const Policy&);

}} // namespaces
Description

The function jacobi_elliptic calculates the three copolar Jacobi elliptic functions sn(u, k), cn(u, k) and dn(u, k). The returned value is sn(u, k), and if provided, *pcn is set to cn(u, k), and *pdn is set to dn(u, k).

The functions are defined as follows, given:

The the angle φ is called the amplitude and:

[Note] Note

φ is called the amplitude.

k is called the modulus.

[Caution] Caution

Rather like other elliptic functions, the Jacobi functions are expressed in a variety of different ways. In particular, the parameter k (the modulus) may also be expressed using a modular angle α, or a parameter m. These are related by:

k = sinα

m = k2 = sin2α

So that the function sn (for example) may be expressed as either:

sn(u, k)

sn(u \ α)

sn(u| m)

To further complicate matters, some texts refer to the complement of the parameter m, or 1 - m, where:

1 - m = 1 - k2 = cos2α

This implementation uses k throughout, and makes this the first argument to the functions: this is for alignment with the elliptic integrals which match the requirements of the Technical Report on C++ Library Extensions. However, you should be extra careful when using these functions!

The final Policy argument is optional and can be used to control the behaviour of the function: how it handles errors, what level of precision to use etc. Refer to the policy documentation for more details.

The following graphs illustrate how these functions change as k changes: for small k these are sine waves, while as k tends to 1 they become hyperbolic functions:

Accuracy

These functions are computed using only basic arithmetic operations and trigomometric functions, so there isn't much variation in accuracy over differing platforms. Typically errors are trivially small for small angles, and as is typical for cyclic functions, grow as the angle increases. Note that only results for the widest floating point type on the system are given as narrower types have effectively zero error. All values are relative errors in units of epsilon.

Table 6.70. Error rates for jacobi_cn

Microsoft Visual C++ version 12.0
Win32
double

GNU C++ version 5.1.0
linux
double

GNU C++ version 5.1.0
linux
long double

Sun compiler version 0x5130
Sun Solaris
long double

Jacobi Elliptic: Mathworld Data

Max = 45.8ε (Mean = 11.4ε)

Max = 0ε (Mean = 0ε)

(GSL 1.16: Max = 17.3ε (Mean = 4.29ε) And other failures.)
(Cephes: Max = +INFε (Mean = +INFε) And other failures.)

Max = 71.6ε (Mean = 19.3ε)

Max = 71.6ε (Mean = 19.4ε)

Jacobi Elliptic: Random Data

Max = 1.83ε (Mean = 0.455ε)

Max = 0.816ε (Mean = 0.0563ε)

(GSL 1.16: Max = 2.43ε (Mean = 0.803ε))
(Cephes: Max = 1.83ε (Mean = 0.437ε))

Max = 1.68ε (Mean = 0.443ε)

Max = 1.68ε (Mean = 0.454ε)

Jacobi Elliptic: Random Small Values

Max = 26.2ε (Mean = 1.17ε)

Max = 0ε (Mean = 0ε)

(GSL 1.16: Max = 55.2ε (Mean = 1.64ε) And other failures.)
(Cephes: Max = +INFε (Mean = +INFε) And other failures.)

Max = 10.4ε (Mean = 0.594ε)

Max = 10.4ε (Mean = 0.602ε)

Jacobi Elliptic: Modulus near 1

Max = 513ε (Mean = 126ε)

Max = 0.919ε (Mean = 0.127ε)

(GSL 1.16: Max = 0ε (Mean = 0ε) And other failures.)
(Cephes: Max = +INFε (Mean = +INFε) And other failures.)

Max = 675ε (Mean = 87.1ε)

Max = 675ε (Mean = 86.8ε)

Jacobi Elliptic: Large Phi

Max = 3.27e+004ε (Mean = 1.93e+003ε)

Max = 14.2ε (Mean = 0.927ε)

(GSL 1.16: Max = 5.92e+03ε (Mean = 477ε))
(Cephes: Max = 3.27e+04ε (Mean = 1.93e+03ε))

Max = 2.97e+04ε (Mean = 1.9e+03ε)

Max = 2.97e+04ε (Mean = 1.9e+03ε)


Table 6.71. Error rates for jacobi_dn

Microsoft Visual C++ version 12.0
Win32
double

GNU C++ version 5.1.0
linux
double

GNU C++ version 5.1.0
linux
long double

Sun compiler version 0x5130
Sun Solaris
long double

Jacobi Elliptic: Mathworld Data

Max = 34.3ε (Mean = 8.71ε)

Max = 0ε (Mean = 0ε)

(GSL 1.16: Max = 2.82ε (Mean = 1.18ε) And other failures.)
(Cephes: Max = +INFε (Mean = +INFε) And other failures.)

Max = 49ε (Mean = 14ε)

Max = 49ε (Mean = 14ε)

Jacobi Elliptic: Random Data

Max = 1.52ε (Mean = 0.466ε)

Max = 0ε (Mean = 0ε)

(GSL 1.16: Max = 3ε (Mean = 0.61ε))
(Cephes: Max = 1.49ε (Mean = 0.321ε))

Max = 1.53ε (Mean = 0.473ε)

Max = 1.53ε (Mean = 0.481ε)

Jacobi Elliptic: Random Small Values

Max = 16.1ε (Mean = 0.685ε)

Max = 0.5ε (Mean = 0.0122ε)

(GSL 1.16: Max = 1.5ε (Mean = 0.391ε) And other failures.)
(Cephes: Max = +INFε (Mean = +INFε) And other failures.)

Max = 22.4ε (Mean = 0.777ε)

Max = 22.4ε (Mean = 0.763ε)

Jacobi Elliptic: Modulus near 1

Max = 6.24e+003ε (Mean = 482ε)

Max = 2.28ε (Mean = 0.194ε)

(GSL 1.16: Max = 0ε (Mean = 0ε) And other failures.)
(Cephes: Max = +INFε (Mean = +INFε) And other failures.)

Max = 3.75e+03ε (Mean = 293ε)

Max = 3.75e+03ε (Mean = 293ε)

Jacobi Elliptic: Large Phi

Max = 1.67e+004ε (Mean = 1e+003ε)

Max = 14.1ε (Mean = 0.897ε)

(GSL 1.16: Max = 121ε (Mean = 22ε))
(Cephes: Max = 196ε (Mean = 30.2ε))

Max = 2.82e+04ε (Mean = 1.79e+03ε)

Max = 2.82e+04ε (Mean = 1.79e+03ε)


Table 6.72. Error rates for jacobi_sn

Microsoft Visual C++ version 12.0
Win32
double

GNU C++ version 5.1.0
linux
double

GNU C++ version 5.1.0
linux
long double

Sun compiler version 0x5130
Sun Solaris
long double

Jacobi Elliptic: Mathworld Data

Max = 481ε (Mean = 113ε)

Max = 0ε (Mean = 0ε)

(GSL 1.16: Max = 588ε (Mean = 146ε) And other failures.)
(Cephes: Max = +INFε (Mean = +INFε) And other failures.)

Max = 341ε (Mean = 80.7ε)

Max = 341ε (Mean = 80.7ε)

Jacobi Elliptic: Random Data

Max = 1.92ε (Mean = 0.567ε)

Max = 0ε (Mean = 0ε)

(GSL 1.16: Max = 4.02ε (Mean = 1.07ε))
(Cephes: Max = 1.92ε (Mean = 0.567ε))

Max = 2.01ε (Mean = 0.584ε)

Max = 2.01ε (Mean = 0.593ε)

Jacobi Elliptic: Random Small Values

Max = 2.11ε (Mean = 0.385ε)

Max = 0ε (Mean = 0ε)

(GSL 1.16: Max = 11.7ε (Mean = 1.65ε) And other failures.)
(Cephes: Max = +INFε (Mean = +INFε) And other failures.)

Max = 1.99ε (Mean = 0.347ε)

Max = 1.99ε (Mean = 0.347ε)

Jacobi Elliptic: Modulus near 1

Max = 23.2ε (Mean = 1.85ε)

Max = 0ε (Mean = 0ε)

(GSL 1.16: Max = 0ε (Mean = 0ε) And other failures.)
(Cephes: Max = +INFε (Mean = +INFε) And other failures.)

Max = 109ε (Mean = 7.35ε)

Max = 109ε (Mean = 7.38ε)

Jacobi Elliptic: Large Phi

Max = 4.36e+004ε (Mean = 2.54e+003ε)

Max = 12ε (Mean = 0.771ε)

(GSL 1.16: Max = 4.54e+04ε (Mean = 2.63e+03ε))
(Cephes: Max = 4.36e+04ε (Mean = 2.54e+03ε))

Max = 2.45e+04ε (Mean = 1.51e+03ε)

Max = 2.45e+04ε (Mean = 1.51e+03ε)


Testing

The tests use a mixture of spot test values calculated using the online calculator at functions.wolfram.com, and random test data generated using MPFR at 1000-bit precision and this implementation.

Implementation

For k > 1 we apply the relations:

Then filter off the special cases:

sn(0, k) = 0 and cn(0, k) = dn(0, k) = 1.

sn(u, 0) = sin(u), cn(u, 0) = cos(u) and dn(u, 0) = 1.

sn(u, 1) = tanh(u), cn(u, 1) = dn(u, 1) = 1 / cosh(u).

And for k4 < ε we have:

Otherwise the values are calculated using the method of arithmetic geometric means.


PrevUpHomeNext