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

Simplifying Logs

138 views
Skip to first unread message

Themis Matsoukas

unread,
Oct 13, 2010, 2:39:52 AM10/13/10
to
This works as expected and combines the logs:

Simplify[Log[a] - Log[b], Assumptions -> {a > 0, b > 0}]

Log[a/b]

But this doesn't:

Simplify[1 + Log[a] - Log[b], Assumptions -> {a > 0, b > 0}]

1 + Log[a] - Log[b]

This seems inconsistent to me. I suppose I would like to see a CombineLogs command in the future.

Themis

gekko

unread,
Oct 13, 2010, 11:31:45 PM10/13/10
to
> This seems inconsistent to me. I suppose I would like to see a CombineLog=

s command in the future.
>
> Themis

This is an interesting example. The reason Mathematica doesn't combine
the logs in the second case is that it doesn't consider that the
original expression is any simpler than the original one. The exact
details of why depend on the definition of the default
ComplexityFunction used by Simplify (an implementation of this is
given in the function SimplifyCount, defined in the help menu page for
ComplexityFunction, under the "Properties & Relations" tab). You could
specify an alternative ComplexityFunction, but probably the simplest
is to use a custom rule to perform the desired simplification, e.g.

In[1] := 1 + 2 Log[a] - 3 Log[b] /. x_. Log[a_] + y_. Log[b_] :>
Log[a^x b^y]

Out[1] = 1 + Log[a^2/b^3]

Raffy

unread,
Oct 13, 2010, 11:32:40 PM10/13/10
to
> This seems inconsistent to me. I suppose I would like to see a CombineLog=

s command in the future.
>
> Themis

1 + Log[a/b] // LeafCount === 8
1 + Log[a] - Log[b] // LeafCount === 8

ClearAll[exprSize];
exprSize[x_] := StringLength@ToString[Unevaluated[x], InputForm];
SetAttributes[exprSize,HoldFirst];

Caution: exprSize[1+1] ==> "1 + 1" ==> 5

1 + Log[a/b] // exprSize === 12
1 + Log[a] - Log[b] // exprSize === 19

Simplify[1 + Log[a] - Log[b], Assumptions -> {a > 0, b > 0},
ComplexityFunction -> exprSize] === 1 + Log[a/b]

It would be great for Mathematica to support multiple complexity
functions in case of a tie, similar to SortBy/GatherBy/SplitBy/etc.
ie. ComplexityFunction -> {LeafCount, exprSize}

Bob Hanlon

unread,
Oct 15, 2010, 2:03:39 PM10/15/10
to

That would be written something like

ComplexityFunction -> (100 LeafCount[#] + exprSize[#] &)


Bob Hanlon

---- Raffy <adr...@gmail.com> wrote:

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

Andrzej Kozlowski

unread,
Oct 15, 2010, 2:05:27 PM10/15/10
to

On 14 Oct 2010, at 05:27, gekko wrote:

> On Oct 13, 5:39 pm, Themis Matsoukas <tmatsou...@me.com> wrote:
>> This works as expected and combines the logs:
>>
>> Simplify[Log[a] - Log[b], Assumptions -> {a > 0, b > 0}]
>>
>> Log[a/b]
>>
>> But this doesn't:
>>
>> Simplify[1 + Log[a] - Log[b], Assumptions -> {a > 0, b > 0}]
>>
>> 1 + Log[a] - Log[b]
>>

>> This seems inconsistent to me. I suppose I would like to see a =
CombineLog=


> s command in the future.
>>
>> Themis
>

> This is an interesting example. The reason Mathematica doesn't combine
> the logs in the second case is that it doesn't consider that the
> original expression is any simpler than the original one. The exact
> details of why depend on the definition of the default
> ComplexityFunction used by Simplify (an implementation of this is
> given in the function SimplifyCount, defined in the help menu page for
> ComplexityFunction, under the "Properties & Relations" tab). You could
> specify an alternative ComplexityFunction, but

This isn't quite true. In fact 1+Log[a]-Log[b] is more complex according =
to the default complexity function than Log[E a/b]. The default =
complexity of the former is 9 while the later is 8 (Leaf count, which =
gives answers close to the default complexity is 8 and 7 accordingly.

The real reason why the simplification does not work seems to be due to =
the fact that Mathematica lacks a suitable transformation function and =
it will never replace 1 by Log[E] (since Log[E] is automatically =
converted to 1).

Andrzej Kozlowski

Bob Hanlon

unread,
Oct 16, 2010, 12:16:11 PM10/16/10
to

That would be written something like

ComplexityFunction -> (100 LeafCount[#] + exprSize[#] &)


Bob Hanlon

---- Raffy <adr...@gmail.com> wrote:

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


On Oct 12, 11:39 pm, Themis Matsoukas <tmatsou...@me.com> wrote:
> This works as expected and combines the logs:
>
> Simplify[Log[a] - Log[b], Assumptions -> {a > 0, b > 0}]
>
> Log[a/b]
>
> But this doesn't:
>
> Simplify[1 + Log[a] - Log[b], Assumptions -> {a > 0, b > 0}]
>
> 1 + Log[a] - Log[b]
>

> This seems inconsistent to me. I suppose I would like to see a CombineLog=


s command in the future.
>
> Themis

1 + Log[a/b] // LeafCount === 8

Andrzej Kozlowski

unread,
Oct 16, 2010, 12:17:58 PM10/16/10
to

On 14 Oct 2010, at 05:27, gekko wrote:

> On Oct 13, 5:39 pm, Themis Matsoukas <tmatsou...@me.com> wrote:
>> This works as expected and combines the logs:
>>
>> Simplify[Log[a] - Log[b], Assumptions -> {a > 0, b > 0}]
>>
>> Log[a/b]
>>
>> But this doesn't:
>>
>> Simplify[1 + Log[a] - Log[b], Assumptions -> {a > 0, b > 0}]
>>
>> 1 + Log[a] - Log[b]
>>

>> This seems inconsistent to me. I suppose I would like to see a =
CombineLog=


> s command in the future.
>>
>> Themis
>

Themis Matsoukas

unread,
Oct 18, 2010, 5:52:22 AM10/18/10
to
Thanks for the replies. The best approach seems to be using patterns. Using ComplexityFunction seems too complex :)

Thanks

0 new messages