Message Boards Message Boards


Why does WL not know that Log[a]-Log[b] is Log[a/b]?

Posted 1 year ago
7 Replies
2 Total Likes

Obviously I am to too stupid to understand WL's symbolic calculations. I try to explain my question stepwise:

After a ClearAll["Global`*"] I start with some primitive examples:

In[187]:= Simplify[Log[a] - Log[b]]    
Out[187]= Log[a] - Log[b]

In[188]:= Simplify[Log[a] - Log[b], Reals]    
Out[188]= Log[a] - Log[b]

In[189]:= Simplify[Log[a] - Log[b], b > 0]    
Out[189]= Log[a/b]

Only the last one works. But I have to know, that there is some "-Log[b]" within my expression.

Actually I have some unknown expression exp resulting from some former calculations and I have no idea what that expression will be. Say:

In[190]:= exp = Assuming[Reals, Integrate[1/(m x + c), {x, s0, s}]]    
Out[190]= ConditionalExpression[(Log[1 + (m s)/c] - Log[1 + (m s0)/c])/m, 
 s0 > 0 && Re[s] > s0 && s == Re[s]]

BTW: I have no idea, why I get a ConditionalExpression telling something about real parts although I restricted everything to Reals. But this is another problem.

For the moment I just take the first part of exp (which is nonsense in a general case):

In[191]:= exp1 = First[exp]    
Out[191]= (Log[1 + (m s)/c] - Log[1 + (m s0)/c])/m

... and Simplify it. Which doesn't change anything of course. Unlike the above primitive a,b-example I do not know the structure of my expression exp1 and hence cannot assume anything apart from being Reals:

In[192]:= Simplify[exp1, Reals]    
Out[192]= (Log[1 + (m s)/c] - Log[1 + (m s0)/c])/m

If I knew the result already I could write:

In[193]:= Simplify[exp1, {m s + c > 0, m s0 + c > 0}]    
Out[193]= Log[(c + m s)/(c + m s0)]/m

... and get the desired result. But I don't know anything about exp1.

Now I get to my real application. I have some arbitrary symbolic function v(s) and need the definite integral t(s) of 1/v(s) from s0 to s in a simple form. I know that v(s)>0 within the interval [s0,s]. But I do not know, what the structure of v(s) is. Here a simple example with a straigt line for v(s) (BTW: Without assuming Reals the Integrate takes an awfull long time):

In[194]:= v[s_] := m s + c;
t1 = Assuming[Reals, Integrate[1/v[x], {x, s0, s}]]    
Out[195]= ConditionalExpression[(Log[1 + (m s)/c] - Log[1 + (m s0)/c])/m, 
 s0 > 0 && Re[s] > s0 && s == Re[s]]

If I assume everything I know, i.e. Reals and v(s)>0 I can write:

In[196]:= v[s_] := m s + c;
t2 = Assuming[{Reals, v[x] > 0}, Integrate[1/v[x], {x, s0, s}]]    
Out[197]= ConditionalExpression[(Log[1 + (m s)/c] - Log[1 + (m s0)/c])/m, 
 s0 > 0 && Re[s] > s0 && s == Re[s]]

... but this doesn't change anything.

What I need is a result like t = Log[(c+ m s)/(c+m s0)]/m. How could I get this?

7 Replies

(1) I am pretty sure Assuming[Reals,...] has no meaning. Reals can be used as a domain in solvers that accept such an argument. Assumptions by contrast expects explicit assumptions on stated parameters e.g. c>0.

(2) That second Simplify looks fine, in that log a - log b is not equal to log a/b for arbitrary real (a,b).

Log[a] - Log[b] - Log[a/b] /. {a -> 3, b -> -1}

(* Out[1]= -2 I \[Pi] *)

(3) For parametrized definite integrals, it generally helps to use as many assumptions as possible. Below is an example which could be modified for specific needs.

v[s_] := m s + c;
t1 = Integrate[1/v[x], {x, s0, s}, Assumptions -> {m > 0, c > 0, 0 < s < s0}]

(* Out[416]= Log[(c + m s)/(c + m s0)]/m *)
Posted 1 year ago

Thanks, Daniel. Of course Log[a]-Log[b}==Log[a/b holds true only for a>0 && b>0. But this is not my problem.

Your proposition (3) doesn't help since it makes assumptions about the structure of my expression. Actually I do not know anything about


apart from v[x] being real and positive within the real integration interval [s0,s]. Not even s>=s0 needs to be. Hence I think I cannot write more than the t2 in my original post.

Anyway I can live with log(a)-log(b) not being resolved to log(a/b).

In[3]:= Reduce[Log[a] - Log[b] ==  Log[a/b], {a, b}, Reals]

Out[3]= a > 0 && b > 0
Posted 1 year ago

Ja, of course. That's known, but not my problem.

Posted 1 year ago

A kind of roundabout way:

In[1]:= Log@Exp[Log@a - Log@b]

Out[1]= Log[a/b]

Applied to Werners example:

In[2]:= t = (Log[1 + (m s)/c] - Log[1 + (m s0)/c])/m

Out[2]= (Log[1 + (m s)/c] - Log[1 + (m s0)/c])/m

In[3]:= t /. Log[a_] - Log[b_] -> Log@Exp[Log@a - Log@b]

Out[3]= Log[(1 + (m s)/c)/(1 + (m s0)/c)]/m
Posted 1 year ago

Your Replace-idea will certainly work and does not disturb anything if my expression does not contain loag(a)-log(b). I think it can even be simplified:

In[275]:= v[s_] := m s + c;
t3 = Assuming[{Reals, v[x] > 0}, Integrate[1/v[x], {x, s0, s}]]

Out[276]= ConditionalExpression[(Log[1 + (m s)/c] - Log[1 + (m s0)/c])/m, 
 s0 > 0 && Re[s] > s0 && s == Re[s]]

In[277]:= t3 = Simplify[t3 /. Log[a_] - Log[b_] -> Log[a/b]]

Out[277]= ConditionalExpression[Log[(c + m s)/(c + m s0)]/m, 
 s0 > 0 && Re[s] > s0 && s == Re[s]]
Posted 1 year ago

BTW: To avoid the ConditionalExpression from Integrate, which is useless in my case, one can suppress them with option GenerateConditions. Instead auf writing:

In[359]:= v[s_] := m s + c;
t5 = Assuming[Reals, Integrate[1/v[x], {x, s0, s}]]

Out[360]= ConditionalExpression[(Log[1 + (m s)/c] - Log[1 + (m s0)/c])/m, 
s0 > 0 && Re[s] > s0 && s == Re[s]]

... one can write:

In[361]:= v[s_] := m s + c;
t6 = Assuming[Reals, 
  Integrate[1/v[x], {x, s0, s}, GenerateConditions -> False]]

Out[362]= (Log[1 + (m s)/c] - Log[1 + (m s0)/c])/m
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract