Simplification of Radical Expressions

by

B. F. Caviness (I) Computer Science Department lllinois Institute of Technology Chicago, lllinois

and

R. J. Fateman Computer Science Division Department of Electrical Engineering and Computer Sciences University of California at Berkeley Berkeley, California

Abstract As is the case with all simplification problems there are three desirable attributes for In this paper we discuss the problem of any solution. First it is desirable to have a simplifying unnested radical expressions. We clean theoretical solution to the problem. Second describe an implemented in ~CSYMA that the to carry out the simplifications simplifies radical expressions and then follow should be as efficient as possible, and finally the this description with a formal treatment of the solution should have good human engineering features, problem. Theoretical computing times for some of i.e., the use and actions of the simplification the algorithms are briefly discussed as is related procedures should be as natural and transparent as work of other authors. possible. Unfortunately these three aspects of a solution are not usually compatible with each other I. Introduction and compromises and choices must be made. This is certainly the case for the simplification of radical In this paper we discuss the problem of expressions. Standard techniques from the theory simplifying unnested radical expressions. By of algebraic field extensions can be used to get a radical expressions we mean, roughly speaking, nice theoretical solution to the problem. However sums, differences, products, and quotients of the nice theoretical solution neither leads to fast rational functions raised to rational powers. algorithms nor possesses nice human engineering Thus we will be discussing algorithms for carrying features. out transformations such as The theoretical solution involves finding an _x_z_J{ ÷ algebraic extension field of Q(x I ..... Xn), the field /x+/y /x - /y (1) of rational functions in x I ..... x n with coefficients (x-I)~ (x-I)3/4 in Q the field of rational numbers, to which the • - ¢2 ÷ o (2) (l-x) ~ (l-x) 3/4 given radical expressions belong. In the algebraic extension field each element can be represented and 1/(x+/2+32/3) ÷ uniquely and this unique representation can be considered to be the simplified form for the given [((2x3-4x-g)/2 -x 4 -9x + 4)32/3 expression. Thus for example +((-9x2-6)¢2 + 3x3+ 18x + 27)31/3 2~+3½[-(x2+I)]I/3 (4) +(-x4+4x2+18x-4)/2 + x 5 -4x 3 + 9x 2 + 4x + 18] (x2+l) ½ /[xS-6x4+18x 3 + 12x 2 + 108x + 73]. (3) is a member of the field Q(x)[m6,2~,3½,(x2+l)I/6 ].

We will primarily consider only expressions in Each element of this field may be uniquely repre- which the rational exponentiation is unnested, sented in the form that is, like those expressions in (I), (2) and ~o+~I(X2+I)I/6+...+ ~5(x2+I) 5/6 (5) (3) above as opposed to expressions like [(x+l)~+(x-l)½] ½ in which the is where ai is in Q(x)[w 6, 2~, 3½]. In particular nested. (4) may be written in the form (5) and is thus (I) Present address: Department of Mathematical Sciences, Rensselaer Polytechnic Institute, Troy, (61 N.Y. 12181

Proceedings of the 1976 ACM Symposium 329 on Symbolic and Algebraic Computation However from a human engineering point of view (4) description of the algorithm that is used in would usually be more desirable than (6). Further- MACSYMA for the simplification of expressions more, to find the extension field of Q(x) to which containing radicals. The algorithm which is called (4) belongs requires that one verify that the RADCAN, an acronym for RADical CANonical simplifier, polynomials Y14-2 and Y22-3 are irreducible over was implemented by Fateman [Mat 75] and was initially available in 1970. In our discussion we will con- Q(x)[~6] and Q(x)[~ 6, 2~] respectively. In general centrate on RADCAN's handling of radicals although such polynomials have to be factored over algebraic the program has the capability to handle a larger extension fields. Currently no efficient class of functions. More information about RADCAN algorithms are known for factoring polynomials over can be found in [Fat 72]. algebraic extension fields although recently Wang [Wan 75] and Weinberger [Wei 76] have reported Programs with purposes similar to those of some progress on finding such algorithms. RADCAN have been written by Fitch [Fit 71 and Fit 73] for CAMAL, by Shtokhamer [Sht 75a and Sht 75b] In section 2 the MACSYMA algorithm for for REDUCE, and by Jenks [GJY 75] for SCRATCHPAD. simplifying radical expressions will be presented. In particular the compromises that were made to RADCAN attempts to convert an arbitrary try to balance the clean theoretical solution with expression containing radicals, exponentials and the efficiency and human engineering problems will logarithms into a simpler form. The result pro- be discussed. duced by RADCAN can be in various forms depending on which options are chosen. There are three In simplifying radical expressions there are options: (i) an option to produce the result in other problems which must be confronted. For form 1 or form 2, (ii) an option to rationalize example what does the symbol ~x mean? The square denominators, and (iii) an option to combine pro- root function is multi-valued. Which branch, if ducts of expressions raised to the same fractional any, does the s~mbol /x represent? Also, what do power. symbols like /x z mean? Is this to be taken as -x, x or Ixl? To answer these questions precisely With the form 1 option, all polynomials requires a careful discussion as is given in appearing under radicals are factored into irreduc- section 3. Roughly speaking the answers are that ibles, i.e., prime integers or polynomials irreduc- ~x can stand for either of the single-valued ible over the integers. With the form 2 opti.on, branches of the "square root function without the polynomials appearing under radicals are affecting the way the arithmetic and simplifica- factored into square-free, pair-wise relative prime tion is carried out. The ambiguity in the symbol factors. /x 2 is inherent and an arbitrary choice must be made to resolve it. The choice of Ixl for this For examRle with the form 1 option RADCAN symbol would lead to certain difficulties that we do not consider herein. In section 3 one precise way is given that changes ~x 2 into x. With suitable modifications the same ideas could be used to change it into -x. Basically what is done in section 3 is to give a set of rules that ii!ii!zii!ii!i!ii!iiiii! iiii!ileiii !'iiii e iil transform ambiguous expressions into non- transformed into (x+3)(x+l)2(x+2) + (x+2) ambiguous ones. The rules given there are not under either the form 1 or form 2 option. The the only ones that can be given but the important dinstinction between form 1 and form 2 is discussed point is that the ambiguities must be resolved further in section 3. and the rules for resolving them should be clearly stated. Section 3 also contains a description With the rationalization of denominator option of the algorithm for finding a common algebraic the expression (x-y)/(/x-/y) will be transformed extension field to which a given set of radical into /x+/y. Otherwise it is not transformed. This expressions belongs. option will also produce the transformation (3) above. In section 5 a brief discussion of theoreti- cal computing times for some of the algorithms Option (iii) is used in the final step of of section 2 and 3 is presented. Section 5 RADCAN to determine whether or not expressions like follows section 4 in which some theorems that show /2 /3 should be rewritten as /6. a priori the irreducibility of polynomials like Except for expressions involving roots of y14-2 and y22-3 over certain algebraic extension unity, RADCAN with the form 1 and rationalization fields. This knowledge simplifies and speeds- of denominators option is a canonical form [Cav 70] up the algorithms for finding the extension fields. for the unnested radical expressions.

In section 6 an alternative approach to With the form 2 option any unnested radical finding field extensions, based on the so-called expression equivalent to zero which does not theorem on the primitive element ~dW49], is involve roots of unity will be transformed to zero. discussed. This section also contains a review The form 2 option requires less computation than of other related research. the form 1 option since finding square-free, pair- wise relatively prime factors for non-constant 2. The MACSYMA Algorithm RADCAN polynomials is much easier than finding irreducible factors. In this section we present an informal

330 Experience with MACSYMA has indicated that it If appropriate, phase 3 also carries out op- is not generally desirable to automatically invoke tions (ii) and (iii), in this order. the rationalization of denominators option because simple expressions like the left-hand side of (3) The three phases of simplifying an expression are frequently transformed into complicated expres- S may be further subdivided as follows. sions like the right-hand side of (3), I. First Phase As will be explained later to reduce zero- equivalent expressions involving roots of unity to I. Make a list R of all distinct radicals in zero, requires in general the factorization of the expression S. Collect the distinct radicands, polynomials over algebraic number fields, a task i.e., polynomials appearing under radicals, on a for which no efficient algorithms are known. So list P. one of the compromises made in RADCAN was not to handle algebraic relationships involving roots 2. For each radicand Pi on P of unity in a completely general way to avoid such (i) If Pi is an integer, factor it com- factoriza~gn probl~m~. Thus RADCAN will not re- pletely, placing the distinct prime factors on a duce (-I) I/~ - (-l)J/~ - (2) 1/2 to zero. Although list B, the basis list. Only factors of Pi not this is an expression that is unlikely to occur in already on B are placed on B. So B always contains practice, roots of unity do get introduced in at most one instance of an element. natural,ways since, for examole, RADCAN transforms (-x+l)E/~ into (-I)I/4 (x-l)I/4. (ii) If Pi is a polynomial of positive degree, factor it into factors irreducible over the The RADCAN algorithm consists of three basic integers for the form l option or into square-free phases which, depending upon the expression being factors for the form 2 option. For the form l simplified, may have to be repeated. The first option place all irreducible factors not occurring phase is a global pass through the expression on B thereon. In the case of the form 2 option let collecting the set R of all subexpressions which Pi* denote a square-free factor of Pi. If Pi* ~s are radicals, exponentials, or logarithms. From relatively prime to each element on B, place Pi on R is generated a basis B in terms of which the B. Otherwise there exist some Pi on B with elements of R can be represented. If R consists of gcd(Pi*,P i) = C ~ I. Remove P~ ~rom B and replace only radicals, B is generated by factoring the it with the two factors C and ~P~/C). If C : Pi ~ polynomials that appear under the radicals. The then repeat the process on the n~xt square-free particular set B that is generated depends on which factor of Pi. If• C ~ Pi* then replace. P.*l by Pi*/C option, form 1 or form 2, is taken. and repeat the immediately precedlng procedure for Pi*. After B is generated, appropriate radicals of the elements of B are considered as new variables At the completion of phase 2 B will and the original expression is represented in terms be a list of polynomials of non-negative degree of the new and original variables. which are square-free and pair-wise relatively prime. Under the form 1 option each element on B will also be irreducible. In the second phase standard rational func- tion simplification procedures such as expansion, 3. As step 2 processing takes place, each collection of terms over a common denominator, radical on the list R is constantly updated to re- and removal of greatest common divisors are flect the changing representation of each of the applied to the arguments of any imbedded non- original radicals in terms of the latest basis B. rational functions as well as to the expression as a whole. In this phase the radicals are con- 4. Associated with each element on B is a sidered simply as new independent variables. All radical degree. If, for example, x+l is on B and knowledge of algebraic dependence is submerged. the only occurrences of x+l in the radicals on R The third phase reimposes the interpretation are (x+l)I/3 and (x+l)2/5 then the radical degree of the variables as radicals. The transformation of x+l is 15 = ~cm(3,5). As B changes in step 2 ( I/a)b ÷ mq(ml/a)r is applied for each radical the radical degrees must be revised also. In the above example (x+l)I/3 and (x+l)2/5 are repre- ml/a with b > a where b = qa + r, 0 ~ r < a. sented in terms of a new variable vj = (x+l)I/15 Thus (21/6)7-would be changed to 2(21/6). If this transformation is applied to any radical in the as vj 5 and vi 6 respectively. In the case the base expression, the expression must be rationally is -l and the radical degree is m, the dis- simplified again. Furthermore if the expression tinguished indeterminate ~qn = ei~/m is introduced. contains nested radicals then the above trans- formation can change nested radicals to unnested II. Second Phase ones. A contrived example that illustrates this possibility is At this point the expression S is considered as a rational function in its original variables (x 2 + 3x + 3 + (x+l)I/2(x+l)I/2) I/2. After and a set of new variables obtained from the phase l and phase 2 the expression would be in the elements on B and their radical degrees. S so form (x2 + 3x + y2 + 3)I/2 where y = (x+l)I/2. The considered is rationally simplified. phase 3 transformation changes yL to x+l and then the reapplication of phases l and 2 simplifies the III. Third Phase original expression to x+2 after which no further changes are made. The algebraic properties of the new variables are reintroduced. If any reductions are achieved

