Classroom Tips and Techniques: The One and TwoArgument Arctangent Functions in Maple
Robert J. Lopez
Emeritus Professor of Mathematics and Maple Fellow
Maplesoft

Introduction


Computational computer languages such as FORTRAN provide the functions and for the one and twoargument arctangent functions, respectively. Maple's single arctan function accepts accepts either one or two arguments. The range of Maple's oneargument arctan consists of quadrants 1 and 4, whereas the range of the twoargument arctan is .
In general, a "conversion" between these two forms of the arctangent function is not mathematically correct. However, we will give two instances of calculations that benefit from a formal interchange of these two functions. The challenge is to devise an efficient tool for making the swap in what can be a complicated expression. Our search for such a tool will illustrate some Maple programming strategies.


Example 1


The most recent need I had for changing the twoargument arctangent to the oneargument version arose when I discovered that Maple's solve command was stumped by the equation

(1) 

but not by

(2) 

The simplest way to convert to is by editing: simply change the comma to a division stroke, and move the second argument to the denominator. Indeed, if this is done, we have
(Note: Cells tinted in yellow contain hidden input. To see such input, select "Show Input" in the Table Properties dialog.)


Example 2


The Dirichlet problem on the first quadrant where has a formal solution given by
If , this integral evaluates to

(3) 

Flow lines for this potential function are the integral curves of the differential equations
where is the parameter along the integral curve and subscripts denote differentiation. The initial conditions are given at , so there is an immediate divisionbyzero error when numerically integrating these equations. The oneargument arctangents must be changed to the twoargument form, since
Numeric integration can then proceed. In the Advanced Engineering Mathematics ebook, the transformation was initially made by bruteforce substitutions. It has since been replaced by one of the strategies discussed below.


Changing from the OneArgument to the TwoArgument Function


Consider the following simple tool:

(4) 
It appears to convert to = . Indeed, there may be applications where this is all that is needed. However, applying to something like will generate an error:
There are other shortcomings of . For example, while = is a valid result, = is not. Moreover, is not robust in other ways: , , and all generate an error message, while
=
is only partly transformed. So, must be modified if it is to be more robust. Here is a second version, but it uses two functions, one to define the transformation, and another to impose it.
Since = , we see that one shortcoming of has been corrected.
Of course, the immediate question now is whether or not a single function can both define and apply the required transformation. The programmer who suggested then provided , defined as follows.
We test with the following calculation.
=
Indeed, is robust  it correctly handles multiple and nested arctangent functions, and maps across expressions and equations. Moreover, = , and = , so is considerably more robust than .
However, another programmer raised an eyebrow at , and offered a "oneliner" on the order of
The help page of the evalindets command says it transforms all subexpressions of a given type. The first argument is the expression to be transformed; the second, is the type of the subexpressions that will be transformed; and the third, is the "transformer."
That succeeds is seen from such calculations as = , = , = , and
=
Of course, we would also have

(5) 
the result needed for the integration in Example 2.


Changing from the TwoArgument to the OneArgument Function


Corresponding to that was designed to take to , we have
that should take to . It works, but with shortcomings similar to those in , as we see from = , but = , etc. In fact, applying to results in a divisionbyzero error. Clearly, this version of the function is too naive. Hence, we have the pair of functions
and
This pair of functions corrects the defects in , as we see with the calculations in Table 1.
But of course, we want just a single function to do the work of these two, so is defined as
and we have the results in Table 2.
Finally, to show once again the various styles of Maple programming, we define the "oneliner" as
and illustrate its use in Table 3.
That either or will suffice for the transformation needed in Example 1, is seen with
and


A Notational Surprise


In forming the functions , and , the operator is applied to the op function. It was a surprise to see a difference in the behavior of this construction when it is typed in text mode (i.e., "1D math") or math mode (i.e., "2D math"). Typed in text mode, we have
but typed in math mode, we have = . Thus, the coding fails if implemented in math mode. Since this construction is used in the definitions of the functions , and , they are made in text mode, with the input hidden in a table cell.
The Maple programmer who wrote the Typesetting package upon which Maple's math mode rests, gave the following "explanation" of this difference.
"The `/` operator, together with the `*`,`+`,`` and `^` operators (to name a few), bind at parse time for 2d math, but not 1d math. This means that in 2d math `/`(op(a)) is interpreted as the unary `/` function... the parser identifies the number of arguments based upon the expression rather than the evaluation of the expression, and matches accordingly. Read this as 'forming argument sequences using 'op' for any function with special rules will not work as expected.'"

Legal Notice: © Maplesoft, a division of Waterloo Maple Inc. 2010. 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 noncommercial, nonprofit use only. Contact Maplesoft for permission if you wish to use this application in forprofit activities.
