| Home | Libraries | People | FAQ | More

### 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
φ is called the amplitude. k is called the elliptic modulus.

| 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 trigonometric 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 8.70. Error rates for jacobi_cn

| GNU C++ version 7.1.0 linux double | GNU C++ version 7.1.0 linux long double | Sun compiler version 0x5150 Sun Solaris long double | Microsoft Visual C++ version 14.1 Win32 double
--- | --- | --- | --- | ---
Jacobi Elliptic: Mathworld Data | Max = 0ε (Mean = 0ε) (GSL 2.1: Max = 17.3ε (Mean = 4.29ε) And other failures.) | Max = 71.6ε (Mean = 19.3ε) | Max = 71.6ε (Mean = 19.4ε) | Max = 45.8ε (Mean = 11.4ε)
Jacobi Elliptic: Random Data | Max = 0.816ε (Mean = 0.0563ε) (GSL 2.1: Max = 2.43ε (Mean = 0.803ε)) | Max = 1.68ε (Mean = 0.443ε) | Max = 1.68ε (Mean = 0.454ε) | Max = 1.83ε (Mean = 0.455ε)
Jacobi Elliptic: Random Small Values | Max = 0ε (Mean = 0ε) (GSL 2.1: Max = 55.2ε (Mean = 1.64ε) And other failures.) | Max = 10.4ε (Mean = 0.594ε) | Max = 10.4ε (Mean = 0.602ε) | Max = 26.2ε (Mean = 1.17ε)
Jacobi Elliptic: Modulus near 1 | Max = 0.919ε (Mean = 0.127ε) (GSL 2.1: Max = 0ε (Mean = 0ε) And other failures.) | Max = 675ε (Mean = 87.1ε) | Max = 675ε (Mean = 86.8ε) | Max = 513ε (Mean = 126ε)
Jacobi Elliptic: Large Phi | Max = 14.2ε (Mean = 0.927ε) (GSL 2.1: Max = 5.92e+03ε (Mean = 477ε)) | Max = 2.97e+04ε (Mean = 1.9e+03ε) | Max = 2.97e+04ε (Mean = 1.9e+03ε) | Max = 3.27e+04ε (Mean = 1.93e+03ε)

Table 8.71. Error rates for jacobi_dn

| GNU C++ version 7.1.0 linux double | GNU C++ version 7.1.0 linux long double | Sun compiler version 0x5150 Sun Solaris long double | Microsoft Visual C++ version 14.1 Win32 double
--- | --- | --- | --- | ---
Jacobi Elliptic: Mathworld Data | Max = 0ε (Mean = 0ε) (GSL 2.1: Max = 2.82ε (Mean = 1.18ε) And other failures.) | Max = 49ε (Mean = 14ε) | Max = 49ε (Mean = 14ε) | Max = 34.3ε (Mean = 8.71ε)
Jacobi Elliptic: Random Data | Max = 0ε (Mean = 0ε) (GSL 2.1: Max = 3ε (Mean = 0.61ε)) | Max = 1.53ε (Mean = 0.473ε) | Max = 1.53ε (Mean = 0.481ε) | Max = 1.52ε (Mean = 0.466ε)
Jacobi Elliptic: Random Small Values | Max = 0.5ε (Mean = 0.0122ε) (GSL 2.1: Max = 1.5ε (Mean = 0.391ε) And other failures.) | Max = 22.4ε (Mean = 0.777ε) | Max = 22.4ε (Mean = 0.763ε) | Max = 16.1ε (Mean = 0.685ε)
Jacobi Elliptic: Modulus near 1 | Max = 2.28ε (Mean = 0.194ε) (GSL 2.1: Max = 0ε (Mean = 0ε) And other failures.) | Max = 3.75e+03ε (Mean = 293ε) | Max = 3.75e+03ε (Mean = 293ε) | Max = 6.24e+03ε (Mean = 482ε)
Jacobi Elliptic: Large Phi | Max = 14.1ε (Mean = 0.897ε) (GSL 2.1: Max = 121ε (Mean = 22ε)) | Max = 2.82e+04ε (Mean = 1.79e+03ε) | Max = 2.82e+04ε (Mean = 1.79e+03ε) | Max = 1.67e+04ε (Mean = 1e+03ε)

Table 8.72. Error rates for jacobi_sn

| GNU C++ version 7.1.0 linux double | GNU C++ version 7.1.0 linux long double | Sun compiler version 0x5150 Sun Solaris long double | Microsoft Visual C++ version 14.1 Win32 double
--- | --- | --- | --- | ---
Jacobi Elliptic: Mathworld Data | Max = 0ε (Mean = 0ε) (GSL 2.1: Max = 588ε (Mean = 146ε) And other failures.) | Max = 341ε (Mean = 80.7ε) | Max = 341ε (Mean = 80.7ε) | Max = 481ε (Mean = 113ε)
Jacobi Elliptic: Random Data | Max = 0ε (Mean = 0ε) (GSL 2.1: Max = 4.02ε (Mean = 1.07ε)) | Max = 2.01ε (Mean = 0.584ε) | Max = 2.01ε (Mean = 0.593ε) | Max = 1.92ε (Mean = 0.567ε)
Jacobi Elliptic: Random Small Values | Max = 0ε (Mean = 0ε) (GSL 2.1: Max = 11.7ε (Mean = 1.65ε) And other failures.) | Max = 1.99ε (Mean = 0.347ε) | Max = 1.99ε (Mean = 0.347ε) | Max = 2.11ε (Mean = 0.385ε)
Jacobi Elliptic: Modulus near 1 | Max = 0ε (Mean = 0ε) (GSL 2.1: Max = 0ε (Mean = 0ε) And other failures.) | Max = 109ε (Mean = 7.35ε) | Max = 109ε (Mean = 7.38ε) | Max = 23.2ε (Mean = 1.85ε)
Jacobi Elliptic: Large Phi | Max = 12ε (Mean = 0.771ε) (GSL 2.1: Max = 4.54e+04ε (Mean = 2.63e+03ε)) | Max = 2.45e+04ε (Mean = 1.51e+03ε) | Max = 2.45e+04ε (Mean = 1.51e+03ε) | Max = 4.36e+04ε (Mean = 2.54e+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.