I have asked this question on MathStackExchange. My question: is there any non-constant real analytic function $f:\mathbb{R}^n\rightarrow\mathbb{R}$ such that, $$\nabla f(x_0)=0 \Rightarrow \nabla^2 f(x_0)=0$$ and $$f(x+m)=f(x),\quad\forall m\in\mathbb{Z}^n,x\in\mathbb{R}^n.$$
I could find a smooth function with the given property. For example, let $$ f(x)=(2-x^4)\exp(1/(x^4-1))\quad x\in[-1,1],$$ then copy and translate it to fill the whole $\mathbb{R}$. I guess that existence of such functions is impossible, but I don't know how to use the analyticity to prove it