Albert D. Rich. Soft Warehouse, Inc.



Similar documents
Complex Conjugation and Polynomial Factorization

TRANSCENDENTAL NUMBERS

The Cubic Formula. The quadratic formula tells us the roots of a quadratic polynomial, a polynomial of the form ax 2 + bx + c. The roots (if b 2 b+

CUBIC AND QUARTIC FORMULAS. James T. Smith San Francisco State University

Pythagorean Triples and Rational Points on the Unit Circle

Precalculus Prerequisites a.k.a. Chapter 0. August 16, 2013

SOME PROPERTIES OF EXTENSIONS OF SMALL DEGREE OVER Q. 1. Quadratic Extensions

1 Gambler s Ruin Problem

Lectures on the Dirichlet Class Number Formula for Imaginary Quadratic Fields. Tom Weston

More Properties of Limits: Order of Operations

6.042/18.062J Mathematics for Computer Science December 12, 2006 Tom Leighton and Ronitt Rubinfeld. Random Walks

Concurrent Program Synthesis Based on Supervisory Control

As we have seen, there is a close connection between Legendre symbols of the form

Sage Timberline Office

CABRS CELLULAR AUTOMATON BASED MRI BRAIN SEGMENTATION

A MOST PROBABLE POINT-BASED METHOD FOR RELIABILITY ANALYSIS, SENSITIVITY ANALYSIS AND DESIGN OPTIMIZATION

Price Elasticity of Demand MATH 104 and MATH 184 Mark Mac Lean (with assistance from Patrick Chan) 2011W

Computational Finance The Martingale Measure and Pricing of Derivatives

Risk in Revenue Management and Dynamic Pricing

C-Bus Voltage Calculation

c 2009 Je rey A. Miron 3. Examples: Linear Demand Curves and Monopoly

Introduction to NP-Completeness Written and copyright c by Jie Wang 1

The impact of metadata implementation on webpage visibility in search engine results (Part II) q

Machine Learning with Operational Costs

Branch-and-Price for Service Network Design with Asset Management Constraints

Beyond the F Test: Effect Size Confidence Intervals and Tests of Close Fit in the Analysis of Variance and Contrast Analysis

Point Location. Preprocess a planar, polygonal subdivision for point location queries. p = (18, 11)

Automatic Search for Correlated Alarms

POISSON PROCESSES. Chapter Introduction Arrival processes

An inventory control system for spare parts at a refinery: An empirical comparison of different reorder point methods

Synopsys RURAL ELECTRICATION PLANNING SOFTWARE (LAPER) Rainer Fronius Marc Gratton Electricité de France Research and Development FRANCE

NUTSS: A SIP-based Approach to UDP and TCP Network Connectivity

A Modified Measure of Covert Network Performance

FREQUENCIES OF SUCCESSIVE PAIRS OF PRIME RESIDUES

ENFORCING SAFETY PROPERTIES IN WEB APPLICATIONS USING PETRI NETS

IEEM 101: Inventory control

Stat 134 Fall 2011: Gambler s ruin

Project Management and. Scheduling CHAPTER CONTENTS

A Simple Model of Pricing, Markups and Market. Power Under Demand Fluctuations

Pressure Drop in Air Piping Systems Series of Technical White Papers from Ohio Medical Corporation

FDA CFR PART 11 ELECTRONIC RECORDS, ELECTRONIC SIGNATURES

CRITICAL AVIATION INFRASTRUCTURES VULNERABILITY ASSESSMENT TO TERRORIST THREATS

The Online Freeze-tag Problem

Comparing Dissimilarity Measures for Symbolic Data Analysis

Secure synthesis and activation of protocol translation agents

The HIV Epidemic: What kind of vaccine are we looking for?

Sage Document Management. User's Guide Version 12.1

Exponents and Radicals

The risk of using the Q heterogeneity estimator for software engineering experiments

Finding a Needle in a Haystack: Pinpointing Significant BGP Routing Changes in an IP Network

Risk and Return. Sample chapter. e r t u i o p a s d f CHAPTER CONTENTS LEARNING OBJECTIVES. Chapter 7

Monitoring Frequency of Change By Li Qin

Evaluating a Web-Based Information System for Managing Master of Science Summer Projects

On the predictive content of the PPI on CPI inflation: the case of Mexico

Memory management. Chapter 4: Memory Management. Memory hierarchy. In an ideal world. Basic memory management. Fixed partitions: multiple programs

Measuring relative phase between two waveforms using an oscilloscope

Sage Document Management. User's Guide Version 13.1

This document is downloaded from DR-NTU, Nanyang Technological University Library, Singapore.

Index Numbers OPTIONAL - II Mathematics for Commerce, Economics and Business INDEX NUMBERS

4. Influence of Temperature and Pressure on Chemical Changes

Free Software Development. 2. Chemical Database Management

A Note on Integer Factorization Using Lattices

Large firms and heterogeneity: the structure of trade and industry under oligopoly

Web Application Scalability: A Model-Based Approach

X How to Schedule a Cascade in an Arbitrary Graph

Two-resource stochastic capacity planning employing a Bayesian methodology

Multiperiod Portfolio Optimization with General Transaction Costs

An Efficient NURBS Path Generator for a Open Source CNC

How To Understand The Difference Between A Bet And A Bet On A Draw Or Draw On A Market

Assignment 9; Due Friday, March 17

5.1 Radical Notation and Rational Exponents

Failure Behavior Analysis for Reliable Distributed Embedded Systems

DAY-AHEAD ELECTRICITY PRICE FORECASTING BASED ON TIME SERIES MODELS: A COMPARISON

COST CALCULATION IN COMPLEX TRANSPORT SYSTEMS

Working paper No: 23/2011 May 2011 LSE Health. Sotiris Vandoros, Katherine Grace Carman. Demand and Pricing of Preventative Health Care

Electronic Commerce Research and Applications

EECS 122: Introduction to Communication Networks Homework 3 Solutions

Managing specific risk in property portfolios

Continued Fractions and the Euclidean Algorithm

Normally Distributed Data. A mean with a normal value Test of Hypothesis Sign Test Paired observations within a single patient group

Static and Dynamic Properties of Small-world Connection Topologies Based on Transit-stub Networks

CONTENTS 1. Peter Kahn. Spring 2007

An Introduction to Risk Parity Hossein Kazemi

Storage Basics Architecting the Storage Supplemental Handout

Indices and Surds. The Laws on Indices. 1. Multiplication: Mgr. ubomíra Tomková

The fast Fourier transform method for the valuation of European style options in-the-money (ITM), at-the-money (ATM) and out-of-the-money (OTM)

Coordinate Transformation

Transcription:

4 Simlifying Suare Roots of Suare Roots by Denesting David J. Jerey The University of Western Ontario Albert D. Rich Soft Warehouse, Inc. Abstract: We discuss why it is imortant to try to simlify the suare root of an exression containing other suare roots, and we give rules for doing this when it is ossible. The suare root of an exression containing nth roots is also considered briey. This article, in addition to treating a secic mathematical toic, shows some of the stes that develoers must take when writing comuter algebra systems. 4.1 Introduction Numbers such as 2 and 3 5 are called surds 1 [Chrystal64, Hall88]. The more general terms radical and algebraic number are also used, but surd is the most secic. It is avenerable term that has been revived for use in comuter systems 2. Given ositive integers n and k, the uniue ositive real root of the euation x n = k will be denoted n k and called a surd. Most books [Chrystal64, Hall88] allow k to be a ositive rational number, and there is no great dierence in rincile if we accet that generalization in this article, however, all the examles use integers. Another oint ofvariation is the treatment of erfect-ower factors, i.e., whether one writes 8or2 2 here we use whichever form is more convenient. The term radical may be familiar to some readers from the common hrase `solvable in terms of radicals', which is used whenever a textbook discusses the roots of a olynomial [Dickson26]. A olynomial euation is solvable by radicals if `... its roots can be found by rational oerations and extractions of a root... ' [Dickson26]. Thus a uantity such as 1+ 2 is a radical, but not a surd. Polynomials of degree less 1 Please do not tell us jokes about these numbers being absurd. We have heard them all before. 2 The term surd is used by TEX as the name for the symbol Male has a function called surd that is similar to the nth root dened here like all good mathematical terms, the recise denition deends uon the context. In general, a mathematical term that does not have several conicting denitions is not imortant enough to be worth learning.

62 COMPUTER ALGEBRA SYSTEMS: A PRACTICAL GUIDE than or eual to 4 are always solvable by radicals, and higher-degree olynomials are sometimes solvable by radicals. An algebraic number is a root of some olynomial with integer coecients, and in general will not be exressible as a radical, although all radicals are secial cases of algebraic numbers. The ositive real solution of the euation x n = r, where r is a ositive radical, will here be called the nth root of r, and will itself be a radical. The other familiar name for these tyes of numbers is (1=n)th ower, but this term will not be used because fractional owers are regarded by many eole as multivalued functions 3, and we want towork with uniuely dened (and named) uantities. Our attention in this article is directed to radicals consisting of the suare root of an exression containing surds, for examle 2+ 3. Such exressions are often called nested radicals, although one could argue that strictly the word nested is redundant. Such exressions can sometimes be simlied, but the rules for such simlications are not discussed in standard books. Here are some examles of simlications. The rst examle shows that two suare roots can sometimes be reduced to one: 3+2 2=1+ 2 : (4.1) Sometimes the number of suare root oerations remains unchanged, but eole refer the format of the new exression: 5+2 6= 2+ 3 : (4.2) This rearrangement of the suare-root oerations is usually called denesting. Here are some more examles of suare-root denesting. 5 3+6 2 = 4 27 + 4 12 (4.3) 12 + 2 6+2 14 + 2 21 = 2+ 3+ 7 : (4.4) 3 We do not restrict ourselves to taking the suare root only of other suare roots: 3 9+6 3 3+9 = 3+ 3 3 (4.5) 5 ; 3 4 = 1 3 4.2 Why denest suare roots? ; 3 2+ 3 20 ; 3 25 : (4.6) Discovering the relations given in the examles above is an interesting mathematical challenge, but why should a comuter algebra system (CAS) devote comuting resources to denesting roblems? The rst reason is simlicity. Users of CAS, like all mathematicians, refer to see their results exressed in `simlest' form. Most eole would regard the right-hand sides of our examles above as being `simler' than the left-hand sides, although there might be some who would disagree. For examle, in 3 The uestion \Are fractional owers multivalued?" is a standard basis for table assignments at conference banuets.

SIMPLIFYING SQUARE ROOTS OF SQUARE ROOTS BY DENESTING 63 [Landau92b], reasons are given for referring the left-hand side of (4.2). However, we assume that in general users would want denesting to be discovered 4. Another reason for denesting is reliable simlication. For both eole and comuters, there is a danger that the result of a mathematical simlication will deend uon the order in which rules are alied. For examle, the simlication of (1 ; 2) 2 can roceed two ways. The rst way is called `to-down' by those who think of the exression as a tree, and `outside to middle' by those who look at the rinted form. Following this rocedure, one alies rst the rule x 2 = jxj for any real x, and obtains (1 ; 2) 2 = 2 ; 1. The other way is `bottom-u' or `middle outwards', in which one exands the suare and obtains 3 ; 2 2. Without denesting, the simlication will not roceed any further. Thus two eole using the same CAS to solve the same roblem could arrive at aarently dierent answers, and this is what we wish to avoid 5. A nal reason is a small imrovement in the accuracy of the numerical evaluation of some radical exressions. For examle, the uantity 199999 ; 600 111110 0:00158 aroximates to zero if 10 decimal digits of recision are used, and only at 15 digits is the exression found to be nonzero in contrast, the euivalent 100 10 ; 3 11111 aroximates to 0:00158 using just 7 digits of recision. 4.3 Where do nested radicals arise? Older algebra textbooks contain exlicit roblems on nested radicals, for examle, the books by Chrystal [Chrystal64] and Hall & Knight [Hall88], which are both 19th century books (the 1964 date on the Chrystal citation is not indicative of the age of the book, whose rst edition was ublished in 1886). Clearly, users could challenge a comuter system with roblems from such books, but there are other sources of roblems. Even if users do not deliberately ose denesting roblems, the roblems they do ose can generate subroblems that contain nested radicals. Many roblems in mathematics have solutions exressed as standard formulae. For examle, all students learn uite early in their studies the formula for solving a uadratic euation not surrisingly, it is rogrammed into most CAS. Consider what haens when that formula is used for the roblem The standard formula gives x 2 +6x ; 4 5=0: x = ;3 9+4 5 4 Long after ordinary text was set mechanically, mathematical euations were still set by hand. Long horizontal lines, as in large fractions or large roots, were troublesome for the comositors, and authors of mathematics were encouraged to refer forms that reduced the need for such lines. Perhas now that we have TEX to set these exressions easily, our mathematical tastes with resect to simlicity will change also. 5 Not to mention all the hone calls to technical suort.

64 COMPUTER ALGEBRA SYSTEMS: A PRACTICAL GUIDE but in fact the uadratic can be factored as (x +1; 5)(x +5+ 5). Therefore the general formula is correct, but does not directly give the simlest result in this secial case. The roblem is an interesting one to try on humans, as well as comuter systems. Now consider the formula, valid for real a b with b>a 2, Z 1 4x 2 +4ax + b dx = 1 2 2x + a arctan b ; a2 b ; a 2 : (4.7) If we substitute a =2andb =7+2 2, we nd that (4.7) becomes Z 1 4x 2 +8x +7+2 2 dx = 1 2 3+2 2 arctan 2x +2 : 3+2 2 As examle (4.1) shows, however, the nested radicals on the right-hand side can be simlied. Of course, for most values of a and b, the term b ; a 2 must remain unsimlied. 4.4 Develoing algorithms In the next section, we shall give algorithms for simlifying nested radicals, but it is worthwhile rst to make a few general comments. Every descrition of an algorithm should secify the class of roblems to which it alies, which in turn reuires that we decide which roblems we are going to tackle. As a rule of thumb, the more general our class of roblems, the larger and slower our algorithm is likely to be. In general, system develoers identify the most freuently occurring cases and concentrate rst on them. The simlication of radicals has been the subject of several recent studies [Landau92b, Landau92a, Ziel85], but these studies have taken general aroaches to the roblem, with the algorithms they derive being corresondingly lengthy. Here we consider algorithms of restricted alicability, handling only commonly occurring cases, and gain brevity at the rice of generality. Secically, the algorithms given here do not address examle (4.6) above. A second comonent in the secication of an algorithm is the form the answer will take. In this context, we observe that aroximating a nested radical as a decimal fraction is certainly a tye of simlication, but not one in which we are interested. The ossibility that dierent mathematicians will dene simlication dierently was ointed out above, and that will certainly inuence the form in which a simlication is sought. Here we shall take itthatwe aim to reduce the level of nesting, that we reuire exact results and that the result will also be exressed as a radical. 4.5 The algorithms We begin with a short treatment of a simle case, and then roceed to the main case, which reuires a longer study.

SIMPLIFYING SQUARE ROOTS OF SQUARE ROOTS BY DENESTING 65 4.5.1 Suare root of a three-term sum Euation (4.5) can be generalized to the attern a 2 2ab + b 2 = ja bj (4.8) where either a or b is a surd other than a suare root (i.e., so that the corresonding suared term is still a surd). The obvious starting oint for detecting this attern is the fact that there are 3 terms under the suare root, although it must be realised that, in general, we shall not know the order in which the terms aear. For examle, in the case of the roblem 4+ 3 81 + 4 3 9=2+ 3 9, the rst term under the suare root corresonds to a 2.However, in the similar looking 6+ 3 81 + 3 9= 3 3+ 3 9, the rst term corresonds to 2ab. So the uestion is: given X + Y + Z, do there exist a and b such that X, Y, Z corresond in some order to a 2, b 2 and 2ab? We can suose that the roblem has been formulated in such away that we know that X + Y + Z >0. One might think of analysing the structure of the 3 terms, but this could be a lengthy oeration for a CAS. A uicker way to roceed is to notice that if X = a 2 and Y = b 2,then 4XY =4a 2 b 2 =(2ab) 2 = Z 2. So the system can test 4XY ; Z 2 for zero, and then return X +sgnz Y. The signum function takes care of the ossibility, and the absolute-value signs take care of the ossibility that Y > X. In the same way, wecan test 4XZ ; Y 2 and 4Y Z; X 2. Some nal things to notice about this rocedure are the simlicity of the failure condition we give u if all test uantities are nonzero and the fact that there is no obvious ath to generalize it to encomass a wider class of roblems. 4.5.2 Suare root of suare roots Examles (4.1) (4.3) show that an imortant attern to consider is X + Y = A + B: (4.9) We need to nd A B in terms of X Y, and we need the circumstances in which the right-hand side is simler than the left. Suaring both sides gives us X + Y = A + B +2 AB : (4.10) One way to satisfy this euation is to set X = A + B and Y 2 =4AB. Now if (4.9) is valid, then it should also be true that X ; Y = A ; B: (4.11) Multilying (4.9) and (4.11) gives X 2 ; Y 2 = A ; B. Having exressions for A + B and A ; B, we can derive exressions for A and B in terms of X and Y, and hence discover the following theorem. Theorem: Let X Y 2 R with X>Y >0, then X Y = 1 2 X + 1 2 X 2 ; Y 2 1 2 X ; 1 2 X 2 ; Y 2 : (4.12)

66 COMPUTER ALGEBRA SYSTEMS: A PRACTICAL GUIDE We call this the suare-root-nesting euation. Some numerical exeriments will show how it can be useful. If X =3andY = 8, then (4.12) reroduces examle (4.1), because in this case X 2 ; Y 2 = 1. Examle (4.2) is obtained similarly. Examle (4.3) is a little dierent. Now, X = 75 and Y = 72, giving X 2 ; Y 2 = 3. This is a rational multile of X, and hence the rst term on the right of (4.12) becomes 1 2 X + 1 2 X 2 ; Y 2 = 5 2 3+ 1 2 3= 3 3= 4 27 : The other term is similar and we still have a denesting. The common feature in these examles is the reduction of each of the exressions X X 2 ; Y 2 to a single term, or in other words to a non-sum. This, then, is a condition for (4.12) to be a simlication. An algorithm based on (4.12) works by assigning X and Y and then comuting the terms on the right side of the euation, acceting them as a simlication if the suare roots simlify to non-sums. We shall call this method 1. We now turn to examle (4.4). A little dexterity allows us to use (4.12) again. We grou the terms so that X =12+2 6 and Y =2 14 + 2 21. The terms in (4.12) now become X X 2 ; Y 2 =12+2 6 28 ; 8 6 : This may not seem to be leading to a simlication, but using method 1 above, we see 28 ; 8 6=2 6 ; 2. Therefore, X + X 2 ; Y 2 = 10 + 4 6 X ; X 2 ; Y 2 = 14 : So with these simlications, euation (4.12) becomes 12+2 6+2 14 + 2 21 = 5+2 6+ 7 : This is already a simlication, but additionally the rst term on the right-hand side is examle (4.2) and can be simlied further. Therefore we nally reroduce (4.4). The reeated use of method 1 we shall call method 2. Why sto there? Consider an even bigger roblem: 65 ; 6 35 ; 2 22 ; 6 55 + 2 77 ; 2 14 + 6 10 : (4.13) Assigning X =65; 6 35 ; 2 22 and Y = ;6 55 + 2 77 ; 2 14 + 6 10, wecan use method 2 to simlify the critical factor. X 2 ; Y 2 = ;468 35 + 156 22 ; 24 770 + 2869 = 39 ; 6 35 + 2 22 : Continued use of (4.12) simlies (4.13) to 3 5 ; 7 ; 11 + 2. This is method 3. Pursued further, this techniue solves larger and larger roblems. These successes show that an algorithm is ossible, but we must ask several more uestions before we attemt to imlement it in a system. The most imortant one

SIMPLIFYING SQUARE ROOTS OF SQUARE ROOTS BY DENESTING 67 is how the method fails. After all, the majority of nested surds do not denest, and so any imlementation must know when to give u. Answering this uestion turns out to be as dicult as nding the successful art of the algorithm 6.Itmightseem frustrating having to send a lot of time deciding when the system will not succeed, but this decidedly less glamorous activity is essential to the smooth oeration of a CAS. Consider, therefore, an examle slightly altered from (4.1): 4+2 2. Substituting X = 4 and Y =2 2into (4.12) gives 4+2 2= 2+ 2+ 2 ; 2 : Observe that, on the right, there are two exressions, each as comlicated as the one on the left, and therefore the rocess fails and no more denesting is ossible. Moving u one level of diculty, we alter (4.4) and see what haens. Consider 12 + 2 6+2 14 + 2 20 : We assign X =12+2 6 and Y =2 14+2 20, and nd X 2 ; Y 2 = 32 ; 16 70 + 48 6 : Thus we have exressed a suare root of 4 terms in terms of 2 suare roots of 3 terms, and trying to simlify these leads to suare roots of 2 terms, which do not simlify. So we have relaced one ugly exression with one ugly set of exressions, and so the rocedure fails. So we nowhave an idea of when there is no simlication, but we can also ask whether we would ever miss a simlication. For method 2, we must break a sum u into two grous, and it may be that the wrong grouing will miss a denesting. To check this ossibility, we consider (a + b + c) 2 = a 2 + b 2 + c 2 +2ab +2bc +2ca : If a b c are all suare-root surds, then a 2 + b 2 + c 2 is an integer and we set X = a 2 + b 2 + c 2 +2ab. Further, by the symmetry of the exression, it will not matter how we divide u the four terms, because one art of the division always contains the a 2 + b 2 + c 2 art together with one of the terms 2ab, 2bc, 2ca, and the other art always contains the rest. Thus, we never miss. For larger roblems, however, the ordering does become imortant. For the case (a + b + c + d) 2 = a 2 + b 2 + c 2 + d 2 +2ab +2ac +2ad +2bc +2bd +2cd only the division X = a 2 + b 2 + c 2 + d 2 +2ab +2cd leads to successfully discovering the denesting. In this case, the algorithm is guaranteed to succeed only if the system invests the resources to analyse the structure of the exression. If the exression is blindly slit into two, then the method will sometimes succeed by the luck of the ordering, but otherwise fail. 6 Since we used dexterity to get the algorithm to succeed, we need sinisterity to nd examles for which it fails.

68 COMPUTER ALGEBRA SYSTEMS: A PRACTICAL GUIDE 4.6 Tyes of imlementation The rst aim of this article has been to describe the mathematical basis of some algorithms used in CAS, but there is a second aim, which is to give aavour of the ways in which algorithms are imlemented in CAS. To this end, we shall write out some imlementations in a seudocode. This code is not in the language of any system we know it is just a way of setting down the stes one would follow. Let us now consider dierent ways in which a develoer might imlement the rules we have seen above. As a rst cut, we notice that each tye of examle has a dierent number of terms under the suare root. We might therefore use this fact to select between methods 1 3 in section 4.5.2. Assume that our system has a function that counts the number of terms in a sum, called TermsInSum. Some code for a function that returns a simlication, or else fails, is given below using this aroach. Simlify_Suare_Root(Exression) Check that Exression is made u of surds. Let T=TermsInSum(Exression) If T=1 then Extract the root if ossible, else FAIL else if T=3 then Follow method for suare-root of 3 terms X=first term Y=second term Z=third term is any of 4XY-Z^2, 4XZ-Y^2, 4YZ-X^2 zero? Yes: comute aroriate exression else FAIL. else if T=2 then Follow method 1. X=first term Y=second term is X^2-Y^2 a non-sum? Yes: comute suare root, else FAIL. Is X+srt(X^2-Y^2) a non-sum, and X-srt(X^2-Y^2) a non-sum? Yes: comute the two suare roots, else FAIL. else if T=4 then Follow method 2. X=first 2 terms Y=remaining terms Comute TEMP=X^2-Y^2. Does TermsInSum(TEMP)=2? Yes: Let U=first term in TEMP V=remaining term. Is U^2-V^2 a non-sum? Yes: comlete method else FAIL. else if T=7 then Follow method 3. Order terms select 2 corresonding to 2ab and 2cd Assign X, Y continue as described in the text. else FAIL. This very exlicit code would not be attractive to many current comuter algebra system develoers. In articular, it is very secic and tied to the examles that we

SIMPLIFYING SQUARE ROOTS OF SQUARE ROOTS BY DENESTING 69 have so far exlored. Therefore, adding new cases must be done exlicitly, and the code has little hoe of working for examles slightly dierent from those it was designed for. For examle, if this code were imlemented and a user challenged the system with an examle the develoer had not considered, like 5+2 6+5 7+2 4 700 + 2 4 1575 = 2+ 3+ 4 175 then there is no hoe that the system could surrise the rogrammer by rising to the occasion, because the suare root contains 5 terms, and that case is not treated 7. As users reort roblems that the system `cannot do', the develoer is faced with constantly revisiting the code. This will always haen to some extent, of course, but it is articularly inevitable with this style of rogramming. The above code also contains coding that reeats itself. This suggests that a more exible aroach will be a recursive one,meaning one in which the routine will be structured to call itself. The diculty with a recursive aroach is that we must be very careful to have away of stoing it 8.Wewant to abandon the rocess whenever it looks as though we are no longer making rogress. The easiest way todothisisto have a numerical measure of the degree of nesting of a radical, and sto the recursion whenever this measure increases. 4.7 A measure of the degree of nesting of a radical We now describe the function that is used to control the recursive denesting of radicals. One measure of the nesting of a radical is given in [Landau92b] the one given here is similar in sirit. Suose we have a radical x. We wish to associate with it an integer N (x) that is its nesting level. Our rules are: 4.7.1 If x is a number Anumber here means an integer, but more generally it includes rational numbers also. (More abstractly, a member of the base number eld.) For a number x, setn (x) =1. Some measures of nesting start counting at 0, but the starting oint is arbitrary. Any undened symbols are also given N =1. 4.7.2 If x is an nth root of something If x has the form n y, with n>1, then we assignn ( n y)=1+n (y). This is the fundamental feature that we wish to cature with our measure, so if we think of the radical being built u from other radicals, then every time we take another root we increase the measure. Thus N ( 2) = 1 + N (2) = 2. Notice that the size of n is not used. Therefore the simlication 4 = 2 is visible to this measure (N decreases from 2 to 1), but the simlication 4 4= 2 is not, because only the strength of the root is 7 As a case in oint, we were agreeably surrised ourselves when Derive succeeded on this one. 8 A system exeriencing uncontrolled recursion is said to suer from recussion a secial form of concussion. Its name reminds us that the develoer often starts cussin' all over again.

70 COMPUTER ALGEBRA SYSTEMS: A PRACTICAL GUIDE reduced. This is accetable, since nesting is what we are trying to measure, but other alications might reuire a measure in which n is included somehow. 4.7.3 If x is a roduct From the oint of view of nesting, 2 3 is no more comlicated than 6. More generally, given radicals m x and n y, there are integers a such that m x n y = a. Clearly the right-hand side counts as a single nesting, so it would be inconsistent to consider the left side as being more nested. Now consider 2 2+ 2. The second factor is the one that will attract our attention and dictate the degree of nestedness of the whole exression, and so the rule is N (xy) = max(n (x) N (y)). 4.7.4 If x is a sum 2+ 2+ 2. To simlify this exression, we must give Consider the examle 2+ 8=3 2. The right-hand side is referable, and so any measure should give abonus for a reduction in the numberofterms.now consider x = 4+ 2+ 2+ searate attention to each term if in addition we can combine terms, so much the better. Therefore our measure adds together the degrees of nestedness of the searate terms. This can be written as follows. A sum of radicals is slit into two grous, a and b. ThenN (a + b) =N (a)+n (b). 4.7.5 Examles Let us aly these rules to our examles above. For examle (4.1), the left side is N 3+2 2 =1+N 3+2 2 =1+N (3) + N 2 =1+1+2=4: The right side has N = 3, so there is a denite simlication by this measure. For examle (4.2), both sides have N = 4, and as mentioned, most users would then choose the denested exression. In (4.3), the left side has N = 5, while the right has N =4 because the 4th roots do not change the value of N. This result suorts the choices made in designing N, because if 4th roots had been enalised relative to suare roots, then the right side could easily have obtained the higher score. 4.8 Recursive simlication Once we have the function N,we can use it in alying the suare-root-nesting euation (4.12). Again resorting to a seudocode for the imlementation, we write Recursive-Srt-Simlify(E) Comute n=n(e) Slit E^2 into X and Y. Comute T=X^2-Y^2 If N(T) > n then FAIL. Simlify P=X+SQRT(T)

SIMPLIFYING SQUARE ROOTS OF SQUARE ROOTS BY DENESTING 71 If N(P) > n then FAIL. Simlify Q=X-SQRT(T) If N(Q) > n then FAIL. Return SQRT(P/2)+SIGN(Y)*SQRT(Q/2) Notice the advantage of recursion: this code covers all cases. However, itdoesnot include any attemt to sort the exression before slitting, and so will miss some cases. Now let us ste through the code using examle (4.4). Since we shall make several tris through the Recursive-Srt-Simlify routine, we must distinguish the same variable names in dierent calls. We dothisby adding subscrits to each variable name. Thus we start with the exression E 1 = 12 + 2 6+2 14+2 21 : The rst ste is to comute n 1 = N (E 1 )=8.Thenwe slit: X 1 =12+2 6 and Y 1 =2 14 + 2 21. Now comute T 1 =28; 8 6 and N (T 1 )=3<n 1 : The reduction in nesting allows the calculation to continue to the comutation of P 1. P 1 =12+2 6+ 28 ; 8 6 : This exression must now be simlied. When P 1 is assed to the simlier, it will see the nested root contained in P 1 and call Recursive-Srt-Simlify. The following comutation will now take lace. The intermediate uantities in this tri through Recursive-Srt-Simlify will be subscrited with 2. E 2 = 28 ; 8 6 and n 2 = N (E 2 )=4: Now slitting, we getx 2 =28andY 2 = ;8 6, giving T 2 = 400 and N (T 2 )=1.Since the nesting is reducing, the rocess continues. P 2 =28+ 400 = 48 and N (P 2 )=1<n 2 Q 2 =28; 400 = 8 and N (Q 2 )=1<n 2 : So this second run through Recursive-Srt-Simlify returns 24 ; 2. That was all to simlify P 1 at the rst level, so now we return to that level and continue. P 1 =12+2 6+ 24 ; 2=10+4 6 and N (P 1 )=3 n 1 =8: Using the simlication of T 1 already found, we can comute Q 1 = 14 and hence the rocedure returns 5+2 6+ 7. Since this exression is dierent from the starting one, the system will return this to the main simlication routine, which will restart from the to. This time, the denesting routine will receive E = 5+2 6 and return 2+ 3. Together with the 7 already found, the simlify routine obtains 2+ 3+ 7. Again the nal exression has changed, but this time when the rocess restarts, there is nothing to simlify, so it stos.

72 COMPUTER ALGEBRA SYSTEMS: A PRACTICAL GUIDE 4.9 Testing All CAS develoers have test suites that they run their systems on. These suites must contain roblems for which the system is exected to obtain the correct simlication, and roblems for which the system should correctly nd no simlication. Derive has one such suite secically for denesting roblems. It contains all the examles given in this chater and many others. We challenge readers to use their dexterity and sinisterity to invent some interesting examles to add to our suite. As a starting oint, a secic case for which we have not given an examle is a suare root in which the ordering of the terms is imortant to the denesting. An ideal test suite will have at least one examle to activate each ath through the algorithms of the system. As this simle denesting code illustrates, there are always many laces where uantities are tested and execution aths switched. Comiling a thorough test suite even for this small art of a comlete system is lengthy and dicult, so it is no wonder that over many years of use, users nd examles that activate reviously unexercised aths in the code. The test suites of all the CAS contain many examles contributed, often inadvertently, by(we hoe temorarily) disgruntled users.

References [Chrystal64] G. Chrystal (1964) Algebra, volumes I and II. Chelsea Publishing Comany, NewYork, 7th edition. [Dickson26] L. E. Dickson (1926) Algebraic theories. Dover, New York. [Hall88] H. S. Hall and S. R. Knight (1888) Higher Algebra. MacMillan, London, 2nd edition. [Landau92a] Susan Landau (1992) A Note on Ziel Denesting. Journal of Symbolic Comutation 13: 41{45. [Landau92b] Susan Landau (1992) Simlication of Nested Radicals. SIAM Journal on Comuting 21: 85{110. [Ziel85] R. Ziel (1985) Simlication of Exressions involving Radicals. Journal of Symbolic Comutation 1: 189{210.