Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Working with Log

27 views
Skip to first unread message

Themis Matsoukas

unread,
Aug 30, 2010, 6:20:14 AM8/30/10
to
I can use PowerExapnd to expand a Log:

PowerExpand[Log[a b]]

Log[a] + Log[b]

How can I do the opposite, i.e. combine Log[a] + Log[b] into Log[a b]?

Thanks

Themis

Sjoerd C. de Vries

unread,
Aug 31, 2010, 4:15:47 AM8/31/10
to
Assuming[{a > 0, b > 0}, Simplify[Log[a] + Log[b]]]

Cheers -- Sjoerd

Patrick Scheibe

unread,
Aug 31, 2010, 4:16:08 AM8/31/10
to
Hi,

there's no unexpand but to know that PowerExpand uses heavy assumptions
per default is useful. This should be a warning too that the results of
PowerExpand not in general true. See for instance what

PowerExpand[Log[a b], Assumptions -> Element[{a, b}, Complexes]]

gives:

2*I*Pi*Floor[1/2 - Arg[a]/(2*Pi) - Arg[b]/(2*Pi)] + Log[a] +
Log[b]

Your expansion is valid for instance for

PowerExpand[Log[a b], Assumptions -> a > 0 && b > 0]

and therefore

FullSimplify[%, Assumptions -> a > 0 && b > 0]

gives again

Log[a b]

To see where exactly the log rule works you could do maybe

Reduce[2*I*Pi*Floor[1/2 - Arg[a]/(2*Pi) - Arg[b]/(2*Pi)] == 0, {a, b}]

Cheers
Patrick

Alexei Boulbitch

unread,
Aug 31, 2010, 4:16:51 AM8/31/10
to
Hi, Themis,
one idea may be as follows. Introduce two functions for expansion and to collect logarithms:

expandLog[expr_] := Module[{rule1, rule2, a, b, x},
rule1 = Log[a_*b_] -> Log[a] + Log[b];
rule2 = Log[a_^x_] -> x*Log[a];
(expr /. rule1) /. rule2
];
collectLog[expr_] := Module[{rule1, rule2, a, b, x},
rule1 = Log[a_] + Log[b_] -> Log[a*b];
rule2 = x_*Log[a_] -> Log[a^x];
(expr /. rule1) /. rule2 /. rule1 /. rule2
];

Then:


Log[Sin[x]*Cos[y]] // expandLog

Log[Cos[y]] + Log[Sin[x]]


Log[a + b] + Log[c + d] // collectLog

Log[(a + b) (c + d)]

Have fun, Alexei

I can use PowerExapnd to expand a Log:

PowerExpand[Log[a b]]

Log[a] + Log[b]

How can I do the opposite, i.e. combine Log[a] + Log[b] into Log[a b]?

Thanks

Themis

--
Alexei Boulbitch, Dr. habil.
Senior Scientist
Material Development

IEE S.A.
ZAE Weiergewan
11, rue Edmond Reuter
L-5326 CONTERN
Luxembourg

Tel: +352 2454 2566
Fax: +352 2454 3566
Mobile: +49 (0) 151 52 40 66 44

e-mail: alexei.b...@iee.lu

www.iee.lu

--

This e-mail may contain trade secrets or privileged, undisclosed or
otherwise confidential information. If you are not the intended
recipient and have received this e-mail in error, you are hereby
notified that any review, copying or distribution of it is strictly
prohibited. Please inform us immediately and destroy the original
transmittal from your system. Thank you for your co-operation.

__________ Information from ESET NOD32 Antivirus, version of virus signature database 5410 (20100830) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

Simon

unread,
Aug 31, 2010, 4:17:02 AM8/31/10
to
Note that Log[a] + Log[b] does not always equal Log[a b], that being
said...
Just write some replacement rules
logRep = x_. Log[a_] + y_. Log[b_] :> Log[a^x b^y]

Then, e.g.
In[2]:= y Log[2]+Log[x^2]-Log[z]
Out[2]= y Log[2]+Log[x^2]-Log[z]

In[3]:= %//.logRep
Out[3]= Log[(2^y x^2)/z]

Simon

Peter Breitfeld

unread,
Aug 31, 2010, 4:14:01 AM8/31/10
to
Themis Matsoukas wrote:

PowerExpand treats its expressions assuming all variables are positive.
Normally Log[ab]==Log[a]+Log[b] is not always tru, e.g.

0=Log[(-1)(-1)]!=Log[-1]+Log[-1]==2Pi I

So you have to declare the variables as positives (if your domains are right):

In[1]:= Simplify[Log[a]+Log[b], Assumptions->a>0&&b>0]
Out[1]= Log[ab]

--
_________________________________________________________________
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de

Bob Hanlon

unread,
Aug 31, 2010, 4:14:12 AM8/31/10
to

PowerExpand[Log[a b c]]

log(a)+log(b)+log(c)

% //. Log[x_] + Log[y_] -> Log[x*y]

log(a b c)


Bob Hanlon

---- Themis Matsoukas <tmats...@me.com> wrote:

=============

Peter

unread,
Aug 31, 2010, 4:27:27 AM8/31/10
to

try:

In[1]:= FullSimplify[Log[a]+Log[b],a>0<b]
Out[1]= Log[a b]

Peter

Themis Matsoukas

unread,
Sep 2, 2010, 2:29:51 AM9/2/10
to
To summarize the responses, there are two solutions:

1: Tell mathematica that the arguments are positive numbers:

FullSimplify[2 Log[a] + 3 Log[b], Assumptions -> {a > 0, b > 0, c > 0}]

Log[a^2 b^3]

2: Use a replacement rule

2 Log[a] + 3 Log[b] //. a_ Log[b_] + c_ Log[d_] -> Log[b^a d^c]

Log[a^2 b^3]

Thanks to all.

Themis

0 new messages