I need to find a method to transform an expression like
a^(1+m+n) b^(2+2m - 2n)
into
(a b^2)^m (a/b^2)^n (a b^2),
that is, to group terms with the same exponent. I tried using Collect[], etc, but can't get anything to work.
Any suggestions?
Thanks, Tom
Using Log
in combination with CoefficientRules
:
exp = a^(1 + m + n) b^(2 + 2 m - 2 n);
Times @@ (Exp[#[[2]]]^(Times @@ ({n, m}^#[[1]])) & /@
CoefficientRules[PowerExpand[Log[exp]], {n, m}])
output:
a (a/b^2)^n b^2 (a b^2)^m
You can do this, for example:
log[x_*y_] := log[x] + log[y];
log[x_^y_] := y*log[x];
log1 /: a_*log1[b_] := log1[b^a];
log1 /: Plus[x__log1] := log1[Times @@ Map[First, {x}]];
exp[HoldPattern[Plus[x__]]] := Times @@ Map[exp, {x}];
exp[log1[x_]] := x
and then:
In[58]:= exp[Collect[Expand[log[a^(1+m+n) b^(2+2m-2n)]],{m,n}]]/.log->log1
Out[58]= a (a/b^2)^n b^2 (a b^2)^m
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With