How do I get maxima to simplify logs usefully

Viewed 89

I have a maxima script that generates terms where after logcontract is run I get an expression with many terms of the type

log((A^n)/(B^n))

where both A and B are non trivial expressions

how can I get maxima to rearrange this into n*log(A/B) so that I can then perform a variable substitution and factor in terms of log(A/B) ?

I explicitly need it in the form log(A/B) and not log(A)-log(B)

A and B may be assumed positive.

2 Answers

OK, take two. Here's another approach via pattern matching.

(%i1) matchdeclare ([aa, bb, nn], all);
(%o1)                         done
(%i2) defrule (mylogrule, log((bb^nn)/(aa^nn)), nn*log(bb/aa));
                                 nn
                               bb           bb
(%o2)          mylogrule : log(----) -> log(--) nn
                                 nn         aa
                               aa
(%i3) log(A^4/B^4);
                                  4
                                 A
(%o3)                        log(--)
                                  4
                                 B
(%i4) apply1 (%o3, mylogrule);
                                  A
(%o4)                       4 log(-)
                                  B
(%i5) log(A^k/B^k);
                                  k
                                 A
(%o5)                        log(--)
                                  k
                                 B
(%i6) apply1 (%o5, mylogrule);
                                A
(%o6)                       log(-) k
                                B

Note that apply1 finds log(...) expressions and applies the rule even in complex expressions (not just expressions where the top-level operator is log).

I wrote the rule as log(bb^nn/aa^nn) because log(aa^nn/bb^nn) comes out as -nn*log(bb/aa) ... which isn't wrong but it's inconvenient. Probably has to do with the order in which arguments are matched; I didn't investigate.

I find the following combination of logexpand (with the super option) and logcontract seems to do the job.

(%i1) log((A^n)/(B^n)), logexpand=super;
(%o1)                  log(A) n - log(B) n
(%i2) %, logcontract;
                                A
(%o2)                       log(-) n
                                B
Related