login  home  contents  what's new  discussion  bug reports     help  links  subscribe  changes  refresh  edit

Edit detail for SandBoxMaxima revision 5 of 17

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
Editor: page
Time: 2007/09/11 22:53:53 GMT-7
Note:

added:


Testing the Maxima interface

Maxima commands are entered like this:

  \begin{maxima}
  command;
  \end{maxima}

Each such pseudo-environment is saved in a temporary file and executed via the Maxima batch("filename") command.

First test: \begin{maxima} 1+2; 2+3; sqrt(2); \end{maxima}

We can also print the root as float: \begin{maxima} sqrt(2), numer; \end{maxima}

We are able to separate out the LaTeX? code and display it nicely:

But separating input lines from output lines is rather hard.

Here is are some more sophisticated examples:

Math Teachers: Maxima Examples
WebSite:www.google.ca/search?hs=x4&hl=en&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&q=maths.york.ac.uk%2Fyorkmoodle%2Fmod%2Fresource%2Fview.php%3Fid%3D590&btnG=Search&meta=

Ordinary differential equations \begin{maxima} depends(y,x); diff(y,x)=(4-2x)/(3y^2-5); ode2(%,y,x); \end{maxima}

Working with Matrices \begin{maxima} a: matrix([1,2]?,[3,4]?); b: matrix([2,2]?,[2,2]?); a.b; a*b; h[i,j]:=1/(i+j); a: genmatrix(h,3,3); determinant(a); b: matrix([2,3]?,[5,6]?); echelon(b); invert(b); eigenvectors(b); \end{maxima}

Programming \begin{maxima} s:0; for i:1 while i<=10 do s:s+i; done; s; fib[0]:0; fib[1]:1; fib[n]:=fib[n-1]+fib[n-2]; fib[20]; \end{maxima}

For more examples, see SandBoxMaxima2?.

See also:

WebSite:maxima.sourceforge.net:/docs/maximabook

WebSite:/melusine.eu.org:/syracuse/maxima/

How to properly separate Maxima input and output --billpage, Wed, 09 Aug 2006 11:51:17 -0500 reply
I would like to be able to distinquish Maxima input (%i ) lines from output (%o ) lines, but Maxima insists on horizonatally centering the line identifier with the 2d ascii artwork. This makes find the start of an input or output line nearly impossible.

I know almost nothing about Maxima...

I have read about the Maxima external interface but I do not seem to be able to get Maxima to behave this way:

WebSite:/web.mit.edu:/maxima_v5.9.1/share/maxima/5.9.1/doc/implementation/external-interface.txt

but I do not understand how to get it to work. For example entering the following commands at the console:

  (setf *prompt-prefix* "prefix: ")
  (setf *prompt-suffix* " :suffix")

seems to have no effect. We are running here Maxima 5.9.3.

Any hints or pointers to some more useful documentation from the Maxima gurus would be greatly appreciated!

Try this --Bob McElrath?, Wed, 09 Aug 2006 13:01:46 -0500 reply
Use the texmacs scripts directly, and modify them...

echo "integrate(x^2,x);" | maxima -p /usr/share/texmacs/TeXmacs?/plugins/maxima/lisp/texmacs-maxima-5.9.2.lisp > integral.txt

Note that the texmacs inserts a lot of control characters that will make your xterm go goofy, so above I sent the output to a file and you can look at it with a text editor.

We really don't want to parse maxima's ascii-art... ;)

Good work!

-- Bob

Re: Try this --Bill Page, Wed, 09 Aug 2006 15:32:25 -0500 reply
Damn good idea! Thanks.

I pulled just the texmacs-maxima-5.9.2.lisp from the TeXmacs? CVS and it seems to work fine. I think I will mode it a little to make it more friendly to Python. This is going to make things a lot easier.

maxima script for mathaction --billpage, Thu, 10 Aug 2006 02:32:14 -0500 reply
mathaction-maxima-5.9.3.lisp

Based on a suggestion by Bob McElrath?, I modified the lisp code of the texmacs-maxima interface to produce something much easier to handle than raw Maxima console interface using only Python. This version also avoids the funny binary delimiter characters used by TeXmacs?. The result bears some resemblence to an XML-style protocol.

This works really great as you can see from the examples above.

The original version for TeXmacs? was written by James Amundson and modified for recent versions of TeXmacs? and Maxima by A. G. Grozin ARXiv:html/cs.SC/0504039

lisp
(in-package :maxima)
#+clisp (defvar *old-suppress-check-redefinition*
              custom:*suppress-check-redefinition*)
