|
Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
/*
* This file:
* http://anggtwu.net/MAXIMA/showexpression1.mac.pyg.html
* http://anggtwu.net/MAXIMA/showexpression1.mac.html
* http://anggtwu.net/MAXIMA/showexpression1.mac
* (find-angg "MAXIMA/showexpression1.mac")
* Author: Eduardo Ochs <eduardoochs@gmail.com>
*
* Shows a Maxima expression in explicit form.
* Code by Stavros Macrakis, from:
* https://sourceforge.net/p/maxima/mailman/message/58795759/
* (find-maximamsg "58795759 202407 15" "Stavros: show_expression")
*
* See: (find-es "maxima" "mtree")
* (find-es "maxima" "annotations")
* (find-es "maxima" "nouns-and-verbs")
*
* (defun e () (interactive) (find-angg "MAXIMA/showexpression1.mac"))
*/
/*
* (find-maximanode "part")
* (find-maximanode "nounify")
* (find-maximanode "verbify")
* (find-maximanode "push")
*/
show_expression(ex):=
if atom(ex) then ex
elseif subvarp(ex) then funmake('subsc,cons(op(ex),[maplist(show_expression,args(ex))]))
elseif ratnump(ex) then funmake('rat,[first(ex),second(ex)])
elseif mapatom(ex) then ex
elseif member(part(ex,0), show_special)
then funmake(show_expression_name[part(ex,0)], maplist(show_expression,args(ex)))
elseif not(atom(part(ex,0)))
then funmake('apply,[show_expression(part(ex,0)),maplist(show_expression,args(ex))])
else block([pex:part(ex,0)],
funmake(concat(if nounify(pex)=pex then 'N else 'V,pex), maplist(show_expression,args(ex))))$
show_special: []$
for i in
'[["+",add], ["-",minus], ["*",mul], ["^",power], ["/",div],
[".",ncmul], ["^^", ncpower],
["[",list], ["{",set],
[":",assign], ["::",varassign],
[":=",define], ["::=",definemac]
["'",quote], ["(",prog],
["=",equal], ["#",notequal], [">",greaterp],[">=", greatereq], ["<", lessp], ["<=",lesseq],
["!",factorial], ["@",field]
]
do (show_expression_name[first(i)]: second(i), push(first(i),show_special));
/*
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
load("showexpression1.mac");
linel : 100;
show_special;
show_expression_name["+"];
show_expression_name["foo"];
show_expression( a[b] );
show_expression( a(b) );
show_expression( a(b)(c) );
show_expression( -2/3*(a-b)/(b*sqrt(5)) );
show_expression( -2/3*(a-b)/(b*sqrt(5)) ),inflag:true;
grind(%), linel=30;
show_expression('[integrate(x,x), 'integrate(x,x)]);
show_expression('(if a then b else c));
show_expression('(for i thru 4 do print(i)));
show_expression('(for i:2 thru 4 while i^2 < 10 do print(i)));
show_expression('(for i:2 step 1/2 thru 4 while i^2 < 10 do print(i)));
show_expression('(for i:2 thru 4 next i+1/3 while i^2 < 10 do print(i)));
show_expression('(for i in [a,b,c] do print(i)));
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
load("showexpression1.mac");
a : factor(1000); "shows a as 2^3 * 5^3"$
show_expression(a), inflag:true; "shows a as 2^3 * 5^3"$
show_expression(a); "shows a as 8 * 125"$
b1 : 4 + 40*x + 400*x^2;
b2 : trunc(b1); "has a ..."$
b3 : taylor(b1, x, 0, 2); "has a ... and a /T/"$
show_expression(b1);
show_expression(b1), inflag:true;
show_expression(b2);
show_expression(b2), inflag:true;
show_expression(b3);
show_expression(b3), inflag:true;
inflag : false;
inflag : true;
show_expression(a); "shows a as 2^3 * 5^3"$
show_expression(b);
show_expression(c); "same as above - same order, no /T/ or ..."$
*/
/*
* Local Variables:
* coding: utf-8-unix
* End:
*/