<<

London Mathematical Society ISSN 1461–1570

SYMBOLIC INTEGRATION AND SUMMATION USING HOMOTOPY METHODS

BERNARDDECONINCK AND MICHAEL NIVALA

Abstract The homotopy is a powerful method for indefinite in- tegration of total , and for the indefinite summation of differences. By combining these ideas with straightforward Gaus- sian elimination, we construct an algorithm for the optimal sym- bolic integration or summation of expressions that contain terms that are not total derivatives or differences. The optimization con- sists of minimizing the of terms that remain unintegrated or are not summed. Further, the algorithm imposes an ordering of terms so that the differential or difference order of these remaining terms is minimal.

1. Introduction Homotopy methods are powerful tools originating in differential geometry and the cal- culus of variations for the integration and summation of exact expressions. In one contin- uous spatial dimension, this amounts to integrating total derivatives of expressions con- taining unknown functions and their derivatives. Such calculations occur frequently in ap- plications. For instance, in soliton theory, the form of consecutive conserved densities and their fluxes are given by functional expressions of unknown functions and their derivatives. As shown in [6], the fluxes may be reconstructed by the indefinite integration of such ex- pressions. A second application is the solution of an exact differential equation of arbitrary order [10]. The question addressed in this paper is the design of a fully automated procedure for the integration of expressions containing unknown functions and their derivatives, usable by a system (CAS) such as or Mathematica, especially if the input expressions are not exact. The current versions of both Maple (Release 10) and Mathe- matica (Release 5.1) are unable to integrate expressions that contain both and nonderivative terms, even when the vast majority of the terms is exact. For example, sup- pose one wants to integrate the expression

E = u0(x)v(x) + v0(x)u(x) + u(x), where u(x) and v(x) are unspecified functions of the independent variable x and u0(x) denotes the derivative of u with respect to x. Immediately

Z Z Edx = u(x)v(x) + u(x)dx.

.

c ????, Bernard Deconinck and Michael Nivala

LMS J. Comput. Math. ?? (????) 1–24 Symbolic integration and summation

Below we present an algorithm to obtain this answer systematically. The algorithm is es- pecially suited for expressions containing many terms, not all of which are exact. In to expressions depending on a continuous variable x ∈ R, we also con- sider expressions with a discrete variable n ∈ Z. Such expressions also occur frequently in applications (see [8, 12]). All of the above statements remain true, by replacing “inte- gral” with “sum” and “derivative” with “shift”. To illustrate this, consider the example of summing the expression

2 En = un+1 − un + un. Immediately

X X 2 En = un+1 + un, n n P where n denotes indefinite summation with respect to n. The current implementations of the symbolic integration and summation used by Maple 10 or Mathematica 5.1 do not perform these calculations, in part because of their refusal to make choices about which terms to integrate (sum) and which terms to leave unintegrated (unsummed). Indeed, this is a legitimate concern for more complicated expressions and one may argue about whether or not the answer our algorithm produces is optimal. Be that as it may, there should be no discussion on the resulting answer being an improvement over leaving the expressions untouched, which is the response of Maple 10 or Mathematica 5.1. This is demonstrated in examples. An implementation in Maple of the algorithm presented in this paper is available from [3]. It should be noted that the ideas in this paper are easily generalized to the multidimensional case, i.e., the inversion of the operator (or its discrete analog) [7, 11] . We state everything in one dimension because it is the most important and transparent case.

2. Integrating exact expressions

In this section we are concerned with expressions E(x, u, ux, u2x,..., uNx) of an unknown (vector) u and its derivatives with respect to x. Here N is the order of the highest derivative of any component of u with respect to x appearing in E . For ease of presentation, we assume that E is free of terms of the form Eˆ(x), i.e., terms that are independent of the dependent variable. Such expressions are exact in a trivial sense. We also use the notation DxF to denote the derivative of the expression F with respect to x. We begin by introducing some mathematical tools from the of variations and differential geometry, the Euler operators and the homotopy operator. These operators al- low us to answer the following questions: • Question 1: How does one check if an expression E is exact, i.e., a total derivative, E = DxF for some function F ? −1 • Question 2: If an expression E is exact, how does one determine F = Dx (E) = R Edx? For clarity, we first introduce the more familiar zeroth-order Euler operator or the vari- ational derivative, before introducing the higher-order versions. With the Euler operators in hand, we introduce the homotopy operator and demonstrate how it is used to integrate

2 Symbolic integration and summation exact expressions. Most of the material presented in this section is not new. It may be found in a more abstract form in [2, 11], e.g., or in a more concrete form in [6, 7], for instance.

2.1. The continuous Euler operators DEFINITION 1. The one-dimensional Euler operator of order zero (variational deriva- tive), with independent variable x and dependent variable u = u(1)(x), . . . , u(M)(x), (0) is defined as the operator Lu(x) with M components

(0)  (0) (0)  Lu(x) = Lu(1)(x),..., Lu(M)(x) ∞ ∞ ! (1) X ∂ X ∂ = (−D )k ,..., (−D )k . x (1) x (M) k=0 ∂ukx k=0 ∂ukx In particular, the explicit formula for the variational derivative with scalar component u and variable x is

∞ (0) X k ∂ ∂ ∂ 2 ∂ 3 ∂ Lu(x) = (−Dx) = − Dx + Dx − Dx + ··· . (2) ∂ukx ∂u ∂ux ∂u2x ∂u3x k=0 The Euler operator of order zero allows us to answer Question 1 by the following theo- rem [11].

THEOREM 1. A necessary and sufficient condition for an expression E to be exact is that (0) Lu(x)(E) ≡ 0. Example. Consider

0 0 E = uv + vu = Dx (uv) . (3) Then

(0) 0 Lu(x)(E) = v − Dx (v) = 0.

(0) 0 Lv(x)(E) = u − Dx (u) = 0. −1 R To compute F = Dx (E) = Edx we need the higher Euler operators.

DEFINITION 2. The one-dimensional higher Euler operator of order i with variable x is given by

∞   (i) X k k−i ∂ Lu(x) = (−Dx) , (4) i ∂ukx k=i k k! where = . i i!(k − i)! In particular, the explicit formulas for the first four higher Euler operators (with component u and variable x) are

