Suppose I have an expression like (actually mine is much more complex, thousands of characters)
expr:a+b*c+b*c*d;
and I want to replace an internal sub-expression with a symbol (useful to avoid recomputation of common subexpressions), say k
in place of b*c
:
subst(b*c=k,expr);
returns
k+b*c*d+a
How I can make Maxima calculate the "right" substitution so to return (apart from obviuos simplification, here)
k+k*d+a
?
You can try optimize
http://maxima.sourceforge.net/docs/manual/en/maxima_6.html#IDX219
Take a look at
let
andletsimp
. E.g.:letsimp
differs fromsubst
andtellsimp
ordefrule
in that those other functions make only formal substitutions, i.e., replacing subexpressions which are exactly the same as some pattern.