331 each of the three phases must be repeated. 3. Theoretical Issues

A well-known general procedure [Pol 50, p.38] In this section we formally define the concept for rationalizing denominators is based on a of a radical expression in both a syntactic and se- straightforward application of the extended mantic sense, give formal procedures for simpli- Euclidean algorithm [Knu 69, p.377, exercise 3]. fying and performing arithmetic on radical expres- We will explain the algorithm by an example. To sions, and discuss the relationship between the rationalize the denominator we merely need to find formal presentation and the previously discussed its inverse. So to rationalize the denominator in algorithm RADCAN. (3) we find ~ inverse of x+/2 + 32/3 . We consi- der x+/2 + 3L/~ as an element of the field Radical expressions are rational roots of Q(x)[/2, 31/3] which is isomorphic to the polynomi- polynomials, rational functions, and other radical al rino Q(x)[yl,y2] modulo the ideal generated by expressions. They are built up from: y12-2=0 and y23-3=0. Now y12-2 is irreducible over (i) the field Q of rational numbers, Q(x) and y23-3 is irreducible over Q(x)[/2]. Thus (ii) the variables x.,x ...... x , we2consider x+~2 + 32/3 as the polynomial and (iii) the operations ~f ~dditioB, subtraction, Y2 + (x+/2) in the variable Y2 with coefficients multiplication, division, composition, in Q(x)CV2]. W~ apply the extended Euclidean and rational exponentiation. algorithm to Y2 + (x+~2) and y2J-3 to find poly- nomials S(yp) and T(yp) with coefficients in We will restrict our attention to unnested Q(x)[V2] such that - radical expressions, i.e. expressions like ((x 2 + 2x) I/2 + 5) 273 wil~ not be considered fur- S(Y2)[Y22 + x + ~2] + T(Y2)[Y23 - 3] = a ~ 0 (7) ther. Shtokhamer [Sht 75b] has recently discussed where a is also in Q(x)[~2]. ~e are guaranteed one way in which these ideas can be modified and that a is in Q(x)[~2] since Y2 -3 is irreducible extended to cover nested radical expressions. and hence cannot ~ave a factor of positive degree in common with y2 L + x+/2. Given a radical expression such as ((x 2 - l)/(x + 2))I/2/(x + 3x + 2) I/3 (9) If we consider (7) modulo y23-3 as we should since yp is just another symbol for 31/3 and hence we wish to interpret it as a single-valued branch y2~-3=0~ we have that S(Y2)[y22 + x + /2] = a ~ O. of a meromorphic function in an algebraic extension l of the field Q(x I ..... Xn) of multivariate rational Thus Y2 + x + W2 = ~S(Y2) Furthermore the S and functions over Q. Since in general there are a number of single-valued branches that might reason- T produced by the extended Euclidean algorithm will ably be associated with an expression like (9) we have degrees in Y2 at most 2 and l respectively. would like to interpret (9) in as general, but yet In this example SLY2) = -(x+/2)-ly22 + as natural, a way as possible. 3(xZ + 2~/2x + 2)-iy2 + 1 and a = x + ~2 + There are two different aspects to the in- 9/(x ~ + 2~/Zx + 2). Thus terpretation problem that are intimately related l = + ( )31/3 + to the way that we simplify and perform computa- x + ~2 + 32/3 tions with radical expressions. It is important (B) that these two different aspects be clearly x 2 + 2~2x + 2 distinguished. D The first aspect of the problem is to take a where D = (x + /2) 3 + 9 = (3x 2 + 2)~2 + x 3 + 6x+9. set of radical expressions and to find an algebraic extension field to which they belong and to find To obtain (3) we must rationalize D with the representation of the expressions in this respect to ~2. To do this we again apply the ex- extension field. The finding of the extension tended Euclidean algorithm, this time, to y~2_2 field and the representation of the expressions and D = (3x2 + 2)y I + x3 + 6x + 9 considered as within the field is the process that is frequently polynomials~in Yl= J2 qver Q(x). We find that referred to as "simplification of radical ex- I/D = [-(3x ~ + 2)~2 + xJ + 6x + 9]/E where pressions," and this is essentially the process that is carried out by RADCAN. E = x 6 - 6x4 + 18x3 + 12x2 + 54x + 73. The desired extension field is not uniquely In general we must apply the extended determined by the symbols ~or.~he radical ex- Euclidean algorithm at most one time for each pressions. For ~xample (xJ) I/J satisfies the algebraic extension. polynomial y~-x~O which ~as the irreducible factors y-x and y~ + xy + x ~. To do the This algorithm for rationalizing denominators arithmetic in Q(x)((xJ)I/3), i'e"3tb~3fieldl has been programmed for multiple algebraic number of rational functions in x with (x) / adjoinea,• extensions in the MACSYMA algebraic arithmetic we must know the irreducible polynomial of which system by Richard Zippel and Barry Trager. (xJ) 1/3 is a root and then perform arithmetic in the polynomial ring Q(x)[y] modulo the ideal ~e~ Examples of the use of RADCAN may be found in erated by the irreducible polynomial which (x~) I/j [MaF 71]. satisfies. We have two choices for the extension field: namely Q(x)[y]/(y-x) which is isomorphic to Q(x) and Q(x)[y]/(y L + xy + x~) which is not