3 Symbolic integration and summation

(0) ∂ ∂ 2 ∂ 3 ∂ Lu(x) = 1 · − 1 · Dx + 1 · Dx − 1 · Dx + ··· , (5a) ∂u ∂ux ∂u2x ∂u3x (1) ∂ ∂ 2 ∂ 3 ∂ Lu(x) = 1 · − 2 · Dx + 3 · Dx − 4 · Dx + ··· , (5b) ∂ux ∂u2x ∂u3x ∂u4x (2) ∂ ∂ 2 ∂ 3 ∂ Lu(x) = 1 · − 3 · Dx + 6 · Dx − 10 · Dx + ··· , (5c) ∂u2x ∂u3x ∂u4x ∂u5x (3) ∂ ∂ 2 ∂ 3 ∂ Lu(x) = 1 · − 4 · Dx + 10 · Dx − 20 · Dx + ··· . (5d) ∂u3x ∂u4x ∂u5x ∂u6x Though not explicitly used in what follows, it is interesting to note that the higher-order m analog of Question 1 is answered by the higher Euler operators (see [9]), E = Dx F for (k) some F if and only if Lu(x)(E) ≡ 0 for k = 0, . . . , m − 1.

2.2. The continuous homotopy operator We now define the homotopy operator, which reduces integration of an expression in- volving unknown functions to integration of a known function with respect to a single scalar variable.

DEFINITION 3. The one-dimensional homotopy operator with variable x is given by

M Z 1 X dλ H (E) = I (E)[λu] , (6) λ0 j λ λ0 j=1 with

N−1 X i  (j) (i+1)  Ij(E) = Dx u Lu(j)(x)(E) . (7) i=0 The integrand (7) involves the one-dimensional higher Euler operators and M is the num- (1) (M)  ber of components of u(x) = u (x), . . . , u (x) . The notation Ij(E)[λu] implies that in Ij(E) one replaces u(x) with λu(x), ux(x) with λux(x), etc.

Remarks: • This definition differs from that found in [6, 11] to avoid singularities as a conse- quence of the lower of integration, as discussed in [1, 13]. This is illustrated below. • We have not included the part of the homotopy operator that deals with expressions whose only x-dependence is explicit (Sections 1.5 and 5.4 in [11]), as we have as- sumed that all such expressions are removed from E. • The homotopy operator defined above is one of many homotopy operators introduced in [11] and elsewhere. For our purposes here, we simply refer to it as the homotopy operator. The homotopy operator allows us to answer Question 2 by the following theorem (Sec- tion 5.4 in [11], with a more general lower bound used throughout).

4 Symbolic integration and summation

THEOREM 2. For an exact function E = DxF one has

Hλ0 (E) = F [u] − F [λ0u]. (8) It is important to note that the kernel of the homotopy operator is non-trivial (see Appendix A). Because of this, different cases have to be considered: expressions which vanish at zero or infinity and expressions which do not. We can exclude mixed cases (containing both types of limit terms) since Hλ0 is a linear operator.

• Expressions which vanish at zero or infinity: If limλ→λ0 E[λu] = 0 for λ0 equal

to zero or infinity, then evaluating Hλ0 (E) gives F [u], up to an integration con- stant, according to (8). This can be seen by applying the : DxF [λ0u] = E[λ0u] = 0, from which F [λ0u] is a constant independent of x.

• Expressions which do not vanish at zero or infinity: If limλ→λ0 E[λu] = E0[u] 6= 0 for both λ0 = 0 and λ0 = ∞, then: (i) E0[u] is exact (since E[u] is exact) and (ii) E0[u] is an expression of degree zero (see Appendix A). Therefore, E0[u] is in the kernel of the homotopy operator (see Appendix A), and must be dealt with separately. One method of dealing with such terms is the introduction of a parameter, as demonstrated in the examples below. For an alternative approach, see [1]. Also, non-homotopy methods can be used (see [10], for instance). Example. Returning to (3)

E = uv0 + vu0. In this case, u = (u, v) and

0 0 0 0 2 0 0 2 lim E[λu, λv] = lim ((λu)(λv ) + (λv)(λu )) =(uv +vu ) lim λ = (uv +vu )λ0. λ→λ0 λ→λ0 λ→λ0

Thus we choose λ0 = 0. Proceeding without this, we have

Z 1 dλ Hλ0 (E) = (Iu(E)[λu] + Iv(E)[λu]) , λ0 λ with

∞ ∞ X i  (i+1)  X i  (i+1)  Iu(E) = Dx u Lu(x) (E) and Iv(E) = Dx v Lv(x) (E) . i=0 i=0 These formulas give

(1) ∂E (1) ∂E Iu(E) = uLu(x)(E) = u = uv, Iv(E) = vLv(x)(E) = v = vu. ∂ux ∂vx Thus, (6) gives

Z 1 Z 1 2 2  dλ 2 Hλ0 (E) = λ uv + λ uv = 2uv λdλ = uv − uvλ0. λ0 λ λ0

Using λ0 = 0 results in

5 Symbolic integration and summation

F = uv, as desired. Example. Consider

E = u0up. (9) Here

E[λu] = λ(p+1)u0up.

A similar calculation to that given above establishes that λ0 = 0 for p > −1, whereas λ0 = ∞ for p < −1. For p 6= −1, (7) gives

(p+1) Iu(E) = u . Therefore,

Z 1 p (p+1) 1 (p+1) 1 (p+1) (p+1) Hλ0 (E) = λ u dλ = u − u λ0 . λ0 p + 1 p + 1

Evaluating at λ0 = ∞ for p < −1 or λ0 = 0 for p > −1 gives

Z u(p+1) Edx = , p 6= −1. (10) p + 1 Example. Suppose p = −1 in (9) from our previous example, then E is homogeneous of degree zero. In this case (7) gives

Iu(E) = 1, resulting in

Z 1 1  1  Hλ0 (E) = dλ = ln , (11) λ0 λ λ0 which is independent of u(x). Nevertheless, this is correct since upon inspection one has

