Can't substitute subexpression in one command by ratsubst or subst
I have used ode2 and got a bigger solution. Such I want to simplify expression by replacing recurring subexpressions.
But as shown in these examples it is not possible to substitute all occuring subexpressions using ratsubst:
ratsubst(a,%e^(ab),sqrt(%e^(ab)-1) + %e^(abz));
ratsubst(a,%e^(ab/2),sqrt(%e^(ab)-1) + %e^(a*b/2));
wxMaxima version: 13.4.0
Maxima version: 5.31.2
Maxima build date: 2013-10-07 23:05:06
Host type: i686-pc-mingw32
Lisp implementation type: GNU Common Lisp (GCL)
Lisp implementation version: GCL 2.6.8
It's a little bit hard to tell exactly what's going on from your report, because it looks like you've missed some multiply signs. (Note that in Maxima
%e^(ab)
means%e
raised to the power of some variable calledab
, which is not equal to%e^a * %e^b
.Putting the multiply signs back in, I see this:
Maxima has indeed failed to replace one of the
exp(a*b)
's. The problem is that, whileratsubst
is cleverer thansubst
on rational expressions (stuff you can make from addition, multiplication and division), it doesn't know anything about expressions like%e^(a*b*z)
, so it just treats them like a black box.Because
%e^(a*b*z)
doesn't contain%e^(a*b)
as a literal subexpression, neitherratsubst
norsubst
can help. This is a property of the design (or lack of features) rather than a bug.The good news is that it's possible to work around this problem. Consider this substitution:
And in fact, here the rat part of
ratsubst
is actually helping. The substitution doesn't completely succeed with justsubst
:Of course, you'll want to get rid of that unsightly
%e^log(a)
term. Theradcan
function will deal with it, but I'm not absolutely sure why it's not being got rid of by the logsimp flag's default value of true.My guess is that the simplification doesn't happen because if
log(a) = 0
andz = 0
, then the transformation ofexp(log(a)*z)
toa^z
would be incorrect. I think theradcan
function does simplifications that assume all the atoms are large (so neitherlog(a)
norz
is zero), which is why it can make the substitution you want.Anyway, I'm going to close this bug report because I don't think the behaviour you're reporting is buggy. Please feel free to reopen it if I've misunderstood your report in some way.