def powdenest(eq, force=False, polar=False):
 from sympy.simplify.simplify import posify
 if force:
  (eq, rep) = posify(eq)
  return powdenest(eq, force=False).xreplace(rep)
 if polar:
  (eq, rep) = polarify(eq)
  return unpolarify(powdenest(unpolarify(eq, exponents_only=True)), rep)
 new = powsimp(sympify(eq))
 return new.xreplace(Transform(_denest_pow, filter=(lambda m: (m.is_Pow or (m.func is exp)))))

def powdenest ( eq , force = False , polar = False ) : from sympy . simplify . simplify import posify if force : ( eq , rep ) = posify ( eq ) return powdenest ( eq , force = False ) . xreplace ( rep ) if polar : ( eq , rep ) = polarify ( eq ) return unpolarify ( powdenest ( unpolarify ( eq , exponents_only = True ) ) , rep ) new = powsimp ( sympify ( eq ) ) return new . xreplace ( Transform ( _denest_pow , filter = ( lambda m : ( m . is_Pow or ( m . func is exp ) ) ) ) )
collect exponents on powers as assumptions allow .