Z F [u] = Edx = ln (u) , so that

 u   1  F [u] − F [λ0u] = ln (u) − ln (λ0u) = ln = ln , λ0u λ0 in agreement with (8) and (11). Thus F [u] cannot be recovered from the above expression. In order to obtain the desired answer for the case p = −1, we can exploit the fact that the homotopy operator is defined up to a . Using (10), we can remove

6 Symbolic integration and summation the singularity at p = −1 by subtracting the constant of integration 1/(p + 1) (this choice is unique among integration constants that cause an indefinite form as p → −1):

Z u0 u(p+1) 1  dx = lim − = ln (u) . u p→−1 p + 1 p + 1 Example. Only if a singularity is present in the obtained solution (depending on a parame- ter) is it necessary to subtract a suitable integration constant (depending on this parameter) to obtain the correct result, as in the previous example. Otherwise, a simple substitution of the desired parameter suffices. This second scenario is illustrated here. Let

 up 0 pup−1 2upu00 E = = − , u02 u0 u03 which does not vanish at zero or infinity for p = 2. Proceeding for p 6= 2 gives

up  up  H (E) = − λp−2 . λ0 u02 0 u02

Evaluating at λ0 = ∞ for p < 2 or λ0 = 0 for p > 2 gives

up F = , u02 which is correct. Note that this expression is well defined for p = 2. Taking the limit p → 2 gives

Z 2u 2u2u00  u2 − dx = , u0 u03 u02 as desired.

3. Integrating non-exact expressions If an expression E is not exact, we aim to integrate as many total derivatives in E as pos- sible, while optimizing the number and type of terms remaining in the . We use the following six-step method, which we refer to as the homotopy method with optimization.

Step 1. Integrate total derivatives in E. Calculate

F = Hλ0 (E), R where λ0 is equal to zero or infinity. Since E is not exact, F 6= Edx. Step 2. Construct the set of all terms of F . Let p be the number of terms of F = Pp (i) (i) i=1 ciF , such that no two F ’s are constant multiples of each other and each ci is a constant. Form the set R = {F (1),F (2),...,F (p)} of all terms in F . Several choices may be possible for the set R. Preference should be given to the set with the largest p. To this end, expressions should be expanded when possible. It should be noted that working

7 Symbolic integration and summation with a smaller set R will not result in a wrong answer, but merely in a less than optimal answer. Step 3. Separate E into its derivative part and its non-derivative part. Using R,

Z p Z p ! X (i) X (i) Edx = αiF + E − αiDxF dx. (12) i=1 i=1 R R Note that choosing αi = ci for all i gives Edx = F + (E − DxF )dx, which is obviously true. Doing this is referred to as the homotopy method without optimization.

Pp (i) Step 4. Construct an ordered list of terms S occurring in E − i=1 αiDxF . Re- duce S to ensure no two elements are constant multiples of each other. The list starts with elements containing the highest derivatives, ending with those containing the lowest derivatives. Different choices for this ordering are possible, which may result in different but correct final results.

Step 5. Construct a linear algebraic system for α = (α1, . . . , αp). Construct a system Pp (i) of q linear equations such that the j-th equation is the coefficient of Sj in i=1 αiDxF equated to the coefficient of Sj in E. These equations are linear in the components of α, and the system of equations may be written as

Cα = b, (13) where the C is of dimension q × p and the vector b is of dimension q. Note that q > p, since S contains at least p elements obtained by taking a derivative of all elements of R. Thus, (13) is typically overdetermined.

Step 6. Solve for α = (α1, . . . , αp). Typically, the rank of C is p, and p of the equations in (13) can be satisfied. In any case, the goal is to solve as many as possible (= rank C) equations of (13) for the components of α. For every equation satisfied, a term disappears from the integrand of (12). It is preferable to solve the equations in the order they appear in (13), so as to minimize the order of differentiation of the remaining integrand of (12). This may be accomplished by Gaussian elimination, using a minimal number of row switching operations. Once this solution is obtained, (12) provides the final answer for R Edx. Example. Consider

E = 2uu03 + 3u2u0u00 + 2uu0, (0) which is easily checked not to be exact: Lu (E) 6= 0.

Step 1. Applying the homotopy operator with λ0 = 0 we get

3 F = H (E) = u2u02 + u2. λ0 4

Step 2. The above F gives,

R = {u2u02, u2},

8 Symbolic integration and summation thus p = 2.

Step 3. Applying the homotopy method without optimization results in

Z 3 1 Z Edx = u2u02 + u2 + uu03 + 3u2u0u00 dx, (14) 4 2 which is correct, but not optimal. Instead, using (12) we get

Z Z 2 02 2 03 2 0 00 0 Edx = α1u u +α2u + (2 − 2α1) uu + (3 − 2α1) u u u + (2 − 2α2) uu dx.

Step 4. Using this expression to construct the list S gives

S = u2u0u00, uu03, uu0 , so that q = 3. Note that we have placed the term with the higher derivative first. The two terms of differential order 1 were ordered by degree of nonlinearity in their highest derivative.

Step 5. The resulting q × p = 3 × 2 linear system is

 2 0   3   α  2 0 1 = 2 .   α   0 2 2 2

Step 6. As announced, this system is overdetermined. Performing Gaussian elimination with a minimal number of row switching operations gives the equivalent system

 1 0   3/2   α  0 1 1 = 1 .   α   0 0 2 −1

Solving the first two of these equations results in α1 = 3/2 and α2 = 1, at which point no more equations can be solved. Therefore, our final answer is

Z 3 Z Edx = u2u02 + u2 − uu03dx, 2 which is to be preferred over (14).

Example. Let

E = 3u0v2 sin u − u03 sin u − 6vv0 cos u + 2u0u00 cos u + 8v0v00 + v + uv3 + euu000.

Here we have two unknown functions and known functions of these. Using the homotopy

