Content uploaded by Toshio Fukushima

Author content

All content in this area was uploaded by Toshio Fukushima on Dec 16, 2017

Content may be subject to copyright.

Numerical Computation of Inverse Complete Elliptic

Integrals of First and Second Kind

Toshio Fukushima

National Astronomical Observatory of Japan, 2-21-1, Ohsawa, Mitaka, Tokyo 181-8588,

Japan

Abstract

We developed the numerical procedures to evaluate the inverse functions of

the complete elliptic integrals of the ﬁrst and second kind, K(m) and E(m),

with respect to the parameter m. The evaluation is executed by inverting

eight sets of the truncated Taylor series expansions of the integrals in terms

of mor of −log(1 −m). The developed procedures are (1) so precise that

the maximum absolute errors are less than 3-5 machine epsilons, and (2)

30-40% faster than the evaluation of the integrals themselves by the fastest

procedures (Fukushima 2009a, 2011).

Keywords: complete elliptic integral; inversion

1. Introduction

1.1. Complete elliptic integrals of ﬁrst and second kind

The complete elliptic integrals of the ﬁrst and the second kind are deﬁned

[1, Section 19.2(i)] as

K(m)≡Zπ/2

0

dθ

p1−msin2θ, E(m)≡Zπ/2

0p1−msin2θ dθ, (1)

where mis called the parameter. They appear in various ﬁelds of mathe-

matical physics and engineering [2, 3, 4, 5]. In discussing the real-valued

integrals, we assume that mis in the standard domain,

0≤m < 1.(2)

Email address: Toshio.Fukushima@nao.ac.jp (Toshio Fukushima)

Preprint submitted to Journal of Computational and Applied MathematicsJanuary 31, 2013

Figure 1: Dependence of the complete elliptic integrals on the parameter m.

Refer to [6, 7] for the process to reduce the other cases to the standard

one. See Figure 1 for the functional dependence of K(m) and E(m) on the

parameter min the standard domain.

1.2. Numerical computation of complete elliptic integrals

Many methods have been developed to compute the values of K(m)

and/or E(m) when mis given. The popular iterative schemes are those

using (1) the arithmetic-geometric mean [1, Section 19.8(i)], (2) the Landen

transformation [8, 9], (3) the Bartky transformation [10, 11], or (4) the du-

plication theorems [12, 13]. They are useful in computing the integrals in

arbitrary precision arithmetic.

For practical purposes, however, their Chebyshev approximations [14, 15,

16, 17, 18] are suﬃcient. Recently, we developed a method based on their

Taylor series expansions [6]. It is as precise as the Chebyshev approximation

and runs twice faster than that. Also, we extended it to the case of a general

complete elliptic integral of the second kind, αK(m) + βE(m) [7]. The

extended method is as precise as Bulirsch’s cel2 and Carlson’s rf and rd

and runs 5-18 times faster than them.

1.3. Necessity of inverse complete elliptic integrals

In practical applications, we sometimes encounter with the inversion prob-

lem of K(m) or E(m), namely the determination of mwhen K(m) or E(m)

is given. Especially, that of K(m) is required in estimating a physical quan-

tity related to mfrom 4K(m), the observed period of a certain physical

phenomenon expressed by the Jacobian elliptic functions, sn(u|m), cn(u|m),

and dn(u|m) [1, Chapter 22]. A classic example of such phenomenon is the

motion of a simple gravity pendulum [1, Section 22.19(i)]. Another is the

torque-free rotation of an asymmetrical rigid body [19].

1.4. Outline of article

Despite such practical needs, the inversion problem of K(m) and E(m)

has not been studied comprehensively. This might be due to their logarithmic

singularity around m= 1. In this short article, we report a numerical method

to invert the integrals by adopting the same approach in our previous work

of their evaluation [6, 7]: the piecewise polynomial approximation based on

2

the Taylor series expansion. In §2, we discuss the diﬃculties of the inversion

problem and ﬁnd a clue to resolve them. In §3, we present the details of the

method we developed based on the hint we found in §2. In §4, we show the

results of the numerical experiments in order to illustrate the computational

error and the CPU times of the new method.

2. Consideration

2.1. Slow convergence of inverted Maclaurin series

If mis expected to be small, we may compute it by inverting the Maclau-

rin series expansion of the integrals by the Lagrange inversion theorem [1,

Section 1.10(vii)]. The Maclaurin series of the integrals are expressed in

terms of Gauss’s hypergeometric series [1, Formulas 19.5.1 and 19.5.2] as

K(m) = π

2F1

2,1

2; 1; m, E(m) = π

2F1

2,−1

2; 1; m.(3)

Their inversion series around K(0) = E(0) = π/2 are given as

m≈4x−9x2+31

2x3−185

8x4+507

16 x5+···,(4)

m≈ −4y−3y2+1

2y3−5

8y4+15

16y5+···,(5)

where

x≡2K(m)

π−1, y ≡2E(m)

π−1.(6)

One may obtain the higher order expressions by issuing a command in Math-

ematica [21] such as

InverseSeries[Series[EllipticK[m],{m,0,65}]]

The convergence of the hypergeometric series to compute K(m) and E(m) is

slow when mincreases [22]. The same is that of the inverted series. Figure 2

illustrates the order of these inverted power series needed to assure a certain

level of accuracy, say 14 digits in this case, as functions of m. Apparently,

they signiﬁcantly increase according as m→1.

3

Figure 2: Necessary order of the truncated inversion series of K(m) and E(m) around

m= 0. Plotted are the minimum order of the truncated inversion series of K(m) and

