Previous: Writing Programs in CL for Maxima Up: Helpful Hints to MAXIMA Programmers Next: A Complete Example

Expressions and Operations in CL under MAXIMA

The advantage of working in the Maxima CL base is speed and the availability of many existing mathematical functions. For example (div 'x 'y) will construct the symbolic expression


((mtimes simp) x ((mexpt simp) y -1))
which is in valid internal representation.

There is a set of functions to help create and simply symbolic mathematical expressions and aid doing arithmetics. To divide two integers a and b one uses (rat a b). For numbers a and b (integer, rational numbers, floating and bigfloats) use (addk a b), (timesk a b), for addition and multiplication. For general symbolic operands (including numbers) we have: addn, muln (ncmuln), power, sub, neg and div. Both addn and muln take a list as the first argument and a T or NIL flag as the second argument. For example,


(muln  (list a b (addn (list  c d) nil) nil)

should be used in a lisp program instead of


(simplifya (list '(mtimes) a b (list '(mplus) c d)) nil)

The second argument to addn or muln is called a simp-flag. This simp-flag is used to indicate whether the operands are already simplified (T if simplified).

Sometimes it is convenient to invoke a top-level macsyma function in a lisp program. For example the top-level command


kill(a,b,c)
can be done at the lisp level as

(mcall '$kill '$a '$b '$c)
Or, alternatively, one can do

(setq x (list '$a '$b '$c))
(mapply '$kill x '$kill)
Or yet another form is

(setq x (list ($kill) '$a '$b '$c))
(meval x)
By examining the internal value of a C-line you can easily find the correct CL-level form for any operation that can be invoked at the maxima top level.

farrell@mcs.kent.edu