Fix the inefficient evaluation of translated predicates
[maxima.git] / archive / info / maxima-primer.tex
blob44356df185d0c9aa45748ae48b1e8777c6dbeb90
1 %%document begins here!!!!!!!!
2 \documentclass[titlepage]{article}
3 \usepackage{moreverb}%to get pretty listings with verbatimtab
4 \usepackage{varioref}
5 \usepackage{makeidx}% load up the indexing package
6 \makeindex%tell it to make an index.
8 \newcommand{\idea}[1]{#1}%use for putting things in concept index
9 \newcommand{\noun}[1]{\index{#1}{\large \bf #1 }}%put all nouns in the
10 %index
11 \newcommand{\e}{\mathrm{e}}%%the exponential
12 \newcommand{\dd}{\mathrm{d}}%%the differential
14 \newcommand{\fixme}[1]{{\bf[FIXME: #1 ]}}% this should be handy...
16 %%take care page numbering for coverpage
17 \setcounter{page}{0}
19 \begin{document}
21 %puts page number on title with doc-class{article}
22 \title{A Brief Introduction to Maxima}
23 %Version 0.1
24 \author{\copyright Nels Tomlinson}
26 \date{\today}
28 \vspace{-1.0cm}
29 \maketitle
31 %\clearpage
33 \tableofcontents
34 \clearpage
36 \section{Introduction}
38 Matlab, Maple, Mathematica, and any other trademarks mentioned herein
39 are the property of whoever owns them\dots This document is \copyright{
40 Nels Tomlinson, 2001}. This is a work in progress, and is NOT complete.
42 \subsection{What is a Symbolic Math System?}
44 A symbolic math system is a computer program intended to manipulate
45 symbols rather than numbers. So, this lets one add $a+b$ without
46 worrying about what values they have. One modern example of this is the
47 TI-92 calculator, which has some symbolic math capabilities.
48 Mathematica and Maple are two more examples.
50 \subparagraph{What is \emph{not} a symbolic math system?} Matlab and
51 GNU Octave are a fine pair of programs, very popular with engineers for
52 numerical computation. They can both compute $\int_{1}^{2}\e^x \dd x$
53 to any reasonable number of decimal places, but by
54 themselves\footnote{Matlab can be induced to give a symbolic answer,
55 because it incorporates Maple, a commercial symbolic math system.},
56 cannot tell you that the answer is $\e^2-\e^1$. That is the answer that
57 a symbolic math package should give by default, and this is what
58 distinguishes a symbolic from a numeric system: it will (hopefully\dots)
59 give the same answer that you would get by hand if you had the patience
60 to do it right.
62 \subsection{What is Maxima?}
64 Maxima is a symbolic math system, written in Koyoto Common Lisp (now GNU
65 lisp). It has been released, recently, under the GNU Public License.
66 This means that it is libr\'e software, so one may download it and put
67 it to work, legally. It is free, so one needn't pay anything to do
68 this. It has been around for about 30+ years, and after this length of
69 time, should be a fairly well--tested, mature product, with few unknown
70 bugs. It is rather older than the two commercial symbolic math systems,
71 Mathematica and Maple (M\&M) which have achieved commercial success .
73 Since M\&M are made to sell, they have a number of features which can be
74 listed on reviewer's checklists. They also have beautiful graphical
75 user interfaces which make wonderful screen shots for reviewer's
76 articles and for packaging. They are generally useful and have no bugs
77 which the manufacturers publicize\footnote{Let me over--stress a point:
78 I didn't say that they have \emph{no} bugs.}.
80 Maxima, on the other hand, was made by academic researchers to test
81 their theories, and developed for their own use. It has been used in
82 hundreds of graduate--level classes in physics, computer science, and so
83 on. It has been used in a great many large projects; the large
84 bibliography available at {\verb*
85 http://www.math.utah.edu:8080/pub/tex/bib/macsyma.html } should give
86 some indication of how much research interest has involved Maxima. It
87 is intended for use by experts, who are willing to invest some effort in
88 learning how to use it. Thus, it is made to be powerful and easy for an
89 expert to use, rather than superficially attractive and easy to learn.
90 It seems to me that the authors have succeeded in three quarters of
91 this: it is indeed fast and powerful, and is not superficially
92 attractive\footnote{But see Section \vref{sec:gui-version}; there is now
93 a graphical user interface which is superficially attractive! }. They
94 have failed in one respect , though, since (to me at least) it seems no
95 harder to learn than M\&M.
97 The authors have generously given the public a powerful and useful tool
98 for doing math homework on a PC and for doing large--scale work on super
99 computers. They have provided a reasonably good reference manual, which
100 is probably all the documentation an expert needs. Unfortunately, the
101 reference manual assumes that you are familiar with the syntax, and
102 doesn't give examples.
104 I'm not an expert, and since it would be ungrateful of me to whine that
105 they didn't give me enough, I've done the only reasonable thing: as I
106 learned how to use Maxima, I've taken notes, which I've tried to put
107 into a readable form, which I hope will help you.
109 \section{Obtaining and Running Maxima}
111 Maxima may be found at \ {\verb http://www.ma.utexas.edu/maxima.html }.
112 Both Windows and Unix versions are available. Get the most recent
113 versions of GCL and Maxima; as I write this, that is version 5.5 beta
114 for the Unix version. Put them into the directories \emph{from} which
115 you wish to install them.
117 \subsection{MSWindows Installation}
119 Since I don't use MSWindows, I don't feel qualified to give any details,
120 however, I understand that the windows installation is the standard
121 windows procedure, and should not cause any problems.
123 \subsection{Unix Installation}
125 The Unix installation is the standard unix procedure: ./configure, make,
126 make install. Unlike the windows version, this will custom configure
127 and compile a version just for your machine. You will need to have
128 write permissions for the directories in which you intend to install the
129 packages. Thus, you may need to use the su command to become root
130 before you type make install. If you can't do that, merely install the
131 packages in some directory for which you have permissions. Your home
132 directory should be fine.
134 Use the cd command to change to the directory in which you have
135 downloaded the tarballs and untar and unzip the files using the command:
137 \begin{verbatim}
138 tar -xzvf filename
139 \end{verbatim}
142 Cd to the GCL directory, read the readme file, and follow the directions
143 to install. This took about 10 minutes on my little
144 machine\footnote{233MHz Pentium II laptop, 144M ram}. Now cd to the
145 Maxima directory, read the readme file, and again follow the
146 directions. Maxima will take a bit longer to compile. Note that before
147 you type ./configure, you will have to edit the configure file for
148 Maxima. Don't panic, this is trivial. The configure file is well
149 commented: just open it in your favorite text editor and follow the
150 instructions. You will need to cut--and--paste in the pathname of the
151 directory where you just built GCL. Again, that's the directory, not the
152 pathname of any file in the directory. There is an example pathname in
153 the configure file. If you have cd'd to the directory in which you are
154 building Maxima, you will be able to leave the MAXDIR=`pwd' line, and
155 comment out the other MAXDIR line. Make sure that the directories in
156 which the Maxima and elisp files will be installed are the ones that you
157 want, and that you have write permissions on those directories. Now you
158 are ready. Type ./configure, make, make install.
160 \subsection{Running Maxima}\label{sec:running-maxima}
162 There are now two versions of Maxima: xmaxima, a GUI version based on
163 the TCL/TK toolkit, and maxima, the traditional command--line version.
164 Both live in the same directory, so if typing /path/maxima starts the
165 command line version, typing /path/xmaxima will start the pretty one.
167 In both versions of Maxima, the input and output are both ascii. This
168 will seem rather plain to someone accustomed to seeing the beautiful
169 on--screen output of M\&M. One types in commands, and what comes back
170 is ascii--art: symbols are drawn, over multiple lines, using the
171 characters available on the keyboard. An expression with sub-- and
172 super--scripts will be written over three lines. If you are accustomed
173 to MSWindows, this will probably seem odd. If you ever need to run
174 Maxima on a machine which you cannot physically access (e.g., by
175 telnetting into your work machine from home), you will realize that this
176 is a \emph{wonderful} feature. If you simply cannot stand ascii output,
177 try the program \idea{Symaxx}, which may be found at {\verb
178 http://symaxx.sourceforge.net/ }. It provides a graphical front end to
179 Maxima, and seems to work reasonably well, though it is still in its
180 infancy. At this stage of its evolution, Symaxx is probably best suited
181 for use as a super--calculator rather than a programming environment.
183 \subsubsection{The GUI Version}\label{sec:gui-version}
185 The X--windows version is probably the best starting point for new users
186 who are not familiar with emacs. For MSWindows users, the GUI will be
187 the only option. The MSWindows and Unix GUI's seem to be identical, so
188 the information in this section should be useful for MSWindows users
189 too. Starting xmaxima will open a window with two panes\footnote{It
190 should go without saying that you must be running X--windows to run the
191 GUI version on a Unix machine. Thus, you won't be able to use it via
192 telnet. }. The upper pane contains a command--line interface to Maxima,
193 while the lower pane contains a Maxima Primer. I recommend the Maxima
194 Primer to your attention, since it has a number of examples. As with
195 all GUI's, there are buttons with labels and menus, so if you want more
196 information about using this interface, your best bet is to start
197 Xmaxima now and explore. The actual process of getting work done in the
198 GUI will be exactly as detailed for the command line, below.
200 \subsubsection{Using the Command--Line Version with Emacs}
202 The default installation of Maxima should have installed several emacs
203 lisp files into the site--lisp subdirectory. You will need to make sure
204 that the appropriate path is in your .emacs file, e.g., on my machine,
205 the following command in my .emacs file does the trick:
207 \begin{verbatim}
208 (setq load-path (cons "/usr/lib/emacs/site-lisp" load-path))
209 \end{verbatim}
211 You'll need to put the correct pathname for your machine, of course.
212 You will also need to copy the add-defaults.el file, which came with the
213 Maxima package, into your .emacs file. Here is what is in it:
215 \begin{verbatim}
216 ;;;BEGIN maxima addition
217 (autoload 'dbl "dbl" "Make a debugger to run
218 lisp, maxima and or gdb in" t)
219 (autoload 'maxima-mode "maxima-mode" "Major mode
220 for editing maxima code and interacting with debugger" t)
221 (autoload 'gcl-mode "gcl" "Major mode for editing
222 maxima code and interacting with debugger" t)
223 (setq auto-mode-alist (cons '("\\.ma?[cx]\\'" . maxima-mode)
224 auto-mode-alist))
225 (setq auto-mode-alist (cons '("\\.li?sp\\'" . gcl-mode)
226 auto-mode-alist))
227 ;;;END maxima addition
228 \end{verbatim}
231 Once these preliminaries are out of the way, you are ready to begin. To
232 run Maxima as an inferior process, use
234 \begin{verbatim}
235 M-x dbl
236 \end{verbatim}
237 which produces the following output in the new buffer:
238 \begin{verbatim}
239 Welcome to DBL a Debugger for Lisp, Maxima, Gdb and others.
241 You start your program as usually would in a shell. For Lisp and
242 Maxima the debugger commands begin with a ':', and there is
243 completion. Typing ':' should list all the commands. In GCL these
244 are typed when in the debugger, and in Maxima they may be typed at any
245 time. To see the wonderful benefits of this mode, type C-h m.
247 Note you may also use this mode to run gdb. In fact I often debug
248 MAXIMA over GCL using gdb, thus having three debuggers at once.
249 To run gdb and enable the automatic line display, you must supply
250 the `--fullname' keyword as in:
252 gdb your-file --fullname
253 Current directory is /home/tomlinso/jerrys/
254 [tomlinso@localhost jerrys]%
255 \end{verbatim}
257 Now, at the prompt in that buffer, type maxima, and begin:
259 \begin{verbatim}
260 [tomlinso@localhost jerrys]% maxima
261 GCL (GNU Common Lisp) Version(2.3.8) Fri Feb 23 18:10:05 EST 2001
262 Licensed under GNU Library General Public License
263 Contains Enhancements by W. Schelter
264 Maxima 5.5 Fri Feb 23 18:09:58 EST 2001 (with enhancements by W.
265 Schelter).
266 Licensed under the GNU Public License (see file COPYING)
267 (C1)
268 \end{verbatim}
269 This does not seem to provide syntactic highlighting, but does seem to
270 work well. It is a bit of a disappointment to me after using ESS,
271 though.
274 \subsubsection{Using the Emacs Info with
275 Maxima}\label{sec:using-emacs-info}
277 \fixme{Needs to be written!}
282 \section{Quick Start}
284 In order to run Maxima, type maxima or xmaxima at the shell prompt. See
285 Section \vref{sec:running-maxima} for some details about which to
286 choose. If you are running xmaxima, or if you have an MSWindows
287 machine, you will start a GUI in which you can type commands, which
288 should work as described here. I don't use MSWindows, so if you have
289 an MSWindows machine, I really can't help you with details about the
290 user interface which are specific to MSWindows.
292 In order to exit Maxima, one can type \noun{quit()};
294 \begin{verbatimtab}
295 (C18) quit();
297 [tomlinso@localhost tomlinso]%
298 \end{verbatimtab}
299 to end the Maxima session and return to the shell.
301 You will sooner or later make a syntax error, and fall into a debugging
302 level. It can happen like this:
303 \begin{verbatimtab}
304 (C2) describe(set-up-index);
306 Error: Takes a symbol ((MPLUS SIMP) ((MTIMES SIMP) -1 $index) $set ...)
307 Fast links are on: do (si::use-fast-links nil) for debugging
308 Error signalled by CATCH.
309 Broken at MACSYMA-TOP-LEVEL. Type :H for Help.
310 MAXIMA>>:q
312 (C3)
313 \end{verbatimtab}
314 To get back out of the debugging mode, type :q as above. Notice that
315 the colon comes \emph{before} the q!
318 \subsection{Getting ``Help!''}
320 There is a manual which you should have found included with the Maxima
321 package. I will assume that you have it available to refer to. It is a
322 reasonably good reference, and has some introductory material in it.
323 Some sections of it are particularly useful to beginners. In
324 particular, the
325 \begin{itemize}
326 \item Introduction to Command Line
327 \item Help
328 \item Input and Output
329 \item Runtime Environment
330 \item Constants
331 \end{itemize}
332 sections have some value for beginners. Unfortunately, the manual has
333 little else which is oriented towards beginners. Some sections refer to
334 Macsyma, which was a non--libr\'e, sometimes non--free predecessor.
335 Some sections, particularly Miscellaneous Options, are specific to
336 DEC-10 machines. One section (Symmetries) is in French, which will
337 limit its usefulness to Americans (we only speak English\dots).
339 \subsubsection{Using the Manual}
341 The manual is intended as a reference work, and so \emph{if} you know
342 where to look, it has much of what you need. It has a complete index
343 of functions and variables. Most sections have at least a brief
344 introduction, and then a list of functions and variable definitions
345 which logically fall under that heading, in alphabetic order. The
346 functions are usually what you should look for first, as they will be
347 what you need to actually do a job. You will also need to look at the
348 variables, since they often control the behavior of the functions.
349 Usually the functions will refer you to the appropriate variables,
350 another good reason to look first at the functions.
352 \subsubsection{Electronic Help} There is also online and electronic
353 help available. The manual is available in html format, which is
354 convenient (and cheaper than printing out the 230+ page manual). It is
355 possible to read the Maxima info files using emacs. See section
356 \vref{sec:using-emacs-info} for details. If you are using the Xwindows
357 version (or MSWindows) there is help available in the bottom pane of the
358 GUI.
360 There is also some help available from the Maxima command line. The
361 manual mentions three help functions, which seem to have similar
362 syntax. The first is \noun{describe(command)}, e.g.:\footnote0{The stuff
363 after this sentence, {\verb in this font}, is copied verbatim from a
364 Maxima session, to illustrate commands and their results.}1
366 \begin{verbatimtab}
367 (C63) describe(save);
370 0: FASSAVE :(maxima.info)Definitions for Input and Output.
371 1: SAVE :Definitions for Input and Output.
372 2: SAVEDEF :Definitions for Input and Output.
373 3: SAVEFACTORS :Definitions for Polynomials.
374 Enter n, all, none, or multiple choices eg 1 3 : 0
376 Info from file /usr/lib/maxima-5.4/info/maxima.info:
377 - Function: FASSAVE (ARGS)
378 is similar to SAVE but produces a FASL file in which the sharing
379 of subexpressions which are shared in core is preserved in the
380 file created. Hence, expressions which have common subexpressions
381 will consume less space when loaded back from a file created by
382 FASSAVE rather than by SAVE. Files created with FASSAVE are
383 reloaded using LOADFILE, just as files created with SAVE. FASSAVE
384 returns a list of the form [<name of file>,<size of file in
385 blocks>,...] where ... are the things saved. Warnings are
386 printed out in the case of large files. FASSAVE may be used while
387 a WRITEFILE is in progress.
389 (D63) FALSE
390 \end{verbatimtab}
392 Describe seems to amplify a bit on some of the commands in the manual.
393 If you give it all as a reply, you will need a semicolon after the all.
394 Strangely, you don't seem to need the semicolon if your choice is
395 numeric.
397 Next is \noun{apropos(stuff)}. This doesn't seem to work, though it is
398 mentioned in the Reference Manual in Chapter 26, Miscellaneous Options,
399 and the function can be described with describe(apropos);.
401 The command \noun{demo(stuff)} demonstrates certain commands. It will
402 run a file, so use a filename as the argument. You will need to hit a
403 semicolon followed by a carriage return to step through the examples.
404 The command \noun{example(stuff)} will run an example file in batch
405 mode for some commands. To find out which commands and topics you can
406 get examples for, type examples(manual);. Actually, example(anything not
407 in the list of things which example can provide an example of) will
408 display the list. I recommend that you experiment with these. The
409 examples tend to be cryptic, but do at least give a starting point for
410 learning.
413 \subsection{Syntax}
415 Maxima's syntax is more--or--less standard for a programming language.
416 That is, there is nothing {\`o}utr\'e such as is found in APL or
417 intercal (well, not much). On the other hand, because it is
418 ``normal'', it doesn't have the consistancy of Lisp\footnote{Yes, Lisp
419 is rather strange if you are used to Fortran, but it \emph{is}
420 consistent: everything is prefix notation.}.
422 \paragraph{A quick list of some important syntactic points:}
423 \begin{itemize}
424 \item Everything must end with either a \noun{semicolon} (\noun{;}) or a
425 \noun{dollar sign} (\noun{\$})! If the interpreter seems to ``hang'',
426 you probably forgot the semicolon. Normally you will want to use a
427 semicolon to end a line. If you don't want to see the output of your
428 command (e.g., it might be too big), use the \$ instead. It will
429 \idea{suppress the output}.
431 \item The assignment operator is the colon. To assign 4 to the variable
432 a, proceed as follows:
434 \begin{verbatimtab}
435 (C3) a:4;
437 (D3) 4
438 (C4)
439 \end{verbatimtab}
441 \item To declare a function, use colon equals, like so:
442 \begin{verbatimtab}
443 (C4) f(x,y):=x^2+y^2;
446 (D4) f(x, y) := x + y
447 (C5)
448 \end{verbatimtab}
450 \item To differentiate a function, use diff(f(x,y),x);
451 \begin{verbatimtab}
452 (C5) diff(f,x);
454 (D5) 0
455 (C6) diff(f(x,y),x);
457 (D6) 2 x
458 (C7)
459 \end{verbatimtab}
460 Notice that {\verb diff(f,x);} didn't work. It seems to have tried to
461 differentiate the variable f with respect to the variable x, rather
462 than differentiating the function f(x,y). { \verb diff(f(x,y),x);} did
463 what we wanted. We didn't \emph{need} to make f a function; it is also
464 possible to differentiate expressions.
466 \item Matrices are not arrays! An array is a data structure, while a
467 matrix is an object on which one may commit linear algebra. One way to
468 construct matrices is with the matrix command.
470 \begin{verbatimtab}
471 (C29) matrix([w,x],[y,z]);
473 [ w x ]
474 (D29) [ ]
475 [ y z ]
476 (C30)
477 \end{verbatimtab}
479 \end{itemize}
481 Maxima of course has a number of built--in functions with which one can
482 save and load data, differentiate and integrate, plot, generate Fortran
483 or \TeX code, and so on. As mentioned above, it also has a number of
484 global variables which one can use to affect the behavior of these
485 functions.
487 \subsubsection{Some Other Elements of Syntax}
489 The \noun{square bracket}, (\noun{[]}) is used to delimit a list. The
490 \noun{parentheses } (\ \noun{()} \ ) are used to enclose the arguments
491 of functions. The asterisk, (\noun{*}) is used for multiplication. The
492 \noun{caret}, (\noun{\^{}}) is used for exponentiation. The
493 \noun{double colon}, \noun{::} is used to assign the contents of one
494 variable to a variable which is referenced by another variable. See
495 Section \vref{sec:expressions} for some details on this.
498 \subsubsection{Using Earlier Results} The \idea{prompt} in Maxima is
499 (\idea{Cnumber}), where number is a counter, telling you how many
500 commands you have issued. When Maxima returns a result to you, it will
501 preface it with (\idea{Dnumber}), as shown below:
503 \begin{verbatimtab}
504 (C2) 1+1;
506 (D2) 2
507 (C3) %+3;
509 (D3) 5
510 (C4) %th(2)+4;
512 (D4) 6
513 (C5) D2;
515 (D5) 2
516 (C6)
517 \end{verbatimtab}
518 There are several points to notice here. First, the (Dnumber)'s have
519 the same number as the (Cnumber)'s which produced them. Second, you can
520 refer to the previous result as \noun{percent}, \noun{\%}, as shown in
521 (C3) in the example above. The command \%+3; says to take the previous
522 result and add three to it. Third, you can refer to an earlier result
523 by saying \noun{\%th(i)} for the i${}^\mathrm{th}$ previous result. On
524 command (C4) above, I added 4 to the second previous result, which was
525 (D2). Fourth, you can refer to the results by name. The result of the
526 1+1; command was (D2). In command (C5), I re--displayed it by typing
527 its name D2.
530 \subsection{Writing and reading files}
532 Maxima gives several ways to save a workspace to a file.
533 \noun{save(filename,arg1,arg2,\dots)} allows you to save the variables
534 arg1, arg2 \dots to the file filename. \emph{filename} should be a
535 proper Unix filename, with path. If a relative path is given (i.e., a
536 path which does \emph{not} begin with a / ), it is taken to be relative
537 to the present working directory. \fixme{How do we find the pwd?
538 Relative pathnames \emph{don't} work?} Here is an example:
540 \begin{verbatimtab}
542 (C6) f(x,y):=x^2+y^2+2*x*y;
545 (D6) f(x, y) := x + y + 2 x y
546 (C7) a:4;
548 (C12) save("/home/tomlinso/slime.stuff",f,a);
550 (D12) /home/tomlinso/slime.stuff
552 \end{verbatimtab}
553 This saves the function f and the variable a to a file in my home
554 directory. If you do this and then take a look at the file, you will
555 find that it is a text file, but does not look at all like the function
556 you saw on your screen. You will get some idea about why it looks so
557 strange in section \vref{sec:internal-details}, which details some of
558 the internal workings of Maxima.
560 The command \noun{loadfile(filename)} should reload a file saved by
561 save() or \noun{fassave()}. The filename uses the same syntax here as
562 in save.
564 There is also the command \noun{writefile(filename)}, which will keep a
565 log of your maxima session. If you run Maxima under emacs, this may
566 seem redundant. The file which this command makes is \emph{not}
567 readable by loadfile().
569 \fixme{Is there a way to load some ascii data, maybe a csv file?}
571 \section{Expressions}\label{sec:expressions}
573 \idea{Expressions} are still a bit fuzzy to me in this version of the
574 notes, \fixme{get defuzzed!} as are functions. I won't try to define
575 them yet.
577 \subsection{Assignment Operators}
579 Maxima has two assignment operators: the \noun{colon} (\noun{:}) and
580 the \noun{double colon}, (\noun{::}). The single colon is simple to
581 understand. A:3; sets the variable A to the value 3.
582 \begin{verbatimtab}
583 (C11) A:3$
585 (C12) A;
587 (D12) 3
588 (C13)
589 \end{verbatimtab}
591 The double colon is a bit harder to grasp at first. Consider the
592 following example:
594 \begin{verbatimtab}
595 (C24) A:3$
597 (C25) B:5$
599 (C26) C:'A;
601 (D26) A
602 (C27) C::B;
604 (D27) 5
605 (C28)
606 \end{verbatimtab}
607 I assigned the value 3 to the symbol A, the value 5 to the symbol B,
608 and then I assigned the symbol A to the symbol B. That's why (C26)
609 says C:'A;, the apostrophe prevents Maxima from evaluating the symbol A
610 and assigning 3 to C. Then, in (C27), I used the double colon to assign
611 the value of B (remember, that's 5) to the value of C (remember, that's
612 A). Here's the final result:
614 \begin{verbatimtab}
616 (C28) A;
618 (D28) 5
619 (C29)
620 \end{verbatimtab}
621 A is five! The manual says ``:: assigns the value of the expression on
622 its right to the value of the quantity on its left \dots''. Hopefully
623 that makes more sense with an example staring at you than it did the
624 first time I read it. This seems to be analogous to the idea of a
625 pointer: we didn't assign the value of B to C, we assigned the value of
626 B to what C \emph{held}, or pointed to.
628 \section{Defining Functions}
630 To define a \idea{function}, use function name:=function value, as
631 follows
633 \begin{verbatimtab}
635 (C9) lv:=x^2+2*x*y+y^2;
637 Improper function definition:
639 -- an error. Quitting. To debug this try DEBUGMODE(TRUE);)
640 (C10) lv(x,y):=a*x^2+2*a*b*x*y+b*y^2;
643 (D10) lv(x, y) := a x + 2 a b x y + b y
644 (C11)
646 \end{verbatimtab}
648 Notice that we must specify what lv is a function of. The first
649 attempt, (C9), didn't work, while (C10) specifies that lv depends on x
650 and y, but that a and b are parameters. It appears that Maxima's
651 function is not a function in the sense that mathematicians use the
652 word, but rather in the computer science sense. That is, a function is
653 a subroutine which may be called. Thus, you may find what you are
654 looking for in Section \vref{sec:expressions}, which covers expressions.
656 \section{Doing Calculus}
658 \subsection{Differentiation}
660 \subsubsection{Differential Equations}
662 \subsection{Integration}
666 \section{Working with Matrix Algebra}
668 \subsection{Building and Manipulating Matrices}
670 Matrices are not arrays! An array is a data structure, while a matrix
671 is an objecton on which one may commit linear algebra.
673 One way to construct matrices is with the \noun{entermatrix(m,n)}
674 command, which allows one to enter a matrix with m rows and n columns,
675 with prompting. The manual gives a good example of this, which I won't
676 repeat.
678 Another way to construct matrices is with the \noun{matrix} command.
681 \begin{verbatimtab}
682 (C29) matrix([w,x],[y,z]);
684 [ w x ]
685 (D29) [ ]
686 [ y z ]
687 (C30) row(matrix([w,x],[y,z]),1);
689 (D30) [ w x ]
690 (C31) row(matrix([w,x],[y,z]),2);
692 (D31) [ y z ]
693 \end{verbatimtab}
695 The matrix command takes as its arguments a series of lists. Each list
696 makes up one row of the matrix. The \noun{row} command takes a matrix
697 and a number as arguments, and returns the row specified by the number.
698 There is also a \noun{submatrix} command, which takes a number, a
699 matrix, and a number as arguments. The first number specifies the row to
700 cast out, the second number specifies the column to cast out, and the
701 function returns the submatrix which is lect after casting out these
702 rows and columns.
704 \begin{verbatimtab}
706 (C7) m:matrix([a,b,c],[d,e,f],[g,h,i]);
708 [ A b c ]
710 (D7) [ d e f ]
712 [ g h i ]
713 (C8) submatrix(2,m,2);
715 [ A c ]
716 (D8) [ ]
717 [ g i ]
718 (C9) submatrix(1,m,3);
720 [ d e ]
721 (D9) [ ]
722 [ g h ]
723 (C10)
724 \end{verbatimtab}
725 In this example, we first defined the matrix m, then cast out the second
726 row and column on line (C8). Finally in line (C9), we cast out the
727 first row and the last column.
729 The \noun{diagmatrix(n,x)} command produces a diagonal matrix of size n,
730 with all the diagonal elements x. Plainly, x=1 will produce an n by n
731 identity matrix. So will \noun{ident(n)}.
733 \begin{verbatimtab}
734 (C11) diagmatrix(4,3);
736 [ 3 0 0 0 ]
738 [ 0 3 0 0 ]
739 (D11) [ ]
740 [ 0 0 3 0 ]
742 [ 0 0 0 3 ]
743 (C12)
744 \end{verbatimtab}
746 A third way to build a matrix is with the
747 \noun{genmatrix(array,i2,j2,i1,j1)} command. This fills a matrix from
748 an array. The manual provides examples.
750 \subsection{Doing Linear Algebra}
752 \paragraph{Matrix Multiplication} To multiply two matrices together, the
753 \noun{dot operator}, or \noun{.} is used. To make certain that the
754 interpreter does not mistake it for a decimal point, it is important
755 that at least one space should be left on each side of it.
757 \begin{verbatimtab}
758 (C26) A:matrix([b,c],[d,e]);
760 [ b c ]
761 (D26) [ ]
762 [ d e ]
763 (C27) f:matrix([g,h],[i,j]);
765 [ g h ]
766 (D27) [ ]
767 [ i j ]
768 (C28) A . f;
770 [ c i + b g c j + b h ]
771 (D28) [ ]
772 [ e i + d g e j + d h ]
773 (C29)
774 \end{verbatimtab}
776 And a quadratic form:
778 \begin{verbatimtab}
779 (C29) matrix([1,2]) . A . transpose(matrix([1,2]));
781 (D29) 2 (2 e + d) + 2 c + b
782 (C30)
783 \end{verbatimtab}
784 The \noun{transpose()} function, of course, gives the transpose of its
785 matrix argument.
787 To square a matrix, use the dot operator, as in A . A, or use the
788 exponential version:
790 \begin{verbatimtab}
791 (C7) a^^2;
793 [ 2 ]
794 [ c d + b c e + b c ]
795 (D7) [ ]
796 [ 2 ]
797 [ d e + b d e + c d ]
798 (C8) a . a;
800 [ 2 ]
801 [ c d + b c e + b c ]
802 (D8) [ ]
803 [ 2 ]
804 [ d e + b d e + c d ]
805 (C9)
806 \end{verbatimtab}
809 The \noun{invert()} function also has a self--explanatory name. Notice
810 that the \noun{doallmxops} variable, if true, causes the determinant to
811 be moved inside the inverse. When false, it causes the determinant to
812 be left outside the matrix. The Reference Manual also mentions the
813 variable \noun{detout} in this regard, but it seems to have no effect.
815 \begin{verbatimtab}
816 (C42) doallmxops:true;
818 (D42) TRUE
819 (C43) invert(a);
821 [ e c ]
822 [ --------- - --------- ]
823 [ b e - c d b e - c d ]
824 (D43) [ ]
825 [ d b ]
826 [ - --------- --------- ]
827 [ b e - c d b e - c d ]
828 (C44) doallmxops:false;
830 (D44) FALSE
831 (C45) invert(A);
833 [ e - c ]
835 [ - d b ]
836 (D45) ------------
837 b e - c d
838 (C46)
839 \end{verbatimtab}
842 \paragraph{Row Reduction} The \noun{echelon(matrix)} command returns
843 the echelon form of the matrix argument.
845 \section{Getting Numbers}
847 \subsection{Evaluating: the ev() function}
849 \section{Plotting}
851 \section{Internal Details} \label{sec:internal-details}
853 \subsection{Lists}
855 \subsection{Maxima and Lisp}
857 \section{\emph{Making} it Work: What to do When Maxima is Stubborn}
859 \subsection{Pickapart}
860 \clearpage
861 \printindex
863 \end{document}