E(m) to provide 14 correct digits of m.

2.2. Diﬃculty in root ﬁnding

Another approach of the inversion is the application of a root ﬁnding

algorithm [5, Chapter 9] to the deﬁning equations

K(m) = K, or E(m) = E. (7)

Although the precise and fast evaluation of K(m) and E(m) is established

[6, 7], it is not enough. We must ﬁnd a robust and suﬃciently accurate ap-

proximate solution such that the following repetition of the update formulas

such as the Newton method surely converges.

However, this is a diﬃcult task. The feature of the curves depicted in

Figure 1 support this conjecture. Also, the convergence of the iteration

becomes slow when m≈1 because the absolute magnitude of the derivatives

of K(m) and E(m) grow inﬁnitely when m→1.

2.3. Logarithmic singularity

The diﬃculties explained in the previous subsections are caused by the

logarithmic singularity of K(m) and E(m) at m= 1 [1, Formulas 19.12.1

and 19.12.2]. Their simple expressions around the singularity are given [7] as

K(m) = K1−KXlog mc, E(m) = E1−EXlog mc,(8)

where mc≡1−mis the complementary parameter and K1through EXare

the quantities being regular around mc= 0 as

K1≡K(mc)

πlog mc

q(mc)= 2 log 2 + log 2

2−1

4mc+···,(9)

KX≡K(mc)

π=1

2+mc

8+···,(10)

E1≡1

2KX

+1−E(mc)

K(mc)K1= 1 + log 2 −1

4mc+···,(11)

EX≡1−E(mc)

K(mc)KX=mc

4+···,(12)

where q(m) is Jacobi’s nome [1, Formula 19.5.5]. These are the base expres-

sions of the Chebyshev approximations [14, 16].

4

Figure 3: Dependence of complete elliptic integrals on p. Shown are K(m) and r≡

−log(E(m)−1) as functions of the alternate variable, p≡ −log mc.

2.4. Variable transformation

The asymptotic forms of the integrals around m= 1 shown in the previous

subsection trigger us to change the main variable from mto

p≡ −log mc.(13)

The domain of pis semi-inﬁnite since p→+∞when m→1. However, its

practical domain can be limited since we may set the meaningful maximum of

pas pMAX ≡ −log where is the machine epsilon. It is at most a few tens as

pMAX ≈16.6 and ≈36.7 in the single and the double precision environments,

respectively.

If mcis suﬃciently small, say less than , we may retain only the leading

terms in Eqs (9) and (10). Thus, we obtain an asymptotic expression of

K≡K(m) as

K= 2 log 2 + p

2+···.(14)

This leads to the inversion in terms of pas

p= 2K−4 log 2 + ···,(15)

Namely, pis almost linear with respect to Kwhen Kis suﬃciently large, say

larger than 2. Figure 3 conﬁrms this conjecture.

In the case of E≡E(m), we must keep up to the ﬁrst order terms in Eqs

(11) and (12). Then, we arrive at a little complicated expression as

E= 1 + (p+ 4 log 2 −1) e−p

4+···.(16)

We rewrite this as

r≡ −log (E−1) = p−log p−1

4+ log 2+···.(17)

The variability of the second term in the right hand side is relatively small

as

−2.264 <−log p−1

4+ log 2<−0.814,(18)

5

when 0 <p<36.7. Thus, we ignore its contribution and obtain a solution

as

p≈r. (19)

This is a crude approximation. A better solution would be obtained by di-

rectly solving Eq.(16) with help of W−1(x), the secondary branch of Lambert

W-function [21]. Since the numerical evaluation of W−1(x) is itself a diﬃcult

problem [23, 24, 25], we do not go further in this direction.

At any rate, Figure 3 indicates that Kand rare almost linear with respect

to p. Then, they may be candidates of the functions to be expanded in terms

of the new variable, p.

3. Method

3.1. Strategy

Based on the discussions in §2, we developed a method to invert Kand

Ewith respect to min the standard domain, 0 ≤m < 1. Let us denote the

inverted solutions by mK(K) and mE(E), respectively. They are deﬁned as

the functions to satisfy the relations

K(mK(x)) = x, E (mE(x)) = x. (20)

The key idea is splitting the integral value domain into two regions: that

corresponding to not-so-large m, say less than 0.9 or so, and the rest.

In the former region, we approximate mby a piecewise polynomial of K

or E. Each piece of the approximate polynomials is obtained by inverting

the Taylor series expansion of K(m) and E(m) around a certain reference

value of m. In the second region, we approximate p≡ −log mcby a piecewise

polynomial of Kor r≡ −log(E−1). Similarly, each piece of the approximate

polynomials is obtained by inverting the Taylor series expansion of K(m(p))

and −log(E(m(p)) −1) around a certain reference value of pwhere

m(p)≡1−e−p.(21)

Once pis obtained, we can numerically evaluate mby this relation.

In the double precision environment, we limit the order of the approxi-

mate polynomials less than 19. This is in order to reduce the typical compu-

tational time of the inverted solutions down to the level of that of elementary

functions like exp. Under this restriction, we try to minimize the number of

pieces by adjusting the reference values in terms of mor p.

6

After the approximate polynomials are ﬁxed, we try to apply the Lanczos

economization [5, Section 5.11] to them. Namely, we rewrite each piece of

them into a ﬁnite series of the Chebyshev polynomials of the ﬁrst kind [26].

Except the cases near the singularity, the magnitude of the series coeﬃcients

smoothly decreases according as the degree of the Chebyshev polynomial.

