Substituting expressions in Maxima result



On Tue, Sep 23, 2008 at 10:07 AM, weaker <weaker at directbox.com> wrote:

> I have a very long expression as a maxima result. In it there is quite
> often the part sqrt(a^2 + b^2 + c^2) (the frobenius norm of a vector).
> Now I want to substitute that by a variable like e.g. "myvectnorm".
>
> Do I have to do that with a RegEx search/replace in an editor or can I
> tell maxima to do that already inside maxima? I'd prefer doing it in
> maxima to avoid stupid RegEx errors. And it would make for an easier
> copying into C++ (which is tedious because all "^2" must be replaced).

Much better to do the substitutions in Maxima, as Stavros mentioned.
Maxima is, to a large extent, a system for formal (i.e. ignoring content)
manipulation of expressions.

Try: subst(sqrt(a^2 + b^2 + c^2) = myvectnorm, expr);

Also try optimize(expr); which looks for common subexpressions
and substitutes made-up variables for them.

About the "^" replacement, try: subst("^" = pow, expr);
(or use some other function name if pow is not suitable for you).

HTH

Robert Dodier