Go to the first, previous, next, last section, table of contents.


Input and Output

Introduction to Input and Output

Files

A file is simply an area on a particular storage device which contains data or text. Files on the disks are figuratively grouped into "directories". A directory is just a list of files. Commands which deal with files are: save, load, loadfile, stringout, batch, demo, writefile, closefile, and appendfile.

Definitions for Input and Output

System variable: _

_ is the most recent input expression (e.g., %i1, %i2, %i3, ...).

_ is assigned the input before the input is simplified or evaluated. However, the value of _ is simplified (but not evaluated) when it is displayed.

_ is recognized by batch, but not by load.

See also %.

Examples:

(%i1) 13 + 29;
(%o1)                          42
(%i2) :lisp $_
((MPLUS) 13 29)
(%i2) _;
(%o2)                          42
(%i3) sin (%pi/2);
(%o3)                           1
(%i4) :lisp $_
((%SIN) ((MQUOTIENT) $%PI 2))
(%i4) _;
(%o4)                           1
(%i5) a: 13$
(%i6) b: 29$
(%i7) a + b;
(%o7)                          42
(%i8) :lisp $_
((MPLUS) $A $B)
(%i8) _;
(%o8)                         b + a
(%i9) a + b;
(%o9)                          42
(%i10) ev (_);
(%o10)                         42

System variable: %
% is the output expression (e.g., %o1, %o2, %o3, ...) most recently computed by Maxima, whether or not it was displayed.

% is recognized by batch, but not by load.

See also _, %%, and %th.

System variable: %%
In a compound statement comprising two or more statements, %% is the value of the previous statement. For example,

block (integrate (x^5, x), ev (%%, x=2) - ev (%%, x=1));
block ([prev], prev: integrate (x^5, x), ev (prev, x=2) - ev (prev, x=1));

yield the same result, namely 21/2.

A compound statement may comprise other compound statements. Whether a statement be simple or compound, %% is the value of the previous statement. For example,

block (block (a^n, %%*42), %%/6)

yields 7*a^n.

Within a compound statement, the value of %% may be inspected at a break prompt, which is opened by executing the break function. For example, at the break prompt opened by

block (a: 42, break ())$

entering %%; yields 42.

At the first statement in a compound statement, or outside of a compound statement, %% is undefined.

%% is recognized by both batch and load.

See also %.

Option variable: %edispflag
Default value: false

When %edispflag is true, Maxima displays %e to a negative exponent as a quotient. For example, %e^-x is displayed as 1/%e^x.

Function: %th (i)
The value of the i'th previous output expression. That is, if the next expression to be computed is the n'th output, %th (m) is the (n - m)'th output.

%th is useful in batch files or for referring to a group of output expressions. For example,

block (s: 0, for i:1 thru 10 do s: s + %th (i))$

sets s to the sum of the last ten output expressions.

%th is recognized by batch, but not by load.

See also %.

Special symbol: "?"
As prefix to a function or variable name, ? signifies that the name is a Lisp name, not a Maxima name. For example, ?round signifies the Lisp function ROUND. See section Lisp and Maxima for more on this point.

The notation ? word (a question mark followed a word, separated by whitespace) is equivalent to describe ("word").

Option variable: absboxchar
Default value: !

absboxchar is the character used to draw absolute value signs around expressions which are more than one line tall.

Function: appendfile (filename)
Appends a console transcript to filename. appendfile is the same as writefile, except that the transcript file, if it exists, is always appended.

closefile closes the transcript file opened by appendfile or writefile.

Function: batch (filename)
Reads Maxima expressions from filename and evaluates them. batch searches for filename in the list file_search_maxima. See file_search.

filename comprises a sequence of Maxima expressions, each terminated with ; or $. The special variable % and the function %th refer to previous results within the file. The file may include :lisp constructs. Spaces, tabs, and newlines in the file are ignored. A suitable input file may be created by a text editor or by the stringout function.

batch reads each input expression from filename, displays the input to the console, computes the corresponding output expression, and displays the output expression. Input labels are assigned to the input expressions and output labels are assigned to the output expressions. batch evaluates every input expression in the file unless there is an error. If user input is requested (by asksign or askinteger, for example) batch pauses to collect the requisite input and then continue.

