When is the square of the module of an analytic function harmonic? Let $f$ be an analytic function. When is $\lvert f(x+iy) \rvert^2$ a harmonic function? So we know that if $f$ is analytic then $f = u(x,y) + iv(x,y)$ and $u$ and $y$ are both harmonic. So we can write $\lvert f(x+iy) \rvert^2 = u^2 + v^2 = h(x,y)$. In order for $h$ to be harmonic we need $h_{xx} + h_{yy} = 0$. So calculating
$$
h_x = 2u\cdot u_x + 2v \cdot v_x, \quad h_y = 2u \cdot u_y + 2v \cdot  v_y
$$
and 
$$
h_{xx} = 2u_x^2 + 2v_x^2 + 2u \cdot u_{xx} + 2v \cdot v_{xx} \\
h_{yy} = 2u_y^2 + 2v_y^2 + 2u \cdot u_{yy} + 2v \cdot v_{yy}
$$
So if we need $h_{xx} + h_{yy} = 0$ and knowing that $u$ and $v$ are harmonic we get the criteria
$$
u_x^2 + u_y^2 + v_x^2 + v_y^2 = 0
$$
My question is that is this correct and can this criteria be improved some way?
 A: This can be seen quickly using Wirtinger derivatives. Note that $$ \frac{\partial^2}{\partial x^2}+  \frac{\partial^2}{\partial y^2} = 4  \frac{\partial}{\partial z}  \frac{\partial}{\partial \overline{z}}$$ and $$\frac{\partial}{\partial z}  \frac{\partial}{\partial \overline{z}} \lvert f(z)\rvert^2 = \lvert f’(z)\rvert^2.$$
A: Note that for any constant $c \in \mathbb{C}$ and any holomorphic $f$ the difference $$\lvert f(z) \rvert^2 - \lvert f(z)-c \rvert^2$$ is harmonic. In particular if $\lvert f(z) \rvert^2$ is harmonic then so is $\lvert f(z)-c\rvert^2$. In that case $\lvert f(z)-f(z_0) \rvert^2$ is harmonic around $z_0$ and by the mean value property of harmonic functions $\lvert f(z)-f(z_0) \rvert^2$ must be identically zero around $z_0$.
A: What you have derived is essentially one step further than WimC's original answer, and to answer your question as to whether the criteria you've attained can be imporved: it is optimal because it implies that if $f$ is analytic with harmonic $|f|^2$, then $f$ must be constant. Due to your comment on WimC's answer, it seems this wasn't yet clear.
To elaborate:
Your derivation correctly shows that $(\partial_x^2 + \partial_y^2) |f|^2 = 2(u_x^2 + u_y^2 + v_x^2 + v_y^2)$, which is true by $u$ and $v$ being harmonic as you've noted and also that $u_x^2 + u_y^2 + v_x^2 + v_y^2 = 0$ due to the additional condition that $|f|^2$ need be harmonic. Now, each term in this sum is non-negative: $u_x^2, u_y^2 , v_x^2, v_y^2 \geq 0$, so clearly you must have $u_x = u_y = v_x = v_y = 0$. Therefore, since the first derivatives of $u$ and $v$ vanish, both $u$ and $v$ must be constant, which implies $f = u + iv$ is constant.
