Application Center - Maplesoft

# Classroom Tips and Techniques: More Gems from the Little Red Book of Maple Magic

You can switch back to the summary page by clicking here.

Classroom Tips and Techniques:  More Gems from the Little Red Book of Maple Magic

Robert J. Lopez

Emeritus Professor of Mathematics and Maple Fellow

Maplesoft

 Introduction Last month's article contained five "gems" from my Little Red Book of Maple Magic, a red ring-binder in which I record those wonderful bits of Maple functionality that I glean from interacting with the Maple programmers in the building. This month, I'm sharing five more gems.
 Gem 6 Often, when using an if-statement to make a comparison between exact numbers such as  or , I'd find that Maple couldn't determine if the comparison were true or not. The cure I would then use would be to apply the evalf command so that the comparison would be between floating-point numbers. Not so long ago I asked why the following version of the if-command generated the error shown.   What I learned is that the if-statement can only make comparisons between "numbers" and that  is not a number. It is an "unevaluated function call." Similarly,  is a "symbol" and , the exponential "e," is a function. I then learned that modifying the if-statement to include the is command works. Thus, Similarly, we would also have
 Gem 7 In math mode, typing the numeral 4, followed immediately by a name such as , produces the product . In math mode, typing the numeral 4, followed immediately by a parenthesized expression such as  produces the product . If  is defined in Maple as a function, then  evaluates to the number 6. In math mode, if  is followed immediately by the parenthesized expression , the result is 6, not .   Why is this? Why isn't  evaluated to ?   The answer is that  is "parsed, but not evaluated." Since  does not then evaluate to a number, Maple can't apply the default Typesetting rule that treats  as a product, and not as the constant function 4 evaluated at . This default rule can be modified by the command     in which case  reverts to the constant function 4 evaluated at .   The default setting is probably the preferred one, but in this case (arising from the equation of a tangent line), care must be taken to provide some form of explicit multiplication, either with a space, or with the asterisk.

Gem 8

Not long ago I was asked how to replace the product  with  in an expression such as

Table 1 contains three different answers that I was able to provide.

 Brute-force replacement = Use of simplify with side relations (siderels) = Use of algsubs command = Table 1   Three ways to replace a product with a single name

The algsubs command was designed for this type replacement. However, it handles only one replacement at a time. Multiple replacements require multiple applications of the command.

Gem 9

Attaching assumptions to variables with the assume command has on-going effects because the variable with the assumption is different from the same variable without the assumption. Once the assuming facility because available, I made exclusive use of it because it allows "local" or "in-place" assumptions that are active only for the duration of a given calculation.

However, a recent dialog about assumptions on table elements caught my attention. Recall that in Maple, the subscripted variable  is actually an element of a table whose name is . Hence, my interest in the two questions  raised.

Question 1: Can separate assumptions be made on subscripted variables?

Answer 1: Yes. Table 2 gives an example, and shows how to verify that the assumptions are indeed attached.

 • Use assume to make assumptions on  and .

 • Verify the assumption on .

 Originally x[1], renamed x~[1]:   is assumed to be: RealRange(-infinity,Open(0))
 • Verify the assumption on .

 Originally x[2], renamed x~[2]:   is assumed to be: RealRange(Open(0),infinity)
 • Alternate verification with signum.

=

Table 2   Making and verifying separate assumptions on subscripted variables

The last line in Table 2 illustrates the use of the tilde (w) as an element-wise operator to map operations onto members of, for example, a list. This in itself is a useful gem to keep in mind.

These assumptions cannot be selectively removed. The complete table must be cleared of assumptions, as we see in Table 3.

 • Use the unassign command.

 • Verify that  carries no assumption.

 • Verify that  carries no assumption.

 • Use signum to examine both members of the table.

=

Table 3   Removal of assumptions on table members

So again, an assumption on a single table member can't be selectively removed. Assumptions on all table members must be removed at the same time. However, Table 4 shows that the assuming facility makes assumptions "in-place."

 • Assumptions made "in-place" on table members.

 • Verify that no assumption remains attached to a table member.

y[1]:

Table 4   In-place assumptions by means of assuming

Gem 10

The following investigation started with an example of directional derivative, computed stepwise, without having to load any supplementary packages. Table 5 summarizes the calculations whose results are at issue.

 • Type  for some expression in  and

 • Matrix palette: 2 × 1 column-vector template
 • Expression palette: partial derivative template Press the Enter key.

 • Context Menu: Evaluate at a Point_

 • Context Menu: Assign to a Name_N

The next step in computing a directional derivative is the dot product of the gradient with the direction vector. No need to introduce the direction vector here. Just compute  to see the result.

=

Table 5   Behavior of vector inserted from the Matrix palette in math mode

References to the vector N, supposedly , are in terms of the evaluated derivatives that constitute the gradient. The overbars denote conjugation because Maple's dot product sees only symbols that could, perhaps, be complex. Fortunately, a call to simplify in the Context Menu results in the correct value of the dot product.

So the challenge is implementing these same mathematical steps without having the dot product echo in terms of . The Maple magic is to define the gradient vector with angle brackets, or to use the Matrix palette in text mode. These forms of the calculation are summarized in Tables 6 and 7.

 • Type the expression shown to the right. Use inequality signs for the angle brackets, and use the partial derivative operators from the Expression palette.
 • Press the Enter key.

 • Context Menu: Evaluate at a Point_

 • Context Menu: Assign to a Name_F

 • Type the dot product notation.
 • Context Menu: Evaluate and Display Inline

=

Table 6   Gradient vector constructed with angle brackets

Apparently, the difficulty shown in Table 5 occurs when the Matrix palette is used in math mode. Table 7 shows these same calculations with the Matrix palette used in text mode.

 • Matrix palette: 2 × 1 column-vector template
 • Expression palette: partial differentiation operator
 > Vector[column]([ diff(f,x) ,                  diff(f,y) ]);
 (1)
 • Expression palette: evaluation template
 • Context Menu: Evaluate and Display Inline
 • Context Menu: Assign to a Name_A

=

 • Type the dot product notation
 • Context Menu: Evaluate and Display Inline

=

Table 7   Behavior of Matrix palette in text mode

Legal Notice: © Maplesoft, a division of Waterloo Maple Inc. 2011. Maplesoft and Maple are trademarks of Waterloo Maple Inc. This application may contain errors and Maplesoft is not liable for any damages resulting from the use of this material. This application is intended for non-commercial, non-profit use only. Contact Maplesoft for permission if you wish to use this application in for-profit activities.