# Unexpected behavior of log() in complex plane

For the log() to be defined properly in the complex plane we need to agree on where its cut is located. So, for sage it is easy to check that the cut is located on the negative Re-axis (as is most common), namely

```
sage: var('eps')
sage: limit(log(-1+i*eps),eps=0,dir='+')
I*pi
sage: limit(log(-1+i*eps),eps=0,dir='-')
-I*pi
```

Ok. Now I want to use this with symbolic variables. So I do

```
sage: var('w eps')
sage: forget()
sage: assume(w,'real')
sage: assume(w>0)
sage: limit(log(-w+i*eps),eps=0,dir='+')
I*pi + log(w)
sage: limit(log(-w+i*eps),eps=0,dir='-')
-I*pi + log(w)
```

Ok. That is correct. Now I want to get a little more adventurous, namely

```
sage: var('w ec eps')
sage: forget()
sage: assume(w,'real')
sage: assume(ec,'real')
sage: assume(eps,'real')
sage: assume(w>0)
sage: assume(w<ec)
sage: limit(log(w-ec+i*eps),eps=0,dir='+')
I*pi + log(-ec + w)
sage: limit(log(w-ec+i*eps),eps=0,dir='-')
-I*pi + log(-ec + w)
```

**Oops? This is wrong.** The argument of the log() has not been turned into the absolute value its real part, i.e. `ec-w`

. This also contradicts the previous simpler startup examples.

Just for backup. Mathematica will give you

```
In[6]:= Limit[Log[w-ec+I eps],eps->0,Direction->-1,Assumptions->{w>0,w<ec}]
Out[6]= I Pi+Log[ec-w]
In[7]:= Limit[Log[w-ec+I eps],eps->0,Direction->1,Assumptions->{w>0,w<ec}]
Out[7]= -I Pi+Log[ec-w]
```

As I was expecting and at variance with sage's output.

The documentation for log says that it picks "the branch with angle between -pi and pi." So you're saying that this is not the actual behavior?

I have an even simpler example that shows that your startup example 2 was only correct by chance: var('w,eps') forget() assume(w,'real') assume(w<0) limit(log(w+i*eps),eps=0,dir='+') This is evaluated as I*pi + log(w) I don't know what exactly goes on here, but it seems the whole 'assume()'-business in SAGE is behaving unintuitively, if not just wrong.

@John Palmieri: with z=r * e^(i * phi), where r=|z|, we have log(z)=i*phi+log(|z|). As always we have to chose how to count phi. The 1st and 2nd example agree with sage having the branch cut on the negative real axis with phi=+pi in the upper half and -pi in the lower half plane. The 3rd example still agrees with that but the real part is not log(|z|), which would be log(ec-w), but log(w-ec), which is not even defined, since w-ec is real and negative. The last example shows that Mathematica does this right. It has Log[ec-w], which is ok.

Good catch, Xaver -- this does seem like a bug. No matter what branch you use to evaluate log(-ev+w) in that output, Sage's answer is wrong.

We should be able to do these examples in pure Maxima, since the limit and assumption facilities are from Maxima. HOWEVER, Maxima is pretty explicit that its integrals and solve commands do *not* take account of assumptions like that very much, because 1) their assumption facilities are "weak" (obviously stronger than anything else in Sage, though) and 2) often they let things in things like solve be treated as dummy variables, differently from how it works in Python/Sage where you can't really do that.