9 Symbolic integration and summation method without optimization we obtain Z u0 2 u02eu euu02 Edx = −3 − 3 + u02 cos u + euu02 + 3 + euu00 − 3v2 cos u u u u2 Z  u0u00 u0 3 u03eu u0u00eu +4v02 + v + uv3 + 6 − 6 − 6 + 6 u2 u u2 u2 u03eu u0 3 u0u00  +3 − euu03 − 3euu0u00 + 6eu − 6eu dx, u u u2 not a desirable result. In this case, the homotopy method with optimization gives Z 1 Z  1  Edx = u02 cos u − euu02 + euu00 − 3v2 cos u + 4v002 + v + uv3 + euu03 dx, 2 2 which is a significant improvement over the non-optimized version. Remarks: • In essence, the homotopy operator is used as a guessing mechanism to generate a list of possible integrated terms, so that the size and the order of differentiation of the integrand in (12) can be reduced. However this does not always work as desired. Consider the example

E = uu00.

(0) 00 (1) 0 Then Lu (E) = 2uu 6= 0, so that E is not exact. Next, Lu (E) = −2u and (2) Lu (E) = u. The action of all remaining higher Euler operators results in zero. Then

1 X i  (i+1)  0 2 0 I(E) = Dx uLu (E) = u(−2u ) + (u ) = 0 ⇒ Hλ0 (E) = 0. i=0 Thus E = uu00 is in the kernel of the homotopy operator and this calculation gives no progress toward achieving

Z Z Edx = uu0 − u02dx, (15)

which has a remaining integrand of lower differential order. This is a consequence of the cancellation occurring in (7). This problem may be avoided by introducing i  (j) (i+1)  PN−1 Jji(E) = Dx u Lu(j)(x)(E) , so that Ij(E) = i=0 Jji(E). Now use (6) with Jji(E) instead of Ij(E) for i ∈ [0,N − 1]. This results in N homotopy-like constructions from which a set R may be constructed which will not suffer from 0 cancellations internal to Ij(E). For the above example J1(E) = −2uu = −J2(E). The resulting R = {uu0}. Using this R, our procedure gives the desired result.

• It should be noted that (12) is an identity for all choices of α1, . . . , αp. Even without using the previous remark, the obtained answer,

Z Z Edx = uu00dx,

10 Symbolic integration and summation

is correct, even though (15) may be more desirable. In summary, our procedure always gives a correct result, even though other guessing mechanisms may prove equally or more successful.

4. Application: modulo derivatives In many applications [4, 5, 11], terms are considered equivalent if they are the same up to a total derivative. Applying the homotopy method with optimization may considerably simplify such computations. Example. Consider 03 2 0 00 E1 = 2uu + 3u u u , 0 2 03 0 0 00 0 00 3 E2 = 3u v sin u − u sin u − 6vv cos u + 2u u cos u + 8v v + v + uv . Applying the homotopy method with optimization and only keeping terms which are left inside the resulting integral gives

03 E1 ∼ −uu , and

3 E2 ∼ v + uv , where E ∼ Eˆ means E − Eˆ is a total derivative. Thus, the homotopy method with optimization allows one to efficiently reduce an ex- pression to one of equal or lower differential order, equivalent to the original one up to a total derivative.

5. Summing exact expressions We now turn our attention to the discrete case, where we are concerned with expressions of the form En = E(n, un, un+1,..., un+N ) of an unknown (vector) function un and a finite number of its positive shifts, where N is the order of the highest shift of any component of un appearing in En. As in the continuous case, we assume that En contains no terms Eˆ(n) that are independent of the dependent variable. We will make use of the shift operator D, DEn = En+1. The identity operator is denoted by I, IEn = En, and ∆ = D − I, is the forward difference operator, ∆En = (D − I)En = En+1 − En. We begin by introducing the discrete analogs of the previously stated mathematical tools from the and differential geometry, the discrete Euler operators and the discrete homotopy operator. These operators will allow us to answer the following questions:

• Question 1: How does one check if an expression En is exact, i.e., a total difference, En = ∆Fn = Fn+1 − Fn for some function Fn? P • Question 2: If an expression En is exact, how does one determine Fn+1 = n En? We first introduce the zeroth-order discrete Euler operator or the discrete variational derivative, before proceeding to introduce the higher-order versions. With the discrete Eu- ler operators in hand, we introduce the discrete homotopy operator and demonstrate how it is used to sum exact expressions. Most of the material presented in this section is not new.

11 Symbolic integration and summation

It may be found in a more abstract form in [8], or in a more concrete form in [6, 7], for instance.

5.1. The discrete Euler operators DEFINITION 4. The one-dimensional discrete Euler operator of order zero (discrete variational derivative), with the discrete independent variable n and dependent variable   u = u(1), . . . , u(M) L(0) M n n n , is defined as the operator un with components

N N ! (0)  (0) (0)  X ∂ X ∂ L = L ,..., L = D−k ,..., D−k un (1) (M) (16a) un un (1) (M) k=0 ∂un+k k=0 ∂un+k N ! N !! ∂ X ∂ X = D−k ,..., D−k . (1) (M) (16b) ∂un k=0 ∂un k=0

Note the similarity of (16a) to the continuous Euler operator of order zero (1). In what follows, we use the second formulation (16b) because of its computational convenience. The discrete variational derivative allows us to answer Question 1 by the following theorem [8].

THEOREM 3. A necessary and sufficient condition for an expression En, with positive L(0) (E ) ≡ 0 shifts, to be exact is that un n .

Example. Consider

2 2 5 2 5 2 En = un+3vn+2 + un − vn − un+1vn + vn+1 − un+1. (17) 2 2 2 5 Note that En = ∆Fn, Fn = −un + un+1vn + un+2vn+1 + vn. Indeed, ∂ L(0)(E ) = (u v2 + v5 − u2 + u v2 − u v2 un n n+3 n+2 n+1 n+1 n+2 n+1 n−1 n−2 ∂un 2 5 2 +un−3 − vn−3 − un−2vn−3) = 0 and ∂ L(0)(E ) = (u v2 + v5 − u2 + u v2 − u v2 + u2 vn n n+3 n+2 n+1 n+1 n+2 n+1 n n−1 n−2 ∂vn 5 2 −vn−2 − un−1vn−2) = 0. P To compute Fn+1 = n En, we need the discrete higher Euler operators.

DEFINITION 5. The one-dimensional discrete higher Euler operator of order k with discrete independent variable n is given by N   N   (k) X m ∂ ∂ X m L = D−m = D−m. un (18) k ∂un+k ∂un k m=k m=k