332 isomorphic to Q(x). relatively prime members of Z[x I ..... Xn]. Z de- notes the ring of integers; r is a positive member Either of. the choices is a legitimate choice. of Q and r ~ I. If P2 = 1 then we write (PI) r. The first choice effectively gives us the simplifi- P1 and P2 are assumed to be relatively prime in the ca~iRD3(x3)I/33+, x3wher~as the second one qives strong sense that their only common divisors in Z (x~) L! + -x~x )I/ - x and the symbol (x3)I/3 are ±I. Henceforth we will always use relatively would not be rewritten or simplified at all. Of prime in this strong sense. Furthermore it is course one would normally take the first interpre- assumed that P2 is positive, that is, that its tation in this case, but there are other cases that leading coefficient is a positive member of Z. Let are not so obvious. For example should (x2)I/2 be P consist of all polynomials Pi,P2 where (Pi/P2)r considered as x or -x, i.e., should we choose y-x appears in R. or y+x as the irreducible factor of y2 - x2? Following Collins [Col 74] we define a basis So we conclude that there are choices to be for the set P of polynomials of degree ~ 0 to be a made, no one of which is more right than the set B of positive, square-free elements of other, at least from a mathematical point of view. Z[x I ..... Xn] satisfying the following three con- The important point is that the inherent ambiguity ditions: of these symbols must be realized and the rules chosen for the resolution of the ambiguities must (i) If B1 and B2 are distinct members of B, be stated clearly and careful. Of course the rules they are relatively prime. may be chosen by the system designer or they may be (ii) If B is in B then BIP for some P in P. left to the user. Below we describe the set of (iii) If P is in P, there exist Bi in B and rules that are used by RADCAN to resolve the am- positive integers ei such that biguities. These rules attempt to give as natural P = ± RBi ei . an interpretation as possible to the symbols. Note that our definition of basis differs slightly The second aspect of the interpretation from Collins'. His definition is only for a set P problem is illustrated by the following simple containing primitive polynomials of positive degree example. Suppose we have resolved the previously in xn. In our definition the elements of P are discussed ambiguities and have found that our neither required to be primitive nor to be of radical expressions belong to the^field Q(x)[~x] positive degree in any variable. which is isomorphic to Q(x)[y]/(yL-x). What does ~x mean? From a general point of view, it is a Let B be a basis for P. In finding an multivalued function so when we evaluate it at algebraic extension of Q(xI ..... Xn) to which each x = 4, either +2 or -2 is a legitimate value. element (Pi/P2) r of R belongs we impose the If we want to interpret it as a single-valued following rules to resolve the inherent ambigu- branch which branch do we choose and what dif- ities: ference does it make? The answer is that it does (i) (Pi/P2) r = Plr/P2 r. not make any difference which branch we choose when (ii) we are doing the field operations of addition, If Pl(or P2) = +~Bi ei where each Bi subtraction, multiplication, and division. That is in ~ and each e i is a positive in- is, if we take two functions from Q(x)[Jx] such as teger, then P1 r = ~Bi eir. If P1 = (xI+~)Jx + 1 and (2x2 - 2)~x + x and perform a field -~Bi ei, tiLen P1 r= (-l)r~Bi eir operation on them such as multiplication the (iii) Suppose r = s/t where s,t are positive, relatively prime members of Z. If answer will be ( 2x3 + 2x2-x-2)~x + 2x2_x no s = qt + v, 0 ~ v < t, then Br = x+l BqB v/z for m in ~. Also (-I) r matter which single-valued branch we choose for the (-l)q(-l)V/t. interpretation of ~x. These assumptions imply that ~x 2 = W(-x) 2 = (x3) I/3 Once we have chosen the algebraic field ex- = x and similarly resolve other inherently am- tension to which the expressions belong, there is biguous expressions. no longer any ambiguity in carrying out the field operations. The answers depend on the symbols Given R and assuming (i) - (iii) above, we alone and not on the interpretations. When other find an extension field to which each member operations such as evaluation and substitution are (Pi/P2)r~R belongs by the following procedure: performed the expressions may become ambiguous (a) Using (i) above, each element of R, again. We will have more to say about these two operations later in this section. (Pi/P2)r, can be written as a quotient of radical polynomials of the form Pir/P2 r, P1 and P2 are The foregoing should be considered as an in- called radicands. Form the set P of all distinct troduction to the rigorous discussion that follows. radicands. We first give a set of rules for resolving the (b) Compute a basis ~ for the set P. inherent ambiguities discussed previously along with a procedure for finding the field extensions (c) Using the properties of a basis and to which a finite set of radical expressions be- (ii) and (iii) above, each Pl r and P2 r can be longs. So we assume we are given a finite set of uniquely expressed as a product of integer and radical expressions. The expressions are scanned fractional powers of members of B~{-l}. and a set of radicals R is formed where each (d) For each B in ~ let sl/t I ..... sk/t k be member of R is of the form (PI/P2) r with Pl and P2 the reduced rational powers to which it appears