In that case, by removing the Chebyshev polynomials of some highest de-

grees from the series, we can reduce the degree of the original approximate

polynomials signiﬁcantly while keeping their precision practically unchanged.

It is well known that the ﬁnite linear sum of the Chebyshev polynomials

can be eﬃciently evaluated by Clenshaw’s summation algorithm [26, Sec-

tion 3.2]. See also [27, Section 3.7]. Nevertheless, the fastest evaluation is

achieved by Horner’s method of the power series expanded around the mid-

dle point of the deﬁning interval. The coeﬃcients of the rearranged power

series are rigorously obtained from the Chebyshev polynomial coeﬃcients by

a conversion procedure such as given in Appendix A.2.

In place of the economized power series, however, we present here the

Chebyshev polynomial coeﬃcients such that one can truncate them at an

arbitrary precision. This will be useful to construct the single precision pro-

cedures. Skipping the details, we show the ﬁnal results below.

3.2. Case of small parameter

When the solution mis not expected to be large, say less than 0.9 or so,

we evaluate mKand mEby their piecewise approximate polynomials derived

from the inverted Taylor series expansions. The piecewise polynomials consist

of four polynomials corresponding to the four sub domains of the integral

values denoted by A, B, C, and D. Table 1 shows the integral values to

separate these sub domains. For example, as mK, we use the approximate

polynomial obtained in the sub domain A if KA≤K < KB, that in the sub

domain B if KB≤K < KC, and so on.

In constructing the piecewise polynomials, we set m0, the reference value

of min each sub domain, as 0.2, 0.5, 0.7, and 0.85 for Kand 0.2, 0.5, 0.7,

and 0.83 for E. In each sub domain, we ﬁrst obtained the approximate

polynomials in the form of truncated Taylor series such as

mK=

N

X

n=0

an(K−K0)n,(22)

where K0≡K(m0) is the reference integral value. We determined the power

7

Table 1: Separation values of Kand E. Listed are the values of Kand Eto select the

best approximate polynomial. The index means that, for K, the sub domain A is the

interval [KA, KB), the sub domain B is the interval [KB, KC), ···, and the sub domain

H is the interval [KH,∞). On the other hand, for E, the sub domain A is the interval

(EB, EA], the sub domain B is the interval (EC, EB], ···, and the sub domain H is the

interval [1, EH]. Also, we added the values of r≡ −log(E−1) for the indices E through

H.

Index K E r

A 1.5707963267948966 1.5707963267948966

B 1.7539969906494259 1.4111237670965148

C 1.9495677498060259 1.2907868683852396

D 2.1998873957149437 1.1878333138534634

E 2.5687780604965515 1.1199612906642078 2.1286317858706077

F 3.6189656655262064 1.0556008611359877 2.8895565897882066

G 5.3616789503774974 1.0048203911429256 5.3349002042275533

H 8.7012952137792582 1.0000443476373730 10.0234511229381364

series coeﬃcients, an, by issuing commands of Mathematica [21] like

InverseSeries[Series[EllipticK[m],{m,0.2,17}]]

which gives those of mKin the sub domain A.

Next, we examined the errors of the piecewise polynomial, mK(K) or

mE(E), by comparing the corresponding integral values, K(mK(K)) or E(mE(E)),

with the original input values of Kor E, respectively. We conducted the

comparison in the quadruple precision by using qcel, the quadruple preci-

sion extension of Bulirsch’s cel [11]. In the errors of some pieces, we found a

constant oﬀset of the order of a few machine epsilons. It seems to be caused

by the accumulation of round-oﬀ errors in the inversion process. At any rate,

we adjusted a0in that case.

Third, by taking the balance between the measured errors of the approx-

imate polynomials obtained in the adjacent sub domains, we determined

their separation values in terms of mas 0.365, 0.600, 0.773, and 0.898 for

Kand 0.375, 0.614, 0.786, and 0.881 for E. These are translated into the

corresponding integral values as KB=K(0.365), ···,KE=K(0.898), and

EB=E(0.375), ···,EE=E(0.881). They are listed in Table 1 together

with the lower end values, KA≡K(0) = π/2 and EA≡E(0) = π/2.

8

Finally, we transformed the obtained polynomials into the ﬁnite sum of

Chebyshev polynomials as

mK=

N

X

n=0

cnTn(t) = c0T0(t) + c1T1(t) + c2T2(t) + ···,(23)

where Nis the degree of the obtained polynomial, Tn(t) is the Chebyshev

polynomial of the ﬁrst kind of degree n[1, Table 18.3.1], and cnis its n-th

coeﬃcient. Appendix A.1 describes an algorithm to do the conversion from

anto cn. Notice that we deﬁne the zeroth coeﬃcient, c0, without the divisor

2. This is diﬀerent from the deﬁnition of the Chebyshev expansion in some

literatures [26, 5, 27].

Meanwhile, the argument of the Chebyshev polynomials, t, which is in

the range [−1,+1], is computed from the integral values such as

t≡a(K−b),(24)

where

a≡2

KU−KL

, b ≡KU+KL

2,(25)

are the transformation coeﬃcients determined from KUand KL, the upper

and lower ends of the sub domain. These end values are already listed in

Table 1. We conducted exactly the same treatment for E. The resulting

Chebyshev polynomial coeﬃcients and the transformation coeﬃcients are

explicitly given in Tables 2 and 3 for mKand mE, respectively.

3.3. Case of large parameter

If K≥KEor E≤EE, the parameter mbecomes signiﬁcantly large, say

