Handling subscripted expressions WAS: Simplifying by replacing expressions?
Subject: Handling subscripted expressions WAS: Simplifying by replacing expressions?
From: Stavros Macrakis
Date: Mon, 27 Sep 2004 16:41:21 -0400
You don't actually need to delve into Lisp -- Maxima provides all the
necessary primitives.
However, subscripting in Maxima is idiosyncratic. In particular,
part/inpart do not allow you to tell the difference between f(x) and
f[x] -- you need to use the subvarp predicate, and then rebuild usinjg
arraymake instead of funmake.
By the way, be sure to use funmake/arraymake and not apply/arrayapply.
The following code walks an expression and reconstructs it:
copy_expr(e) :=
if atom(e) then e
else
(if subvarp(e) then 'arraymake else 'funmake)
(copy_expr(part(e,0)),map(copy_expr,args(e)));
Tests:
copy_expr(1);
copy_expr(x);
copy_expr(x^2+1/y);
copy_expr(f[i]+g[i](x));
copy_expr((a+b)[i]);
copy_expr('([a,b,c][i]));
Let me know if you have any problems with this.
-s