matching or some other thing for sums of exponentials?
Subject: matching or some other thing for sums of exponentials?
From: dlakelan
Date: Tue, 04 Oct 2011 09:15:22 -0700
On 10/03/2011 09:01 PM, Edwin Woollett wrote:
> Some code from my dirac2.mac code file (Maxima by Example,
> Ch. 13) seems to work here:
>...
I think this is very similar to using multthru, such as:
(%i455) myee: (a*exp(b) + exp(c));
c b
(%o455) %e + a %e
(%i456) exp(c)*multthru(1/exp(c),myee);
b - c c
(%o456) (a %e + 1) %e
The issue I have is that there are several locations within this big
ugly expression where this *type* of simplification could occur, but I
want to get maxima to traverse the expression tree and recognize when it
is possible and carry it out.
I thought pattern matching would be the way, but I can't figure out how
to match a sum of two exponentials multiplied by constants in a reliable
way (since it doesn't have a unique match it gives me some kinds of
warnings)
(%i457) matchdeclare([consta],atom,[expa,expb],lambda([x],not(atom(x))
and op(x)="^" and part(x,1)=%e));
(%o457) done
(%i458) defrule(sumexp,consta*expa+expb,expb*(consta*(expa/expb)+1));
defmatch: expa consta
will be matched uniquely since sub-parts would otherwise be
ambigious.
consta expa
(%o458) sumexp : expb + consta expa -> (----------- + 1) expb
expb
I guess I could use "scanmap" with a function I'd write that checks to
see if the expression is a sum of the right form, and then performs the
simplification.