From the Wolfram functions web site it is known that
$$\log(z_1)+\log(z_2)=\log(z_1z_2),\text{ for $z_1+z_2>0$}$$
In an answer to this question Alexei Boulbitch wrote a useful function collectLog
. However, this function does not impose conditions on the Log
-arguments.
Therefore, my question is, how should collectLog
look like, so that it can be used in
FullSimplify[Log[a] + Log[b],
TransformationFunctions -> {Automatic, collectLog},
Assumptions -> a + b > 0]
providing the desired simplification only when the condition is met.
Addendum
In trying to create a minimal example I simplify the problem too much. In fact, the main motivation is to combine two Log
-functions together when it can be inferred from the given assumptions that the sum of arguments is positive. In many cases the solution of Carl Woll already works fine. For instance here
Assuming[a∈Reals,FullSimplify[Log[1-Sin[a]]+Log[1+Sin[a]],
TransformationFunctions->{Automatic,LogContract}]]
(* Log[Cos[a]^2] *)
The product of 1-Sin[a]
and 1+Sin[a]
is equal to Cos[a]^2
, which is positive for $x\in\mathbb{R}$, thus, endorsing the simplification.
However, there are many exceptions that I would like to be addressed too. Below are two simple examples where the LogContract
fails.
- Identity 1
$$\log(\mathrm{sign}\,x)+\log(x)=\log(x\,\mathrm{sign}\,x)=\log{\!|x|},\text{ for $x\in\mathbb{R}$.}$$
Assuming[a∈Reals,FullSimplify[Log[Sign[a]]+Log[a],
TransformationFunctions->{Automatic,LogContract}]]
(* Log[a]+Log[Sign[a]] *)
The expected result is Log[Abs[a]]
.
- Identity 2
$$\log(1-\cos2x)-\log(1+\cos2x)=\log\!\left(\frac{1-\cos2x}{1+\cos2x}\right)=\log\!\left(\tan^2\!x\right),\text{ for $x\in\mathbb{R}$.}$$
Assuming[a∈Reals,FullSimplify[Log[1-Cos[2 x]]-Log[1+Cos[2 x]],
TransformationFunctions->{Automatic,LogContract}]]
(*-Log[Cos[x]^2]+Log[Sin[x]^2]*)
The expected result is Log[Tan[x]^2]
.
Comment
Many expressions of this kind result from the integration and not artificially constructed just to make the function fail. At the moment it is a rather laborious process to bring the expressions to a human-readable form.