Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

If one makes the assumptions $x>0,a>0$, then $\frac{1}{a}\log x^a = \log x$. Thus, in Mathematica, Simplify[1/a*Log[x^a], {a > 0, x > 0}] returns Log[x]. If the argument of the logarithm becomes more complicated, the assumption one must declare becomes proportionately more complicated. For instance, Simplify[1/a*Log[(x + Log[x]*Cos[x])^a], {a > 0, x + Log[x]*Cos[x] > 0}].

Of course, one could also use Simplify[1/a*Log[(x + Log[x]*Cos[x])^a], {a > 0, x > 1}]; however, one may not always know the range of the argument of the logarithm.

Is there a way to specify that the argument of the logarithm is non-negative without spelling out the entire argument in the assumption? Perhaps, one could simply declare to Mathematica that complex numbers should be ignored?

share|improve this question
It is always a good idea to leave your question open for at least a few hours if not a day so that more people may be enticed into submitting an answer. –  Sjoerd C. de Vries Mar 20 '12 at 21:21

5 Answers 5

up vote 9 down vote accepted

In your particular examples, PowerExpand[Log[x^a]/a] evaluates to Log[x], and PowerExpand[1/a*Log[(x + Log[x]*Cos[x])^a]] also works.

EDIT: To be clear, and as commented upon by Andrzej, PowerExpand may give wrong answers. See the documentation, in particular this.

EDIT2: Does something like (1/a*Log[(3*Exp[-1/x]*Sqrt[1 - Exp[1/x]])^a]) //. Log[Times[x_, y_]] -> Log[x] + Log[y] do what you want? (this it pattern-matching, a Andrzej suggested in reply to your comment).

share|improve this answer

I would avoid applying PowerExpand to anything except very simple expressions, since PowerExpand can easily return incorrect answers. For example, PowerExpand[Sqrt[(1 - x)^2] + Log[(x - 1)^2]] will return 1 - x + 2 Log[-1 + x], which is wrong, except when x=1 and both expressions are infinite. So if you only want to expand logarithms, it is better to use pattern matching, like:

1/a*Log[(x + Log[x]*Cos[x])^a] /. Log[m_^n_] :> n Log[m]
share|improve this answer
this is better posted as a comment, not an answer (as it is not, actually, an answer) –  acl Mar 20 '12 at 21:43
Well, pattern matching is an answer... –  Andrzej Kozlowski Mar 20 '12 at 21:52
Andrzej: What do you mean by pattern matching? Thanks. –  user001 Mar 20 '12 at 21:54
1/a*Log[(x + Log[x]*Cos[x])^a] /. Log[m_^n_] :> n Log[m] –  Andrzej Kozlowski Mar 20 '12 at 21:57
@Andrzej, why don't you add this to your answer and I'll remove it from mine (to avoid overlap) –  acl Mar 20 '12 at 22:02

As the OP mentioned in a comment, pattern matching has difficulties with something more complex, such as


where $(3 \sqrt{1 - x})^a$ is interpreted as $3^a (1-x)^{a/2}$. It is possible to create something more general that will cover this case, and a few others. To do so is significantly more complicated, as follows:

1/a*Log[(3*Sqrt[1-x])^a] /. 
 Log[ a_Power b___Power ] :> 
  Module[{bases, exps, common}, 
   {bases, exps} = Transpose[List @@@ {a, b}];
   common = exps /. {(p_ | p_ ___) ..} :> p;
   common Log[ Times @@ Power @@@ Transpose[ {bases, exps/common} ]]


Because of the implicit simplification going on, we have to get creative in extracting out the common terms. First, we need to be able to get at the individual exponents of each term, hence the pattern

Log[ a_Power b___Power ]

which I use to split the bases and the exponents into two separate lists, via

{bases, exps} = Transpose[List @@@ {a, b}];

Once that's done, I use a second pattern to extract the common term from the exponents. In my limited search, I could not come up with a more straightforward method, although it likely exists. Lastly, I re-construct the expression.

As a general caution, this explosion in complexity is a perennial problem with these types of structural changes. They are often difficult to construct, and likely to fail with small deviations from the prescribed pattern. Consider what happens if the above replacement rule is applied to Log[3^b*Sqrt[1 - x]^a]/a, instead:

{(b Log[3 (1 - x)])/a, 1/2 Log[3 (1 - x)]}

It completely breaks without any fail over into something workable.

share|improve this answer
So, as someone new to Mathematica, I have a growing realization that there must be an interaction between computation and pen-and-paper. Would you agree with this? This, for instance, is not the first example I have encountered where something that is trivially reduced by pen-and-paper is quite complicated to reduce using Mathematica. I like to be able to follow the entire logic in Mathematica, but I guess I should get in the habit of manually manipulating expressions and leaving explanatory comments in the notebook. –  user001 Mar 21 '12 at 3:31
@user001 Mathematica (mma) is a tool, and should be used like one. (Here's an example I'm rather fond of.) Manipulating expressions into different forms is actually one of the hardest things to do in mma, as the system will likely thwart you. But, as an investigative tool, it can be extremely useful. I've written code in it that literally takes thousands of lines to write in c++ in under a page. The c++ code is faster, but it is also incomplete at this point. –  rcollyer Mar 21 '12 at 3:48

Simply factor out the common expression:

Module[{t = x + Log[x]*Cos[x]}, Simplify[1/a*Log[t^a], {a > 0, t > 0}]]
share|improve this answer

As a comment to a very nice note given by Andrzej I would like to remind of the fact that PowerExpand accepts assumptions. The example given in the reply of Andrzej may be "healed" by this option:

PowerExpand[Sqrt[(1 - x)^2] + Log[(x - 1)^2], Assumptions -> x > 1]
-1 + x + 2 Log[-1 + x]
PowerExpand[Sqrt[(1 - x)^2] + Log[(x - 1)^2], Assumptions -> x < 1] // 
1 - x + 2 Log[1 - x]

Nevertheless, I will be now more careful with this operator. Thank you, Andrzej, for your note.

Now, concerning the original question, why not using Abs[] in the pattern to avoid possible errors? For example,

Log[A*B] /. Log[Times[a_, b_]] :> Log[Abs[a]] + Log[Abs[b]]
Log[A^B] /. Log[Power[a_, b_]] :> b*Log[Abs[a]]
Log[Abs[A]] + Log[Abs[B]]
B Log[Abs[A]]

In the example given in the original question by using the second pattern above one gets:

Simplify[Log[(x + Log[x]*Cos[x])^a] /. 
 Log[Power[a_, b_]] :> b*Log[Abs[a]], {a > 0, x > 1}]
a Log[x + Cos[x] Log[x]]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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