12 Symbolic integration and summation

In particular, the first four higher Euler operators for component un are ∂ L(0) = (1 · I + 1 · D−1 + 1 · D−2 + 1 · D−3 + ··· ), un (19a) ∂un ∂ L(1) = 1 · D−1 + 2 · D−2 + 3 · D−3 + 4 · D−4 + ···  , un (19b) ∂un ∂ L(2) = 1 · D−2 + 3 · D−3 + 6 · D−4 + 10 · D−5 + ···  , un (19c) ∂un ∂ L(3) = 1 · D−3 + 4 · D−4 + 10 · D−5 + 20 · D−6 + ···  . un (19d) ∂un

As in the continuous case, the higher-order analog of Question 1 is answered by the discrete E = ∆mF F L(k) (E ) ≡ 0 k = higher Euler operators, n n for some n if and only if un n for 0, . . . , m − 1 L(k) (∆E ) = (the proof is analogous to the continuous version [9], using un n L(k−1)(E )) un n .

5.2. The discrete homotopy operator Next, we define the discrete homotopy operator, which reduces summation of an ex- pression involving unknown functions to integration of a known function with respect to a single scalar variable.

DEFINITION 6. The one-dimensional discrete homotopy operator with discrete indepen- dent variable n is M Z 1 X dλ Hˆ (E ) = I (E )[λu ] , (20) λ0 n j n n λ λ0 j=1 with N−1 X i  (j) (i+1)  Ij(En) = ∆ un L (j) (En) . (21) un i=0 The integrand (21) involves the one-dimensional higher Euler operators and M is the  (1) (M) number of components of un = un , . . . , un . The notation Ij(En)[λun] implies that in Ij(En) one replaces un with λun, un+1 with λun+1, etc. The discrete homotopy operator allows us to answer Question 2 by the following theo- rem [8].

THEOREM 4. For an exact function En = ∆Fn, one has ˆ Hλ0 (En) = Fn[un] − Fn[λ0un]. (22) As in the continuous case, the kernel of the discrete homotopy operator is non-trivial (see Appendix Appendix A). Thus, we consider two cases: expressions which vanish at zero or ˆ infinity and expressions which do not. Again, we can exclude mixed cases since Hλ0 is a linear operator.

• Expressions which vanish at zero or infinity: If limλ→λ0 En[λun] = 0 for λ0 ˆ equal to zero or infinity, then evaluating Hλ0 (En) gives Fn[un], up to a summa- tion constant, according to (22). This can be seen by noting that ∆Fn[λ0un] =

13 Symbolic integration and summation

En[λ0un] = 0 ⇒ Fn+1[λ0un] = Fn[λ0un], thus Fn[λ0un] is a constant indepen- dent of n.

• Expressions which do not vanish at zero or infinity: If limλ→λ0 En[λun] 6= 0 for both λ0 = 0 and λ0 = ∞, then as in the continuous case, the limiting value is in the kernel of the discrete homotopy operator (see Appendix A), and must be dealt with separately. One method of dealing with such terms is the introduction of a parameter, as demonstrated in the examples below. A modified version of the homotopy operator may be used as well, as discussed in the remark at the end of the next section. Also, non-homotopy methods can be used (see Appendix B, for example). Example. Returning to (17),

2 2 5 2 5 2 En = un+3vn+2 + un − vn − un+1vn + vn+1 − un+1.

In this case, un = (un, vn) and

 3 2 2 2 5 5 3 2 lim En[λun, λvn] = lim λ un+3vn+2 + λ un − λ vn − λ un+1vn λ→λ0 λ→λ0 5 5 2 2  +λ vn+1λ un+1

2 2 2 3 5 2 3 5 = λ0 λ0un+3vn+2 + un − λ0vn − λ0un+1vn + λ0vn+1

2  −un+1 .

Thus we choose λ0 = 0. Proceeding without this, we have Z 1 ˆ dλ Hλ0 (En) = (Iun (f)[λun] + Ivn (f)[λun]) , 0 λ with ∞ ∞ X   X   I (E ) = ∆i u L(i+1)(E ) and I (E ) = ∆i v L(i+1)(E ) . un n n un n vn n n vn n i=0 i=0 These formulas give     I (E ) = u L(1)(E ) + ∆ u L(2)(E ) + ∆2 u L(3)(E ) un n n un n n un n n un n   ∂ −1 −2 −3 ∂ −2 −3 = un D + 2D + 3D (En) + ∆ un D + 3D (En) ∂un ∂un   2 ∂ −3 +∆ un D (En) ∂un 2 2 2 = −2un + un+1vn + un+2vn+1, and   I (E ) = v L(1)(E ) + ∆ v L(2)(E ) vn n n vn n n vn n   ∂ −1 −2 ∂ −2 = vn D + 2D (En) + ∆ vn D (En) ∂vn ∂vn 5 2 2 = 5vn + 2un+1vn + 2un+2vn+1. 14 Symbolic integration and summation

Thus, (20) gives Z 1 ˆ dλ Hλ0 (En) = (Iun (En)[λun] + Ivn (En)[λun]) λ0 λ Z 1 2 2 2 2 2 4 5  = −2λun + 3λ un+1vn + 3λ un+2vn+1 + 5λ vn dλ λ0 2 2 2 5 2 2 3 2 2 = −un + un+1vn + un+2vn+1 + vn + λ0un − λ0unun+1vn 3 2 2 5 2 5 −λ0unun+2vn+1 − λ0unvn.

Evaluating at λ0 = 0 results in 2 2 2 5 Fn = −un + un+1vn + un+2vn+1 + vn, as desired.

Example. Consider p p En = un+2un+1 − un+1un. (23) Here we have (p+1) p p  En[λun] = λ un+2un+1 − un+1un .

A similar calculation to that given above establishes that λ0 = 0 for p > −1, whereas λ0 = ∞ for p < −1. For p 6= −1, (21) gives

p Iun (En) = (p + 1)un+1un. Therefore,

Z 1 ˆ p p p (p+1) p Hλ0 (En) = λ (p + 1)un+1undλ = un+1un − λ0 un+1un. λ0

