# [Maxima] Best practice for defining special functions?

Dieter Kaiser drdieterkaiser at web.de
Wed Dec 3 16:42:25 CST 2008

```Hello David,

I have send my last Email not to the list and lost it. Thus I am writing
again.

This year we had two discussions on the mailing list with the topics:
"linear display not correct" and "laplace w 1d display". The problem is
that we do not get a correct linear display of functions when the
properties ALIAS and REVERSEALIAS are not defined. But there are further
side effects of this definitions.

I have tried to summarize some points for different implementations of
functions:

Case 1: Simplifying function, noun, verb and alias on property list

A lot of functions like sin, cos, log, gamma... have a noun,verb and an alias on
the property list. I think that was the way in early times all functions were
implemented. This functions work with linear display. The parser does the change
from \$function -> %function. The Maxima User never calls the corresponding Lisp
function. The argument check is done by the simplifying function. A wrong number
of arguments gives a Maxima Error. Quoting does not prevent simplification:
'(sin 1.0)) is evaluated. The \$-function can only be called within Lisp code
e.g. (\$log arg) is equivalent to (simplifya (list '(%log) (resimplify arg) t).

Case 2: Simplifying functions and no entries on the property list
e.G. bessel_j, airy_ai, elliptic_ec

The parser returns ((\$function) <args>). The transformation to the Noun-form is
done by a supplied \$-Lisp-function. A Maxima user calls directly the Lisp
function. Linear display has problems. Quoting prevent evaluation
'(bessel_j(1,0.5) -> bessel_j(1,0.5). A call with a wrong number of arguments
causes Lisp Errors or strange effects.

Case 3: No simplifying function supported
e.g. realpart, cabs, hermite, ...

Only a \$-function. Noun form is not supported. The parser returns ((\$function)
<args>). No problems with linear display. A Maxima User calls directly the Lisp
function. Lisp Error when called with wrong number of arguments. No
automatically simplification of forms like '(realpart(1)).
Sometimes a noun form is introduced in a returned expression e. g. ((%realpart)
arg) when evaluation is not possible. This noun form is not known by Maxima.
Linear display has problems with this noun form. In other cases e. g. hermite
something like ((\$function simp) <args>) is returned.

Case 4: Simplifying functions and no entries on the proberty list
\$-function defined with defmspec, e.g. sum, lsum and product

Like Case 2 but argument check by the Maxima mfexpr*-function and Maxima Error
when called with wrong number of arguments. No call of a Lisp function by the
Maxima User. This mechanism is used for Maxima User functions like save,
batch,....

There are further variations (see \$integrate, \$diff). But I think most of the
Maxima User functions fit in one of the above cases.

Dieter Kaiser

```