333 after the steps (a) - (c) are carried out for each positive degree square-free factorization is much member of R. Let t = Lcm(t I ..... tk). If k = O, faster than factoring the polynomials into irre- t = I. Then every element of R belongs to the ducible factors. See Yun [these Proceedings, pp. algebraic extension field F obtained by adjoining 248-259] for square-free factorization algorithms. all the BI/t to Q(x I ..... Xn). may be refined into a square-free basis if For example if R = {(2/3)I/3,(x+I)I/2, for each pair Bi,B2 in g with gcd(Bi,B 2) : C ~ 1 we (2-2x2) I/2} then P = {2,3,x+l,2x2-2}i/2 replace B1 and B2 by the non-units among (Bi/C), (B2/C), and C. This process must be repeated until B = {2,3,x+l,x-l} and F = {Q(x)((-l) ,2 I/6 ,31/3, the elements of g are pair-wise relatively prime at (x+l)1/2,(x-l)1/2)}. which time we will have the desired basis B. All of these operations can be carried out fairly To do the arithmetic in F in a canonical efficiently with the exception of computing square- fashion we must know the minimal polynomial M(y) free factors of integers. The only method known satisfied b~ each bI/t. Of course M(y) will be a for computing square-free factors of integers is to factor of y~-B. In the examRle above we must know completely factor them into primes. The best of the the irreducible factors ~f yL+l over F0 = Q(x), the known algorithms for factoring an integer requires irreducible factors of y^-2 over Fl = F0(i}~ the time that is exponential in the length of the in- irreducible factors of y~-3 over F2 = Fl(21/b), the teger. irreducible factors of.y z ~ (x+l) over_F3 F2(31/3), and the irreauciDle Tac~ors uf y - (x-l) With the form 1 option RADCAN computes a basis over F4 = F3((x+l)I/2). in which each element is irreducible. With the form 2 option RADCAN computes a basis in which the In general to find the required irreducible integers are prime and the polynomials of positive factors of the jth such polynomial it is necessary degree are square-free and pair-wise relatively to factor it over Fj-I. As was mentioned earlier, prime. Wang and Weinberger-have recently discussed algorithms for factoring over algebraic number This ends our discussion of the first aspect fields and van der Waerden [vdW 49] presents an of the interpretation and simplification of radical algorithm for factoring polynomials over an alge- expressions. We still need to give an intrepreta- braic extension of the field Q(x I ..... Xn). How- tion for the symbols that describe the algebraic ever, except for special cases, these algorithms extension fields found by the above procedure. are quite slow. This has been done precisely and elegantly by Fortunately in most cases the pure polynomials R. H. Risch [Ris 69a] for univariate functions. that arise can be proved irreducible a priori and For simplicity we also shall specify interpreta- in such cases no factoring has to be done at all. tions only for univariate functions. Interpreta- One case in which the pure polynomials can be re- tions for multivariate expressions can be specified ducible is when the degree t is even, B is an in- in a similar way. See, for example [Eps 75, teger, and a has been adjoined to pp.161-163] for an interpretation of multivariate the field in which the coefficients of the faGtor exponential and logarithmic expressions. must lie. For example y2 _ 2 = [y - (~8 - ~8J)] Suppose S is a list of symbols and let E(S) be [Y + (m8 - m83)] since m8 - m83 = ~2 where m8 is the smallest set of expressions containing the the primitive eighth root of unity e i~/4. In elements of S with the property that whenever a,b RADCAN, it was decided not to attempt such factori- are in S, so are a + b, a - b, a * b and a/b. For zations in order to make the algorithm faster. our purposes S is always of the form S = (I, x, Hence, as was discussed in the previous section Y1 ..... Ym) where m ~ O. For each Yi there is a Pi RADCAN does not handle expressions involving roots in E((l,x)) and an r i in E((1)) such that Yi is the of unity and even roots of integers in a completely general way. The theorems on the irreducibility symbol Pi ri. Roughly speaking, E((1)) denotes of the pure equations are presented in section 4. rational numbers and Pi ri denotes a polynomial raised to a rational power. E(S) is a special case Let us return to step (b) in the above pro- of Risch's elementary field descriptions and shall cedure. In general, given P, there are many sets B be called an aloebraic field description. An that form a basis for P. For example if P = {24, interpretation of E(S) Ts a pair (Mer(A),l) where x4+6x3+13x2+12x+4,x2+2x+l} then {24,x2+4x+4,x2+2x+ Mer(A) is a field of single-valued algebraic I}, {6,x+2,x+l} and {2,3,x+2,x+l} are all bases for functions which are meromorphic on an open, con- P. The extension field found depends not only on nected subset A of the complex plane. I is a the rules (i) - (iii) but the basis B also. In mapping from a subset of E(S), namely that subset order for the irreducibility theorems to apply the of expressions with a well-defined interpretation, elements of B must be square-free and pair-wise onto Mer(A) such that relatively prime. A basis in which each element is square-free is called a square-free basis. But (i) I(1) is the constant function l; even a square-free basis is not necessarily unique. (ii) I(x) is the identity function on A; (iii) For each Yi symbol pr, let s/t = I(r) There are two natural ways to compute a square- where s and t are relatively ~ me in- free basis. One way is to let B consist of all the tegers with t > 0. Then I(yi) -i distinct irreducible factors of elements in P. A I(P) s = 0. If I(Yi) z - I(P) s is the second way is to compute a set B of all square-free monic irreducible equation satisfied factors of elements in P. For polynomials of

