How can I require Mathematica to format an expression like
Exp[x] x^s
as Exp[x + s Log[x]]
?
2 Answers
$\begingroup$
$\endgroup$
The following code
Exp[x] x^s /. {a_^b_ :> Exp[log[a] b]} /. log -> Log // InputForm
returns the result
E^(x + s*Log[x])
which is what I think you wanted. By comparison, the original expression
Exp[x] x^s // InputForm
returns the result
E^x*x^s
$\begingroup$
$\endgroup$
Method for output formatting:
MakeBoxes[Power[b_, p_], form_] :=
With[{p2 = p*Log[b]}, MakeBoxes[Exp[p2], form]];
MakeBoxes[Times[pow__Power, c__], form_] := MakeBoxes[Times[c, Times[pow]]];
MakeBoxes[Times[pow__Power], form_] :=
With[{p2 =
With[{terms = List @@@ {pow}},
Total[terms[[All, 2]] Log[terms[[All, 1]]]]]},
MakeBoxes[Exp[p2], form]]
Exp[x] x^s
(* Exp[x + s Log[x]] *)
2 + y Exp[x] x^s
(* 2 + y Exp[x + s Log[x]] *)
I don't know if this is desired, but it shows that all powers are converted to Exp[]
:
x^2
(* Exp[2 Log[x]] *)
{}
button above the edit window. The edit window help button?
is useful for learning how to format your questions and answers) $\endgroup$expr = Exp[x] x^s; Assuming[ x > 0 && s > 0, (Exp@*FullSimplify@*Log)[expr]]
. $\endgroup$Exp[z]
automatically evaluates toPower[E, z]
, so I don't think there is. There is a way to format output in the way you indicate, but the internal representation willl revert toPower
. $\endgroup$