Maxima Manual. Node: Definitions for Input and Output
Input and Output
8.4: Definitions for Input and Output
- Variable: %
The last D-line computed by MACSYMA (whether or not it was printed
out). (See also %%.)
- Variable: %%
The value of the last computation performed while in a
(MACSYMA-BREAK). Also may be used in compound statements in the nth
statement to refer to the value of the (n-1)th statement. E.g.
F(N):=(INTEGRATE(X^N,X),SUBST(3,X,%%)-SUBST(2,X,%%)); is in essence
equivalent to F(N):=BLOCK([%%], %%:INTEGRATE(X^N,X),
SUBST(3,X,%%)-SUBST(2,X,%%)); This will also work for communicating
between the (n-1)th and nth (non-atomic) BLOCK statements.
- Variable: %EDISPFLAG
default: [FALSE] - if TRUE, MACSYMA displays %E to a
negative exponent as a quotient, i.e. %E^-X as 1/%E^X.
- Function: %TH
is the ith previous computation. That is, if the next
expression to be computed is D(j) this is D(j-i). This is useful in
BATCH files or for referring to a group of D expressions. For
example, if SUM is initialized to 0 then FOR I:1 THRU 10 DO
SUM:SUM+%TH(I) will set SUM to the sum of the last ten D expressions.
- special symbol: "?"
- As prefix to a function or variable name, signifies that the
function or variable is a LISP token, not a MACSYMA token. Two
question marks typed together, ??, will flush the current MACSYMA
- Variable: ABSBOXCHAR
default: [!] is the character used to draw absolute value
signs around expressions which are more than a single line high.
- Function: APPENDFILE
(filename1, filename2, DSK, directory)
WRITEFILE(DSK,directory) but appends to the file whose name is
specified by the first two arguments. A subsequent CLOSEFILE will
delete the original file and rename the appended file.
- Function: BACKUP
To "back up" and see what you did, see PLAYBACK.
- Function: BATCH
reads in and evaluates MACSYMA command
lines from a file - A facility for executing command lines stored on a
disk file rather than in the usual on-line mode. This facility has
several uses, namely to provide a reservoir for working command lines,
for giving error-free demonstrations, or helping in organizing one's
thinking in complex problem-solving situations where modifications may
be done via a text editor.
A batch file consists of a set of MACSYMA command lines, each with its
terminating ; or $, which may be further separated by spaces,
carriage- returns, form-feeds, and the like.
The BATCH function calls for reading in the command lines from the
file one at a time, echoing them on the user console, and executing
them in turn. Control is returned to the user console only when
serious errors occur or when the end of the file is met. Of course,
the user may quit out of the file-processing by typing control-G at
BATCH files may be created using a text editor or by use of the
STRINGOUT command. Do DESCRIBE(STRINGOUT) for details
DESCRIBE(FILE); and DESCRIBE(FILES); have additional information on
how the file argument is interpreted, and files in general.
- Variable: BATCHKILL
default: [FALSE] if TRUE then the effect of all previous
BATCH files is nullified because a KILL(ALL) and a RESET() will be
done automatically when the next one is read in. If BATCHKILL is
bound to any other atom then a KILL of the value of BATCHKILL will be
- Function: BATCHLOAD
Batches in the file silently without
terminal output or labels.
- Function: BATCON
continues BATCHing in a file which was interrupted.
- Variable: BATCOUNT
default:  may be set to the number of the last expression
BATCHed in from a file. Thus BATCON(BATCOUNT-1) will resume BATCHing
from the expression before the last BATCHed in from before.
- Variable: BOTHCASES
default: [FALSE] if TRUE will cause MACSYMA to retain lower
case text as well as upper case. Note, however, that the names of any
MACSYMA special variables or functions must be typed in upper case.
(For historical reasons this is also a function, but it should be used
as a switch. Please use it as described here, not as a function.)
- Variable: CHANGE_FILEDEFAULTS
default: [TRUE] on PDP10 systems, and FALSE
elsewhere. Controls whether the user doing a LOADFILE or BATCH has
his file defaults changed to the file LOADFILEd or BATCHed. The TRUE
setting is for people who like DDT-style file defaulting. The FALSE
setting is for people who like the conventions of other operating
systems, who like LISP-style file defaulting, or who write packages
which do LOADFILEs or BATCHes which should not interfere with their
user's file defaults.
- Function: CLOSEFILE
closes a file opened by WRITEFILE and
gives it the name filename1 filename2. (On a Lisp Machine one need
only say CLOSEFILE();.) Thus to save a file consisting of the display
of all input and output during some part of a session with MACSYMA the
user issues a WRITEFILE, transacts with MACSYMA, then issues a
CLOSEFILE. The user can also issue the PLAYBACK function after a
WRITEFILE to save the display of previous transactions. (Note that
what is saved this way is a copy of the display of expressions not the
expressions themselves). To save the actual expression in internal
form the SAVE function may be used. The expression can then be
brought back into MACSYMA via the LOADFILE function. To save the
expression in a linear form which may then be BATCHed in later, the
STRINGOUT function is used.
- Function: COLLAPSE
collapses" its argument 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 before using FASSAVE
or after loading in a SAVE file. You can collapse several expressions
together by using COLLAPSE([expr1,...,exprN])$. Similarly, you can
collapse the elements of the array A by doing
- Function: CONCAT
(arg1, arg2, ...)
evaluates its arguments and returns the
concatenation of their values resulting in a name or a quoted string
the type being given by that of the first argument. Thus if X is
bound to 1 and D is unbound then CONCAT(X,2)="12" and
- Function: SCONCAT
(arg1, arg2, ...)
evaluates its arguments and concatenates them into a string. Unlike
CONCAT, the arguments do NOT need to be atoms. The result is a Common
The resulting string could be used in conjunction with print.
- Variable: CURSORDISP
default: [TRUE] If TRUE, causes expressions to be drawn by
the displayer in logical sequence. This only works with a console
which can do cursor movement. If FALSE, expressions are simply
printed line by line. CURSORDISP is FALSE when a WRITEFILE is in
- Variable: DIREC
- The value of this variable is the default file directory for
SAVE, STORE, FASSAVE, and STRINGOUT. It is initialized to the user's
login name, if he has a disk directory, and to one of the USERSi
directories otherwise. DIREC determines to what directory disk files
will be written.
- Function: DISP
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
displays the contraction properties of
the tensori as were given to DEFCON. DISPCON(ALL) displays all the
contraction properties which were defined.
- Function: DISPLAY
(expr1, expr2, ...)
displays equations whose left side is
expri 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 the DISP function)
B = X - X
- Variable: DISPLAY2D
default: [TRUE] - if set to FALSE will cause the standard
display to be a string (1-dimensional) form rather than a display
(2-dimensional) form. This may be of benefit for users on printing
consoles who would like to conserve paper.
- Variable: DISPLAY_FORMAT_INTERNAL
default: [FALSE] - if set to TRUE will cause
expressions to be displayed without being transformed in ways that
hide the internal mathematical representation. The display then
corresponds to what the INPART command returns rather than the PART
User PART INPART
a-b; A - B A + (- 1) B
A - 1
a/b; - A B
sqrt(x); SQRT(X) X
4 X 4
X*4/3; --- - X
- Function: DISPTERMS
displays its argument 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+...) will display P1, then below it P2, etc. When not
using DISPTERMS, if an exponential expression is too wide to be
displayed as A**B it will appear as EXPT(A,B) (or as NCEXPT(A,B) in
the case of A^^B).
- Variable: DSKALL
default:  If TRUE will cause values, functions, arrays, and
rules to be written periodically onto the disk in addition to labelled
expressions. TRUE is the default value whereas if DSKALL is FALSE
then only labelled expresions will be written.
- Variable: ERROR_SIZE
default: [20 for a display terminal, 10 for others].
controls the size of error messages. For example, let
U:(C^D^E+B+A)/(COS(X-1)+1); . U has an error size of 24. So if
ERROR_SIZE has value < 24 then
(C1) ERROR("The function", FOO,"doesn't like", U,"as input.");
The function FOO doesn't like ERREXP1 as input.
If ERROR_SIZE>24 then as:
C + B + A
The function FOO doesn't like -------------- as input.
COS(X - 1) + 1
Expressions larger than ERROR_SIZE are replaced by symbols, and the
symbols are set to the expressions. The symbols are taken from the
The default value of this switch might change depending on user
experience. If you find the defaults either too big or two small
for your tastes, send mail to MACSYMA.
- Variable: ERROR_SYMS
default: [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, and are initially ERREXP1, ERREXP2, ERREXP3, etc.
After an error message is printed, e.g. "The function FOO doesn't
like ERREXP1 as input.", the user can type ERREXP1; to see the
expression. ERROR_SYMS may be set by the user to a different set
of symbols, if desired.
- Function: EXPT
if an exponential expression is too wide to be displayed
as A^B it will appear as EXPT(A,B) (or as NCEXPT(A,B) in the case of
- Variable: EXPTDISPFLAG
default: [TRUE] - if TRUE, MACSYMA displays expressions
with negative exponents using quotients e.g., X**(-1) as 1/X.
- Function: FASSAVE
is similar to SAVE but produces a FASL file in which
the sharing of subexpressions which are shared in core is preserved in
the file created. Hence, expressions which have common subexpressions
will consume less space when loaded back from a file created by
FASSAVE rather than by SAVE. Files created with FASSAVE are reloaded
using LOADFILE, just as files created with SAVE. FASSAVE returns a
list of the form [<name of file>,<size of file in blocks>,...] where
... are the things saved. Warnings are printed out in the case of
large files. FASSAVE may be used while a WRITEFILE is in progress.
- Function: FILEDEFAULTS
returns the current default filename, in whatever
format is used by the specific Macsyma implementation. (See
DESCRIBE(FILE) for what that format is.) This is the file specification
used by LOADFILE, BATCH, and a number of other file-accessing commands.
FILEDEFAULTS('file) - sets the current filedefaults to "file". The
argument to FILEDEFAULTS is evaulated as it is anticipated that the
command will be used mainly in programs. The "file" need not be a
real file, so one can use this function e.g. if one's real purpose is
to set only the "device" field to something, where one does not care
about the settings of the other fields.
- Variable: FILENAME
default:  - The value of this variable is the first name
of the files which are generated by the automatic disk storage scheme.
The default value is the first three characters of the user's login
name concatenated with the lowest unused integer, e.g. ECR1.
- Function: FILENAME_MERGE
; merges together
filenames. What this means is that it returns "filename1" except
that missing components come from the corresponding components of
"filename2", and if they are missing there, then from "filename3".
- Variable: FILENUM
default:  - The default second file name for files generated
by SAVE, STRINGOUT, or FASSAVE if no file names are specified by the
user. It is an integer, and is incremented by one each time a new file
- Variable: FILE_SEARCH
- this is a list of files naming directories to search
by LOAD and a number of other functions. The default value of this
is a list of the various SHARE directories used by Macsyma.
FILE_SEARCH("filename"); searches on those directories and devices
specified by the FILE_SEARCH variable, and returns the name of the
first file it finds. This function is invoked by the LOAD function,
which is why LOAD("FFT") finds and loads DSK:SHARE;FFT FASL. You may
do FILE_SEARCH:CONS("devdir",FILE_SEARCH); to add other directories
to the search rules, where "devdir" is a file naming only a device
and a directory. In NIL Macsyma, for instance, if one had a directory
for a personal library of Macsyma routines, "devdir" would be something
- Variable: FILE_STRING_PRINT
default: [FALSE] on MC, [TRUE] elsewhere. If
TRUE, filenames are output as strings; if FALSE, as lists. For
example, the message when an out of core file is loaded into
MACSYMA (e.g. the LIMIT package), appears on MC in list format as
LIMIT FASL DSK MACSYM being loaded
and in string format as:
DSK:MACSYM;LIMIT FASL being loaded
The string format is like the top level (DDT) file specifications.
- Function: FILE_TYPE
; returns FASL, LISP, or MACSYMA, depending on
what kind of file it is. FASL means a compiled Lisp file, which
normally has an extension of .VAS in NIL.
- Function: GRIND
prints out arg in a more readable format than the STRING
command. It returns a D-line as value.
The GRIND switch, default: [FALSE], if TRUE will cause the STRING,
STRINGOUT, and PLAYBACK commands to use "grind" mode instead of
"string" mode. For PLAYBACK, "grind" mode can also be turned on (for
processing input lines) by specifying GRIND as an option.
- Variable: IBASE
default:  - the base for inputting numbers.
- Variable: INCHAR
default: [C] - the alphabetic prefix of the names of
expressions typed by the user.
- Function: LDISP
is like DISP but also generates intermediate
- Function: LDISPLAY
is like DISPLAY but also generates
- Variable: LINECHAR
default: [E] - the alphabetic prefix of the names of
intermediate displayed expressions.
- Variable: LINEDISP
default: [TRUE] - Allows the use of line graphics in the
drawing of equations on those systems which support them (e.g. the
Lisp Machine). This can be disabled by setting LINEDISP to FALSE. It
is automatically disabled during WRITEFILE.
- Variable: LINEL
default:  - the number of characters which are printed on a
line. It is initially set by MACSYMA to the line length of the type of
terminal being used (as far as is known) but may be reset at any time
by the user. The user may have to reset it in DDT with :TCTYP as
- Function: LOAD
; takes one argument, a filename represented as a
"string" (i.e. inside quotation marks), or as list (e.g. inside square
brackets), and locates and loads in the indicated file. If no
directory is specified, it then searches the SHAREi directories and
any other directories listed in the FILE_SEARCH variable and loads the
indicated file. LOAD("EIGEN") will load the eigen package without the
need for the user to be aware of the details of whether the package
was compiled, translated, saved, or fassaved, i.e. LOAD will work on
both LOADILEable and BATCHable files. Note: LOAD will use BATCHLOAD
if it finds the file is BATCHable (which means that it will BATCH the
file in "silently" without terminal output or labels).
Other MACSYMA commands to load in files are: LOADFILE, RESTORE,
BATCH, and DEMO. Do DESCRIBE(command); for details. LOADFILE and
RESTORE work for files written with SAVE; BATCH and DEMO for those
files written with STRINGOUT or created as lists of commands with a
If load can't find the file, check the value FILE_SEARCH to make sure
that it contains an appropriate template.
MACSYMA BUG: Unknown file type NIL
Error: macsyma error
Error signalled by MEVAL1.
Broken at $LOAD. Type :H for Help.
By examining the file system we find the file is actually in
/public/maxima/share/eigen.mc. So we add that to the file_search
path. This can be done at start up (see sys-init.lsp in the
system directory or, else it can be done and then the system resaved
once it has been customized for local directories and pathnames.
At lisp level we would do
(setq $file_search ($append (list '(mlist)
"/tmp/foo.mac" "/tmp/foo.mc") $file_search))
and at maxima level:
- SQRT(D - 2 A D + 4 B C + A ) + D + A
SQRT(D - 2 A D + 4 B C + A ) + D + A
-------------------------------------], [1, 1]]
- Function: LOADFILE
loads a file as designated by its
arguments. This function may be used to bring back quantities that
were stored from a prior MACSYMA session by use of the SAVE or STORE
functions. Specify the pathname as on your operating system. For
unix this would be "/home/wfs/foo.mc" for example.
- Variable: LOADPRINT
default: [TRUE] - governs the printing of messages
accompanying loading of files. The following options are available:
TRUE means always print the message; 'LOADFILE means print only when
the LOADFILE command is used; 'AUTOLOAD means print only when a file
is automatically loaded in (e.g. the integration file SIN FASL); FALSE
means never print the loading message.
- Function: NOSTRING
displays all input lines when playing back rather than
STRINGing them. If arg is GRIND then the display will be in a more
readable format. One may include any number of options as in
- Variable: OBASE
default:  the base for display of numbers.
- Variable: OUTCHAR
default: [D] - the alphabetic prefix of the names of
- Variable: PACKAGEFILE
default:[FALSE] - Package designers who use SAVE,
FASSAVE, or TRANSLATE to create packages (files) for others
to use may want to set PACKAGEFILE:TRUE$ to prevent information
from being added to MACSYMA'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 MACSYMA
- Variable: PARSEWINDOW
default: - the maximum number of "lexical tokens"
that are printed out on each side of the error-point when a syntax
(parsing) error occurs. This option is especially useful on slow
terminals. Setting it to -1 causes the entire input string to be
printed out when an error occurs.
- Variable: PFEFORMAT
default: [FALSE] - if TRUE will cause rational numbers to
display in a linear form and denominators which are integers to
display as rational number multipliers.
- Function: PRINT
(exp1, exp2, ...)
evaluates and displays its arguments one
after the other "on a line" starting at the leftmost position. If
expi is unbound or is preceded by a single quote or is enclosed in "s
then it is printed literally. For example, PRINT("THE VALUE OF X IS
",X). The value returned by PRINT is the value of its last argument.
No intermediate lines are generated. (For "printing" files, see
the PRINTFILE function.)
- Function: READ
prints its arguments, then reads in and evaluates
one expression. For example: A:READ("ENTER THE NUMBER OF VALUES").
- Function: READONLY
prints its arguments, then reads in an
expression (which in contrast to READ is not evaluated).
- Function: REVEAL
will display exp to the specified integer depth
with the length of each part indicated. Sums will be displayed as
Sum(n) and products as Product(n) where n is the number of subparts of
the sum or product. Exponentials will be displayed as Expt.
(D2) Negterm + Quotient + Quotient
(D3) - Quotient + ---------- + ----------
- Variable: RMXCHAR
default: ] - The character used to display the (right)
delimiter of a matrix (see also LMXCHAR).
- Function: SAVE
([optional file spec],arg1, arg2,...,argi)
described by its arguments on disk and keeps them in core also. The
optional file spec is in the form NAME1,NAME2,DSK,DIRECTORY and is
enclosed in square brackets, e.g. [JAMU,FUNCS,DSK,USERS2]. Do
DESCRIBE(FILES) for more details on file specifications. If you omit
the file spec, MACSYMA will select a file name for you consisting of
the first three letters of your login name followed by a digit (the
lowest digit which will give a unique file name). The second file
name will be a number. The arg's are the expressions to be SAVEd.
ALL is the simplest, but note that saving ALL will save the entire
contents of your MACSYMA, which in the case of a large computation may
result in a file which is too large to be reloaded. VALUES,
FUNCTIONS, or any other items on the INFOLISTS (do
DESCRIBE(INFOLISTS); for the list) may be SAVEd, as may functions and
variables by name. C and D lines may also be saved, but it is better
to give them explicit names, which may be done in the command line,
e.g. SAVE(RES1=D15); Files saved with SAVE should be reloaded with
LOADFILE. SAVE returns a list of the form [<name of file>,<size of
file in blocks>,...] where ... are the things saved. Warnings are
printed out in the case of large files, or if an empty file is
accidently generated. It is possible to do a SAVE when a WRITEFILE is
- Variable: SAVEDEF
default: [TRUE] - if TRUE will cause the MACSYMA version of a
user function to remain when the function is TRANSLATEd. This permits
the definition to be displayed by DISPFUN and allows the function to
be edited. If SAVEDEF is FALSE, the names of translated functions are
removed from the FUNCTIONS list.
- Function: SHOW
will display exp with the indexed objects in it shown
having covariant indices as subscripts,contravariant indices as
superscripts. The derivative indices will be displayed as subscripts,
separated from the covariant indices by a comma.
- Function: SHOWRATVARS
returns a list of the RATVARS (CRE variables) of
- Variable: STARDISP
default: [FALSE] - if TRUE will cause multiplication to be
displayed explicitly with an * between operands.
- Function: STRING
converts expr to MACSYMA's linear notation (similar to
FORTRAN's) just as if it had been typed in and puts expr into the
buffer for possible editing (in which case expr is usually Ci) The
STRING'ed expression should not be used in a computation.
- Function: STRINGOUT
will output an expression to a file in a linear
format. Such files are then used by the BATCH or DEMO commands.
STRINGOUT(file-specification, A1, A2, ...) outputs to a file given by
file-specification ([filename1,filename2,DSK, directory]) the values
given by A1,A2,.. in a MACSYMA readable format. The
file-specification may be omitted, in which case the default values
will be used. The Ai are usually C labels or may be INPUT meaning the
value of all C labels. Another option is to make ai FUNCTIONS which
will cause all of the user's function definitions to be strungout
(i.e. all those retrieved by DISPFUN(ALL)). Likewise the ai may be
VALUES, and all the variables to which the user has assigned values
will be strungout. ai may also be a list [m,n] which means to
stringout all labels in the range m through n inclusive. This
function may be used to create a file of FORTRAN statements by doing
some simple editing on the strungout expressions. If the GRIND switch
is set to TRUE, then STRINGOUT will use GRIND format instead of STRING
format. Note: a STRINGOUT may be done while a WRITEFILE is in
- Function: SYSTEM(command)
Execute COMMAND as a subprocess. The command will be passed to the
default shell for execution. System is not supported by all operating
systems, but generally exists in the unix environment.
if hist is a list of frequencies which you wish to plot as a bar graph
for i:1 thru length(hist) do (
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)&")
- Variable: TTYOFF
default: [FALSE] - if TRUE stops printing output to the
- macro: WITH_STDOUT(file,stmt1,stmt2,...)
Opens file and then evaluates stmt1, stmt2, .... Any printing
to standard output goes to the file instead of the terminal.
It always returns FALSE.
for x:range thru range step
system("echo \"set data style lines; set title '",
f,"' ;plot '/tmp/gnu'
;pause 10 \" | gnuplot"));
for i:8 thru n
do(print("factorial(",i,") gives ",i!)));
(C9) system("cat /home/wfs/joe");
factorial( 8 ) gives 40320
factorial( 9 ) gives 362880
factorial( 10 ) gives 3628800
Input and Output
- Function: WRITEFILE
opens up a file for writing. On a Lisp
Machine one uses WRITEFILE("filename"). All interaction between the
user and MACSYMA is then recorded in this file, just as it is on the
console. Such a file is a transcript of the session, and is not
reloadable or batchable into MACSYMA again. (See also CLOSEFILE.)