I was playing with the Expand command and found something that puzzled me. Using Trace did not clarify the situation.
expr=Exp[x^2] (-2 Exp[-x^2] + 4 Exp[-x^2] x^2);
Expand[expr, Exp[x^2]]
(* expr is left unchanged *)
Expand[expr, Exp[-x^2]]
(* - 2 + 4 x^2 - it worked! *)
Expand[-2 Exp[-x^2] + 4 Exp[-x^2] x^2, Exp[-x^2]]
(* -2 Exp[-x^2] + 4 Exp[-x^2] x^2 is left unchanged *)
What exactly happened when the second call to Expand above successfully simplified expr?
Note: Simplify also does the job, but I am trying to figure out Expand.
Thanks for the help.
I would like to clarify my question.
I reasoned that Mathematica would evaluate the second call to Expand above in two steps:
Step 1) Leave Exp[x^2] aside and Expand the remainder of expr with argument Exp[-x^2].
Step 2) Evaluate the resulting expression.
However, the third call above to Expand does not change its argument, and Step 1 is identical to the third call. So Step 1 should leave expr unchanged and therefore in Step 2 expr would be evaluated. But expr evaluates to itself, so Step 2 also should not change expr. So neither of the two steps in the second call should change expr. But the second call does change expr. That is what I do not understand. My hypothesis of a two-step evaluation must be wrong, but I do not know why.
Comments
Post a Comment