larger than 0.89 or so. In that case, we approximate p≡ −log mcby its

piecewise polynomial in terms of Kor r≡ −log(E−1). In constructing the

piecewise polynomials, we set p0, the reference value of pin each sub domain,

as 3.3, 6.0, 10.5, and 17.6 for Kand 1.8, 4.2, 8.0, and 15.0 for r. In each sub

domain, the approximate polynomials are written as

pK=

NK

X

n=0

pn(K−K0)n, pE=

NE

X

n=0

qn(r−r0)n,(26)

where

K0≡K1−e−p0, r0≡ −log E1−e−p0−1,(27)

9

Table 2: Chebyshev polynomial coeﬃcients of mK: sub domains A through D. The nu-

merical values of the coeﬃcients, cn, are multiplied by a certain powers of 10 such as

1017 in order to suppress the leading zeros. For example, the zeroth coeﬃcients must

read +0.19 ·· ·, +0.49 ···, +0.69 · ··, and +0.84 ···. These zeroth coeﬃcients are deﬁned

without the divisor 2. Namely, mKis approximated as mK=c0T0(t) + c1T1(t) + ···.

where Tnis the Chebyshev polynomial of the ﬁrst kind of degree n. Also, we listed aand

b, the transformation coeﬃcients from Kto t, the argument of Chebyshev polynomials,

such that t=a(K−b). All the values are shown with a few more digits than necessary

in the double precision computation. This is in order to avoid the round-oﬀ errors in the

implementation.

A B C D

n1017cn1017 cn1017cn1017 cn

0 +19401242299345095 +48990719448270469 +69305133428229853 +84201552855821970

1 +18194753782220755 +11715040871065477 +8613490854834244 +6201036207545733

2−1148955521044524 −739311643473559 −653420708906968 −648514448920333

3 +55159476593419 +34907474599398 +36436506978491 +48795524452071

4−2283669657743 −1406019129690 −1709827595538 −3029715923753

5 +86634143620 +51595118298 +72527965477 +167839458005

6−3105064734 −1783762901 −2887658427 −8670547452

7 +106925302 +59157015 +110075215 +427595012

8−3574353 −1902485 −4063750 −20387219

9 +116785 +59756 +146392 +947243

10 −3747 −1842 −5173 −43128

11 +118 +56 +180 +1932

12 −85

a+10.916991008220921 +10.226477662739623 +7.9897843924233070 +5.4216606462081334

b+1.6623966587221613 +1.8517823702277259 +2.0747275727604848 +2.3843327281057476

10

Table 3: Chebyshev polynomial coeﬃcients of mE: sub domains A through D. Same as

Table 2 but for mE. The zeroth coeﬃcients must read +0.19 ···, +0.49 ·· ·, +0.70 ···, and

+0.83 ·· ·. Also, the transformation from Eto tis expressed as t=a(E−b).

A B C D

n1018cn1017 cn1017cn1017 cn

0 +191491596762105577 +49694125666025830 +70197876373537509 +83448854563061028

1 +187521750862407743 +11951688581417314 +8602065171825419 +4751257054900759

2−3990799269547337 −244061880474704 −197779951710636 −98795130570153

3−21715474908196 −1685618407984 −2059553190095 −1253506060813

4−795715611047 −63628928178 −96047713357 −59189763242

5−35290453296 −2953987502 −5591458166 −3530719901

6−1771319411 −156070789 −372015072 −241289912

7−96704988 −8986478 −27007660 −18000725

8−5606172 −549838 −2084262 −1427478

9−339873 −35191 −168273 −118417

10 −21330 −2332 −14065 −10167

11 −1376 −159 −1208 −897

12 −106 −81

a−12.5256337330469197 −16.6200061778109266 −19.4262355398589756 −29.4672223697113173

b+1.4909600469457057 +1.3509553177408772 +1.2393100911193515 +1.1538973022588356

are the reference function values. We obtained the approximate polynomials

by issuing commands of Mathematica [21] like

InverseSeries[Series[−Log[EllipticE[1−Exp[−p]] −1]],{p,1.8,17}]]

which gives the coeﬃcients of pEfor p0= 1.8.

After constructing the approximate polynomials, we again examined their

errors by using qcel, and determined the separation values in terms of p

as 4.45, 7.95, and 14.63 for Kand 3.1, 6.0, and 11.2 for E. These are

translated into the corresponding function values as KF=K(1 −e−4.45),

···,KH=K(1 −e−14.63), EF=E(1 −e−3.1), ···,EH=E(1 −e−11.2), and

rE=−log (EE−1), ···, and rH=−log (EH−1). They are already listed

in Table 1.

For the sub domains E and F, we again transformed the obtained poly-

nomials into the form of the series of Chebyshev polynomials such as

pE=

N

X

n=0

cnTn(t),(28)

11

where the transformation of argument becomes

t≡a(r−b),(29)

with the transformation coeﬃcients deﬁned as

a≡2

rU−rL

, b ≡rU+rL

2,(30)

where rUand rLare the upper and lower ends of the sub domain in terms of r,

which are already listed in Table 1. The Chebyshev polynomial coeﬃcients

and the transformation coeﬃcients are explicitly given in Tables 4 and 5.

Noting that ∆m≈e−p∆p, we may truncate the Chebyshev expansion in

terms of pearlier than that in terms of m.

3.4. Case near the singularity

For the sub domains G and H, we ﬁnd that the Lanczos economization is

not eﬀective in reducing the computational labor. Of course, one may execute

the transformation into Chebyshev polynomial series. For the sub domain G,

