This is a rather simple question but for some reason, I am spending too much time on this.
Suppose I have a monomial in 4 variables, each raised to some linear combination of 3 exponent variables: {a1, a2, a3, a4}
, and {b1, b2, b3}
.
Now I want to collect monomial subexpressions with the same exponent variable together. For eg, if I have the following input:
(-a1)^(b1 + 2b2 + b3) a2^(-b2 + b3) (-a3)^(-2b1 + b2) a4^(3b1 + 4b3)
I should obtain precisely the following expression as output:
(-1)^(-b1 + 3b2 + b3) ((a1 a4^3)/a3^2)^b1 ((a1^2 a3)/a2)^b2 (a1 a2 a4^4)^b3
Note: it would be better if the solution to this query doesn't involve the use of ReplaceRepeated
, and that it works for the full general case of $m$ monomial variables {a1, a2, ..., am}
with $n$ exponent variables {b1, b2, ..., bn}
.