Menu

#2730 subst, ratsubst: replace subexpression with exponents

None
closed
nobody
None
5
2014-05-05
2014-05-04
Bjørn
No

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


Discussion

  • Rupert Swarbrick

    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 called ab, which is not equal to %e^a * %e^b.

    Putting the multiply signs back in, I see this:

    (%i2) ratsubst(a,%e^(a*b),sqrt(%e^(a*b)-1) + %e^(a*b*z));
                                   a b z
    (%o2)                        %e      + sqrt(a - 1)
    

    Maxima has indeed failed to replace one of the exp(a*b)'s. The problem is that, while ratsubst is cleverer than subst 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, neither ratsubst nor subst 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:

    (%i4) ratsubst(log(a), a*b, sqrt(%e^(a*b)-1) + %e^(a*b*z));
                                 log(a) z
    (%o4)                      %e         + sqrt(a - 1)
    

    And in fact, here the rat part of ratsubst is actually helping. The substitution doesn't completely succeed with just subst:

    (%i7) subst(log(a), a*b, sqrt(%e^(a*b)-1) + %e^(a*b*z));
                                   a b z
    (%o7)                        %e      + sqrt(a - 1)
    

    Of course, you'll want to get rid of that unsightly %e^log(a) term. The radcan 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 and z = 0, then the transformation of exp(log(a)*z) to a^z would be incorrect. I think the radcan function does simplifications that assume all the atoms are large (so neither log(a) nor z 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.

     
  • Rupert Swarbrick

    • status: open --> closed
     

Log in to post a comment.