#+clisp (setf custom:*suppress-check-redefinition* t)
(setf *alt-display2d* 'texmacs)
(setf *prompt-prefix* "<prompt>")
(setf *prompt-suffix* "</prompt>")
; (setf *general-display-prefix* "<verbatim>")
(setf *maxima-prolog* "<maxima>")
(setf *maxima-epilog* "</maxima>")
#-gcl(setf *debug-io* (make-two-way-stream *standard-input* *standard-output*))
#+(or cmu sbcl scl)
(setf *terminal-io* (make-two-way-stream *standard-input* *standard-output*))
(defun latex (x) (let ((ccol 1)) (mapc #'myprinc (if (and (listp x) (cdr x) (equal (cadr x) "Is ")) (tex x '("<display>") '("</display>") 'mparen 'mparen) (tex x '("<latex>") '("</latex>") 'mparen 'mparen)))))
(setf *alt-display2d* 'latex)
;; Small changes to mactex.lisp for interfacing with TeXmacs ;; Andrey Grozin, 2001-2005
(defun main-prompt () (format () "~A(~A~D) ~A" *prompt-prefix* (tex-stripdollar $inchar) $linenum *prompt-suffix*))
(declare-top (special lop rop ccol $gcprint $inchar) (*expr tex-lbp tex-rbp)) (defconstant texport *standard-output*)
(defun tex-stripdollar (sym) (or (symbolp sym) (return-from tex-stripdollar sym)) (let* ((name (quote-% (print-invert-case sym))) (name1 (if (memq (elt name 0) '($ &)) (subseq name 1) name)) (l (length name1))) (if (eql l 1) name1 (concatenate 'string "\\mathrm{" name1 "}"))))
(defprop mtimes "\\*" texsym)
(defun texmacs (x) (let ((ccol 1)) (mapc #'myprinc (tex x '("latex:$\\displaystyle ") '("$ ") 'mparen 'mparen))))
;; In order to allow cut-and-paste from output to input, ;; we should output \sin(x), not \sin x.
(map 'list #'(lambda (f) (remprop f 'tex) (remprop f 'tex-rbp)) '(%sin %cos %tan %cot %sec %csc %sinh %cosh %tanh %coth %asin %acos %atan %exp %log))
(remprop '$pi 'texword) (remprop '$gamma 'texword) (setf (get '$%i 'texword) "\\mathi") (setf (get '$%e 'texword) "\\mathe")
;; Also, we should output f(x)^2, not f^2(x)
(defun tex-mexpt (x l r) (let((nc (eq (caar x) 'mncexpt))) ; true if a^^b rather than a^b (setq l (if (and (numberp (cadr x)) (numneedsparen (cadr x))) (tex (cadr x) (cons "\\left(" l) '("\\right)") lop (caar x)) (tex (cadr x) l nil lop (caar x))) r (if (mmminusp (setq x (nformat (caddr x)))) ;; the change in base-line makes parens unnecessary (if nc (tex (cadr x) '("^ {-\\langle ")(cons "\\rangle }" r) 'mparen 'mparen) (tex (cadr x) '("^ {- ")(cons " }" r) 'mminus 'mparen)) (if nc (tex x (list "^{\\langle ")(cons "\\rangle}" r) 'mparen 'mparen) (if (and (integerp x) (< x 10)) (tex x (list "^")(cons "" r) 'mparen 'mparen) (tex x (list "^{")(cons "}" r) 'mparen 'mparen))))) (append l r)))
;; binomial coefficients
(defun tex-choose (x l r) `(,@l "\\binom{" ,@(tex (cadr x) nil nil 'mparen 'mparen) "}{" ,@(tex (caddr x) nil nil 'mparen 'mparen) "}" ,@r))
;; Integrals, sums, products
(defun tex-int (x l r) (let ((s1 (tex (cadr x) nil nil 'mparen 'mparen)) ;;integrand delims / & d (var (tex (caddr x) nil nil 'mparen rop))) ;; variable (cond((= (length x) 3) (append l `("\\int {" ,@s1 "}{\\;\\mathd\\;" ,@var "}\\big.") r)) (t ;; presumably length 5 (let ((low (tex (nth 3 x) nil nil 'mparen 'mparen)) ;; 1st item is 0 (hi (tex (nth 4 x) nil nil 'mparen 'mparen))) (append l `("\\int_{" ,@low "}^{" ,@hi "}{" ,@s1 "\\;\\mathd\\;" ,@var "}\\big.") r))))))
(defun tex-sum(x l r) (let ((op (cond ((eq (caar x) '%sum) "\\sum_{") ((eq (caar x) '%product) "\\prod_{") ;; extend here )) ;; gotta be one of those above (s1 (tex (cadr x) nil nil 'mparen rop)) ;; summand (index ;; "index = lowerlimit" (tex `((mequal simp) ,(caddr x),(cadddr x)) nil nil 'mparen 'mparen)) (toplim (tex (car(cddddr x)) nil nil 'mparen 'mparen))) (append l `( ,op ,@index "}^{" ,@toplim "}{" ,@s1 "}\\big.") r)))
(defun tex-lsum(x l r) (let ((op (cond ((eq (caar x) '%lsum) "\\sum_{") ;; extend here )) ;; gotta be one of those above (s1 (tex (cadr x) nil nil 'mparen rop)) ;; summand (index ;; "index = lowerlimit" (tex `((min simp) , (caddr x), (cadddr x)) nil nil 'mparen 'mparen))) (append l `( ,op ,@index "}}{" ,@s1 "}\\big.") r)))
;; This is a hack for math input of integrals, sums, products
(defmfun $tmint (a b f x) ($integrate f x a b))
(defmspec $tmsum (l) (setq l (cdr l)) (if (= (length l) 3) (dosum (caddr l) (cadar l) (meval (caddar l)) (meval (cadr l)) t) (wna-err '$tmsum)))
(defmspec $tmlsum (l) (setq l (cdr l)) (or (= (length l) 2) (wna-err '$tmlsum)) (let ((form (cadr l)) (ind (cadar l)) (lis (meval (caddar l))) (ans 0)) (or (symbolp ind) (merror "Second argument not a variable ~M" ind)) (cond (($listp lis) (loop for v in (cdr lis) with lind = (cons ind nil) for w = (cons v nil) do (setq ans (add* ans (mbinding (lind w) (meval form))))) ans) (t `((%lsum) ,form ,ind ,lis)))))
(defmspec $tmprod (l) (setq l (cdr l)) (if (= (length l) 3) (dosum (caddr l) (cadar l) (meval (caddar l)) (meval (cadr l)) nil) (wna-err '$tmprod)))
#+clisp (setf custom:*suppress-check-redefinition* *old-suppress-check-redefinition*)
lisp
; compiling file "/var/zope2/var/LatexWiki/3232980969489245406-25px001.lisp" (written 21 APR 2011 10:35:49 AM):
; /var/zope2/var/LatexWiki/3232980969489245406-25px001.fasl written ; compilation finished in 0:00:00.315
>> System error: Execution of a form compiled with errors. Form: (SETQ *PACKAGE* (FIND-UNDELETED-PACKAGE-OR-LOSE MAXIMA)) Compile-time error: (during compile-time-too processing) The name "MAXIMA" does not designate any package.

Some or all expressions may not have rendered properly, because Maxima returned the following error:
Error: ulimit -t 240; maxima -p /var/zope2/Products/ZWiki/plugins/mathaction/mathaction-maxima-5.9.3.lisp < /var/zope2/var/LatexWiki/1762373067939120473-25px.mbat


Some or all expressions may not have rendered properly, because Latex returned the following error:
This is pdfTeXk, Version 3.141592-1.40.3 (Web2C 7.5.6)
 \write18 enabled.
 %&-line parsing enabled.
entering extended mode
(./5381280253770850235-16.0px.tex
LaTeX2e <2005/12/01>
Babel <v3.8h> and hyphenation patterns for english, usenglishmax, dumylang, noh
yphenation, arabic, farsi, croatian, ukrainian, russian, bulgarian, czech, slov
ak, danish, dutch, finnish, basque, french, german, ngerman, ibycus, greek, mon
ogreek, ancientgreek, hungarian, italian, latin, mongolian, norsk, icelandic, i
nterlingua, turkish, coptic, romanian, welsh, serbian, slovenian, estonian, esp
eranto, uppersorbian, indonesian, polish, portuguese, spanish, catalan, galicia
n, swedish, ukenglish, pinyin, loaded.
(/usr/share/texmf-texlive/tex/latex/base/article.cls
Document Class: article 2005/09/16 v1.4f Standard LaTeX document class
(/usr/share/texmf-texlive/tex/latex/base/size12.clo))
(/usr/share/texmf-texlive/tex/latex/ucs/ucs.sty
(/usr/share/texmf-texlive/tex/latex/ucs/data/uni-global.def))
(/usr/share/texmf-texlive/tex/latex/base/inputenc.sty
(/usr/share/texmf-texlive/tex/latex/ucs/utf8x.def))
(/usr/share/texmf-texlive/tex/latex/bbm/bbm.sty)
(/usr/share/texmf-texlive/tex/latex/jknapltx/mathrsfs.sty)
(/usr/share/texmf-texlive/tex/latex/base/fontenc.sty
(/usr/share/texmf-texlive/tex/latex/base/t1enc.def))
(/usr/share/texmf-texlive/tex/latex/pstricks/pstricks.sty
(/usr/share/texmf-texlive/tex/generic/pstricks/pstricks.tex
`PSTricks' v1.15  <2006/12/22> (tvz)
(/usr/share/texmf-texlive/tex/generic/pstricks/pstricks.con))
(/usr/share/texmf/tex/latex/xcolor/xcolor.sty
(/etc/texmf/tex/latex/config/color.cfg)
(/usr/share/texmf-texlive/tex/latex/graphics/dvips.def)
(/usr/share/texmf-texlive/tex/latex/graphics/dvipsnam.def)))
(/usr/share/texmf-texlive/tex/latex/graphics/epsfig.sty
(/usr/share/texmf-texlive/tex/latex/graphics/graphicx.sty
(/usr/share/texmf-texlive/tex/latex/graphics/keyval.sty)
(/usr/share/texmf-texlive/tex/latex/graphics/graphics.sty
(/usr/share/texmf-texlive/tex/latex/graphics/trig.sty)
(/etc/texmf/tex/latex/config/graphics.cfg))))
(/usr/share/texmf-texlive/tex/latex/pst-grad/pst-grad.sty
(/usr/share/texmf-texlive/tex/generic/pst-grad/pst-grad.tex
(/usr/share/texmf-texlive/tex/latex/xkeyval/pst-xkey.tex
(/usr/share/texmf-texlive/tex/latex/xkeyval/xkeyval.sty
(/usr/share/texmf-texlive/tex/latex/xkeyval/xkeyval.tex)))
`pst-plot' v1.05, 2006/11/04 (tvz,dg,hv)))
(/usr/share/texmf-texlive/tex/latex/pstricks/pst-plot.sty
(/usr/share/texmf-texlive/tex/generic/pstricks/pst-plot.tex
 v97 patch 2, 1999/12/12
(/usr/share/texmf-texlive/tex/generic/multido/multido.tex
 v1.41, 2004/05/18 <tvz>))) (/usr/share/texmf-texlive/tex/generic/xypic/xy.sty
(/usr/share/texmf-texlive/tex/generic/xypic/xy.tex Bootstrap'ing: catcodes,
docmode, (/usr/share/texmf-texlive/tex/generic/xypic/xyrecat.tex)
(/usr/share/texmf-texlive/tex/generic/xypic/xyidioms.tex)

Xy-pic version 3.7 <1999/02/16> Copyright (c) 1991-1998 by Kristoffer H. Rose <krisrose@ens-lyon.fr> Xy-pic is free software: see the User's Guide for details.

Loading kernel: messages; fonts; allocations: state, direction, utility macros; pictures: \xy, positions, objects, decorations; kernel objects: directionals, circles, text; options; algorithms: directions, edges, connections; Xy-pic loaded) (/usr/share/texmf-texlive/tex/generic/xypic/xyall.tex Xy-pic option: All features v.3.3 (/usr/share/texmf-texlive/tex/generic/xypic/xycurve.tex Xy-pic option: Curve and Spline extension v.3.7 curve, circles, loaded) (/usr/share/texmf-texlive/tex/generic/xypic/xyframe.tex Xy-pic option: Frame and Bracket extension v.3.7 loaded) (/usr/share/texmf-texlive/tex/generic/xypic/xycmtip.tex Xy-pic option: Computer Modern tip extension v.3.3 (/usr/share/texmf-texlive/tex/generic/xypic/xytips.tex Xy-pic option: More Tips extension v.3.3 loaded) loaded) (/usr/share/texmf-texlive/tex/generic/xypic/xyline.tex Xy-pic option: Line styles extension v.3.6 loaded) (/usr/share/texmf-texlive/tex/generic/xypic/xyrotate.tex Xy-pic option: Rotate and Scale extension v.3.3 loaded) (/usr/share/texmf-texlive/tex/generic/xypic/xycolor.tex Xy-pic option: Colour extension v.3.3 loaded) (/usr/share/texmf-texlive/tex/generic/xypic/xymatrix.tex Xy-pic option: Matrix feature v.3.4 loaded) (/usr/share/texmf-texlive/tex/generic/xypic/xyarrow.tex Xy-pic option: Arrow and Path feature v.3.5 path, \ar, loaded) (/usr/share/texmf-texlive/tex/generic/xypic/xygraph.tex Xy-pic option: Graph feature v.3.7 loaded) loaded) (/usr/share/texmf-texlive/tex/generic/xypic/xyknot.tex Xy-pic option: Knots and Links feature v.3.4 knots and links, loaded)) (/usr/share/texmf-texlive/tex/generic/xypic/xyarc.tex Xy-pic option: Circle, Ellipse, Arc feature v.3.4 circles, ellipses, elliptical arcs, loaded) (/usr/share/texmf-texlive/tex/latex/geometry/geometry.sty (/usr/share/texmf-texlive/tex/xelatex/xetexconfig/geometry.cfg)

Package geometry Warning: `lmargin' and `rmargin' result in NEGATIVE (-108.405p t). `width' should be shortened in length.

) (/usr/share/texmf-texlive/tex/latex/amsmath/amsmath.sty For additional information on amsmath, use the `? option. (/usr/share/texmf-texlive/tex/latex/amsmath/amstext.sty (/usr/share/texmf-texlive/tex/latex/amsmath/amsgen.sty)) (/usr/share/texmf-texlive/tex/latex/amsmath/amsbsy.sty) (/usr/share/texmf-texlive/tex/latex/amsmath/amsopn.sty)) (/usr/share/texmf-texlive/tex/latex/amsfonts/amsfonts.sty) (/usr/share/texmf-texlive/tex/latex/amsfonts/amssymb.sty) (/usr/share/texmf-texlive/tex/latex/amscls/amsthm.sty) (/usr/share/texmf-texlive/tex/latex/setspace/setspace.sty Package: `setspace 6.7 <2000/12/01> ) (/usr/share/texmf-texlive/tex/latex/tools/verbatim.sty) (/usr/share/texmf/tex/latex/graphviz/graphviz.sty (/usr/share/texmf-texlive/tex/latex/psfrag/psfrag.sty)) (/usr/share/texmf/tex/latex/sagetex.sty Writing sage input file 5381280253770850235-16.0px.sage (./5381280253770850235-16.0px.sout)) (/usr/share/texmf-texlive/tex/latex/gnuplottex/gnuplottex.sty (/usr/share/texmf-texlive/tex/latex/base/latexsym.sty) (/usr/share/texmf-texlive/tex/latex/moreverb/moreverb.sty) (/usr/share/texmf-texlive/tex/latex/base/ifthen.sty)) (./5381280253770850235-16.0px.aux) (/usr/share/texmf-texlive/tex/latex/ucs/ucsencs.def)

LaTeX Error: Environment maxima undefined.

See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help. ...

l.122 \begin{maxima}

LaTeX Error: \begin{document} ended by \end{maxima}.

See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help. ...

l.126 \end{maxima} \newpage [1]

LaTeX Error: Environment maxima undefined.

See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help. ...

l.127 \begin{maxima}

LaTeX Error: \begin{document} ended by \end{maxima}.

See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help. ...

l.129 \end{maxima} \newpage [2]

LaTeX Error: Environment maxima undefined.

See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help. ...

l.130 \begin{maxima}

Missing $ inserted. <inserted text> $ l.132 diff(y,x)=(4-2x)/(3y^ 2-5); (/usr/share/texmf-texlive/tex/latex/jknapltx/ursfs.fd) (/usr/share/texmf-texlive/tex/latex/amsfonts/umsa.fd) (/usr/share/texmf-texlive/tex/latex/amsfonts/umsb.fd) (/usr/share/texmf-texlive/tex/latex/base/ulasy.fd)

LaTeX Error: \begin{document} ended by \end{maxima}.

See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help. ...

l.134 \end{maxima} \newpage Missing $ inserted. <inserted text> $ l.134 \end{maxima} \newpage [3]

LaTeX Error: Environment maxima undefined.

See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help. ...

l.135 \begin{maxima}

LaTeX Error: \begin{document} ended by \end{maxima}.

See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help. ...

l.147 \end{maxima} \newpage [4]

LaTeX Error: Environment maxima undefined.

See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help. ...

l.148 \begin{maxima}

LaTeX Error: \begin{document} ended by \end{maxima}.

See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help. ...

l.152 \end{maxima}

[5] (./5381280253770850235-16.0px.aux) ) (see the transcript file for additional information) Output written on 5381280253770850235-16.0px.dvi (5 pages, 1664 bytes). Transcript written on 5381280253770850235-16.0px.log.