Evaluating at λ0 = ∞ for p < −1 or λ0 = 0 for p > −1 gives

X p En = un+2un+1, p 6= −1. (24) n

Example. Suppose p = −1 in (23) from our previous example, then En is homogeneous of degree zero. In this case (21) gives

Iu(En) = 0, resulting in Z 1 ˆ 1 Hλ0 (En) = 0 · dλ = 0. (25) λ0 λ This is correct: upon inspection one has

X un+2 F = E = , n+1 n u n n+1 15 Symbolic integration and summation giving

un+1 λ0un+1 Fn[un] − Fn[λ0un] = − = 0, un λ0un in agreement with (22) and (25). However, Fn[un] cannot be recovered from the above expression. In order to obtain the desired answer for p = −1, we proceed as we did in the contin- uous case. Returning to our previous example, making note of the fact that there are no singularities with respect to the parameter p in (24), we make the substitution p = −1 giving X un+2 F = E = , n+1 n u n n+1 as desired.

6. Summing non-exact expressions

If an expression En is not exact, we aim to sum as many differences in En as possible, while optimizing the number and type of terms remaining in the sum. We use the following six-step method, which we refer to as the discrete homotopy method with optimization.

Step 1. Sum total differences in En. Calculate ˆ Fn = Hλ0 (En), P where λ0 is equal to zero or infinity. Since En is not exact, Fn+1 6= n En.

Step 2. Construct the set of all terms of Fn. Let p be the number of terms of Fn = Pp (i) (i) i=1 ciFn , such that no two Fn ’s are constant multiples of each other and each ci is a (1) (2) (p) constant. Form the set R = {Fn ,Fn ,...,Fn } of all terms in Fn. Several choices may be possible for the set R. Preference should be given to the set with the largest p. To this end, expressions should be expanded when possible. It should be noted that working with a smaller set R will not result in a wrong answer, but merely in a less than optimal answer.

Step 3. Separate En into its difference part and its non-difference part. Using R, p p ! X X (i) X X (i) En = αiFn+1 + En − αi∆Fn . (26) n i=1 n i=1 P P Note that choosing αi = ci for all i gives n En = Fn+1 + n (En − (Fn+1 − Fn)), which is obviously true. Doing this is referred to as the discrete homotopy method without optimization. Pp (i) Step 4. Construct an ordered list of terms S occurring in En − i=1 αi∆Fn . Reduce S to ensure no two elements are constant multiples of each other. The list starts with ele- ments which contain the highest degree of non-locality (the difference between the highest shift and the lowest shift). Different choices for this ordering are possible, which may result in different but correct final results.

Step 5. Construct a linear algebraic system for α = (α1, . . . , αp). Construct a system Pp (i) of q linear equations such that the j-th equation is the coefficient of Sj in i=1 αi∆Fn 16 Symbolic integration and summation equated to the coefficient of Sj in En. These equations are linear in the components of α, and the system of equations may be written as

Cα = b, (27) where the matrix C is of dimension q × p and the vector b is of dimension q. Note that q > p, since S contains at least p elements obtained by applying D to all elements of R. Thus, (27) is typically overdetermined.

Step 6. Solve for α = (α1, . . . , αp). Typically, the rank of C is p, and p of the equations in (27) can be satisfied. In any case, the goal is to solve as many as possible (= rank C) equations of (27) for the components of α. For every equation satisfied, a term disappears from the summand of (26). It is preferable to solve the equations in the order they appear in (27), so as to minimize the degree of non-locality of the remaining summand of (26). P Once this solution is obtained, (26) provides the final answer for n En. Example. Consider 2 2 En = 2un+3un+2 − un+1un + un+2, (28) (0) which is easily checked not to be exact: Lun 6= 0 .

Step 1. Applying the discrete homotopy operator with λ0 = 0 we get 2 Hˆ (E ) = u2 u + 2u2 u + 2u2 u + u + u . λ0 n 3 n n−1 n+1 n n+2 n+1 n+1 n

Step 2. The above gives 2 2 2 R = {un+1un, un+2un+1, unun−1, un+1, un}, thus p = 5. Step 3. Applying the discrete homotopy method without optimization results in X 2 E = u2 u + 2u2 u + 2u2 u + u + u n 3 n+1 n n+2 n+1 n+3 n+2 n+2 n+1 n (29) X 1 2  + u2 u + u 2u + u , 3 n+1 n 3 n n−1 n n which is correct, but not optimal. Instead, using (26) we get

X 2 2 2 En = α1un+2un+1 + α2un+3un+2 + α3un+1un + α4un+2 + α5un+1 n X  2 2 + (2 − α2)un+3un+2 + (α2 − α1)un+2un+1 + (1 − α4)un+2 + α5un n 2 2  +(−1 + α1 − α3)un+1un + α3unun−1 + +(α4 − α5)un+1 .

Step 4. Using this expression to construct the list S gives

 2 2 2 2  S = un+3un+2, un+2un+1, unun−1, un+1un, un+2, un+1, un , 17 Symbolic integration and summation so that q = 7. Note that in this case the first four terms have the same degree of non- locality, 1, while the last three terms have degree of non-locality 0. Terms with the same degree of non-locality have been ordered by the absolute value of their lowest shift, from highest to lowest (with negative shifts before positive shifts).

Step 5. The resulting q × p = 7 × 5 linear system is

 0 1 0 0 0   2     −1 1 0 0 0  α1  0       0 0 1 0 0   α2   0         1 0 −1 0 0   α3  =  1  .        0 0 0 1 0   α4   1       0 0 0 1 −1  α5  0  0 0 0 0 1 0

Step 6. As announced, this system is overdetermined. Performing Gaussian elimination with a minimal number of row switching operations gives the equivalent system

 1 0 0 0 0   2     0 1 0 0 0  α1  2       0 0 1 0 0   α2   0         0 0 0 1 0   α3  =  1  .        0 0 0 0 1   α4   1       0 0 0 0 0  α5  −1  0 0 0 0 0 −1

Solving the first five of these equations results in α1 = α2 = 2, α3 = 0, and α4 = α5 = 1 at which point no more equations can be solved. Therefore, our final answer is

