# How to efficiently simplify using PowerExpand

I am tying to simplify the following expression using Simplify, FullSimplify, Expand and PowerExpand, Factor. However it is not always possible to completely simplify an expression.

 expr = a  + (1+b^2+b (2-(4 d^2 e)/(1+d (-1+e))))^(1-n/2);


I am interested in simplifying this such that it will not have a fractional form as a sum. However in this way a final fractional form is of course expected.

The desired form is the following

 expr = ((a)*(1+d (-1+e))^(1-n/2)  + (((1+b^2)*(1+d (-1+e))+b (2(1+d (-1+e))-4 d^2 e))^(1-n/2)) )/(1+d (-1+e))^(1-n/2);


where the numerator has the terms with positive powers and an overall denominator with also positive powers (n<2).

How to I use PowerExpand in simplifying such expression?

## 2 Answers

You cannot get your desired form by using Simplify. Indeed, these are your expressions:

expr1 = a + (1 + b^2 + b (2 - (4 d^2 e)/(1 + d (-1 + e))))^(1 - n/2);
expr2 = ((a)*(1 + d (-1 + e))^(1 -
n/2) + (((1 + b^2)*(1 + d (-1 + e)) +
b (2 (1 + d (-1 + e)) - 4 d^2 e))^(1 - n/2)))/(1 +
d (-1 + e))^(1 - n/2);


Let us count their leaves:

LeafCount[expr1]
LeafCount[expr2]

(*  34

74   *)


Thus, from the point of view of Mma (and also from my personal) the second expression is more complex than the first.

However, if you need to get the factor (1 + d (-1 + e))^(-1 + n/2) out of the expression you might use the following function:

factor[expr_, fact_, fun1_ : Expand, fun2_ : Identity] :=
Module[{a = fact, b = expr/fact},
fun2[Evaluate[a]]*fun1[Evaluate[b]]];


as follows

expr3 = factor[expr1, (1 + d (-1 + e))^(1 - n/2), Expand, Expand]

(*  (1 + d (-1 + e))^(
1 - n/2) (a (1 + d (-1 + e))^(-1 + n/2) + (1 + d (-1 + e))^(-1 + n/2) (1 + b^2 + b (2 - (4 d^2 e)/(1 + d (-1 + e))))^(1 - n/2))  *)


After that, I would do one additional thing:

expr3 /. a_^(-1 + n/2)*b_^(1 - n/2) :> (b/a)^(1 - n/2)

(*  (1 + d (-1 + e))^(
1 - n/2) (a (1 + d (-1 + e))^(-1 + n/2) + ((
1 + b^2 + b (2 - (4 d^2 e)/(1 + d (-1 + e))))/(1 + d (-1 + e)))^(1 - n/2))   *)


looking at the screen as follows: Have fun!

• Interesting to learn LeafCount. However the final expression is not the expected one. You are right that the expected simplification is of the form expr1^x / expr2^y where any x and y are positive. Replacement seems like the only option. – Boogeyman Feb 2 at 17:57

This should find the denominator (factors with a negative power) to factor out in an expression of the form A + B/C + D/E + .... The DeleteDuplicates would delete factors of the denominator with the same base but different exponents, but you would really want to select the correct one, which DeleteDuplicates is not guaranteed to do. It does not matter in this case, because there are no duplicates. I just leave it there in case someone in the future wants to adapt it. I think this achieves the described goal, although the numerator is in a slightly different form than the example output.

Assuming[n < 2,
With[{e = PowerExpand[expr /. p_Power :> Together /@ p]},
(* find desired denominator *)
With[{den =
Times @@
(*(DeleteDuplicatesBy[#,First]&)@*)
Cases[
Union @@ Cases[
PowerExpand[e /. p_Power :> Together /@ p],
HoldPattern@Times[a___] :> {a}],
Power[b_, p_] /; Simplify[p < 0]
]},
FullSimplify[ExpandAll[e/den]]*den // Simplify
]]
] The first transformation of expr puts the powers in a form on which PowerExpand will operate:

PowerExpand[expr /. p_Power :> Together /@ p] • This exactly achieves the desired form. For multiple denominators with same base and different exponents, I see this is already working fine. In that case I need to just take out the highest exponent of the denominator. – Boogeyman Feb 2 at 19:31