It may be possible to halt batch by typing control-C at the console. The effect of control-C depends on the underlying Lisp implementation.

batch has several uses, such as to provide a reservoir for working command lines, to give error-free demonstrations, or to help organize one's thinking in solving complex problems.

batch evaluates its argument. batch has no return value.

See also load, batchload, and demo.

Function: batchload (filename)
Reads Maxima expressions from filename and evaluates them, without displaying the input or output expressions and without assigning labels to output expressions. Printed output (such as produced by print or describe) is displayed, however.

The special variable % and the function %th refer to previous results from the interactive interpreter, not results within the file. The file cannot include :lisp constructs.

batchload returns the path of filename, as a string. batchload evaluates its argument.

See also batch and load.

Function: closefile ()
Closes the transcript file opened by writefile or appendfile.

Function: collapse (expr)
Collapses expr by causing all of its common (i.e., equal) subexpressions to share (i.e., use the same cells), thereby saving space. (collapse is a subroutine used by the optimize command.) Thus, calling collapse may be useful after loading in a save file. You can collapse several expressions together by using collapse ([expr_1, ..., expr_n]). Similarly, you can collapse the elements of the array A by doing collapse (listarray ('A)).

Function: concat (arg_1, arg_2, ...)
Concatenates its arguments. The arguments must evaluate to atoms. The return value is a symbol if the first argument is a symbol and a Maxima string otherwise.

concat evaluates its arguments. The single quote ' prevents evaluation.

(%i1) y: 7$
(%i2) z: 88$
(%i3) concat (y, z/2);
(%o3)                          744
(%i4) concat ('y, z/2);
(%o4)                          y44

A symbol constructed by concat may be assigned a value and appear in expressions. The :: (double colon) assignment operator evaluates its left-hand side.

(%i5) a: concat ('y, z/2);
(%o5)                          y44
(%i6) a:: 123;
(%o6)                          123
(%i7) y44;
(%o7)                          123
(%i8) b^a;
                               y44
(%o8)                         b
(%i9) %, numer;
                               123
(%o9)                         b

Note that although concat (1, 2) looks like a number, it is a Maxima string.

(%i10) concat (1, 2) + 3;
(%o10)                       12 + 3

Function: sconcat (arg_1, arg_2, ...)

Concatenates its arguments into a string. Unlike concat, the arguments do not need to be atoms.

The result is a Lisp string.

(%i1) sconcat ("xx[", 3, "]:", expand ((x+y)^3));
(%o1)               xx[3]:y^3+3*x*y^2+3*x^2*y+x^3

Function: disp (expr_1, expr_2, ...)
is like display but only the value of the arguments are displayed rather than equations. This is useful for complicated arguments which don't have names or where only the value of the argument is of interest and not the name.

Function: dispcon (tensor_1, tensor_2, ...)
Function: dispcon (all)
Displays the contraction properties of its arguments as were given to defcon. dispcon (all) displays all the contraction properties which were defined.

Function: display (expr_1, expr_2, ...)
Displays equations whose left side is expr_i unevaluated, and whose right side is the value of the expression centered on the line. This function is useful in blocks and for statements in order to have intermediate results displayed. The arguments to display are usually atoms, subscripted variables, or function calls. See also disp.

(%i1) display(B[1,2]);
                                      2
                         B     = X - X
                          1, 2
(%o1)                            done

Option variable: display2d
Default value: true

When display2d is false, the console display is a string (1-dimensional) form rather than a display (2-dimensional) form.

Option variable: display_format_internal
Default value: false

When display_format_internal is true, expressions are displayed without being transformed in ways that hide the internal mathematical representation. The display then corresponds to what inpart returns rather than part.

Examples:

User     part       inpart
a-b;      A - B     A + (- 1) B

           A            - 1
a/b;       -         A B
           B
                       1/2
sqrt(x);   sqrt(X)    X

          4 X        4
X*4/3;    --        - X
           3         3

Function: dispterms (expr)
Displays expr in parts one below the other. That is, first the operator of expr is displayed, then each term in a sum, or factor in a product, or part of a more general expression is displayed separately. This is useful if expr is too large to be otherwise displayed. For example if P1, P2, ... are very large expressions then the display program may run out of storage space in trying to display P1 + P2 + ... all at once. However, dispterms (P1 + P2 + ...) displays P1, then below it P2, etc. When not using dispterms, if an exponential expression is too wide to be displayed as A^B it appears as expt (A, B) (or as ncexpt (A, B) in the case of A^^B).

Option variable: error_size
Default value: 10

error_size modifies error messages according to the size of expressions which appear in them. If the size of an expression (as determined by the Lisp function ERROR-SIZE) is greater than error_size, the expression is replaced in the message by a symbol, and the symbol is assigned the expression. The symbols are taken from the list error_syms.

Otherwise, the expression is smaller than error_size, and the expression is displayed in the message.

See also error and error_syms.

Example:

The size of U, as determined by ERROR-SIZE, is 24.

(%i1) U: (C^D^E + B + A)/(cos(X-1) + 1)$

(%i2) error_size: 20$

(%i3) error ("Example expression is", U);

Example expression is errexp1
 -- an error.  Quitting.  To debug this try debugmode(true);
(%i4) errexp1;
                            E
                           D
                          C   + B + A
(%o4)                    --------------
                         cos(X - 1) + 1
(%i5) error_size: 30$

(%i6) error ("Example expression is", U);

                         E
                        D
                       C   + B + A
Example expression is --------------
                      cos(X - 1) + 1
 -- an error.  Quitting.  To debug this try debugmode(true);

Option variable: error_syms
Default value: [errexp1, errexp2, errexp3]

In error messages, expressions larger than error_size are replaced by symbols, and the symbols are set to the expressions. The symbols are taken from the list error_syms. The first too-large expression is replaced by error_syms[1], the second by error_syms[2], and so on.

If there are more too-large expressions than there are elements of error_syms, symbols are constructed automatically, with the n-th symbol equivalent to concat ('errexp, n).

See also error and error_size.

Function: expt (a, b)
If an exponential expression is too wide to be displayed as a^b it appears as expt (a, b) (or as ncexpt (a, b) in the case of a^^b).

expt and ncexpt are not recognized in input.

Option variable: exptdispflag
Default value: true

When exptdispflag is true, Maxima displays expressions with negative exponents using quotients, e.g., X^(-1) as 1/X.

Function: filename_merge (path, filename)
Constructs a modified path from path and filename. If the final component of path is of the form ###.something, the component is replaced with filename.something. Otherwise, the final component is simply replaced by filename.

Function: file_search (filename)
Function: file_search (filename, pathlist)

file_search searches for the file filename and returns the path to the file (as a string) if it can be found; otherwise file_search returns false. file_search (filename) searches in the default search directories, which are specified by the file_search_maxima, file_search_lisp, and file_search_demo variables.

file_search first checks if the actual name passed exists, before attempting to match it to "wildcard" file search patterns. See file_search_maxima concerning file search patterns.

The argument filename can be a path and file name, or just a file name, or, if a file search directory includes a file search pattern, just the base of the file name (without an extension). For example,

file_search ("/home/wfs/special/zeta.mac");
file_search ("zeta.mac");
file_search ("zeta");

all find the same file, assuming the file exists and /home/wfs/special/###.mac is in file_search_maxima.

file_search (filename, pathlist) searches only in the directories specified by pathlist, which is a list of strings. The argument pathlist supersedes the default search directories, so if the path list is given, file_search searches only the ones specified, and not any of the default search directories. Even if there is only one directory in pathlist, it must still be given as a one-element list.

The user may modify the default search directories. See file_search_maxima.

file_search is invoked by load with file_search_maxima and file_search_lisp as the search directories.

Option variable: file_search_maxima
Option variable: file_search_lisp
Option variable: file_search_demo
These variables specify lists of directories to be searched by load, demo, and some other Maxima functions. The default values of these variables name various directories in the Maxima installation.

The user can modify these variables, either to replace the default values or to append additional directories. For example,

file_search_maxima: ["/usr/local/foo/###.mac",
    "/usr/local/bar/###.mac"]$

replaces the default value of file_search_maxima, while

file_search_maxima: append (file_search_maxima,
    ["/usr/local/foo/###.mac", "/usr/local/bar/###.mac"])$

appends two additional directories. It may be convenient to put such an expression in the file maxima-init.mac so that the file search path is assigned automatically when Maxima starts.

Multiple filename extensions and multiple paths can be specified by special "wildcard" constructions. The string ### expands into the sought-after name, while a comma-separated list enclosed in curly braces {foo,bar,baz} expands into multiple strings. For example, supposing the sought-after name is neumann,

"/home/{wfs,gcj}/###.{lisp,mac}"

expands into /home/wfs/neumann.lisp, /home/gcj/neumann.lisp, /home/wfs/neumann.mac, and /home/gcj/neumann.mac.

Function: file_type (filename)
Returns a guess about the content of filename, based on the filename extension. filename need not refer to an actual file; no attempt is made to open the file and inspect the content.

The return value is a symbol, either object, lisp, or maxima. If the extension starts with m or d, file_type returns maxima. If the extension starts with l, file_type returns lisp. If none of the above, file_type returns object.

Function: grind (expr)
Option variable: grind
The function grind prints expr to the console in a form suitable for input to Maxima. grind always returns done.

See also string, which returns a string instead of printing its output. grind attempts to print the expression in a manner which makes it slightly easier to read than the output of string.

When the variable grind is true, the output of string and stringout has the same format as that of grind; otherwise no attempt is made to specially format the output of those functions. The default value of the variable grind is false.

grind can also be specified as an argument of playback. When grind is present, playback prints input expressions in the same format as the grind function. Otherwise, no attempt is made to specially format input expressions.

Option variable: ibase
Default value: 10

Integers entered into Maxima are interpreted with respect to the base ibase.

ibase may be assigned any integer between 2 and 35 (decimal), inclusive. When ibase is greater than 10, the numerals comprise the decimal numerals 0 through 9 plus capital letters of the alphabet A, B, C, ..., as needed. The numerals for base 35, the largest acceptable base, comprise 0 through 9 and A through Y.

See also obase.

Option variable: inchar
Default value: %i

inchar is the prefix of the labels of expressions entered by the user. Maxima automatically constructs a label for each input expression by concatenating inchar and linenum. inchar may be assigned any string or symbol, not necessarily a single character.

(%i1) inchar: "input";
(%o1)                                input
(input1) expand ((a+b)^3);
                            3        2      2      3
(%o1)                      b  + 3 a b  + 3 a  b + a
(input2)

See also labels.

Function: ldisp (expr_1, ..., expr_n)
Displays expressions expr_1, ..., expr_n to the console as printed output. ldisp assigns an intermediate expression label to each argument and returns the list of labels.

See also disp.

(%i1) e: (a+b)^3;
                                   3
(%o1)                       (b + a)
(%i2) f: expand (e);
                     3        2      2      3
(%o2)               b  + 3 a b  + 3 a  b + a
(%i3) ldisp (e, f);
                                   3
(%t3)                       (b + a)

                     3        2      2      3
(%t4)               b  + 3 a b  + 3 a  b + a

(%o4)                      [%t3, %t4]
(%i4) %t3;
                                   3
(%o4)                       (b + a)
(%i5) %t4;
                     3        2      2      3
(%o5)               b  + 3 a b  + 3 a  b + a

Function: ldisplay (expr_1, ..., expr_n)
Displays expressions expr_1, ..., expr_n to the console as printed output. Each expression is printed as an equation of the form lhs = rhs in which lhs is one of the arguments of ldisplay and rhs is its value. Typically each argument is a variable. ldisp assigns an intermediate expression label to each equation and returns the list of labels.

See also display.

(%i1) e: (a+b)^3;
                                   3
(%o1)                       (b + a)
(%i2) f: expand (e);
                     3        2      2      3
(%o2)               b  + 3 a b  + 3 a  b + a
(%i3) ldisplay (e, f);
                                     3
(%t3)                     e = (b + a)

                       3        2      2      3
(%t4)             f = b  + 3 a b  + 3 a  b + a

(%o4)                      [%t3, %t4]
(%i4) %t3;
                                     3
(%o4)                     e = (b + a)
(%i5) %t4;
                       3        2      2      3
(%o5)             f = b  + 3 a b  + 3 a  b + a

Option variable: linechar
Default value: %t

linechar is the prefix of the labels of intermediate expressions generated by Maxima. Maxima constructs a label for each intermediate expression (if displayed) by concatenating linechar and linenum. linechar may be assigned any string or symbol, not necessarily a single character.

Intermediate expressions might or might not be displayed. See programmode and labels.

Option variable: linel
Default value: 79

linel is the assumed width (in characters) of the console display for the purpose of displaying expressions. linel may be assigned any value by the user, although very small or very large values may be impractical. Text printed by built-in Maxima functions, such as error messages and the output of describe, is not affected by linel.

Option variable: lispdisp
Default value: false

When lispdisp is true, Lisp symbols are displayed with a leading question mark ?. Otherwise, Lisp symbols are displayed with no leading mark.

Examples:

(%i1) lispdisp: false$
(%i2) ?foo + ?bar;
(%o2)                       foo + bar
(%i3) lispdisp: true$
(%i4) ?foo + ?bar;
(%o4)                      ?foo + ?bar

Function: load (filename)
Evaluates expressions in filename, thus bringing variables, functions, and other objects into Maxima. The binding of any existing object is clobbered by the binding recovered from filename. To find the file, load calls file_search with file_search_maxima and file_search_lisp as the search directories. If load succeeds, it returns the name of the file. Otherwise load prints an error message.

load works equally well for Lisp code and Maxima code. Files created by save, translate_file, and compile_file, which create Lisp code, and stringout, which creates Maxima code, can all be processed by load. load calls loadfile to load Lisp files and batchload to load Maxima files.

See also loadfile, batch, batchload, and demo. loadfile processes Lisp files; batch, batchload, and demo process Maxima files.

See file_search for more detail about the file search mechanism.

load evaluates its argument.

Function: loadfile (filename)
Evaluates Lisp expressions in filename. loadfile does not invoke file_search, so filename must include the file extension and as much of the path as needed to find the file.

loadfile can process files created by save, translate_file, and compile_file. The user may find it more convenient to use load instead of loadfile.

loadfile quotes its argument, so filename must be a literal string, not a string variable. The double-single-quote operator defeats quotation.

Option variable: loadprint
Default value: true

loadprint tells whether to print a message when a file is loaded.

Option variable: obase
Default value: 10

obase is the base for integers displayed by Maxima.

obase may be assigned any integer between 2 and 35 (decimal), inclusive. When obase is greater than 10, the numerals comprise the decimal numerals 0 through 9 plus capital letters of the alphabet A, B, C, ..., as needed. The numerals for base 35, the largest acceptable base, comprise 0 through 9, and A through Y.

See also ibase.

Option variable: outchar
Default value: %o

outchar is the prefix of the labels of expressions computed by Maxima. Maxima automatically constructs a label for each computed expression by concatenating outchar and linenum. outchar may be assigned any string or symbol, not necessarily a single character.

(%i1) outchar: "output";
(output1)                           output
(%i2) expand ((a+b)^3);
                            3        2      2      3
(output2)                  b  + 3 a b  + 3 a  b + a
(%i3)

See also labels.

Option variable: packagefile
Default value: false

Package designers who use save or translate to create packages (files) for others to use may want to set packagefile: true to prevent information from being added to Maxima's information-lists (e.g. values, functions) except where necessary when the file is loaded in. In this way, the contents of the package will not get in the user's way when he adds his own data. Note that this will not solve the problem of possible name conflicts. Also note that the flag simply affects what is output to the package file. Setting the flag to true is also useful for creating Maxima init files.

Option variable: pfeformat
Default value: false

When pfeformat is true, a ratio of integers is displayed with the solidus (forward slash) character, and an integer denominator n is displayed as a leading multiplicative term 1/n.

(%i1) pfeformat: false$
(%i2) 2^16/7^3;
                              65536
(%o2)                         -----
                               343
(%i3) (a+b)/8;
                              b + a
(%o3)                         -----
                                8
(%i4) pfeformat: true$ 
(%i5) 2^16/7^3;
(%o5)                       65536/343
(%i6) (a+b)/8;
(%o6)                      1/8 (b + a)

Function: print (expr_1, ..., expr_n)
Evaluates and displays expr_1, ..., expr_n one after another, from left to right, starting at the left edge of the console display.

The value returned by print is the value of its last argument. print does not generate intermediate expression labels.

See also display, disp, ldisplay, and ldisp. Those functions display one expression per line, while print attempts to display two or more expressions per line.

To display the contents of a file, see printfile.

(%i1) r: print ("(a+b)^3 is", expand ((a+b)^3), "log (a^10/b) is", radcan (log (a^10/b)))$
            3        2      2      3
(a+b)^3 is b  + 3 a b  + 3 a  b + a  log (a^10/b) is 

                                              10 log(a) - log(b) 
(%i2) r;
(%o2)                  10 log(a) - log(b)
(%i3) disp ("(a+b)^3 is", expand ((a+b)^3), "log (a^10/b) is", radcan (log (a^10/b)))$
                           (a+b)^3 is

                     3        2      2      3
                    b  + 3 a b  + 3 a  b + a

                         log (a^10/b) is

                       10 log(a) - log(b)

Function: tcl_output (list, i0, skip)
Function: tcl_output (list, i0)
Function: tcl_output ([list_1, ..., list_n], i)

Prints elements of a list enclosed by curly braces { }, suitable as part of a program in the Tcl/Tk language.

tcl_output (list, i0, skip) prints list, beginning with element i0 and printing elements i0 + skip, i0 + 2 skip, etc.

tcl_output (list, i0) is equivalent to tcl_output (list, i0, 2).

tcl_output ([list_1, ..., list_n], i) prints the i'th elements of list_1, ..., list_n.

Examples:

(%i1) tcl_output ([1, 2, 3, 4, 5, 6], 1, 3)$

 {1.000000000     4.000000000     
 }
(%i2) tcl_output ([1, 2, 3, 4, 5, 6], 2, 3)$

 {2.000000000     5.000000000     
 }
(%i3) tcl_output ([3/7, 5/9, 11/13, 13/17], 1)$

 {((RAT SIMP) 3 7) ((RAT SIMP) 11 13) 
 }
(%i4) tcl_output ([x1, y1, x2, y2, x3, y3], 2)$

 {$Y1 $Y2 $Y3 
 }
(%i5) tcl_output ([[1, 2, 3], [11, 22, 33]], 1)$

 {SIMP 1.000000000     11.00000000     
 }

Function: read (expr_1, ..., expr_n)
Prints expr_1, ..., expr_n, then reads one expression from the console and returns the evaluated expression. The expression is terminated with a semicolon ; or dollar sign $.

See also readonly.

(%i1) foo: 42$ 
(%i2) foo: read ("foo is", foo, " -- enter new value.")$
foo is 42  -- enter new value. 
(a+b)^3;
(%i3) foo;
                                     3
(%o3)                         (b + a)

Function: readonly (expr_1, ..., expr_n)
Prints expr_1, ..., expr_n, then reads one expression from the console and returns the expression (without evaluation). The expression is terminated with a ; (semicolon) or $ (dollar sign).

(%i1) aa: 7$
(%i2) foo: readonly ("Enter an expression:");
Enter an expression: 
2^aa;
                                  aa
(%o2)                            2
(%i3) foo: read ("Enter an expression:");
Enter an expression: 
2^aa;
(%o3)                            128

See also read.

Function: reveal (expr, depth)
Replaces parts of expr at the specified integer depth with descriptive summaries.

When depth is greater than or equal to the maximum depth of expr, reveal (expr, depth) returns expr unmodified.

reveal evaluates its arguments. reveal returns the summarized expression.

Example:

(%i1) e: expand ((a - b)^2)/expand ((exp(a) + exp(b))^2);
                          2            2
                         b  - 2 a b + a
(%o1)               -------------------------
                        b + a     2 b     2 a
                    2 %e      + %e    + %e
(%i2) reveal (e, 1);
(%o2)                       quotient
(%i3) reveal (e, 2);
                             sum(3)
(%o3)                        ------
                             sum(3)
(%i4) reveal (e, 3);
                     expt + negterm + expt
(%o4)               ------------------------
                    product(2) + expt + expt
(%i5) reveal (e, 4);
                       2                 2
                      b  - product(3) + a
(%o5)         ------------------------------------
                         product(2)     product(2)
              2 expt + %e           + %e
(%i6) reveal (e, 5);
                         2            2
                        b  - 2 a b + a
(%o6)              --------------------------
                       sum(2)     2 b     2 a
                   2 %e       + %e    + %e
(%i7) reveal (e, 6);
                          2            2
                         b  - 2 a b + a
(%o7)               -------------------------
                        b + a     2 b     2 a
                    2 %e      + %e    + %e

Option variable: rmxchar
Default value: ]

rmxchar is the character drawn on the right-hand side of a matrix.

See also lmxchar.

Function: save (filename, name_1, name_2, name_3, ...)
Function: save (filename, values, functions, labels, ...)
Function: save (filename, [m, n])
Function: save (filename, name_1=expr_1, ...)
Function: save (filename, all)
Stores the current values of name_1, name_2, name_3, ..., in filename. The arguments are the names of variables, functions, or other objects. If a name has no value or function associated with it, it is ignored. save returns filename.

save stores data in the form of Lisp expressions. The data stored by save may be recovered by load (filename). The effect of executing save when filename already exists depends on the underlying Lisp implementation; the file may be clobbered, or save may complain with an error message.

The special form save (filename, values, functions, labels, ...) stores the items named by values, functions, labels, etc. The names may be any specified by the variable infolists. values comprises all user-defined variables.

The special form save (filename, [m, n]) stores the values of input and output labels m through n. Note that m and n must be literal integers or double-quoted symbols. Input and output labels may also be stored one by one, e.g., save ("foo.1", %i42, %o42). save (filename, labels) stores all input and output labels. When the stored labels are recovered, they clobber existing labels.

The special form save (filename, name_1=expr_1, name_2=expr_2, ...) stores the values of expr_1, expr_2, ..., with names name_1, name_2, .... It is useful to apply this form to input and output labels, e.g., save ("foo.1", aa=%o88). The right-hand side of the equality in this form may be any expression, which is evaluated. This form does not introduce the new names into the current Maxima environment, but only stores them in filename.

These special forms and the general form of save may be mixed at will. For example, save (filename, aa, bb, cc=42, functions, [11, 17]).

The special form save (filename, all) stores the current state of Maxima. This includes all user-defined variables, functions, arrays, etc., as well as some automatically defined items. The saved items include system variables, such as file_search_maxima or showtime, if they have been assigned new values by the user; see myoptions.

save quotes its arguments. filename must be a string, not a string variable. The first and last labels to save, if specified, must be integers. The double quote operator evaluates a string variable to its string value, e.g., s: "foo.1"$ save ("s, all)$, and integer variables to their integer values, e.g., m: 5$ n: 12$ save ("foo.1", ["m, "n])$.

Option variable: savedef
Default value: true

When savedef is true, the Maxima version of a user function is preserved when the function is translated. This permits the definition to be displayed by dispfun and allows the function to be edited.

When savedef is false, the names of translated functions are removed from the functions list.

Function: show (expr)
Displays expr with the indexed objects in it shown having covariant indices as subscripts, contravariant indices as superscripts. The derivative indices are displayed as subscripts, separated from the covariant indices by a comma.

Function: showratvars (expr)
Returns a list of the canonical rational expression (CRE) variables in expression expr.

See also ratvars.

Option variable: stardisp
Default value: false

When stardisp is true, multiplication is displayed with an asterisk * between operands.

Function: string (expr)
Converts expr to Maxima's linear notation just as if it had been typed in.

The return value of string is a string, and thus it cannot be used in a computation.

Lisp variable: stringdisp
Default value: false

When ?stringdisp is true, strings are displayed enclosed in double quote marks. Otherwise, quote marks are not displayed.

?stringdisp is always true when displaying a function definition.

?stringdisp is a Lisp variable, so it must be written with a leading question mark ?.

Examples:

(%i1) ?stringdisp: false$
(%i2) "This is an example string.";
(%o2)              This is an example string.
(%i3) foo () := print ("This is a string in a function definition.");
(%o3) foo() := 
              print("This is a string in a function definition.")
(%i4) ?stringdisp: true$
(%i5) "This is an example string.";
(%o5)             "This is an example string."

Function: stringout (filename, expr_1, expr_2, expr_3, ...)
Function: stringout (filename, [m, n])
Function: stringout (filename, input)
Function: stringout (filename, functions)
Function: stringout (filename, values)

stringout writes expressions to a file in the same form the expressions would be typed for input. The file can then be used as input for the batch or demo commands, and it may be edited for any purpose. stringout can be executed while writefile is in progress.

The general form of stringout writes the values of one or more expressions to the output file. Note that if an expression is a variable, only the value of the variable is written and not the name of the variable. As a useful special case, the expressions may be input labels (%i1, %i2, %i3, ...) or output labels (%o1, %o2, %o3, ...).

If grind is true, stringout formats the output using the grind format. Otherwise the string format is used. See grind and string.

The special form stringout (filename, [m, n]) writes the values of input labels m through n, inclusive.

The special form stringout (filename, input) writes all input labels to the file.

The special form stringout (filename, functions) writes all user-defined functions (named by the global list functions) to the file.

The special form stringout (filename, values) writes all user-assigned variables (named by the global list values) to the file. Each variable is printed as an assignment statement, with the name of the variable, a colon, and its value. Note that the general form of stringout does not print variables as assignment statements.

Function: tex (expr)
Function: tex (expr, filename)
Function: tex (label, filename)

In the case of a label, a left-equation-number is produced. in case a file-name is supplied, the output is appended to the file.

(%i1) integrate (1/(1+x^3), x);
                                    2 x - 1
                  2            atan(-------)
             log(x  - x + 1)        sqrt(3)    log(x + 1)
(%o1)      - --------------- + ------------- + ----------
                    6             sqrt(3)          3
(%i2) tex (%o1);
$$-{{\log \left(x^2-x+1\right)}\over{6}}+{{\arctan \left({{2\,x-1
 }\over{\sqrt{3}}}\right)}\over{\sqrt{3}}}+{{\log \left(x+1\right)
 }\over{3}}\leqno{\tt (\%o1)}$$
(%o2)                          (\%o1)
(%i3) tex (integrate (sin(x), x));
$$-\cos x$$
(%o3)                           false
(%i4) tex (%o1, "foo.tex");
(%o4)                          (\%o1)

Function: system (command)
Executes command as a separate process. The command is passed to the default shell for execution. system is not supported by all operating systems, but generally exists in Unix and Unix-like environments.

Supposing _hist.out is a list of frequencies which you wish to plot as a bar graph using xgraph.

(%i1) (with_stdout("_hist.out",
           for i:1 thru length(hist) do (
             print(i,hist[i]))),
       system("xgraph -bar -brw .7 -nl < _hist.out"));

In order to make the plot be done in the background (returning control to Maxima) and remove the temporary file after it is done do:

system("(xgraph -bar -brw .7 -nl < _hist.out;  rm -f _hist.out)&")

Option variable: ttyoff
Default value: false

When ttyoff is true, output expressions are not displayed. Output expressions are still computed and assigned labels. See labels.

Text printed by built-in Maxima functions, such as error messages and the output of describe, is not affected by ttyoff.

Macro: with_stdout (filename, expr_1, expr_2, expr_3, ...)
Opens filename and then evaluates expr_1, expr_2, expr_3, .... The values of the arguments are not stored in filename, but any printed output generated by evaluating the arguments (from print, display, disp, or grind, for example) goes to filename instead of the console.

with_stdout returns the value of its final argument.

See also writefile.

(%i1) with_stdout ("tmp.out", for i:5 thru 10 do print (i, "! yields", i!))$
(%i2) printfile ("tmp.out")$
5 ! yields 120 
6 ! yields 720 
7 ! yields 5040 
8 ! yields 40320 
9 ! yields 362880 
10 ! yields 3628800

Function: writefile (filename)
Begins writing a transcript of the Maxima session to filename. All interaction between the user and Maxima is then recorded in this file, just as it appears on the console.

As the transcript is printed in the console output format, it cannot be reloaded into Maxima. To make a file containing expressions which can be reloaded, see save and stringout. save stores expressions in Lisp form, while stringout stores expressions in Maxima form.

The effect of executing writefile when filename already exists depends on the underlying Lisp implementation; the transcript file may be clobbered, or the file may be appended. appendfile always appends to the transcript file.

It may be convenient to execute playback after writefile to save the display of previous interactions. As playback displays only the input and output variables (%i1, %o1, etc.), any output generated by a print statement in a function (as opposed to a return value) is not displayed by playback.

closefile closes the transcript file opened by writefile or appendfile.


Go to the first, previous, next, last section, table of contents.