334 by I(Yi) over Q(I(x), I(Yl) ..... I!Yi_1)) real interpretations of Fateman that are used in then E(S) is regular; otherwise E(S) is MACSYMA. non-regular. (iv) If a and b are in the domain of I, so 4. Irreducibility Theorems for Pure Polynomials are a + b, a - b, and a * b. If I(b) ~ O, a/b is also in the domain of In this section we present the irreducibility I. Furthermore, I(aob) = l(a)oI(b) theorems for the pure polynomials discussed when aob is in the domain of I and o is earlier. The first theorem tells us that ym _ p, one of +, -, *, or /. p a prime integer is irreducible over any algebraic number extension of Q(x) obtained by adjoining A regular algebraic field description E(S) has roots of other prime integers. It is important the desirable property that all interpretations of that roots of unity not be contained in the exten- it are differentially isomorphic (see [Ris 69a], sion field for then the result is false as was p.176, proposition 2.3 for a proof of this fact). sbowQ by the example in which y2 _ 2 factors when This is the previously alluded to mathematical re- e I~/~ is in the extension field. sult that means for computational purposes all re- sults of performing field operations and differ- Theorem I. Let m be a positive integer, ~}~ .... Pk entiation on the elements of E(S) are independent dis~t positive prime integers. Let Pi of the interpretation, i.e., independent of the deno~ an mth rQot of Pi. Then tee field single-valued branches of the multi-valued func- Q(pl I/m ..... pk I/m) is of degree m~ over Q. tions chosen. For a proof of this theorem see [Fat 72, pp. Normally it is not necessary to distinguish 135-140] or [Ric 74]. the interpretation of a symbol from the symbol itself and we shall not do so henceforth. Corollary 2. Let mI ..... mk be positive integers; Pl .... ,p~ be distinct positive prime integers; and Let us now consider the problem of substitu- let pi I/~i denote an mith root of Pi. Then tion in a radical expression, i.e., we are given a m m m radical expression f(x) and a polynomial P(x) and y k_pk is irreducible over Q(Pl l ..... pkk~l). we wish to substitute P(x) for x in f(x) to obtain f(P(x)). When P(x) is a constant we have the Proof. Let m = Lcm(mI ..... mk). By theorem l evaluation problem. ym_ Pk is irreducible over G = Q(pl m..... P~-l) ml We restrict ourselves to substituting poly- which contains F = Q(Pl ..... P ~l). Hence ym Pk nomials for x. If radical expressions are substi- cannot factor over F without factoring over G. | tuted for x we can obtain nested radical ex- pressions. Our restriction insures that f(P(x)) All examples known to us in which ym_p fac- will be an unnested radical expression. tors involve roots o~ unity with m even. It would be nice to know if v k_p~ factors over It is easy to see that one can obtain com- ~, 17ml i/~_i ' K. pletely general unnested radical expressions q~,Pl ''"'Pk-l" j wnere Pl .... ,Pk are dis- through the process of substituting in a multi- tinct primes, mk is odd, and, ~, mI ..... mk_ l are variate radical expression. Thus the substitution arbitrary positive integers. The next theorem process is equivalent to the simplification process provides a partial answer to this question. itself. Thus the interpretation of the symbol f(P(x)) can be given by our previous discussion Theorem 3. Let & be a positive integer, m an odd and the "value" of f(P(x)) can be computed by positive integer, and Pl ..... Pk be distinct applying our simplification process. In general positive prime integers. Then the field Q(m~, when evaluating f(P(x)) one already has an pl I/m ..... pk I/m) is of degree mk over Q(~) where algebraic extension F of Q(x) in which f(x) lies. It is only necessary to extend F and its corre- m& is a primitive cth root of unity. sponding basis to find an algebraic extension of F in which f(P(x)) lies. It is not necessary to For a proof see [Cav 68, pp.50-54]. The repeat the entire process of finding an algebraic three results above still hold under the weaker extension of Q(x) for f(P(x)). hypotheses that the Pi are square-free and pair- wise relatively prime. With this view of substitution and our pre- vious rules for resolving ambiguities and inter- If the hypotheses of theorem 3 are changed preting radical expressions, we have a generaliza- so that & is odd and m is any arbitrary po§itive tion of Fateman's positive real interpretation integer the result is false since ~5 = -2m~ - [Fat 72] of radical expressions. The interpreta- 2m~ - I. tion given herein effectively chooses the positive real branch for algebraic functions when the The final theorem tells us that in our radical expression is ambiguous as it may be algorithm ym_B(Xl ..... Xn) is always irreducible initially or as it may be after substitution. But where B is a non-constant polynomial in once the ambiguities are solved and the extension Q(x I ..... Xn). field found, the field operations can be carried out in a manner that is independent of the inter- Theorem 4. Let m be a positive integer, B] ..... Bk pretation. Thus there is no conflict between the be non-constant, square-free, pair-wise retatively regular field extensions of Risch and the positive prime polynomials in Q[x I ..... Xn]. Then the field

