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
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]
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}
ComplexityFunction -> (100 LeafCount[#] + exprSize[#] &)
Bob Hanlon
---- Raffy <adr...@gmail.com> 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
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
> 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
>
Thanks