X 2 2 X 2  En = 2un+2un+3 + 2un+1un+2 + un+2 + un+1 + un+1un + un , n n which is to be preferred over (29).

Example. Let

9 3 2 un 5 9 3 un+1 5 2 En = 7 un+3vn+2 + un+1vn − e vn+1 − un+2vn+1 + e vn+2 − 3 un+2vn+1. Here we have two unknown functions and a known function of these. Using the discrete homotopy method without optimization gives

X 9 3 9 3 9 3 un+1 5 2 En = 7 un+3vn+2 + 9/2 un+1vn + 6 un+2vn+1 + e vn+2 − 4/3 un+1vn n 2 X  2 9 3 9 3 −3 un+2vn+1 + − 2/3 un+1vn + 3/2 un+1vn + 9/2 unvn−1 n 2  −4/3 unvn−1 .

In this case, the discrete homotopy method with optimization gives

18 Symbolic integration and summation

X 9 3 9 3 un+1 5 2 En = 7 un+3vn+2 + 6 un+2vn+1 + e vn+2 − 3 un+2vn+1 n X 9 3 2  + 6 un+1vn − 2 un+1vn , n which is an improvement over the non-optimized version. Remark: The homotopy method with optimization also provides a way of summing exact expressions which do not vanish as the homotopy parameter λ approaches zero or infinity. As in the continuous case, we introduce

i  (j) (i+1)  Jji(En) = ∆ un L (j) (En) , un PN−1 so that Ij(En) = i=0 Jji(En). Now use (20) with Jji(En) instead of Ij(En) for i ∈ [0,N − 1]. This results in N homotopy-like constructions from which a set R may be constructed which will not suffer from cancellations internal to Ij(En). For example, returning to (23) with p = −1 we have

un+2 un+1 En = − . un+1 un This was shown to be in the kernel of the homotopy operator, thus, we were unable to recover Fn. Instead, using the above gives J1(En) = −un+1/un +un/un−1 = −J2(En). u u This results in R = { n , n+1 }. Using this R, our procedure gives the desired result. un−1 un

7. Application: modulo differences In many applications [6, 12], terms are considered equivalent if they are identical up to differences. Applying the homotopy method with optimization may considerably simplify such computations. Example. Consider (1) 2 2 7 En = n un+1 + 3 nun+1 + 2 un+1 − n un − nun + un, (2) 2 2 En = −unun+1vn − vn + un+1un+2vn+1 + vn+1 + un+3vn+2 − un+1vn + un+1 11 +vn − unun+1vn+5. Applying the homotopy method with optimization and retaining the remaining summand gives

(1) 7 En ∼ un, and (2) 11 En ∼ vn + un − unun+1vn+5, where En ∼ Eˆn means En − Eˆn is a difference. Thus, the homotopy method with optimization allows one to efficiently reduce an ex- pression to a simpler (difference free) expression, equivalent to the original one up to a difference.

19 Symbolic integration and summation

Appendix A. The kernel of the homotopy operator Here we discuss the kernel of the continuous and discrete homotopy operators. Definition. An expression E[u] is equivalent to a term of degree zero if

E[λu] = E[u] + Cλ where Cλ is a constant independent of (u, ux, u2x,...). E is of degree zero if Cλ ≡ 0.

Theorem. An exact expression E = DxF is in the kernel of the homotopy operator if and only if E is of degree zero. Remark: The kernel is defined only up to a constant of integration. All constants of inte- gration are considered equivalent to 0. Lemma. E is of degree zero if and only if F is equivalent to a term of degree zero.

Proof of the lemma. First, suppose F is equivalent to a term of degree zero. Then

E[λu] = Dx (F [λu]) = Dx (F [u] + C) = DxF [u] = E[u]. Therefore E is of degree zero. Now, suppose E is of degree zero. Then

Dλ (E[λu]) = Dλ (E[u]) = 0. Thus,

0 = Dλ (E[λu]) = Dλ (DxF [λu]) = Dx (DλF [λu]) .

This implies that DλF [λu] is some constant, B(λ), independent of x. Integrating with respect to λ gives

Z 1 Z 1 Z 1 DλF [λu]dλ = B(λ)dλ ⇒ F [u] − F [λ0u] = B(λ)dλ. λ0 λ0 λ0 This implies, Z 1 F [λ0u] = F [u] − B(λ)dλ. λ0

Therefore, since λ0 is arbitrary, F is equivalent to a term of degree zero.  Proof of the theorem. Now, suppose E is in the kernel of the homotopy operator. Then

Hλ0 (E) = F [u] − F [λ0u] = A, where A is some constant. This implies that

F [λ0u] = F [u] − A.

20 Symbolic integration and summation

Thus, F is equivalent to a term of degree zero, which in turn implies E is of degree zero by the lemma. Now, suppose E is of degree zero. This implies that F is equivalent to a term of degree zero by the lemma. Thus,

F [λu] = F [u] + Cλ. Therefore,

Hλ0 (E) = F [u] − F [λ0u] = −Cλ0 , i.e., E is in the kernel of the homotopy operator.  We have the analogous result for the discrete case.

Theorem. An exact expression En = ∆Fn is in the kernel of the discrete homotopy oper- ator if and only if En is of degree zero. The proof closely resembles that of the continuous case, and it is omitted here.

Appendix B. A non-homotopy summation algorithm Alternatively, we can use the following non-homotopy method to sum exact and non- exact expressions in one dimension. This method is devoid of the problem with the homo- topy method when summing terms that do not vanish in the limit as λ goes to 0 or infinity. However, it is not easily generalized to the multi-dimensional setting unlike the homotopy method (see remark below). Our goal is to reduce the summand to a standard form, which we define as an expression with every term having a lowest shift of zero. This will automatically eliminate differences from the summand since the standard form of a difference, En = ∆Fn = Fn+1 − Fn (assuming, without loss of generality, that the lowest shift in Fn is 0), is Fn − Fn = 0. To −m accomplish this, we define the minimum shift operator, Z, such that Z(En) = D (En), where m is the minimum shift occurring in En. In other words, Z returns an expression which has a minimum shift of zero. Applying Z to each term in the summand reduces it to standard form. Since we wish to apply Z to terms inside a sum, we need the telescoping P P summand rule, n En = En +En−1 +···+En−m+1 + n Z(En). This rule allows one to compensate for the action of Z on the summand. For En = ∆Fn, this rule reduces to P P P P P the more familiar identity n ∆Fn = n Fn+1 − n Fn = Fn+1 + n Fn − n Fn = Fn+1. Using the above remarks, the algorithm is as follows. Let p be the number of terms of Pp (i) (i) En = i=1 En , such that no two En ’s are constant multiples of each other (see Step 2 of the discrete homotopy method). Then one has

