1
$\begingroup$

This question already has an answer here:

I tried to do something below

Log[PDF[NormalDistribution[m, s], x]] /. Log[u_[x__] ] :> Plus @@ Log[List[x]]

which gives a desirable result that splits the expression into pieces. Note that PDF[NormalDistribution[m, s], x] was evaluated of the form Times[a,b,c] and thus u was identified as Times.

However, if I replace u_ by Times, i.e.,

Log[PDF[NormalDistribution[m, s], x]] /. Log[Times[x__] ] :> Plus @@ Log[List[x]]

then, I got an unexpected result that does not change the expression. Can you explain why I should not use Times even though I know that u_ will match Times in the first example?

$\endgroup$

marked as duplicate by Mr.Wizard Jun 23 '15 at 12:37

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    $\begingroup$ Take a look at HoldPattern. Times[x__] is evaluated. $\endgroup$ – Kuba Jun 5 '15 at 11:52
  • $\begingroup$ @Kuba I don't think I understand you. Could you be more specific? $\endgroup$ – Sungmin Jun 5 '15 at 11:57
4
$\begingroup$

@Kuba is actually pretty specific.

In[1]:= Log[PDF[NormalDistribution[m, s], x]] /. 
 HoldPattern[Log[Times[x__]]] :> Plus @@ Log[List[x]]

Out[1]= Log[E^(-((-m + x)^2/(2 s^2)))] - 1/2 Log[2 \[Pi]] + Log[1/s]

BTW, you may also interested in PowerExpand.

$\endgroup$

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