Preface

This section discusses the structure of Maxima expressions. It does not discuss the functions used to create and manipulate expressions, or the detailed mathematical or programming semantics of operations.

Maxima expressions

Maxima expressions are native numbers, symbols, or lists.

Numbers

Native Lisp numbers represent themselves. Currently, Maxima uses only native integers and floating-point numbers, and does not use or support native rationals and complexes. Maxima normally uses full/double-precision native floating-point numbers (1.0d0).

Symbols

Symbols represent simple symbolic constants or variables. (Note that the term "constant" in Maxima normally includes not just simple symbolic constants such as %PI, but also numbers and expressions involving only numbers and constants, such as 2/3*%PI.) For the representation of subscripted variables, see below under "The ARRAY flag".

The Maxima symbol X is normally represented as the Lisp symbol $X. There are some special cases, using the ALIAS mechanism (qv). For example, the Maxima symbols TRUE, FALSE, and LAMBDA are represented by the Lisp symbols T, NIL, and LAMBDA. Certain mathematical functions are named as %function rather than $function, following the noun/verb scheme (qv).

Constants such as $%I (in Maxima, %I), $%PI, and $%E are symbols with the Maxima property (qv) $CONSTANT.

Structured objects

Lists represent all other structured objects. They are always of the form:

( ( operator flags... ) arguments... )

The operator, a symbol, indicates the type of object, the flags the properties of the object (checked with MEMQ), and the arguments any constituent parts of the object.

Most operators denote the application of a function or relation to its arguments. Some operators represent programming constructs like assignments or loops. In both those cases, the arguments are themselves Maxima expressions. But several special operators indicate special representations, where the arguments in the CDR are not Maxima expressions and are only meaningful to the modules responsible for the special representation. The contents of the CDAR usually have special meanings, and usually do change the meaning of the expression, unlike flags for non-special operators.

Special operators: RAT, BIGFLOAT, MRAT, and MPOIS

In expressions built with special operators, both the CDAR (other than the SIMP flag) and the CDR of the expression should be treated as opaque, and only manipulated by their own modules.

RAT denotes a rational number: ((RAT) x y) is the rational number x/y. The only flag used with RAT is SIMP. ((RAT SIMP) x y) is in reduced form -- that is, GCD(x,y). (xref rat)

BIGFLOAT denotes a multiple-precision floating point number. ((BIGFLOAT SIMP? prec) mantissa shift), where prec, mantissa, and shift are integers, denotes the number mantissa × 2(shift-prec), to precision prec bits. (xref bigfloat) Normally, the mantissa is normalized to the range 2prec-1 .. 2prec-1, but this is not guaranteed, even with the SIMP flag on. No other flags are used with BIGFLOAT.

MRAT denotes a Canonical Rational Expression (CRE), which may represent a rational function or an extended Taylor series. (xref CRE) The SIMP and TRUNC flags are used with MRAT. Besides these flags, MRAT also stores internal data (variable list and so on) in the CAR. Curiously, the various factorization flags (factored, irreducible, etc.) are *not* used with MRAT, even with RATFAC:TRUE.

MPOIS denotes a truncated Poisson series expression. (qv)

General operators

All other operators denote the application of a function to its arguments, or a Maxima programming language construct (e.g. DO). In these cases, the arguments are also Maxima expressions. Functions include not only functions written in prefix form (log(x)), but also functions with special syntax (x!), and arithmetic operators such as addition, multiplication. Associative operators are normally represented as n-ary functions.

Note that functions and operators which have special syntax have = special names. Users can also define their own infix and prefix operators = (qv).