which is semi-inﬁnite, this is practically feasible by setting the upper end as

KI= +19.755 or rI= +34.472, which roughly corresponds to the numerical

value of Kor Ewhen m= 1 −double where double ≡2−53 ≈1.11 ×10−16 is

the double precision machine epsilon.

However, we learn that the decreasing manner of the magnitude of the

resulting coeﬃcients of the Chebyshev polynomials is quite slow. This is be-

cause the minimax type approximation with respect to pdoes not guarantee

a uniform error distribution in terms of msince ∆m≈e−p∆p. Therefore, we

abandon the economization and present the original Taylor series themselves

in Tables 6 and 7. We truncated them such that the numbers of terms are

the necessary minimum to assure the maximum of |∆m|remain at the level

of double.

4. Numerical Experiments

Let us examine the computational cost and performance of the method

described in the previous section. The absolute errors of mobtained by the

method in the double precision environment are illustrated in Figs 4 and

5. They are measured by using qcel, the quadruple precision extension of

Bulirsch’s procedure to evaluate the general complete elliptic integral [11].

12

Table 4: Chebyshev polynomial coeﬃcients of pK: sub domains E and F. Same as Table

2 but for pK. The zeroth coeﬃcients must read +3.37 ·· ·, and +6.20 · ··. The argu-

ment transformation becomes t=a(K−b) again. In truncating the series of Chebyshev

polynomials, one should note that the ﬁnal error in mis reduced by the factor e−pas

|∆m| ≈ e−p|∆p|. The maximum reduction factor in each sub domain is also listed.

E F

n1015cn1014cn

0 +3372842411096568 +620234816387263

1 +1082799019684612 +174947955583875

2−6377916757929 −226305230130

3 +804553258630 +50978226844

4−72934012596 −8407174303

5 +5172172149 +1058249590

6−325770457 −103492197

7 +21898786 +7909234

8−1696166 −487701

9 +136104 +30082

10 −10427 −2890

11 +780 +372

12 −60 −42

13 +5 +4

a+1.9044216389732810 +1.1476357111552424

b+3.0938718630113789 +4.4903223079518519

max e−p0.102 ≈0.0450

13

Table 5: Chebyshev polynomial coeﬃcients of pE: sub domains E and F. Same as Table

4 but for pE. The zeroth coeﬃcients must read +2.62 ·· · and +4.56 ···. The argument

transformation is written as t=a(r−b) where r≡ −log(E−1).

E F

n1015cn1015cn

0 +2621927976267172 +4563857924247435

1 +480434270533396 +1448978332531438

2−2421516965161 −13787853000146

3 +60368511503 +1017879586053

4−1103238537 −69972247182

5 +4267375 +3797035826

6 +654240 −100760933

7−30728 −8981925

8 +745 +1749497

9−5−170996

10 +11351

11 −400

12 −22

a+2.62838060962536483 +0.817880966989805936

b+2.5090941878294072 +4.1122283970078800

max e−p0.119 ≈0.0450

14

Table 6: Taylor series coeﬃcients of pK: sub domains G and H. Listed are the coeﬃcients

of the power series expression as pK=PN

n=0 an(K−K0)n.

G H

n anan

0 +10.500000000000 +17.600000000000

1 +2.0001414497655 +2.0000001973566

2−1.277026552E−4−1.859964E−7

3 +7.59811036E−5 +1.164242E−7

4−3.34231082E−5−5.44254E−8

5 +1.15490151E−5 +2.02555E−8

6−3.2468658E−6−6.2470E−9

7 +7.573936E−7 +1.6406E−9

8−1.476109E−7−3.74E−10

9 +2.383963E−8 +7.5E−11

10 −3.07883E−9−1.3E−11

11 +2.83187E−10

12 −9.125E−12

13 −2.572E−12

14 +5.45E−13

15 −3.E−14

16 −2.E−14

17 +6.2E−15

K0+6.6363331625866755 +10.186294413299100

15

Table 7: Taylor series coeﬃcients of pE: sub domains G and H. Same as Table 6 but for

pEexpressed as pE=PN

n=0 an(r−r0)nwhere r≡ −log(E−1).

G H

n anan

0 +8.000000000000000000 +15.00000000000000000

1 +1.1138558445808138764 +1.0634010131365226997

2−7.160737009252904412E−3−2.137214443579717823E−3

3 +6.14816637761486272E−4 +9.8905527968533563E−5

4−5.7949395860221721E−5−5.240426861207633E−6

5 +5.451526070327390E−6 +2.99271455626484E−7

6−4.80075731204772E−7−1.7869634729734E−8

7 +3.7093529426652E−8 +1.092804281815E−9

8−2.222894130707E−9−6.7254295377E−11

9 +5.377967260E−11 +4.096019951E−12

10 +1.071061734E−11 −2.42723757E−13

11 −2.33974846E−12 +1.3740808E−14

12 +3.0858084E−13 −7.2627E−16

13 −3.239999E−14 +3.455E−17

14 +2.84089E−15 −1.36E−18

15 −2.0071E−16 +3.E−20

16 +9.0E−18 −1.4E−21

17 +3.E−19 +7.E−23

18 −2.E−19

r0+7.10660216677717055 +13.5665483242003067

16

Figure 4: Parameter dependence of the errors of the inverse complete elliptic integrals: case

of small parameters. Shown are the absolute errors of the double precision computation

of mK(K) and mE(E) as functions of their values. The unit of the errors is the double

precision machine epsilon, double ≈1.11 ×10−16.

