# Simplifying Logs assuming arbitrary arguments real and positive

I have some expressions involving Logs which I would like to simplify. Unfortunately FullSimplify doesn't work because it assuming the arguments are general. I have no way of knowing a priori what the arguments will be. I just need a way of forcing Mathematica to think that everything inside a Log is real and positive, so that FullSimplify works appropriately!

Does anyone know how I might go about doing this? An alternative would be to write a really good TransformationFunction which does the same as FullSimplify would do for Logs. But all my efforts so far have worked in isolated cases and failed on really complicated expressions. If anyone could point me towards a library where this is implemented I'd be eternally grateful.

Simple Examples

x Log[a/b] + y Log[b/a] = (x-y)Log[a/b]
x Log[a] + x Log[b] = x Log[a b]


Of course these could occur at any point during Simplify, and I'd like Mathematica to be looking out for them and trying to do them. Often, by the time an ordinary Simplify is finished it takes quite a long time to recast the terms in a form where I can combine the Logs (I've got circa 500 terms to deal with)!

Edit

Trying the Assumption

FullSimplify[expr,Log[_]>0]


doesn't work, sadly. See this question, for example!

• Try PowerExpand (documentation page). It will automatically assume that exponents are integers, and arguments are positive real numbers. Careful though: checking whether these assumptions are appropriate is entirely left to the user! Jun 11, 2015 at 15:38
• @MarcoB - thanks for the suggestion. As I understand it, PowerExpand will split the Logs up and I'll then have to reassemble them. In my case this would generate an enormous number of terms. I'd prefer to keep the vast majority of terms intact and just combine Logs when appropriate. Do you have a suggestion which would accomplish this? Jun 11, 2015 at 15:41
• Edward, could you give a minimal example of an expression you have, and what you would like the transformed output to be? Jun 11, 2015 at 15:41
• Sure - have added these to the question. Jun 11, 2015 at 15:45
• You might consider the SuperLog function by Colin Rose and Murray D. Smith of mathStatica fame: [mathematica.stackexchange.com/questions/32472/…
– JimB
Jun 11, 2015 at 16:43

Maybe you could extract the arguments of your Logs, then turn them into a list of assumptions to feed to e.g. FullSimplify:

arguments = Cases[
{(3 Log[whatever/argument + you have] + 5)/2 +
some other crud / and + many Exp[4^more] Log[expressions]},
Log[a_] -> a, Infinity
];

arguments > 0

(* Out: {expressions > 0, whatever/argument + have you > 0} *)


Any expression involved in an inequality is automatically assumed to be Real by the Simplify family of functions.

• Cheers - I might have to do that I suppose. I'd thought of it, but hoped Mathematica had some more elegant way of dealing with it! Jun 11, 2015 at 16:07
• Doesn't seem to work for Log[x^2]. It figures out assumption x^2>0 but it doesn't help to get 2Log[x] Jun 11, 2015 at 16:17
• Yes - I agree with @BlacKow. It won't work for x Log[a/b] + y Log[b/a] either... Jun 11, 2015 at 16:31
• I came up with simplistic rules that deal with your particular situation - see my answer updated. Not sure how deep you want to go? Factor the arguments? Jun 11, 2015 at 16:45

Will Assumptions work?

Log[z^2] // FullSimplify
(* Log[z^2] *)

Log[z^2] // FullSimplify[#, z > 0] &
(* 2 Log[z] *)


Edit: Naive implementation of rules.

LSimpl[f_] :=
f //. Log[x_*y_] -> Log[x] + Log[y] //.
Log[x_^n_Integer] -> n*Log[x];
LSimpl[x Log[a/b] + y Log[b/a]]
(* x (Log[a] - Log[b]) + y (-Log[a] + Log[b]) *)

• Not really, because I have no idea what the argument of the Log is in general! If you know of a way of setting global assumptions on the argument of the Log function, that would certainly work. But I can't work out how to do this... Jun 11, 2015 at 15:48
• @EdwardHughes I'm not sure I understand. If at some point you have Log[-x^2] what would be a simplification? if x is imaginary the argument of Log is still positive Jun 11, 2015 at 15:52
• You simplification is exactly correct. It's just that I can't implement your strategy, because I don't actually know what will appear inside the Logs. It will involve some very complicated quantities in several variables coming from the expansion of hypergeometric functions. So I can't write an Assumption of z >0 because I don't know naively what form z will take! Maybe I could write Log[x_] > 0 as a pattern match assumption... I'll try that... Jun 11, 2015 at 15:57
• Yes, I got that. What would be the desired behavior for situation in my previous comment? Log[-x^2] Jun 11, 2015 at 16:07
• That's mathematically incorrect. Jun 11, 2015 at 16:21

The following works on the two "Simple Examples"

logSimplify = FullSimplify[#, (# > 0) & /@
Union@Cases[Cases[#, Log[z_] -> z, Infinity], z_Symbol -> z, Infinity]] &

logSimplify[x Log[a] + x Log[b]]
(* x Log[a b] *)

logSimplify[x Log[a/b] + y Log[b/a]]
(* (x - y) Log[a/b] *)


and also on some variants

logSimplify[x Log[a^2/b^3] + y Log[b^3/a^2]]
(* (x - y) Log[a^2/b^3] *)


Undoubtedly, it does not work in all situations. Nonetheless, it may be a step in the right direction.