Lisp syntaxMaxima syntax
Arithmetic operators
((MPLUS) a b ...) a+b+...
((MTIMES) a b ...) a*b*...
((MEXPT) a b) a**b
((MEXPT) a b) a^b
((MQUOTIENT) a b) a/b Not used in simplified expressions
((MNCTIMES) a b ...) a . b . ...
((MNCEXPT) a b) a^^b
Unary arithmetic operators
((MMINUS) a) -a Not used in simplified expressions
((MUNARYPLUS) a) +a Not used in simplified expressions
((MFACTORIAL) a) a!
Relational operators
((MEQUAL) a b) a = b
((MNOTEQUAL) a b) a # b
((MGREATERP) a b) a > b
((MLESSP) a b) a < b
((MGEQP) a b) a >= b
((MLEQP) a b) a <= b
Definitional operators
((MSETQ) a b) a : b
((MSET) a b) a :: b
((MDEFINE) a b) a := b
((MDEFMACRO) a b) a ::= b
Miscellaneous operators
((MLIST) a ...) [ a, ... ]
((MQUOTE) a) 'A
((MCOMMA a b) a , b Used only on output
((MANGLE) a ...) <a ...> Used only on output
((MARROW) a b) a -> b Used only on output
Logical operators (executable)
((MAND) a b ...) a AND b AND ...
((MOR) a b ...) a OR b OR ...
((MNOT) a) NOT a
((MCOND) a b T d) IF a THEN b ELSE c
((MCOND) a b c d ...) IF a THEN b ELSEIF c THEN d ...ELSEIF currently doesn't print correctly, though it parses and evaluates correctly.
Program structure
((MPROGN) a b ...) ( a, b, ... )
((MDO) ...) WHILE ... DO ... details TBD
FOR ... FROM ... STEP ... THRU ... UNLESS ... DO ...
((MDOIN) ...) FOR ... IN ... THRU ... UNLESS ... DO ...

Indexed functions: MQAPPLY

Maxima requires the operator of an expression always to be a symbol so that it can easily dispatch on it. Thus, it cannot represent an indexed function such as BesselJ[2](z) as (((($BESSELJ) 2)) $Z) (illegal!). Instead, there is a special operator MQAPPLY which denotes the application of its first argument to its remaining arguments. So BesselJ[2](z) is represented as:

((MQAPPLY) (($BESSELJ) 2) $Z)
Note that MQAPPLY with a symbol first argument is simplified to the direct form, with the symbol in the CAAR.

Flags

The CDAR of structured objects is a null-terminated list of flags. Most flags are symbols, but arbitrary list structures are also permitted, and are used for example by MRAT. With the exception of the ARRAY flag (see below), and of flags in special representations, flags are advisory, and may be removed from an expression without any loss of information. In fact, the simplifier removes flags from expressions whenever it changes them. This means that flags are most useful to indicate properties of a particular form of an expression rather than a mathematical property of the function it denotes (e.g. everywhere differentiable). For example, the FACTORED flag indicates that the expression is fully factored, so the FACTOR routine will not try to re-factor it. But if the flag were not there, it would simply re-factor it and come up with the same result.

Flags should never be used to change the meaning of an expression or to make operators have multiple meanings. For example, if the MDOT operator . is being used to mean matrix multiplication, it would be exceedingly poor practice to have ((MDOT CROSSPRODUCT) ...) denote the vector cross-product.

The ARRAY flag

The ARRAY flag is an exception to the rule that flags do not modify the meaning of an expression, and may be discarded. The expression

( ( name ARRAY ) index... )
denotes the array reference name[index, ...] as opposed to the function call name(index, ...). The ARRAY property must never be removed from an expression. Moreover, many functions which recurse over expressions treat array references differently from function applications.

Flags used in Maxima

Here is a list of the normal flags used by Maxima.

SIMP Expression is simplified.
RATSIMP Expression has been simplified by $RATSIMP
IRREDUCIBLE Expression is irreducible over the integers (cf FACTOR).
IRREDUCIBLEG Expression is irreducible over the Gaussian integers (cf GFACTOR).
FACTORED Expression is factored over the integers (cf FACTOR).
GFACTORED Expression is factored over the Gaussian integers (cf GFACTOR).
SQFR Expression is square-free (cf SQFR).
SQFRED Expression's factors are square-free (cf SQFR).
TRUNC Used only on MRATs to indicate that they are extended Taylor series.
CF This MLIST denotes a continued fraction (this violates the rule about changing the meaning of an operation). (cf CF)
MULT Used internally by the matrix package to indicate that a matrix is the result of multiplying two other matrices. Not visible outside the matrix package (?).