sSyntax14b.Scn.Fnt u8 bParcElemsAlloc "Syntax12i.Scn.FntR u8StyleElemsAlloc TitleSyntax10.Scn.Fnt8FoldElemsNewSyntax12.Scn.Fnt u8 Text3(Lo8 u8 Title 8 u8 Text 8 u8 Title 8 u8 TextSyntax12b.Scn.Fnt u8 SubTitle8 u8 Textf Math10.Scn.Fnt  H u8  ExampleN` ExprMapleAllocScriptconvert to expSyntax10.Scn.Fntp"ExprIconsAllocDT(DTExprViewsAllocPlaceholderExprIconsAllocGraphconvert(, exp)qExprIconsAllocr(v/GxEsExprStdAllocSymbolxExprStdAllocFunctioncos0BxBwcExprStdAllocInteger yeExprLib0StdConstAllocemB].+-5*/++-=4fB+=w#B+o[y^*/7y ^WBVBy^+-+=~BiBĩy^y=z/Gsinh^+-+=iKB/GB*/coskB*/+-+B{RB+nEsn+-ExprLib0AllocFunction{R */y B*/^Q[y^y£B#*/^BB)yx-^+-*/yBR/GBxB+*/+-ln*/^cy^4 /GdQBf/G%/GEsexpconvert Espowercombine=subsVBcEsc=ydBO/Gln*/^yB/GB*/cos+-^9BfsBwc ]@@ywc x^*/tsBwc `>ywc ^*/ZsBwc B$<y^*/+-By^B*/y^+-7kB$B*/B*/JkB*/HkB*/++-K[B+-)B+-j9ExprLib0AllocGreekphij}BsEssRSB6/Gsin*/=BbvEsv+ExprStdAllocIndexed+wcExprMatricesAlloc=ՎBb Б++ =-B~bB++- ++ =B)ۭb o+ =nBl{RڭbAEsA u1++++++++++++ =}BBB{Rb */š{RbB+- +-=&B0-{RJb +=Bq{RUb+ =4/GyBt/GaBaBiQ/Ga*/jQ/Ga+-=}B/Ga+=QB'/G+a=ExprStdAllocCollectionrsolvetB:B]8By^+-ϗyB>B+-*/^*/:BϗyB>B+-*/^*/+-EBSy^eBHSyB++-^HSy^+-*/LBBpy[BwEsw+-^py[B+-^+-*/ծB=>B=B=qBB++-=QB-B&vB&*/+-SBB*/+-*/-B5*B&*/B&*/+-B=BB,B&*/B&*/yB&*/6PB&*/+-&*/zBB++-*/%B8B*/++-BB&uWBB*/++-*/=ExprIconsAllocGraphExprSlangAlloc +ExprSlangAllocLP convert to trigSyntax10.Scn.Fntp"ExprIconsAllocDT(DTExprViewsAllocPlaceholderExprIconsAllocGraphconvert(, trig)  EExprSlangAlloc@~qExprSlangAlloc8 u8 SubTitle8 u8 Text u8  Example\@~expandSyntax10.Scn.Fntp"ExprIconsAllocDT(DTExprViewsAllocPlaceholderExprIconsAllocGraph expand()hqExprSlangAlloc`P4ExprSlangAlloc\@~expandSyntax10.Scn.Fntp"ExprIconsAllocDT(DTExprViewsAllocPlaceholderExprIconsAllocGraph expand()P4ExprSlangAlloc0ExprSlangAlloc\@~expandSyntax10.Scn.Fntp"ExprIconsAllocDT(DTExprViewsAllocPlaceholderExprIconsAllocGraph expand()`qExprSlangAllocpdqExprSlangAlloc u8 Text8 u8 CenteredText"ExprSlangAllocP qExprSlangAllocMath12.Scn.Fnt"ExprSlangAlloc u8 Text"ExprSlangAlloc/l"ExprSlangAlloc/P P4ExprSlangAlloc@BqExprSlangAlloc u8  Example*ExprSlangAllocP P4ExprSlangAlloc``[ExprSlangAllocp"l"ExprSlangAlloc u8  Example&@ 0ExprSlangAlloc0n@~ExprSlangAllocp"l"ExprSlangAlloc8 u8 SubTitle8 u8 Text 9w: u8  ExampleON combine trigSyntax10.Scn.Fntp"ExprIconsAllocDT(DTExprViewsAllocPlaceholderExprIconsAllocGraphcombine(, trig)`P4ExprSlangAllochqExprSlangAllocMq combine powerSyntax10.Scn.Fntp"ExprIconsAllocDT(DTExprViewsAllocPlaceholderExprIconsAllocGraphcombine(, power)ExprSlangAlloc0ExprSlangAlloc8 u8 SubTitle8 u8 TextM P4ExprSlangAlloc`P4ExprSlangAllocCourier10.Scn.Fnt u8  ExampleX@~simplifySyntax10.Scn.Fnt p"ExprIconsAllocDT(DTExprViewsAllocPlaceholderExprIconsAllocGraph simplify() P4ExprSlangAlloc8"ExprSlangAllocXAIsimplifySyntax10.Scn.Fnt p"ExprIconsAllocDT(DTExprViewsAllocPlaceholderExprIconsAllocGraph simplify()` 0ExprSlangAlloc_ExprSlangAlloc u8 Textb4C288 u8 Title8 u8 Text u8 TextlExprSlangAlloc"pExprSlangAllocExprSlangAlloc 0ExprSlangAlloc0ExprSlangAlloc0 hExprSlangAlloc_ u8  ExampleNp Iconvert to expSyntax10.Scn.Fntp"ExprIconsAllocDT(DTExprViewsAllocPlaceholderExprIconsAllocGraphconvert(, exp)lExprSlangAlloc``=ExprSlangAlloc u8 TextE u8 TextlExprSlangAllocR-lExprSlangAllocExprSlangAlloc$ u8  Example8`1hExprSlangAlloc u8  ExampleExprSlangAlloc u8 Text 0ExprSlangAlloc u8 TextB lExprSlangAlloclExprSlangAllocR u8  Example.@BImap (convert pow)Syntax10.Scn.Fnt*p"ExprIconsAllocDT(DTExprViewsAllocPlaceholderExprIconsAllocGraph,map(t -> combine(convert(t, exp), power), )lExprSlangAllocExprSlangAlloc u8 Text u8 TextT;f u8 Text_lExprSlangAlloc8 u8  Example0@BIfront (conv. to exp)Syntax10.Scn.Fntp"ExprIconsAllocDT(DTExprViewsAllocPlaceholderExprIconsAllocGraph'frontend(convert, [, exp], [{`^`},{}])lExprSlangAlloc ExprSlangAlloc u8 Text u8 TextСlExprSlangAlloc7' u8  Example\PIexpandSyntax10.Scn.Fntp"ExprIconsAllocDT(DTExprViewsAllocPlaceholderExprIconsAllocGraph expand()СlExprSlangAllocpExprSlangAllocSIexpand cosSyntax10.Scn.Fntp"ExprIconsAllocDT(DTExprViewsAllocPlaceholderExprIconsAllocGraphexpand(, cos)СlExprSlangAlloc!ExprSlangAllocH Ifront (expand)Syntax10.Scn.Fntp"ExprIconsAllocDT(DTExprViewsAllocPlaceholderExprIconsAllocGraphfrontend(expand, [])СlExprSlangAlloc!ExprSlangAllocIP Iexpand cos(4*x)Syntax10.Scn.Fntp"ExprIconsAllocDT(DTExprViewsAllocPlaceholderExprIconsAllocGraph expand(, cos(4*x))СlExprSlangAlloc7'ExprSlangAlloc, Ifront (expand ...)Syntax10.Scn.Fntp"ExprIconsAllocDT(DTExprViewsAllocPlaceholderExprIconsAllocGraph-frontend(expand, [], [{`+`,`*`},{cos(2*x)}])СlExprSlangAlloc7'ExprSlangAlloc u8 TexteExprSlangAlloc hExprSlangAlloc}8 u8 Title 8 u8 TextDvr  u8 SubTitle u8 TextIExprSlangAlloc!u 0ExprSlangAlloc u8 CenteredTextPExprSlangAllocPExprSlangAllocPExprSlangAllocPExprSlangAlloc u8 Text  u8 Text?IExprSlangAlloc6 u8 CenteredTextPExprSlangAlloc u8 Text<IpExprSlangAllocJlExprSlangAlloc* u8  ExampleЃlExprSlangAlloclExprSlangAlloclExprSlangAlloc u8 Text@ u8  Example8P&/ExprSlangAlloc u8  Example@p ExprSlangAlloc u8  ExampleA Isimplify powerSyntax10.Scn.Fnt p"ExprIconsAllocDT(DTExprViewsAllocPlaceholderExprIconsAllocGraphsimplify(, power, symbolic) u8  Example ExprSlangAlloc u8  Example0WlExprSlangAlloc u8  Examplep{ExprSlangAlloc u8 Text  u8  ExampleAExprSlangAlloc u8 TextpdlExprSlangAlloc u8 TextExprSlangAlloc,u lExprSlangAlloc ExprSlangAlloc@BExprSlangAlloc u8  Example8pt/ExprSlangAlloc u8  ExampleExprSlangAlloc u8  Example832ExprSlangAlloc u8  Example ExprSlangAlloc u8 Text5lExprSlangAlloc  u 0ExprSlangAllocIExprSlangAlloc`=@~ExprSlangAlloc+ u8 TextlExprSlangAlloc& u8  ExamplePExprSlangAlloc u8 Text0ExprSlangAlloc6 u8  Example0WlExprSlangAlloc0ExprSlangAlloc u8  Examplel3zExprSlangAlloc u8 TextpExprSlangAllocExprSlangAlloc C"simplify trigSyntax10.Scn.Fnt p"ExprIconsAllocDT(DTExprViewsAllocPlaceholderExprIconsAllocGraphsimplify(, trig, symbolic)Q  u8  ExampleCu Isimplify trigSyntax10.Scn.Fnt p"ExprIconsAllocDT(DTExprViewsAllocPlaceholderExprIconsAllocGraphsimplify(, trig, symbolic) 0ExprSlangAlloc u8  Example0zExprSlangAlloc u8 Text 8 u8  ExampleA Isimplify powerSyntax10.Scn.Fnt p"ExprIconsAllocDT(DTExprViewsAllocPlaceholderExprIconsAllocGraphsimplify(, power, symbolic)qExprSlangAlloc u8  Example^0 ExprSlangAlloc u8 Text 0ExprSlangAlloc pExprSlangAllocMN@` "convert to expSyntax10.Scn.Fntp"ExprIconsAllocDT(DTExprViewsAllocPlaceholderExprIconsAllocGraphconvert(, exp)R u8  ExampleNp Iconvert to expSyntax10.Scn.Fntp"ExprIconsAllocDT(DTExprViewsAllocPlaceholderExprIconsAllocGraphconvert(, exp)qExprSlangAlloc u8  ExampleГ< ExprSlangAlloc u8 Textb u8  Example\PIexpandSyntax10.Scn.Fntp"ExprIconsAllocDT(DTExprViewsAllocPlaceholderExprIconsAllocGraph expand()qExprSlangAlloc u8  Example0 ExprSlangAlloc u8 TextMlpExprSlangAlloc u8  ExampleA Isimplify powerSyntax10.Scn.Fnt p"ExprIconsAllocDT(DTExprViewsAllocPlaceholderExprIconsAllocGraphsimplify(, power, symbolic)$ u8  Example4ExprSlangAlloc u8  Example8)PExprSlangAlloc u8  Example`k*ExprSlangAlloc u8 TextON@` "convert to expSyntax10.Scn.Fntp"ExprIconsAllocDT(DTExprViewsAllocPlaceholderExprIconsAllocGraphconvert(, exp)Q "combine expSyntax10.Scn.Fntp"ExprIconsAllocDT(DTExprViewsAllocPlaceholderExprIconsAllocGraphcombine(, exp)7 u8  ExampleNp Iconvert to expSyntax10.Scn.Fntp"ExprIconsAllocDT(DTExprViewsAllocPlaceholderExprIconsAllocGraphconvert(, exp)$ u8  Example`M/pExprSlangAlloc u8  ExampleQ Icombine expSyntax10.Scn.Fntp"ExprIconsAllocDT(DTExprViewsAllocPlaceholderExprIconsAllocGraphcombine(, exp)- u8  ExampleE<pExprSlangAlloc u8  Example\lIfactorSyntax10.Scn.Fntp"ExprIconsAllocDT(DTExprViewsAllocPlaceholderExprIconsAllocGraph factor() u8  Example%ExprSlangAlloc u8 Text3IExprSlangAllocpExprSlangAlloc u8  ExampleC IargumentSyntax10.Scn.Fntp"ExprIconsAllocDT(DTExprViewsAllocPlaceholderExprIconsAllocGraph evalc(argument(convert(, exp)))$ u8  Example02 `ExprSlangAlloc u8  Example8`'ExprSlangAlloc u8  Example&ExprSlangAlloc u8  ExampleK Isolve in phiSyntax10.Scn.Fntp"ExprIconsAllocDT(DTExprViewsAllocPlaceholderExprIconsAllocGraph solve(, greek(phi)) u8  Example @~ExprSlangAlloc u8 Text)IExprSlangAlloczExprSlangAlloc  u8  ExampleVPIsolve in mSyntax10.Scn.Fntp"ExprIconsAllocDT(DTExprViewsAllocPlaceholderExprIconsAllocGraph solve(, m)@~ExprSlangAlloc u8  Examplep ExprSlangAlloc u8  Example\PInormalSyntax10.Scn.Fntp"ExprIconsAllocDT(DTExprViewsAllocPlaceholderExprIconsAllocGraph normal() u8  ExamplezExprSlangAlloc u8 Text(ExprSlangAllocIExprSlangAlloc u8 CenteredText5 ExprSlangAlloc ExprSlangAlloc8 u8 Title 8 u8 Text u8 Text1 Pt8 u8 Title8 u8 Textx8 Title 8 u8 Text Syntax12m.Scn.Fnt284Formula Manipulation using Maple Dominik Gruntz Institute for Scientific Computing, ETH Zrich, gruntz@inf.ethz.ch Preface This document is a reproduction of an article from The Maple Technical Newsletter, Issue 10. It has been rewritten to demonstrate the possibilities of documents using ExpressionIcons. Whereas the text has been kept in its original form, the presentation of the examples has been changed. The small examples of the first section are now given as tables consisting of three columns. The first column will contain a command - mostly in form of a maple script icon. The second column gives the operand. The expression that results from the application of the command to the operand can be found in the third column. The (inter-) active reader is encouraged to reproduce the results himself. Given, you set up the maple interface correctly, you could e.g. delete the expression from the third column of this text, copy the expression from the second column in its place, select this copy and activate the command in the first column to reproduce the result. Another possibility is to select directly the expression from the second column and activate the script thus reproducing the expressions of the third column for direct comparison. Maybe, you will want to make modifications to the operand and see how these influence the result. Of course, there are infinitely more possibilities for experimentation with this text. Introduction Apart from its powerful symbolic capabilities, Maple may also be used as a simple formula manipulator and may replace paper and pencil in this mode. Many commands to transform and simplify expressions are available for this task. For a good introduction we refer to chapter 7 of the book Introduction to Maple [2]. However, we made the experience that sometimes a user gets stuck with a particular expression which he easily could transform into another form by hand but not with the help of Maple. In this article we will present some tools which may be useful in such a situation. We will specially focus on the manipulation of subexpressions of a given expression. We will close the article with a demonstration of a small and nice problem, whose solution is derived mostly with the help of formula manipulations. Transformation Commands in Maple Maple offers a variety of commands to transform expressions into other forms and we give a brief overview of them in this section. All these commands work in their simplest form on the whole expression and decide themselves on which subexpressions they operate. convert The convert command allows one to explicitly transform an expression into a different form. This may be used for data-type conversions (list >. set, series >. polynom) or for form conversions (horner form, exponential form), especially for different representations of trigonometric functions.       expand The expand command in general distributes a function over a sum, a product or a power, as far as expansion rules are known. This includes the trigonometric functions, exp, ln and others.          Unfortunately, the manipulation commands are not always equivalence preserving and it is under the responsibility of the user, whether the application of a particular transformation is mathematically valid in his context or not. Consider the last two examples above: Both transformation are only valid for  <  # . If we e.g. set a = b = -1 and e =  then we can construct some famous proofs that  from each of the previously derived equations  and : ExprTools.Substitute a => -1 b => -1 e =>    ExprMaple.Eval   ExprTools.Substitute a => -1 b => -1   ExprMaple.Eval   combine The combine command is the opposite to the expand command. It tries to combine terms in sums, products and powers into a single term. The terms which should be combined in an expression must be specified with a second argument like trig, exp, ln, etc. As for expand, the combine transformations are performed regardless of correctness.       simplify The simplify command is a general purpose simplification routine which tries to find the simplest form of an expression; because of that it also knows some special transformation rules for specific functions such as the identities  and .       These are only the most important transformation commands. Others which we have not mentioned are normal, collect, factor, and of course the more specific functions such as isolate, student[changevar] (to perform a change of variable in integrals, sums or limits) or student[completesquare] (to complete squares of polynomials of degree 2). Manipulation of subexpressions In this section we will discuss how to apply a transformation to a specific part of a particular expression. Usually a single Maple command is not available for this purpose and the user must also have some basic knowledge of Maple data structures. All commands we mentioned in the last section may also work on complicated expressions and operate recursively on all subexpressions, but it is difficult to specify on which part they should operate if not on all. Consider the expression . On this expression we will apply the form conversion to exponential notation. This transformation may either be applied to the exponentiation operator ( >. ) or to the  term ( >. ). If the conversion command acts on the whole expression, both transformations are performed.    How must the command be guided to only operate on the desired parts? It turns out that essentially two different methods may be applied to transform subexpressions. The transformation is either applied to a node in the expression tree whose sub-trees will not be affected by the transformation command (e.g. transformations on leaves of the expression tree) or the node has sub-trees whose representations change when the transformation command is applied on them (e.g. the ^-node in ). In the first case the specific subexpression must be picked up and must be replaced by the result of the application of the transformation command onto it. For the selection of the subexpression a sequence of op commands may be used. The expression may be restored by hand or better using the subs command. For example, the transformation of  into  can be performed with the commands ExprMaple.Eval     The drawback of using subs is that all occurrences of  are transformed. In our particular example the goal may also be achieved using the map command. map(f, ) applies the function f to all operands of . In the above example we can perform the desired transformation with the command    The specified function is applied both on the basis and the exponent of the power. The basis is converted as intended and the transformation has no affect on the exponent. If on the other hand the transformation is applied to a node in the expression tree where one of its sub-trees would also be affected by the transformation command, other tools must be used. One solution is to convert back the unwanted transformations, but this is awful and may not always work. What one really needs is a way to temporary freeze those subexpressions, i.e. to replace them by a name. The frontend command is employed to temporarely freeze subexpressions to unique names, to apply a specified procedure and to finally thaw the frozen names. For example, with the following commands we convert the exponential operator of the expression  to exp-log notation without affecting the cos(x) term.    The third argument to frontend, a list of two sets, specifies how to freeze the arguments. The first set specifies types and the second one expressions not to be frozen. The default is [{`+`,`*`},{\}]}, [{`+`,`*`},{}], i.e. the expression is converted into a rational function. The expand command itself offers a possibility to prevent the expansion of particular non-rational functions in an expression. These subexpressions may be specified directly of by a function name. Consider the expression  which we will expand in different ways using both the frontend command and the extended interface to expand.                Note that all the transformation tools we discussed in this section only work when the subexpression on which one operates can be specified by a sequence of op commands, i.e. is a proper subexpression in the Maple data structure. For example the subexpression  in the sum  does not meet this condition and more powerful substitution commands must be used. We refer at this place to the procedures asubs and student[powsubs] without going into detail. A Case Study In this section we solve problem 1065 proposed by H. Stocker in the Elemente der Mathematik [1], a journal published in Switzerland and directed to teachers of mathematics. The solution cannot be obtained by a simple Maple command, but by applying a sequence of formula transformations of the types described in the last two sections. Problem For which values of  N ! are the following vectors (with ) linearly dependent? , , ..., ,  Solution This problem is equivalent to the problem, for which values of  the determinant of the tridiagonal, symmetric matrix  is zero. Maple cannot be used to compute the determinant of  directly (for a symbolic n), but it is easy to see, that the determinant  meets the following recurrence equation.     This recurrence equation can be solved with the help of Maple. ExprMaple.Eval        ExprTools.Substitute  => w   Thus, for s 9 12 we get the solution (1)  where . For  the solution of the recurrence equation is  and for  we get . ExprMaple.Eval     ExprMaple.Eval     One conclusion we can draw from this result is, that  only for s 9 12. Since  we conclude, that  9  for m N Z. It remains to solve equation (1) for s 9 12. The condition  can be transformed into the equation (2) . We substitute back for w and  for s and try to simplify equation (2) step by step. ExprTools.Substitute w =>  s =>    First we replace  by  using the  command. Since we want to simplify both sides of the equation, we could use the map command, but simplify itself maps onto the equation.  applied to each    Additionally we simplify the square roots of the squares. As we have seen, this operation may introduce sign errors and hence we must assure that its application is valid. It turns out that the result will be correct since the left hand side and the right hand side of the equation are conjugates and hence it is not of importance which sign is taken.  applied to the bases rised to    We then convert  1  to exponential notation. One way to perform this simplification is to apply  at the second level of the expression tree (i.e. to the sums within the powers).  applied to the bases rised to    In addition we expand the sums of exponentials, which will simplify the expression significantly.  applied to the bases rised to    Now we can combine the exponentials and the power and divide by the constant .  applied to each side of the equation   ExprMaple.Eval     Next we convert the left hand side also into an exponential using the commands  and  and finally factor the arguments of the exponentials.  applied to each side of the equation    applied to the left hand side of the equation    applied to both exponents   This equation still must be solved with respect to . Since the absolute value of the two complex numbers on both sides of the equation are 1, we can equate the arguments of both sides. Additionally we add an integer multiple of  to the right hand side.  applied to each side of the equation   ExprMaple.Eval        for k N Z. According to the precondition that s 9 12 we must assure that  9  for any m N Z.        Hence, only those k are valid for which  O Z. The overall solution for  then becomes  Rk N Z where  O Z. Conclusion We have seen, that it is not always easy to find the right commands to transform an expression into the desired form. On the one hand there are numerous transformations which may be applied to an expression and hence the overview in the thicket of commands may be lost very soon. On the other hand, it is often difficult to predict, which side effects a command will have, i.e. which parts of the expression will also be affected by the transformation command. We think, that it would be very useful to have a graphical user interface which allows to simplify an expression in place (similar to the edit function). One could then select with the mouse the node where the transformation should be applied and convert it in place. In addition these conversion procedures should exactly operate on the specified node and not affect its subexpressions. This would be an easy to understand and easy to use model, which would make Maple even more powerful as a formula manipulator. Acknowledgments I would like to thank G. Gonnet, M. Mongagan and W. Weck for careful reading and many valuable comments on this article. References [1] Elemente der Mathematik. 47: p. 128, Birkhuser, Basel, (1992). [2] A. Heck: Introduction to Maple.Springer-Verlag, (1993).