Why does Arg'[1. + I] return -0.5?

The internal Trace[] Kuba advises shows calculations consistent with the numeric approximation of the partial derivative with respect to the real part:

D[ComplexExpand[Arg[x + I y], TargetFunctions -> {Re, Im}], x] /. 
  x -> 1 /. y -> 1
(*  -(1/2)  *)

This is what Mathematica does with the derivative of a numeric function with approximate input.

Other examples:

ClearAll[f, g];
f[x_?NumericQ] := Re[x]^2;
g[x_?NumericQ] := Im[x]^2;

f'[1. + I]
g'[1. + I]
(*
  1.999999999999995`  
  -2.7506672371246275`*^-15 
*)

It seems like the wrong way to evaluate Derivative.


The definition of the argument is $\arg(z)=\text{Im}(\ln(z))$. Its partial derivative with respect to $z$ would then be

$$ \frac{\partial \arg(z)}{\partial z}= \frac{\partial}{\partial z}\frac{\ln(z)-\ln(z^*)}{2i} = -\frac{i}{2z}. $$

What you see looks like twice the real part of this expression:

With[{z = 2. + 5 I},
  {Arg'[z], 2Re[-I/(2z)]}]

(* {-0.172414, -0.172414} *)

I don't know in which sense this is the "correct" answer. It could be that what is actually calculated is not the partial derivative with respect to $z$, but rather the partial derivative with respect to the real part of $z$:

$$ \frac{\partial \arg(z)}{\partial\text{Re}(z)} =\frac{\partial \arg(z)}{\partial z}\frac{\partial z}{\partial\text{Re}(z)} +\frac{\partial \arg(z)}{\partial z^*}\frac{\partial z^*}{\partial\text{Re}(z)}\\ =\frac{\partial \arg(z)}{\partial z} +\frac{\partial \arg(z)}{\partial z^*} = -\frac{i}{2z}+\frac{i}{2z^*} = -\frac{\text{Im}(z)}{|z|^2} $$

With[{z = 2. + 5 I},
  {Arg'[z], 2Re[-I/(2z)], -Im[z]/Abs[z]^2}]

(* {-0.172414, -0.172414, -0.172414} *)