Function Repository Resource:

LogContract

Source Notebook

Contracts sums of logarithms into a single logarithm

Contributed by: Carl Woll

ResourceFunction["LogContract"][expr]

contracts sums of Log expressions into a single Log expression.

Details and Options

ResourceFunction["LogContract"] converts aLog[b] to Log[ba] plus an extra term that depends on the branch cut of Log for the given arguments.
ResourceFunction["LogContract"] converts Log[a]+Log[b] to Log[ab] plus an extra term that depends on the branch cut of Log for the given arguments.
ResourceFunction["LogContract"] automatically threads over lists, as well as equations, inequalities and logic functions.
Products that contain a Log expression are converted into an equivalent Log expression where the factor is included as the exponent.
ResourceFunction["LogContract"] has the option Assumptions, specifying assumptions to use.
The default setting for the Assumptions option is True, corresponding to no assumptions.
With the setting Automatic for the Assumptions option, a maximal set of assumptions is made, disregarding all issues of branches of multivalued functions.

Examples

Basic Examples (3) 

Reproduce a basic Log identity:

In[1]:=
ResourceFunction["LogContract"][Log[a] + Log[b], Assumptions -> a + b > 0]
Out[1]=

Find conditions for which Log[a]-Log[b] is equal to Log[a/b]:

In[2]:=
d = Log[a] - Log[b];
e = ResourceFunction["LogContract"][d]
Out[2]=

Contract logs, disregarding branch cut issues:

In[3]:=
ResourceFunction["LogContract"][Log[x] + x Log[x], Assumptions -> Automatic]
Out[3]=

The result is not generically true:

In[4]:=
FindInstance[Log[x] + x Log[x] != Log[x^(1 + x)], x]
Out[4]=

Scope (2) 

LogContract automatically threads over equations:

In[5]:=
ResourceFunction["LogContract"][Log[a] - Log[b] == Log[a/b], Assumptions -> b > 0]
Out[5]=

LogContract is essentially the inverse of PowerExpand for logarithmic expressions:

In[6]:=
PowerExpand[Log[Sin[x]/x]]
Out[6]=

Contracting to the original expression:

In[7]:=
ResourceFunction["LogContract"][%, Assumptions -> Automatic]
Out[7]=

Options (2) 

Assumptions (2) 

The default option setting for Assumptions is $Assumptions. By default $Assumptions=True, meaning that LogContract gives a universally correct result:

In[8]:=
ResourceFunction["LogContract"][-8 I \[Pi] + c (Log[a] + Log[b])]
Out[8]=

With the setting Automatic, a maximal set of assumptions are used and the output is not generically correct:

In[9]:=
ResourceFunction["LogContract"][-8 I \[Pi] + c (Log[a] + Log[b]), Assumptions -> Automatic]
Out[9]=

A simpler result is obtained with suitable assumptions:

In[10]:=
ResourceFunction["LogContract"][-8 I \[Pi] + c (Log[a] + Log[b]), Assumptions -> 3 < a < 5 && -2 < b < -1 && 7 < c < 9]
Out[10]=

Contract logs assuming real arguments:

In[11]:=
ResourceFunction["LogContract"][Log[1 - Sin[a]] + Log[1 + Sin[a]], Assumptions -> a \[Element] Reals]
Out[11]=
In[12]:=
ResourceFunction["LogContract"][Log[Sign[x]] + Log[x], Assumptions -> x \[Element] Reals]
Out[12]=
In[13]:=
ResourceFunction["LogContract"][
 Log[1 - Cos[2 x]] - Log[1 + Cos[2 x]], Assumptions -> x \[Element] Reals]
Out[13]=

Possible Issues (1) 

The default option for LogContract is AssumptionsTrue, unlike PowerExpand which uses Automatic as the default:

In[14]:=
ResourceFunction["LogContract"][Log[x] + Log[y]]
Out[14]=
In[15]:=
ResourceFunction["LogContract"][Log[x] + Log[y], Assumptions -> Automatic]
Out[15]=

Publisher

Carl Woll

Version History

  • 1.0.0 – 22 October 2019

License Information