Lisp and Maxima
===============

Maxima is written in Lisp, and it is easy to access Lisp functions and variables from Maxima and vice versa. Lisp and Maxima symbols are distinguished by a naming convention. A Lisp symbol which begins with a dollar sign $ corresponds to a Maxima symbol without the dollar sign. A Maxima symbol which begins with a question mark ? corresponds to a Lisp symbol without the question mark. For example, the Maxima symbol foo corresponds to the Lisp symbol $foo, while the Maxima symbol ?foo corresponds to the Lisp symbol foo, Note that ?foo is written without a space between ? and foo; otherwise it might be mistaken for describe ("foo").

Hyphen -, asterisk *, or other special characters in Lisp symbols must be escaped by backslash \ where they appear in Maxima code. For example, the Lisp identifier *foo-bar* is written ?\*foo\-bar\* in Maxima.

Lisp code may be executed from within a Maxima session. A single line of Lisp (containing one or more forms) may be executed by the special command :lisp. For example,

     (%i1) :lisp (foo $x $y)

calls the Lisp function foo with Maxima variables x and y as arguments. The :lisp construct can appear at the interactive prompt or in a file processed by batch or demo, but not in a file processed by load, batchload, translate_file, or compile_file.

The function to_lisp() opens an interactive Lisp session. Entering (to-maxima) closes the Lisp session and returns to Maxima.

Lisp functions and variables which are to be visible in Maxima as functions and variables with ordinary names (no special punctuation) must have Lisp names beginning with the dollar sign $.

Maxima is case-sensitive, distinguishing between lowercase and uppercase letters in identifiers, while Lisp is not. There are some rules governing the translation of names between Lisp and Maxima.

 1. A Lisp identifier not enclosed in vertical bars corresponds to a Maxima identifier in lowercase. Whether the Lisp identifier is uppercase, lowercase, or mixed case, is ignored. E.g., Lisp $foo, $FOO, and $Foo all correspond to Maxima foo.

 2. A Lisp identifier which is all uppercase or all lowercase and enclosed in vertical bars corresponds to a Maxima identifier with case reversed. That is, uppercase is changed to lowercase and lowercase to uppercase. E.g., Lisp |$FOO| and |$foo| correspond to Maxima foo and FOO, respectively.

 3. A Lisp identifier which is mixed uppercase and lowercase and enclosed in vertical bars corresponds to a Maxima identifier with the same case. E.g., Lisp |$Foo| corresponds to Maxima Foo.