335 C(x I ..... Xn)(Bl I/m ..... Bk I/m) is of degree mk over non-constant elements of P without additional work. C(x I ..... x,) wbere C denotes the field of complex His algorithm as currently constituted actually numbers an~ Bi I/m denotes any one of the roots of computes the integer contents but ignores it. Thus the entire basis computation can be done i i ym _ Bi = O. ~ ~ ~ bounded by a function which is O(k I/2a +k a d 2 The proof in [Cav 68, pp.54-59] can be modi- (d+l) n+l) where k = max(kl,k2). fied in a straightforward way to give the above result. In [Fat 72, pp.135-140] a slightly weaker This computing time bound was obtained result is proved with C replaced by Q and with the assuming that the modular greatest common divisor added hypothesis that the Bi be positive or m be algorithm is used for gcd computations and that the odd. assumptions made by Brown [Bro 71] in analyzing the modular gcd algorithm hold. Theorem 4 has a natural corollary that is analogous to the corollary of theorem 1 and is In RADCAN's phase II rational simplification proved in the same manner. Hence we will not is performed on rational functions in n +~ vari- actually state it. ables where ~ is the number of elements in B. 5. Computing Times A set of integers, all bounded in magnitude by A, has at most ~og2A distinct prime factors. Thus In this section we present a brief discussion B contains at most a+l integers. If each polyno- of the worst case computing time of some of the mial in P should factor into distinct linear fac- algorithms involved in the simplification process. tors in B then B would contain at most k2nd non- The length of a non-zero integer n, denoted L(n), constant polynomials. ismzogzlnU +I . L(O) = I. Let Z[n,d,a] denote Thus the rational functions in phase II of the set of polynomials in Z[Xl, .... Xn] with degree RADCAN have at most k2nd + a + n +l variables. in each variable < d and the length of each integer Hence the time for the gcd calculation in this coefficient < a. phase, assuming the modular algorithm is used, is One of the major procedures in the simplifica- O((d+l) k2nd+a+n+l) assuming each of the polynomials tion process is the computation of a basis B for P, has degree at most d in each of the variables. the set of radicands. Suppose each element of P is in Z[n,d,a]. Hence one can see that the bounds for the worst case computing times for phases I and II of In [Eps 76] Epstein' presents carefully RADCAN grow very rapidly as a, n, d and k2 increase. analyzed algorithms for computing a square-free basis for polynomials with Gaussian integer co- Although these algorithms can require a lot of efficients. We assume straightforward changes to computing time in practice, experience with MACSYMA Epstein's algorithms and computing time analyses to indicates that RADCAN is a reasonable algorithm to the restricted case that we are considering, namely use for routine simplification of small expressions. polynomials with rational integer coefficients. In fact it was, at one time, a default preliminary step in simplifying single algebraic equations We have also defined basis in a slightly dif- prior to their solution by the SOLVE command ferent manner from Epstein - his definition ignores [Mar 7l]. constants. Thus for our purposes we can compute a square-free basis by first finding the integer con- 6. An Alternative Approach and a Review of tent and primitive parts of each of the non-constant Related Research polynomials in P. Let ~l - the set obtained by the union of the constants In P and the integer con- As is well-known each multiple algebraic ex- tents of the non-constant members of P. Let P2 tension field of Q(x) can be expressed as a single be the set of primitive parts of non-constant mem- extension. This statement is known as the theorem bers of P. Let Bl be a basis for Pl and P2 be a on the primitive element [vdW 49]. From van der basis for B2. Then BiuB2 will be our desired Waerden's discussion algorithms can be constructed basis for P. Assume the elements of Pl and Pp are to find an element ~ such that Q(x)(B) is isomor- in Z[n,d,a] and that Pl contains kI distinct Tn- .phic to Q(x)(el ..... en) where e I ..... en are alge- tegers while P2 contains k2 distinct polynomials. braic over Q(x). Loo~[Loo 73] also discusses con- Then Bl can be computed by factoring each element structive aspects of the theorem on the primitive into prime factors which can be done in.%ime element in relationship to performing arithmetic in bounded by a function, which is O(k-. l 2 a/z). The the field of all algebraic numbers. best known algorlthms for factoring integers have somewhat better computing time bounds but they still So since the theorem on the primitive element require time that is an exponential fuq~tion of a. can be constructively implemented, why use multiple Hence we will be content with the 0(2 a/L) bound. algebraic extensions when one would do. There seem to be at least two reasons for not simplifying Epstein's algorithms will compute B2 in time radical expressions via the approach suggested by bounded by a function which is the theorem on the primitive element. First it seems likely, although there has been no definitive O(k23a2d3/2(d+l)n+l). Furthermore Epstein's study to verify it, that multiple algebraic exten- algorithm GPPSQF (Gaussian Polynomial Primitive sions of lower degree lead to faster algorithms Square-Free Factorization) can be trivially modi- than would one extension of high degree. The de- fied to provide the desired integer contents of the gree of the one extension would be the product of

