The derivative of absolute value of complex function $f(x,z)$ where $x \in \mathbb{R}$ and $z \in \mathbb{C}$ Let $f: \mathbb{R} \to \mathbb{R}$ be a real function and let $z \in \mathbb{C}$ be a complex number such that
$$
f(x)=|x \cdot z|
$$
Let's calculate the derivative of $f$
if we applicate the derivation rules:
$$
f'(x)=\dfrac{x \cdot z}{|x \cdot z|}
\cdot
z
$$
but it's wrong indeed
$$
f(x)=|x \cdot z| = |x| \cdot |z|
$$
and now
$$
f'(x)=\dfrac{x}{|x|}
\cdot
|z|
$$
so what's the derivative of $f$?
In general what's the derivative of absolute value of a function $|f(x,z)|$ respect the real variable $x$ and $z \in \mathbb{C}$?
Thanks.
 A: I'm going to deal with the general problem: Given a complex valued function
$$g:\quad{\mathbb R}\to {\mathbb C},\qquad x\mapsto g(x)=u(x)+i v(x)\ ,$$
one has   $|g(x)|=\sqrt{u^2(x)+v^2(x)}$ and $g'=u'+i v'$. Therefore
$${d\over dx}\bigl|g(x)\bigr|={u(x)u'(x)+v(x)v'(x)\over\sqrt{u^2(x)+v^2(x)}}={{\rm Re}\bigl(g(x) \overline{ g'(x)}\bigr)\over|g(x)|}\ .\tag{1}$$
In the example at hand $z$ is a constant, and $g(x):=xz$, so that $g'(x)=z$. According to $(1)$ one then has
$${d\over dx}\bigl|x\,z\bigr|={{\rm Re}\bigl(xz\,\bar z\bigr)\over|x\,z|}={x\,|z|^2\over |x|\,|z|}={x\over|x|}\,|z|\qquad\bigl(xz\ne0)\ .$$
A: $f(x)=|x\cdot z|$ is a real function, for any $z\in\mathbb{C}$
Let $z= a+bi;\;a,b\in\mathbb{R}$
then $$f(x)=|x\,z|=|ax+bxi|=\sqrt{a^2x^2+b^2x^2}$$
and $$f'(x)=\frac{a^2 x+ b^2 x}{ \sqrt{a^2 x^2+b^2 x^2}}=|z|\cdot \dfrac{x}{|x|}$$
A: Interesting.  We try to use the chain rule I guess.
You are using the formula
$$
\frac{d}{dx} |x| = \frac{x}{|x|}
\tag{*}$$
which is true when $x$ is real and nonzero.  Then you try to use the chain rule like this
$$
\frac{d}{dx} \big|g(x)\big| = \frac{g(x)}{|g(x)|}\;g'(x)
\tag{**}$$
This will be OK if $g$ is a differentiable function whose values are nonzero reals.  But you attempt to apply it to the function $g(x) = xz$ with non-real values.  No good.  As I said, (*) is only for real values, so (**) is only for real-valued functions $g$.