X X En = Tn + Gn, n n where p X (i) Gn = Z(En ) i=1 21 Symbolic integration and summation is in standard form, and is therefore difference free. Here Tn is found by use of the tele- scoping summand rule: p X (i) Tn = Tn , i=1

T (i) = E(i) + E(i) + ··· + E(i) m E(i) where n n n−1 n−mi+1 and i is the lowest shift occurring in n . For example, consider

un+2 un+1 2 2 En = − + 2un+3un+2 − un+1un + un+2, un+1 un a combination of our previous examples. We have

−1 Z (un+2/un+1) = D (un+2/un+1) = un+1/un, 0 Z (−un+1/un) = D (−un+1/un) = −un+1/un, 2  −2 2  2 Z 2un+3un+2 = D 2un+3un+2 = 2un+1un, 2  0 2  2 Z −un+1un = D −un+1un = −un+1un, −2 Z (un+2) = D (un+2) = un. Thus,

un+1 un+1 2 2 2 Gn = − + 2un+1un − un+1un + un = un+1un + un, un un which is indeed difference free. Using the telescoping summand rule each time we apply Z to a term inside the sum gives

un+2 2 2 Tn = + 2un+3un+2 + 2un+2un+1 + un+2 + un+1. un+1 Therefore, our final result is

X un+2 X E = + 2u2 u + 2u2 u + u + u + u2 u + u  , n u n+3 n+2 n+2 n+1 n+2 n+1 n+1 n n n n+1 n in agreement with our results using homotopy methods. Remark: This and other non-homotopy methods (see [10] for instance) rely on the fact that summation (integration) and the inversion of the discrete (continuous) divergence op- erator are equivalent in one-dimension. In the multi-dimensional setting, however, this equivalence no longer holds, i.e., multiple summation (integration) is not the higher di- mensional analog of the inversion of the discrete (continuous) divergence operator. As explicitly shown in [7, 11], the homotopy operator reduces this inversion in any dimen- sion to a single integration. We see no clear extension of the algorithm presented in this appendix to higher dimensions, where as homotopy methods may still be used.

Acknowledgments We gratefully acknowledge useful discussions with Willy Hereman and Elizabeth Mans- field. The work presented here was supported by the National Science Foundation under grants DMS 0139093 (BD) and DMS-VIGRE 0354131 (MN).

22 Symbolic integration and summation

References

1. S.C.ANCO and G. BLUMAN, ‘Direct construction method for conservation laws of partial differential equations. II. General treatment.’ European J. Appl. Math. 13 (2002) 567–585. 2. I.M.ANDERSON, ‘Introduction to the variational bicomplex.’ ‘Mathematical aspects of classical field theory (Seattle, WA, 1991),’ (Amer. Math. Soc., Providence, RI, 1992), vol. 132 of Contemp. Math. pp. 51–73, pp. 51–73. 3. B.DECONINCK and M. NIVALA, ‘A maple package for symbolic integration and summation.’ Available at http://www.amath.washington.edu/˜bernard/papers.html . 4. L.A.DICKEY, Soliton equations and Hamiltonian systems, vol. 26 of Advanced in Mathematical Physics (World Scientific Publishing Co. Inc., River Edge, NJ, 2003), 2nd edn. ISBN 981-238-173-2. 5. A. P. FORDY (ed.), Soliton theory: a survey of results. Nonlinear Science: Theory and Applications (Manchester University Press, Manchester, 1990). ISBN 0-7190- 1491-3. 6. W. HEREMAN,M.COLAGROSSO,R.SAYERS,A.RINGER,B.DECONINCK, M.NIVALA and M. HICKMAN, ‘Continuous and discrete homotopy operators and the computation of conservation laws.’ ‘Differential Equations with Symbolic com- putation,’ (Birkhauser,¨ Boston, MA, 2005), Trends in mathematics pp. 255–290, pp. 255–290. 7. W. HEREMAN,L.D.POOLE and B. DECONINCK, ‘Continuous and discrete homo- topy operators: a theoretical approach made concrete.’ (Submitted for publication, 2005) . 8. P. E. HYDON and E. L. MANSFIELD, ‘A variational complex for difference equa- tions.’ Found. Comput. Math. 4 (2004) 187–217. 9. M.D.KRUSKAL,R.M.MIURA,C.S.GARDNER and N. J. ZABUSKY, ‘Korteweg- de Vries equation and generalizations. V. Uniqueness and nonexistence of conservation laws.’ J. Mathematical Phys. 11 (1970) 952–960. 10. G.M.MURPHY, Ordinary differential equations and their solutions (D. Van Nos- trand Co., Inc., Princeton, N.J.-Toronto-London-New York, 1960). 11. P. J. OLVER, Applications of Lie groups to differential equations, vol. 107 of Gradu- ate Texts in Mathematics (Springer-Verlag, New York, 1993), 2nd edn. ISBN 0-387- 94007-3; 0-387-95000-1. 12. Y. B. SURIS, The problem of integrable discretization: Hamiltonian approach, vol. 219 of Progress in Mathematics (Birkhauser¨ Verlag, Basel, 2003). ISBN 3-7643- 6995-7. 13. T. WOLF,A.BRAND and M. MOHAMMADZADEH, ‘Computer algebra algorithms and routines for the computation of conservation laws and fixing of gauge in differ- ential expressions.’ J. Symbolic Comput. 27 (1999) 221–238.

23 Symbolic integration and summation

Bernard Deconinck [email protected] Michael Nivala [email protected] Department of Applied Mathematics University of Washington Seattle, WA 98195-2420

24