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?
3 Answers
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.
-
$\begingroup$ I think @Zzz has right sign. May be you would like to consider it. Let me know if I am wrong, but I checked it(properly hope so). E.g.
myLog[Exp[3 I Pi], Pi] = 3 I Pi
, however, in your case, it comes out to be-I Pi
, which is not even in the cut range(i.e fromPi
to3 Pi
). I hope I am not talking bullshit $\endgroup$– L.K.Commented Apr 14, 2018 at 17:24 -
$\begingroup$ @L.K I posted this answer as a response to the one by Zzz and therefore took over the definition of the angle from that answer. But that angle is actually the (negative of) the direction angle of the branch cut plus $\pi$. A more useful definition that really uses the angle of the branch cut is in the answer I gave here. It also gives the result you expect with the value of the second argument corresponding to the true branch angle. $\endgroup$– JensCommented Apr 14, 2018 at 23:30
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.
-
$\begingroup$ You have a little sign error in there - see my answer. $\endgroup$– JensCommented Nov 18, 2012 at 3:27
-
$\begingroup$ No one ever answered original ZZZ's question in a straightforward shortest code 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? $\endgroup$– simonCommented Dec 30, 2022 at 15:44
myLog[-1, 0.1]
as $-2.94159i$, which is quite incorrect. $\endgroup$Exp
of my function, leads back to the original argument. WithZZZ
's definition, that is not the case, so it is not an inverse of the exponential function. $\endgroup$