matching or some other thing for sums of exponentials?



Maybe you need to substitute a lambda form for "+".  Try something like 

(%i85) xexpy_p(e):= 
  if ?mtimesp(e) and every(lambda([s], not ?mexptp(s)), rest(args(e),-1)) 
and ?mexptp(last(e)) then last(e) 
  else if ?mexptp(e) then e else false$

(%i86) powfactor(e) := subst("+" = lambda([[s]], block([s1 : 0, s2 : 0, 
xo, po : 1],
              for sk in s do (
               xo : xexpy_p(sk),
               if xo=false then s1 : s1 + sk
                else (s2 : s2 + sk, po : xo)), 
             s1+ po * expand(s2/po))),e)$

(%i94) powfactor(log(x^2 + 943*x^q) -56 * log(x^2 + y^3));
(%o94) log(x^q*(x^(2-q)+943))-56*log((x^2/y^3+1)*y^3)


This function is untested; further, it simply factors out the last  b^c 
term it scans. And that's silly.

--Barton

maxima-bounces at math.utexas.edu wrote on 10/03/2011 07:13:26 PM:

> From: dlakelan <dlakelan at street-artists.org>
> To: Maxima Mailing List <maxima at math.utexas.edu>
> Date: 10/03/2011 07:13 PM
> Subject: matching or some other thing for sums of exponentials?
> Sent by: maxima-bounces at math.utexas.edu
> 
> I have an expression that I get back from ode2 which contains things
> like (a*%e^b + %e^c)
> 
> I would like to convert this to %e^c*(a*%e^(b-c)+1) or maybe in general
> take the sum of two exponentials multiplied by something and do this:
> 
> a*exp(b) + c*exp(d) -> exp(d) * (a*(exp(b)/exp(d)) + c)
> 
> one of the reasons I want to do this is that many times this appears
> inside a logarithm and the resulting simplifications will eliminate
> intermediate overflows in floating point.
> 
> I can't figure out how to do this with matching / defrule, or with
> fooling around using factor or factorsum or anything like that.
> 
> One of the problems seems to be the general problem that matching sub
> parts of sums or products can be tricky.
> 
> any ideas?
> 
> 
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima