16
$\begingroup$

Ok, this is awkward.

E^Log[a]

gives a, which is what I expected, BUT,

Log[E^a]

is not evaluated at all (I expected the result to be a—this is actually an MWE, what I was trying to do was more complex).

Since I still struggle to understand some of Mathematica's concepts (like when expressions are/n't evaluated), I thought (wrongly, it seems) that it was an Evaluate or Assumptions issue, but now I think it wasn't. I tried:

Assuming[a ∈ Reals, Log[E^a]] // Evaluate
Assuming[a > 0, Log[Exp[a]]] // Simplify

and other variants—which in turn shows that I'm giving a shot in the dark.

What is the explanation for this behavior? How do I get to a? Am I missing an assumption? I don't really care about any weird special cases, a is real, not complex, nor a function, nor anything else.

It obviously seems that I'm missing something (possibly very simple and obvious), but I can't figure out what.

$\endgroup$
1
  • 1
    $\begingroup$ perhaps reading up on PowerExpand will help you achieve the desired goal $\endgroup$
    – user42582
    Jun 11, 2019 at 18:57

3 Answers 3

20
$\begingroup$

Since Log is a multi-valued inverse function of Exp, Mathematica doesn't evaluate Log[Exp[a]] (or equivalently, Log[E^a]). If you want to simplify these, you need to provide an assumption on the domain of a, e.g.,

Simplify[Log[E^a], a ∈ Reals]

a

or

Simplify[Log[E^a], a > 0]

a

as suggested in the other answer. Another method is to use PowerExpand:

PowerExpand[Log[E^a], Assumptions -> True]

a + 2 I π Floor[1/2 - Im[a]/(2 π)]

Addendum

As an aside, Log behave exactly like ArcSin here:

ArcSin[Sin[x]]

ArcSin[Sin[x]]

Including a domain restriction:

Simplify[ArcSin[Sin[x]], -Pi/2 < x < Pi/2]

x

For larger domains, Simplify doesn't work:

Simplify[ArcSin[Sin[x]], 0 < x < 2 Pi]

ArcSin[Sin[x]]

Again, using PowerExpand is useful:

p = PowerExpand[ArcSin[Sin[x]], Assumptions -> 0 < x < 2Pi];
p //TeXForm

$\begin{cases} \pi -x & \frac{\pi }{2}<x\leq \frac{3 \pi }{2} \\ x & x\leq \frac{\pi }{2} \\ x-2 \pi & \text{True} \end{cases}$

Visualization:

GraphicsColumn[{
    Plot[ArcSin[Sin[x]], {x, 0, 2 Pi}],
    Plot[p, {x, 0, 2 Pi}]
}]

enter image description here

$\endgroup$
3
  • $\begingroup$ Nice explanation! Is there/Shouldn't there be a standard, single valued version of Log, just as the classical, ubiquitous asin, acos, atan? (I know this question may be beyond Mathematica). Is there a mathematical reason for the different treatment? Is it just for historic/convenience/arbitrary reasons? $\endgroup$
    – Rafael
    Jun 4, 2019 at 16:10
  • 5
    $\begingroup$ @Rafael Log is a standard single valued function when given numerical input. When given symbolic input, Log is not able to figure out the right branch to use without assumptions. This is exactly how ArcSin etc, behave, e.g., ArcSin[Sin[x]] returns it's input. $\endgroup$
    – Carl Woll
    Jun 4, 2019 at 16:17
  • $\begingroup$ I see, silly me. Thanks $\endgroup$
    – Rafael
    Jun 4, 2019 at 16:20
14
$\begingroup$

The assumption a > 0 is needed when Simplify is called:

Assuming[a > 0, Log[Exp[a]] // Simplify]

a

$\endgroup$
4
  • 9
    $\begingroup$ a \[Element] Reals works, too. The problem with complex a is that Log[Exp[a + 2 Pi I]] and Log[Exp[a]] are equal. $\endgroup$
    – Michael E2
    Jun 4, 2019 at 2:59
  • 2
    $\begingroup$ Thanks. Is there a good reason why Assuming[a > 0, Log[Exp[a]]] won't just evaluate to a? I don't get it. (cc: @MichaelE2 ) $\endgroup$
    – Rafael
    Jun 4, 2019 at 3:01
  • 8
    $\begingroup$ @Rafael - The assumptions specified in Assuming only affect functions that take the option Assumptions. Neither Log nor Exp take options. You need to include Simplify or FullSimplify within the Assuming for the assumptions to be used. $\endgroup$
    – Bob Hanlon
    Jun 4, 2019 at 4:06
  • $\begingroup$ @BobHanlon, Ok, I see. Thank you for your answer. $\endgroup$
    – Rafael
    Jun 4, 2019 at 4:40
0
$\begingroup$

Logarithm is a problematic function for MMA. I do not know the reason. One can see, for example Log[a] + Log[b] // Simplify returns Log[a] + Log[b] though LeafCount[Log[a] + Log[b]] yields 5, while LeafCount[Log[a*b]] gives 4.

I do not think that in the case Log[E^a] we should use such conditions as a>0 or whatever, since the relation in question is universal. On the other hand, in the case Log[E^a]===a the expression a is doubtless much simpler and, therefore, preferable. It is not that clear what one prefers to have in the case Log[a] + Log[b]

The way around can be using rules. For example, in this case one may use

rule = Log[x_^y_] :> y*Log[x];

Then its application gives

In[5]:= Log[E^a] /. rule

  (*   Out[5]= a *)

Have fun!

$\endgroup$
6
  • $\begingroup$ Would you say you disagree with the other answers, then? I'd love to read more debate on the issue, if it is somehow contentious $\endgroup$
    – Rafael
    Jun 4, 2019 at 12:28
  • 2
    $\begingroup$ @Rafael No, I do not. However, they used some conditions imposed on a to achieve the desired results. We know, however, that the relation Log[Exp[a]]===a holds for any a. So, using the relation, say, a>0 is to extent misleading. Indeed, in this case, we know that it holds for any a. However, in a more cumbersome case this condition may lead you into an erroneous assumption that such an inequality is necessary. Anyway, one should be careful. $\endgroup$ Jun 4, 2019 at 12:52
  • $\begingroup$ @AlexeiBoulbitch the expression isn't general for complex values of a. a > 0 forces a into the reals. Also, consider a = -1 + I, b=-1; the sum of the logs is not the log of the product. $\endgroup$
    – Davidmh
    Jun 4, 2019 at 14:00
  • 1
    $\begingroup$ @AlexeiBoulbitch sorry, I was unclear. I should have split my comment: Log[Exp[a]]===a isn't general for complex values of a (in particular, when Abs[Im[a]] > 2 Pi), but a > 0 forces a into the reals. Furthermore, Log[a] + Log[b] is not, in general, Log[a*b] if a or b are complex. $\endgroup$
    – Davidmh
    Jun 4, 2019 at 14:39
  • 4
    $\begingroup$ In[33]:= Log[Exp[a]] /. a->-1-5*I Out[33]= (-1 - 5 I) + (2 I) Pi So this claimed identity is simply wrong. As has been noted in the comment by @Davidmh $\endgroup$ Jun 4, 2019 at 16:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.