Fully simplifiying Exp function



I have closed the bug SF[1247549] "noun/verb forms of erf and exp not treated
consistently", because the Erf function works as expected. But I was too fast.
The Exp function has still a different behavior. I had a further look at the Exp
function and would like to suggest to add the following code (perhaps to the
file simp.lisp):

(defprop %exp simp-exp operators)
(defprop $exp %exp alias)
(defprop %exp $exp reversealias)

(defun simp-exp (x y z)
  (oneargcheck x)
  (setq y (simpcheck (cadr x) z))
  (cond ((taylorize (mop x) (second x))) ; Check for taylor-expansion
        (t (simplifya (list '(mexpt) '$%e y) z)))) ; 

Now some results to show how this works:

Session 1: The old behaviour without any change

(%i4) %e^1.0;
(%o4) 2.718281828459045  

(%i5) exp(1.0);
(%o5) 2.718281828459045

(%i6) 'exp(1.0);
(%o6) 'exp(1.0)     /* no simplification to number */

The reason is that the parser does the following:

exp(1.0)  --->  (($exp) 1.0)
'exp(1.0) --->  ((%exp) 1.0)

The $exp-expression is numerically evaluated because we support a $exp function
which does the transformation to %e^1.0 which than simplifies to a number. But
we have no simplifying function for the expression %exp. The noun form for the
Exp function in not known by Maxima und can not be further handled.

Session 2: Adding a simplifying function

Now we get the expected simplification:

(%i5) exp(1.0);
(%o5) 2.718281828459045

(%i6) 'exp(1.0);
(%o6) 2.718281828459045

But now we pass the wrong number of arguments:

(%i7) exp(1.0,2.0);
Maxima encountered a Lisp error:

 Error in MACSYMA-TOP-LEVEL [or a callee]: MACSYMA-TOP-LEVEL [or a callee]
requires less than two arguments.

Automatically continuing.
To reenable the Lisp debugger set *debugger-hook* to nil.

(%i8) 'exp(1.0,2.);
Wrong number of arguments to exp
 -- an error.  To debug this try debugmode(true);

In one case we get a Lisp Error, the other case gives a Maxima Error.

The reason is, that the $exp expression which we get from the parser calls
directly the Lisp function $exp. This function does no check for the arguments
and gives therefore a Lisp Error. In the second case the %exp expression is
passed to the simplifying function which checks the number of arguments and
gives a Maxima Error.

3. Session: Add the properties Alias and Reversealias

At first again the expected numerical evaluation:

(%i10) exp(1.0);
(%o10) 2.718281828459045
(%i11) 'exp(1.0);
(%o11) 2.718281828459045

Now both examples with a wrong number of arguments:

(%i12) exp(1.0,2.0);
Wrong number of arguments to exp
 -- an error.  To debug this try debugmode(true);
(%i13) 'exp(1.0,2.0);
Wrong number of arguments to exp
 -- an error.  To debug this try debugmode(true);

We get in both cases a Maxima Error. When the Alias properties are defined the
parser transforms both expression to a %exp noun form. This noun form is then
simplified by simp-exp which checks the arguments. The Maxima User never calls
the $exp function. It is no longer necessary to support this function for a
Maxima User. 

But: When correctly implemented the $exp function has a very nice feature.
Instead of writing 

  (simplify (list '(%exp) x)

or using other shortcuts or macros you can write

  ($exp x)

in Lisp code. The $exp function does the right, save and complete simplification
of the expression. It works for all Maxima numbers and expressions:

A complete $exp function would be

(defun $exp (x)
  (simplify '(%exp) (resimplify x)))

To be complete, the $exp function does a bit more than the code (simplify
(...)). It does a resimplify of the argument. This might be an extra call to the
simplifier for the argument, because the simp-flags are ignored when calling
resimplify, but on the other side this resimplify ensures that we pass a well
formed Maxima expression to the code of Maxima. Perhaps a lot of subtle problems
migth vanish if we always let the simplifier do the the work.

Sorry, because of the long posting. But it might be, that a lot of noun/verb
confusion has its origin in not complete implemented noun/verb/alias properties
of a lot of functions. E.g. one further known problem is the wrong
linear-display of functions which are not fully implemented.

I have tested the full implementation of the Exp function with the testsuite. As
expected there are no problems.

Dieter Kaiser