336 the degrees of the multiple extensions. M. N. Huxley, of the fact that (I +x) l+x is tran- iscendental over Q(x). This result also follows Secondly multiple algebraic extensions seem to from the more general structure theorem of Risch possess better human engineering attributes than [Ris 6gb]. extensions obtained through the theorem on the primitive element. For example the field Q(~3, ~5) Rubald [Rub 73] developed algorithms for poly- is contained in the field Q(a) wher~ a satisfies nomial arithmetic over real algebraic number fields the irreducible polynomial M(a) = a~- 16a +4. In .Q(a) where the extension is simple. His algorithms Q(a),J3 is written as I/4(a j-14a) which from a do not require an irreducible defining polynomial human engineering point of view is generally less for a. He also presents an algorithm for deter- desirable than simply ~3. mining if ~ < B where ~ and B are real algebraic numbers. Such a determination is dependent on the So for these reasons replacing multiple alge- particular root of the defining equation joined to braic extensions by a single extension seems un- Q and could not be realized by the methods dis- desirable. cussed here.

There have been a number of other papers Recently Shtokhamer has written on matters re- written that are related to our discussion in one lated to the work of Kleiman [Sht 75a] and on the fashion or another. We will give a brief discus- simplification of nested radicals [Sht 75b]. In sion of the related work. Much of it has already [Sht 75a] he claims to have developed algorithms been mentioned in the preceding sections. First it for finding unique representatives of equivalence should be noted that the present paper is based on classes of R[xI ..... Xn] modulo an ideal where R is the authors' Ph.D. dissertations [Cav 68] and a Noetherian domain. In [Sht 75b] he generalizes [Fat 72]. the methods given in the authors' dissertations to apply to nested radical expressions. His algo- Many papers have been written on various rithms are programmed in REDUCE. aspects of algebraic simplication. We will dis- cuss only those that treat algebraic numbers and M. Lauer [Lau 76] brings together the algo- algebraic functions. For an overview of other as- rithms of Shtokhamer [Sht 75a] and an earlier pects of simplification up to IgTl, see the paper algorithm of Buchberger [Buc 70] to solve the prob- by Moses [Mos 71]. Further much of the material in lem of finding canonical representatives for the classical modern on algebraic extension equivalence classes of S[x I ..... in] modulo an ideal fields is relevant to this work. van der Waerden when S is either a field or a prlncipal ideal [vdW 49] contains a treatment of this material with domain. many algorithmic methods given. The recent paper by Wang [Wan 75] reports on The first significant paper to deal explicitly the progress of a program to factor polynomials with simplification of algebraic functions was an over algebraic number fields. While efficiencies unpublished Bell Laboratories report by S. L. may be realized in special cases, the general Kleiman [Kle 66]. Kleiman considers some problems computational intractability has not been resolved. that are closely related to the problems considered here. He assumes that he is given a set of ir- Although the irreducibility theorems of reducible algebraic equations that define the alge- section 4 may have been known to some members of braic dependencies among the variables involved. the mathematical community for many years, the Thus he avoids discussing the problem of trans- first published results appeared in 1940 [Bes 40] forming a set of radical expressions into a set of when Besicovitch proved Theorem I. In 1972 pure polynomials and the factoring of such polyno- [Fat 72] Fateman gave an independent proof of mials over algebraic extensions of Q. However, theorem I. In 1968 Caviness [Cav 68] presented his paper is precisely written, contains interest- theorems 3 and 4, and in 1974 Richards [Ric 74] ing ideas, and should be more widely available and published theorem l and theorem 3 for even ~. better known. For example, if the polynomials gen- erate a prime ideal, Kleiman's results construc- Acknowledgments tively refute Loos' [Loo 74] conjecture that given a set of polynomial equivalences, there does not The authors wish to thank their colleagues at exist a canonical form for a polynomial under these Berkeley, MIT, the University of Wisconsin, and relations. Bell Telephone Laboratories for stimulating dis- cussions. This work was supported in part by Fitch [Fit 71] discusses the general problem Project MAC, an MIT interdepartmental laboratory of algebraic simplification. From his work in sponsored by the Advanced Research Projects general relativity in which unnested radical ex- Agency (ARPA), Department of Defense, under pressions occurred extensively he was lead to con- Office of Naval Research Contract NOOO14-70-A- sider in some detail the problem of simplifying 0362-0001. One author (RJF) was supported, while radical expressions. His solution has much in a graduate student, by ARPA under Air Force con- common with the methods described in this paper tract F19628-68-0101 with Harvard University, by although he neither discusses interpretations of the National Science Foundation under their radical expressions nor deals with the problems Graduate Traineeship program and by Bell Telephone associated with roots of unity. Laboratories under a contract with Harvard Univer- sity. The other author (BFC) was supported, while The more accessible [Fit 73] covers much of a graduate student, by the National Science the same ground as [Fit 71]. In addition it con- Foundation, in the form of a graduate fellowship. tains a simple proof, which he attributed to Professors Alan Perlis of Yale University and