The #$ Lisp macro allows the use of Maxima expressions in Lisp code. #$EXPR$ expands to a Lisp expression equivalent to the Maxima expression EXPR.

     (msetq $foo #$[x, y]$)

This has the same effect as entering

     (%i1) foo: [x, y];

The Lisp function displa prints an expression in Maxima format.

     (%i1) :lisp #$[x, y, z]$
     ((MLIST SIMP) $X $Y $Z)
     (%i1) :lisp (displa '((MLIST SIMP) $X $Y $Z))
     [x, y, z]
     NIL

Functions defined in Maxima are not ordinary Lisp functions. The Lisp function mfuncall calls a Maxima function. For example:

     (%i1) foo(x,y) := x*y$
     (%i2) :lisp (mfuncall '$foo 'a 'b)
     ((MTIMES SIMP) A B)

Some Lisp functions are shadowed in the Maxima package, namely the following.

complement, continue, //, float, functionp, array, exp, listen, signum, atan, asin, acos, asinh, acosh, atanh, tanh, cosh, sinh, tan, break, and gcd.

Garbage Collection
==================

Symbolic computation tends to create a good deal of garbage, and effective handling of this can be crucial to successful completion of some programs.

Under GCL, on UNIX systems where the mprotect system call is available (including SUN OS 4.0 and some variants of BSD) a stratified garbage collection is available.   This limits the collection to pages which have been recently written to.    See the GCL documentation under ALLOCATE and GBC.   At the Lisp level doing (setq si::*notify-gbc* t) will help you determine which areas might need more space.

Documentation
=============

The Maxima on-line user's manual can be viewed in different forms. From the Maxima interactive prompt, the user's manual is viewed as plain text by the ? command (i.e., the describe function). The user's manual is viewed as info hypertext by the info viewer program and as a web page by any ordinary web browser.

example displays examples for many Maxima functions. For example,

     (%i1) example (integrate);

yields

     (%i2) test(f):=block([u],u:integrate(f,x),ratsimp(f-diff(u,x)))
     (%o2) test(f) := block([u], u : integrate(f, x),

                                              ratsimp(f - diff(u, x)))
     (%i3) test(sin(x))
     (%o3)                           0
     (%i4) test(1/(x+1))
     (%o4)                           0
     (%i5) test(1/(x^2+1))
     (%o5)                           0

and additional output.

Functions and Variables for Help
================================

 -- Function: demo (FILENAME)
     Evaluates Maxima expressions in FILENAME and displays the results. demo pauses after evaluating each expression and continues after the user enters a carriage return. (If running in Xmaxima, demo may need to see a semicolon ; followed by a carriage return.)

     demo searches the list of directories file_search_demo to find filename. If the file has the suffix dem, the suffix may be omitted. See also file_search.

     demo evaluates its argument. demo returns the name of the demonstration file.

     Example:

          (%i1) demo ("disol");

          batching /home/wfs/maxima/share/simplification/disol.dem
           At the _ prompt, type ';' followed by enter to get next demo
          (%i2)                      load(disol)

          _
          (%i3)           exp1 : a (e (g + f) + b (d + c))
          (%o3)               a (e (g + f) + b (d + c))

          _
          (%i4)                disolate(exp1, a, b, e)
          (%t4)                         d + c

          (%t5)                         g + f

          (%o5)                   a (%t5 e + %t4 b)

          _
          (%i5) demo ("rncomb");

          batching /home/wfs/maxima/share/simplification/rncomb.dem
           At the _ prompt, type ';' followed by enter to get next demo
          (%i6)                     load(rncomb)

          _
                                       z         x
          (%i7)               exp1 : ----- + ---------
                                     y + x   2 (y + x)
                                    z         x
          (%o7)                   ----- + ---------
                                  y + x   2 (y + x)

          _
          (%i8)                     combine(exp1)
                                    z         x
          (%o8)                   ----- + ---------
                                  y + x   2 (y + x)

          _
          (%i9)                     rncombine(%)
                                       2 z + x
          (%o9)                       ---------
                                      2 (y + x)

          _
                                       d   c   b   a
          (%i10)                exp2 : - + - + - + -
                                       3   3   2   2
                                    d   c   b   a
          (%o10)                    - + - + - + -
                                    3   3   2   2

          _
          (%i11)                    combine(exp2)
                                2 d + 2 c + 3 (b + a)
          (%o11)                ---------------------
                                          6

          _
          (%i12)                   rncombine(exp2)
                                2 d + 2 c + 3 b + 3 a
          (%o12)                ---------------------
                                          6

          _
          (%i13)

 -- Function: describe (STRING)
 -- Function: describe (STRING, exact)
 -- Function: describe (STRING, inexact)

     describe(STRING) is equivalent to describe(STRING, exact).

     describe(STRING, exact) finds an item with title equal (case-insensitive) to STRING, if there is any such item.

     describe(STRING, inexact) finds all documented items which contain STRING in their titles. If there is more than one such item, Maxima asks the user to select an item or items to display.

     At the interactive prompt, ? foo (with a space between ? and foo) is equivalent to describe("foo", exact), and ?? foo is equivalent to describe("foo", inexact).

     describe("", inexact) yields a list of all topics documented in the on-line manual.

     describe quotes its argument. describe returns true if some documentation is found, otherwise false.

     See also Documentation.

     Example:

          (%i1) ?? integ
           0: Functions and Variables for Elliptic Integrals
           1: Functions and Variables for Integration
           2: Introduction to Elliptic Functions and Integrals
           3: Introduction to Integration
           4: askinteger  (Functions and Variables for Simplification)
           5: integerp  (Functions and Variables for Miscellaneous Options)
           6: integer_partitions  (Functions and Variables for Sets)
           7: integrate  (Functions and Variables for Integration)
           8: integrate_use_rootsof  (Functions and Variables for
              Integration)
           9: integration_constant_counter  (Functions and Variables for
              Integration)
           10: nonnegintegerp  (Functions and Variables for linearalgebra)
          Enter space-separated numbers, `all' or `none': 7 8

           -- Function: integrate (<expr>, <x>)
           -- Function: integrate (<expr>, <x>, <a>, <b>)
               Attempts to symbolically compute the integral of <expr> with
               respect to <x>.  `integrate (<expr>, <x>)' is an indefinite
               integral, while `integrate (<expr>, <x>, <a>, <b>)' is a
               definite integral, [...]

           -- Option variable: integrate_use_rootsof
               Default value: `false'

               When `integrate_use_rootsof' is `true' and the denominator of
               a rational function cannot be factored, `integrate' returns
               the integral in a form which is a sum over the roots (not yet
               known) of the denominator.
               [...]

     In this example, items 7 and 8 were selected (output is shortened as indicated by [...]. All or none of the items could have been selected by entering all or none, which can be abbreviated a or n, respectively.

 -- Function: example (TOPIC)
 -- Function: example ()
     example (TOPIC) displays some examples of TOPIC, which is a symbol (not a string). Most topics are function names. example () returns the list of all recognized topics.

     The name of the file containing the examples is given by the global variable manual_demo, which defaults to "manual.demo".

     example quotes its argument. example returns done unless there is an error or there is no argument, in which case example returns the list of all recognized topics.

     Examples:

          (%i1) example (append);
          (%i2) append([x+y,0,-3.2],[2.5E+20,x])
          (%o2)             [y + x, 0, - 3.2, 2.5E+20, x]
          (%o2)                         done
          (%i3) example (coeff);
          (%i4) coeff(b+tan(x)+2*a*tan(x) = 3+5*tan(x),tan(x))
          (%o4)                      2 a + 1 = 5
          (%i5) coeff(1+x*%e^x+y,x,0)
          (%o5)                         y + 1
          (%o5)                         done