## Yet More Gems from the Little Red Book of Maple Magic

Maple

Each of my two previous two blog posts (Maple Gems, More Maple Gems) 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. Here are five more such "gems" that appeared in a Tips & Techniques column in a recent issue of the Maple Reporter.

Gem 11 - Picard Iterates

A basic existence and uniqueness theorem for the initial value problem , is based on the convergence of the Picard iterates . For example, the initial value problem

whose solution is

has Picard iterates given by the task template in Table 1.

Differential Equations_ODEs_Picard Iterates

Picard Iterates for the IVP

The function

 >
 (1.1)

Set

 >
 (1.2)

Set

 >
 (1.3)

Number of iterates

 >
 (1.4)

Picard Iterates

 >
 (1.5)
 >

Table 1   Picard iterates for

The limit of these iterates is not easy to deduce. However, the function in the gfun package provides the following resolution, which is the essence of this gem.

Experiment shows that  is the first iterate for which guessgf can determine the exact solution.

The task template in Table 2 implements the command interface(imaginaryunit=i); that sets  in place of the default . Clicking the OK button collapses the display.

Algebra_Complex Arithmetic_Set Imaginary Unit

Notation for Imaginary Unit

Table 2   Task template for setting the imaginary unit

For nonnegative , is an identity. One way to verify this algebraically in Maple is

=

However, it is not obvious that this equation is an identity only for . Figures 1 and 2 demonstrate one method of determining this condition. Figure 1 is a graph of the real part of the difference between

 and

while Figure 2 is a graph of the imaginary part of the difference.

Figure 1   Real part

Figure 2   Imaginary part

Figure 1 implies that  has to be real for the identity to hold, and Figure 2 shows that  has to be nonnegative. Of course, the gem is the use of graphs of the real and imaginary parts of a complex expression to determine its behavior over the complex plane.

 Gem 13 - A Factoring Trick By hand, it is trivial to factor  as . Simply factor the first three terms, ignoring the additive . In fact, my first attempts at this amounted to subtracting the , factoring, then adding back the . However, my colleagues provided the gem    = The collect command admits as an argument, a function that is to be applied to the coefficients after collection takes place. Using to apply factor to the first three terms is, indeed, a gem.

Gem 14 - A Sum-to-Product Trig Identity

For a basic trig identity such as

Maple converts the left side to the right via

=

and the right side to the left via

=

However, for the identity

Maple converts the right side to the left via

=

but struggles to convert the left side to the right. Table 3 summarizes calculations suggested for the conversion of the sum to the product.

 Table 3   Conversion of a trig sum to a product

Alternatives I hope my readers explore include and simplify (with side relations). I'll be sure to include (with attribution and admiration), the best of these in my Little Red Book.

Gem 15 - Sort Strategies

Over the years, I've dabbled with the command, using it to sort lists of real numbers, polynomials, and lists containing both real and complex numbers. Here's a summary of what I've learned about sort.

By default, sort can sort real numbers that are of type numeric. A number such as  is not of type numeric! (The following command verifies this assertion.)

=

Hence, a naive use of sort will fail on a list containing such exact expressions. Table 4 shows two lists, one with, and one without numbers that are all of type numeric. The sort command easily sorts on the first, but requires an auxiliary function for the second. For the second list, the second argument to sort must be a function that returns true if a comparison between two elements is ordered "correctly" and false if not.

 Table 4   Sorting lists of real numbers

Sorting a list containing both real and complex numbers presents more of a challenge. Of course, the complex field is not ordered, but if, say, the zeros of an equation are both real and complex and a unique ordering of these zeros is needed for the continuing computations, then some method of sorting the list of zeros has to be devised. Suppose the zeros are to be sorted in ascending order of the real parts, and if there are zeros with the same real part but different imaginary parts, sort these in ascending order of the imaginary part. This would give a unique order of such a list of zeros.

The procedure  defined below is a function that implements the appropriate comparisons.

If we use this function to sort the list

we get

Sorting the powers in a polynomial is actually easier than sorting "numbers", as we see in the following example.

Sorting a list of reciprocal powers of , such as

yields to a sort on degree (here, negative integers), as we see from

 (5.1)