337 Henry Leonard of Northern Illinois University made [Knu 69] D. E. Knuth, _The Art of Computer Pro- valued contributions to this work. The comments of gramming, vol. 2 "Semi-numerical Algorithms," John Fitch, Peter Weinberger, and the referees Addison-Wesley (1969). about an earlier version of the paper were also helpful. [Lau 76] Markus Lauer, Canonical Representatives for Residue Classes of a Polynomial Ideal, References these Proceedings. [Bes 40] A. S. Besicovitch, On the Linear Indepen- [Loo 73] R. Loos, A Constructive Approach to dence of Fractional Powers of Integers, Algebraic Numbers, preprint. J. London Math. Soc. 15 (1940), 3-6. [Loo 74] , Toward a Formal Implementa- [Bro 71] W. S. Brown, On Euclid's Algorithm and tion of Computer Algebra, SlGSAM Bulletin 9, the Computation of Polynomial Greatest Common 3 (August 1975), 21-23. Divisors, J. ACM 18, 4 (Oct. 1971), 478-504. [MaF 71] W. A. Martin and R. J. Fateman, The [Buc 70] B. Buchberger, Ein Algorithmisches MACSYMA System, Proceedings of Second Symposi- Kriterium fur die L~sbarkeit eines um on Symbolic and Algebraic Manipulation Algebraischen Gleichungssystems, Aequationes (March 1971). Mathematicae 4 (1970). [Mat 75] Mathlab Group, MACSYMAReference Manual, [Cav 68] B. F. Caviness, On Canonical Forms and The Laboratory for Computer Science, M.I.T., Simplification, Ph.D. Dissertation, Cambridge, Massachusetts, (November 1975), Carnegie-Mellon University (May, 1968), 80 199 pages. pages. Available from Xerox University Microfilms, Ann Arbor, Michigan. [Mos 71] Joel Moses, Algebraic Simplification: A Guide for the Perplexed, Comm. ACM 14, 8 [Cav 70] , On Canonical Forms and (August 1971), 527-537. Simplification, J. ACM 17 2 (April 1970), 385-396. [Pol 50] Harry Pollard, The Theory of Algebraic Numbers, The Mathematical Association of [Col 74] G. E. Collins, Quantifier Elimination for America (1950). Real Closed Fields by Cylindrical Algebraic Decomposition - Preliminary Report, SIGSAM [Ric 74] lan Richards, An Application of Galois Bulletin 8, 3 (August 1974), 80-90. Theory to Elementary Arithmetic, Adv. in Math. 13 (1974), 268-273. [Eps 75] H. I. Epstein, Algorithms for Elementary Transcendental Function Arithmetic, Ph.D. [Ris 69a] R. H. Risch, The Problem of Integration Dissertation, University of Wisconsin, (May in Finite Terms, Trans. AMS, I_39 (May 1969), 1975), 408 pages. Available from Xerox 167-189. University Microfilms, Ann Arbor, Michigan. IRis 69b] , Further Results on Elemen- [Eps 76] , Using Basis Computation to tary Functions, IBM Tech. Report RC 2402, Determine Pseudo-Multiplicative Independence, Yorktown Heights, N.Y. (March 1969). these Proceedings. [Rub 73] C. M. Rubald, Algorithms for Polynomials [Fat 72] R. J. Fateman, Essays in Algebraic Over a Real Algebraic Number Field, Ph.D. Simplification, Ph.D. Dissertation, Harvard Dissertation, University of Wisconsin (1973), University. Revised version reprinted as MIT 224 pages. Project MAC Tech. Report MAC TR-95 (April 1972), 190 pages. [Sht 75a] Roman Shtokhamer, Simple Ideal Theory: Some Applications to Algebraic Simplification, [Fit 71] John P. Fitch, An Algebraic Manipulatcr, University of Utah Tech. Report UCP-36 Ph.D. Dissertation, University of Cambridge (July 1975), 22 pages. (Oct. 1971). [Sht 75b] , Simplification of Nested [Fit 73] , On Algebraic Simplification, Radicals, University of Utah Tech. Report Com~gter#. 16 (1973), 23-27. UCP-37 (July 1975), 16 pages. [GJV 75] J. H. Griesmer, R. D. Jenks, and [vdW 49] B. L. van der Waerden, Modern Alqebra, D. Y. Y. Yun, SCRATCHPAD Users Manual, tr. F. Blum, Frederick Ungar Publ. Co. (1949). Report RA 70, IBM Research Center, Yorktown Heights, N.Y. (June 1975), 66 pages. [Wan 75] Paul Wang, Factoring Multivariate Poly- nomials Over Algebraic Number Fields in [Kle 66] S. L. Kleiman, Computing with Rational MACSYMA, SIGSAM Bulletin 9, 3 (August 1975), Expressions in Several Algebraically Depen- 21-23. dent Variables, Bell Laboratories Tech. Report, Murray Hill, New Jersey, (1966), 40 [Wei 76] Peter Weinberger, Factoring Polynomials pages. Reprinted as Computing Science Tech. Over Algebraic Number Fields, ACM Trans. on Report #42 (1976). Math. Software (to appear).

338