# Moving the location of the branch cut in Mathematica

According to the documentation, Mathematica chooses the branch cut for $\log(z)$ to lie along the negative real axis. It it possible to change this so that it lies along the positive axis or elsewhere in the complex plane?

-
By the way, welcome to Mathematica.SE! Please consider registering your account so that any upvotes you get on this question are added to those you might get on future questions and answers. That way, over time you will be able to do more on the site (post graphics, edit things, etc). – Sjoerd C. de Vries Nov 18 '12 at 19:16
I don't have enough reputation to comment or vote, but I am just making a note that Mathematica's default branch cut means values fall in (-Pi,Pi], making Jens answer incorrect and Zzz's original answer the correct one. – Owen Barrett Apr 11 '14 at 2:13
Can you explain your reasoning in more detail? @Zzz's answer gives myLog[-1, 0.1] as $-2.94159i$, which is quite incorrect. – Rahul Apr 11 '14 at 2:28
@Owen You are wrong. The inverse of my definition, i.e. the Exp of my function, leads back to the original argument. With ZZZ's definition, that is not the case, so it is not an inverse of the exponential function. – Jens Apr 11 '14 at 2:34
In any case, this is not an answer and should be deleted, perhaps after some more discussion (in case I overlooked something). – Jens Apr 11 '14 at 2:35

Let me join the fun and see if I can write my answer without any omissions... both of the previous ones had little errors you can easily check by inverting the newly defined log function myLog, i.e., doing Exp[myLog[...]].

So here is my definition that I just verified:

myLog[z_, θ_: 0] := Log[Abs[z]] + I (Arg[z Exp[I θ]] - θ)


Note that the sign in front of the branch angle θ has to be different in the two places where it appears, so that when you do the inverse the two instances of θ cancel.

-

My comment from elsewhere seems relevant here, so I'm reposting it.

Here's a Log with a branch cut along any curve of the form $z=-re^{i\theta(r)}$:

myLog[z_, θ_: Function[0]] := With[{r = Abs[z]}, Log[z/Exp[I θ[r]]] + I θ[r]]


Neat example: ArcTan with a weird branch cut.

myArcTan[z_] := Evaluate@ExpToTrig[TrigToExp@ArcTan[z] /. Log[w_] -> myLog[w, # &]]
ContourPlot[Re@myArcTan[x + I y], {x, -3, 3}, {y, -3, 3},
Contours -> FindDivisions[{-π/2, π/2}, 20]]


-

I think the correct way to achieve this is

    myLog[z_, θ_: 0] := Log[Abs[z]] + I (Arg[z Exp[I θ]] + θ)


Positive or negative θ corresponds to moving up or down the Riemann surface.

-
You have a little sign error in there - see my answer. – Jens Nov 18 '12 at 3:27

Sorry for the confusion.

Neither of the proposed answers are correct.

Consider the branch cut along the angle $\theta=\pi/4$. $\log(i)$ with this branch cut should return $-3\pi i/2$.

@Jens's function returns $i\pi/2$.

@Zzz's answer returns the admittedly very wrong $i\pi$. I propose the solution

myLog[z_, θ_: 2 Pi] := Log[Abs[z]] + I (Mod[Arg[z], 2 Pi, -2 Pi + θ])


The issue with this setup is that we must take $\theta \in (0,2\pi]$. This is awkward, because it means that if we want the branch cut at the positive reals, we must set $\theta = 2\pi$, not $0$. Perhaps someone else can fix it. But anyway, it gives the right answers.

-
Again, you are misunderstanding something if you think there's a mistake in my answer. My definition returns the correct result if you set the branch parameter in my function such that the branch cut is at $\pi/4$. However, that means, with my parametrization, that you have to choose $\theta= 3 \pi/4$. In fact, I used that parametrization only to correspond more closely to ZZZ's answer. I used a less confusing parametrization in this related answer. – Jens Apr 11 '14 at 22:50
@Jens: Yes, indeed this is the confusion, since I assumed the parameter $\theta$ would give the branch cut at $\{ s e^{i\theta} : 0 \leq s\in\mathbf{R} < \infty \}$, but apparently that is not the case. This is how I parametrize it. Thanks for the clarification. – Owen Barrett Apr 12 '14 at 2:13