Figure 5: Parameter dependence of the errors of the inverse complete elliptic integrals: case

of large parameters. Same as Fig. 4 but as functions of p≡ −log(1 −m). The maximum

value of pshown here is that corresponding to the extreme case, m= 1 −double.

More speciﬁcally speaking, we ﬁrst prepare min the quadruple precision

environment. Next, we compute K(m) and E(m) in the quadruple precision

by qcel as

K(m) = qcel(√1.0−m, 1.0,1.0,1.0),(31)

E(m) = qcel(√1.0−m, 1.0,1.0,1.0−m).(32)

Third, we compute the double precision values of mKand mEfrom the

double precision value of K(m) and E(m) using the procedures described in

the previous section, namely the ﬁnite series of the Chebyshev polynomials

in the sub domains A through F and the inverted Taylor series in the sub

domains G and H. Finally, we take the diﬀerence of mKand mEfrom the

original min the quadruple precision environment.

Figs 4 and 5 show that, in the double precision computation, the mag-

nitude of the absolute errors of mKand mEare less than 3 and 5 machine

epsilons, respectively.

On the other hand, Table 8 compares the CPU time of the fastest proce-

dures to compute K(m) or E(m) [6, 7] as well as the procedures to obtain

mK(K) and mE(E) using Horner’s method to evaluate the economized or

original power series. The coeﬃcients of the economized power series are

obtained from the tables in the previous section by the conversion procedure

described in Appendix A.2. The CPU times are averaged for 226 grid points

evenly distributed in the parameter domain, 0 ≤m < 1. The measurements

are conducted at a PC with an Intel Core i7-2675QM run at 2.20 GHz clock

under Windows 7.

Table 8 shows that the procedures to compute the inverse functions of

K(m) and E(m) are 30 and 40 % faster than those to compute themselves

[6, 7], respectively. This is mainly due to the faster convergence of the

inverted Taylor series than the Taylor series and partly due to the Lanczos

economization of the polynomial expressions.

17

Table 8: CPU time comparison. Listed are the averaged CPU time of some procedures to

compute the complete elliptic integrals and their inverse in the double precision environ-

ment. The unit of CPU time is nano second at a latest consumer PC with an Intel Core

i7-2675QM run at 2.20 GHz clock.

Target Procedure Reference CPU time

K(m)celk [6] 71

mK(K)icelk This article 55

E(m)celbd [7] 83

mE(E)icele This article 58

5. Conclusion

We developed the numerical procedures to compute mK(K) and mE(E),

the inverse complete elliptic integrals of the ﬁrst and the second kind, K≡

K(m) and E≡E(m), in the double precision environment, respectively.

The key idea of the procedures is splitting the integral value domain into two

regions: that corresponding to not-so-large m, say smaller than 0.9 or so,

and that near the logarithmic singularity, m= 1. In the former region, we

obtained a piecewise power series approximation of the inverse functions by

using the inverted Taylor series expansion with respect to m. In the latter

region, we (1) changed the main variable from mto p≡ − log(1 −m), (2)

regarded Kor r≡ −log(E−1) as a function of p, and (3) inverted the Taylor

series of Kand rwith respect to p. The resulting piecewise polynomials con-

sist of four polynomials for each region. Their selection rules are determined

from the error measurement of the obtained polynomials by means of the

quadruple precision computation of the integral values. Except for the two

sub domains near the singularity point, m= 1, we rearranged the polynomial

expressions into the ﬁnite series of Chebyshev polynomials such that one may

truncate them at an arbitrary level of precision. This makes easy to obtain

the single precision procedures. Thanks to the eﬀectiveness of the policy of

divide-and-rule, the developed procedures are so precise that, in the double

precision environment, the maximum absolute error of mKand mEis less

than 3 and 5 machine epsilons, respectively. Also, the procedures run signif-

icantly faster than the fastest procedures of the integral value computation

[6].

18

The double precision Fortran functions of the developed procedures, icelk

and icele, are available from the author’s personal WEB page at Research-

Gate:

https ://www.researchgate.net/profile/Toshio Fukushima/

Acknowledgments

The author thanks the anonymous referee for many valuable advices to

improve the quality of the present article including the application of the

Lanczos economization.

Appendix A. Transformation between power series and Cheby-

shev polynomial series

Any polynomial can be expressed in two ways, a power series and a series

of Chebyshev polynomials [26]. Namely, it is written as

N

X

n=0

anxn=

N

X

n=0

cnTn(x),(A.1)

where Nis the degree of the polynomial, Tn(x) is the Chebyshev polynomial

of the ﬁrst kind of degree n[1, Table 18.3.1], and we assumed that the

argument xis in the standard interval, [−1,+1]. Below, we summarize the

transformation between the coeﬃcients of the power series, {an}, and those

of the Chebyshev polynomials, {cn}.

Appendix A.1. From power series to Chebyshev polynomial series

It is well known that Tn(x) is a polynomial of degree nwith integral

coeﬃcients [27, Eq.(3.32)] as

Tn(x) =

bn/2c

X

`=0

Tn` xn−2`,(A.2)

where Tn` is an integer and bxcis the ﬂoor function. Note that the range of

the second index is 0 ≤`≤ bn/2c≤bN/2c. Its length is roughly the half of

that of the ﬁrst one since 0 ≤n≤N.

19

The explicit expression of Tn` is known [27, Eq.(3.33)] as

T00 =T10 = 1,(A.3)

