Substituting expressions in Maxima result



On Wed, Sep 24, 2008 at 1:20 PM, weaker <weaker at directbox.com> wrote:

> Is there an easier way to do multiple subst operations in one or can I
> only do it with having a whole new subst operation each time?
>

Check out the documentation for subst:

    ? subst

It will show you that you can do, e.g.

    subst( [ x = a, y = b], x^2+y^2 ) => a^2+b^2

The list of substitutions does not have to be static, either:

   sublist1: [x=a]$
   sublist2: [y=b]$
   subst( append(sublist1, sublist2), ... )


> ...it doesn't need to display the intermediate results ... as that takes
> some time


To perform a calculation without displaying the results, end your line with
$ instead of ;

(%i10) 1+1;
(%o10) 2
(%i11) 2+2$
(%i12)

Though the result is not displayed, it is still assigned to %o11.


> RD> About the "^" replacement, try: subst("^" = pow, expr);
>
> That also helps me much. But no matter what I chose instead of "pow" I
> always get something like "mychosenname(variable, 2)". I'd rather have
> something like "square(variable)". Is that also possible?
>

You'll have to use pattern-matching for that.  Same thing for sqrt, which
Maxima represents as x^(1/2)

             -s