Q:

When is the composition of a function and a harmonic function harmonic?

I was looking at a comprehensive exam, and I found the this question. Can anyone help me out?
If $u$ is a harmonic function, which type of function $f$ is needed so that $f(u)$ is harmonic?

A:

Note that $u$ is harmonic if and only if 
$$\Delta u:=\frac{\partial^2 u}{\partial x^2}+\frac{\partial^2 u}{\partial y^2}=0.$$ Therefore, if $u$ is harmonic, by chain rule we have
$$\Delta f(u)=\frac{df}{du}\Big(\frac{\partial^2 u}{\partial x^2}+\frac{\partial^2 u}{\partial y^2}\Big)+\frac{d^2f}{du^2}\Big(\big(\frac{\partial u}{\partial x}\big)^2+\big(\frac{\partial u}{\partial y}\big)^2\Big)=\frac{d^2f}{du^2}\Big(\big(\frac{\partial u}{\partial x}\big)^2+\big(\frac{\partial u}{\partial y}\big)^2\Big).$$
If $u$ is a constant function (which is harmonic), then $\frac{\partial u}{\partial x}=\frac{\partial u}{\partial y}=0$. It follows from the above formula that $f(u)$ is harmonic for any function $f$. On the other hand, if $u$ is a nonconstant harmonic function, then $\big(\frac{\partial u}{\partial x}\big)^2+\big(\frac{\partial u}{\partial y}\big)^2\neq 0$. Again it follows from the above formula that $f(u)$ is harmonic when $\frac{d^2f}{du^2}=0$, that is, when $f$ is a linear function in $u$:
$$f(u)=Au+B,$$
where $A$ and $B$ are constants. 