Tn` = (−1)`2n−2`−1n

n−` n−`

`.(2 ≤n, 0≤`≤ bn/2c) (A.4)

The latter is simpliﬁed when n= 2`[27, Eq.(3.34)] as

T2`, ` = (−1)`.(A.5)

Instead of evaluating these expressions, we compute Tn` by recursion as

Tn+1,0= 2Tn0,(1 ≤n≤N−1) (A.6)

Tn+1, ` = 2Tn` −Tn−1, `−1,(2 ≤n≤N−1,1≤`≤ bn/2c − 1) (A.7)

T2`, ` =−T2(`−1), `−1,(1 ≤`≤ bN/2c) (A.8)

starting from the initial conditions, Eq.(A.3). The above recurrence formulas

are nothing but the translation of the three term recurrence relation of Tn(x)

[27, Eq.(3.20)],

Tn+1(x)=2xTn(x)−Tn−1(x),(1 ≤n) (A.9)

in terms of the coeﬃcients. The recursion consists of integer operations only,

and therefore it suﬀers no round-oﬀ errors when nis suﬃciently small, say

less than 30 when using the 4 byte integers. Also, its execution is fairly fast.

Using Tn`, we obtain a transformation formula from {cn}to {an}as

an=

b(N−n)/2c

X

`=0

Tn+2`, ` cn+2`.(0 ≤n≤N) (A.10)

This is simpliﬁed when n= 0 as

a0=

bN/2c

X

`=0

(−1)`cn+2`.(A.11)

Usually the magnitude of cnis monotonically decreasing with the index, n.

Then, we execute the summation in the above transformation formula in the

reverse order, i.e. the order decreasing `. This trick signiﬁcantly suppresses

the accumulation of round-oﬀ errors in the transformation procedure. This is

the reason why we prepare the coeﬃcient matrix, Tn`, at the cost of additional

memory. For the readers’ convenience, we present a double precision Fortran

subroutine to do the transformation in Table A.9.

20

Table A.9: Double precision Fortran subroutine to transform the Chebyshev polynomial

coeﬃcients, {cn}, into the power series coeﬃcients, {an}.

subroutine cheb2poly(n,c,a)

integer JMAX,NMAX

parameter (JMAX=15,NMAX=JMAX*2)

integer n,T(0:NMAX,0:JMAX),m,j

real*8 c(0:n),a(0:n),am

logical ﬁrst/.TRUE./

save ﬁrst,T

if(ﬁrst) then

ﬁrst=.FALSE.;T(0,0)=1;T(1,0)=1

do j=1,JMAX

T(2*j,j)=-T(2*(j-1),j-1)

enddo

do m=2,NMAX

T(m,0)=2*T(m-1,0)

do j=1,(m-1)/2

T(m,j)=2*T(m-1,j)-T(m-2,j-1)

enddo

enddo

endif

do m=0,n

am=0.d0

do j=(n-m)/2,0,-1

am=am+dble(T(m+2*j,j))*c(m+2*j)

enddo

a(m)=am

enddo

return;end

21

Appendix A.2. From Chebyshev polynomial series to power series

A monomial of degree nis expressed as a ﬁnite linear sum of the Cheby-

shev polynomial of the same or lower degree [27, Eq.(3.35)] as

xn=

bn/2c

X

`=0

Bn` Tn−2`(x),(A.12)

where the coeﬃcients Bn` are explicitly written as

B00 = 1,(A.13)

Bn` =1

2n−1n

`.(1 ≤n, 0≤`≤ bn/2c) (A.14)

These coeﬃcients are ﬁnite fractions in the binary machines, and therefore

can be expressed without round-oﬀ errors when nis suﬃciently small, say

less than 50 in the double precision environment. Again, we prefer computing

them by recursion as

Bn+1,0= 2−1Bn0,(1 ≤n≤N−1) (A.15)

Bn+1, ` = 2−1(Bn, `−1+Bn`),(2 ≤n≤N−1,1≤`≤ b(n−1)/2c) (A.16)

