Integration of the signum, piecewise and related functions

D.J. Jefirey1, G. Labahn2, M. v. Mohrenschildt3 and A.D. Rich4 1Department of Applied Mathematics, The University of Western Ontario, London, Ontario, Canada N6A 5B7; [email protected] 2Department of Computer Science, University of Waterloo, Waterloo, Ontario, Canada N2L 3G1; [email protected] 3Department of Computer Engineering, McMaster University, Hamilton, Canada;[email protected] 4Soft Warehouse Inc., 3660 Waialae Avenue, Suite 304 Honolulu, Hawaii 96816 USA

Abstract Maple V and Mathematica evaluate this integral as

When a computer algebra system has an assump- 1 1 3x2 1 + dx = (x3 + x) 1 + , (1) tion facility, it is possible to distinguish between x2 x2 integration problems with respect to a real vari- Z r r able, and those with respect to a complex vari- because they assume x C. In contrast, Derive assumes able. Here, a class of integration problems is de- x R and returns ∈ fined in which the integrand consists of compo- ∈ sitions of continuous functions and signum func- 1 3x2 1 + dx = [(x2 + 1)3/2 1] sgn x . (2) tions. and integration is with respect to a real x2 − variable. Algorithms are given for evaluating Z r such integrals. Maple can also obtain this answer, as will be shown later. Both answers are correct, and the difference lies in the as- 1 Introduction sumptions. Notice in particular that the integrand in equa- tion (1) is continuous on R, but the right side of (2) is In recent years, ‘assume’ or ‘declare’ facilities have been im- discontinuous at x = 0. plemented in most of the available computer algebra systems The example just given can be treated as a member of (CAS). As well, such facilities have been gaining wider ac- the class of integral problems studied here. In this paper, ceptance within the user community. The presence of these we consider some classes of integration problems obtained facilities has altered the way CAS behave, and many estab- through the composition of continuous functions and signum lished areas of symbolic computation need to be reconsid- functions, or equivalents and discuss the implementations in ered. The topic of this paper is an example of the impact on both Derive and in Maple V. one traditional field of computer algebra, namely, symbolic The interest in this class of problems arises because func- integration. tions that have piecewise definitions are widely used in engi- Because the early versions of many present-day CAS neering, physics, and other areas. Such functions are often could not record the domain of a variable, they assumed constructed explicitly by users of CAS to represent discon- that the variable was complex. In particular the problem tinuous processes. They can also appear as the result of f(x) dx was usually interpreted as requiring the evalua- algebraic simplifications performed by a CAS on an inte- grand, even if that integrand contained no signum functions tion of a complex integral, valid for x C. This immedi- atelyR ruled out the possibility of formulating∈ problems such explicitly when first presented. An important feature of the as x dx, because the is not dif- computations discussed here is the fact that they ensure that ferentiable| | in the . With domain information the expressions obtained are valid on domains of maximum available,R it is possible to specify an integration problem extent. We remark that functions equivalent to signum are sup- ported by all the major CAS. However, the support takes f(x) dx for x R , ∈ various forms and the definitions used by the different sys- Z tems are not completely equivalent. Examples include the and one consequence of this is the possibility that the above function in Derive, the signum and piecewise func- problem may have a different answer from the problem tions in Maple V and the UnitStep in Mathematica.

f(x) dx for x C . ∈ 2 Definitions of functions Z For example, consider the integral The signum function is defined differently in each of the ma- jor CAS. This is not really surprising given that different ar- 1 eas of mathematics also use different definitions of a signum 3x2 1 + dx . x2 function. However, these disagreements do not affect the Z r integration question, and a discussion of variations would 3 Definition of integration only distract attention from the main problem. Therefore one particular definition, and a specific unambiguous nota- The example in the introduction showed that different defi- tion, is used here, so that the issue of variations in defini- nitions of integration are possible. Therefore it is necessary tion does not intrude on this discussion of integration. A to define the integration problem and verify the existence of signum function Snn : R R that is 1 for all non-negative a solution. real numbers, briefly an n-n→ signum, is defined by Definition 1. Let f : [a, b] R be a function that is con- → b b b tinuous except at the n points D = x1 , x2 , . . . , xn where 1 , for x 0, b { } S (x) = (3) xi [a, b]. The function f is then piecewise continuous on nn 1 , for x ≥< 0. ∈ b ½ − [a, b], and the points xi are the break points of f. 2

Notice that Snn(x) is antisymmetric only on R 0 . Some \{ } Definition 2. If the left and right limits of a piecewise comments on the implementation of this definition will be f separately exist at a break xb, made below. then xb is called a bounded break point of f, otherwise it is The functions absolute value and Heaviside step are also called an unbounded breakpoint. 2 defined in terms of Snn by

1 1 Remark 1. A bounded break point is also called a jump x = xSnn(x) and H(x) = + Snn(x) . (4) | | 2 2 discontinuity. There is a possibility that the terms bounded The characteristic function χ of a closed interval [a, b] R and unbounded will be taken to refer to number of break- ⊂ is defined also in terms of Snn: points rather than the behaviour of the function at a par- ticular breakpoint; in the former case it is the set D that is 1 1 χ(x, [a, b]) = Snn(x a) + Snn(b x) . (5) bounded or not, rather than the point itself. 2 2 − 2 − b Notice that this definition implies that a point function, non- If xi is a bounded breakpoint of f, then we denote the b b b zero only at a point a, can be defined as χ(x, [a, a]). It is left and right limits of f at xi by f(xi ) and f(xi +). In also useful to define the characteristic function of an open the case of bounded breakpoints a continuous− integral always interval ]a, b[. exists.

χ(x, ]a, b[) = χ(x, [a, b]) χ(x, [a, a]) χ(x, [b, b]) . (6) − − Theorem 1. Let f : [a, b] R be a piecewise-continuous For semi-infinite intervals, the χ function reverts to one function with a set D of bounded→ breakpoints. There exists equivalent to Snn. a function g, called an integral of f on [a, b], written An alternative to signum functions has been introduced by Maple. Maple V release 4 defines the function piecewise f(x) dx = g(x) , (11) by Z f1 , c1 true, with the properties that g is continuous on [a, b] and g is 0 . . . differentiable on [a, b] D, where its is g = f. 2 piecewise(c1, f1, . . . , cn, fn, f) = (7) \  fn , cn true,  f, otherwise, Remark 2. If g1 and g2 are integrals of f on [a, b], then  g1 = g2 +K for some constant K. For on any open subinter- where the ci are Boolean expressionsof the Maple type re- b b val defined by successive breakpoints, namely ]xi , xi+1[, the lation and the fi are algebraic expressions. The relations ci functions differ by a constant, and one can write g1 g2 = are evaluated in order from left to right, until one is found − Ki. Since g1 and g2 are separately continuous at each break- to be true. In terms of this function, Snn is point,

Snn(x) = piecewise(x < 0, 1, 1) . (8) b b − Ki = g1(xi+1 ) g2(xi+1 ) − − − b b Since piecewise is more general than signum, the converse = g1(x +) g2(x +) = Ki+1 . (12) i+1 − i+1 is more lengthy. Let condition ci be true on a union of disjoint intervals Ii = Iij , where each Iij R, and let 2 j ⊂ Ji = Ii k