Re: Simplify Log[ab] - Log[b] to Log[a] ?

• To: mathgroup at smc.vnet.net
• Subject: [mg16050] Re: Simplify Log[ab] - Log[b] to Log[a] ?
• From: dreissBLOOP at bloop.earthlink.net (David Reiss)
• Date: Mon, 22 Feb 1999 01:44:31 -0500
• References: <7ao3po\$rv0@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```In article <7ao3po\$rv0 at smc.vnet.net>, "Simon Allfrey"
<simon at allfrey13.freeserve.co.uk> wrote:

> How do I persuade Mathematica to simplify
>
> Log[a b] - Log[b] to Log[a]?
>
> when processing algebraic expressions?

In your simple example you could do the following
with pattern matching in a repalcement rule:

In[1]:=
rules = {Log[x_ y_] :> Log[x] + Log[y]}

Out[1]=
{Log[(x_) (y_)] :> Log[x] + Log[y]}

In[2]:=
Log[a*b] - Log[b] /. rules

Out[2]=
Log[a]

In the following case you need to use ReplaceRepeated (//.)
so that the rule is applied until the expression no longer
changes:

In[3]:=
Log[a*b*c] - Log[b] - Log[c] /. rules

Out[3]=
Log[a] - Log[b] - Log[c] + Log[b c]

In[4]:=
Log[a*b*c] - Log[b] - Log[c] //. rules

Out[4]=
Log[a]

However, since a and b can be rather complicated,
and because in such a case the product, a b, might
be represented in its FullForm by something other
than Times[a, b], you need to write transformation
rules that cover all cases of interest.

In[5]:=
FullForm[a*b]

Out[5]//FullForm=
Times[a, b]

Note that the following doesn't simplify to the
degree that you want:

In[6]:=
Log[a*b/c] - Log[b] /. rules

Out[6]=
b
Log[a] - Log[b] + Log[-]
c

This is because the FullForm of (a b/c) does not correspond
to the rule:

In[7]:=
FullForm[a*b/c]

Out[7]//FullForm=
Times[a, b, Power[c, -1]]

In[8]:=
FullForm[b/c]

Out[8]//FullForm=
Times[b, Power[c, -1]]

But, if we include another rule to cover this case,
it does work:

In[9]:=
rules = {Log[(x_)*(y_)] :> Log[x] + Log[y],
Log[(x_)/(y_)] :> Log[x] - Log[y]}

Out[9]=
{Log[(x_) (y_)] :> Log[x] + Log[y],

Log[x_/y_] :> Log[x] - Log[y]}

In[10]:=
Log[a*b/c] - Log[b] //. rules

Out[10]=
1
Log[a] + Log[-]
c

--

----------------------------------------

Scientific Arts:
Creative Services and Consultation
for the Applied and Pure Sciences

David Reiss
Email: dreiss at !SPAMscientificarts.com

----------------------------------------

Remove the !SPAM to send email

```

• Prev by Date: Re: Simplify Log[ab] - Log[b] to Log[a] ?
• Next by Date: Reset In[ ] & Out[ ]
• Previous by thread: Re: Simplify Log[ab] - Log[b] to Log[a] ?
• Next by thread: Re: Simplify Log[ab] - Log[b] to Log[a] ?