B2`, ` =B2`−1, `−1,(1 ≤`≤ bN/2c) (A.17)

starting from the initial condition, Eq.(A.13). At any rate, the transforma-

tion from {an}to {cn}is of the same form as Eq.(A.10) as

cn=

b(N−n)/2c

X

`=0

Bn+2`, ` an+2`.(1 ≤n≤N) (A.18)

We anticipate that the magnitude of anis also monotonically decreasing with

the index, n. Then, we again execute the summation in the transformation

formula in the reverse order.

As for the most important coeﬃcient, c0, we adopt a diﬀerent approach.

We solve the expression of a0, Eq.(A.11), with respect to c0. Then, using

thus-computed coeﬃcients cnfor n6= 0 and a0, we evaluate the solution

form of c0by Horner’s method as

c0=a0+ (c2−(c4−(···(cM−2−cM)···))) ,(A.19)

where M≡2bN/2c. This technique further reduces the accumulation of

round-oﬀ errors. Table A.10 lists a double precision Fortran subroutine to

do the transformation. We used its quadruple precision extension in deriving

the tables in the main text.

22

Table A.10: Double precision Fortran subroutine to transform the power series coeﬃcients,

{an}, into the Chebyshev polynomial coeﬃcients, {cn}.

subroutine poly2cheb(n,a,c)

integer JMAX,NMAX

parameter (JMAX=15,NMAX=JMAX*2)

integer n,m,j

real*8 a(0:n),c(0:n),B(0:NMAX,0:JMAX),cm

logical ﬁrst/.TRUE./

save ﬁrst,B

if(ﬁrst) then

ﬁrst=.FALSE.;B(0,0)=1.d0;B(1,0)=1.d0

do m=2,NMAX

B(m,0)=0.5d0*B(m-1,0)

do j=1,(m-1)/2

B(m,j)=0.5d0*(B(m-1,j-1)+B(m-1,j))

enddo

if(m.eq.m/2*2) then

B(m,m/2)=B(m-1,m/2-1)

endif

enddo

endif

do m=1,n

cm=0.d0

do j=(n-m)/2,0,-1

cm=cm+B(m+2*j,j)*a(m+2*j)

enddo

c(m)=c(m)

enddo

cm=c(n/2*2)

do j=n/2-1,1,-1

cm=c(2*j)-cm

enddo

c(0)=a(0)+cm

return;end

23

References

[1] Olver, F.W.J., Lozier, D.W., Boisvert, R.F., & Clark,

C.W. (eds),NIST Handbook of Mathematical Functions, Cam-

bridge Univ. Press, Cambridge, 2010, Chapter 4. Freely accessible at

http://dlmf.nist.gov/

[2] Byrd, P.F., & Friedman, M.D.,Handbook on Elliptic Integrals for

Engineers and Physicists, 2nd ed., Springer-Verlag, Berlin, 1971.

[3] Press, W.H., Flannery, B.P., Teukolsky, S.A., & Vetter-

ling, W.T.,Numerical Recipes: the Art of Scientiﬁc Computing, Cam-

bridge Univ. Press, Cambridge, 1986

[4] Jeffrey, A., & Zwillinger, D. (eds.),Gradshteyn and Ryzhik’s Ta-

ble of Integrals, Series, and Products, Seventh edition, Academic Press,

New York, 2007

[5] Press W.H., Teukolsky S.A., Vetterling W.T., Flannery

B.P.,Numerical Recipes: the Art of Scientiﬁc Computing, 3rd ed.. Cam-

bridge Univ. Press, Cambridge, 2007.

[6] Fukushima, T.,Fast Computation of Complete Elliptic Integrals and

Jacobian Elliptic Functions, Celest. Mech. Dyn. Astron., 105 (2009a)

305-328.

[7] Fukushima, T.,Precise and Fast Computation of the General Com-

plete Elliptic Integral of the Second Kind, Math. Comp., 80 (2011) 1725-

1743.

[8] Bulirsch, R.,Numerical Computation of Elliptic Integrals and Elliptic

Functions, Numer. Math., 7 (1965a) 78-90.

[9] Bulirsch, R.,Numerical Computation of Elliptic Integrals and Elliptic

Functions II, Numer. Math., 7 (1965b) 353-354.

[10] Bulirsch, R.,An Extension of the Bartky-Transformation to Incom-

plete Elliptic Integrals of the Third Kind, Numer. Math., 13 (1969a)

266-284.

[11] Bulirsch, R.,Numerical Computation of Elliptic Integrals and Elliptic

Functions III, Numer. Math., 13 (1969b) 305-315.

24

[12] Carlson, B.C.,Computing Elliptic Integrals by Duplication, Numer.

Math., 33 (1979) 1-16.

[13] Carlson, B.C., & Notis, E.M.,Algorithm 577. Algorithms for In-

complete Elliptic Integrals, ACM Trans. Math. Software, 7 (1981) 398-

403.

[14] Hastings, C. Jr.,Approximations for Digital Computers, Princeton

Univ. Press, Princeton, 1955.

[15] Abramowitz, M., & Stegun, I.A. (eds),Handbook of Mathematical

Functions with Formulas, Graphs, and Mathematical Tables, National

Bureau of Standards, Washington, 1964, Chapter 17.

[16] Cody, W.J.,Chebyshev Approximations for the Complete Elliptic In-

tegrals K and E, Math. Comp., 19 (1965a) 105-112.

[17] Cody, W.J.,Chebyshev Polynomial Expansions of Complete Elliptic

Integrals K and E, Math. Comp., 19 (1965b) 249-259.

[18] Cody, W.J.,Corrigenda: Chebyshev Approximations for the Complete

Elliptic Integrals K and E, Math. Comp., 20 (1966) 207.

[19] Fukushima, T.,Eﬃcient Solution of Initial-Value Problem of Torque-

Free Rotation, Astron. J., 137 (2009b) 210-218.

[20] Fukushima, T.,Numerical inversion of a general incomplete elliptic

integral, J. Comp. Appl. Math., 237 (2013a) 43-61.

[21] Wolfram, S.,The Mathematica Book, 5th ed., Wolfram Research

Inc./Cambridge Univ. Press, Cambridge, 2003.

[22] Whittaker, E.T., & Watson, G.N.,A Course of Modern Analysis,

4th ed., Cambridge Univ. Press, Cambridge, 1958.

[23] Chapeau-Blondeau, F. & Monir, A,Evaluation of the Lambert

Wfunction and application to generation of generalized Gaussian noise

with exponent 1/2, IEEE Trans. Signal Processing, 50 (2002) 2160-2165.

[24] Veberic, D.,Lambert W function for applications in physics, Comp.

Phys. Comm., 183 (2012) 2622-2628.

25

[25] Fukushima, T.,Precise and fast computation of Lambert W-functions

without transcendental function evaluations, J. Comp. Appl. Math., 244

(2013b) 77-89.

[26] Rivlin, T.J.,Chebyshev Polynomials, 2nd ed., Wiley-Interscience, New

York, 1990.

[27] Gil, A., Segura, J., & Temme, N.M.,Numerical Methods for Spe-

cial Functions, SIAM, Philadelphia, 2007.

26